protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        IList <CAT_FeeApplyDetail> _details = (IList <CAT_FeeApplyDetail>)ViewState["FeeListDetails"];
        CAT_FeeApplyDetail         _m       = new CAT_FeeApplyDetail();
        int client = 0;

        int.TryParse(select_Client.SelectValue, out client);
        _m.Client       = client;
        _m.AccountTitle = int.Parse(ddl_AccountTitle.SelectedValue);
        if (TreeTableBLL.GetChild("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", _m.AccountTitle).Rows.Count > 0)
        {
            MessageBox.Show(this, "费用科目必须选择最底级会计科目!" + ddl_AccountTitle.SelectedItem.Text);
            return;
        }
        _m.ApplyCost = decimal.Parse(tbx_ApplyCost.Text.Trim());
        _m.DICost    = decimal.Parse(tbx_DICost.Text.Trim());
        _m.Remark    = tbx_Remark.Text.Trim();
        if ((int)ViewState["ID"] != 0)
        {
            _m.BeginMonth = AC_AccountMonthBLL.GetMonthByDate(new CAT_ActivityBLL((int)ViewState["ID"]).Model.PlanBeginDate);
            _m.Activity   = (int)ViewState["ID"];
        }
        else
        {
            _m.BeginMonth = AC_AccountMonthBLL.GetCurrentMonth();
        }
        if (_details.Where(p => p.Client == client && p.AccountTitle == _m.AccountTitle).Count() == 0)
        {
            if (_m.Activity > 0)
            {
                CAT_FeeApplyDetailBLL _bll = new CAT_FeeApplyDetailBLL();
                _bll.Model = _m;
                _bll.Add();
            }
            _details.Add(_m);
            BindGrid();
        }
    }
    protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        ListTable <CM_ContractDetail> _details = ViewState["Details"] as ListTable <CM_ContractDetail>;

        DateTime begindate     = new DateTime();
        DateTime enddate       = new DateTime();
        TextBox  tbx_BeginDate = pl_detail.FindControl("CM_Contract_BeginDate") == null ? null : (TextBox)pl_detail.FindControl("CM_Contract_BeginDate");
        TextBox  tbx_EndDate   = pl_detail.FindControl("CM_Contract_EndDate") == null ? null : (TextBox)pl_detail.FindControl("CM_Contract_EndDate");

        if (tbx_BeginDate != null && tbx_EndDate != null)
        {
            DateTime.TryParse(tbx_BeginDate.Text, out begindate);
            DateTime.TryParse(tbx_EndDate.Text, out enddate);
            if (enddate < begindate)
            {
                MessageBox.Show(this, "协议终止日期不能小于起始日期。");
                return;
            }
        }

        if (ddl_PayMode.SelectedValue == "0")
        {
            MessageBox.Show(this, "付款周期必选!");
            return;
        }


        CM_ContractDetail item;

        if (ViewState["Selected"] == null)
        {
            //新增科目
            if (_details.Contains(ddl_AccountTitle.SelectedValue))
            {
                MessageBox.Show(this, "该科目已添加!");
                return;
            }

            item = new CM_ContractDetail();
            item.AccountTitle = int.Parse(ddl_AccountTitle.SelectedValue);
            if (TreeTableBLL.GetChild("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", item.AccountTitle).Rows.Count > 0)
            {
                MessageBox.Show(this, "费用科目必须选择最底级会计科目!" + ddl_AccountTitle.SelectedItem.Text);
                return;
            }
        }
        else
        {//修改科目
            if (!_details.Contains(ddl_AccountTitle.SelectedValue))
            {
                MessageBox.Show(this, "要修改的项目不存在!");
                return;
            }
            item = _details[ViewState["Selected"].ToString()];
        }
        item.ApplyLimit = decimal.Parse(tbx_ApplyLimit.Text);
        if (item.ApplyLimit == 0)
        {
            MessageBox.Show(this, "对不起,月费用金额不能为0!");
            return;
        }
        item.PayMode = int.Parse(ddl_PayMode.SelectedValue);

        if (ViewState["Selected"] == null)
        {
            _details.Add(item);
        }
        else
        {
            _details.Update(item);
        }

        BindGrid();

        tbx_ApplyLimit.Text   = "0";
        bt_AddDetail.Text     = "新增";
        ViewState["Selected"] = null;
    }
    protected void bt_Generate_Click(object sender, EventArgs e)
    {
        decimal giftamountbalance = 0;
        int     month = 0, city = 0, feetype = 0, client = 0, productbrand = 0, giftclassify = 0;

        feetype = (int)ViewState["GiftFeeType"];

        int.TryParse(ddl_ApplyMonth.SelectedValue, out month);
        int.TryParse(tr_OrganizeCity.SelectValue, out city);
        int.TryParse(select_Client.SelectValue, out client);
        int.TryParse(ddl_Brand.SelectedValue, out productbrand);
        int.TryParse(rbl_GiftClassify.SelectedValue, out giftclassify);

        #region 判断有效性
        if (city == 0)
        {
            MessageBox.Show(this, "请正确选择管理片区");
            return;
        }

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

        if (productbrand == 0)
        {
            MessageBox.Show(this, "请正确选择赠品费用归属品牌");
            return;
        }
        giftamountbalance = GetGiftAmountBalance();
        if (giftamountbalance == 0)
        {
            MessageBox.Show(this, "可申请赠品金额为0,不可申请赠品");
            return;
        }

        int AccountTitle = int.Parse(ddl_AccountTitle.SelectedValue);
        if (TreeTableBLL.GetChild("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", AccountTitle).Rows.Count > 0)
        {
            MessageBox.Show(this, "费用科目必须选择最底级会计科目!" + ddl_AccountTitle.SelectedItem.Text);
            return;
        }

        decimal applycost = 0;
        decimal.TryParse(tbx_ApplyCost.Text, out applycost);
        if (applycost == 0)
        {
            MessageBox.Show(this, "申请赠品金额不可为0");
            return;
        }

        if (applycost > giftamountbalance)
        {
            MessageBox.Show(this, "赠品申请金额:" + tbx_ApplyCost.Text + "不能大于可用申请赠品金额:" + lb_GiftAmountBalance.Text);
            return;
        }
        #endregion

        #region 创建费用申请单
        FNA_FeeApplyBLL bll = new FNA_FeeApplyBLL();

        bll.Model.OrganizeCity       = int.Parse(tr_OrganizeCity.SelectValue);
        bll.Model.AccountMonth       = int.Parse(ddl_ApplyMonth.SelectedValue);
        bll.Model.Client             = client; //费用代垫客户
        bll.Model.State              = 1;      //草稿
        bll.Model.ApproveFlag        = 2;      //未审核
        bll.Model.InsertStaff        = (int)Session["UserID"];
        bll.Model["Title"]           = ddl_ApplyMonth.SelectedItem.Text + " 赠品费用申请单" + " " + select_Client.SelectText + " " + Session["UserRealName"].ToString();
        bll.Model.FeeType            = feetype;
        bll.Model["GiftFeeClassify"] = giftclassify.ToString();
        bll.Model.ProductBrand       = productbrand;

        AC_AccountMonth    accountmonth = new AC_AccountMonthBLL(month).Model;
        FNA_FeeApplyDetail detail       = new FNA_FeeApplyDetail();
        detail.Client            = client;
        detail.AccountTitle      = AccountTitle;
        detail.BeginMonth        = month;
        detail.EndMonth          = month;
        detail.BeginDate         = accountmonth.BeginDate;
        detail.EndDate           = accountmonth.EndDate;
        detail.ApplyCost         = applycost * (100 - decimal.Parse(tbx_DIPercent.Text)) / 100;
        detail.DICost            = applycost * decimal.Parse(tbx_DIPercent.Text) / 100;
        detail.SalesForcast      = decimal.Parse(tbx_SalesForcast.Text);
        detail.Remark            = tbx_Remark.Text;
        detail.RelateBrands      = productbrand.ToString();
        detail.LastWriteOffMonth = int.Parse(ddl_LastWriteOffMonth.SelectedValue);
        detail.Flag            = 1; //未报销
        detail["FeeApplyType"] = "1";
        bll.Items.Add(detail);

        bll.Model.SheetCode = FNA_FeeApplyBLL.GenerateSheetCode(bll.Model.OrganizeCity, bll.Model.AccountMonth);
        int id = bll.Add();
        #endregion


        if (id > 0)
        {
            Response.Redirect("FeeApplyDetail3.aspx?ID=" + id.ToString());
        }
        else
        {
            MessageBox.Show(this, "对不起,赠品费用申请单生成失败!错误码:" + id.ToString());
        }
    }
