Exemplo n.º 1
0
        private void InsertSubstation_Info()
        {
            //LayoutList ll1 = this.ctrlLayoutList1.FocusedObject;
            //if (ll1 == null)
            //    return;

            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 <Substation_Info> lii = new List <Substation_Info>();
                    DateTime s8 = DateTime.Now;
                    int      x  = 0;
                    for (int i = 0; i < dts.Rows.Count; i++)
                    {
                        if (dts.Rows[i][1].ToString().IndexOf("合计") >= 0)
                        {
                            continue;
                        }

                        Substation_Info l1 = new Substation_Info();
                        foreach (DataColumn dc in dts.Columns)
                        {
                            columnname = dc.ColumnName;
                            if (dts.Rows[i][dc.ColumnName].ToString() == "")
                            {
                                continue;
                            }

                            switch (dc.ColumnName)
                            {
                            case "L2":
                            case "L9":
                                double LL2 = 0;
                                try
                                {
                                    LL2 = Convert.ToDouble(dts.Rows[i][dc.ColumnName].ToString());
                                }
                                catch { }
                                l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, LL2, null);
                                break;

                            case "L10":
                                double L10 = 0;
                                try
                                {
                                    L10 = ChangeDou(dts.Rows[i][dc.ColumnName].ToString());
                                }
                                catch { }
                                l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, L10, null);
                                break;

                            case "L1":
                            case "L3":
                                int LL3 = 0;
                                try
                                {
                                    LL3 = Convert.ToInt32(dts.Rows[i][dc.ColumnName].ToString());
                                }
                                catch { }
                                l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, LL3, null);
                                break;

                            default:
                                l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, dts.Rows[i][dc.ColumnName].ToString(), null);
                                break;
                            }
                        }
                        l1.Flag       = selectid;
                        l1.CreateDate = s8.AddSeconds(i);
                        l1.AreaID     = ProjectUID;
                        lii.Add(l1);
                    }

                    foreach (Substation_Info lll in lii)
                    {
                        Substation_Info l1 = new Substation_Info();
                        l1.AreaName = lll.AreaName;
                        l1.Title    = lll.Title;
                        l1.AreaID   = ProjectUID;
                        l1.Flag     = selectid;
                        string con = "AreaID='" + ProjectUID + "' and Title='" + l1.Title + "' and Flag='" + selectid + "'";
                        object obj = Services.BaseService.GetObject("SelectSubstation_InfoByCon", con);
                        if (obj != null)
                        {
                            lll.UID = ((Substation_Info)obj).UID;
                            Services.BaseService.Update <Substation_Info>(lll);
                        }
                        else
                        {
                            Services.BaseService.Create <Substation_Info>(lll);
                        }
                    }
                    this.ctrlSubstation_Info1.CalcTotal();
                }
            }
            catch (Exception ex) { MsgBox.Show(columnname + ex.Message); MsgBox.Show("导入格式不正确!"); }
        }
Exemplo n.º 2
0
        private void InsertSubstation_Info()
        {
            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 <Substation_Info> lii = new List <Substation_Info>();
                    DateTime s8 = DateTime.Now;
                    for (int i = 2; i < dts.Rows.Count; i++)
                    {
                        if (dts.Rows[i][1].ToString().IndexOf("合计") >= 0)
                        {
                            continue;
                        }

                        Substation_Info l1 = new Substation_Info();
                        foreach (DataColumn dc in dts.Columns)
                        {
                            columnname = dc.ColumnName;
                            if (dts.Rows[i][dc.ColumnName].ToString() == "")
                            {
                                continue;
                            }

                            switch (dc.ColumnName)
                            {
                            case "L2":
                            case "L9":
                            case "L10":
                                double LL2 = 0;
                                try
                                {
                                    LL2 = Convert.ToDouble(dts.Rows[i][dc.ColumnName].ToString());
                                }
                                catch { }
                                l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, LL2, null);
                                break;

                            case "L1":
                            case "L3":
                                int LL3 = 0;
                                try
                                {
                                    LL3 = Convert.ToInt32(dts.Rows[i][dc.ColumnName].ToString());
                                }
                                catch { }
                                l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, LL3, null);
                                break;

                            case "L13":
                            case "L14":
                            case "L15":
                            case "L16":
                            case "L17":
                            case "L18":
                            case "L19":
                            case "L20":
                                ////int LL3 = 0;
                                ////try
                                ////{
                                ////    LL3 = Convert.ToInt32(dts.Rows[i][dc.ColumnName].ToString());
                                ////}
                                ////catch { }

                                l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, dts.Rows[i][dc.ColumnName].ToString(), null);
                                break;

                            default:
                                l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, dts.Rows[i][dc.ColumnName].ToString(), null);
                                break;
                            }
                        }
                        l1.Flag       = "1";
                        l1.CreateDate = s8.AddSeconds(i);
                        lii.Add(l1);
                    }

                    foreach (Substation_Info lll in lii)
                    {
                        Substation_Info l1 = new Substation_Info();
                        l1.AreaName = lll.AreaName;
                        l1.Title    = lll.Title;
                        l1.Flag     = "1";
                        object obj = Services.BaseService.GetObject("SelectSubstation_InfoByNameFlag", l1);
                        if (obj != null)
                        {
                            lll.UID = ((Substation_Info)obj).UID;
                            Services.BaseService.Update <Substation_Info>(lll);
                        }
                        else
                        {
                            Services.BaseService.Create <Substation_Info>(lll);
                        }
                    }
                    this.ctrlSubstation_Info_LangFang1.RefreshData();
                }
            }
            catch (Exception ex) { MsgBox.Show(columnname + ex.Message); MsgBox.Show("导入格式不正确!"); }
        }