Beispiel #1
0
    protected void bt_Delete_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["VolumeID"] != 0)
        {
            SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Delete();

            MessageBox.ShowAndRedirect(this, "数据删除成功!", "SalesVolumeList.aspx?SellOutClientID=" + bll.Model.Supplier.ToString() +
                                       "&SellInClientID=" + bll.Model.Client.ToString() + "&Type=" + ViewState["Type"].ToString());
        }
    }
Beispiel #2
0
    protected void ddl_Flag_SelectedIndexChanged(object sender, EventArgs e)
    {
        CM_Client _r = new CM_ClientBLL((int)ViewState["ClientID"]).Model;

        IList <SVM_SalesVolume> svmlists = new List <SVM_SalesVolume>();
        string conditon = "";

        if (!(bool)ViewState["IsCXP"])
        {
            switch (ViewState["Type"].ToString())
            {
            case "1":
            case "2":
                conditon = "Client=" + _r.ID.ToString()
                           + " AND Type IN(1,2) AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                           + " AND Flag=" + ddl_Flag.SelectedValue;

                break;

            case "3":
                conditon = "Supplier=" + _r.ID.ToString()
                           + " AND Type=3 AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                           + " AND Flag=" + ddl_Flag.SelectedValue + " AND ISNULL(Promotor,0)=" + ddl_Promotor.SelectedValue;

                break;
            }
        }
        else //判断是否有过门店赠品进货
        {
            switch (ViewState["Type"].ToString())
            {
            case "1":
            case "2":
                conditon = "Client=" + _r.ID.ToString()
                           + " AND Type IN(1,2) AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                           + " AND Flag=" + ddl_Flag.SelectedValue;

                break;

            case "3":
                conditon = "Client=" + _r.ID.ToString()
                           + " AND Type=3 AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                           + " AND Flag=" + ddl_Flag.SelectedValue;

                break;
            }
        }
        svmlists = SVM_SalesVolumeBLL.GetModelList(conditon);
        if (svmlists.Count > 0)
        {
            bt_Save.OnClientClick   = "return confirm('系统中已存在其他对应条件的销量或进货,将会替换原数据明细!是否确定暂存?')";
            bt_Submit.OnClientClick = "return confirm('系统中已存在其他对应条件的销量或进货,将会替换原数据明细!是否确定暂存?')";
        }
    }
Beispiel #3
0
    protected void bt_Delete_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["VolumeID"] != 0)
        {
            SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Delete();

            MessageBox.ShowAndRedirect(this, "数据删除成功!", "TransferVolumeList.aspx?TransferOutClientID=" +
                                       select_Supplier.SelectValue + "&TransferInClientID=" + select_Client.SelectValue);
        }
    }
    protected void bt_Delete_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["VolumeID"] != 0)
        {
            SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Delete();

            MessageBox.ShowAndRedirect(this, "数据删除成功!", "TransferVolumeList.aspx?TransferOutClientID=" +
                select_Supplier.SelectValue + "&TransferInClientID=" + select_Client.SelectValue);
        }
    }
Beispiel #5
0
    protected void gv_List_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            #region 显示销量库存录入情况
            int clientid = (int)gv_List.DataKeys[e.Row.RowIndex]["CM_Client_ID"];
            int month    = AC_AccountMonthBLL.GetMonthByDate(DateTime.Today.AddDays(0 - ConfigHelper.GetConfigInt("JXCDelayDays")));

            DataTable dt = SVM_SalesVolumeBLL.GetCountByClient(month, clientid);
            if (dt != null && dt.Rows.Count == 3)
            {
                foreach (DataRow row in dt.Rows)
                {
                    HyperLink link = null;
                    switch (row["Title"].ToString())
                    {
                    case "SaleIn":
                        link = (HyperLink)(e.Row.Cells[0].Controls[0]);
                        break;

                    case "SaleOut":
                        link = (HyperLink)(e.Row.Cells[1].Controls[0]);
                        break;

                    case "Inventory":
                        link = (HyperLink)(e.Row.Cells[2].Controls[0]);
                        break;
                    }
                    if (link != null)
                    {
                        link.Text += "<br/>";
                        if (row["ApprovedCount"] != DBNull.Value && (int)row["ApprovedCount"] > 0)
                        {
                            link.ToolTip += " 已审核:" + row["ApprovedCount"].ToString();
                            link.Text    += "-<font color=red>" + row["ApprovedCount"].ToString() + "</font>";
                        }
                        if (row["SubmitedCount"] != DBNull.Value && (int)row["SubmitedCount"] > 0)
                        {
                            link.ToolTip += " 已提交:" + row["SubmitedCount"].ToString();
                            link.Text    += "-<font color=blue>" + row["SubmitedCount"].ToString() + "</font>";
                        }
                        if (row["InputedCount"] != DBNull.Value && (int)row["InputedCount"] > 0)
                        {
                            link.ToolTip += " 未提交:" + row["InputedCount"].ToString();
                            link.Text    += "-<font color=black>" + row["InputedCount"].ToString() + "</font>";
                        }
                    }
                }
            }
            #endregion
        }
    }
    protected void bt_Approve_Click(object sender, EventArgs e)
    {
        if (ViewState["VolumeID"] != null)
        {
            bt_Save_Click(null, null);

            SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Approve((int)Session["UserID"]);

            MessageBox.ShowAndRedirect(this, "数据审核成功!", "TransferVolumeList.aspx?TransferOutClientID=" +
                select_Supplier.SelectValue + "&TransferInClientID=" + select_Client.SelectValue);
        }
    }
Beispiel #7
0
    protected void bt_Approve_Click(object sender, EventArgs e)
    {
        if (ViewState["VolumeID"] != null)
        {
            bt_Save_Click(null, null);

            SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Approve((int)Session["UserID"]);

            MessageBox.ShowAndRedirect(this, "数据审核成功!", "TransferVolumeList.aspx?TransferOutClientID=" +
                                       select_Supplier.SelectValue + "&TransferInClientID=" + select_Client.SelectValue);
        }
    }
Beispiel #8
0
    protected void bt_Approve_Click(object sender, EventArgs e)
    {
        if (ViewState["VolumeID"] != null)
        {
            bt_Submit_Click(null, null);

            SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Approve((int)Session["UserID"]);

            MessageBox.ShowAndRedirect(this, "数据审核成功!", "SalesVolumeList.aspx?SellOutClientID=" + bll.Model.Supplier.ToString() +
                                       "&SellInClientID=" + bll.Model.Client.ToString() + "&Type=" + ViewState["Type"].ToString());
        }
    }
    protected void bt_Approve_Click(object sender, EventArgs e)
    {
        if (ViewState["VolumeID"] != null)
        {
            bt_Submit_Click(null, null);

            SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Approve((int)Session["UserID"]);

            MessageBox.ShowAndRedirect(this, "数据审核成功!", "SalesVolumeList.aspx?SellOutClientID=" + bll.Model.Supplier.ToString() +
                "&SellInClientID=" + bll.Model.Client.ToString() + "&Type=" + ViewState["Type"].ToString());
        }
    }
Beispiel #10
0
 protected void bt_Submit_Click(object sender, EventArgs e)
 {
     bt_Save_Click(null, null);
     if ((int)ViewState["VolumeID"] > 0)
     {
         SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
         bll.Model["SubmitFlag"] = "1";
         bll.Update();
         if (sender != null)
         {
             MessageBox.ShowAndRedirect(this, "数据提交成功!", "SalesVolumeList.aspx?SellOutClientID=" + bll.Model.Supplier.ToString() +
                                        "&SellInClientID=" + bll.Model.Client.ToString() + "&Type=" + ViewState["Type"].ToString());
         }
     }
 }
    protected void bt_BathApprove_Click(object sender, EventArgs e)
    {
        string ids = "";

        foreach (GridViewRow gr in gv_List.Rows)
        {
            if (((CheckBox)gr.FindControl("chk_ID")).Checked == true)
            {
                ids += gv_List.DataKeys[gr.RowIndex]["SVM_SalesVolume_ID"].ToString() + ",";
            }
        }

        SVM_SalesVolumeBLL.BatApprove(ids, (int)Session["UserID"]);
        BindGrid();
    }
Beispiel #12
0
 protected void bt_Search_Click(object sender, EventArgs e)
 {
     if ((int)ViewState["VolumeID"] == 0)
     {
         if (SVM_SalesVolumeBLL.CheckSalesVolume((int)ViewState["ClientID"], DateTime.Parse(tbx_VolumeDate.Text),
                                                 (int)ViewState["Type"], int.Parse(ddl_Flag.SelectedValue)) > 0)
         {
             MessageBox.Show(this, "该客户在当前日期:" + tbx_VolumeDate.Text + " 已经填报过数据,请检查以免重复录入!");
         }
     }
     if (bt_Save.Visible)
     {
         SaveMyViewState();
     }
     gv_List.PageIndex = 0;
     BindGrid();
 }
    protected void bt_Submit_Click(object sender, EventArgs e)
    {
        int organizecity = int.Parse(tr_OrganizeCity.SelectValue);
        int month        = int.Parse(ddl_Month.SelectedValue);
        int level        = int.Parse(ddl_Level.SelectedValue);
        int state        = int.Parse(ddl_State.SelectedValue);
        int flag         = int.Parse(ddl_Flag.SelectedValue);
        int result       = SVM_SalesVolumeBLL.SubmitByStaff(organizecity, (int)Session["UserID"], month, (int)ViewState["ClientType"], flag, (int)ViewState["Type"]);

        if (result < 0)
        {
            MessageBox.Show(this, "您还有" + (-result).ToString() + "个客户的销量没有填写,无法提交! 填报进度请参照桌面的【填报进度表】");
        }
        else
        {
            MessageBox.Show(this, "共成功提交" + result.ToString() + "条销量!");
            BindGrid();
        }
    }
    protected void bt_Approve_Click(object sender, EventArgs e)
    {
        int organizecity = int.Parse(tr_OrganizeCity.SelectValue);
        int month        = int.Parse(ddl_Month.SelectedValue);
        int level        = int.Parse(ddl_Level.SelectedValue);
        int state        = int.Parse(ddl_State.SelectedValue);
        int flag         = int.Parse(ddl_Flag.SelectedValue);
        int result       = SVM_SalesVolumeBLL.ApproveByStaff(organizecity, (int)Session["UserID"], month, (int)ViewState["ClientType"], flag, (int)ViewState["Type"]);

        if (result == -1)
        {
            MessageBox.Show(this, "请确认客户的进或销都已提交!");
        }
        else
        {
            MessageBox.Show(this, "审核成功!");
        }
        BindGrid();
    }
Beispiel #15
0
    protected void bt_Search_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["VolumeID"] == 0)
        {
            int transferinclient = 0;

            if (int.TryParse(select_Client.SelectValue, out transferinclient) &&
                SVM_SalesVolumeBLL.CheckSalesVolume(transferinclient, DateTime.Parse(tbx_VolumeDate.Text), 6, 1) > 0)
            {
                MessageBox.Show(this, "该客户在当前日期:" + tbx_VolumeDate.Text + " 已经填报过数据,请检查以免重复录入!");
            }
        }
        if (bt_Save.Visible)
        {
            SaveMyViewState();
        }
        gv_List.PageIndex = 0;
        BindGrid();
    }
Beispiel #16
0
    private void BindData()
    {
        SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;

        ViewState["Type"]  = sv.Type;
        ViewState["IsCXP"] = (sv.Flag > 10);

        BindClientInfo(sv.Supplier, sv.Client);
        select_Client.Enabled   = false;
        select_Supplier.Enabled = false;

        tbx_VolumeDate.Text            = sv.SalesDate.ToString("yyyy-MM-dd");
        ddl_AccountMonth.SelectedValue = sv.AccountMonth.ToString();
        tbx_Remark.Text = sv.Remark;

        DataTable dt = SVM_SalesVolumeBLL.InitProductList((int)ViewState["VolumeID"], sv.Supplier,
                                                          (int)ViewState["Type"], sv.AccountMonth, false); //初始化产品列表

        DataColumn[] keys = { dt.Columns["Product"] };
        dt.PrimaryKey         = keys;
        ViewState["DTDetail"] = dt;

        BindGrid();

        if (sv.ApproveFlag == 1)
        {
            #region 已审核,不可再修改
            tbx_VolumeDate.Enabled   = false;
            ddl_AccountMonth.Enabled = false;
            tbx_Remark.Enabled       = false;
            gv_List.SetControlsEnable(false);

            bt_Save.Visible    = false;
            bt_Delete.Visible  = false;
            bt_Approve.Visible = false;
            #endregion
        }
    }
Beispiel #17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            #region 获取页面参数
            ViewState["VolumeID"] = Request.QueryString["VolumeID"] == null ? 0 : int.Parse(Request.QueryString["VolumeID"]);
            ViewState["IsCXP"]    = Request.QueryString["IsCXP"] == null ? false : int.Parse(Request.QueryString["IsCXP"]) != 0; //是否是赠品销量录入 0:成品 1:赠品

            BindDropDown();

            if ((int)ViewState["VolumeID"] == 0)
            {
                ViewState["TransferOutClientID"] = Request.QueryString["TransferOutClientID"] == null ? 0 : int.Parse(Request.QueryString["TransferOutClientID"]);
                ViewState["TransferInClientID"]  = Request.QueryString["TransferInClientID"] == null ? 0 : int.Parse(Request.QueryString["TransferInClientID"]);

                ViewState["Type"] = 6;        //销量类型  6:经销商成品调拨单

                if ((int)ViewState["TransferOutClientID"] == 0)
                {
                    MessageBox.ShowAndRedirect(this, "对不起,必须选择要调出货的经销商!", "TransferVolumeList.aspx");
                    return;
                }
            }
            #endregion

            select_Supplier.PageUrl = "../CM/PopSearch/Search_SelectClient.aspx?ClientType=2&ExtCondition=\"MCS_SYS.dbo.UF_Spilt(CM_Client.ExtPropertys,~|~,7)=1\"";
            select_Client.PageUrl   = "../CM/PopSearch/Search_SelectClient.aspx?ClientType=2&ExtCondition=\"MCS_SYS.dbo.UF_Spilt(CM_Client.ExtPropertys,~|~,7)=1\"";

            #region 调入客户的管理片区为当前人的上一级,以便向管辖外的区域调货
            try
            {
                int organizecity = new Org_StaffBLL((int)Session["UserID"]).Model.OrganizeCity;
                if (organizecity > 1)
                {
                    int superid = new Addr_OrganizeCityBLL(organizecity).Model.SuperID;

                    select_Client.PageUrl += "&OrganizeCity=" + superid.ToString();
                }
            }
            catch { }
            #endregion

            if ((int)ViewState["VolumeID"] == 0)
            {
                tbx_VolumeDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
                BindClientInfo((int)ViewState["TransferOutClientID"], (int)ViewState["TransferInClientID"]);

                int month = int.Parse(ddl_AccountMonth.SelectedValue);

                DataTable    dt   = SVM_SalesVolumeBLL.InitProductList((int)ViewState["VolumeID"], (int)ViewState["TransferOutClientID"], (int)ViewState["Type"], month, (bool)ViewState["IsCXP"]); //初始化产品列表
                DataColumn[] keys = { dt.Columns["Product"] };
                dt.PrimaryKey         = keys;
                ViewState["DTDetail"] = dt;

                bt_Delete.Visible  = false;
                bt_Approve.Visible = false;
            }
            else
            {
                cb_OnlyDisplayUnZero.Checked = true;
                BindData();
            }

            BindDropDown_ByIsCXP();

            //Header.Attributes["WebPageSubCode"] = "Type=" + ViewState["Type"].ToString();
        }
    }
