private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (treeList1.FocusedNode == null) { return; } if (treeList1.FocusedNode.ParentNode == null) { MsgBox.Show("一级分类为固定内容,不能删除!"); return; } if (treeList1.FocusedNode.HasChildren) { MsgBox.Show("此分类下有子分类,请先删除子分类!"); return; } if (!base.DeleteRight) { MsgBox.Show("您没有权限进行此项操作!"); return; } if (MsgBox.ShowYesNo("是否删除分类 " + treeList1.FocusedNode.GetValue("Title") + "?") == DialogResult.Yes) { PSP_Types psp_Type = new PSP_Types(); Class1.TreeNodeToDataObject <PSP_Types>(psp_Type, treeList1.FocusedNode); PSP_Values psp_Values = new PSP_Values(); psp_Values.TypeID = psp_Type.ID; try { //DeletePSP_ValuesByType里面删除数据和分类 Common.Services.BaseService.Update("DeletePSP_ValuesByType", psp_Values); TreeListNode brotherNode = null; if (treeList1.FocusedNode.ParentNode.Nodes.Count > 1) { brotherNode = treeList1.FocusedNode.PrevNode; if (brotherNode == null) { brotherNode = treeList1.FocusedNode.NextNode; } } treeList1.DeleteNode(treeList1.FocusedNode); //删除后,如果同级还有其它分类,则重新计算此类的所有年份数据 if (brotherNode != null) { foreach (TreeListColumn column in treeList1.Columns) { if (column.FieldName.IndexOf("年") > 0) { CalculateSum(brotherNode, column); } } } } catch (Exception ex) { MsgBox.Show("删除出错:" + ex.Message); } } }