Example #1
0
        private void InsertInfo()
        {
            string columnname = "";

              try {
                  DataTable dts = new DataTable();
                  OpenFileDialog op = new OpenFileDialog();
                  op.Filter = "Excel文件(*.xls)|*.xls";
                  if (op.ShowDialog() == DialogResult.OK) {
                      dts = GetExcel(op.FileName);
                      IList<PDrelcontent> lii = new List<PDrelcontent>();
                      DateTime s8 = DateTime.Now;
                      for (int i = 0; i < dts.Rows.Count; i++) {

                          PDrelcontent l1 = new PDrelcontent();
                          foreach (DataColumn dc in dts.Columns) {
                              columnname = dc.ColumnName;
                              Type type = l1.GetType().GetProperty(dc.ColumnName).PropertyType;
                              //if (dts.Rows[i][dc.ColumnName].ToString() == "")
                              //    continue;
                              if (columnname == "TDdatetime" && Convert.ToDateTime(dts.Rows[i][dc.ColumnName]).Year != ParentObj.Year)
                              {
                                  MessageBox.Show("第'" + (i + 1) + "'行停电日期和年份不符!");
                                  break;
                              }
                              if (type == typeof(DateTime))
                              {
                                  l1.GetType().GetProperty(dc.ColumnName).SetValue(l1,Convert.ToDateTime(dts.Rows[i][dc.ColumnName]) , null);
                              }
                              else if (type == typeof(double)) {
                                  l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, Convert.ToDouble(dts.Rows[i][dc.ColumnName]), null);
                              }
                              else if (type == typeof(decimal)) {
                                  l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, Convert.ToDecimal(dts.Rows[i][dc.ColumnName]), null);
                              }
                              else if (type == typeof(int)) {
                                  l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, Convert.ToInt32(dts.Rows[i][dc.ColumnName]), null);
                              } else if (type == typeof(string)) {
                                  l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, dts.Rows[i][dc.ColumnName].ToString(), null);
                              }

                          }

                          lii.Add(l1);
                      }

                      foreach (PDrelcontent lll in lii) {

                         PDrelcontent l1 = new PDrelcontent();

                          IList<PDrelcontent> list = new List<PDrelcontent>();

                          //{
                          lll.ID = Guid.NewGuid().ToString();
                          lll.ParentID = parentID;
                          Services.BaseService.Create<PDrelcontent>(lll);
                          //}
                      }
                      ParentID = ParentObj.ID;  //重新显示数据

                  }
              } catch (Exception ex) {
                  MsgBox.Show(columnname + ex.Message);
                  MsgBox.Show("导入格式不正确!");

              }
        }
Example #2
0
        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            PdDateEdit PDT = new PdDateEdit();
              if (ParentObj==null)
              {
                  Itop.Common.MsgBox.ShowYesNo("配电区域为空!");
                  return;
              }
              PDT.parentobj = ParentObj;
              PDrelcontent pdr = new PDrelcontent();
              pdr.ParentID = ParentObj.ID;
              //pdr.TDdatetime
              PDT.RowData = pdr;
              if (PDT.ShowDialog() == DialogResult.OK) {

                  pdr = PDT.RowData;
                  //if (pdr.TDdatetime.Year!=ParentObj.Year)
                  //{
                  //    Itop.Common.MsgBox.ShowYesNo("停电日期和年份不符!");
                  //    return;
                  //}
                  Itop.Client.Common.Services.BaseService.Create<PDrelcontent>(pdr);

                  //datatable.Rows.Add(Itop.Common.DataConverter.ObjectToRow(pdr, datatable.NewRow()));
                  ((DataTable)gridControl1.DataSource).Rows.Add(Itop.Common.DataConverter.ObjectToRow(pdr, datatable.NewRow()));
                  //gridControl1.DataSource = datatable;
              }
        }