Beispiel #18
0
    private void BindData()
    {
        SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;

        ViewState["Type"] = sv.Type;

        ViewState["ClientID"]          = sv.Type == 3 ? sv.Supplier : sv.Client;
        tbx_VolumeDate.Text            = sv.SalesDate.ToString("yyyy-MM-dd");
        ddl_AccountMonth.SelectedValue = sv.AccountMonth.ToString();
        ddl_Flag.SelectedValue         = sv.Flag.ToString();
        ddl_Flag.Enabled   = false;
        tbx_sheetCode.Text = sv.SheetCode;
        tbx_Remark.Text    = sv.Remark;
        ViewState["IsCXP"] = (sv.Flag > 10);
        if (!(bool)ViewState["IsCXP"])
        {
            tb_AddProduct.Visible = false;
        }
        DataTable dt = SVM_SalesVolumeBLL.InitProductList((int)ViewState["VolumeID"], (int)ViewState["ClientID"],
                                                          (int)ViewState["Type"], sv.AccountMonth, (bool)ViewState["IsCXP"]); //初始化产品列表

        DataColumn[] keys = { dt.Columns["Product"] };
        dt.PrimaryKey         = keys;
        ViewState["DTDetail"] = dt;
        BindClientInfo(sv.Client, sv.Supplier);

        if (sv.Promotor != 0)
        {
            if (ddl_Promotor.Items.FindByValue(sv.Promotor.ToString()) == null)
            {
                PM_Promotor pm = new PM_PromotorBLL(sv.Promotor).Model;
                if (pm != null)
                {
                    ddl_Promotor.Items.Add(new ListItem(pm.Name + "【已离开该门店】", sv.Promotor.ToString()));
                }
            }
            ddl_Promotor.SelectedValue = sv.Promotor.ToString();
        }
        if (sv["DataSource"] == "2")
        {
            gv_List.Columns[7].Visible = true;

            gv_List.Columns[8].HeaderText = "数量确认";
        }
        else if (sv["DataSource"] == "1")
        {
            gv_List.SetControlsEnable(false);
        }
        BindGrid();
        if (sv.InsertStaff != (int)Session["UserID"])
        {
            bt_Delete.Visible = false;
            bt_Save.Visible   = false;
            bt_Submit.Visible = false;
        }
        if (sv.ApproveFlag == 1)
        {
            #region 已审核,不可再修改
            tbx_VolumeDate.Enabled   = false;
            ddl_AccountMonth.Enabled = false;
            ddl_Flag.Enabled         = false;
            ddl_Promotor.Enabled     = false;
            tbx_Remark.Enabled       = false;
            tbx_sheetCode.Enabled    = false;
            gv_List.SetControlsEnable(false);

            bt_Save.Visible      = false;
            bt_Submit.Visible    = false;
            bt_Delete.Visible    = false;
            bt_Approve.Visible   = false;
            bt_ToForcast.Visible = false;

            tb_AddProduct.Visible  = false;
            bt_AddProduct.Visible  = false;
            select_Product.Visible = false;
            #endregion
        }
        else
        {
            bt_Delete.Visible = (int)Session["UserID"] == sv.InsertStaff;
            if (sv["SubmitFlag"] == "1")
            {
                bt_Submit.Visible = false;       //已提交
            }
            else
            {
                bt_Approve.Visible = false;     //未提交
            }
            //门店销售单,不允许即时提交及审核
            if ((int)ViewState["Type"] == 3)
            {
                bt_Submit.Visible  = false;
                bt_Approve.Visible = false;
            }

            if ((int)ViewState["Type"] != 3 || (bool)ViewState["IsCXP"])
            {
                bt_ToForcast.Visible = false;
            }
        }
        if (sv["DataSource"] == "1")
        {
            gv_List.SetControlsEnable(false);
        }
        if (sv["DataSource"] == "2")
        {
            cb_OnlyDisplayUnZero.Enabled = false;
        }
    }
    private void BindData()
    {
        SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;
        ViewState["Type"] = sv.Type;

        ViewState["ClientID"] = sv.Type == 3 ? sv.Supplier : sv.Client;
        tbx_VolumeDate.Text = sv.SalesDate.ToString("yyyy-MM-dd");
        ddl_AccountMonth.SelectedValue = sv.AccountMonth.ToString();
        ddl_Flag.SelectedValue = sv.Flag.ToString();
        ddl_Flag.Enabled = false;
        tbx_sheetCode.Text = sv.SheetCode;
        tbx_Remark.Text = sv.Remark;
        ViewState["IsCXP"] = (sv.Flag > 10);
        if (!(bool)ViewState["IsCXP"]) tb_AddProduct.Visible = false;
        DataTable dt = SVM_SalesVolumeBLL.InitProductList((int)ViewState["VolumeID"], (int)ViewState["ClientID"],
            (int)ViewState["Type"], sv.AccountMonth, (bool)ViewState["IsCXP"]); //初始化产品列表
        DataColumn[] keys = { dt.Columns["Product"] };
        dt.PrimaryKey = keys;
        ViewState["DTDetail"] = dt;
        BindClientInfo(sv.Client, sv.Supplier);

        if (sv.Promotor != 0)
        {
            if (ddl_Promotor.Items.FindByValue(sv.Promotor.ToString()) == null)
            {
                PM_Promotor pm = new PM_PromotorBLL(sv.Promotor).Model;
                if (pm != null)
                    ddl_Promotor.Items.Add(new ListItem(pm.Name + "【已离开该门店】", sv.Promotor.ToString()));
            }
            ddl_Promotor.SelectedValue = sv.Promotor.ToString();
        }
        if (sv["DataSource"] == "2")
        {
            gv_List.Columns[7].Visible = true;

            gv_List.Columns[8].HeaderText = "数量确认";
        }
        else if (sv["DataSource"] == "1")
            gv_List.SetControlsEnable(false);
        BindGrid();
        if (sv.InsertStaff != (int)Session["UserID"])
        {
            bt_Delete.Visible = false;
            bt_Save.Visible = false;
            bt_Submit.Visible = false;
        }
        if (sv.ApproveFlag == 1)
        {
            #region 已审核,不可再修改
            tbx_VolumeDate.Enabled = false;
            ddl_AccountMonth.Enabled = false;
            ddl_Flag.Enabled = false;
            ddl_Promotor.Enabled = false;
            tbx_Remark.Enabled = false;
            tbx_sheetCode.Enabled = false;
            gv_List.SetControlsEnable(false);

            bt_Save.Visible = false;
            bt_Submit.Visible = false;
            bt_Delete.Visible = false;
            bt_Approve.Visible = false;
            bt_ToForcast.Visible = false;

            tb_AddProduct.Visible = false;
            bt_AddProduct.Visible = false;
            select_Product.Visible = false;
            #endregion
        }
        else
        {
            bt_Delete.Visible = (int)Session["UserID"] == sv.InsertStaff;
            if (sv["SubmitFlag"] == "1")
                bt_Submit.Visible = false;       //已提交
            else
            {
                bt_Approve.Visible = false;     //未提交
            }
            //门店销售单,不允许即时提交及审核
            if ((int)ViewState["Type"] == 3)
            {
                bt_Submit.Visible = false;
                bt_Approve.Visible = false;
            }

            if ((int)ViewState["Type"] != 3 || (bool)ViewState["IsCXP"])
            {
                bt_ToForcast.Visible = false;
            }
        }
        if (sv["DataSource"] == "1")
            gv_List.SetControlsEnable(false);
        if (sv["DataSource"] == "2")
        {
            cb_OnlyDisplayUnZero.Enabled = false;
        }
    }
    private void BindData()
    {
        SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;
        ViewState["Type"] = sv.Type;
        ViewState["IsCXP"] = (sv.Flag > 10);

        BindClientInfo(sv.Supplier, sv.Client);
        select_Client.Enabled = false;
        select_Supplier.Enabled = false;

        tbx_VolumeDate.Text = sv.SalesDate.ToString("yyyy-MM-dd");
        ddl_AccountMonth.SelectedValue = sv.AccountMonth.ToString();
        tbx_Remark.Text = sv.Remark;

        DataTable dt = SVM_SalesVolumeBLL.InitProductList((int)ViewState["VolumeID"], sv.Supplier,
            (int)ViewState["Type"], sv.AccountMonth, false); //初始化产品列表
        DataColumn[] keys = { dt.Columns["Product"] };
        dt.PrimaryKey = keys;
        ViewState["DTDetail"] = dt;

        BindGrid();

        if (sv.ApproveFlag == 1)
        {
            #region 已审核,不可再修改
            tbx_VolumeDate.Enabled = false;
            ddl_AccountMonth.Enabled = false;
            tbx_Remark.Enabled = false;
            gv_List.SetControlsEnable(false);

            bt_Save.Visible = false;
            bt_Delete.Visible = false;
            bt_Approve.Visible = false;
            #endregion
        }
    }
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        if (DateTime.Parse(this.tbx_VolumeDate.Text.Trim()) > DateTime.Now.Date)
        {
            MessageBox.Show(this, "发生日期不能超出当天日期!");
            return;
        }

        SaveMyViewState();
        int transferinclient = 0, transferoutclient = 0;
        if (int.TryParse(select_Client.SelectValue, out transferinclient) && int.TryParse(select_Supplier.SelectValue, out transferoutclient))
        {
            #region 更新销量内容

            #region 保存销量头信息
            SVM_SalesVolumeBLL bll;

            if ((int)ViewState["VolumeID"] == 0)
            {
                CM_ClientBLL _s = new CM_ClientBLL(transferoutclient);

                bll = new SVM_SalesVolumeBLL();
                bll.Model.Type = (int)ViewState["Type"];
                bll.Model.OrganizeCity = _s.Model.OrganizeCity;
                bll.Model.Supplier = transferoutclient;
                bll.Model.Client = transferinclient;
                bll.Model.InsertStaff = (int)Session["UserID"];
                bll.Model.ApproveFlag = 2;

                if ((bool)ViewState["IsCXP"])
                    bll.Model.Flag = 16;                            //赠品调拨单
                else
                    bll.Model.Flag = 6;                              //成品调拨单
            }
            else
            {
                bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            }

            bll.Model.SalesDate = DateTime.Parse(this.tbx_VolumeDate.Text.Trim());
            bll.Model.AccountMonth = int.Parse(ddl_AccountMonth.SelectedValue);
            bll.Model.Remark = tbx_Remark.Text;

            if ((int)ViewState["VolumeID"] == 0)
                bll.Model.ID = bll.Add();
            else
                bll.Update();
            #endregion

            #region 更新产品明细数据
            DataTable dt = (DataTable)ViewState["DTDetail"];
            foreach (DataRow dr in dt.Rows)
            {
                int product = (int)dr["ID"];
                int quantity = (int)dr["Quantity"];

                SVM_SalesVolume_Detail _detail = bll.Items.FirstOrDefault(m => m.Product == product);
                if (_detail == null)
                {
                    //销量明细里不存在该产品的记录
                    if (quantity == 0) continue;     //新增销量时,数量为0的不保存到数据库中

                    _detail = new SVM_SalesVolume_Detail();
                    _detail.Product = product;
                    _detail.SalesPrice = (decimal)dr["Price"];
                    _detail.Quantity = quantity;
                    _detail.FactoryPrice = (decimal)dr["FactoryPrice"];
                    bll.AddDetail(_detail);
                }
                else
                {
                    //销量明细里已存在该产品的记录
                    if (quantity == 0)
                    {
                        bll.DeleteDetail(_detail.ID);
                        continue;
                    }
                    else if (_detail.Quantity != quantity || _detail.SalesPrice != (decimal)dr["Price"])
                    {
                        _detail.SalesPrice = (decimal)dr["Price"];
                        _detail.Quantity = quantity;
                        bll.UpdateDetail(_detail);
                    }
                }
            }
            #endregion

            #endregion

            if (sender != null)
            {
                MessageBox.ShowAndRedirect(this, "填报数据保存成功!", "TransferVolumeDetail.aspx?VolumeID=" + bll.Model.ID.ToString());
            }
        }
        else
        {
            MessageBox.Show(this, "请正确选择调入及调出客户!");
            return;
        }
    }
