protected void gv_ListDetail_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int         id        = (int)gv_ListDetail.DataKeys[e.Row.RowIndex][0];
            UC_GridView gv_Detail = (UC_GridView)e.Row.FindControl("gv_Detail");
            if (gv_Detail != null)
            {
                IList <FNA_FeeWriteOffDetail> lists = new FNA_FeeWriteOffBLL(id).Items;

                //费用类型
                int accounttile = 0;
                int.TryParse(tr_AccountTitle.SelectValue, out accounttile);
                if (ddl_FeeType.SelectedValue != "0" && !(accounttile > 1))
                {
                    IList <AC_AccountTitleInFeeType> titles = AC_AccountTitleInFeeTypeBLL.GetModelList("FeeType=" + ddl_FeeType.SelectedValue);
                    int[] ids = new int[titles.Count];
                    for (int i = 0; i < titles.Count; i++)
                    {
                        ids[i] = titles[i].AccountTitle;
                    }
                    lists = lists.Where(p => ids.Contains(p.AccountTitle)).ToList();
                }

                //费用科目
                if (accounttile > 1)
                {
                    DataTable dt  = TreeTableBLL.GetAllChildByNodes("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", accounttile.ToString());
                    int[]     ids = new int[dt.Rows.Count + 1];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        ids[i] = (int)dt.Rows[i]["ID"];
                    }
                    ids[ids.Length - 1] = accounttile;
                    lists = lists.Where(p => ids.Contains(p.AccountTitle)).ToList();
                }

                //核销金额判断
                decimal _cost = 0;
                decimal.TryParse(tbx_WriteOffCost.Text, out _cost);
                if (_cost != 0)
                {
                    if (ddl_WriteOffCostOP.SelectedValue == ">")
                    {
                        lists = lists.Where(p => p.WriteOffCost + p.AdjustCost > _cost).ToList();
                    }
                    else if (ddl_WriteOffCostOP.SelectedValue == "<")
                    {
                        lists = lists.Where(p => p.WriteOffCost + p.AdjustCost < _cost).ToList();
                    }
                }

                gv_Detail.BindGrid(lists);
            }
        }
    }
    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 feetype      = int.Parse(ddl_FeeType.SelectedValue);
        int state        = int.Parse(ddl_State.SelectedValue);

        if (MCSTabControl1.SelectedIndex == 0)
        {
            #region 显示汇总单数据源
            Dictionary_Data dicFeeType = null;
            if (feetype > 0)
            {
                dicFeeType = DictionaryBLL.GetDicCollections("FNA_FeeType")[feetype.ToString()];
            }
            #region 额外条件
            string condition = "";
            //费用代垫客户
            if (select_Client.SelectValue != "")
            {
                condition += " AND FNA_FeeWriteOff.InsteadPayClient=" + select_Client.SelectValue;
            }

            //费用代垫员工
            if (Select_InsteadPayStaff.SelectValue != "")
            {
                condition += " AND MCS_SYS.dbo.UF_Spilt2('MCS_FNA.dbo.FNA_FeeWriteOff',FNA_FeeWriteOff.ExtPropertys,'InsteadPayStaff')=" + Select_InsteadPayStaff.SelectValue;
            }

            //核销申请人
            if (Select_InsertStaff.SelectValue != "")
            {
                condition += " AND FNA_FeeWriteOff.InsertStaff=" + Select_InsertStaff.SelectValue;
            }
            #endregion
            DataTable dtSummary = FNA_FeeWriteOffBLL.GetSummaryTotal(month, organizecity, level, feetype, state, int.Parse(Session["UserID"].ToString()), condition);
            if (dtSummary.Rows.Count == 0)
            {
                gv_List.DataBind();
                return;
            }

            #region 矩阵化数据表,扩展表数据列
            dtSummary.Columns.Add(new DataColumn("ID", Type.GetType("System.Int32")));
            if (level < 10)
            {
                foreach (DataRow row in dtSummary.Rows)
                {
                    row["ID"] = row["OrganizeCity"];
                }
                dtSummary = MatrixTable.Matrix(dtSummary, new string[] { "ID", "管理片区名称" },
                                               new string[] { "FeeTypeName", "AccountTitleName" }, "WriteOffCost", true, true);
            }
            else
            {
                if (level == 10)
                {
                    //按经销商查看
                    #region 将经销商的所属管理片区赋至管理片区列
                    Dictionary <int, string> dicFullOrganizeCityName = new Dictionary <int, string>();
                    foreach (DataRow row in dtSummary.Rows)
                    {
                        row["ID"]    = row["经销商ID"] == DBNull.Value ? 0 : row["经销商ID"];
                        row["经销商名称"] = row["经销商名称"] == DBNull.Value ? "无" : row["经销商名称"];

                        if ((int)row["ID"] > 0)
                        {
                            CM_Client c = new CM_ClientBLL((int)row["ID"]).Model;
                            if (c != null)
                            {
                                if (!dicFullOrganizeCityName.ContainsKey(c.OrganizeCity))
                                {
                                    dicFullOrganizeCityName.Add(c.OrganizeCity, TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OrganizeCity", c.OrganizeCity));
                                }
                                row["管理片区名称"] = dicFullOrganizeCityName[c.OrganizeCity];
                            }
                        }
                    }
                    #endregion

                    dtSummary = MatrixTable.Matrix(dtSummary, new string[] { "ID", "管理片区名称", "经销商名称" },
                                                   new string[] { "FeeTypeName", "AccountTitleName" }, "WriteOffCost", true, true);
                }
                else if (level == 20)
                {
                    //按门店查看
                    #region 将门店的所属管理片区赋至管理片区列
                    Dictionary <int, string> dicFullOrganizeCityName = new Dictionary <int, string>();
                    foreach (DataRow row in dtSummary.Rows)
                    {
                        row["ID"]   = row["客户ID"] == DBNull.Value ? 0 : row["客户ID"];
                        row["客户名称"] = row["客户名称"] == DBNull.Value ? "无" : row["客户名称"];

                        if ((int)row["ID"] > 0)
                        {
                            CM_Client c = new CM_ClientBLL((int)row["ID"]).Model;
                            if (c != null)
                            {
                                if (!dicFullOrganizeCityName.ContainsKey(c.OrganizeCity))
                                {
                                    dicFullOrganizeCityName.Add(c.OrganizeCity, TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OrganizeCity", c.OrganizeCity));
                                }
                                row["管理片区名称"] = dicFullOrganizeCityName[c.OrganizeCity];
                            }
                        }
                    }
                    #endregion

                    dtSummary = MatrixTable.Matrix(dtSummary, new string[] { "ID", "管理片区名称", "客户名称" },
                                                   new string[] { "FeeTypeName", "AccountTitleName" }, "WriteOffCost", true, true);
                }
            }
            dtSummary = MatrixTable.ColumnSummaryTotal(dtSummary, new int[] { 1 }, new string[] { "WriteOffCost" });
            #endregion

            #region 暂不计算分析数据
            //dtSummary.Columns["合计"].ColumnName = "费用合计";
            //dtSummary.Columns.Add("预计销量", Type.GetType("System.Decimal"));

            //if (dicFeeType != null && dicFeeType.Description == "BudgetControl" && level < 10)
            //{
            //    dtSummary.Columns.Add("预算总额", Type.GetType("System.Decimal"));
            //    dtSummary.Columns.Add("其中扩增额", Type.GetType("System.Decimal"));
            //    dtSummary.Columns.Add("预算余额", Type.GetType("System.Decimal"));
            //}

            //if (dicFeeType != null && dicFeeType.Description == "FeeRateControl")
            //    dtSummary.Columns.Add("上月余额", Type.GetType("System.Decimal"));

            //dtSummary.Columns.Add("费点", Type.GetType("System.String"));


            //decimal sumTotalVolume = 0, sumTotalBudget = 0, sumExtBudget = 0, sumPreMonthBudgetBalance = 0, sumUsableAmount = 0;
            //foreach (DataRow row in dtSummary.Rows)
            //{
            //    int id = 0;

            //    if (int.TryParse(row[0].ToString(), out id) && id > 0)
            //    {
            //        bool includechild = true;
            //        if (level < 10 && new Addr_OrganizeCityBLL(id).Model.Level < level) includechild = false;

            //        #region 计算费点
            //        if (level < 10)
            //            row["预计销量"] = SVM_SalesForcastBLL.GetTotalVolume(month, id, includechild);
            //        else if (level == 10 || level == 20)
            //            row["预计销量"] = SVM_SalesForcastBLL.GetTotalVolumeByClient(month, id);

            //        sumTotalVolume += (decimal)row["预计销量"];

            //        if (dicFeeType != null && dicFeeType.Description == "BudgetControl" && level < 10)
            //        {
            //            row["预算总额"] = (FNA_BudgetBLL.GetSumBudgetAmount(month, id, feetype, includechild) + FNA_BudgetBLL.GetSumBudgetAmount(month, id, 0, includechild));
            //            sumTotalBudget += (decimal)row["预算总额"];

            //            row["其中扩增额"] = (FNA_BudgetExtraApplyBLL.GetExtraAmount(month, id, feetype, includechild) + FNA_BudgetExtraApplyBLL.GetExtraAmount(month, id, 0, includechild));
            //            sumExtBudget += (decimal)row["其中扩增额"];

            //            row["预算余额"] = (FNA_BudgetBLL.GetUsableAmount(month, id, feetype, includechild) + FNA_BudgetBLL.GetUsableAmount(month, id, 0, includechild));
            //            sumUsableAmount += (decimal)row["预算余额"];
            //        }

            //        if (dicFeeType != null && dicFeeType.Description == "FeeRateControl" && level < 10)
            //        {
            //            row["上月余额"] = FNA_BudgetBLL.GetUsableAmount(month - 1, id, feetype, includechild);
            //            sumPreMonthBudgetBalance += (decimal)row["上月余额"];

            //            if ((decimal)row["预计销量"] != 0)
            //                row["费点"] = (((decimal)row["费用合计"] - (decimal)row["上月余额"]) / (decimal)row["预计销量"]).ToString("0.00%");
            //        }
            //        else if ((decimal)row["预计销量"] != 0)
            //            row["费点"] = ((decimal)row["费用合计"] / (decimal)row["预计销量"]).ToString("0.00%");
            //        #endregion
            //    }

            //    #region 求合计行
            //    if (id == 0)
            //    {
            //        row["预计销量"] = sumTotalVolume.ToString("0.00");

            //        #region 预算总额及余额
            //        if (dicFeeType != null && dicFeeType.Description == "BudgetControl" && level < 10)
            //        {
            //            row["预算总额"] = sumTotalBudget.ToString("0.00");
            //            row["其中扩增额"] = sumExtBudget.ToString("0.00");
            //            row["预算余额"] = sumUsableAmount.ToString("0.00");
            //        }
            //        #endregion

            //        #region 费点
            //        if (sumTotalVolume != 0)
            //        {
            //            if (dicFeeType != null && dicFeeType.Description == "FeeRateControl" && level < 10)
            //            {
            //                row["上月余额"] = sumPreMonthBudgetBalance;
            //                row["费点"] = (((decimal)row["费用合计"] - sumPreMonthBudgetBalance) / sumTotalVolume).ToString("0.##%");
            //            }
            //            else
            //                row["费点"] = ((decimal)row["费用合计"] / sumTotalVolume).ToString("0.##%");
            //        }
            //        #endregion
            //    }
            //    #endregion

            //}
            #endregion

            #endregion

            gv_List.DataSource = dtSummary;
            gv_List.DataBind();

            if (dtSummary.Columns.Count >= 24)
            {
                gv_List.Width = new Unit(dtSummary.Columns.Count * 55);
            }
            else
            {
                gv_List.Width = new Unit(100, UnitType.Percentage);
            }

            MatrixTable.GridViewMatric(gv_List);

            if (level == 20)
            {
                //按终端门店显示时,将上下行相同管理片区合并
                MatrixTable.GridViewMergSampeValueRow(gv_List, 0);
                MatrixTable.GridViewMergSampeValueRow(gv_List, 1);
            }
            #region 是否可以批量审批
            if (state != 1 || level >= 10)
            {
                gv_List.Columns[0].ItemStyle.Width = new Unit(1);
                foreach (GridViewRow row in gv_List.Rows)
                {
                    row.FindControl("bt_Approved").Visible   = false;
                    row.FindControl("bt_UnApproved").Visible = false;
                }
            }
            else
            {
                gv_List.Columns[0].ItemStyle.Width = new Unit(68);
            }
            #endregion
        }
        else
        {
            string condition = "1=1";

            #region 组织明细记录的查询条件
            //管理片区及所有下属管理片区
            if (tr_OrganizeCity.SelectValue != "1")
            {
                Addr_OrganizeCityBLL orgcity = new Addr_OrganizeCityBLL(int.Parse(tr_OrganizeCity.SelectValue));
                string orgcitys = orgcity.GetAllChildNodeIDs();
                if (orgcitys != "")
                {
                    orgcitys += ",";
                }
                orgcitys += tr_OrganizeCity.SelectValue;

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

            //会计月条件
            condition += " AND FNA_FeeWriteOff.AccountMonth = " + ddl_Month.SelectedValue;

            int accounttile = 0;
            int.TryParse(tr_AccountTitle.SelectValue, out accounttile);
            decimal _cost = 0;
            decimal.TryParse(tbx_WriteOffCost.Text, out _cost);
            //费用类型
            if (ddl_FeeType.SelectedValue != "0" && !(accounttile > 1))
            {
                IList <AC_AccountTitleInFeeType> titles = AC_AccountTitleInFeeTypeBLL.GetModelList("FeeType=" + ddl_FeeType.SelectedValue);
                string ids = "";
                foreach (AC_AccountTitleInFeeType item in titles)
                {
                    ids += item.AccountTitle + ",";
                }
                if (ids.EndsWith(","))
                {
                    ids = ids.Substring(0, ids.Length - 1);
                }

                condition += " AND FNA_FeeWriteOff.ID IN (SELECT WriteOffID FROM MCS_FNA.dbo.FNA_FeeWriteOffDetail WHERE AccountTitle IN(" + ids + ") AND FNA_FeeWriteOffDetail.WriteOffID=FNA_FeeWriteOff.ID)";
            }

            //费用科目
            if (accounttile > 1)
            {
                DataTable dt  = TreeTableBLL.GetAllChildByNodes("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", accounttile.ToString());
                string    ids = "";
                foreach (DataRow dr in dt.Rows)
                {
                    ids += dr["ID"].ToString() + ",";
                }
                ids += accounttile.ToString();

                if (_cost == 0)
                {
                    condition += " AND FNA_FeeWriteOff.ID IN (SELECT WriteOffID FROM MCS_FNA.dbo.FNA_FeeWriteOffDetail WHERE AccountTitle IN(" + ids + ") AND FNA_FeeWriteOffDetail.WriteOffID=FNA_FeeWriteOff.ID)";
                }
                else
                {
                    condition += " AND FNA_FeeWriteOff.ID IN (SELECT WriteOffID FROM MCS_FNA.dbo.FNA_FeeWriteOffDetail WHERE AccountTitle IN(" + ids + ") AND (WriteOffCost+AdjustCost)" + ddl_WriteOffCostOP.SelectedValue + "  " + _cost.ToString() + " AND FNA_FeeWriteOffDetail.WriteOffID=FNA_FeeWriteOff.ID)";
                }
            }
            else if (_cost != 0)
            {   //核销金额判断
                condition += " AND FNA_FeeWriteOff.ID IN (SELECT WriteOffID FROM MCS_FNA.dbo.FNA_FeeWriteOffDetail WHERE (WriteOffCost+AdjustCost)" + ddl_WriteOffCostOP.SelectedValue + "  " + _cost.ToString() + " AND FNA_FeeWriteOffDetail.WriteOffID=FNA_FeeWriteOff.ID)";
            }

            //审批状态
            if (ddl_State.SelectedValue == "0")
            {
                condition += " AND FNA_FeeWriteOff.State IN (2,3) ";
            }
            else if (ddl_State.SelectedValue == "1")
            {
                condition +=
                    @" AND FNA_FeeWriteOff.State = 2 AND FNA_FeeWriteOff.ApproveTask IN 
(SELECT EWF_Task_Job.Task FROM  MCS_EWF.dbo.EWF_Task_JobDecision INNER JOIN
    MCS_EWF.dbo.EWF_Task_Job ON EWF_Task_JobDecision.Job = EWF_Task_Job.ID 
WHERE EWF_Task_JobDecision.RecipientStaff=" + Session["UserID"].ToString() + @" AND
    EWF_Task_JobDecision.DecisionResult=1 and EWF_Task_Job.Status=3)";
            }
            else if (ddl_State.SelectedValue == "2")
            {
                condition += " AND FNA_FeeWriteOff.State = 3 ";
            }
            else if (ddl_State.SelectedValue == "3")
            {
                AC_AccountMonth m = new AC_AccountMonthBLL(month).Model;
                condition +=
                    @" AND FNA_FeeWriteOff.State IN (2,3) AND FNA_FeeWriteOff.ApproveTask IN 
(SELECT EWF_Task_Job.Task FROM  MCS_EWF.dbo.EWF_Task_JobDecision INNER JOIN
	MCS_EWF.dbo.EWF_Task_Job ON EWF_Task_JobDecision.Job = EWF_Task_Job.ID 
WHERE EWF_Task_JobDecision.RecipientStaff=" + Session["UserID"].ToString() + @" AND
	EWF_Task_JobDecision.DecisionResult IN(2,5,6) AND 
	EWF_Task_JobDecision.DecisionTime BETWEEN DATEADD(month,-1,'"     + m.BeginDate.ToString("yyyy-MM-dd") + @"') AND 
		DATEADD(month,3,'"         + m.BeginDate.ToString("yyyy-MM-dd") + @"'))";
            }

            //费用代垫客户
            if (select_Client.SelectValue != "")
            {
                condition += " AND FNA_FeeWriteOff.InsteadPayClient=" + select_Client.SelectValue;
            }

            //费用代垫员工
            if (Select_InsteadPayStaff.SelectValue != "")
            {
                condition += " AND MCS_SYS.dbo.UF_Spilt2('MCS_FNA.dbo.FNA_FeeWriteOff',FNA_FeeWriteOff.ExtPropertys,'InsteadPayStaff')=" + Select_InsteadPayStaff.SelectValue;
            }

            //核销申请人
            if (Select_InsertStaff.SelectValue != "")
            {
                condition += " AND FNA_FeeWriteOff.InsertStaff=" + Select_InsertStaff.SelectValue;
            }
            #endregion

            gv_ListDetail.ConditionString = condition;
            gv_ListDetail.BindGrid();
        }
    }
Пример #3
0
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 1)
        {
            return;
        }

        AC_AccountTitleBLL _bll;

        if ((int)ViewState["ID"] == 0)
        {
            _bll = new AC_AccountTitleBLL();
        }
        else
        {
            _bll = new AC_AccountTitleBLL((int)ViewState["ID"]);
        }

        _bll.Model.Name        = tbx_Name.Text;
        _bll.Model.SuperID     = int.Parse(tree_SuperID.SelectValue);
        _bll.Model.Code        = tbx_Code.Text;
        _bll.Model.Description = tbx_Description.Text;

        _bll.Model.Level                    = new AC_AccountTitleBLL(_bll.Model.SuperID).Model.Level + 1;
        _bll.Model["OverPercent"]           = tbx_OverPercent.Text;
        _bll.Model["MustApplyFirst"]        = cbx_MustApplyFirst.Checked ? "Y" : "N";
        _bll.Model["IsDisable"]             = cbx_IsDisable.Checked ? "Y" : "N";
        _bll.Model["CanApplyInGeneralFlow"] = cbx_CanApplyInGeneralFlow.Checked ? "Y" : "N";
        int MonthsOverdue = 1, YFMonthsOverdue = 1;

        int.TryParse(txt_YFMonthsOverdue.Text.Trim(), out YFMonthsOverdue);
        int.TryParse(txt_MonthsOverdue.Text.Trim(), out MonthsOverdue);
        _bll.Model["MonthsOverdue"]   = MonthsOverdue.ToString();
        _bll.Model["YFMonthsOverdue"] = YFMonthsOverdue.ToString();

        if (DictionaryBLL.GetDicCollections("AC_AccountTitleLevel")[_bll.Model.Level.ToString()] == null)
        {
            lbl_AlertInfo.Text = "添加会计科目失败,等级超出范围";
            return;
        }

        if ((int)ViewState["ID"] == 0)
        {
            int ret = _bll.Add();
            if (ret < 0)
            {
                lbl_AlertInfo.Text = "添加会计科目失败,会计科目名称已存在";
                return;
            }
            _bll.Model.ID = ret;
        }
        else
        {
            if (_bll.Model.SuperID == _bll.Model.ID)
            {
                return;
            }
            int ret = _bll.Update();

            switch (ret)
            {
            case -1:
                lbl_AlertInfo.Text = "更新会计科目失败,会计科目名称已存在";
                return;

            case -2:
                lbl_AlertInfo.Text = "更新会计科目失败,不能将当前会计科目设置为上级会计科目";
                return;

            case -3:
                lbl_AlertInfo.Text = "更新会计科目失败,不能将当前会计科目的子会计科目设置为上级会计科目";
                return;
            }
        }

        IList <AC_AccountTitleInFeeType> lists = AC_AccountTitleInFeeTypeBLL.GetModelList("AccountTitle=" + _bll.Model.ID);

        foreach (ListItem item in cbl_FeeType.Items)
        {
            if (item.Selected)
            {
                if (lists.FirstOrDefault(p => p.FeeType.ToString() == item.Value) == null)
                {
                    AC_AccountTitleInFeeTypeBLL b = new AC_AccountTitleInFeeTypeBLL();
                    b.Model.AccountTitle = _bll.Model.ID;
                    b.Model.FeeType      = int.Parse(item.Value);
                    b.Add();
                }
            }
            else
            {
                if (lists.FirstOrDefault(p => p.FeeType.ToString() == item.Value) != null)
                {
                    AC_AccountTitleInFeeTypeBLL b = new AC_AccountTitleInFeeTypeBLL(lists.FirstOrDefault(p => p.FeeType.ToString() == item.Value).ID);
                    b.Delete();
                }
            }
        }

        DataCache.RemoveCache("Cache-TreeTableBLL-GetAllNode-MCS_Pub.dbo.AC_AccountTitle");
        Response.Redirect("AccountTitle.aspx?SuperID=" + _bll.Model.SuperID.ToString());
    }
