/// <summary>删除/作废 /// /// </summary> /// <param name="strOperation">操作类型</param> private void DoDeleteOrCancel(string strOperation) { string strMsg = CheckSelect(strOperation); if (strMsg != string.Empty) { MessageBox.Show(strMsg); return; } if (MessageBox.Show(string.Format("选中的对象如果存在下级,也会一起{0},是否继续操作?", strOperation), @"提示", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } IList objList = this.dataTreeListView.SelectedObjects; List <TreeListDemo> lstListDemos = new List <TreeListDemo>(); dataTreeListView.GetAllChildrensWithSelfByCollection(objList, ref lstListDemos); string strIds = lstListDemos.Aggregate(string.Empty, (current, item) => current + item.Id + ";"); strIds = strIds.TrimEnd(','); var blnReturn = strOperation == "删除" ? m_treeListDemoDal.DeleteByCond("Id in (" + strIds + ")") : m_treeListDemoDal.Update("Status =0", "Id in (" + strIds + ")"); if (blnReturn) { MessageBox.Show(string.Format("{0}成功", strOperation)); dataTreeListView.RemoveObjects(objList); } else { MessageBox.Show(string.Format("{0}失败", strOperation)); } }
private void btnSave_Click(object sender, EventArgs e) { string strReturnMsg = CheckInput(); if (strReturnMsg != string.Empty) { MessageBox.Show(strReturnMsg); return; } //新增 if (m_TreeListDemo == null) { TreeListDemo model = EntityOperateManager.AddEntity <TreeListDemo>(this.tabPage); model.ParentId = m_intParentId; int intReturn = m_TreeListDemoDAL.Add(model); if (intReturn > 0) { MessageBox.Show(@"添加成功"); model.Id = intReturn; m_lstTreeListDemo.Add(model); ListTreeListDemo = m_lstTreeListDemo; this.DialogResult = DialogResult.OK; } else { MessageBox.Show(@"添加失败"); } } //修改 else { m_TreeListDemo = EntityOperateManager.EditEntity(this.tabPage, m_TreeListDemo); bool blnReturn = m_TreeListDemoDAL.Update(m_TreeListDemo); if (blnReturn) { MessageBox.Show(@"修改成功"); ListTreeListDemo = m_lstTreeListDemo; this.DialogResult = DialogResult.OK; } else { MessageBox.Show(@"修改失败"); } } }
private void btnSave_Click(object sender, EventArgs e) { string strReturnMsg = CheckInput(); if (strReturnMsg != string.Empty) { MessageBox.Show(strReturnMsg); return; } //新增 if (m_TreeListDemo == null) { string strNameValue = txtEditName.Text.Trim() ; if (m_TreeListDemoDAL.CalcCount("Name='" + strNameValue + "'") > 0) { MessageBox.Show(@"名称已经存在"); return; } TreeListDemo model = EntityOperateManager.AddEntity <TreeListDemo>(this.tabPage); model.ParentId = m_intParentId; int intReturn = m_TreeListDemoDAL.Add(model); if (intReturn > 0) { MessageBox.Show(@"添加成功"); model.Id = intReturn; m_lstTreeListDemo.Add(model); ListTreeListDemo = m_lstTreeListDemo; this.DialogResult = DialogResult.OK; } else { MessageBox.Show(@"添加失败"); } } //修改 else { string strNameValue = txtEditName.Text.Trim() ; if (m_TreeListDemoDAL.CalcCount(" Id !=" + m_TreeListDemo.Id + " and Name='" + strNameValue + "'") > 0) { MessageBox.Show(@"名称已经存在"); return; } m_TreeListDemo = EntityOperateManager.EditEntity(this.tabPage, m_TreeListDemo); bool blnReturn = m_TreeListDemoDAL.Update(m_TreeListDemo); if (blnReturn) { MessageBox.Show(@"修改成功"); ListTreeListDemo = m_lstTreeListDemo; this.DialogResult = DialogResult.OK; } else { MessageBox.Show(@"修改失败"); } } }