Beispiel #22
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            #region 获取页面参数
            ViewState["VolumeID"] = Request.QueryString["VolumeID"] == null ? 0 : int.Parse(Request.QueryString["VolumeID"]);
            if ((int)ViewState["VolumeID"] == 0)
            {
                ViewState["Type"]     = Request.QueryString["Type"] == null ? 1 : int.Parse(Request.QueryString["Type"]);            //销量类型 1:经销商进货 2:经销商出货(即门店进货) 3:门店出货
                ViewState["ClientID"] = Request.QueryString["ClientID"] == null ? 0 : int.Parse(Request.QueryString["ClientID"]);
                ViewState["IsCXP"]    = Request.QueryString["IsCXP"] == null ? false : int.Parse(Request.QueryString["IsCXP"]) != 0; //是否是赠品销量录入 0:成品 1:赠品
                if ((int)ViewState["ClientID"] == 0)
                {
                    Response.Redirect("../desktop.aspx");
                }
            }
            #endregion

            BindDropDown();

            if ((int)ViewState["VolumeID"] == 0)
            {
                if ((int)ViewState["Type"] == 3)
                {
                    BindClientInfo(0, (int)ViewState["ClientID"]);
                    if (ddl_Promotor.Visible && ddl_Promotor.Items.Count > 1)
                    {
                        ddl_Promotor.Items[1].Selected = true;
                    }
                    tbx_VolumeDate.Enabled = false;
                    bt_Submit.Visible      = false;     //门店销售单,不允许即时提交
                }
                else
                {
                    BindClientInfo((int)ViewState["ClientID"], 0);
                }

                int month = int.Parse(ddl_AccountMonth.SelectedValue);

                DataTable    dt   = SVM_SalesVolumeBLL.InitProductList((int)ViewState["VolumeID"], (int)ViewState["ClientID"], (int)ViewState["Type"], month, (bool)ViewState["IsCXP"]); //初始化产品列表
                DataColumn[] keys = { dt.Columns["Product"] };
                dt.PrimaryKey         = keys;
                ViewState["DTDetail"] = dt;

                bt_Delete.Visible    = false;
                bt_Approve.Visible   = false;
                bt_ToForcast.Visible = false;

                if (!(bool)ViewState["IsCXP"])
                {
                    tb_AddProduct.Visible = false;
                }
            }
            else
            {
                cb_OnlyDisplayUnZero.Checked = true;
                BindData();
            }

            BindDropDown_ByIsCXP();
            if (Request.QueryString["SalesFlag"] != null && ddl_Flag.Items.FindByValue(Request.QueryString["SalesFlag"]) != null)
            {
                ViewState["SalesFlag"] = int.Parse(Request.QueryString["SalesFlag"]);
                ddl_Flag.SelectedValue = Request.QueryString["SalesFlag"];
                ddl_Flag.Enabled       = false;
            }
            Header.Attributes["WebPageSubCode"] = "Type=" + ViewState["Type"].ToString();
        }
        if ((int)ViewState["VolumeID"] == 0 && !Right_Assign_BLL.GetAccessRight(Session["UserName"].ToString(), 1114, "AddSalesVolumeIN") &&
            Right_Assign_BLL.GetAccessRight(Session["UserName"].ToString(), 1114, "AddSalesVolumeBack"))
        {
            MessageBox.Show(this, "您只具有录入【退货】的权限,请确认是否要录入退货.");
        }
    }
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        SaveMyViewState();
        CM_Client _r = new CM_ClientBLL((int)ViewState["ClientID"]).Model;

        #region 更新销量内容

        #region 保存销量头信息
        SVM_SalesVolumeBLL bll;
        //成/赠品进货
        IList<SVM_SalesVolume> svmlists = new List<SVM_SalesVolume>();
        string conditon = "";
        string message = "";
        if (!(bool)ViewState["IsCXP"])
        {
            switch (ViewState["Type"].ToString())
            {
                case "1":
                case "2":
                    conditon = "Client=" + _r.ID.ToString()
                      + " AND Type IN(1,2) AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                      + " AND Flag=" + ddl_Flag.SelectedValue;
                    message = "该客户当月的进货已审核,不可再次录入";
                    break;
                case "3":
                    conditon = "Supplier=" + _r.ID.ToString()
                 + " AND Type=3 AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                 + " AND Flag=" + ddl_Flag.SelectedValue + " AND ISNULL(Promotor,0)=" + ddl_Promotor.SelectedValue;
                    message = "该客户当月的销量已审核,不可再次录入";
                    break;
            }

        }
        else //判断是否有过门店赠品进货
        {
            switch (ViewState["Type"].ToString())
            {
                case "1":
                case "2":
                    conditon = "Client=" + _r.ID.ToString()
                      + " AND Type IN(1,2) AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                      + " AND Flag=" + ddl_Flag.SelectedValue;
                    message = "该客户当月的赠品进货已审核,不可再次录入";
                    break;
                case "3":
                    conditon = "Client=" + _r.ID.ToString()
                      + " AND Type=3 AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                      + " AND Flag=" + ddl_Flag.SelectedValue;
                    message = "该客户当月的赠品销量已审核,不可再次录入";
                    break;
            }

        }
        svmlists = SVM_SalesVolumeBLL.GetModelList(conditon + " AND InsertStaff!=1");
        if (svmlists.Count > 0)
        {
            if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null)
            {
                MessageBox.Show(this, message);
                return;
            }
            if (svmlists.Count == 1)
            {
                ViewState["VolumeID"] = svmlists[0].ID;
            }
        }
        if ((int)ViewState["VolumeID"] == 0)
        {
            foreach (SVM_SalesVolume m in svmlists)
            {
                bll = new SVM_SalesVolumeBLL(m.ID);
                bll.DeleteDetail();
                bll.Delete();
            }

            bll = new SVM_SalesVolumeBLL();
            bll.Model.Type = (int)ViewState["Type"];
            bll.Model.OrganizeCity = _r.OrganizeCity;
            bll.Model["DataSource"] = "4";
            if (bll.Model.Type == 3)
            {
                //门店销售
                bll.Model.Supplier = _r.ID;
                bll.Model.Promotor = int.Parse(ddl_Promotor.SelectedValue);
            }
            else
            {
                bll.Model.Client = _r.ID;
                if (ddl_SellOutClient.Visible)
                    bll.Model.Supplier = int.Parse(ddl_SellOutClient.SelectedValue);
                else
                    bll.Model.Supplier = _r.Supplier;
            }
            bll.Model.InsertStaff = (int)Session["UserID"];
        }
        else
        {
            bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Model.UpdateStaff = (int)Session["UserID"];
        }

        bll.Model.SalesDate = DateTime.Parse(this.tbx_VolumeDate.Text.Trim());
        bll.Model.AccountMonth = int.Parse(ddl_AccountMonth.SelectedValue);
        bll.Model.Flag = int.Parse(ddl_Flag.SelectedValue);
        bll.Model.SheetCode = tbx_sheetCode.Text;
        bll.Model.Remark = tbx_Remark.Text;

        if (bll.Model.Type == 3)
        {
            //门店销售时记录导购员
            bll.Model.Promotor = int.Parse(ddl_Promotor.SelectedValue);
        }

        bll.Model["SubmitFlag"] = "2";

        if ((int)ViewState["VolumeID"] == 0)
            ViewState["VolumeID"] = bll.Add();
        else
            bll.Update();
        #endregion

        #region 更新产品明细数据
        DataTable dt = (DataTable)ViewState["DTDetail"];
        foreach (DataRow dr in dt.Rows)
        {
            int product = (int)dr["ID"];
            int quantity = (int)dr["Quantity"];
            if (quantity > 5000 && bll.Model.Type == 3)
            {
                MessageBox.Show(this, "超过系统设置的销量上限5000");
                return;
            }

            if ((bll.Model.Flag == 2 || bll.Model.Flag == 3 || bll.Model.Flag == 12) && quantity > 0)
                quantity = 0 - quantity;       //退货时,数量保存为负数 (2:原价退货 3:折价退货 12:赠品退货)

            SVM_SalesVolume_Detail _detail = bll.Items.FirstOrDefault(m => m.Product == product);
            if (_detail == null)
            {
                //销量明细里不存在该产品的记录
                if (quantity == 0) continue;     //新增销量时,数量为0的不保存到数据库中

                _detail = new SVM_SalesVolume_Detail();
                _detail.Product = product;
                _detail.SalesPrice = (decimal)dr["Price"];
                _detail.Quantity = quantity;
                _detail.FactoryPrice = (decimal)dr["FactoryPrice"];
                bll.AddDetail(_detail);
            }
            else
            {
                //销量明细里已存在该产品的记录
                if (quantity == 0)
                {
                    bll.DeleteDetail(_detail.ID);
                    continue;
                }
                else if (_detail.Quantity != quantity || _detail.SalesPrice != (decimal)dr["Price"])
                {
                    _detail.SalesPrice = (decimal)dr["Price"];
                    _detail.Quantity = quantity;
                    bll.UpdateDetail(_detail);
                }
            }
        }
        #endregion

        #endregion

        if (ddl_Promotor.Items.Count > 2)
        {
            MessageBox.Show(this, "本店有" + (ddl_Promotor.Items.Count - 1).ToString() + "个导购员,请确定每个导购员均已录入了销量");
        }
        if (sender != null)
        {
            MessageBox.ShowAndRedirect(this, "数据暂存成功,并在所有门店及经分销商的销量全部录入完成后,及时到汇总页面统一提交!",
                "SalesVolumeBatchInput.aspx?VolumeID=" + ViewState["VolumeID"].ToString());
        }
    }
    private void BindDropDown_ByIsCXP()
    {
        if (ViewState["IsCXP"] == null) return;

        if ((bool)ViewState["IsCXP"])
        {
            ddl_Brand.DataSource = PDT_BrandBLL.GetModelList("IsOpponent in('9')");

            //促销品单
            ddl_Flag.DataSource = DictionaryBLL.GetDicCollections("SVM_SalesFlag").Where(p => int.Parse(p.Key) > 10);
            ddl_Flag.DataBind();
            select_Product.PageUrl += "?IsOpponent=9";
            select_Product1.PageUrl += "?IsOpponent=9";
        }
        else
        {
            ddl_Brand.DataSource = PDT_BrandBLL.GetModelList("IsOpponent in('1')");
            //成品单
            ddl_Flag.DataSource = DictionaryBLL.GetDicCollections("SVM_SalesFlag").Where(p => int.Parse(p.Key) <= 10);
            ddl_Flag.DataBind();
            select_Product.PageUrl += "?IsOpponent=1";
            select_Product1.PageUrl += "?IsOpponent=1";
        }
        ddl_Brand.DataBind();
        ddl_Brand.Items.Insert(0, new ListItem("所有品牌", "0"));
        ddl_Brand_SelectedIndexChanged(null, null);
        ddl_Flag_SelectedIndexChanged(null, null);
        //检查录入进货与退货的权限
        if (!Right_Assign_BLL.GetAccessRight(Session["UserName"].ToString(), 1114, "AddSalesVolumeBack"))//退货
        {
            if ((int)ViewState["VolumeID"] == 0)
            {
                try
                {
                    ddl_Flag.Items.FindByValue("2").Enabled = false;
                }
                catch (Exception)
                {

                }

                try
                {
                    ddl_Flag.Items.FindByValue("12").Enabled = false;

                }
                catch (Exception)
                {

                }

            }
            else
            {
                SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;
                if (sv.Flag == 2 || sv.Flag == 12)
                {
                    bt_Delete.Visible = false;
                    bt_Save.Visible = false;
                    bt_Submit.Visible = false;
                }

            }
        }
        if (!Right_Assign_BLL.GetAccessRight(Session["UserName"].ToString(), 1114, "AddSalesVolumeIN"))//进货(正数)
        {
            if ((int)ViewState["VolumeID"] == 0)
            {
                try
                {
                    ddl_Flag.Items.FindByValue("1").Enabled = false;
                }
                catch (Exception)
                {

                }
                try
                {
                    ddl_Flag.Items.FindByValue("11").Enabled = false;
                }
                catch (Exception)
                {

                }

            }
            else
            {
                SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;
                if (sv.Flag == 1 || sv.Flag == 11)
                {
                    bt_Delete.Visible = false;
                    bt_Save.Visible = false;
                    bt_Submit.Visible = false;
                }
            }
        }
        if ((int)ViewState["VolumeID"] > 0 && Right_Assign_BLL.GetAccessRight(Session["UserName"].ToString(), 1114, "UpdateFJFSalesVolume"))
        {
            SVM_SalesVolumeBLL _bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bt_Save.Visible = _bll.Model["DataSource"] == "2" && _bll.Model.ApproveFlag != 1;
        }
    }
    private void BindGrid()
    {
        int month        = int.Parse(ddl_Month.SelectedValue);
        int organizecity = int.Parse(tr_OrganizeCity.SelectValue);
        int level        = int.Parse(ddl_Level.SelectedValue);
        int state        = int.Parse(ddl_State.SelectedValue);
        int flag         = int.Parse(ddl_Flag.SelectedValue);

        #region 判断是否可以审批通过
        string[] allowdays = Addr_OrganizeCityParamBLL.GetValueByType(1, 7).Replace(" ", "").Split(new char[] { ',', ',', ';', ';' });
        string   date      = DateTime.Now.Day.ToString();
        if (allowdays.Contains(date))
        {
            bt_Approve.Enabled = false;
            bt_Approve.ToolTip = "每月21-25号不可对进销存审批通过!";
        }
        #endregion

        if (new Addr_OrganizeCityBLL(organizecity).Model.Level >= 2 &&
            month == AC_AccountMonthBLL.GetMonthByDate(DateTime.Today.AddDays(-10)))
        {
            if ((int)ViewState["ClientType"] == 3 && (int)ViewState["Type"] == 2)
            {
                DataTable dtFillDataProgress = Org_StaffBLL.GetFillDataProgress((int)Session["UserID"], true);
                DataRow[] rows;
                if (flag == 1)
                {
                    rows = dtFillDataProgress.Select("ItemCode='006'");
                }
                else
                {
                    rows = dtFillDataProgress.Select("ItemCode='012'");
                }

                if (rows.Length > 0)
                {
                    int ItemTargetCount   = (int)rows[0]["ItemTargetCount"];
                    int ItemCompleteCount = (int)rows[0]["ItemCompleteCount"];
                    if (ItemTargetCount > ItemCompleteCount)
                    {
                        MessageBox.Show(this, "对不起,还有" + (ItemTargetCount - ItemCompleteCount).ToString() +
                                        "家门店销量尚未录入,无法提交或审核!具体请查看桌面填报进度表.");
                        bt_Approve.Enabled = false;
                        bt_Submit.Enabled  = false;
                    }
                }
            }
        }

        if (MCSTabControl1.SelectedIndex == 0)
        {
            DataTable dt_summary = SVM_SalesVolumeBLL.GetSummaryTotal(organizecity, month, (int)ViewState["ClientType"], flag, level, state, (int)ViewState["Type"], (int)Session["UserID"]);
            dt_summary            = MatrixTable.Matrix(dt_summary, new string[] { "管理片区名称" }, new string[] { "品牌", "段位" }, "金额", true, true);
            gv_Summary.DataSource = dt_summary;
            gv_Summary.DataBind();
            MatrixTable.GridViewMatric(gv_Summary);
            if (dt_summary.Columns.Count >= 24)
            {
                gv_Summary.Width = new Unit(dt_summary.Columns.Count * 60);
            }
            else
            {
                gv_Summary.Width = new Unit(100, UnitType.Percentage);
            }
        }
        else if (MCSTabControl1.SelectedIndex == 1)
        {
            if (organizecity == 1 || new Addr_OrganizeCityBLL(organizecity).Model.Level < 2)
            {
                MessageBox.Show(this, "按客户及SKU查询时,不能按总部及大区级别查询!");
                return;
            }
            DataTable dt_summary = SVM_SalesVolumeBLL.GetSummaryTotal2(organizecity, month, (int)ViewState["ClientType"], flag, state, (int)ViewState["Type"], (int)Session["UserID"]);
            dt_summary            = MatrixTable.Matrix(dt_summary, new string[] { "管理片区名称", "客户名称", "责任业代" }, new string[] { "品牌", "产品名称" }, "数量", true, true);
            gv_Summary.DataSource = dt_summary;
            gv_Summary.DataBind();
            MatrixTable.GridViewMatric(gv_Summary);
            if (dt_summary.Columns.Count >= 24)
            {
                gv_Summary.Width = new Unit(dt_summary.Columns.Count * 60);
            }
            else
            {
                gv_Summary.Width = new Unit(100, UnitType.Percentage);
            }
        }
        else
        {
            string            condition = " SVM_SalesVolume.AccountMonth=" + ddl_Month.SelectedValue;
            IList <CM_Client> cmlist    = new List <CM_Client>();
            if (organizecity > 1)
            {
                Addr_OrganizeCityBLL orgcity = new Addr_OrganizeCityBLL(organizecity);
                string orgcitys = orgcity.GetAllChildNodeIDs();
                if (orgcitys != "")
                {
                    orgcitys += ",";
                }
                orgcitys += tr_OrganizeCity.SelectValue;
                cmlist    = CM_ClientBLL.GetModelList("OrganizeCity IN (" + orgcitys + ") AND ActiveFlag=1 AND CM_Client.ClientType=" + ViewState["ClientType"].ToString());

                if (CM_ClientBLL.GetModelList("OrganizeCity IN (" + orgcitys + ") AND ActiveFlag=1 AND CM_Client.ClientType=" + ViewState["ClientType"].ToString()).Count != 0)
                {
                    condition += " AND SVM_SalesVolume.OrganizeCity IN (" + orgcitys + ")";
                }
            }

            condition += ddl_Flag.SelectedValue == "1" ? " AND SVM_SalesVolume.Flag<6" : " AND SVM_SalesVolume.Flag>6";

            AC_AccountMonthBLL _monthbll = new AC_AccountMonthBLL(month);

            if (ViewState["ClientType"] != null)
            {
                switch ((int)ViewState["ClientType"])
                {
                case 2:
                    if ((int)ViewState["Type"] == 1)
                    {
                        condition += " AND SVM_SalesVolume.Client IN( Select ID FROM MCS_CM.dbo.CM_Client Where ClientType=2 AND  MCS_SYS.dbo.UF_Spilt2('MCS_CM.dbo.CM_Client',CM_Client.ExtPropertys,'DIClassify')='2'";
                    }
                    else
                    {
                        condition += " AND SVM_SalesVolume.Supplier IN( Select ID FROM MCS_CM.dbo.CM_Client Where ClientType=2";
                    }
                    break;

                case 3:
                    condition += (int)ViewState["Type"] == 1 ? " AND SVM_SalesVolume.Client IN" : " AND SVM_SalesVolume.Supplier IN";
                    condition += "( Select ID FROM MCS_CM.dbo.CM_Client Where ClientType=3 ";
                    break;
                }
                if (cmlist.Count == 0)
                {
                    condition += " AND CM_Client.ClientManager=" + Session["UserID"].ToString();
                }
                condition += " AND ApproveFlag=1 AND OpenTime<='" + _monthbll.Model.EndDate + "'AND ISNULL(CloseTime,GETDATE())>='" + _monthbll.Model.BeginDate + "')";
            }
            switch (ddl_State.SelectedValue)
            {
            case "1":
                condition += "AND SVM_SalesVolume.ApproveFlag=2 AND  MCS_SYS.dbo.UF_Spilt2('MCS_SVM.dbo.SVM_SalesVolume',SVM_SalesVolume.ExtPropertys,'SubmitFlag')='2'";
                break;

            case "2":
                condition += "AND SVM_SalesVolume.ApproveFlag=2 AND  MCS_SYS.dbo.UF_Spilt2('MCS_SVM.dbo.SVM_SalesVolume',SVM_SalesVolume.ExtPropertys,'SubmitFlag')='1'";
                break;

            case "3":
                condition += " AND SVM_SalesVolume.ApproveFlag=1";
                break;
            }
            gv_List.ConditionString = condition;
            gv_List.BindGrid();
        }
    }
