Exemplo 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;
                     }
                     PSP_PowerSubstationInfo area = new PSP_PowerSubstationInfo();
                     area.UID        = Guid.NewGuid().ToString() + "|" + ProjectID;
                     area.AreaID     = ProjectID;
                     area.CreateDate = DateTime.Now;
                     string f = this.gridView2.GetRowCellValue(this.gridView2.FocusedRowHandle, "Title").ToString();
                     if (f == "现状")
                     {
                         f = "1";
                     }
                     else if (f == "规划")
                     {
                         f = "2";
                     }
                     area.Flag = f;
                     foreach (DataColumn col in table.Columns)
                     {
                         area.GetType().GetProperty(col.ColumnName).SetValue(area, table.Rows[i][col].ToString(), null);
                     }
                     Common.Services.BaseService.Create <PSP_PowerSubstationInfo>(area);
                 }
             }
             catch (Exception a) { MessageBox.Show(a.Message); }
             InitGrid1();
         }
     }
     else
     {
         MessageBox.Show("没有选择规划或现状", "导入EXCEL", MessageBoxButtons.OK);
     }
 }
Exemplo n.º 2
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_GDP area = new Ps_Table_GDP();
                     area.ID       += "|" + ProjectID;
                     area.SortID    = OperTable.GetGDPMaxSort() + 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_GDP>(area);
                 }
             }
             catch { }
             InitGrid1();
         }
     }
     else
     {
         MessageBox.Show("没有选择地区(如果没有请添加一个)", "导入EXCEL", MessageBoxButtons.OK);
     }
 }
Exemplo n.º 3
0
        private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            IList <string> filedList = new List <string>();
            IList <string> capList   = new List <string>();

            for (int i = 0; i < gridView2.Columns.Count; i++)
            {
                if (gridView2.Columns[i].Visible == true)
                {
                    capList.Add(gridView2.Columns[i].Caption);
                    filedList.Add(gridView2.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)
                        {
                            continue;
                        }
                        PS_Table_Area_TYPE area = new PS_Table_Area_TYPE();
                        area.ID       += "|" + ProjectID;
                        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, table.Rows[i][col].ToString(), null);
                            }
                        }
                        Common.Services.BaseService.Create <PS_Table_Area_TYPE>(area);
                    }
                }
                catch { }
                InitGrid2();
            }
        }
Exemplo n.º 4
0
        //导入数据
        private void barButtonItem12_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            IList <string> filedList = new List <string>();
            IList <string> capList   = new List <string>();

            for (int i = 0; i < gridView1.Columns.Count; i++)
            {
                if (gridView1.Columns[i].Visible == true)
                {
                    capList.Add(gridView1.Columns[i].Caption);
                    filedList.Add(gridView1.Columns[i].FieldName);
                }
            }
            OpenFileDialog op = new OpenFileDialog();

            op.Filter = "Excel文件(*.xls)|*.xls";
            string Message = "";

            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)
                        {
                            continue;
                        }
                        Ps_Table_Report area = new Ps_Table_Report();
                        area.ProjectID = MIS.ProgUID;
                        foreach (DataColumn col in table.Columns)
                        {
                            if (col.ColumnName == "Num1" || col.ColumnName == "image1" || col.ColumnName == "image2")
                            {
                                //area.GetType().GetProperty(col.ColumnName).SetValue(area, Convert.ToInt32(table.Rows[i][col]), null);
                            }
                            else if (col.ColumnName == "TableID")
                            {
                                string con = " TableID='" + table.Rows[i][col].ToString() + "' and ProjectID='" + MIS.ProgUID + "'";
                                IList <Ps_Table_Report> templist = Common.Services.BaseService.GetList <Ps_Table_Report>("SelectPs_Table_ReportListByConn", con);
                                if (templist.Count > 0)
                                {
                                    Message = "[" + table.Rows[i][col].ToString() + "]";
                                }
                                else
                                {
                                    area.GetType().GetProperty(col.ColumnName).SetValue(area, table.Rows[i][col].ToString(), null);
                                }
                            }
                            else
                            {
                                area.GetType().GetProperty(col.ColumnName).SetValue(area, table.Rows[i][col], null);
                            }
                        }
                        area.Num1   = Convert.ToInt32(Common.Services.BaseService.GetObject("SelectPs_Table_ReportMaxNum1", " ProjectID='" + MIS.ProgUID + "'")) + 1;
                        area.image1 = new byte[0];
                        area.image2 = new byte[0];
                        Common.Services.BaseService.Create <Ps_Table_Report>(area);
                    }
                    InitData();
                    MessageBox.Show("导入完成!");
                    if (Message.Length != 0)
                    {
                        MessageBox.Show("表标识" + Message + " 已经存在,未重复添加!");
                    }
                }
                catch { MessageBox.Show("格式有误,导入失败!"); }
            }
        }