Beispiel #1
0
//		private RepeaterItem GetRepeaterItem( Repeater rp , string costCode )
//		{
//			foreach( RepeaterItem li in rp.Items )
//			{
//				string tempCode = ((HtmlInputHidden)li.FindControl("txtCostCode")).Value;
//				if ( tempCode == costCode )
//					return li;
//			}
//			return null;
//		}
//
//		private decimal GetInputNumber ( RepeaterItem li, string controlName)
//		{
//			decimal re = decimal.Zero;
//			string inputText = ((HtmlInputText)li.FindControl(controlName)).Value;
//			if ( Rms.Check.StringCheck.IsNumber(inputText))
//				re = decimal.Parse(inputText);
//
//			return re;
//		}

        protected void btnSave_ServerClick(object sender, System.EventArgs e)
        {
            string projectCode = Request["ProjectCode"] + "";

            try
            {
                string costCode        = Request["CostCode"];
                string flag            = "-1";
                CostStrategyBuilder sb = new CostStrategyBuilder();
                sb.AddStrategy(new Strategy(CostStrategyName.ProjectCode, projectCode));
                sb.AddStrategy(new Strategy(CostStrategyName.Flag, flag));
                string     sql     = sb.BuildMainQueryString();
                QueryAgent qa      = new QueryAgent();
                EntityData allCost = qa.FillEntityData("Cost", sql);
                qa.Dispose();

                EntityData cbs = DAL.EntityDAO.CBSDAO.GetCBSByProject(projectCode);

                string[] codesTemp = this.txtResult.Value.Trim().Split(new char[] { ';' });
                for (int i = 0; i < codesTemp.Length; i++)
                {
                    if (codesTemp[i] != "")
                    {
                        string[] va           = codesTemp[i].Split(new char[] { ',' });
                        string   costCodeTemp = va[0];
                        string   v1           = va[1];

                        DataRow[] drs = allCost.CurrentTable.Select(String.Format("CostCode='{0}'", costCodeTemp));
                        if (drs.Length > 0)
                        {
                            if (v1 == "F")
                            {
                                drs[0]["projectQuantity"] = System.DBNull.Value;
                                drs[0]["totalMoney"]      = System.DBNull.Value;
                                drs[0]["AccountPoint"]    = 0;
                            }
                            else
                            {
                                if (va[4] != "")
                                {
                                    drs[0]["projectQuantity"] = decimal.Parse(va[4]);
                                }
                                else
                                {
                                    drs[0]["projectQuantity"] = System.DBNull.Value;
                                }

                                if (va[5] != "")
                                {
                                    drs[0]["totalMoney"] = decimal.Parse(va[5]) * IWan;
                                }
                                else
                                {
                                    drs[0]["totalMoney"] = System.DBNull.Value;
                                }

                                drs[0]["AccountPoint"] = 1;
                            }
                        }

                        drs = cbs.CurrentTable.Select(String.Format("CostCode='{0}'", costCodeTemp));
                        if (drs.Length > 0)
                        {
                            if (v1 == "T")
                            {
                                if (va[2] != "")
                                {
                                    drs[0]["UnitPrice"] = decimal.Parse(va[2]);
                                }
                                else
                                {
                                    drs[0]["UnitPrice"] = System.DBNull.Value;
                                }

                                drs[0]["MeasurementUnit"] = va[3];
                            }
                        }
                    }
                }

                AdCostEstimate(allCost, cbs);

                DAL.EntityDAO.CBSDAO.UpdateCost(allCost);
                DAL.EntityDAO.CBSDAO.UpdateCBS(cbs);

                allCost.Dispose();
                Response.Write(JavaScript.ScriptStart);
                Response.Write(JavaScript.OpenerReload(false));
                Response.Write("window.close();");
                Response.Write(JavaScript.ScriptEnd);
                Response.End();
            }
            catch (Exception ex)
            {
                ApplicationLog.WriteLog(this.ToString(), ex, "");
            }
        }
