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

📄 saleaddctrl.ascx.cs

📁 CRM管理系统 CRM管理系统
💻 CS
字号:
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_SaleAddCtrl : PageBaseUserCtrl
{
    WYX.Dataport.Dataport dp = new WYX.Dataport.Dataport();
    long conId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.CacheControl = "no-cache";
        Response.AddHeader("Pragma", "no-cache");
        Response.Expires = 0;
        btnCancel.Attributes.Add("onclick", "window.close();");

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

        if (!Page.IsPostBack)
        {
            BindWin();

            SetData();
        }
    }

    #region 邦定字典元素
    /// <summary>
    /// 邦定赢面
    /// </summary>
    private void BindWin()
    {
        this.BindDictionary(ddlWin, "113", true);
    }
    #endregion

    #region 初始化页面

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

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

        if (ConItem == null)
        {
            ShowAndClose("您输入的参数不正确,请您重试!!", "");
            return;
        }
        else
        {
            this.lblConId.Text = ConItem["customer_id"].ToString();
            this.lblConTitle.Text = ConItem["title"].ToString();
            this.lblCustomId.Text = ConItem["customerName"].ToString();

            this.lblCustomPerson.Text = GetCustomerPerson(ConItem["customer_person_id"]);

            lblPreject.Text = GetDictName(ConItem["project"]);
            lblConTitle.Text = ConItem["title"].ToString();
            lblConTime.Text = string.Format("{0:yyyy-MM-dd}", ConItem["contract_time"]);
            lblPeriod.Text = GetDictName(ConItem["period"]);
            lblPerson.Text = ConItem["userName"].ToString();

        }

        sql = @"SELECT * FROM ITSV_sale WHERE (contract_id = " + conId + ")";
        DataRow SaleItem = null;
        try { SaleItem = dp.GetRowResult(sql); }
        catch { SaleItem = null; }
        if (SaleItem != null && SaleItem["code"].ToString() != string.Empty)
        {
            lblCode.Text = SaleItem["code"].ToString();
            txtContent.Text = SaleItem["content"].ToString();
            txtDateTime1.Text = string.Format("{0:yyyy-MM-dd}", SaleItem["date_time_1"]);
            txtDateTime2.Text = string.Format("{0:yyyy-MM-dd}", SaleItem["date_time_2"]);
            txtDateTime3.Text = string.Format("{0:yyyy-MM-dd}", SaleItem["date_time_3"]);
            txtSaleMoney.Text = SaleItem["total_sale_money"].ToString();
            txtSaleMoneyPower.Text = SaleItem["other_sale_money"].ToString();
            ddlWin.SelectedValue = SaleItem["win"].ToString();
        }
    }
    #endregion

    #region 字典数据显示
    /// <summary>
    /// 字典数据显示
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public string GetDictName(object obj)
    {
        if (obj == null)
            return null;

        string str = obj.ToString();
        Itsv.Model.dictionary dict = this.GetDictionaryMonel(obj.ToString());
        if (dict == null)
        {
            return obj.ToString();
        }
        return dict.dict_name;
    }
    /// <summary>
    /// 读取客户人员名称
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public string GetCustomerPerson(object obj)
    {
        if (obj == null || !IsNuberic(obj.ToString()))
            return null;

        long CustomerPersonId = Convert.ToInt64(obj.ToString());
        string sql = "SELECT first_name FROM ITSV_customer_person where code = " + CustomerPersonId;
        return dp.GetRowResultID(sql);
    }
    #endregion

    #region 数据验证
    private bool CheckData()
    {
        msg = "";
        if (ddlWin.SelectedItem == null || ddlWin.SelectedIndex == 0)
            msg += "请选择赢面\\r\\n";
        if (txtSaleMoney.Text.Trim().Length == 0)
            msg += "销售总金额不能为空\\r\\n";
        else if (!IsNuberic(txtSaleMoney.Text.Trim()))
            msg += "销售总金额必须为数字\\r\\n";
        else if (Convert.ToDouble(txtSaleMoney.Text.Trim()) < 0)
            msg += "销售总金额必须为大于零的数字\\r\\n";

        if (txtSaleMoneyPower.Text.Trim().Length == 0)
            msg += "加权销售总金额不能为空\\r\\n";
        else if (!IsNuberic(txtSaleMoneyPower.Text.Trim()))
            msg += "加权销售总金额必须为数字\\r\\n";
        else if (Convert.ToDouble(txtSaleMoneyPower.Text.Trim()) < 0)
            msg += "加权销售总金额必须为大于零的数字\\r\\n";

        if (txtContent.Text.Trim().Length == 0)
            msg += "项目进展不能为空\\r\\n";

        if (txtDateTime1.Text.Trim().Length > 0 && !IsDate(txtDateTime1.Text.Trim()))
            msg += "预计签约日期格式输入不正确\\r\\n";
        if (txtDateTime2.Text.Trim().Length > 0 && !IsDate(txtDateTime2.Text.Trim()))
            msg += "预计收款日期格式输入不正确\\r\\n";
        if (txtDateTime3.Text.Trim().Length > 0 && !IsDate(txtDateTime3.Text.Trim()))
            msg += "预计进场日期格式输入不正确\\r\\n";

        if (msg == "")
            return true;

        return false;
    }
    #endregion

    #region 提交数据
    /// <summary>
    /// 提交数据
    /// </summary>
    /// <returns></returns>
    private bool SaveData()
    {
        string win = ddlWin.SelectedValue;
        string winStr = ddlWin.SelectedItem.Text;
        double winNum = 0;
        int charIndex = winStr.IndexOf('%');
        if (charIndex >= 0)
        {
            winNum = Convert.ToDouble(winStr.Substring(0, charIndex)) / 100;
        }
        string content = txtContent.Text.Trim().Replace("'", "\"");
        double money = Convert.ToDouble(txtSaleMoney.Text.Trim());
        double otherMoney = Convert.ToDouble(txtSaleMoneyPower.Text.Trim());
        string time1 = txtDateTime1.Text.Trim().Length == 0 ? "null" : "'" + txtDateTime1.Text.Trim() + "'";
        string time2 = txtDateTime2.Text.Trim().Length == 0 ? "null" : "'" + txtDateTime2.Text.Trim() + "'";
        string time3 = txtDateTime3.Text.Trim().Length == 0 ? "null" : "'" + txtDateTime3.Text.Trim() + "'";

        string sql = @"INSERT INTO ITSV_sale
                      (contract_id, win, win_data, content, total_sale_money, other_sale_money, 
                      date_time_1, date_time_2, date_time_3)";
        sql += " VALUES ('" + conId + "','" + win + "','" + winNum + "','" + content + "','" + money + "','" + otherMoney + "'," + time1 + "," + time2 + "," + time3 + ")";

        if (lblCode.Text != "0")
        {
            sql = "UPDATE ITSV_sale SET";
            sql += " win ='" + win + "', win_data ='" + winNum + "', content ='" + content + "', total_sale_money ='" + money + "', ";
            sql += " other_sale_money ='" + otherMoney + "', date_time_1 =" + time1 + ",date_time_2 =" + time2 + ", date_time_3 =" + time3 + "";
            sql += " where contract_id = " + conId;
        }

        return dp.ExeSql(sql);
    }
    #endregion

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!CheckData())
        {
            ShowMessage(msg);
            return;
        }
        if (!SaveData())
        {
            ShowMessage("数据提交失败,请您重试!!");
        }
        else
        {
            if (Request.QueryString["reload"] == "1")
            {
                ShowAndClose("数据提交成功!!", "window.dialogArguments.location='saleIndex.aspx';");
            }
            else
            {
                ShowAndClose("数据提交成功!!", "");
            }
            this.WriteUserAction("提交销售预测\"" + lblPreject.Text + "\"的信息");
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("SaleIndex.aspx");
    }
}

⌨️ 快捷键说明

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