示例#4
0
    private bool SaveGrid()
    {
        #region 获取关联品牌明细
        string relatebrands = "";
        foreach (ListItem item in cbl_Brand.Items)
        {
            if (item.Selected)
            {
                relatebrands += item.Value + ",";
            }
        }
        if (relatebrands.EndsWith(","))
        {
            relatebrands = relatebrands.Substring(0, relatebrands.Length - 1);
        }
        #endregion

        ListTable <FNA_FeeApplyDetail> _details = ViewState["Details"] as ListTable <FNA_FeeApplyDetail>;
        foreach (GridViewRow gr in gv_List.Rows)
        {
            FNA_FeeApplyDetail item = new FNA_FeeApplyDetail();
            item.ID = (int)gv_List.DataKeys[gr.RowIndex]["ID"];
            if (select_Client.SelectValue != "")
            {
                item.Client           = int.Parse(select_Client.SelectValue);
                item["RelateLinkMan"] = ddl_LinkMan.SelectedValue;
                item.SalesForcast     = decimal.Parse(tbx_SalesForcast.Text);
            }
            item.AccountTitle = int.Parse(((DropDownList)gr.FindControl("ddl_AccountTitle")).SelectedValue);
            if (((TextBox)gr.FindControl("tbx_ApplyCost")).Text.Trim() != "")
            {
                item.ApplyCost = decimal.Parse(((TextBox)gr.FindControl("tbx_ApplyCost")).Text.Trim());
            }
            if (((TextBox)gr.FindControl("tbx_DICost")).Text.Trim() != "")
            {
                item.DICost = decimal.Parse(((TextBox)gr.FindControl("tbx_DICost")).Text.Trim());
            }

            if (item.AccountTitle > 1 && item.ApplyCost != 0)
            {
                #region 获取费用的开始及截止日期
                TextBox tbx_BeginDate = (TextBox)gr.FindControl("tbx_BeginDate");
                TextBox tbx_EndDate   = (TextBox)gr.FindControl("tbx_EndDate");

                if (tbx_BeginDate != null && !string.IsNullOrEmpty(tbx_BeginDate.Text))
                {
                    item.BeginDate  = DateTime.Parse(tbx_BeginDate.Text);
                    item.BeginMonth = AC_AccountMonthBLL.GetMonthByDate(item.BeginDate);
                }
                else
                {
                    item.BeginDate  = _details[item.ID.ToString()].BeginDate;
                    item.BeginMonth = _details[item.ID.ToString()].BeginMonth;
                }

                if (tbx_EndDate != null && !string.IsNullOrEmpty(tbx_EndDate.Text))
                {
                    item.EndDate  = DateTime.Parse(tbx_EndDate.Text);
                    item.EndMonth = AC_AccountMonthBLL.GetMonthByDate(item.EndDate);
                }
                else
                {
                    item.EndDate  = _details[item.ID.ToString()].EndDate;
                    item.EndMonth = _details[item.ID.ToString()].EndMonth;
                }

                if (item.BeginDate > item.EndDate)
                {
                    MessageBox.Show(this, "费用发生范围的开始时间不能大于截止时间");
                    return(false);
                }
                #endregion
                item.LastWriteOffMonth = int.Parse(ddl_LastWriteOffMonth.SelectedValue);
                item.Remark            = ((TextBox)gr.FindControl("tbx_Remark")).Text;

                if (item.Remark == "")
                {
                    MessageBox.Show(this, "费用说明必填");
                    return(false);
                }

                if (TreeTableBLL.GetChild("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", item.AccountTitle).Rows.Count > 0)
                {
                    MessageBox.Show(this, "费用科目必须选择最底级会计科目!" + ((DropDownList)gr.FindControl("ddl_AccountTitle")).SelectedItem.Text);
                    return(false);
                }
                item.Flag = 1;      //未报销

                item.RelateBrands = relatebrands;
                _details.Update(item);
            }
            else
            {
                _details.Remove(item);
            }
        }

        return(true);
    }