private void btnOK_Click(object sender, EventArgs e) { if (SaveRecord()) { if (checkEdit1.Checked) { area.InitGrid1(); _obj = new Ps_Table_AreaData(); IList<Ps_Table_AreaData> list1 = new List<Ps_Table_AreaData>(); list1.Add(_obj); this.vGridControl.DataSource = list1; } else { DialogResult = DialogResult.OK; } } }
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); }
//添加地区 private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { FrmAddPN frm = new FrmAddPN(); frm.SetFrmName = "添加地区"; frm.SetLabelName = "地区名称"; if (frm.ShowDialog() == DialogResult.OK) { Ps_Table_AreaData data = new Ps_Table_AreaData(); data.ID += "|" + ProjectID; data.ParentID = "0"; data.ProjectID = ProjectID; data.SortID = OperTable.GetAreaMaxSort()+1; data.Area = frm.ParentName; Common.Services.BaseService.Create<Ps_Table_AreaData>(data); } InitGrid2(); }
private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.gridView2.FocusedRowHandle >= 0) { FrmAddPopu frm = new FrmAddPopu(); frm.Area = this; frm.Text = "添加记录"; frm.IsCreate = true; frm.ProjectID = ProjectID; frm.ParentID = this.gridView2.GetRowCellValue(this.gridView2.FocusedRowHandle, "ID").ToString(); Ps_Table_AreaData obj = new Ps_Table_AreaData(); frm.Object = obj; if (frm.ShowDialog() == DialogResult.OK) { frm.Close(); InitGrid1(); } } else { MessageBox.Show("请先选择一个地区", "添加", MessageBoxButtons.OK); } }