Beispiel #2
0
        protected void btnSave_ServerClick(object sender, System.EventArgs e)
        {
            string projectCode = Request["ProjectCode"] + "";
            string budgetCode  = Request["BudgetCode"] + "";
            string costCode    = Request["CostCode"] + "";
            string type        = Request["Type"] + "";

            try
            {
                EntityData budget = DAL.EntityDAO.CBSDAO.GetStandard_BudgetByCode(budgetCode);
                DataRow    dr     = budget.CurrentRow;

                int iYear       = budget.GetInt("IYear");
                int iMonth      = budget.GetInt("IMonth");
                int periodMonth = budget.GetInt("PeriodMonth");
                int afterPeriod = budget.GetInt("AfterPeriod");

                string firstDate          = iYear.ToString() + "-" + iMonth.ToString() + "-1";
                string lastPeriodLastDate = DateTime.Parse(firstDate).AddDays(-1).ToString("yyyy-MM-dd");

                string flag            = "-1";
                CostStrategyBuilder sb = new CostStrategyBuilder();
                sb.AddStrategy(new Strategy(CostStrategyName.ProjectCode, projectCode));
                sb.AddStrategy(new Strategy(CostStrategyName.Flag, flag));
                string     sql     = sb.BuildMainQueryString();
                QueryAgent qa      = new QueryAgent();
                EntityData allCost = qa.FillEntityData("Cost", sql);
                qa.Dispose();

                EntityData cbs = DAL.EntityDAO.CBSDAO.GetCBSByProject(projectCode);

                string[] codesTemp = this.txtResult.Value.Trim().Split(new char[] { ';' });
                for (int i = 0; i < codesTemp.Length; i++)
                {
                    if (codesTemp[i] != "")
                    {
                        string[] va           = codesTemp[i].Split(new char[] { ',' });
                        string   costCodeTemp = va[0];
                        string   v1           = va[1];                          // 标志是否有东西

                        //DataRow[] drs = budget.Tables["Budget"].CurrentTable.Select( String.Format( "CostCode='{0}'" ,costCodeTemp) );

                        // 先清数据
                        //处理月
                        BLL.CBSRule.ClearBudgetData(budget, costCodeTemp);

                        //加入数据
                        if (v1 == "T")
                        {
                            //先加入月份的
                            for (int m = 1; m <= IMaxMonth; m++)
                            {
                                DataRow[] drMonths = budget.Tables["BudgetMonth"].Select(String.Format(" CostCode='{0}' and IMonth={1} ", costCodeTemp, m));
                                //原先有这一行,
                                if (drMonths.Length > 0)
                                {
                                    // 超过了 每一期的月份数值
                                    if (m > periodMonth)
                                    {
                                        drMonths[0]["Money"] = decimal.Zero;
                                    }
                                    else
                                    {
                                        // 不是空
                                        if (va[1 + m] != "")
                                        {
                                            drMonths[0]["Money"] = decimal.Parse(va[1 + m]) * IWan;
                                        }
                                        else
                                        {
                                            drMonths[0]["Money"] = decimal.Zero;
                                        }
                                    }
                                }
                                //原先没有这一行
                                else
                                {
                                    DataRow drMonth = budget.GetNewRecord("BudgetMonth");
                                    drMonth["BudgetMonthCode"] = DAL.EntityDAO.SystemManageDAO.GetNewSysCode("BudgetMonthCode");
                                    drMonth["BudgetCode"]      = budgetCode;
                                    // 当前一期 ,设置为 0
                                    drMonth["IYear"]       = 0;
                                    drMonth["IMonth"]      = m;
                                    drMonth["ProjectCode"] = projectCode;
                                    drMonth["CostCode"]    = costCodeTemp;
                                    budget.AddNewRecord(drMonth, "BudgetMonth");

                                    // 不是空
                                    if (va[1 + m] != "")
                                    {
                                        drMonth["Money"] = decimal.Parse(va[1 + m]) * IWan;
                                    }
                                    else
                                    {
                                        drMonth["Money"] = decimal.Zero;
                                    }
                                }
                            }

                            // 记录本期数值
                            DataRow[] drCurrentYears  = budget.Tables["BudgetYear"].Select(String.Format(" CostCode='{0}' and IYear=0 ", costCodeTemp));
                            decimal   currentYearCost = BLL.MathRule.SumColumn(budget.Tables["BudgetMonth"], "Money", String.Format(" CostCode='{0}'  ", costCodeTemp));
                            if (drCurrentYears.Length > 0)
                            {
                                drCurrentYears[0]["Money"] = currentYearCost;
                            }
                            else
                            {
                                DataRow drCurrentYear = budget.GetNewRecord("BudgetYear");
                                drCurrentYear["BudgetYearCode"] = DAL.EntityDAO.SystemManageDAO.GetNewSysCode("BudgetYearCode");
                                drCurrentYear["BudgetCode"]     = budgetCode;
                                // 期数 第0期
                                drCurrentYear["IYear"]       = 0;
                                drCurrentYear["ProjectCode"] = projectCode;
                                drCurrentYear["CostCode"]    = costCodeTemp;
                                budget.AddNewRecord(drCurrentYear, "BudgetYear");
                                drCurrentYear["Money"] = currentYearCost;
                            }

                            //记录后续期
                            for (int m = 1; m < IMaxPeriod; m++)
                            {
                                DataRow[] drYears = budget.Tables["BudgetYear"].Select(String.Format(" CostCode='{0}' and IYear={1} ", costCodeTemp, m));
                                //原先有这一行,
                                if (drYears.Length > 0)
                                {
                                    // 超过了 每一期的月份数值
                                    if (m > afterPeriod)
                                    {
                                        drYears[0]["Money"] = decimal.Zero;
                                    }
                                    else
                                    {
                                        // 不是空
                                        if (va[13 + m] != "")
                                        {
                                            drYears[0]["Money"] = decimal.Parse(va[13 + m]) * IWan;
                                        }
                                        else
                                        {
                                            drYears[0]["Money"] = decimal.Zero;
                                        }
                                    }
                                }
                                //原先没有这一行
                                else
                                {
                                    DataRow drYear = budget.GetNewRecord("BudgetYear");
                                    drYear["BudgetYearCode"] = DAL.EntityDAO.SystemManageDAO.GetNewSysCode("BudgetYearCode");
                                    drYear["BudgetCode"]     = budgetCode;
                                    // 期数
                                    drYear["IYear"]       = m;
                                    drYear["ProjectCode"] = projectCode;
                                    drYear["CostCode"]    = costCodeTemp;
                                    budget.AddNewRecord(drYear, "BudgetYear");

                                    // 不是空
                                    if (va[13 + m] != "")
                                    {
                                        drYear["Money"] = decimal.Parse(va[13 + m]) * IWan;
                                    }
                                    else
                                    {
                                        drYear["Money"] = decimal.Zero;
                                    }
                                }
                            }

                            //处理费用项的总预算

                            DataRow[] drBudgetCosts = budget.Tables["BudgetCost"].Select(String.Format(" CostCode='{0}' ", costCodeTemp));
                            DataRow   drBudgetCost  = null;

                            if (drBudgetCosts.Length > 0)
                            {
                                drBudgetCost = drBudgetCosts[0];
                            }
                            else
                            {
                                drBudgetCost = budget.GetNewRecord("BudgetCost");
                                drBudgetCost["BudgetCostCode"] = DAL.EntityDAO.SystemManageDAO.GetNewSysCode("BudgetCostCode");
                                drBudgetCost["BudgetCode"]     = budgetCode;
                                drBudgetCost["ProjectCode"]    = projectCode;
                                drBudgetCost["CostCode"]       = costCodeTemp;
                                drBudgetCost["AccountPoint"]   = 1;
                                budget.AddNewRecord(drBudgetCost, "BudgetCost");
                            }

                            decimal bc = BLL.CBSRule.GetAHMoney(costCodeTemp, "", lastPeriodLastDate);                                          // 期前的实际发生数值
                            //后续期数总费用
                            decimal tempAfterTotalCost = BLL.MathRule.SumColumn(budget.Tables["BudgetYear"], "Money", String.Format(" CostCode='{0}' and IYear<>0 ", costCodeTemp));
                            drBudgetCost["BeforeHappenCost"] = bc;
                            drBudgetCost["AfterPlanCost"]    = tempAfterTotalCost;
                            drBudgetCost["CurrentPlanCost"]  = currentYearCost;
                            drBudgetCost["BudgetCost"]       = bc + tempAfterTotalCost + currentYearCost;
                        }
                    }
                }

                //累加子项到父项
                BLL.CBSRule.AdCostEstimate(costCode, type, cbs, budget, iYear, iMonth, periodMonth, afterPeriod, budgetCode, lastPeriodLastDate, projectCode);

                // 更新主表总费用
                //EntityData cbs = DAL.EntityDAO.CBSDAO.GetCBSByProject(projectCode);
                //BLL.CBSRule.SumTotalMoney(cbs,budget);


                DAL.EntityDAO.CBSDAO.SubmitAllStandard_Budget(budget);
                budget.Dispose();
                cbs.Dispose();

                Response.Write(Rms.Web.JavaScript.ScriptStart);
                Response.Write(Rms.Web.JavaScript.Alert(false, "保存完毕 !"));

                string from = Request["From"] + "";
                if (from == "DynamicCost")
                {
                    Response.Write(" window.navigate( 'DynamicCostInfo.aspx?ProjectCode=" + projectCode + "&CostCode=" + costCode + "' ); ");
                }
                else
                {
                    Response.Write(" window.navigate( 'BudgetInfo.aspx?ProjectCode=" + projectCode + "&BudgetCode=" + budgetCode + "&CostCode=" + costCode + "' ); ");
                }

                Response.Write(Rms.Web.JavaScript.OpenerReload(false));
                Response.Write(Rms.Web.JavaScript.ScriptEnd);
            }
            catch (Exception ex)
            {
                ApplicationLog.WriteLog(this.ToString(), ex, "");
            }
        }