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;
                    for (int i = 1; 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;

                                default:
                                    l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, dts.Rows[i][dc.ColumnName].ToString(), null);
                                    break;
                            }
                        }
                        l1.Flag = ll1.UID;
                        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 = ll1.UID;
                        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_Info1.RefreshData();
                }
            }
            catch (Exception ex) { MsgBox.Show(columnname + ex.Message); MsgBox.Show("�����ʽ����ȷ��"); }
        }
Exemplo n.º 2
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);
                    string str = "";
                    IList<Substation_Info> lii = new List<Substation_Info>();
                    DateTime s8 = DateTime.Now;
                    int x=0;
                    str = "";
                    for (int i = 0; i < dts.Rows.Count; i++)
                    {

                        if (dts.Rows[i][1].ToString().IndexOf("�ϼ�") >= 0)
                            continue;

                        if (dts.Rows[i]["Title"].ToString() == "500ǧ��" || dts.Rows[i]["Title"].ToString() == "220ǧ��" || dts.Rows[i]["Title"].ToString() == "110ǧ������" || dts.Rows[i]["Title"].ToString() == "110ǧ��ר��")
                        {
                            if (dts.Rows[i]["Title"].ToString() == "110ǧ��ר��")
                            {
                                str = "ר��";
                            }
                            else if (dts.Rows[i]["Title"].ToString() == "110ǧ������")
                                str = "����";
                            else
                                str = "";
                            //continue;
                        }
                        try
                        {
                            int.Parse(dts.Rows[i]["S3"].ToString());
                        }
                        catch
                        {
                            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.S4 = str;
                        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.UID += "|" + ProjectUID;
                        l1.AreaName = lll.AreaName;
                        l1.Title = lll.Title;
                        l1.AreaID = ProjectUID;
                        l1.Flag = selectid;
                        try
                        {
                            int tx = int.Parse(l1.S2);
                            if (tx > DateTime.Now.Year)
                                l1.Flag = "2";
                            else
                                l1.Flag = "1";
                        }
                        catch { l1.Flag = "1"; }
                        string con = "AreaID='" + ProjectUID + "' and Title='" + l1.Title + "' and Flag='" + selectid + "'";
                        object obj = Services.BaseService.GetObject("SelectSubstation_InfoByCon", con);

                        ExpressionCalculator ca = new ExpressionCalculator();
                        if (lll.L4 != "")
                        {
                            if (ca.ISIllegal(ca.CharConverter(lll.L4)))
                            {
                                lll.L2 = ca.Calculator(ca.CharConverter(lll.L4), 2);
                            }
                        }
                        if (obj != null)
                        {
                            lll.UID = ((Substation_Info)obj).UID;

                            Services.BaseService.Update<Substation_Info>(lll);
                        }
                        else
                        {
                            lll.UID += "|" + ProjectUID;
                            Services.BaseService.Create<Substation_Info>(lll);
                        }
                    }
                    this.ctrlSubstation_Info1.CalcTotal();
                }
            }
            catch (Exception ex) { MsgBox.Show(columnname + ex.Message); MsgBox.Show("�����ʽ����ȷ��"); }
        }