Ejemplo n.º 1
0
 private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (this.gridView2.FocusedRowHandle > -1)
     {
         IList<string> filedList = new List<string>();
         IList<string> capList = new List<string>();
         for (int i = 0; i < gridView1.Columns.Count; i++)
         {
             capList.Add(gridView1.Columns[i].Caption);
             filedList.Add(gridView1.Columns[i].FieldName);
         }
         OpenFileDialog op = new OpenFileDialog();
         op.Filter = "Excel文件(*.xls)|*.xls";
         if (op.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 DataTable table = OperTable.GetExcel(op.FileName, filedList, capList);
                 for (int i = 0; i < table.Rows.Count; i++)
                 {
                     if (table.Rows[i][0].ToString().IndexOf("合计") > 0 || table.Rows[i][1].ToString().IndexOf("合计") > 0)
                         continue;
                     Ps_Table_AreaData area = new Ps_Table_AreaData();
                     area.ID += "|" + ProjectID;
                     area.SortID = OperTable.GetAreaMaxSort()+1;
                     area.ParentID = this.gridView2.GetRowCellValue(this.gridView2.FocusedRowHandle, "ID").ToString();
                     area.ProjectID = ProjectID;
                     foreach (DataColumn col in table.Columns)
                     {
                         if(col.ColumnName=="Yearf")
                             area.GetType().GetProperty(col.ColumnName).SetValue(area, int.Parse(table.Rows[i][col].ToString()), null);
                         else
                             area.GetType().GetProperty(col.ColumnName).SetValue(area, double.Parse(table.Rows[i][col].ToString()), null);
                     }
                     Common.Services.BaseService.Create<Ps_Table_AreaData>(area);
                 }
             }
             catch { }
             InitGrid1();
         }
     }
     else
         MessageBox.Show("没有选择地区(如果没有请添加一个)","导入EXCEL",MessageBoxButtons.OK);
 }