//删除 private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (treeList1.FocusedNode == null) { return; } if (!base.DeleteRight) { MsgBox.Show("您没有权限进行此项操作!"); return; } if (treeList1.FocusedNode.GetValue("SortId").ToString() == "1") { if (MessageBox.Show("确定要删除项目?", "删除项目", MessageBoxButtons.YesNo) == DialogResult.Yes) { Ps_Table_Yd ny = new Ps_Table_Yd(); ny.Suid = treeList1.FocusedNode.GetValue("Suid").ToString(); Common.Services.BaseService.Delete(ny); } } else { if (MessageBox.Show("这样会把该分类下面的项目一起删掉,确定要删除分类?", "删除分类", MessageBoxButtons.YesNo) == DialogResult.Yes) { DelAll(treeList1.FocusedNode.GetValue("Suid").ToString()); } } LoadData(); }
//添加项目 private void barButtonItem4_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (!base.AddRight) { MsgBox.Show("您没有权限进行此项操作!"); return; } TreeListNode focusedNode = treeList1.FocusedNode; if (focusedNode == null) { return; } FrmAddXM frm = new FrmAddXM(); frm.SetFrmName = "添加" + focusedNode.GetValue("CompName").ToString() + "的子项目"; if (frm.ShowDialog() == DialogResult.OK) { Ps_Table_Yd table_yd = new Ps_Table_Yd(); table_yd.CompName = frm.Comp; table_yd.ParentId = focusedNode.GetValue("Suid").ToString(); table_yd.PlanYear = frm.Plan; table_yd.Power = frm.Pow; table_yd.Progress = frm.Progre; table_yd.SortId = "1"; table_yd.Weight = frm.Weig; table_yd.BuildSize = frm.Build; table_yd.Col1 = DateTime.Now.ToString(); try { Common.Services.BaseService.Create("InsertPs_Table_Yd", table_yd); dataTable.Rows.Add(Itop.Common.DataConverter.ObjectToRow(table_yd, dataTable.NewRow())); this.Cursor = Cursors.WaitCursor; treeList1.BeginUpdate(); LoadData(); treeList1.EndUpdate(); this.Cursor = Cursors.Default; } catch (Exception ex) { MsgBox.Show("增加项目出错:" + ex.Message); } } }
//添加子分类 private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { TreeListNode focusedNode = treeList1.FocusedNode; if (focusedNode == null) { return; } if (!base.AddRight) { MsgBox.Show("您没有权限进行此项操作!"); return; } //string nodestr = (treenode.GetValue("SortId") == null) ? "" : treenode.GetValue("SortId").ToString(); if (focusedNode.GetValue("SortId") != null && focusedNode.GetValue("SortId").ToString() == "1") { MsgBox.Show(focusedNode.GetValue("CompName").ToString() + "不允许添加子分类!"); return; } FrmAddPN frm = new FrmAddPN(); frm.SetFrmName = "增加" + focusedNode.GetValue("CompName").ToString() + "的子分类"; frm.SetLabelName = "子分类名称:"; if (frm.ShowDialog() == DialogResult.OK) { Ps_Table_Yd table_yd = new Ps_Table_Yd(); table_yd.CompName = frm.ParentName; table_yd.ParentId = focusedNode.GetValue("Suid").ToString(); table_yd.Col1 = DateTime.Now.ToString(); try { Common.Services.BaseService.Create("InsertPs_Table_Yd", table_yd); dataTable.Rows.Add(Itop.Common.DataConverter.ObjectToRow(table_yd, dataTable.NewRow())); } catch (Exception ex) { MsgBox.Show("增加子分类出错:" + ex.Message); } } }
//删除所有 public void DelAll(string suid) { string conn = "ParentId=" + suid; IList <Ps_Table_Yd> list = Common.Services.BaseService.GetList <Ps_Table_Yd>("SelectPs_Table_YdListByConn", conn); if (list != null) { foreach (Ps_Table_Yd var in list) { string child = var.Suid; if (var.SortId != "1") { DelAll(child); } Ps_Table_Yd ny = new Ps_Table_Yd(); ny.Suid = child; Common.Services.BaseService.Delete(ny); } } }
//添加父分类 private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (!base.AddRight) { MsgBox.Show("您没有权限进行此项操作!"); return; } TreeListNode focusedNode = treeList1.FocusedNode; //if (focusedNode == null) //{ // return; //} FrmAddPN frm = new FrmAddPN(); if (frm.ShowDialog() == DialogResult.OK) { Ps_Table_Yd table_yd = new Ps_Table_Yd(); table_yd.CompName = frm.ParentName; table_yd.ParentId = "0"; table_yd.Col1 = DateTime.Now.ToString(); try { Common.Services.BaseService.Create("InsertPs_Table_Yd", table_yd); dataTable.Rows.Add(Itop.Common.DataConverter.ObjectToRow(table_yd, dataTable.NewRow())); this.Cursor = Cursors.WaitCursor; treeList1.BeginUpdate(); LoadData(); treeList1.EndUpdate(); this.Cursor = Cursors.Default; } catch (Exception ex) { MsgBox.Show("增加分类出错:" + ex.Message); } } }
//修改 private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (treeList1.FocusedNode == null) { return; } if (!base.EditRight) { MsgBox.Show("您没有权限进行此项操作!"); return; } if (treeList1.FocusedNode.GetValue("SortId") != null && treeList1.FocusedNode.GetValue("SortId").ToString() == "1") { FrmAddXM frm = new FrmAddXM(); frm.SetFrmName = "修改" + treeList1.FocusedNode.GetValue("CompName").ToString() + "的项目名"; frm.Comp = treeList1.FocusedNode.GetValue("CompName").ToString(); frm.Build = treeList1.FocusedNode.GetValue("BuildSize").ToString(); frm.Progre = treeList1.FocusedNode.GetValue("Progress").ToString(); frm.Plan = treeList1.FocusedNode.GetValue("PlanYear").ToString(); frm.Pow = treeList1.FocusedNode.GetValue("Power").ToString(); frm.Weig = treeList1.FocusedNode.GetValue("Weight").ToString(); if (frm.ShowDialog() == DialogResult.OK) { Ps_Table_Yd table_dy = new Ps_Table_Yd(); Itop.Client.Chen.Class1.TreeNodeToDataObject <Ps_Table_Yd>(table_dy, treeList1.FocusedNode); table_dy.CompName = frm.Comp; table_dy.BuildSize = frm.Build; table_dy.Progress = frm.Progre; table_dy.PlanYear = frm.Plan; table_dy.Power = frm.Pow; table_dy.Weight = frm.Weig; try { Common.Services.BaseService.Update <Ps_Table_Yd>(table_dy); treeList1.FocusedNode.SetValue("CompName", frm.Comp); LoadData(); } catch { } } } else { FrmAddPN frm = new FrmAddPN(); frm.SetFrmName = "修改" + treeList1.FocusedNode.GetValue("CompName").ToString() + "的分类名"; frm.ParentName = treeList1.FocusedNode.GetValue("CompName").ToString(); if (frm.ShowDialog() == DialogResult.OK) { Ps_Table_Yd table_dy = new Ps_Table_Yd(); Itop.Client.Chen.Class1.TreeNodeToDataObject <Ps_Table_Yd>(table_dy, treeList1.FocusedNode); table_dy.CompName = frm.ParentName; try { Common.Services.BaseService.Update <Ps_Table_Yd>(table_dy); treeList1.FocusedNode.SetValue("CompName", frm.ParentName); LoadData(); } catch { } } } }