Beispiel #26
0
        private string DoImportProduct(Worksheet worksheet, int accountmonth, int insertstaff, int cloumn, IList <PDT_Product> productlists, out int State)
        {
            string          ImportInfo = "";
            AC_AccountMonth month      = new AC_AccountMonthBLL(accountmonth).Model;
            DateTime        minday     = month.BeginDate;
            DateTime        maxday     = DateTime.Today < month.EndDate ? DateTime.Today : month.EndDate;

            State = 0;

            tbx_Msg.AppendText("\r\n");
            tbx_Msg.AppendText("-------------------------------------------------------------------------\r\n");
            tbx_Msg.AppendText("----批量导入客户进货----\r\n+----批量导入客户销量----\r\nID号      门店类型       门店名     导购员       错误原因\r\n");


            #region 读取Excel表格
            int row      = 1;
            int emptyrow = 0;
            int _cloumn  = 0;
            while (true)
            {
                _cloumn = cloumn;
                row++;
                if (((Range)worksheet.Cells[row, 1]).Value2 == null)
                {
                    emptyrow++;
                    if (emptyrow > 5)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

                int clientid = 0; int promotorid = 0;
                if (!int.TryParse(((Range)worksheet.Cells[row, 1]).Value2.ToString(), out clientid))
                {
                    continue;
                }

                if (cloumn == 8 && ((Range)worksheet.Cells[row, 6]).Value2 != null &&
                    !int.TryParse(((Range)worksheet.Cells[row, 6]).Value2.ToString(), out promotorid))
                {
                    continue;
                }

                #region 验证数据

                CM_Client client = new CM_ClientBLL(clientid).Model;

                if (client == null || client.FullName != ((Range)worksheet.Cells[row, 3]).Text.ToString())
                {
                    tbx_Msg.AppendText("ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",零售商ID与零售商名称" : ",分销商ID与分销商名称") + "不匹配!\r\n");
                    State = 4;
                    continue;
                }
                int uplimit = client.ClientType == 3 ? 5000 : 9000;
                if (((Range)worksheet.Cells[row, 5]).Text.ToString() != month.Name)
                {
                    tbx_Msg.AppendText("ID号:" + clientid.ToString() + ",归属月份必须为【" + month.Name + "】\r\n");
                    State = 4;
                    continue;
                }
                #endregion

                #region 组织销量头
                SVM_SalesVolumeBLL bll      = null;
                string             conditon = "";
                if (cloumn == 6)
                {
                    conditon = "Client=" + clientid.ToString()
                               + " AND Type IN(1,2) AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                               + " AND Flag=1 "
                               + " AND Remark='" + tbx_Remark.Text + "'";
                }
                else
                {
                    conditon = "Supplier=" + clientid.ToString()
                               + " AND Type=3 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                               + " AND Flag=1 AND ISNULL(Promotor,0)=" + promotorid.ToString()
                               + " AND Remark='" + tbx_Remark.Text + "'";
                }
                IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList(conditon);
                if (svmlists.Count > 0)
                {
                    tbx_Msg.AppendText("行号:" + row.ToString() + ",ID号:" + ((Range)worksheet.Cells[row, 1]).Text.ToString() + client.FullName + "  当月的销量单已导入!\r\n");
                    continue;
                }

                if (bll == null)
                {
                    bll = new SVM_SalesVolumeBLL();
                    if (cloumn == 8)
                    {
                        bll.Model.Client   = 0;
                        bll.Model.Supplier = client.ID;
                        bll.Model.Promotor = promotorid;
                        bll.Model.Type     = 3;
                    }
                    else
                    {
                        bll.Model.Client   = clientid;
                        bll.Model.Supplier = client.Supplier;
                        bll.Model.Type     = 2;
                    }

                    bll.Model.OrganizeCity  = client.OrganizeCity;
                    bll.Model.AccountMonth  = month.ID;
                    bll.Model.SalesDate     = maxday;
                    bll.Model.ApproveFlag   = 2;
                    bll.Model.Flag          = 1;    //成品销售
                    bll.Model["IsCXP"]      = "N";
                    bll.Model.InsertStaff   = insertstaff;
                    bll.Model.Remark        = tbx_Remark.Text;
                    bll.Model["DataSource"] = tbx_DataSource.Text;      //6:导购销售拆分 7:补录销量
                }
                #endregion
                bll.Model["SubmitFlag"] = "1";

                #region 读取各产品销量
                IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>();
                bool wrongflag = false;//判断导入数量是否正常(除空导致的异常)
                int  quantity  = 0;
                foreach (PDT_Product product in productlists)
                {
                    if (((Range)worksheet.Cells[row, _cloumn]).Value2 != null)
                    {
                        int.TryParse(((Range)worksheet.Cells[row, _cloumn]).Value2.ToString(), out quantity);
                        if (quantity != 0 && quantity <= uplimit && quantity >= 0)
                        {
                            decimal factoryprice = 0, salesprice = 0;
                            PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, cloumn == 8 ? 3 : 2, out factoryprice, out salesprice);

                            if (factoryprice == 0)
                            {
                                factoryprice = product.FactoryPrice;
                            }
                            if (salesprice == 0)
                            {
                                salesprice = product.NetPrice;
                            }

                            SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                            detail.Product      = product.ID;
                            detail.FactoryPrice = factoryprice;
                            detail.SalesPrice   = salesprice;
                            detail.Quantity     = quantity;
                            details.Add(detail);
                        }
                        else if (trim(((Range)worksheet.Cells[row, _cloumn]).Text.ToString()) != "" && ((Range)worksheet.Cells[row, _cloumn]).Text.ToString() != "0")
                        {
                            wrongflag = true;
                            break;
                        }
                        else if (quantity < 0)
                        {
                            wrongflag = true;
                            break;
                        }
                    }
                    _cloumn++;
                }
                if (wrongflag)
                {
                    tbx_Msg.AppendText("行号:" + row.ToString() + ",ID号:" + clientid.ToString() + (client.ClientType == 3 ? "," + ((Range)worksheet.Cells[row, 4]).Text + ":" : ",分销商:") + client.FullName
                                       + (client.ClientType == 3 ? "" : ",该分销商") + (cloumn == 6 ? "当月的进货单" : ",导购:" + ((Range)worksheet.Cells[row, 7]).Text.ToString() + "  当月的销量单")
                                       + "未能导入!产品名称:" + ((Range)worksheet.Cells[1, _cloumn]).Text + "数量填写错误。\r\n");
                    State = 4;
                    continue;
                }
                #endregion

                #region 更新销量至数据库
                if (bll.Model.ID > 0)
                {
                    //if (details.Count > 0)
                    //{
                    //    bll.DeleteDetail();     //先清除原先导入的数据
                    //    bll.Items = details;
                    //    bll.Model.UpdateStaff = insertstaff;
                    //    bll.AddDetail();
                    //    bll.Update();

                    //    tbx_Msg.AppendText("<span style='color:Blue'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",该零售商:" : ",该分销商:") + client.FullName
                    //        + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + (cloumn == 6 ? " 的进货单" : "的销量单") + "被成功更新!产品SKU数:"
                    //  + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n");
                    //}
                }
                else
                {
                    if (details.Count > 0)    //没有产品也新增一条空销量头
                    {
                        bll.Items = details;
                        if (bll.Add() > 0)
                        {
                            tbx_Msg.AppendText("行号:" + row.ToString() + ",ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",该零售商:" : ",该分销商:") + client.FullName
                                               + (cloumn == 6 ? " 的进货单" : "的销量单") + "已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                                               + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n");

                            tbx_Msg.Focus();
                            tbx_Msg.Select(tbx_Msg.TextLength, 0);
                            tbx_Msg.ScrollToCaret();
                        }
                    }
                }
                #endregion
            }
            #endregion

            return(ImportInfo);
        }
Beispiel #27
0
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        if (DateTime.Parse(this.tbx_VolumeDate.Text.Trim()) > DateTime.Now.Date)
        {
            MessageBox.Show(this, "发生日期不能超出当天日期!");
            return;
        }

        SaveMyViewState();
        int transferinclient = 0, transferoutclient = 0;

        if (int.TryParse(select_Client.SelectValue, out transferinclient) && int.TryParse(select_Supplier.SelectValue, out transferoutclient))
        {
            #region 更新销量内容

            #region 保存销量头信息
            SVM_SalesVolumeBLL bll;

            if ((int)ViewState["VolumeID"] == 0)
            {
                CM_ClientBLL _s = new CM_ClientBLL(transferoutclient);

                bll                    = new SVM_SalesVolumeBLL();
                bll.Model.Type         = (int)ViewState["Type"];
                bll.Model.OrganizeCity = _s.Model.OrganizeCity;
                bll.Model.Supplier     = transferoutclient;
                bll.Model.Client       = transferinclient;
                bll.Model.InsertStaff  = (int)Session["UserID"];
                bll.Model.ApproveFlag  = 2;

                if ((bool)ViewState["IsCXP"])
                {
                    bll.Model.Flag = 16;                            //赠品调拨单
                }
                else
                {
                    bll.Model.Flag = 6;                              //成品调拨单
                }
            }
            else
            {
                bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            }

            bll.Model.SalesDate    = DateTime.Parse(this.tbx_VolumeDate.Text.Trim());
            bll.Model.AccountMonth = int.Parse(ddl_AccountMonth.SelectedValue);
            bll.Model.Remark       = tbx_Remark.Text;

            if ((int)ViewState["VolumeID"] == 0)
            {
                bll.Model.ID = bll.Add();
            }
            else
            {
                bll.Update();
            }
            #endregion

            #region 更新产品明细数据
            DataTable dt = (DataTable)ViewState["DTDetail"];
            foreach (DataRow dr in dt.Rows)
            {
                int product  = (int)dr["ID"];
                int quantity = (int)dr["Quantity"];

                SVM_SalesVolume_Detail _detail = bll.Items.FirstOrDefault(m => m.Product == product);
                if (_detail == null)
                {
                    //销量明细里不存在该产品的记录
                    if (quantity == 0)
                    {
                        continue;                    //新增销量时,数量为0的不保存到数据库中
                    }
                    _detail              = new SVM_SalesVolume_Detail();
                    _detail.Product      = product;
                    _detail.SalesPrice   = (decimal)dr["Price"];
                    _detail.Quantity     = quantity;
                    _detail.FactoryPrice = (decimal)dr["FactoryPrice"];
                    bll.AddDetail(_detail);
                }
                else
                {
                    //销量明细里已存在该产品的记录
                    if (quantity == 0)
                    {
                        bll.DeleteDetail(_detail.ID);
                        continue;
                    }
                    else if (_detail.Quantity != quantity || _detail.SalesPrice != (decimal)dr["Price"])
                    {
                        _detail.SalesPrice = (decimal)dr["Price"];
                        _detail.Quantity   = quantity;
                        bll.UpdateDetail(_detail);
                    }
                }
            }
            #endregion

            #endregion

            if (sender != null)
            {
                MessageBox.ShowAndRedirect(this, "填报数据保存成功!", "TransferVolumeDetail.aspx?VolumeID=" + bll.Model.ID.ToString());
            }
        }
        else
        {
            MessageBox.Show(this, "请正确选择调入及调出客户!");
            return;
        }
    }
        private string DoImportProduct(Worksheet worksheet, int accountmonth, int insertstaff, int cloumn, IList<PDT_Product> productlists, out int State)
        {
            string ImportInfo = "";
            AC_AccountMonth month = new AC_AccountMonthBLL(accountmonth).Model;
            DateTime minday = month.BeginDate;
            DateTime maxday = DateTime.Today < month.EndDate ? DateTime.Today : month.EndDate;

            State = 0;
            ImportInfo += "<br/>";
            ImportInfo += "<span style='color: Red'>-------------------------------------------------------------------------</span><br/>";
            ImportInfo += cloumn == 6 ? "<span style='color: Red'>----批量导入客户进货----</span><br/>" : "<span style='color: Red'>----批量导入客户销量----<br/>ID号      门店类型       门店名     导购员       错误原因<br/></span>";

            #region 读取Excel表格
            int row = 1;
            int emptyrow = 0;
            int _cloumn = 0;
            while (true)
            {
                _cloumn = cloumn;
                row++;
                if (((Range)worksheet.Cells[row, 1]).Value2 == null)
                {
                    emptyrow++;
                    if (emptyrow > 5)
                        break;
                    else
                        continue;
                }

                int clientid = 0; int promotorid = 0;
                if (!int.TryParse(((Range)worksheet.Cells[row, 1]).Value2.ToString(), out clientid))
                {
                    continue;
                }

                if (cloumn == 8 && ((Range)worksheet.Cells[row, 6]).Value2 != null &&
                        !int.TryParse(((Range)worksheet.Cells[row, 6]).Value2.ToString(), out promotorid))
                {
                    continue;
                }

                #region 验证数据

                CM_Client client = new CM_ClientBLL(clientid).Model;

                if (client == null || client.FullName != ((Range)worksheet.Cells[row, 3]).Text.ToString())
                {
                    ImportInfo += "<span style='color: Red'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",零售商ID与零售商名称" : ",分销商ID与分销商名称") + "不匹配!</span><br/>";
                    State = 4;
                    continue;
                }
                int uplimit = client.ClientType == 3 ? 5000 : 9000;
                if (((Range)worksheet.Cells[row, 5]).Text.ToString() != month.Name)
                {
                    ImportInfo += "<span style='color: Red'>ID号:" + clientid.ToString() + ",归属月份必须为【" + month.Name + "】</span><br/>";
                    State = 4;
                    continue;
                }
                #endregion

                #region 组织销量头
                SVM_SalesVolumeBLL bll = null;
                string conditon = "";
                if (cloumn == 6)
                {
                    conditon = "Client=" + clientid.ToString()
                       + " AND Type IN(1,2) AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                       + " AND Flag=1 ";
                }
                else
                {
                    conditon = "Supplier=" + clientid.ToString()
                  + " AND Type=3 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                  + " AND Flag=1 AND ISNULL(Promotor,0)=" + promotorid.ToString();

                }
                IList<SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList(conditon + " AND InsertStaff!=1");
                if (svmlists.Count > 0)
                {
                    if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null)
                    {
                        ImportInfo += "<span style='color: Red'>ID号:" + ((Range)worksheet.Cells[row, 1]).Text.ToString() + (client.ClientType == 3 ? "," : ",该分销商") + client.FullName
                                       + (cloumn == 6 ? "  当月的进货单" : ",导购:" + ((Range)worksheet.Cells[row, 7]).Text.ToString() + "  当月的销量单") + "已审核,不可再次导入!</span><br/>";
                        continue;
                    }
                    if (svmlists.Count == 1)
                    {
                        bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                        bll.Items.Clear();
                    }
                }
                if (bll == null)
                {
                    bll = new SVM_SalesVolumeBLL();
                    if (cloumn == 8)
                    {
                        bll.Model.Client = 0;
                        bll.Model.Supplier = client.ID;
                        bll.Model.Promotor = promotorid;
                        bll.Model.Type = 3;
                    }
                    else
                    {
                        bll.Model.Client = clientid;
                        bll.Model.Supplier = client.Supplier;
                        bll.Model.Type = 2;
                    }

                    bll.Model.OrganizeCity = client.OrganizeCity;
                    bll.Model.AccountMonth = month.ID;
                    bll.Model.SalesDate = maxday;
                    bll.Model.ApproveFlag = 2;
                    bll.Model.Flag = 1;             //成品销售
                    bll.Model["IsCXP"] = "N";
                    bll.Model.InsertStaff = insertstaff;
                    bll.Model.Remark = "Excel批量导入";

                }
                #endregion
                bll.Model["SubmitFlag"] = "1";
                bll.Model["DataSource"] = "3";
                #region 读取各产品销量
                IList<SVM_SalesVolume_Detail> details = new List<SVM_SalesVolume_Detail>();
                bool wrongflag = false;//判断导入数量是否正常(除空导致的异常)
                int quantity = 0;
                bool isnumber = false;
                foreach (PDT_Product product in productlists)
                {
                    quantity = 0;
                    if (((Range)worksheet.Cells[row, _cloumn]).Value2 != null)
                    {
                        int.TryParse(((Range)worksheet.Cells[row, _cloumn]).Value2.ToString(), out quantity);
                        if (int.TryParse(((Range)worksheet.Cells[row, _cloumn]).Value2.ToString(), out quantity) && !isnumber)
                        {
                            isnumber = true;
                        }
                        if (quantity != 0 && quantity <= uplimit && quantity >= 0)
                        {
                            decimal factoryprice = 0, salesprice = 0;
                            PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, cloumn == 8 ? 3 : 2, out factoryprice, out salesprice);

                            if (factoryprice == 0) factoryprice = product.FactoryPrice;
                            if (salesprice == 0) salesprice = product.NetPrice;

                            SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                            detail.Product = product.ID;
                            detail.FactoryPrice = factoryprice;
                            detail.SalesPrice = salesprice;
                            detail.Quantity = quantity;
                            details.Add(detail);
                        }
                        else if (trim(((Range)worksheet.Cells[row, _cloumn]).Text.ToString()) != "" && ((Range)worksheet.Cells[row, _cloumn]).Text.ToString() != "0")
                        {
                            wrongflag = true;
                            break;
                        }
                        else if (quantity < 0)
                        {
                            wrongflag = true;
                            break;
                        }

                    }
                    _cloumn++;
                }
                if (wrongflag)
                {
                    ImportInfo += "<span style='color: Red'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? "," + ((Range)worksheet.Cells[row, 4]).Text + ":" : ",分销商:") + client.FullName
                                      + (client.ClientType == 3 ? "" : ",该分销商") + (cloumn == 6 ? "当月的进货单" : ",导购:" + ((Range)worksheet.Cells[row, 7]).Text.ToString() + "  当月的销量单")
                                      + "未能导入!产品名称:" + ((Range)worksheet.Cells[1, _cloumn]).Text + "数量填写错误。</span><br/>";
                    State = 4;
                    continue;
                }
                #endregion

                #region 更新销量至数据库
                if (bll.Model.ID > 0)
                {
                    if (details.Count > 0)
                    {
                        bll.DeleteDetail();     //先清除原先导入的数据
                        bll.Items = details;
                        bll.Model.UpdateStaff = insertstaff;
                        bll.AddDetail();
                        bll.Update();

                        ImportInfo += "<span style='color:Blue'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",该零售商:" : ",该分销商:") + client.FullName
                            + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + (cloumn == 6 ? " 的进货单" : "的销量单") + "被成功更新!产品SKU数:"
                      + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                    }
                    if (details.Count == 0 && isnumber)
                    {
                        bll.DeleteDetail();
                    }

                }
                else
                {
                    if (details.Count > 0 || svmlists.Count == 0)    //没有产品也新增一条空销量头
                    {
                        bll.Items = details;
                        if (bll.Add() > 0)
                        {
                            foreach (SVM_SalesVolume m in svmlists)
                            {
                                bll = new SVM_SalesVolumeBLL(m.ID);
                                bll.DeleteDetail();
                                bll.Delete();
                            }
                        }
                        ImportInfo += "<span style='color:Black'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",该零售商:" : ",该分销商:") + client.FullName
                      + (cloumn == 6 ? " 的进货单" : "的销量单") + "已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                     + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                    }
                }
                #endregion
            }
            #endregion

            return ImportInfo;
        }
