private void FormCalculator_Load(object sender, EventArgs e) { HideToolBarButton(); #region ��ƽ��s dt = new DataTable(); dt.Columns.Add("Name"); //MessageBox.Show("1"); foreach (DataRow dataRow in dataTable.Rows) { TreeListNode treeNode = treeList1.FindNodeByKeyID(dataRow["ID"]); if (treeNode != null && !treeNode.HasChildren) { dt.Columns.Add(dataRow["Title"].ToString().Trim(), typeof(double)); DevExpress.XtraVerticalGrid.Rows.EditorRow editorRow = new DevExpress.XtraVerticalGrid.Rows.EditorRow(); editorRow.Properties.FieldName = dataRow["Title"].ToString().Trim(); editorRow.Properties.Caption = dataRow["Title"].ToString().Trim(); editorRow.Height = 20; editorRow.Properties.RowEdit = this.repositoryItemCalcEdit4; this.vGridControl2.Rows.AddRange(new DevExpress.XtraVerticalGrid.Rows.BaseRow[] { editorRow }); } } DataRow newrow1 = dt.NewRow(); newrow1["Name"] = "��ʷ������"; foreach (DataRow dataRow in dataTable.Rows) { TreeListNode treeNode = treeList1.FindNodeByKeyID(dataRow["ID"]); if (treeNode != null && !treeNode.HasChildren) { int forecastYears = forecastReport.EndYear - forecastReport.StartYear; double[] historyValues = GenerateHistoryValue(treeNode); newrow1[dataRow["Title"].ToString().Trim()] = Calculator.AverageIncreasing(historyValues); } } dt.Rows.Add(newrow1); newrow2 = dt.NewRow(); dt.Rows.Add(newrow2); newrow2["Name"] = "��ǰ������"; vGridControl2.DataSource = dt; IList<PSP_Calc> list = Services.BaseService.GetList<PSP_Calc>("SelectPSP_CalcByFlag", type); if (list.Count == 0) { pc.ID = Guid.NewGuid().ToString(); pc.Flag = type; pc.Col1 = ""; pc.Value1 = 3; pc.Value2 = 0.4; Services.BaseService.Create<PSP_Calc>(pc); } else pc = list[0]; spinEdit1.Value = Convert.ToDecimal(pc.Value1); spinEdit2.Value = Convert.ToDecimal(pc.Value2); //textEdit1.Text = pc.Value2.ToString(); IList<PSP_Calc> list1 = Services.BaseService.GetList<PSP_Calc>("SelectPSP_CalcByFlag1", type); if (list1.Count == 0) { pc1.ID = Guid.NewGuid().ToString(); pc1.Flag = type; pc1.Col1 = "1"; int i = 1; foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "Name") continue; double value = 0; try { value = Convert.ToDouble(newrow1[dc].ToString()); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } pc1.GetType().GetProperty("Value" + i.ToString()).SetValue(pc1, value, null); newrow2[dc] = value; i++; } Services.BaseService.Create<PSP_Calc>(pc1); } else { pc1 = list1[0]; int i = 1; foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "Name") continue; double value = 0; try { value = (double)pc1.GetType().GetProperty("Value" + i.ToString()).GetValue(pc1, null); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } newrow2[dc] = value; i++; } } #endregion string str11 = " Flag='" + type + "' and Type='����ϵ��'"; IList<PSP_Calc_Spring> list2 = Services.BaseService.GetList<PSP_Calc_Spring>("SelectPSP_Calc_SpringByWhere", str11); int years = forecastReport.EndYear - forecastReport.StartYear; for (int i = 1; i <= years; i++) { bool bl = false; foreach (PSP_Calc_Spring pcs in list2) { if ((forecastReport.StartYear + i).ToString() == pcs.Name) { bl = true; } } if (!bl) { PSP_Calc_Spring pcss = new PSP_Calc_Spring(); pcss.ID = Guid.NewGuid().ToString(); pcss.Name = (forecastReport.StartYear + i).ToString(); pcss.Value1 = 0; pcss.Value2 = 0; pcss.Flag = type; pcss.Type = "����ϵ��"; Services.BaseService.Create<PSP_Calc_Spring>(pcss); list2.Add(pcss); } } Hashtable htt1 = new Hashtable(); for (int i = 0; i < forecastReport.HistoryYears; i++) { double value1 = 0.0; double value2 = 0.0; double value3 = 0.0; double value4 = 0.0; double value5 = 0.0; int yeara=forecastReport.StartYear - forecastReport.HistoryYears + i + 1; PSP_Calc_Spring pcss = new PSP_Calc_Spring(); pcss.ID = Guid.NewGuid().ToString(); pcss.Name = yeara.ToString(); pcss.Flag = type; string str = " TypeID=1 and Year=" + (yeara-1); IList<PSP_Values> pg = Services.BaseService.GetList<PSP_Values>("SelectPSP_ValuesByWhere", str); if (pg.Count > 0) value3 = pg[0].Value; str = " TypeID=1 and Year=" + yeara; IList<PSP_Values> pg1 = Services.BaseService.GetList<PSP_Values>("SelectPSP_ValuesByWhere", str); if (pg1.Count > 0) value5 = pg1[0].Value; pcss.Value2 = (value5 - value3) / value3; str = " TypeID=2 and Year=" + (yeara-1); IList<PSP_Values> pv1 = Services.BaseService.GetList<PSP_Values>("SelectPSP_ValuesByWhere", str); if (pv1.Count > 0) value1 = pv1[0].Value; str = " TypeID=2 and Year=" + yeara; IList<PSP_Values> pv2 = Services.BaseService.GetList<PSP_Values>("SelectPSP_ValuesByWhere", str); if (pv2.Count > 0) value2 = pv2[0].Value; if (value1 != 0 && value3 != 0) { value4 = (value2 - value1) / (value1 * (value5 - value3) / value3); } pcss.Value1 = value4; list2.Add(pcss); } gridControl1.DataSource = list2; ////////string str12 = " Flag='" + type + "' and Type='ר��ָ��'"; ////////IList<PSP_Calc_Spring> list3 = Services.BaseService.GetList<PSP_Calc_Spring>("SelectPSP_Calc_SpringByWhere", str12); ////////int years1 = forecastReport.EndYear - forecastReport.StartYear; ////////for (int i = 1; i <= years1; i++) ////////{ //////// bool bl = false; //////// foreach (PSP_Calc_Spring pcs in list3) //////// { //////// if ((forecastReport.StartYear + i).ToString() == pcs.Name) //////// { //////// bl = true; //////// } //////// } //////// if (!bl) //////// { //////// PSP_Calc_Spring pcss = new PSP_Calc_Spring(); //////// pcss.ID = Guid.NewGuid().ToString(); //////// pcss.Name = (forecastReport.StartYear + i).ToString(); //////// pcss.Value1 = 0; //////// pcss.Value2 = 0; //////// pcss.Flag = type; //////// pcss.Type = "ר��ָ��"; //////// Services.BaseService.Create<PSP_Calc_Spring>(pcss); //////// list3.Add(pcss); //////// } ////////} ////////gridControl2.DataSource = list3; }
private void FormCalculator_Load(object sender, EventArgs e) { #region ��ƽ��s dt = new DataTable(); dt.Columns.Add("Name"); foreach (DataRow dataRow in dataTable.Rows) { TreeListNode treeNode = treeList1.FindNodeByKeyID(dataRow["ID"]); if (!treeNode.HasChildren) { dt.Columns.Add(dataRow["Title"].ToString().Trim(),typeof(double)); DevExpress.XtraVerticalGrid.Rows.EditorRow editorRow = new DevExpress.XtraVerticalGrid.Rows.EditorRow(); editorRow.Properties.FieldName = dataRow["Title"].ToString().Trim(); editorRow.Properties.Caption = dataRow["Title"].ToString().Trim(); editorRow.Height = 20; editorRow.Properties.RowEdit = this.repositoryItemCalcEdit4; this.vGridControl2.Rows.AddRange(new DevExpress.XtraVerticalGrid.Rows.BaseRow[] { editorRow }); } } DataRow newrow1 = dt.NewRow(); newrow1["Name"] = "������(����)"; foreach (DataRow dataRow in dataTable.Rows) { TreeListNode treeNode = treeList1.FindNodeByKeyID(dataRow["ID"]); if (!treeNode.HasChildren) { int forecastYears = forecastReport.EndYear - forecastReport.StartYear; double[] historyValues = GenerateHistoryValue(treeNode); newrow1[dataRow["Title"].ToString().Trim()] = Calculator.AverageIncreasing(historyValues); } } //dt.Rows.Add(newrow1); newrow2 = dt.NewRow(); dt.Rows.Add(newrow2); newrow2["Name"] = "��ǰ������"; vGridControl2.DataSource = dt; IList<PSP_Calc> list = Services.BaseService.GetList<PSP_Calc>("SelectPSP_CalcByFlag", type); if (list.Count == 0) { pc.ID = Guid.NewGuid().ToString(); pc.Flag = type; pc.Col1 = ""; pc.Value1 = 3; pc.Value2 = 0.4; Services.BaseService.Create<PSP_Calc>(pc); } else pc = list[0]; //textEdit1.Text = pc.Value2.ToString(); IList<PSP_Calc> list1 = Services.BaseService.GetList<PSP_Calc>("SelectPSP_CalcByFlag1", type); if (list1.Count == 0) { pc1.ID = Guid.NewGuid().ToString(); pc1.Flag = type; pc1.Col1 = "1"; int i = 1; foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "Name") continue; double value = 0; try { value = Convert.ToDouble(newrow1[dc].ToString()); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } pc1.GetType().GetProperty("Value" + i.ToString()).SetValue(pc1, value, null); newrow2[dc] = value; i++; } Services.BaseService.Create<PSP_Calc>(pc1); } else { pc1 = list1[0]; int i = 1; foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "Name") continue; double value = 0; try { value = (double)pc1.GetType().GetProperty("Value" + i.ToString()).GetValue(pc1, null); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } newrow2[dc] = value; i++; } } #endregion IList<PSP_Calc_Spring> list2 = Services.BaseService.GetList<PSP_Calc_Spring>("SelectPSP_Calc_SpringByFlag", type); int years = forecastReport.EndYear - forecastReport.StartYear; for (int i = 1; i <= years; i++) { bool bl = false; foreach (PSP_Calc_Spring pcs in list2) { if ((forecastReport.StartYear + i).ToString() == pcs.Name) { bl = true; } } if (!bl) { PSP_Calc_Spring pcss = new PSP_Calc_Spring(); pcss.ID = Guid.NewGuid().ToString(); pcss.Name = (forecastReport.StartYear + i).ToString(); pcss.Value1 = 0; pcss.Value2 = 0; pcss.Flag = type; Services.BaseService.Create<PSP_Calc_Spring>(pcss); list2.Add(pcss); } } }
/// <summary> /// 用年增长率计算预测数据 /// </summary> /// <param name="baseValue">基年数据</param> /// <param name="averageIncreasing">年均增长率</param> /// <param name="years">需要预测的年数</param> /// <returns>预测数据数组</returns> public static double[] ArverageIncreasingMethod(double[] historyValue, double baseValue, int years,int i) { bool bz = false; foreach (double d in historyValue) { if (d == 0) bz = true; } double[] rt = new double[years]; if (!bz) { double value = 0; PSP_Calc pc1 = new PSP_Calc(); IList<PSP_Calc> list1 = Services.BaseService.GetList<PSP_Calc>("SelectPSP_CalcByFlag1", type); if (list1.Count ==0) { pc1.ID = Guid.NewGuid().ToString(); pc1.Flag = type; pc1.Col1 = "1"; pc1.Value1 = 0.0000001; pc1.Value2 = 0.0000001; pc1.Value3 = 0.0000001; pc1.Value4 = 0.0000001; pc1.Value5 = 0.0000001; pc1.Value6 = 0.0000001; pc1.Value7 = 0.0000001; pc1.Value8 = 0.0000001; pc1.Value9 = 0.0000001; pc1.Value10 = 0.0000001; pc1.Value11 = 0.0000001; pc1.Value12 = 0.0000001; pc1.Value13 = 0.0000001; pc1.Value14 = 0.0000001; pc1.Value15 = 0.0000001; value = AverageIncreasing(historyValue); pc1.GetType().GetProperty("Value" + i.ToString()).SetValue(pc1, value, null); Services.BaseService.Create<PSP_Calc>(pc1); } else { pc1 = list1[0]; try { value = (double)pc1.GetType().GetProperty("Value" + i.ToString()).GetValue(pc1, null); if (value == 0.0000001) { value = AverageIncreasing(historyValue); pc1.GetType().GetProperty("Value" + i.ToString()).SetValue(pc1, value, null); Services.BaseService.Update<PSP_Calc>(pc1); } } catch { value=AverageIncreasing(historyValue); pc1.GetType().GetProperty("Value" + i.ToString()).SetValue(pc1, value, null); Services.BaseService.Update<PSP_Calc>(pc1); } } double averageIncreasing = value; for (int i1 = 0; i1 < years; i1++) { rt[i1] = baseValue * Math.Pow(1 + averageIncreasing, i1 + 1); } } return rt; }
/// <summary> /// 二次移动平均法计算预测年数据,默认周期为3年 /// </summary> /// <param name="historyValue">历史数据,维数不能小于周期的2倍减1</param> /// <param name="years">要预测的年数</param> /// <returns>预测数据的数组</returns> public static double[] TwiceMoveArverageMethod(double[] historyValue, int years) { PSP_Calc pc=new PSP_Calc(); IList<PSP_Calc> list = Services.BaseService.GetList<PSP_Calc>("SelectPSP_CalcByFlag", type); if (list.Count == 0) { pc.ID = Guid.NewGuid().ToString(); pc.Flag = type; pc.Value1 = 3; pc.Value2 = 0.4; Services.BaseService.Create<PSP_Calc>(pc); } else pc = list[0]; int year = Convert.ToInt32(pc.Value1); return TwiceMoveArverageMethod(historyValue, years, year); }
/// <summary> /// 二次指数平滑法计算预测值,以平滑常数0.25进行计算 /// </summary> /// <param name="historyValue">历史数据</param> /// <param name="years">预测年数</param> /// <returns>包含预测年数据的数组</returns> public static double[] IndexSmoothMethod(double[] historyValue, int years) { PSP_Calc pc = new PSP_Calc(); IList<PSP_Calc> list = Services.BaseService.GetList<PSP_Calc>("SelectPSP_CalcByFlag", type); if (list.Count == 0) { pc.ID = Guid.NewGuid().ToString(); pc.Flag = type; pc.Value1 = 3; pc.Value2 = 0.4; Services.BaseService.Create<PSP_Calc>(pc); } else pc = list[0]; double a = Convert.ToDouble(pc.Value2); //if (years > 5) // a = 0.4; //if (years > 10) // a = 0.6; return IndexSmoothMethod(historyValue, years, a); }