Example #1
0
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        FNA_FeeWriteOffBLL    _bll = new FNA_FeeWriteOffBLL((int)ViewState["ID"]);
        FNA_FeeWriteOffDetail m    = new FNA_FeeWriteOffDetail();

        if ((int)ViewState["DetailID"] > 0)
        {
            m              = _bll.GetDetailModel((int)ViewState["DetailID"]);
            m.ApplyCost    = decimal.Parse(tbx_Taxes.Text.Trim());
            m.WriteOffCost = m.ApplyCost;
            m.Remark       = tbx_Remark.Text.Trim();
            _bll.UpdateDetail(m);
        }
        else
        {
            m.ID            = 0;
            m.ApplyDetailID = 0;
            m.Client        = _bll.Model.InsteadPayClient;
            m.BeginMonth    = _bll.Model.AccountMonth;
            m.EndMonth      = _bll.Model.AccountMonth;
            m.AccountTitle  = 129;
            m.ApplyCost     = decimal.Parse(tbx_Taxes.Text.Trim());
            m.WriteOffCost  = m.ApplyCost;
            m.Remark        = tbx_Remark.Text.Trim();
            _bll.AddDetail(m);
        }
        Session["SuccessFlag"] = true;
        MessageBox.ShowAndClose(this, "税金调整成功。");
    }
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        FNA_FeeWriteOffBLL _bll = new FNA_FeeWriteOffBLL((int)ViewState["ID"]);
        FNA_FeeWriteOffDetail m = new FNA_FeeWriteOffDetail();

        if ((int)ViewState["DetailID"] > 0)
        {
            m = _bll.GetDetailModel((int)ViewState["DetailID"]);
            m.ApplyCost = decimal.Parse(tbx_Taxes.Text.Trim());
            m.WriteOffCost = m.ApplyCost;
            m.Remark = tbx_Remark.Text.Trim();
            _bll.UpdateDetail(m);

        }
        else
        {
            m.ID = 0;
            m.ApplyDetailID = 0;
            m.Client = _bll.Model.InsteadPayClient;
            m.BeginMonth = _bll.Model.AccountMonth;
            m.EndMonth = _bll.Model.AccountMonth;
            m.AccountTitle = 129;
            m.ApplyCost = decimal.Parse(tbx_Taxes.Text.Trim());
            m.WriteOffCost = m.ApplyCost;
            m.Remark = tbx_Remark.Text.Trim();
            _bll.AddDetail(m);
        }
        Session["SuccessFlag"] = true;
        MessageBox.ShowAndClose(this, "税金调整成功。");
    }
    private void UpdateDetail(FNA_FeeWriteOffBLL bll, int AccountTitle, Decimal Cost, int flag, DateTime minbegindate, DateTime maxenddate)
    {
        if (Cost == 0)
        {
            return;
        }
        FNA_FeeWriteOffDetail d = bll.Items.FirstOrDefault(p => p.AccountTitle == AccountTitle);

        if (d != null)
        {
            if (flag == 1)
            {
                d.WriteOffCost += Cost;
                if (d.BeginDate > minbegindate)
                {
                    d.BeginDate = minbegindate;
                }
                if (d.EndDate < maxenddate)
                {
                    d.EndDate = maxenddate;
                }
            }
            else
            {
                d.WriteOffCost -= Cost;
            }

            if (d.WriteOffCost == 0)
            {
                bll.DeleteDetail(d.ID);
            }
            else
            {
                bll.UpdateDetail(d);
            }
        }
        else
        {
            if (flag == 1)
            {
                d = new FNA_FeeWriteOffDetail();
                d.AccountTitle = AccountTitle;
                d.ApplyCost    = 0;
                d.WriteOffCost = Cost;
                d.BeginDate    = minbegindate;
                d.EndDate      = maxenddate;
                d.BeginMonth   = bll.Model.AccountMonth;
                d.EndMonth     = bll.Model.AccountMonth;
                bll.Items.Add(d);
                bll.AddDetail(d);
            }
        }
    }
    private void UpdateDetail(FNA_FeeWriteOffBLL bll, int AccountTitle, Decimal Cost, int flag, DateTime minbegindate, DateTime maxenddate)
    {
        if (Cost == 0) return;
        FNA_FeeWriteOffDetail d = bll.Items.FirstOrDefault(p => p.AccountTitle == AccountTitle);
        if (d != null)
        {
            if (flag == 1)
            {
                d.WriteOffCost += Cost;
                if (d.BeginDate > minbegindate) d.BeginDate = minbegindate;
                if (d.EndDate < maxenddate) d.EndDate = maxenddate;
            }
            else
            {
                d.WriteOffCost -= Cost;
            }

            if (d.WriteOffCost == 0)
                bll.DeleteDetail(d.ID);
            else
                bll.UpdateDetail(d);
        }
        else
        {
            if (flag == 1)
            {
                d = new FNA_FeeWriteOffDetail();
                d.AccountTitle = AccountTitle;
                d.ApplyCost = 0;
                d.WriteOffCost = Cost;
                d.BeginDate = minbegindate;
                d.EndDate = maxenddate;
                d.BeginMonth = bll.Model.AccountMonth;
                d.EndMonth = bll.Model.AccountMonth;
                bll.Items.Add(d);
                bll.AddDetail(d);
            }
        }
    }