⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagebase.cs

📁 CRM管理系统 CRM管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Data;
using System.Configuration;
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.Text;

/// <summary>
/// PageBase 的摘要说明
/// </summary>
public partial class PageBase:System.Web.UI.Page
{
    /// <summary>
    /// 公用的消息
    /// </summary>
    protected string msg = string.Empty;
    public PageBase()
    {
    }

    #region 身份验证
    /// <summary>
    /// 用户帐号
    /// </summary>
    protected Itsv.Model.User CurrentUser
    {
        get
        {
            if (Session["CurrentUser"] == null)
            {
                this.CheckUserState();
            }

            return (Itsv.Model.User)Session["CurrentUser"];
        }
        set
        {
            Session["CurrentUser"] = value;

        }
    }
    /// <summary>
    /// 验证用户身份
    /// </summary>
    protected void CheckUserState()
    {
        if (Session["CurrentUser"] == null)
        {
            string url = Request.RawUrl;
            Response.Write("<script>parent.location.href=('../ulogin.aspx?reload=1')</script>");

        }
    }
    protected string GetCurrentUserDepartmentCode()
    {
        if (this.CurrentUser == null)
            return "";
        return GetCurrentUserDepartmentCode(this.GetCurrentUserDepartmentCode(this.CurrentUser.departmentcode));

    }
    public string GetCurrentUserDepartmentCode(string departmentcode)
    {
        string[] ss = departmentcode.Split('|');
        if (ss.Length > 1)
            return ss[1];
        return ss[0];
    }
    #endregion

    #region  绑定数据
    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="dt"></param>
    /// <param name="gv"></param>
    protected void BindGridView(DataSet ds, GridView gv, string key)
    {
        if (ds == null)
        {
            this.ShowMessage("数据访问失败");
            return;
        }
        this.BindGridView(ds.Tables[0], gv, key);
    }
    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="dt"></param>
    /// <param name="gv"></param>
    protected void BindGridView(DataTable dt, GridView gv, string key)
    {
        string[] keys ={ key };
        this.BindGridView(dt, gv, keys);
    }
    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="dt"></param>
    /// <param name="gv"></param>
    protected void BindGridView(DataTable dt, GridView gv, string[] keys)
    {
        if (dt == null)
        {
            this.ShowMessage("数据访问失败");
            return;
        }

        if (dt.Rows.Count == 0)
        {

            //dt.Rows.Add(dt.NewRow());

            gv.DataSource = dt;

            gv.DataBind();

            //int columnCount = gv.Columns.Count;
            //for (int i = 0; i < gv.Rows[0].Cells.Count; i++)
            //{
            //    gv.Rows[0].Cells[i].Text = "";
            //}

            //gv.Rows[0].Cells.Add(new TableCell());

            //gv.Rows[0].Cells[0].ColumnSpan = columnCount;

            //gv.Rows[0].Cells[0].Text = "没有记录";

            //gv.Rows[0].Cells[0].Style.Add("text-align", "left");
        }

        else
        {

            gv.DataKeyNames = keys;
            gv.DataSource = dt;
            gv.DataBind();
        }

    }
    protected DataTable GetDictionary(string dictcode)
    {
        Itsv.BLL.SystemManage.dictionaryBLL dictbll = new Itsv.BLL.SystemManage.dictionaryBLL();
        DataSet ds = dictbll.GetChildList(dictcode, ref msg);
        if (ds == null)
        {
            this.ShowMessage(msg);
            return null;
        }
        return ds.Tables[0];
    }

    protected Itsv.Model.dictionary GetDictionaryMonel(string dictCode)
    {
        Itsv.BLL.SystemManage.dictionaryBLL dictBll = new Itsv.BLL.SystemManage.dictionaryBLL();

        Itsv.Model.dictionary dict = dictBll.GetModel(dictCode, ref msg);

        if (dict == null)
        {
            this.ShowMessage(msg);
            return null;
        }
        return dict;
    }

    /// <summary>
    /// 根据字典表里的父节点名称和字节点名称查找字节点的dict_code
    /// </summary>
    /// <param name="parentName">父节点名称如:会员状态</param>
    /// <param name="name">字节点名称如:待审核</param>
    /// <returns>string型 dict_code</returns>
    protected string GetDictCodeBaseName(string parentName, string name)
    {
        Itsv.BLL.SystemManage.dictionaryBLL dictBll = new Itsv.BLL.SystemManage.dictionaryBLL();
        DataSet ds = null;
        if (parentName != null && parentName != "")
        {
            ds = dictBll.GetList("(parent_id = (SELECT dict_id FROM dictionary WHERE dict_name = '" + parentName + "')) AND (dict_name = '" + name + "')", ref msg);
        }
        else
        {
            ds = dictBll.GetList("(parent_id = 0) AND (dict_name = '" + name + "')", ref msg);
        }

        if (ds == null)
        {
            ShowMessage(msg);
            return null;
        }
        if (ds.Tables[0].Rows.Count > 0)
        {
            return ds.Tables[0].Rows[0]["dict_code"].ToString();
        }

        return null;
    }

    protected void BindDictionary(DropDownList ddl, string dictcode)
    {
        ddl.DataTextField = "dict_name";
        ddl.DataValueField = "dict_code";
        DataTable dt = this.GetDictionary(dictcode);
        if (dt != null)
        {
            ddl.DataSource = dt;
            ddl.DataBind();
        }
    }
    protected void BindDictionary(DropDownList ddl, string dictcode, bool appendnull)
    {
        if (appendnull)
        {
            DataTable dt = this.GetDictionary(dictcode);
            System.Web.UI.WebControls.ListItem LItem = new ListItem();
            LItem.Value = "";
            LItem.Text = "请选择...";
            ddl.Items.Add(LItem);
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    LItem = new ListItem();
                    LItem.Value = dt.Rows[i].ItemArray[2].ToString();
                    LItem.Text = dt.Rows[i].ItemArray[1].ToString();
                    ddl.Items.Add(LItem);
                }
            }
            ddl.SelectedIndex = 0;
            dt = null;
        }
        else
        {
            BindDictionary(ddl, dictcode);
        }
    }
    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="ckb"></param>
    /// <param name="dictcode"></param>
    protected void BindDictionary(CheckBoxList ckb, string dictcode)
    {
        DataTable dt = this.GetDictionary(dictcode);
        System.Web.UI.WebControls.ListItem LItem = new ListItem();
        if (dt != null)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                LItem = new ListItem();
                LItem.Value = dt.Rows[i].ItemArray[2].ToString();
                LItem.Text = dt.Rows[i].ItemArray[1].ToString();
                ckb.Items.Add(LItem);
            }
        }
    }
    #endregion

    #region 公用的方法
    /// <summary>
    /// 编码
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public string GetEncode(object str)
    {
        return str.ToString();
        // return Server.UrlEncode(str.ToString());
    }
    #endregion

    #region  构造Xtree
    protected StringBuilder DrawNodes(StringBuilder sb, DataView pdv, DataTable dt, string parentfield, string showfield, string[] valuefield, string parentnode, bool allowparentselect)
    {
        for (int i = 0; i < pdv.Count; i++)
        {
            String strAction;
            DataView dv = dt.Copy().DefaultView;
            dv.RowFilter = parentfield + " = '" + pdv[i][valuefield[0]].ToString() + "'";
            string sValue = "";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -