private void LoadData() { string projectCode = Request["ProjectCode"] + ""; string costCode = Request["CostCode"] + ""; this.lblProjectName.Text = BLL.ProjectRule.GetProjectName(projectCode); try { string flag = "-1"; V_CBSCostStrategyBuilder sb = new V_CBSCostStrategyBuilder(); sb.AddStrategy(new Strategy(V_CBSCostStrategyName.ProjectCode, projectCode)); sb.AddStrategy(new Strategy(V_CBSCostStrategyName.Flag, flag)); string sql = sb.BuildMainQueryString(); QueryAgent qa = new QueryAgent(); EntityData allCost = qa.FillEntityData("V_CBSCost", sql); // allCost.CurrentTable.Columns.Add("IsEnd",System.Type.GetType("System.Int32")); // allCost.CurrentTable.Columns.Add("AccountPoint",System.Type.GetType("System.Int32")); qa.Dispose(); EntityData cbs = DAL.EntityDAO.CBSDAO.GetCBSByProject(projectCode); DataRow[] drs0 = allCost.CurrentTable.Select("CostCode='" + costCode + "'"); string fullCode = (string)drs0[0]["FullCode"]; string codes = ""; foreach (DataRow dr in allCost.CurrentTable.Select(String.Format("FullCode like '{0}%' ", fullCode), "FullCode")) { codes += (string)dr["CostCode"] + ","; } this.txtAllCode.Value = codes; this.repeat1.DataSource = new DataView(allCost.CurrentTable, String.Format("FullCode like '{0}%' ", fullCode), "SortID", DataViewRowState.CurrentRows); this.repeat1.DataBind(); allCost.Dispose(); // 已经审核过的不能再做估算 EntityData entity = RmsPM.DAL.EntityDAO.CBSDAO.GetCostEstimateCheckByCode(projectCode); if (entity.HasRecord()) { this.btnSave.Visible = true; } entity.Dispose(); } catch (Exception ex) { ApplicationLog.WriteLog(this.ToString(), ex, ""); } }
private void LoadData() { string budgetCode = Request["BudgetCode"] + ""; string costCode = Request["CostCode"] + ""; string projectCode = Request["ProjectCode"] + ""; try { // 取费用分解结构和估算费用 V_CBSCostStrategyBuilder sb = new V_CBSCostStrategyBuilder(); sb.AddStrategy(new Strategy(V_CBSCostStrategyName.ProjectCode, projectCode)); sb.AddStrategy(new Strategy(V_CBSCostStrategyName.Flag, "-1")); sb.AddOrder("SortID", true); string sql = sb.BuildMainQueryString(); QueryAgent qa = new QueryAgent(); EntityData allCost = qa.FillEntityData("V_CBSCost", sql); qa.Dispose(); DataTable tb = allCost.CurrentTable; tb.Columns.Add("BudgetCost"); // 预算费用 tb.Columns.Add("BeforeHappenCost"); // 年前发生 tb.Columns.Add("CurrentPlanCost"); // 当年计划 tb.Columns.Add("AfterPlanCost"); // 剩余预算 for (int i = 1; i <= IMaxMonth; i++) { tb.Columns.Add("CurrentPlanCost" + i.ToString()); } for (int i = 1; i <= IMaxPeriod; i++) { tb.Columns.Add("AfterPlanCost" + i.ToString()); } // 取相关的成本项 DataRow[] drs0 = tb.Select("CostCode='" + costCode + "'"); string fullCode = (string)drs0[0]["FullCode"]; string costName = (string)drs0[0]["CostName"]; int childCount = (int)drs0[0]["ChildCount"]; int deep = (int)drs0[0]["Deep"]; DataRow[] drs = allCost.CurrentTable.Select(String.Format("FullCode like '{0}%' ", fullCode), "FullCode"); string codes = ""; foreach (DataRow dr in drs) { codes += (string)dr["CostCode"] + ","; } this.txtAllCode.Value = codes; if (budgetCode != "") { EntityData budget = DAL.EntityDAO.CBSDAO.GetStandard_BudgetByCode(budgetCode); int year = budget.GetInt("IYear"); this.txtYear.Value = year.ToString(); this.txtMonth.Value = budget.GetInt("IMonth").ToString(); this.txtPeriodMonth.Value = budget.GetInt("PeriodMonth").ToString(); int afterPeriod = budget.GetInt("AfterPeriod"); this.txtAfterPeriod.Value = afterPeriod.ToString(); int flag = budget.GetInt("Flag"); int periodIndex = budget.GetInt("PeriodIndex"); // if ( flag != 1 ) // this.btnModify.Visible = false; int isDynamic = budget.GetInt("IsDynamic"); int iLength = drs.Length; this.tdTitle.InnerHtml = budget.GetString("budgetName") + " " + costName; // 处理每期预算的名称 EntityData planName = DAL.EntityDAO.SystemManageDAO.GetPeriodDefineByProjectCode(projectCode); for (int i = 1; i <= afterPeriod; i++) { HtmlTableCell cell = (HtmlTableCell)this.FindControl("tdYearTitle" + i.ToString()); if (cell != null) { int index = periodIndex + i; DataRow[] drYearNames = planName.CurrentTable.Select(String.Format("PeriodIndex={0}", index)); if (drYearNames.Length > 0) { if (!drYearNames[0].IsNull("PeriodName")) { string yearName = (string)drYearNames[0]["PeriodName"]; if (yearName != "") { cell.InnerHtml = yearName; } } } } } planName.Dispose(); // 预算的控制点 // 规则 新预算时,从第一级开始制定,层层制定。 DataRow[] drsBudget = budget.Tables["BudgetCost"].Select(String.Format("CostCode='{0}'", costCode)); this.btnModify.Visible = false; this.btnModifyDetail.Visible = false; int accountPoint = 2; if (drsBudget.Length == 0) { this.btnModify.Visible = true; if (childCount > 0) { this.btnModifyDetail.Visible = true; } } else { accountPoint = (int)drsBudget[0]["AccountPoint"]; if (accountPoint == 1) { this.btnModify.Visible = true; if (childCount > 0) { this.btnModifyDetail.Visible = true; } } } for (int i = 0; i < iLength; i++) { string tempCode = (string)drs[i]["CostCode"]; budget.SetCurrentTable("BudgetCost"); DataRow[] drSelect = budget.CurrentTable.Select(String.Format("CostCode ='{0}' ", tempCode)); if (drSelect.Length > 0) { drs[i]["BudgetCost"] = drSelect[0]["BudgetCost"]; drs[i]["BeforeHappenCost"] = drSelect[0]["BeforeHappenCost"]; drs[i]["CurrentPlanCost"] = drSelect[0]["CurrentPlanCost"]; drs[i]["AfterPlanCost"] = drSelect[0]["AfterPlanCost"]; } // 取月份 budget.SetCurrentTable("BudgetMonth"); drSelect = budget.CurrentTable.Select(String.Format("CostCode ='{0}' ", tempCode)); foreach (DataRow drMonth in drSelect) { int month = (int)drMonth["IMonth"]; drs[i]["CurrentPlanCost" + month.ToString()] = drMonth["Money"]; } // 取年份 budget.SetCurrentTable("BudgetYear"); for (int l = 1; l <= IMaxPeriod; l++) { int tempPeriod = l; DataRow[] yearSelect = budget.CurrentTable.Select(String.Format("CostCode ='{0}' and IYear={1} ", tempCode, tempPeriod.ToString())); if (yearSelect.Length > 0) { drs[i]["AfterPlanCost" + l.ToString()] = yearSelect[0]["Money"]; } } } budget.Dispose(); } this.repeat1.DataSource = new DataView(tb, String.Format(" FullCode like '{0}%' ", fullCode), "FullCode", DataViewRowState.CurrentRows); this.repeat1.DataBind(); allCost.Dispose(); } catch (Exception ex) { ApplicationLog.WriteLog(this.ToString(), ex, ""); } }
private void LoadData() { string costCode = Request["CostCode"] + ""; string projectCode = Request["ProjectCode"] + ""; string budgetCode = Request["BudgetCode"] + ""; string type = Request["Type"] + ""; try { // 取费用分解结构和估算费用 V_CBSCostStrategyBuilder sb = new V_CBSCostStrategyBuilder(); sb.AddStrategy(new Strategy(V_CBSCostStrategyName.ProjectCode, projectCode)); sb.AddStrategy(new Strategy(V_CBSCostStrategyName.Flag, "-1")); sb.AddOrder("SortID", true); string sql = sb.BuildMainQueryString(); BudgetStrategyBuilder sb0 = new BudgetStrategyBuilder(); sb0.AddStrategy(new Strategy(BudgetStrategyName.ProjectCode, projectCode)); sb0.AddStrategy(new Strategy(BudgetStrategyName.IsDynamic, "0,1")); sb0.AddOrder("MakeDate", false); string sql0 = sb0.BuildMainQueryString(); QueryAgent qa = new QueryAgent(); EntityData allBudget = qa.FillEntityData("Budget", sql0); EntityData allCost = qa.FillEntityData("V_CBSCost", sql); qa.Dispose(); // 找历年的最后一次生效的预算(动态) string lastBudgetCode = ""; DataRow[] drLast = allBudget.CurrentTable.Select(String.Format(" BudgetCode <> '{0}' and Flag in (0,2) ", budgetCode), " MakeDate DESC "); EntityData lastBudget = new EntityData("Standard_Budget"); if (drLast.Length > 0) { lastBudgetCode = (string)drLast[0]["BudgetCode"]; lastBudget = DAL.EntityDAO.CBSDAO.GetStandard_BudgetByCode(lastBudgetCode); } lastBudget.SetCurrentTable("BudgetYear"); DataTable tb = allCost.CurrentTable; tb.Columns.Add("BudgetCost"); // 预算费用 tb.Columns.Add("BeforeHappenCost"); // 年前发生 tb.Columns.Add("CurrentPlanCost"); // 当年计划 tb.Columns.Add("AfterPlanCost"); // 剩余预算 for (int i = 1; i <= IMaxMonth; i++) { tb.Columns.Add("CurrentPlanCost" + i.ToString()); } for (int i = 1; i <= IMaxPeriod; i++) { tb.Columns.Add("AfterPlanCost" + i.ToString()); } for (int i = 1; i <= IMaxMonth; i++) { tb.Columns.Add("MonthAH" + i.ToString()); } for (int i = 1; i <= IMaxMonth; i++) { tb.Columns.Add("MonthUse" + i.ToString()); } for (int i = 1; i <= IMaxMonth; i++) { tb.Columns.Add("MonthApply" + i.ToString()); } for (int i = 1; i <= IMaxPeriod; i++) { tb.Columns.Add("YearAH" + i.ToString()); } for (int i = 1; i <= IMaxPeriod; i++) { tb.Columns.Add("YearUse" + i.ToString()); } for (int i = 1; i <= IMaxPeriod; i++) { tb.Columns.Add("YearApply" + i.ToString()); } // 取相关的成本项 DataRow[] drs0 = tb.Select("CostCode='" + costCode + "'"); string fullCode = (string)drs0[0]["FullCode"]; string costName = (string)drs0[0]["CostName"]; DataRow[] drs = null; if (type == "Detail") { drs = allCost.CurrentTable.Select(String.Format("ParentCode = '{0}' or CostCode = '{0}' ", costCode), "SortID"); foreach (DataRow drC in drs) { string ccc = (string)drC["CostCode"]; if (ccc != costCode) { drC["ChildCount"] = 0; } } } else { drs = allCost.CurrentTable.Select(String.Format("CostCode = '{0}' ", costCode)); foreach (DataRow drC in drs) { drC["ChildCount"] = 0; } } int iLength = drs.Length; string codes = ""; EntityData budget = DAL.EntityDAO.CBSDAO.GetStandard_BudgetByCode(budgetCode); int iYear = budget.GetInt("IYear"); int iMonth = budget.GetInt("IMonth"); this.txtYear.Value = iYear.ToString(); this.txtMonth.Value = iMonth.ToString(); int periodMonth = budget.GetInt("PeriodMonth"); this.txtPeriodMonth.Value = periodMonth.ToString(); int afterPeriod = budget.GetInt("AfterPeriod"); int periodIndex = budget.GetInt("PeriodIndex"); this.txtAfterPeriod.Value = afterPeriod.ToString(); DateTime periodStartDate = DateTime.Parse(budget.GetDateTime("StartDate")); // 上一个周期最后一天 string lastDateLastPeriod = periodStartDate.AddDays(-1).ToString("yyyy-MM-dd"); this.lblBudgetName.Text = budget.GetString("BudgetName") + " " + costName; // 处理每期预算的名称 EntityData planName = DAL.EntityDAO.SystemManageDAO.GetPeriodDefineByProjectCode(projectCode); for (int i = 1; i <= afterPeriod; i++) { HtmlTableCell cell = (HtmlTableCell)this.FindControl("tdYearTitle" + i.ToString()); if (cell != null) { int index = periodIndex + i; DataRow[] drYearNames = planName.CurrentTable.Select(String.Format("PeriodIndex={0}", index)); if (drYearNames.Length > 0) { if (!drYearNames[0].IsNull("PeriodName")) { string yearName = (string)drYearNames[0]["PeriodName"]; if (yearName != "") { cell.InnerHtml = yearName; } } } } } planName.Dispose(); for (int i = 0; i < iLength; i++) { string tempCode = (string)drs[i]["CostCode"]; codes += tempCode + ","; budget.SetCurrentTable("BudgetCost"); DataRow[] drSelect = budget.CurrentTable.Select(String.Format("CostCode ='{0}' ", tempCode)); if (drSelect.Length > 0) { drs[i]["BudgetCost"] = drSelect[0]["BudgetCost"]; drs[i]["BeforeHappenCost"] = drSelect[0]["BeforeHappenCost"]; drs[i]["CurrentPlanCost"] = drSelect[0]["CurrentPlanCost"]; drs[i]["AfterPlanCost"] = drSelect[0]["AfterPlanCost"]; } else { drs[i]["BeforeHappenCost"] = BLL.CBSRule.GetAHMoney(tempCode, "", lastDateLastPeriod); } // 取月份 budget.SetCurrentTable("BudgetMonth"); drSelect = budget.CurrentTable.Select(String.Format("CostCode ='{0}' ", tempCode)); foreach (DataRow drMonth in drSelect) { int month = (int)drMonth["IMonth"]; // 本期开始时间 string tempStartDate = DateTime.Parse(String.Format("{0}-{1}-1", iYear, iMonth)).AddMonths(month - 1).ToString("yyyy-MM-dd"); // 本期结束时间 string tempEndDate = DateTime.Parse(String.Format("{0}-{1}-1", iYear, iMonth)).AddMonths(month).AddDays(-1).ToString("yyyy-MM-dd"); // 上期开始时间 string preTempStartDate = DateTime.Parse(tempStartDate).AddMonths(-1).ToString("yyyy-MM-dd"); // 上期结束时间 string preTempEndDate = DateTime.Parse(tempStartDate).AddDays(-1).ToString("yyyy-MM-dd"); decimal monthAH = decimal.Zero; decimal monthUse = decimal.Zero; decimal monthApply = decimal.Zero; // 已发生 monthAH = BLL.CBSRule.GetAHMoney(tempCode, tempStartDate, tempEndDate, "", ""); // 合同占用: // 合同占用 = 本时间段以内的合同款项总和-本时间段内的合同款项中已经发生的部分(该部分已经计算在已发生金额中了) monthUse = BLL.CBSRule.GetContractAllocationCost(tempCode, "", "", tempStartDate, tempEndDate) - BLL.CBSRule.GetContractAllocationHappenedCost(tempCode, "", "", tempStartDate, tempEndDate); // 待审批的合同 monthApply = BLL.CBSRule.GetApplyContractAllocationCost(tempCode, "", "", tempStartDate, tempEndDate); drs[i]["MonthAH" + month.ToString()] = @"<a href=## class=trAH code='" + tempCode + @"' startDate='" + tempStartDate + @"' endDate='" + tempEndDate + @"' NumberType='AH' onclick='ShowNumberDetail(this.code,this.NumberType,this.startDate,this.endDate);' >" + BLL.StringRule.BuildMoneyWanFormatString(monthAH) + @"</a>"; drs[i]["MonthUse" + month.ToString()] = @"<a href=## class=trUse code='" + tempCode + @"' startDate='" + tempStartDate + @"' endDate='" + tempEndDate + @"' NumberType='Use' onclick='ShowNumberDetail(this.code,this.NumberType,this.startDate,this.endDate);' >" + BLL.StringRule.BuildMoneyWanFormatString(monthUse) + "</a>"; drs[i]["MonthApply" + month.ToString()] = @"<a href=## class=trApply code='" + tempCode + @"' startDate='" + tempStartDate + @"' endDate='" + tempEndDate + @"' NumberType='Apply' onclick='ShowNumberDetail(this.code,this.NumberType,this.startDate,this.endDate);' >" + BLL.StringRule.BuildMoneyWanFormatString(monthApply) + "</a>"; drs[i]["CurrentPlanCost" + month.ToString()] = drMonth["Money"]; } // 取年份 budget.SetCurrentTable("BudgetYear"); drSelect = budget.CurrentTable.Select(String.Format("CostCode ='{0}' and IYear <> 0 ", tempCode)); foreach (DataRow drYear in drSelect) { int year = (int)drYear["IYear"]; string tempStartDate = periodStartDate.AddMonths(periodMonth * (year + periodIndex)).ToString("yyyy-MM-dd"); string tempEndDate = periodStartDate.AddMonths(periodMonth * (year + periodIndex + 1)).AddDays(-1).ToString("yyyy-MM-dd"); decimal yearAH = decimal.Zero; decimal yearUse = decimal.Zero; decimal yearApply = decimal.Zero; // 已发生 yearAH = BLL.CBSRule.GetAHMoney(tempCode, tempStartDate, tempEndDate, "", ""); yearUse = BLL.CBSRule.GetContractAllocationCost(tempCode, "", "", tempStartDate, tempEndDate) - BLL.CBSRule.GetContractAllocationHappenedCost(tempCode, "", "", tempStartDate, tempEndDate); yearApply = BLL.CBSRule.GetApplyContractAllocationCost(tempCode, "", "", tempStartDate, tempEndDate); drs[i]["YearAH" + year.ToString()] = @"<a href=## class=trAH code='" + tempCode + @"' startDate='" + tempStartDate + @"' endDate='" + tempEndDate + @"' NumberType='AH' onclick='ShowNumberDetail(this.code,this.NumberType,this.startDate,this.endDate);' >" + BLL.StringRule.BuildMoneyWanFormatString(yearAH) + "</a>"; drs[i]["YearUse" + year.ToString()] = @"<a href=## class=trUse code='" + tempCode + @"' startDate='" + tempStartDate + @"' endDate='" + tempEndDate + @"' NumberType='Use' onclick='ShowNumberDetail(this.code,this.NumberType,this.startDate,this.endDate);' >" + BLL.StringRule.BuildMoneyWanFormatString(yearUse) + "</a>"; drs[i]["YearApply" + year.ToString()] = @"<a href=## class=trApply code='" + tempCode + @"' startDate='" + tempStartDate + @"' endDate='" + tempEndDate + @"' NumberType='Apply' onclick='ShowNumberDetail(this.code,this.NumberType,this.startDate,this.endDate);' >" + BLL.StringRule.BuildMoneyWanFormatString(yearApply) + "</a>"; DataRow[] yearSelect = budget.CurrentTable.Select(String.Format("CostCode ='{0}' and IYear={1} ", tempCode, year)); if (yearSelect.Length > 0) { drs[i]["AfterPlanCost" + year.ToString()] = yearSelect[0]["Money"]; } else { // 现在IYear是期数。 所以,上次预算的第 5 期,应该等于这次预算的第4期 DataRow[] lastYearSelect = lastBudget.CurrentTable.Select(String.Format("CostCode ='{0}' and IYear={1} ", tempCode, (year + 1))); if (lastYearSelect.Length > 0) { drs[i]["AfterPlanCost" + year.ToString()] = lastYearSelect[0]["Money"]; } } } } budget.Dispose(); this.txtAllCode.Value = codes; if (type == "Detail") { this.repeat1.DataSource = new DataView(tb, String.Format(" ParentCode = '{0}' or CostCode = '{0}' ", costCode), "SortID", DataViewRowState.CurrentRows); } else { this.repeat1.DataSource = new DataView(tb, String.Format(" CostCode = '{0}' ", costCode), "", DataViewRowState.CurrentRows); } this.repeat1.DataBind(); allCost.Dispose(); } catch (Exception ex) { ApplicationLog.WriteLog(this.ToString(), ex, ""); } }