using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


namespace .UI.images.Expro
{
    public partial class NewsTypeList : .BLL.AdminPage
    {
        protected string tempTable="Expro_NewsType";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                AjaxFunction();
              //  Power(this.U_Account, this.MIDS[Convert.ToInt32(.BLL.ModelList.系统设置)]);
                BindSortList();
                if (this.GetRequest("columnid").Length > 0 && this.GetRequest("mark").Length < 1)
                {
                    Move(Convert.ToInt32(this.GetRequest("direction")), this.GetRequest("columnid"), this.GetRequest("columnorder"));
                }
                ViewState["depth"] = this.GetRequest("depth").Length < 1 ? ("0") : (this.GetRequest("depth"));

            }
        }
        public override .BLL.RightClass Power(string U_Account, string M_ID)
        {
            .BLL.RightClass rc = base.Power(U_Account, M_ID);
            this.BtDel.Visible = rc.right_Delete;
            this.BtVerfly.Visible = rc.right_Verify;

            return rc;

        }
        public void AjaxFunction()
        {
            string IsAjax = GetRequest("IsAjax");
            if (IsAjax.Length > 0)
            {
                string temp = "";
                string State = GetRequest("State").ToLower();
                State = State == "true" || State.Length < 1 ? ("0") : ("1");
                string Gid = GetRequest("Gid");
                string sql = "update " + tempTable + " set bs_showindex=@bs_showindex where Column_ID=@Column_ID";
                if (this.Db.GetState(sql, new SqlParameter[] { new SqlParameter("@bs_showindex", State), new SqlParameter("@Column_ID", Gid) }))
                {
                    temp = "1";
                }
                else
                {
                    temp = "0";
                }
                Response.Clear();
                Response.Write(temp);
                Response.End();
            }
        }
        /// <summary>
        /// 移动操作
        /// </summary>
        /// <param name="direction"></param>
        /// <param name="columnid"></param>
        public void Move(int direction, string columnid, string columnorder)
        {

            string sql = "";
            string message = "";
            switch (direction)
            {
                case -1:
                    sql = string.Format("select top 2 Column_Name,Column_ID,Column_Order,(select count(*) from {2} a where a.parent_id=t.column_id) childsnNum from {2} t where Parent_ID='{0}'  and Column_Order<={1} order by Column_Order desc", columnid, columnorder, tempTable);
                    message = "已经是该栏目的顶分类不能移动";
                    break;
                case 1:
                    sql = string.Format("select top 2 Column_Name,Column_ID,Column_Order,(select count(*) from {2} a where a.parent_id=t.column_id) childsnNum from {2} t where Parent_ID='{0}'  and Column_Order>={1} order by Column_Order asc", columnid, columnorder,tempTable);
                    message = "已经是该栏目的底分类不能移动";
                    break;
                default:

                    break;

            }
            DataTable dt = this.Db.GetTable(sql);
            if (dt != null)
            {
                if (dt.Rows.Count < 2)
                {
                    this.ShowMessage(message, "history.go(-1)");
                }
                else
                {

                    string selfid = Convert.ToString(dt.Rows[0]["Column_ID"] ?? "");
                    string selforder = Convert.ToString(dt.Rows[0]["Column_Order"] ?? "");
                    string otherid = Convert.ToString(dt.Rows[1]["Column_ID"] ?? "");
                    string otherorder = Convert.ToString(dt.Rows[1]["Column_Order"] ?? "");
                    ArrayList al = new ArrayList();
                    al.Add(string.Format("update [{2}] set [Column_Order]={0} where Column_ID='{1}'", otherorder, selfid,tempTable));
                    al.Add(string.Format("update [{2}] set [Column_Order]={0} where Column_ID='{1}'", selforder, otherid, tempTable));
                    if (this.Db.GetTranState(al))
                    {

                        Response.Redirect(Request.UrlReferrer.ToString().Length < 1 ? (Request.Url.ToString().IndexOf("?") >= 0 ? (Request.Url.ToString().IndexOf("mark=") >= 0 ? (System.Text.RegularExpressions.Regex.Replace(Request.Url.ToString(), "mark=[^&]*", "mark=0")) : (Request.Url.ToString() + "&mark=0")) : (Request.Url.ToString() + "?mark=0")) : (Request.UrlReferrer.ToString().IndexOf("?") >= 0 ? (Request.UrlReferrer.ToString().IndexOf("mark=") >= 0 ? (System.Text.RegularExpressions.Regex.Replace(Request.UrlReferrer.ToString(), "mark=[^&]*", "mark=0")) : (Request.UrlReferrer.ToString() + "&mark=0")) : (Request.UrlReferrer.ToString() + "?mark=0")));

                    }
                    else
                    {
                        this.ShowError("网络连接错误请联系系统管理员!!");
                    }

                }
            }


        }
        /// <summary>
        /// /分类绑定
        /// </summary>
        public void BindSortList()
        {
            string parent_id = this.GetRequest("parentid");
            parent_id = parent_id.Length < 1 ? ("0") : (parent_id);
            string keys = Convert.ToString(ViewState["keys"]);
            string sql = string.Format("select Column_Name,Column_ID,Column_Order,Column_depth,parent_id,(select count(*) from {2} a where a.parent_id=t.column_id) childsnNum from {2} t where Parent_ID='{0}'{1} order by Column_Order", parent_id, keys, tempTable);
            this.gvList.DataSource = this.Db.GetTable(sql);
            this.gvList.DataBind();
        }
        /// <summary>
        /// 递归生成列表
        /// </summary>
        /// <param name="parentid"></param>
        public void BindSort(string parentid, string parentname)
        {
            DataTable dt = this.Db.GetTable(string.Format("select Column_Name,Column_ID from [sort] where Parent_ID='{0}'", parentid));
            if (dt != null)
            {

            }
            else
            {

            }
        }

        protected void BtSearch_Click(object sender, EventArgs e)
        {
            string keys = this.TbKeyword.Text.Trim();
            keys = keys.Length < 1 ? ("") : (" and Column_name like '%" + keys + "%'");
            ViewState["keys"] = keys;
            this.BindSortList();
        }

        protected void BtVerfly_Click(object sender, EventArgs e)
        {

        }

        protected void BtDel_Click(object sender, EventArgs e)
        {
            //删除没有子类的栏目
            ArrayList al = this.GetSqls("delete from " + tempTable + "  where Column_id='{0}' and not exists(select * from " + tempTable + " where parent_id='{0}')");
            if (this.Db.GetTranState(al))
            {
                this.ShowMessage("删除成功!!", "document.location=document.location.href");
            }
            else
            {
                this.ShowError("没有要删除的数据或数据不存在!!请联系系统管理员!!");
            }


        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex != -1)
            {
                DataRowView drv = e.Row.DataItem as DataRowView;
                string column_id = Convert.ToString(drv["Column_ID"] ?? "");
                string parent_id = Convert.ToString(drv["parent_id"] ?? "");
                string column_order = Convert.ToString(drv["Column_Order"] ?? "");
                string column_depth = Convert.ToString(drv["Column_depth"] ?? "");
               // string State = Convert.ToString(drv["bs_showindex"] ?? "").ToLower();
                e.Row.Cells[0].Text = string.Format(this.CheckBoxString, column_id);
                e.Row.Cells[5].Text = string.Format("<a href='" + Request.Path.ToString() + "?direction={0}&columnid={1}&columnorder={2}'>上移</a>", "-1", parent_id, column_order);
                e.Row.Cells[6].Text = string.Format("<a href='" + Request.Path.ToString() + "?direction={0}&columnid={1}&columnorder={2}'>下移</a>", "1", parent_id, column_order);
                // e.Row.Cells[7].Text = string.Format("<a href='EditSort.aspx?parentid={0}&depth={1}&action=add' target='_blank'>添加子类</a>&nbsp;<a href='EditSort.aspx?id={0}&action=update' target='_blank'>编辑该类</a>", Convert.ToString(drv["Column_ID"] ?? ""), column_depth);
                e.Row.Cells[7].Text = string.Format("<a href='#' onclick=\"openWindow('SortEdit.aspx?parentid={0}&depth={1}&action=add',800,300);return false;\">添加子类</a>&nbsp;<a href='#'  onclick=\"openWindow('SortEdit.aspx?id={0}&action=upd',800,300);return false;\">编辑该类</a>", Convert.ToString(drv["Column_ID"] ?? ""), column_depth);
                e.Row.Cells[8].Text = string.Format("<a href='"+Request.Path.ToString()+"?parentid={0}&depth={1}'>查看子类</a>", Convert.ToString(drv["Column_ID"] ?? ""), column_depth);
            }

 

        }
    }
}

posted on 2009-03-13 18:21  bestsaler  阅读(138)  评论(0编辑  收藏  举报