Beispiel #29
0
    private void BindDropDown_ByIsCXP()
    {
        if (ViewState["IsCXP"] == null)
        {
            return;
        }

        if ((bool)ViewState["IsCXP"])
        {
            ddl_Brand.DataSource = PDT_BrandBLL.GetModelList("IsOpponent in('9')");

            //促销品单
            ddl_Flag.DataSource = DictionaryBLL.GetDicCollections("SVM_SalesFlag").Where(p => int.Parse(p.Key) > 10);
            ddl_Flag.DataBind();
            select_Product.PageUrl  += "?IsOpponent=9";
            select_Product1.PageUrl += "?IsOpponent=9";
        }
        else
        {
            ddl_Brand.DataSource = PDT_BrandBLL.GetModelList("IsOpponent in('1')");
            //成品单
            ddl_Flag.DataSource = DictionaryBLL.GetDicCollections("SVM_SalesFlag").Where(p => int.Parse(p.Key) <= 10);
            ddl_Flag.DataBind();
            select_Product.PageUrl  += "?IsOpponent=1";
            select_Product1.PageUrl += "?IsOpponent=1";
        }
        ddl_Brand.DataBind();
        ddl_Brand.Items.Insert(0, new ListItem("所有品牌", "0"));
        ddl_Brand_SelectedIndexChanged(null, null);
        ddl_Flag_SelectedIndexChanged(null, null);
        //检查录入进货与退货的权限
        if (!Right_Assign_BLL.GetAccessRight(Session["UserName"].ToString(), 1114, "AddSalesVolumeBack"))//退货
        {
            if ((int)ViewState["VolumeID"] == 0)
            {
                try
                {
                    ddl_Flag.Items.FindByValue("2").Enabled = false;
                }
                catch (Exception)
                {
                }

                try
                {
                    ddl_Flag.Items.FindByValue("12").Enabled = false;
                }
                catch (Exception)
                {
                }
            }
            else
            {
                SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;
                if (sv.Flag == 2 || sv.Flag == 12)
                {
                    bt_Delete.Visible = false;
                    bt_Save.Visible   = false;
                    bt_Submit.Visible = false;
                }
            }
        }
        if (!Right_Assign_BLL.GetAccessRight(Session["UserName"].ToString(), 1114, "AddSalesVolumeIN"))//进货(正数)
        {
            if ((int)ViewState["VolumeID"] == 0)
            {
                try
                {
                    ddl_Flag.Items.FindByValue("1").Enabled = false;
                }
                catch (Exception)
                {
                }
                try
                {
                    ddl_Flag.Items.FindByValue("11").Enabled = false;
                }
                catch (Exception)
                {
                }
            }
            else
            {
                SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;
                if (sv.Flag == 1 || sv.Flag == 11)
                {
                    bt_Delete.Visible = false;
                    bt_Save.Visible   = false;
                    bt_Submit.Visible = false;
                }
            }
        }
        if ((int)ViewState["VolumeID"] > 0 && Right_Assign_BLL.GetAccessRight(Session["UserName"].ToString(), 1114, "UpdateFJFSalesVolume"))
        {
            SVM_SalesVolumeBLL _bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bt_Save.Visible = _bll.Model["DataSource"] == "2" && _bll.Model.ApproveFlag != 1;
        }
    }
