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

📄 coneditctrl.ascx.cs

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

public partial class Contact_Ctrls_ConEditCtrl : PageBaseUserCtrl
{
    WYX.Dataport.Dataport dp = new WYX.Dataport.Dataport();
    long code = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        btnCancel.Attributes.Add("onclick", "window.close();");
        Response.CacheControl = "no-cache";
        Response.AddHeader("Pragma", "no-cache");
        Response.Expires = 0;

        if (Request.QueryString["code"] != null && IsNuberic(Request.QueryString["code"]))
        {
            code = Convert.ToInt64(Request.QueryString["code"]);
        }
        else
        {
            ShowAndClose("您输入的参数不正确,请您重试!!", "");
            return;
        }
        if (!Page.IsPostBack)
        {
            SetData();
        }
    }

    #region 初始化页面
    /// <summary>
    /// 初始化页面
    /// </summary>
    private void SetData()
    {
        BindddlConType();
        BindConPriod();
        BindAndItem();
        BindCustomer();
        BindPerson();

        string sql = @"SELECT ( select name from ITSV_CustomerManager where code = customer_id) as customerName,customer_id, customer_person_id, title, 
                    type,period, project, money, contract_person, 
                    contract_time, content, note, document
                    FROM ITSV_CustomerContract";
        sql += "    WHERE (code = " + code + ")";

        DataRow ConItem = null;
        try { ConItem = dp.GetRowResult(sql); }
        catch { ConItem = null; }

        if (ConItem == null)
        {
            ShowAndClose("您输入的参数不正确,请您重试!!", "");
            return;
        }
        else
        {
            ddlAndItem.SelectedValue = ConItem["project"].ToString();
            txtConMoney.Text = ConItem["money"].ToString();
            ddlConPriod.SelectedValue = ConItem["period"].ToString();
            txtContent.Value = ConItem["content"].ToString();
            ddlConType.SelectedValue = ConItem["type"].ToString();
            ddlCustomNo.SelectedValue = ConItem["customer_id"].ToString();

            ddlPerson.SelectedValue = ConItem["contract_person"].ToString();
            
            if(ddlCustomNo.SelectedItem != null && ddlCustomNo.SelectedIndex > 0)
                BindCustPerson(ddlCustomNo.SelectedValue);
            ddlCustPerson.SelectedValue = ConItem["customer_person_id"].ToString();
            
            txtDateTime.Text = ConItem["contract_time"].ToString();
            txtNote.Value = ConItem["note"].ToString();
            txtTitle.Text = ConItem["title"].ToString();
            lblAcc.Text = ConItem["document"].ToString();
        }

        BindDtlAccList(lblAcc.Text);
    }

    /// <summary>
    /// 邦定DataList
    /// </summary>
    /// <param name="sourceStr"></param>
    private void BindDtlAccList(string sourceStr)
    {
        DataTable dt = ItemSplit(sourceStr);
        if (dt != null)
        {
            this.dtlAccList.DataSource = dt;
            this.dtlAccList.DataBind();
        }
    }

    /// <summary>
    /// 分解附件到DataTable
    /// </summary>
    /// <param name="document">附件的字符串</param>
    /// <returns></returns>
    private DataTable ItemSplit(string document)
    {
        if (document == null)
        {
            return null;
        }

        string[] documentItems = document.Split('|');
        if (documentItems.Length == 0)
        {
            return null;
        }

        DataTable accTable = new DataTable();
        accTable.Columns.Add("documentName");
        accTable.Columns.Add("documentPath");

        foreach (string str in documentItems)
        {
            if (str != null && str.Trim().Length > 0)
            {
                int charIndex = str.IndexOf(']');
                if (charIndex < 0)
                {
                    continue;
                }

                DataRow row = accTable.NewRow();
                string documentName = str.Substring(0, charIndex + 1);
                string documentPath = str.Substring(charIndex + 1);
                row[0] = documentName;
                row[1] = documentPath;
                accTable.Rows.Add(row);
            }
        }

        return accTable;
    }
    #endregion

    #region 读取字典表

    /// <summary>
    /// 邦定联络方式
    /// </summary>
    private void BindddlConType()
    {
        this.BindDictionary(ddlConType, "101", true);
    }

    /// <summary>
    /// 邦定联络阶段
    /// </summary>
    private void BindConPriod()
    {
        this.BindDictionary(ddlConPriod, "102", true);
    }

    /// <summary>
    /// 邦定相关项目
    /// </summary>
    private void BindAndItem()
    {
        string sql = "SELECT * FROM dictionary where parent_id = 103 order by dict_name";
        DataTable dt = null;
        try
        {
            dt = dp.GetTableResult(sql);
        }
        catch
        {
            dt = null;
        }
        if (dt == null || dt.Rows.Count == 0)
        {
            this.ddlAndItem.Items.Insert(0, new ListItem("请选择..."));
            return;
        }

        this.ddlAndItem.DataSource = dt;
        this.ddlAndItem.DataTextField = "dict_name";
        this.ddlAndItem.DataValueField = "dict_code";
        this.ddlAndItem.DataBind();
        this.ddlAndItem.Items.Insert(0, new ListItem("请选择..."));
        //this.BindDictionary(ddlAndItem, "103", true);
    }

    /// <summary>
    /// 邦定客户
    /// </summary>
    private void BindCustomer()
    {
        string sql = "SELECT code, name FROM ITSV_CustomerManager where is_delete = 0 and is_use = 0 order by name";
        DataTable dt = null;
        try
        {
            dt = dp.GetTableResult(sql);
        }
        catch
        {
            dt = null;
        }
        if (dt == null || dt.Rows.Count == 0)
        {
            this.ddlCustomNo.Items.Insert(0, new ListItem("请选择..."));
            return;
        }

        this.ddlCustomNo.DataSource = dt;
        this.ddlCustomNo.DataTextField = "name";
        this.ddlCustomNo.DataValueField = "code";
        this.ddlCustomNo.DataBind();
        this.ddlCustomNo.Items.Insert(0, new ListItem("请选择..."));
    }

    /// <summary>
    /// 邦定我方人员
    /// </summary>
    private void BindPerson()
    {
        string sql = "SELECT account, user_id, name FROM Users WHERE (inuse = 1)";
        DataTable dt = null;
        try
        {
            dt = dp.GetTableResult(sql);
        }
        catch
        {
            dt = null;
        }
        if (dt == null || dt.Rows.Count == 0)
        {
            this.ddlPerson.Items.Insert(0, new ListItem("请选择..."));
            return;
        }

        this.ddlPerson.DataSource = dt;
        this.ddlPerson.DataTextField = "name";
        this.ddlPerson.DataValueField = "user_id";
        this.ddlPerson.DataBind();
        this.ddlPerson.Items.Insert(0, new ListItem("请选择..."));
    }

    /// <summary>
    /// 设置客户联系人

    /// </summary>
    /// <param name="custom_id"></param>
    private void BindCustPerson(string custom_id)
    {
        string sql = @"select code,first_name from iTSV_customer_person where customer_id = " + custom_id;
        DataTable dt = null;
        try
        {
            dt = dp.GetTableResult(sql);
        }
        catch
        {
            dt = null;
        }
        if (dt == null || dt.Rows.Count == 0)
        {
            this.ddlCustPerson.Items.Clear();
            this.ddlCustPerson.Items.Insert(0, new ListItem("请选择..."));
            return;
        }

        this.ddlCustPerson.DataSource = dt;
        this.ddlCustPerson.DataTextField = "first_name";
        this.ddlCustPerson.DataValueField = "code";
        this.ddlCustPerson.DataBind();
        this.ddlCustPerson.Items.Insert(0, new ListItem("请选择..."));
    }
    #endregion

⌨️ 快捷键说明

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