using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Collections; namespace LYFZ.Software.MainBusiness.InitialSet { public partial class FrmSystemSet : LYFZ.Software.UI.InitialSet.FrmSystemSet { LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder(); LYFZ.BLL.BLL_ErpProduct ptbll = new BLL.BLL_ErpProduct(); LYFZ.BLL.BLL_ErpSystemCategory scbll = new BLL.BLL_ErpSystemCategory(); LYFZ.BLL.BLL_ErpWageCommissionSet wcsbll = new BLL.BLL_ErpWageCommissionSet(); public FrmSystemSet() { this.FormClosed += FrmSystemSet_FormClosed; this.Shown += FrmSystemSet_Shown; this.txtName.MouseDoubleClick += txtName_MouseDoubleClick; } /// /// 是否有修改类别 /// bool isUpdate = false; private string _TypeName; /// /// 传入的当前一级类别码 /// public string TypeName { get { return _TypeName; } set { _TypeName = value; } } private string _Version; /// /// 旧属性设置 已用 IsLoadAllCategory 代替 /// public string Version { set { if (string.IsNullOrEmpty(value)) { isLoadAllCategory = true; } else { isLoadAllCategory = false; } _Version = value; } } bool isLoadAllCategory = true; /// /// 是否加载所有类别码 /// public bool IsLoadAllCategory { get { return isLoadAllCategory; } set { isLoadAllCategory = value; } } /// /// 关闭事件 /// /// /// void FrmSystemSet_FormClosed(object sender, FormClosedEventArgs e) { if (isUpdate == true) { this.DialogResult = DialogResult.OK; } } /// /// 窗体加载事件 /// /// /// protected override void FrmSystemSet_Load(object sender, EventArgs e) { BindCategoryTree(); } DataTable SystemCategoryDataTable = null; /// /// 绑定类别树 /// void BindCategoryTree() { if (SystemCategoryDataTable != null) { SystemCategoryDataTable.Rows.Clear(); SystemCategoryDataTable.Dispose(); SystemCategoryDataTable = null; } LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { SystemCategoryDataTable = scbll.GetList("1=1", "Sc_ClassParentID,id,sc_className").Tables[0]; }); this.trvSystemSet.Nodes.Clear(); if (IsLoadAllCategory) { //显示所有 TreeNode node = new TreeNode(); node.Text = "系统类别"; this.trvSystemSet.Nodes.Add(node); foreach (DataRow row in SystemCategoryDataTable.Rows) { if (row["Sc_ClassParentID"].ToString() == "0") { TreeNode subNode = new TreeNode(); subNode.Text = row["Sc_ClassName"].ToString().Trim(); subNode.Tag = row; subNode.ImageKey = subNode.Text.Trim(); this.trvSystemSet.Nodes.Add(subNode); BindCategorySubTreeNode(subNode, Convert.ToInt32(row["id"])); } } node.Expand(); } else { if (!string.IsNullOrEmpty(TypeName)) { foreach (DataRow row in SystemCategoryDataTable.Rows) { if (row["Sc_ClassCode"].ToString().Trim().ToLower() == TypeName.Trim().ToLower()) { TreeNode subNode = new TreeNode(); subNode.Text = row["Sc_ClassName"].ToString().Trim(); subNode.Tag = row; subNode.ImageKey = subNode.Text.Trim(); this.trvSystemSet.Nodes.Add(subNode); BindCategorySubTreeNode(subNode, Convert.ToInt32(row["id"])); subNode.Expand(); break; } } } else { MessageBoxCustom.Show("父类别码参数不能为空"); } } } /// /// 绑定子节点 /// /// /// void BindCategorySubTreeNode(TreeNode cNode, int pid) { foreach (DataRow row in SystemCategoryDataTable.Rows) { if (row["Sc_ClassParentID"].ToString().Trim().ToLower() == pid.ToString()) { TreeNode subNode = new TreeNode(); subNode.Text = row["Sc_ClassName"].ToString().Trim(); subNode.Tag = row; subNode.ImageKey = cNode.ImageKey; cNode.Nodes.Add(subNode); BindCategorySubTreeNode(subNode, Convert.ToInt32(row["id"])); } } } /// /// 窗体加载事件 /// /// /// void FrmSystemSet_Shown(object sender, EventArgs e) { if (string.IsNullOrEmpty(TypeName)) { this.btnAdd.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.SystemCompetence, CustomAttributes.OperatingAuthority.Add); this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.SystemCompetence, CustomAttributes.OperatingAuthority.Delete); } } /// /// 点击树节点 /// /// /// protected override void trvSystemSet_AfterSelect(object sender, TreeViewEventArgs e) { try { if (this.trvSystemSet.SelectedNode.Text == "系统类别") { this.txtSc_ClassCode.Text = scbll.GetNewClassCode(0); } else { if (this.trvSystemSet.SelectedNode.Tag != null) { DataRow cRow = (DataRow)this.trvSystemSet.SelectedNode.Tag; //增加 this.txtSc_ClassCode.Text = scbll.GetNewClassCode(Convert.ToInt32(cRow["id"].ToString())); //修改 this.txtSc_ClassCode2.Text = cRow["Sc_ClassCode"].ToString(); this.txtSc_ClassName2.Text = cRow["Sc_ClassName"].ToString(); this.txtSc_ClassRemark2.Text = cRow["Sc_ClassRemark"].ToString(); this.txtName.Text = this.trvSystemSet.SelectedNode.Text.ToString(); this.txtSc_ClassName2.ReadOnly = Convert.ToBoolean(cRow["Sc_IsReadOnly"]); this.cb_EditDisabled.Checked = Convert.ToBoolean(cRow["Sc_IsDisable"]); if (LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Account.ToLower().Trim() == "admin") { this.toolTipSystemCode.SetToolTip(this.txtName, this.txtName.Text.Trim() + ":" + this.txtSc_ClassCode2.Text.Trim()); } } else { MessageBoxCustom.Show("获取父类别码失败"); } } TreeNode fistParentNode = this.trvSystemSet.SelectedNode; int whileIndex = 10; while (whileIndex > 0) { if (fistParentNode.Parent == null) { break; } else { fistParentNode = fistParentNode.Parent; } whileIndex--; } if (fistParentNode != null && fistParentNode.Text == "客户来源") { cb_EditDisabled.Visible = true; cb_AddDisabled.Visible = true; } else { cb_EditDisabled.Visible = false; cb_AddDisabled.Visible = false; } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 增加 /// /// /// protected override void btnAdd_Click(object sender, EventArgs e) { try { bool _IsReadOnly = false; int cID = 0; if (this.trvSystemSet.SelectedNode.Tag != null) { DataRow cRow = (DataRow)this.trvSystemSet.SelectedNode.Tag; cID = Convert.ToInt32(cRow["id"].ToString()); _IsReadOnly = Convert.ToBoolean(cRow["Sc_IsReadOnly"].ToString()); } else { cID = 0; } if (this.txtSc_ClassName.Text.Trim().Length > 50) { MessageBoxCustom.Show("类别名称最长不能超过50字!"); return; } LYFZ.Model.Model_ErpSystemCategory model = null; if (this.tab.SelectedIndex == 0) { //增加 model = new Model.Model_ErpSystemCategory(); #region 以下节点不能添加 switch (this.txtSc_ClassCode2.Text.Trim()) { case "BEBBBCADFEBEJBGD": case "BEBACCAFFHEAJICDF": case "BEBACCAFEGECFBJFD": MessageBoxCustom.Show("此类别不能再增加!"); return; } if (!string.IsNullOrEmpty(TypeName)) { if (TypeName.Trim() == "AAAAAAB") { DataTable dt = orbll.GetView_Custom("tb_ErpPackages", StrWhere: "Pak_PackagesClass = '" + this.txtSc_ClassCode2.Text.Trim() + "'", ShowColumnName: "ID").Tables[0]; if (dt.Rows.Count > 0) { MessageBoxCustom.Show("此类别已设置了套系名称,不能再添加子类别!"); return; } } } #endregion if (string.IsNullOrEmpty(this.txtSc_ClassCode.Text)) { MessageBoxCustom.Show("请选择树类别,增加系统类别!"); return; } if (string.IsNullOrEmpty(this.txtSc_ClassName.Text)) { MessageBoxCustom.Show("类别名称不能为空!"); return; } #region 获取树的深度不能 if (IsLoadAllCategory) { if (this.trvSystemSet.SelectedNode.Level.ToString() == "3") { MessageBoxCustom.Show("此类别不能再增加!"); return; } } else { if (this.trvSystemSet.SelectedNode.Level.ToString() == "2") { MessageBoxCustom.Show("此类别不能再增加!"); return; } } #endregion model.Sc_ClassCode = this.txtSc_ClassCode.Text; model.Sc_ClassName = this.txtSc_ClassName.Text; if (this.trvSystemSet.SelectedNode.Text == "系统类别") { model.Sc_ClassParentID = 0; } else { model.Sc_ClassParentID = cID; } model.Sc_ClassRemark = this.txtSc_ClassRemark.Text; model.Sc_IsDisable = cb_AddDisabled.Checked; model.Sc_IsReadOnly = false; model.Sc_IsDelete = false; model.Sc_URL = ""; model.Sc_IsEnabledURL = false; if (scbll.Add(model) == true) { this.isUpdate = true; this.txtSc_ClassCode.Text = ""; this.txtSc_ClassName.Text = ""; this.txtSc_ClassCode2.Text = ""; this.txtSc_ClassName2.Text = ""; this.txtSc_ClassRemark.Text = ""; this.txtName.Text = ""; this.trvSystemSet.Nodes.Clear(); this.FrmSystemSet_Load(sender, e); SetSelectAndExpand(cID); MessageBoxCustom.Show("保存成功!"); } else { MessageBoxCustom.Show("保存失败"); } } else { //修改 try { if (string.IsNullOrEmpty(this.txtSc_ClassCode2.Text)) { MessageBoxCustom.Show("请选择树类别,修改系统类别!"); return; } if (string.IsNullOrEmpty(this.txtSc_ClassName2.Text)) { MessageBoxCustom.Show("类别名称不能为空!"); return; } if (_IsReadOnly) { MessageBoxCustom.Show("此类别不能修改,请选择类别!"); return; } model = scbll.GetModel(cID); model.Sc_ClassName = this.txtSc_ClassName2.Text; model.Sc_ClassRemark = this.txtSc_ClassRemark2.Text; model.Sc_UpdateDatetime = SDateTime.Now; model.Sc_IsDisable = this.cb_EditDisabled.Checked; if (scbll.Update(model)) { this.isUpdate = true; this.txtSc_ClassCode.Text = ""; this.txtSc_ClassName.Text = ""; this.txtSc_ClassCode2.Text = ""; this.txtSc_ClassName2.Text = ""; this.txtSc_ClassRemark2.Text = ""; this.txtName.Text = ""; this.trvSystemSet.Nodes.Clear(); this.FrmSystemSet_Load(sender, e); SetSelectAndExpand(cID); MessageBoxCustom.Show("修改成功!"); } else { MessageBoxCustom.Show("保存失败"); } } catch { MessageBoxCustom.Show("请选择你要修改的类别"); } } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } void SetSelectAndExpand(int cid) { SetSelectAndExpand(cid, this.trvSystemSet.Nodes); } void SetSelectAndExpand(int cid, TreeNodeCollection Nodes) { foreach (TreeNode node in Nodes) { if (node.Tag != null) { DataRow cRow = (DataRow)node.Tag; if (cid.ToString() == cRow["id"].ToString()) { node.Expand(); this.trvSystemSet.SelectedNode = node; break; } else if (node.Nodes.Count > 0) { SetSelectAndExpand(cid, node.Nodes); } } } } /// /// 检查指定类别是否已使用,如果已使用返回 true 不可以删除 ,如果没有使用 返回 false 可以删除 /// /// /// bool DeleteCheckremove(string checkType, string classCode, out string checkMsg) { bool ret = false; checkMsg = ""; switch (checkType) { case "商品类别": ret = ptbll.Exists("Prod_Class", classCode); checkMsg = "此类别已经在商品表中使,不能删除!请删除商品后在删除此类别"; break; case "提成点方案": case "工作内容": ret = wcsbll.Exists("Wcs_TypeCode", classCode); checkMsg = "此提成类别已在“提成方案设置”中已经使用,不能删除。"; break; default: ret = false; checkMsg = "不做任何检查"; break; } return ret; } /// /// 删除 /// /// /// protected override void btnDelete_Click(object sender, EventArgs e) { try { bool Sc_IsDelete = false; int cID = 0; string Sc_ClassCode = ""; int pid = 0; string checkType = "商品类别"; if (this.trvSystemSet.SelectedNode != null) { checkType = this.trvSystemSet.SelectedNode.ImageKey.Trim(); if (this.trvSystemSet.SelectedNode.Tag != null) { DataRow sRow = (DataRow)this.trvSystemSet.SelectedNode.Tag; Sc_ClassCode = sRow["Sc_ClassCode"].ToString(); cID = Convert.ToInt32(sRow["id"].ToString()); Sc_IsDelete = Convert.ToBoolean(sRow["Sc_IsDelete"].ToString()); } if (this.trvSystemSet.SelectedNode.Parent != null && this.trvSystemSet.SelectedNode.Parent.Tag != null) { DataRow cRow = (DataRow)this.trvSystemSet.SelectedNode.Parent.Tag; pid = Convert.ToInt32(cRow["id"].ToString()); } } if (string.IsNullOrEmpty(this.trvSystemSet.SelectedNode.Text)) { MessageBoxCustom.Show("请选择你要删除的类别!"); return; } if (this.trvSystemSet.SelectedNode.Text == "系统类别") { MessageBoxCustom.Show("此类别不能删除,请选择节点!"); return; }; if (Sc_IsDelete) { MessageBoxCustom.Show("此类别不能删除,请选择节点!"); return; } //判断商品 if (!string.IsNullOrEmpty(Sc_ClassCode)) { DataTable dt_d = scbll.GetList("Sc_ClassCode='" + Sc_ClassCode + "'").Tables[0]; if (dt_d.Rows.Count > 0) { DataTable dt_s = scbll.GetList("Sc_ClassParentID='" + dt_d.Rows[0]["ID"] + "'").Tables[0]; if (dt_s.Rows.Count > 0) { MessageBoxCustom.Show("为了保证数据完整和有效性,如果您确定要删除“" + this.trvSystemSet.SelectedNode.Text + "”类别,请先删除其下的子类别后再来删除此类别!"); return; } } } string checkMsg = ""; if (DeleteCheckremove(checkType, Sc_ClassCode, out checkMsg)) { MessageBoxCustom.Show(checkMsg); return; } if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (scbll.Delete(cID) == true) { // 写入操作日志 string logsContent = "删除系统设置名称:" + this.txtSc_ClassName2.Text.Trim() + ";编号:" + Sc_ClassCode; LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除系统设置, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name); isUpdate = true; this.txtSc_ClassCode.Text = ""; this.txtSc_ClassName.Text = ""; this.txtSc_ClassCode2.Text = ""; this.txtSc_ClassName2.Text = ""; this.txtSc_ClassRemark2.Text = ""; this.txtName.Text = ""; this.trvSystemSet.Nodes.Clear(); this.FrmSystemSet_Load(sender, e); SetSelectAndExpand(pid); // MessageBoxCustom.Show("删除成功!"); } else { MessageBoxCustom.Show("删除失败!"); } } } catch { MessageBoxCustom.Show("请选择你要删除的节点"); } } /// /// 选项目选择事件 /// /// /// protected override void tab_SelectedIndexChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TypeName)) { if (this.tab.SelectedIndex == 0) { this.btnAdd.Text = " 增加"; this.btnAdd.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.SystemCompetence, CustomAttributes.OperatingAuthority.Add); } else if (this.tab.SelectedIndex == 1) { this.btnAdd.Text = " 修改"; this.btnAdd.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.SystemCompetence, CustomAttributes.OperatingAuthority.Update); } } } void txtName_MouseDoubleClick(object sender, MouseEventArgs e) { Clipboard.SetDataObject(this.txtSc_ClassCode2.Text.Trim()); //if (LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Account.ToLower().Trim() == "admin") //{ // this.txtSystemCode.Text = this.txtSc_ClassCode2.Text.Trim(); // this.txtSystemCode.Visible = true; //} } } }