Beispiel #30
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime     minday, maxday = DateTime.Now;
            HSSFWorkbook hssfworkbook;
            FileStream   file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);

            hssfworkbook = new HSSFWorkbook(file);
            ISheet sheet = hssfworkbook.GetSheetAt(0);

            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            int  i = 0, count = getRowsCount() - 1;
            bool flag = true;

            try
            {
                IRow headerRow = sheet.GetRow(0);
                if (headerRow.GetCell(0).ToString() != "零售商ID" ||
                    headerRow.GetCell(1).ToString() != "零售商编号" ||
                    headerRow.GetCell(2).ToString() != "零售商名称" ||
                    headerRow.GetCell(3).ToString() != "零售商分类" ||
                    headerRow.GetCell(4).ToString() != "归属月份" ||
                    headerRow.GetCell(5).ToString() != "导购ID" ||
                    headerRow.GetCell(6).ToString() != "导购姓名")
                {
                    flag = false;
                }
                if (!flag)
                {
                    MessageBox.Show(this, "表头(1~7列)错误!");
                    return;
                }
                int column = getColumnCount(headerRow) + 1;
                int month  = 0;
                rows.MoveNext();

                while (rows.MoveNext())
                {
                    int datacolumn = 7;

                    i++;
                    HSSFRow row = (HSSFRow)rows.Current;
                    if (row.GetCell(0).ToString() == "")
                    {
                        break;
                    }


                    int clientid = 0; int promotorid = 0;
                    if (!int.TryParse(row.GetCell(0).ToString(), out clientid))
                    {
                        errormessage += "零售商:" + row.GetCell(2).ToString() + "的ID错误;\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }
                    CM_Client client = new CM_ClientBLL(clientid).Model;

                    if (client == null)
                    {
                        errormessage += "ID号:" + clientid.ToString() + "零售商在系统中不存在!\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }
                    if (int.TryParse(row.GetCell(5).ToString(), out promotorid))
                    {
                        PM_Promotor pm = new PM_PromotorBLL(promotorid).Model;
                        if (pm == null)
                        {
                            errormessage += "导购ID号:" + promotorid.ToString() + "导购在系统中不存在!\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                    }

                    if (month == 0 && headerRow.GetCell(4).ToString() == "归属月份")
                    {
                        IList <AC_AccountMonth> _monthlist = AC_AccountMonthBLL.GetModelList("Name='" + row.GetCell(4).ToString() + "'");
                        if (_monthlist.Count > 0)
                        {
                            month  = _monthlist[0].ID;
                            minday = _monthlist[0].BeginDate;
                            maxday = DateTime.Today < _monthlist[0].EndDate ? DateTime.Today : _monthlist[0].EndDate;
                        }
                        else
                        {
                            errormessage += "会计月错误;\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                    }
                    #region 组织销量头
                    SVM_SalesVolumeBLL bll      = null;
                    string             conditon = "";

                    conditon = "Supplier=" + clientid.ToString()
                               + "AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',4)='7' AND Type=3 AND AccountMonth=" + month.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                               + " AND Flag=1 AND ISNULL(Promotor,0)=" + promotorid.ToString();

                    IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList(conditon);
                    if (svmlists.Count > 0)
                    {
                        if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null)
                        {
                            errormessage += "ID号:" + row.GetCell(0).ToString() + "," + client.FullName
                                            + ",导购:" + row.GetCell(6).ToString() + "  当月的销量单" + "已审核,不可再次导入!\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                        if (svmlists.Count == 1)
                        {
                            bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                            bll.Items.Clear();
                        }
                    }
                    if (bll == null)
                    {
                        bll = new SVM_SalesVolumeBLL();

                        bll.Model.Client   = 0;
                        bll.Model.Supplier = client.ID;
                        bll.Model.Promotor = promotorid;
                        bll.Model.Type     = 3;


                        bll.Model.OrganizeCity = client.OrganizeCity;
                        bll.Model.AccountMonth = month;
                        bll.Model.SalesDate    = maxday;
                        bll.Model.ApproveFlag  = 2;
                        bll.Model.Flag         = 1;     //成品销售
                        bll.Model["IsCXP"]     = "N";
                        bll.Model.InsertStaff  = 1;
                        bll.Model.Remark       = "线下补录导入";
                    }
                    #endregion
                    bll.Model["SubmitFlag"] = "1";
                    bll.Model["DataSource"] = "7";
                    IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>();
                    bool wrongflag = false;//判断导入数量是否正常(除空导致的异常)
                    int  quantity  = 0;
                    bool isnumber  = false;
                    while (true)
                    {
                        PDT_Product product = null;
                        quantity = 0;

                        if (headerRow.GetCell(datacolumn) == null || headerRow.GetCell(datacolumn).CellType == CellType.BLANK || headerRow.GetCell(datacolumn).ToString() == string.Empty)
                        {
                            break;
                        }

                        IList <PDT_Product> products = PDT_ProductBLL.GetModelList("ShortName='" + headerRow.GetCell(datacolumn).ToString() + "' AND State=1");
                        if (products.Count > 0)
                        {
                            product = products[0];
                        }
                        else
                        {
                            errormessage += "产品名称:" + headerRow.GetCell(datacolumn).ToString() + "在产品列表中不存在!\r\n";
                            datacolumn++;
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }

                        if ((product != null) && row.GetCell(datacolumn).CellType != CellType.BLANK)
                        {
                            int.TryParse(row.GetCell(datacolumn).ToString(), out quantity);
                            if (int.TryParse(row.GetCell(datacolumn).ToString(), out quantity) && !isnumber)
                            {
                                isnumber = true;
                            }
                            if (quantity != 0 && quantity <= 5000 && quantity >= 0)
                            {
                                decimal factoryprice = 0, salesprice = 0;
                                PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 3, out factoryprice, out salesprice);

                                if (factoryprice == 0)
                                {
                                    factoryprice = product.FactoryPrice;
                                }
                                if (salesprice == 0)
                                {
                                    salesprice = product.NetPrice;
                                }

                                SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                                detail.Product      = product.ID;
                                detail.FactoryPrice = factoryprice;
                                detail.SalesPrice   = salesprice;
                                detail.Quantity     = quantity;
                                details.Add(detail);
                            }
                            else if (row.GetCell(datacolumn).CellType != CellType.BLANK && (row.GetCell(datacolumn).ToString() != "0"))
                            {
                                wrongflag = true;
                                break;
                            }
                            else if (quantity < 0)
                            {
                                wrongflag = true;
                                break;
                            }
                        }
                        datacolumn++;
                    }
                    if (wrongflag)
                    {
                        errormessage += "ID号:" + clientid.ToString() + "," + client.FullName
                                        + ",导购:" + row.GetCell(6).ToString() + "  当月的线下补录销量单"
                                        + "未能导入!产品名称:" + headerRow.GetCell(datacolumn).ToString() + "数量填写错误。\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }

                    #region 更新销量至数据库
                    if (bll.Model.ID > 0)
                    {
                        if (details.Count > 0)
                        {
                            bll.DeleteDetail();     //先清除原先导入的数据
                            bll.Items             = details;
                            bll.Model.UpdateStaff = 1;
                            bll.AddDetail();
                            bll.Update();

                            string message = " ID号:" + clientid.ToString() + ",该零售商:" + client.FullName
                                             + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + "的销量单" + "被成功更新!产品SKU数:"
                                             + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n";
                            improtmessage += message;
                            row.CreateCell(column).SetCellValue(message);
                        }
                        if (details.Count == 0 && isnumber)
                        {
                            bll.DeleteDetail();
                        }
                    }
                    else
                    {
                        if (details.Count > 0 || svmlists.Count == 0)    //没有产品也新增一条空销量头
                        {
                            bll.Items = details;
                            if (bll.Add() > 0)
                            {
                                foreach (SVM_SalesVolume m in svmlists)
                                {
                                    bll = new SVM_SalesVolumeBLL(m.ID);
                                    bll.DeleteDetail();
                                    bll.Delete();
                                }
                            }
                            string message = "ID号:" + clientid.ToString() + ",该零售商:" + client.FullName
                                             + "的销量单" + "已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                                             + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n";
                            improtmessage += message;
                            row.CreateCell(column).SetCellValue(message);
                        }
                    }
                    #endregion
                    ((BackgroundWorker)sender).ReportProgress(i * 100 / count, i);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                FileStream writefile = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
                hssfworkbook.Write(writefile);
                writefile.Close();

                sheet = null;
            }
        }
    private void BindGrid()
    {
        DateTime dtBegin      = DateTime.Parse(this.tbx_begin.Text);
        DateTime dtEnd        = DateTime.Parse(this.tbx_end.Text).AddDays(1);
        int      organizecity = int.Parse(tr_OrganizeCity.SelectValue);

        if (tr_detail.Visible)
        {
            string condition = " SVM_SalesVolume.SalesDate between '" + dtBegin.ToString() + "' AND '" + dtEnd.ToString() +
                               "' AND SVM_SalesVolume.Type = 6";

            if (rbl_ApproveFlag.SelectedValue != "0")
            {
                condition += " And SVM_SalesVolume.ApproveFlag =" + rbl_ApproveFlag.SelectedValue;
            }

            //管理片区及所有下属管理片区
            //销量查询可以不根据某个指定的客户,根据一个片区范围来查找
            if (select_Supplier.SelectValue != "")
            {
                condition += " AND SVM_SalesVolume.Supplier = " + select_Supplier.SelectValue;
            }

            if (select_Client.SelectValue != "")
            {
                condition += " AND SVM_SalesVolume.Client =" + select_Client.SelectValue;
            }

            if (organizecity > 1 && select_Supplier.SelectValue == "" && select_Client.SelectValue == "")
            {
                Addr_OrganizeCityBLL orgcity = new Addr_OrganizeCityBLL(organizecity);
                string orgcitys = orgcity.GetAllChildNodeIDs();
                if (orgcitys != "")
                {
                    orgcitys += ",";
                }
                orgcitys += tr_OrganizeCity.SelectValue;

                condition += " AND SVM_SalesVolume.OrganizeCity IN (" + orgcitys + ")";
            }

            gv_List.ConditionString = condition;
            gv_List.BindGrid();
        }
        else
        {
            int supplier = select_Supplier.SelectValue == "" ? 0 : int.Parse(select_Supplier.SelectValue);
            int client   = select_Client.SelectValue == "" ? 0 : int.Parse(select_Client.SelectValue);
            if (organizecity == 0)
            {
                organizecity = 1;
            }

            DataTable dt          = SVM_SalesVolumeBLL.GetSummary(organizecity, supplier, client, dtBegin, dtEnd, 6, 0);
            int       _quantity   = 0;
            decimal   _totalvalue = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                _quantity   += (int)dt.Rows[i]["SumQuantity"];
                _totalvalue += (decimal)dt.Rows[i]["SumFactoryMoney"];
            }
            DataRow dr = dt.NewRow();
            dr["ProductCode"] = "合计";
            dr["SumQuantity"] = _quantity;
            dr["SumMoney"]    = _totalvalue;
            dt.Rows.Add(dr);
            gv_Summary.DataSource = dt;
            gv_Summary.DataBind();
        }
    }
    protected void bt_Import_Click(object sender, EventArgs e)
    {
        string ImportInfo = "";
        lb_ErrorInfo.Text = "";

        System.Data.DataTable dtSellIn = null, dtSellOut = null;

        if (Session["DataTable-SellIn"] != null && Session["DataTable-SellOut"] != null)
        {
            dtSellIn = (System.Data.DataTable)Session["DataTable-SellIn"];
            dtSellOut = (System.Data.DataTable)Session["DataTable-SellOut"];
        }

        #region 获取允许最迟的销量日期
        int JXCDelayDays = ConfigHelper.GetConfigInt("JXCDelayDays");
        AC_AccountMonth month = new AC_AccountMonthBLL(AC_AccountMonthBLL.GetMonthByDate(DateTime.Now.AddDays(-JXCDelayDays))).Model;
        DateTime minday = month.BeginDate;
        DateTime maxday = DateTime.Today < month.EndDate ? DateTime.Today : month.EndDate;
        #endregion

        IList<PDT_Product> productlists = PDT_ProductBLL.GetModelList("Brand IN (SELECT ID FROM dbo.PDT_Brand WHERE IsOpponent='1') AND State=1 AND ApproveFlag=1 ORDER BY ISNULL(SubUnit,999999),Code");

        ImportInfo += "<span style='color: Red'>-------------------------------------------------------------------------</span><br/>";
        ImportInfo += "<span style='color: Red'>----批量导入零售商进货销量----</span><br/>";

        #region 开始导入零售商进货
        foreach (System.Data.DataRow dr in dtSellIn.Rows)
        {
            #region 验证数据
            int clientid = (int)dr["零售商ID"];
            CM_Client client = new CM_ClientBLL(clientid).Model;
            if (client == null || client.FullName != (string)dr["零售商名称"])
            {
                ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商ID与零售商名称不匹配!</span><br/>";
                continue;
            }

            if (dr["归属月份"].ToString() != month.Name)
            {
                ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",归属月份必须为【" + month.Name + "】</span><br/>";
                continue;
            }
            //DateTime salesdate = (DateTime)dr["进货日期"];
            //if (salesdate < minday || salesdate > maxday)
            //{
            //    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",进货日期必须在" + minday.ToString("yyyy-MM-dd") +
            //        "至" + maxday.ToString("yyyy-MM-dd") + "之间!</span><br/>";
            //    continue;
            //}
            #endregion

            #region 组织销量头
            SVM_SalesVolumeBLL bll = null;
            IList<SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList("Client=" + clientid.ToString()
                + " AND Type=2 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',1)='N' ");
            if (svmlists.Count > 0)
            {
                if (svmlists[0].ApproveFlag == 1)
                {
                    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",该零售商当月的进货已审核,不可再次导入!</span><br/>";
                    continue;
                }

                bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                bll.Items.Clear();
            }
            else
            {
                bll = new SVM_SalesVolumeBLL();
                bll.Model.Client = clientid;
                bll.Model.OrganizeCity = client.OrganizeCity;
                bll.Model.Supplier = client.Supplier;
                bll.Model.AccountMonth = month.ID;
                bll.Model.SalesDate = maxday;
                bll.Model.Type = 2;
                bll.Model.ApproveFlag = 2;
                bll.Model.Flag = 1;             //成品销售
                bll.Model["SubmitFlag"] = "1";
                bll.Model["IsCXP"] = "N";
                bll.Model.InsertStaff = (int)Session["UserID"];
                bll.Model.Remark = "Excel批量导入";
            }
            #endregion

            #region 读取各产品销量
            IList<SVM_SalesVolume_Detail> details = new List<SVM_SalesVolume_Detail>();
            foreach (PDT_Product product in productlists)
            {
                int quantity = (int)dr["[" + product.ShortName + "]"];
                if (quantity != 0)
                {
                    decimal factoryprice = 0, salesprice = 0;
                    PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 2, out factoryprice, out salesprice);

                    if (factoryprice == 0) factoryprice = product.FactoryPrice;
                    if (salesprice == 0) salesprice = product.NetPrice;

                    SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                    detail.Product = product.ID;
                    detail.FactoryPrice = factoryprice;
                    detail.SalesPrice = salesprice;
                    detail.Quantity = quantity;

                    details.Add(detail);
                }
            }
            #endregion

            #region 更新销量至数据库
            if (bll.Model.ID > 0)
            {
                if (details.Count > 0)
                {
                    bll.DeleteDetail();     //先清除原先导入的数据

                    bll.Items = details;
                    bll.AddDetail();
                    bll.Update();

                    ImportInfo += "<span style='color: Blue'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName
                        + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + " 的进货单被成功更新!产品SKU数:"
                        + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                }
            }
            else
            {
                //if (details.Count > 0)    //没有产品也新增一条空销量头
                {
                    bll.Items = details;
                    bll.Add();
                    ImportInfo += "<span style='color: Black'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName
                        + " 的进货单已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                        + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                }
            }
            #endregion
        }
        #endregion

        ImportInfo += "<br/><br/>";
        ImportInfo += "<span style='color: Red'>-------------------------------------------------------------------------</span><br/>";
        ImportInfo += "<span style='color: Red'>----批量导入零售商销货销量----</span><br/>";

        #region 开始导入零售商销货
        foreach (System.Data.DataRow dr in dtSellOut.Rows)
        {
            #region 验证数据
            int clientid = (int)dr["零售商ID"];
            CM_Client client = new CM_ClientBLL(clientid).Model;
            if (client == null || client.FullName != (string)dr["零售商名称"])
            {
                ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商ID与零售商名称不匹配!</span><br/>";
                continue;
            }

            if (dr["归属月份"].ToString() != month.Name)
            {
                ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",归属月份必须为【" + month.Name + "】</span><br/>";
                continue;
            }
            //DateTime salesdate = (DateTime)dr["销售日期"];
            //if (salesdate < minday || salesdate > maxday)
            //{
            //    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",销售日期必须在" + minday.ToString("yyyy-MM-dd") +
            //        "至" + maxday.ToString("yyyy-MM-dd") + "之前!</span><br/>";
            //    continue;
            //}

            int promotorid = (int)dr["导购ID"];
            if (promotorid > 0)
            {
                if (PM_PromotorInRetailerBLL.GetModelList("Client=" + client.ID.ToString() +
                    " AND Promotor=" + promotorid.ToString()).Count == 0)
                {
                    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商中没有关联该导购员!</span><br/>";
                    continue;
                }
            }
            #endregion

            #region 组织销量头
            SVM_SalesVolumeBLL bll = null;
            IList<SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList("Supplier=" + clientid.ToString()
                + " AND Type=3 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',1)='N' AND ISNULL(Promotor,0)=" + promotorid.ToString());
            if (svmlists.Count > 0)
            {
                if (svmlists[0].ApproveFlag == 1)
                {
                    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",该零售商当月的销量已审核,不可再次导入!</span><br/>";
                    continue;
                }

                bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                bll.Model["SubmitFlag"] = "1";
                bll.Items.Clear();
            }
            else
            {
                bll = new SVM_SalesVolumeBLL();
                bll.Model.Client = 0;
                bll.Model.OrganizeCity = client.OrganizeCity;
                bll.Model.Supplier = client.ID;
                bll.Model.Promotor = promotorid;
                bll.Model.AccountMonth = month.ID;
                bll.Model.SalesDate = maxday;
                bll.Model.Type = 3;
                bll.Model.ApproveFlag = 2;
                bll.Model.Flag = 1;             //成品销售
                bll.Model["SubmitFlag"] = "1";
                bll.Model["IsCXP"] = "N";
                bll.Model.InsertStaff = (int)Session["UserID"];
                bll.Model.Remark = "Excel批量导入";
            }
            #endregion

            #region 读取各产品销量
            IList<SVM_SalesVolume_Detail> details = new List<SVM_SalesVolume_Detail>();
            foreach (PDT_Product product in productlists)
            {
                int quantity = (int)dr["[" + product.ShortName + "]"];
                if (quantity != 0)
                {
                    decimal factoryprice = 0, salesprice = 0;
                    PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 3, out factoryprice, out salesprice);

                    if (factoryprice == 0) factoryprice = product.FactoryPrice;
                    if (salesprice == 0) salesprice = product.StdPrice;

                    SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                    detail.Product = product.ID;
                    detail.FactoryPrice = factoryprice;
                    detail.SalesPrice = salesprice;
                    detail.Quantity = quantity;

                    details.Add(detail);
                }
            }
            #endregion

            #region 更新销量至数据库
            if (bll.Model.ID > 0)
            {
                if (details.Count > 0)
                {
                    bll.DeleteDetail();     //先清除原先导入的数据

                    bll.Items = details;
                    bll.AddDetail();
                    bll.Update();

                    ImportInfo += "<span style='color: Blue'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName
                        + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + " 的销量单被成功更新!产品SKU数:"
                        + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                }
            }
            else
            {
                //if (details.Count > 0)    //没有产品也新增一条空销量头
                {
                    bll.Items = details;
                    bll.Add();
                    ImportInfo += "<span style='color: Black'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName
                        + " 的销量单已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                        + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                }
            }
            #endregion
        }
        #endregion

        lb_ErrorInfo.Text = ImportInfo;
        bt_Import.Enabled = false;

        Session["DataTable-SellIn"] = null;
        Session["DataTable-SellOut"] = null;
    }
 protected void bt_Submit_Click(object sender, EventArgs e)
 {
     bt_Save_Click(null, null);
     if ((int)ViewState["VolumeID"] > 0)
     {
         SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
         bll.Model["SubmitFlag"] = "1";
         bll.Update();
         if (sender != null)
         {
             MessageBox.ShowAndRedirect(this, "数据提交成功!", "SalesVolumeList.aspx?SellOutClientID=" + bll.Model.Supplier.ToString() +
                  "&SellInClientID=" + bll.Model.Client.ToString() + "&Type=" + ViewState["Type"].ToString());
         }
     }
 }
    protected void bt_Generate_Click(object sender, EventArgs e)
    {
        int month        = int.Parse(ddl_Month.SelectedValue);
        int organizecity = 0;
        int client       = 0;

        int.TryParse(tr_OrganizeCity.SelectValue, out organizecity);
        int.TryParse(select_Client.SelectValue, out client);

        if (organizecity == 0)
        {
            MessageBox.Show(this, "请正确选择管理片区");
            return;
        }

        if (client == 0)
        {
            MessageBox.Show(this, "请正确选择经销商");
            return;
        }

        #region 判断指定区域下是否还有门店销量未审核
        string citys = new Addr_OrganizeCityBLL(organizecity).GetAllChildNodeIDs();
        if (citys == "")
        {
            citys = organizecity.ToString();
        }
        else
        {
            citys += "," + organizecity.ToString();
        }
        string condition = "Type=3 AND Supplier=" + client.ToString() + " AND AccountMonth=" + month.ToString() +
                           " AND OrganizeCity IN (" + citys + ") AND ApproveFlag=2 AND Flag=1 AND EXISTS (SELECT 1 FROM MCS_CM.dbo.CM_Client WHERE ClientType=3 AND CM_Client.ID=SVM_SalesVolume.Client)";

        int counts = SVM_SalesVolumeBLL.GetModelList(condition).Count;
        if (counts > 0)
        {
            MessageBox.Show(this, "对不起,您区域还有" + counts.ToString() + "条门店销量未审核");
            return;
        }
        #endregion

        int FeeType = 0;
        FeeType = ConfigHelper.GetConfigInt("ContractFeeType-FL");

        int id = CM_ContractBLL.CreateFLFeeApply(organizecity, month, client, (int)Session["UserID"], FeeType);

        if (id > 0)
        {
            MessageBox.ShowAndRedirect(this, "返利费用申请单生成成功!", "FeeApplyDetail3.aspx?ID=" + id.ToString());
        }
        else if (id == 0)
        {
            MessageBox.Show(this, "对不起,目前尚无返利合同需要申请费用!");
        }
        else if (id == -1)
        {
            MessageBox.Show(this, "对不起,无返利费用生成!请检查是否有返利店有销量,或是之前已经生成该月的返利费用!");
        }
        else
        {
            MessageBox.Show(this, "对不起,返利合同费用申请单生成失败!错误码:" + id.ToString());
        }
    }
Beispiel #35
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime minday, maxday=DateTime.Now;
            HSSFWorkbook hssfworkbook;
            FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
            hssfworkbook = new HSSFWorkbook(file);
            ISheet sheet = hssfworkbook.GetSheetAt(0);
            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            int i = 0, count = getRowsCount()-1;
            bool flag = true;
            try
            {
                IRow headerRow = sheet.GetRow(0);
                if (headerRow.GetCell(0).ToString() != "零售商ID" ||
                    headerRow.GetCell(1).ToString() != "零售商编号" ||
                    headerRow.GetCell(2).ToString() != "零售商名称" ||
                    headerRow.GetCell(3).ToString() != "零售商分类" ||
                    headerRow.GetCell(4).ToString() != "归属月份" ||
                    headerRow.GetCell(5).ToString() != "导购ID" ||
                    headerRow.GetCell(6).ToString() != "导购姓名")
                {

                    flag = false;
                }
                if (!flag)
                {
                    MessageBox.Show(this, "表头(1~7列)错误!");
                    return;
                }
                int column = getColumnCount(headerRow) + 1;
                int month = 0;
                rows.MoveNext();

                while (rows.MoveNext())
                {
                    int datacolumn = 7;

                    i++;
                    HSSFRow row = (HSSFRow)rows.Current;
                    if (row.GetCell(0).ToString() == "")
                    {
                        break;
                    }

                    int clientid = 0; int promotorid = 0;
                    if (!int.TryParse(row.GetCell(0).ToString(), out clientid))
                    {
                        errormessage += "零售商:" + row.GetCell(2).ToString() + "的ID错误;\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }
                    CM_Client client = new CM_ClientBLL(clientid).Model;

                    if (client == null)
                    {
                        errormessage += "ID号:" + clientid.ToString() + "零售商在系统中不存在!\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }
                    if (int.TryParse(row.GetCell(5).ToString(), out promotorid))
                    {
                        PM_Promotor pm = new PM_PromotorBLL(promotorid).Model;
                        if (pm == null)
                        {
                            errormessage += "导购ID号:" + promotorid.ToString() + "导购在系统中不存在!\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }

                    }

                    if (month == 0 && headerRow.GetCell(4).ToString() == "归属月份")
                    {
                        IList<AC_AccountMonth> _monthlist = AC_AccountMonthBLL.GetModelList("Name='" + row.GetCell(4).ToString() + "'");
                        if (_monthlist.Count > 0)
                        {
                            month = _monthlist[0].ID;
                            minday = _monthlist[0].BeginDate;
                            maxday = DateTime.Today < _monthlist[0].EndDate ? DateTime.Today : _monthlist[0].EndDate;
                        }
                        else
                        {
                            errormessage += "会计月错误;\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                    }
                    #region 组织销量头
                    SVM_SalesVolumeBLL bll = null;
                    string conditon = "";

                    conditon = "Supplier=" + clientid.ToString()
                  + "AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',4)='7' AND Type=3 AND AccountMonth=" + month.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                  + " AND Flag=1 AND ISNULL(Promotor,0)=" + promotorid.ToString();

                    IList<SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList(conditon);
                    if (svmlists.Count > 0)
                    {
                        if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null)
                        {
                            errormessage += "ID号:" + row.GetCell(0).ToString() + "," + client.FullName
                                           + ",导购:" + row.GetCell(6).ToString() + "  当月的销量单" + "已审核,不可再次导入!\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                        if (svmlists.Count == 1)
                        {
                            bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                            bll.Items.Clear();
                        }
                    }
                    if (bll == null)
                    {
                        bll = new SVM_SalesVolumeBLL();

                        bll.Model.Client = 0;
                        bll.Model.Supplier = client.ID;
                        bll.Model.Promotor = promotorid;
                        bll.Model.Type = 3;

                        bll.Model.OrganizeCity = client.OrganizeCity;
                        bll.Model.AccountMonth = month;
                        bll.Model.SalesDate = maxday;
                        bll.Model.ApproveFlag = 2;
                        bll.Model.Flag = 1;             //成品销售
                        bll.Model["IsCXP"] = "N";
                        bll.Model.InsertStaff = 1;
                        bll.Model.Remark = "线下补录导入";

                    }
                    #endregion
                    bll.Model["SubmitFlag"] = "1";
                    bll.Model["DataSource"] = "7";
                    IList<SVM_SalesVolume_Detail> details = new List<SVM_SalesVolume_Detail>();
                    bool wrongflag = false;//判断导入数量是否正常(除空导致的异常)
                    int quantity = 0;
                    bool isnumber = false;
                    while (true)
                    {

                        PDT_Product product = null;
                        quantity = 0;

                        if (headerRow.GetCell(datacolumn) == null||headerRow.GetCell(datacolumn).CellType == CellType.BLANK || headerRow.GetCell(datacolumn).ToString() == string.Empty)
                        {
                            break;
                        }

                        IList<PDT_Product> products = PDT_ProductBLL.GetModelList("ShortName='" + headerRow.GetCell(datacolumn).ToString() + "' AND State=1");
                        if (products.Count > 0)
                        {
                            product = products[0];
                        }
                        else
                        {
                            errormessage += "产品名称:" + headerRow.GetCell(datacolumn).ToString() + "在产品列表中不存在!\r\n";
                            datacolumn++;
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }

                        if ((product != null) && row.GetCell(datacolumn).CellType != CellType.BLANK)
                        {
                            int.TryParse(row.GetCell(datacolumn).ToString(), out quantity);
                            if (int.TryParse(row.GetCell(datacolumn).ToString(), out quantity) && !isnumber)
                            {
                                isnumber = true;
                            }
                            if (quantity != 0 && quantity <= 5000 && quantity >= 0)
                            {

                                decimal factoryprice = 0, salesprice = 0;
                                PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 3, out factoryprice, out salesprice);

                                if (factoryprice == 0) factoryprice = product.FactoryPrice;
                                if (salesprice == 0) salesprice = product.NetPrice;

                                SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                                detail.Product = product.ID;
                                detail.FactoryPrice = factoryprice;
                                detail.SalesPrice = salesprice;
                                detail.Quantity = quantity;
                                details.Add(detail);
                            }
                            else if (row.GetCell(datacolumn).CellType != CellType.BLANK && (row.GetCell(datacolumn).ToString() != "0"))
                            {
                                wrongflag = true;
                                break;
                            }
                            else if (quantity < 0)
                            {
                                wrongflag = true;
                                break;
                            }
                        }
                        datacolumn++;

                    }
                    if (wrongflag)
                    {
                        errormessage += "ID号:" + clientid.ToString() + "," + client.FullName
                                     + ",导购:" + row.GetCell(6).ToString() + "  当月的线下补录销量单"
                                          + "未能导入!产品名称:" + headerRow.GetCell(datacolumn).ToString() + "数量填写错误。\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }

                    #region 更新销量至数据库
                    if (bll.Model.ID > 0)
                    {
                        if (details.Count > 0)
                        {
                            bll.DeleteDetail();     //先清除原先导入的数据
                            bll.Items = details;
                            bll.Model.UpdateStaff = 1;
                            bll.AddDetail();
                            bll.Update();

                            string message = " ID号:" + clientid.ToString() + ",该零售商:" + client.FullName
                                + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + "的销量单" + "被成功更新!产品SKU数:"
                          + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n";
                            improtmessage += message;
                            row.CreateCell(column).SetCellValue(message);
                        }
                        if (details.Count == 0 && isnumber)
                        {
                            bll.DeleteDetail();
                        }

                    }
                    else
                    {
                        if (details.Count > 0 || svmlists.Count == 0)    //没有产品也新增一条空销量头
                        {
                            bll.Items = details;
                            if (bll.Add() > 0)
                            {
                                foreach (SVM_SalesVolume m in svmlists)
                                {
                                    bll = new SVM_SalesVolumeBLL(m.ID);
                                    bll.DeleteDetail();
                                    bll.Delete();
                                }
                            }
                            string message = "ID号:" + clientid.ToString() + ",该零售商:" + client.FullName
                          + "的销量单" + "已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                         + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n";
                            improtmessage += message;
                            row.CreateCell(column).SetCellValue(message);
                        }
                    }
                    #endregion
                    ((BackgroundWorker)sender).ReportProgress(i * 100 / count, i);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
            finally
            {
                FileStream writefile = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
                hssfworkbook.Write(writefile);
                writefile.Close();

                sheet = null;
            }
        }
Beispiel #36
0
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        SaveMyViewState();
        CM_Client _r = new CM_ClientBLL((int)ViewState["ClientID"]).Model;

        #region 更新销量内容

        #region 保存销量头信息
        SVM_SalesVolumeBLL bll;
        //成/赠品进货
        IList <SVM_SalesVolume> svmlists = new List <SVM_SalesVolume>();
        string conditon = "";
        string message  = "";
        if (!(bool)ViewState["IsCXP"])
        {
            switch (ViewState["Type"].ToString())
            {
            case "1":
            case "2":
                conditon = "Client=" + _r.ID.ToString()
                           + " AND Type IN(1,2) AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                           + " AND Flag=" + ddl_Flag.SelectedValue;
                message = "该客户当月的进货已审核,不可再次录入";
                break;

            case "3":
                conditon = "Supplier=" + _r.ID.ToString()
                           + " AND Type=3 AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                           + " AND Flag=" + ddl_Flag.SelectedValue + " AND ISNULL(Promotor,0)=" + ddl_Promotor.SelectedValue;
                message = "该客户当月的销量已审核,不可再次录入";
                break;
            }
        }
        else //判断是否有过门店赠品进货
        {
            switch (ViewState["Type"].ToString())
            {
            case "1":
            case "2":
                conditon = "Client=" + _r.ID.ToString()
                           + " AND Type IN(1,2) AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                           + " AND Flag=" + ddl_Flag.SelectedValue;
                message = "该客户当月的赠品进货已审核,不可再次录入";
                break;

            case "3":
                conditon = "Client=" + _r.ID.ToString()
                           + " AND Type=3 AND AccountMonth=" + ddl_AccountMonth.SelectedValue
                           + " AND Flag=" + ddl_Flag.SelectedValue;
                message = "该客户当月的赠品销量已审核,不可再次录入";
                break;
            }
        }
        svmlists = SVM_SalesVolumeBLL.GetModelList(conditon + " AND InsertStaff!=1");
        if (svmlists.Count > 0)
        {
            if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null)
            {
                MessageBox.Show(this, message);
                return;
            }
            if (svmlists.Count == 1)
            {
                ViewState["VolumeID"] = svmlists[0].ID;
            }
        }
        if ((int)ViewState["VolumeID"] == 0)
        {
            foreach (SVM_SalesVolume m in svmlists)
            {
                bll = new SVM_SalesVolumeBLL(m.ID);
                bll.DeleteDetail();
                bll.Delete();
            }

            bll                     = new SVM_SalesVolumeBLL();
            bll.Model.Type          = (int)ViewState["Type"];
            bll.Model.OrganizeCity  = _r.OrganizeCity;
            bll.Model["DataSource"] = "4";
            if (bll.Model.Type == 3)
            {
                //门店销售
                bll.Model.Supplier = _r.ID;
                bll.Model.Promotor = int.Parse(ddl_Promotor.SelectedValue);
            }
            else
            {
                bll.Model.Client = _r.ID;
                if (ddl_SellOutClient.Visible)
                {
                    bll.Model.Supplier = int.Parse(ddl_SellOutClient.SelectedValue);
                }
                else
                {
                    bll.Model.Supplier = _r.Supplier;
                }
            }
            bll.Model.InsertStaff = (int)Session["UserID"];
        }
        else
        {
            bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Model.UpdateStaff = (int)Session["UserID"];
        }

        bll.Model.SalesDate    = DateTime.Parse(this.tbx_VolumeDate.Text.Trim());
        bll.Model.AccountMonth = int.Parse(ddl_AccountMonth.SelectedValue);
        bll.Model.Flag         = int.Parse(ddl_Flag.SelectedValue);
        bll.Model.SheetCode    = tbx_sheetCode.Text;
        bll.Model.Remark       = tbx_Remark.Text;

        if (bll.Model.Type == 3)
        {
            //门店销售时记录导购员
            bll.Model.Promotor = int.Parse(ddl_Promotor.SelectedValue);
        }

        bll.Model["SubmitFlag"] = "2";

        if ((int)ViewState["VolumeID"] == 0)
        {
            ViewState["VolumeID"] = bll.Add();
        }
        else
        {
            bll.Update();
        }
        #endregion

        #region 更新产品明细数据
        DataTable dt = (DataTable)ViewState["DTDetail"];
        foreach (DataRow dr in dt.Rows)
        {
            int product  = (int)dr["ID"];
            int quantity = (int)dr["Quantity"];
            if (quantity > 5000 && bll.Model.Type == 3)
            {
                MessageBox.Show(this, "超过系统设置的销量上限5000");
                return;
            }

            if ((bll.Model.Flag == 2 || bll.Model.Flag == 3 || bll.Model.Flag == 12) && quantity > 0)
            {
                quantity = 0 - quantity;       //退货时,数量保存为负数 (2:原价退货 3:折价退货 12:赠品退货)
            }
            SVM_SalesVolume_Detail _detail = bll.Items.FirstOrDefault(m => m.Product == product);
            if (_detail == null)
            {
                //销量明细里不存在该产品的记录
                if (quantity == 0)
                {
                    continue;                    //新增销量时,数量为0的不保存到数据库中
                }
                _detail              = new SVM_SalesVolume_Detail();
                _detail.Product      = product;
                _detail.SalesPrice   = (decimal)dr["Price"];
                _detail.Quantity     = quantity;
                _detail.FactoryPrice = (decimal)dr["FactoryPrice"];
                bll.AddDetail(_detail);
            }
            else
            {
                //销量明细里已存在该产品的记录
                if (quantity == 0)
                {
                    bll.DeleteDetail(_detail.ID);
                    continue;
                }
                else if (_detail.Quantity != quantity || _detail.SalesPrice != (decimal)dr["Price"])
                {
                    _detail.SalesPrice = (decimal)dr["Price"];
                    _detail.Quantity   = quantity;
                    bll.UpdateDetail(_detail);
                }
            }
        }
        #endregion

        #endregion

        if (ddl_Promotor.Items.Count > 2)
        {
            MessageBox.Show(this, "本店有" + (ddl_Promotor.Items.Count - 1).ToString() + "个导购员,请确定每个导购员均已录入了销量");
        }
        if (sender != null)
        {
            MessageBox.ShowAndRedirect(this, "数据暂存成功,并在所有门店及经分销商的销量全部录入完成后,及时到汇总页面统一提交!",
                                       "SalesVolumeBatchInput.aspx?VolumeID=" + ViewState["VolumeID"].ToString());
        }
    }
    protected void bt_Delete_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["VolumeID"] != 0)
        {
            SVM_SalesVolumeBLL bll = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]);
            bll.Delete();

            MessageBox.ShowAndRedirect(this, "数据删除成功!", "SalesVolumeList.aspx?SellOutClientID=" + bll.Model.Supplier.ToString() +
                "&SellInClientID=" + bll.Model.Client.ToString() + "&Type=" + ViewState["Type"].ToString());
        }
    }
        private string ImportGifts(Worksheet worksheet, string remark, AC_AccountMonth month, int insertstaff, IList<PDT_Product> productlists, out int State)
        {
            string ImportInfo = "";
            int cloumn = 6;
            int sellinrow = 1;
            DateTime maxday = DateTime.Today < month.EndDate ? DateTime.Today : month.EndDate;

            ImportInfo += "<br/>";
            ImportInfo += "<span style='color: Red'>-------------------------------------------------------------------------</span><br/>";
            ImportInfo += "<span style='color: Red'>----" + remark + "----</span><br/>";

            State = 0;
            PDT_Product product;

            #region 读取Excel表格
            while (true)
            {

                cloumn = 6;
                sellinrow++;

                if (((Range)worksheet.Cells[sellinrow, 1]).Value2 == null)
                {
                    break;
                }

                int clientid = 0;
                if (!int.TryParse(((Range)worksheet.Cells[sellinrow, 1]).Value2.ToString(), out clientid))
                {
                    continue;
                }
                #region 验证数据
                CM_Client client = new CM_ClientBLL(clientid).Model;
                if (client == null || client.FullName != ((Range)worksheet.Cells[sellinrow, 3]).Text.ToString())
                {

                    ImportInfo += "<span style='color: Red'>ID号:" + ((Range)worksheet.Cells[sellinrow, 1]).Text.ToString() + (client.ClientType == 3 ? ",零售商ID与零售商名称" : ",分销商ID与分销商名称") + "不匹配!</span><br/>";

                    State = 4;
                    continue;
                }
                int uplimit = client.ClientType == 3 ? 5000 : 9000;
                if (((Range)worksheet.Cells[sellinrow, 5]).Text.ToString() != month.Name)
                {
                    ImportInfo += "<span style='color: Red'>ID号:" + ((Range)worksheet.Cells[sellinrow, 1]).Text.ToString() + ",归属月份必须为【" + month.Name + "】</span><br/>";
                    State = 4;
                    continue;
                }
                #endregion

                #region 组织销量头
                SVM_SalesVolumeBLL bll = null;
                IList<SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList("Client=" + clientid.ToString() + " AND InsertStaff!=1"
                    + " AND Type IN(1,2) AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                    + " AND Flag=11 AND (Remark='" + remark + "' OR Remark NOT IN ('Excel批量导入本品赠品','Excel批量导入试用装赠品','Excel批量导入高值促销品'))");
                if (svmlists.Count > 0)
                {
                    if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null)
                    {
                        ImportInfo += "<span style='color: Red'>ID号:" + ((Range)worksheet.Cells[sellinrow, 1]).Text.ToString() + (client.ClientType == 3 ? ",该零售商" : ",该分销商") + "当月的本品赠品进货已审核,不可再次导入!</span><br/>";
                        continue;
                    }
                    //仅存在一条符合条件的赠品,进行覆盖
                    if (svmlists.Count == 1 && svmlists[0].Remark == remark)
                    {
                        bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                        bll.Items.Clear();
                    }
                }
                if (bll == null)
                {
                    bll = new SVM_SalesVolumeBLL();
                    bll.Model.Client = clientid;
                    bll.Model.OrganizeCity = client.OrganizeCity;
                    bll.Model.Supplier = client.Supplier;
                    bll.Model.AccountMonth = month.ID;
                    bll.Model.SalesDate = maxday;
                    bll.Model.Type = 2;
                    bll.Model.ApproveFlag = 2;
                    bll.Model.Flag = 11;             //赠品进货
                    bll.Model["IsCXP"] = "Y";
                    bll.Model.InsertStaff = insertstaff;
                    bll.Model.Remark = remark;
                }
                #endregion

                bll.Model["SubmitFlag"] = "1";

                IList<SVM_SalesVolume_Detail> details = new List<SVM_SalesVolume_Detail>();
                int quantity = 0;
                bool wrongflag = false;//判断导入数量是否正常(除空导致的异常)
                bool isnumber = false;
                while (true)
                {

                    if (((Range)worksheet.Cells[1, cloumn]).Text.ToString() == string.Empty)
                    {
                        break;
                    }

                    IList<PDT_Product> products = PDT_ProductBLL.GetModelList("ShortName='" + ((Range)worksheet.Cells[1, cloumn]).Text + "' AND State=1");
                    if (products.Count > 0)
                    {
                        product = products[0];
                    }
                    else
                    {
                        ImportInfo += "<span style='color: Red'>赠品产品名称:" + ((Range)worksheet.Cells[1, cloumn]).Text + "在赠品列表中不存在!</span><br/>";
                        State = 4;
                        cloumn++;
                        continue;
                    }
                    if (product != null && ((Range)worksheet.Cells[sellinrow, cloumn]).Value2 != null)
                    {
                        #region 读取各产品销量

                        if (!isnumber && int.TryParse(((Range)worksheet.Cells[sellinrow, cloumn]).Value2.ToString(), out quantity))
                        {
                            isnumber = true;
                        }
                        if (quantity != 0 && quantity <= uplimit && quantity >= 0)
                        {
                            decimal factoryprice = 0, salesprice = 0;
                            PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 2, out factoryprice, out salesprice);

                            if (factoryprice == 0) factoryprice = product.FactoryPrice;
                            if (salesprice == 0) salesprice = product.NetPrice;

                            SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                            detail.Product = product.ID;
                            detail.FactoryPrice = factoryprice;
                            detail.SalesPrice = salesprice;
                            detail.Quantity = quantity;
                            details.Add(detail);
                        }
                        else if (trim(((Range)worksheet.Cells[sellinrow, cloumn]).Text.ToString()) != "" && ((Range)worksheet.Cells[sellinrow, cloumn]).Text.ToString() != "0")
                        {
                            wrongflag = true;
                            break;
                        }
                        #endregion
                    }
                    cloumn++;
                }
                if (wrongflag)
                {
                    ImportInfo += "<span style='color: Red'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",零售商" : ",分销商:") + client.FullName
                                       + "的赠品进货单未能导入,赠品名称:" + ((Range)worksheet.Cells[1, cloumn]).Text + "数量填写错误";
                    State = 4;
                    continue;
                }
                #region 更新销量至数据库
                if (bll.Model.ID > 0)
                {
                    if (details.Count > 0)
                    {
                        bll.DeleteDetail();     //先清除原先导入的数据
                        bll.Model.UpdateStaff = insertstaff;
                        bll.Items = details;
                        bll.AddDetail();
                        bll.Update();
                        ImportInfo += "<span style='color: Blue'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",零售商:" : ",分销商:") + client.FullName
                      + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + " 的赠品进货单被成功更新!产品SKU数:"
                      + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";

                    }
                    if (details.Count == 0 && isnumber)
                    {
                        bll.DeleteDetail();
                    }
                }
                else
                {
                    if (details.Count > 0 || svmlists.Count == 0)    //没有产品也新增一条空销量头
                    {
                        bll.Items = details;

                        if (bll.Add() > 0)
                        {
                            foreach (SVM_SalesVolume m in svmlists)
                            {
                                bll = new SVM_SalesVolumeBLL(m.ID);
                                bll.DeleteDetail();
                                bll.Delete();
                            }
                        }
                        ImportInfo += "<span style='color: Black'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",零售商:" : ",分销商:") + client.FullName
                      + " 的赠品进货单已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                      + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                    }
                }

                #endregion
            }
            #endregion

            return ImportInfo;
        }
    protected void bt_Import_Click(object sender, EventArgs e)
    {
        string ImportInfo = "";

        lb_ErrorInfo.Text = "";

        System.Data.DataTable dtSellIn = null, dtSellOut = null;

        if (Session["DataTable-SellIn"] != null && Session["DataTable-SellOut"] != null)
        {
            dtSellIn  = (System.Data.DataTable)Session["DataTable-SellIn"];
            dtSellOut = (System.Data.DataTable)Session["DataTable-SellOut"];
        }

        #region 获取允许最迟的销量日期
        int             JXCDelayDays = ConfigHelper.GetConfigInt("JXCDelayDays");
        AC_AccountMonth month        = new AC_AccountMonthBLL(AC_AccountMonthBLL.GetMonthByDate(DateTime.Now.AddDays(-JXCDelayDays))).Model;
        DateTime        minday       = month.BeginDate;
        DateTime        maxday       = DateTime.Today < month.EndDate ? DateTime.Today : month.EndDate;
        #endregion

        IList <PDT_Product> productlists = PDT_ProductBLL.GetModelList("Brand IN (SELECT ID FROM dbo.PDT_Brand WHERE IsOpponent='1') AND State=1 AND ApproveFlag=1 ORDER BY ISNULL(SubUnit,999999),Code");

        ImportInfo += "<span style='color: Red'>-------------------------------------------------------------------------</span><br/>";
        ImportInfo += "<span style='color: Red'>----批量导入零售商进货销量----</span><br/>";

        #region 开始导入零售商进货
        foreach (System.Data.DataRow dr in dtSellIn.Rows)
        {
            #region 验证数据
            int       clientid = (int)dr["零售商ID"];
            CM_Client client   = new CM_ClientBLL(clientid).Model;
            if (client == null || client.FullName != (string)dr["零售商名称"])
            {
                ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商ID与零售商名称不匹配!</span><br/>";
                continue;
            }

            if (dr["归属月份"].ToString() != month.Name)
            {
                ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",归属月份必须为【" + month.Name + "】</span><br/>";
                continue;
            }
            //DateTime salesdate = (DateTime)dr["进货日期"];
            //if (salesdate < minday || salesdate > maxday)
            //{
            //    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",进货日期必须在" + minday.ToString("yyyy-MM-dd") +
            //        "至" + maxday.ToString("yyyy-MM-dd") + "之间!</span><br/>";
            //    continue;
            //}
            #endregion

            #region 组织销量头
            SVM_SalesVolumeBLL      bll      = null;
            IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList("Client=" + clientid.ToString()
                                                                               + " AND Type=2 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                                                                               + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',1)='N' ");
            if (svmlists.Count > 0)
            {
                if (svmlists[0].ApproveFlag == 1)
                {
                    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",该零售商当月的进货已审核,不可再次导入!</span><br/>";
                    continue;
                }

                bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                bll.Items.Clear();
            }
            else
            {
                bll = new SVM_SalesVolumeBLL();
                bll.Model.Client        = clientid;
                bll.Model.OrganizeCity  = client.OrganizeCity;
                bll.Model.Supplier      = client.Supplier;
                bll.Model.AccountMonth  = month.ID;
                bll.Model.SalesDate     = maxday;
                bll.Model.Type          = 2;
                bll.Model.ApproveFlag   = 2;
                bll.Model.Flag          = 1;    //成品销售
                bll.Model["SubmitFlag"] = "1";
                bll.Model["IsCXP"]      = "N";
                bll.Model.InsertStaff   = (int)Session["UserID"];
                bll.Model.Remark        = "Excel批量导入";
            }
            #endregion

            #region 读取各产品销量
            IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>();
            foreach (PDT_Product product in productlists)
            {
                int quantity = (int)dr["[" + product.ShortName + "]"];
                if (quantity != 0)
                {
                    decimal factoryprice = 0, salesprice = 0;
                    PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 2, out factoryprice, out salesprice);

                    if (factoryprice == 0)
                    {
                        factoryprice = product.FactoryPrice;
                    }
                    if (salesprice == 0)
                    {
                        salesprice = product.NetPrice;
                    }

                    SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                    detail.Product      = product.ID;
                    detail.FactoryPrice = factoryprice;
                    detail.SalesPrice   = salesprice;
                    detail.Quantity     = quantity;

                    details.Add(detail);
                }
            }
            #endregion

            #region 更新销量至数据库
            if (bll.Model.ID > 0)
            {
                if (details.Count > 0)
                {
                    bll.DeleteDetail();     //先清除原先导入的数据

                    bll.Items = details;
                    bll.AddDetail();
                    bll.Update();

                    ImportInfo += "<span style='color: Blue'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName
                                  + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + " 的进货单被成功更新!产品SKU数:"
                                  + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                }
            }
            else
            {
                //if (details.Count > 0)    //没有产品也新增一条空销量头
                {
                    bll.Items = details;
                    bll.Add();
                    ImportInfo += "<span style='color: Black'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName
                                  + " 的进货单已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                                  + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                }
            }
            #endregion
        }
        #endregion

        ImportInfo += "<br/><br/>";
        ImportInfo += "<span style='color: Red'>-------------------------------------------------------------------------</span><br/>";
        ImportInfo += "<span style='color: Red'>----批量导入零售商销货销量----</span><br/>";

        #region 开始导入零售商销货
        foreach (System.Data.DataRow dr in dtSellOut.Rows)
        {
            #region 验证数据
            int       clientid = (int)dr["零售商ID"];
            CM_Client client   = new CM_ClientBLL(clientid).Model;
            if (client == null || client.FullName != (string)dr["零售商名称"])
            {
                ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商ID与零售商名称不匹配!</span><br/>";
                continue;
            }

            if (dr["归属月份"].ToString() != month.Name)
            {
                ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",归属月份必须为【" + month.Name + "】</span><br/>";
                continue;
            }
            //DateTime salesdate = (DateTime)dr["销售日期"];
            //if (salesdate < minday || salesdate > maxday)
            //{
            //    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",销售日期必须在" + minday.ToString("yyyy-MM-dd") +
            //        "至" + maxday.ToString("yyyy-MM-dd") + "之前!</span><br/>";
            //    continue;
            //}

            int promotorid = (int)dr["导购ID"];
            if (promotorid > 0)
            {
                if (PM_PromotorInRetailerBLL.GetModelList("Client=" + client.ID.ToString() +
                                                          " AND Promotor=" + promotorid.ToString()).Count == 0)
                {
                    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商中没有关联该导购员!</span><br/>";
                    continue;
                }
            }
            #endregion

            #region 组织销量头
            SVM_SalesVolumeBLL      bll      = null;
            IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList("Supplier=" + clientid.ToString()
                                                                               + " AND Type=3 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                                                                               + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',1)='N' AND ISNULL(Promotor,0)=" + promotorid.ToString());
            if (svmlists.Count > 0)
            {
                if (svmlists[0].ApproveFlag == 1)
                {
                    ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",该零售商当月的销量已审核,不可再次导入!</span><br/>";
                    continue;
                }

                bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                bll.Model["SubmitFlag"] = "1";
                bll.Items.Clear();
            }
            else
            {
                bll = new SVM_SalesVolumeBLL();
                bll.Model.Client        = 0;
                bll.Model.OrganizeCity  = client.OrganizeCity;
                bll.Model.Supplier      = client.ID;
                bll.Model.Promotor      = promotorid;
                bll.Model.AccountMonth  = month.ID;
                bll.Model.SalesDate     = maxday;
                bll.Model.Type          = 3;
                bll.Model.ApproveFlag   = 2;
                bll.Model.Flag          = 1;    //成品销售
                bll.Model["SubmitFlag"] = "1";
                bll.Model["IsCXP"]      = "N";
                bll.Model.InsertStaff   = (int)Session["UserID"];
                bll.Model.Remark        = "Excel批量导入";
            }
            #endregion

            #region 读取各产品销量
            IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>();
            foreach (PDT_Product product in productlists)
            {
                int quantity = (int)dr["[" + product.ShortName + "]"];
                if (quantity != 0)
                {
                    decimal factoryprice = 0, salesprice = 0;
                    PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 3, out factoryprice, out salesprice);

                    if (factoryprice == 0)
                    {
                        factoryprice = product.FactoryPrice;
                    }
                    if (salesprice == 0)
                    {
                        salesprice = product.StdPrice;
                    }

                    SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                    detail.Product      = product.ID;
                    detail.FactoryPrice = factoryprice;
                    detail.SalesPrice   = salesprice;
                    detail.Quantity     = quantity;

                    details.Add(detail);
                }
            }
            #endregion

            #region 更新销量至数据库
            if (bll.Model.ID > 0)
            {
                if (details.Count > 0)
                {
                    bll.DeleteDetail();     //先清除原先导入的数据

                    bll.Items = details;
                    bll.AddDetail();
                    bll.Update();

                    ImportInfo += "<span style='color: Blue'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName
                                  + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + " 的销量单被成功更新!产品SKU数:"
                                  + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                }
            }
            else
            {
                //if (details.Count > 0)    //没有产品也新增一条空销量头
                {
                    bll.Items = details;
                    bll.Add();
                    ImportInfo += "<span style='color: Black'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName
                                  + " 的销量单已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                                  + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>";
                }
            }
            #endregion
        }
        #endregion

        lb_ErrorInfo.Text = ImportInfo;
        bt_Import.Enabled = false;

        Session["DataTable-SellIn"]  = null;
        Session["DataTable-SellOut"] = null;
    }
Beispiel #40
0
    protected void bt_Generate_Click(object sender, EventArgs e)
    {
        int organizecity = 0;
        int client       = 0;
        int month        = 0;

        int.TryParse(tr_OrganizeCity.SelectValue, out organizecity);
        int.TryParse(select_Client.SelectValue, out client);
        int.TryParse(ddl_Month.SelectedValue, out month);

        if (organizecity == 0)
        {
            MessageBox.Show(this, "请选择管理片区!");
            return;
        }

        if (client == 0)
        {
            MessageBox.Show(this, "请选择经销商!");
            return;
        }

        #region 判断指定区域下是否还有门店销量未审核

        Addr_OrganizeCityBLL _bll = new Addr_OrganizeCityBLL(organizecity);
        if (_bll.Model.Level < ConfigHelper.GetConfigInt("OrganizeCity-CityLevel"))
        {
            MessageBox.Show(this, "对不起,导购工资不能在营业部及以上层级生成!");
            return;
        }

        string citys = _bll.GetAllChildNodeIDs();
        if (citys == "")
        {
            citys = organizecity.ToString();
        }
        else
        {
            citys += "," + organizecity.ToString();
        }
        string condition = "Type=3 AND AccountMonth=" + month.ToString() +
                           " AND Promotor IS NOT NULL AND OrganizeCity IN (" + citys + ") AND ApproveFlag=2 AND Flag=1";

        int counts = SVM_SalesVolumeBLL.GetModelList(condition).Count;
        if (counts > 0)
        {
            MessageBox.Show(this, "对不起,您区域还有" + counts.ToString() + "条导购销量未审核");
            return;
        }
        #endregion

        int id = PM_SalaryBLL.GenerateSalary(organizecity, client, month, (int)Session["UserID"]);

        if (id > 0)
        {
            MessageBox.ShowAndRedirect(this, "导购员工资生成成功,请及时核对工资信息并提交!", "PM_SalaryList.aspx?Client=" + select_Client.SelectValue);
        }
        else if (id == 0)
        {
            MessageBox.Show(this, "对不起,该经销商下无导购员需要生成工资!");
        }
        else if (id == -1)
        {
            MessageBox.Show(this, "对不起,该月该经销商已有导购员工资生成!,请选择正确的会计月与经销商!");
        }
        else if (id == -2)
        {
            MessageBox.Show(this, "对不起,该经销商下不存在导购员!");
        }
        else if (id == -3)
        {
            MessageBox.ShowAndRedirect(this, "对不起,请先维护导购员的奖惩调整项,并且审核之后才能生成工资!", "PM_SalaryDataObject.aspx?AccountMonth=" + month.ToString());
        }
        else if (id == -4)
        {
            MessageBox.Show(this, "对不起,有部分导购员的薪酬定义没有正确维护,请正确设定薪酬定义信息后,再生成工资!");
        }
        else
        {
            MessageBox.Show(this, "对不起,导购员工资生成失败!错误码:" + id.ToString());
        }
    }