private bool InsertDataPsp(InDataClass idc, string filename) { bool result = false; UCDeviceBase curDevice = GetDevice(idc.SType, idc.Sclass); IList <string> filedList = new List <string>(); IList <string> capList = new List <string>(); WaitDialogForm wait = new WaitDialogForm("", "正在导入" + idc.Name + "数据, 请稍候..."); for (int i = 0; i < curDevice.gridView1.Columns.Count; i++) { capList.Add(curDevice.gridView1.Columns[i].Caption); filedList.Add(curDevice.gridView1.Columns[i].FieldName); } try { DataTable table = DeviceHelper.GetExcel(filename, filedList, capList); curDevice.UpdateIn(table); wait.Caption = "已成功导入" + idc.Name + "数据!"; wait.Close(); result = true; return(result); } catch (Exception) { wait.Close(); return(result); } }
private void DealTreelist(InDataClass idc) { SetYear(idc.YearFlag); AddFixColumn(); Ps_History psp_Type = new Ps_History(); psp_Type.Forecast = idc.IType; psp_Type.Col4 = ProjectUID; IList <Ps_History> listTypes = Common.Services.BaseService.GetList <Ps_History>("SelectPs_HistoryByForecast", psp_Type); treeList1.DataSource = listTypes; }
private void AddFixeData() { InList.Clear(); InDataClass JI = new InDataClass(); JI.Name = "经济人口数据"; JI.FileName = "经济人口数据"; JI.Flag = 1; JI.YearFlag = "电力发展实绩经济"; JI.SType = "5"; JI.IType = 5; InList.Add(JI); InDataClass DL = new InDataClass(); DL.Name = "电量数据"; DL.FileName = "电量数据"; DL.Flag = 1; DL.YearFlag = "电力发展实绩电量"; DL.SType = "6"; DL.IType = 6; InList.Add(DL); InDataClass FH = new InDataClass(); FH.Name = "负荷数据"; FH.FileName = "负荷数据"; FH.Flag = 1; FH.YearFlag = "电力发展实绩负荷"; FH.SType = "7"; FH.IType = 7; InList.Add(FH); InDataClass DY = new InDataClass(); DY.Name = "电源"; DY.FileName = "电源"; DY.Flag = 2; DY.YearFlag = ""; DY.Sclass = "Itop.TLPSP.DEVICE.UCDeviceDY"; DY.SType = "30"; InList.Add(DY); InDataClass BDZ = new InDataClass(); BDZ.Name = "变电站"; BDZ.FileName = "变电站"; BDZ.Flag = 2; BDZ.YearFlag = ""; BDZ.Sclass = "Itop.TLPSP.DEVICE.UCDeviceBDZ"; BDZ.SType = "20"; InList.Add(BDZ); InDataClass XL = new InDataClass(); XL.Name = "线路"; XL.FileName = "线路"; XL.Flag = 2; XL.YearFlag = ""; XL.Sclass = "Itop.TLPSP.DEVICE.UCDeviceXL"; XL.SType = "05"; InList.Add(XL); }
private bool InsertdataHistory(InDataClass idc, string filename) { bool result = false; string columnname = ""; DealTreelist(idc); DataTable dts = GetExcel(filename); IList <Ps_History> lii = new List <Ps_History>(); DateTime s8 = DateTime.Now; int x = 0; WaitDialogForm wait = new WaitDialogForm("", "正在导入" + idc.Name + "数据, 请稍候..."); try { for (int i = 0; i < dts.Rows.Count; i++) { this.Cursor = Cursors.WaitCursor; Ps_History l1 = new Ps_History(); foreach (DataColumn dc in dts.Columns) { columnname = dc.ColumnName; if (dts.Rows[i][dc.ColumnName].ToString() == "") { continue; } switch (l1.GetType().GetProperty(dc.ColumnName).PropertyType.Name) { case "Double": if (dts.Rows[i][dc.ColumnName] == null || dts.Rows[i][dc.ColumnName] == DBNull.Value || dts.Rows[i][dc.ColumnName].ToString() == "") { l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, 0, null); break; } l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, Convert.ToDouble(dts.Rows[i][dc.ColumnName]), null); break; case "Int32": if (dts.Rows[i][dc.ColumnName] == null || dts.Rows[i][dc.ColumnName] == DBNull.Value || dts.Rows[i][dc.ColumnName].ToString() == "") { l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, 0, null); break; } l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, Convert.ToInt32(dts.Rows[i][dc.ColumnName]), null); break; default: l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, dts.Rows[i][dc.ColumnName], null); break; } } l1.Forecast = idc.IType; l1.Col4 = ProjectUID; l1.ForecastID = idc.SType; lii.Add(l1); } int parenti = -4; Ps_History psl1; for (int i = 0; i < lii.Count; i++) { psl1 = lii[i]; psl1.Sort = i; string con = "Col4='" + ProjectUID + "' and Title='" + psl1.Title + "' and Forecast='" + idc.SType + "' and ParentID='" + psl1.ParentID + "'"; object obj = Services.BaseService.GetObject("SelectPs_HistoryByCondition", con); if (obj != null) { psl1.ID = ((Ps_History)obj).ID; if (psl1.ParentID.Contains("-")) { psl1.ParentID = ((Ps_History)obj).ParentID; } Services.BaseService.Update <Ps_History>(psl1); } else { psl1.ID = Guid.NewGuid().ToString() + "|" + ProjectUID; Services.BaseService.Create <Ps_History>(psl1); } for (int j = i + 1; j < lii.Count; j++) { if (lii[j].ParentID == parenti.ToString()) { lii[j].ParentID = psl1.ID; } } parenti--; } DealTreelist(idc); wait.Close(); wait = new WaitDialogForm("", "正在重新计算" + idc.Name + "数据, 请稍候..."); for (int i = 0; i < lii.Count; i++) { TreeListNode nd = treeList1.FindNodeByKeyID(lii[i].ID); if (nd != null) { foreach (TreeListColumn tr in treeList1.Columns) { if (tr.FieldName.IndexOf("y") >= 0) { CalculateSum(nd, tr); } } } } this.Cursor = Cursors.Default; wait.Caption = "已成功导入" + idc.Name + "数据!"; wait.Close(); result = true; return(result); } catch (Exception ex) { this.Cursor = Cursors.Default; wait.Close(); MsgBox.Show(columnname + ex.Message); MsgBox.Show("导入格式不正确!"); return(result); } }