Exemplo n.º 1
0
        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);

            if (row != null)
            {
                PDrelcontent PD  = Itop.Common.DataConverter.RowToObject <PDrelcontent>(row);
                PdDateEdit   PDT = new PdDateEdit();
                PDT.parentobj = ParentObj;
                PDT.RowData   = PD;
                if (PDT.ShowDialog() == DialogResult.OK)
                {
                    PD = PDT.RowData;
                    //if (PD.TDdatetime.Year != ParentObj.Year) {
                    //    Itop.Common.MsgBox.ShowYesNo("停电日期和年份不符!");
                    //    return;
                    //}
                    Itop.Client.Common.Services.BaseService.Update <PDrelcontent>(PD);
                    ParentID = ParentObj.ID;
                    //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;
                }
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 3
0
        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);

            if (row != null)
            {
                PDrelcontent dev = Itop.Common.DataConverter.RowToObject <PDrelcontent>(row);
                if (Itop.Common.MsgBox.ShowYesNo("是否确认删除?") == DialogResult.Yes)
                {
                    Itop.Client.Common.Services.BaseService.Delete <PDrelcontent>(dev);
                    ((DataTable)gridControl1.DataSource).Rows.Remove(row);
                }
            }
        }
Exemplo n.º 4
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("导入格式不正确!");
            }
        }