Пример #4
0
    private void BindData(int ID)
    {
        ViewState["ID"] = ID;

        AC_AccountTitleBLL _bll = new AC_AccountTitleBLL(ID);

        lbl_ID.Text   = _bll.Model.ID.ToString();
        tbx_Name.Text = _bll.Model.Name;
        if (_bll.Model.SuperID != 0)
        {
            tree_SuperID.SelectValue = _bll.Model.SuperID.ToString();
        }
        tbx_Code.Text                     = _bll.Model.Code;
        tbx_Description.Text              = _bll.Model.Description;
        tbx_OverPercent.Text              = _bll.Model["OverPercent"] == "" ? "0" : _bll.Model["OverPercent"];
        cbx_MustApplyFirst.Checked        = _bll.Model["MustApplyFirst"] != "N";
        cbx_IsDisable.Checked             = _bll.Model["IsDisable"] == "Y";
        cbx_CanApplyInGeneralFlow.Checked = _bll.Model["CanApplyInGeneralFlow"] != "N";
        txt_MonthsOverdue.Text            = _bll.Model["MonthsOverdue"] == "" ? "1" : _bll.Model["MonthsOverdue"];
        txt_YFMonthsOverdue.Text          = _bll.Model["YFMonthsOverdue"] == "" ? "1" : _bll.Model["YFMonthsOverdue"];
        if (_bll.Model.Level != 0)
        {
            lbl_LevelName.Text = DictionaryBLL.GetDicCollections("AC_AccountTitleLevel")[_bll.Model.Level.ToString()].Name;
        }

        if (_bll.Model.Level > 3)
        {
            cbl_FeeType.Enabled = false;
        }
        else
        {
            cbl_FeeType.Enabled = true;
        }

        cbl_FeeType.Items.Clear();
        cbl_FeeType.DataSource = DictionaryBLL.GetDicCollections("FNA_FeeType");
        cbl_FeeType.DataBind();

        foreach (AC_AccountTitleInFeeType item in AC_AccountTitleInFeeTypeBLL.GetModelList("AccountTitle=" + ID.ToString()))
        {
            cbl_FeeType.Items.FindByValue(item.FeeType.ToString()).Selected = true;
        }

        btn_Save.Text      = "修改";
        btn_Save.ForeColor = System.Drawing.Color.Red;
        btn_Delete.Visible = true;
        MessageBox.ShowConfirm(btn_Delete, "数据删除将不可恢复,确定删除么?");
        btn_Cancel.Visible = true;
        bt_AddSub.Visible  = true;

        lbl_AlertInfo.Text = "";

        if ((int)ViewState["ID"] == 1)
        {
            btn_Save.Enabled = false;
        }
        else
        {
            btn_Save.Enabled = true;
        }
        btn_Delete.Visible = AC_AccountTitleBLL.GetModelList("SuperID=" + ViewState["ID"].ToString()).Count == 0;
    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 1) return;

        AC_AccountTitleBLL _bll;
        if ((int)ViewState["ID"] == 0)
        {
            _bll = new AC_AccountTitleBLL();
        }
        else
        {
            _bll = new AC_AccountTitleBLL((int)ViewState["ID"]);
        }

        _bll.Model.Name = tbx_Name.Text;
        _bll.Model.SuperID = int.Parse(tree_SuperID.SelectValue);
        _bll.Model.Code = tbx_Code.Text;
        _bll.Model.Description = tbx_Description.Text;

        _bll.Model.Level = new AC_AccountTitleBLL(_bll.Model.SuperID).Model.Level + 1;
        _bll.Model["OverPercent"] = tbx_OverPercent.Text;
        _bll.Model["MustApplyFirst"] = cbx_MustApplyFirst.Checked ? "Y" : "N";
        _bll.Model["IsDisable"] = cbx_IsDisable.Checked ? "Y" : "N";
        _bll.Model["CanApplyInGeneralFlow"] = cbx_CanApplyInGeneralFlow.Checked ? "Y" : "N";
        int MonthsOverdue = 1, YFMonthsOverdue=1;
        int.TryParse(txt_YFMonthsOverdue.Text.Trim(), out YFMonthsOverdue);
        int.TryParse(txt_MonthsOverdue.Text.Trim(), out MonthsOverdue);
        _bll.Model["MonthsOverdue"] = MonthsOverdue.ToString();
        _bll.Model["YFMonthsOverdue"] = YFMonthsOverdue.ToString();

        if (DictionaryBLL.GetDicCollections("AC_AccountTitleLevel")[_bll.Model.Level.ToString()] == null)
        {
            lbl_AlertInfo.Text = "添加会计科目失败,等级超出范围";
            return;
        }

        if ((int)ViewState["ID"] == 0)
        {
            int ret = _bll.Add();
            if (ret < 0)
            {
                lbl_AlertInfo.Text = "添加会计科目失败,会计科目名称已存在";
                return;
            }
            _bll.Model.ID = ret;
        }
        else
        {
            if (_bll.Model.SuperID == _bll.Model.ID) return;
            int ret = _bll.Update();

            switch (ret)
            {
                case -1:
                    lbl_AlertInfo.Text = "更新会计科目失败,会计科目名称已存在";
                    return;
                case -2:
                    lbl_AlertInfo.Text = "更新会计科目失败,不能将当前会计科目设置为上级会计科目";
                    return;
                case -3:
                    lbl_AlertInfo.Text = "更新会计科目失败,不能将当前会计科目的子会计科目设置为上级会计科目";
                    return;
            }
        }

        IList<AC_AccountTitleInFeeType> lists = AC_AccountTitleInFeeTypeBLL.GetModelList("AccountTitle=" + _bll.Model.ID);
        foreach (ListItem item in cbl_FeeType.Items)
        {
            if (item.Selected)
            {
                if (lists.FirstOrDefault(p => p.FeeType.ToString() == item.Value) == null)
                {
                    AC_AccountTitleInFeeTypeBLL b = new AC_AccountTitleInFeeTypeBLL();
                    b.Model.AccountTitle = _bll.Model.ID;
                    b.Model.FeeType = int.Parse(item.Value);
                    b.Add();
                }
            }
            else
            {
                if (lists.FirstOrDefault(p => p.FeeType.ToString() == item.Value) != null)
                {
                    AC_AccountTitleInFeeTypeBLL b = new AC_AccountTitleInFeeTypeBLL(lists.FirstOrDefault(p => p.FeeType.ToString() == item.Value).ID);
                    b.Delete();
                }
            }
        }

        DataCache.RemoveCache("Cache-TreeTableBLL-GetAllNode-MCS_Pub.dbo.AC_AccountTitle");
        Response.Redirect("AccountTitle.aspx?SuperID=" + _bll.Model.SuperID.ToString());
    }