123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- 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;
- }
- /// <summary>
- /// 是否有修改类别
- /// </summary>
- bool isUpdate = false;
- private string _TypeName;
- /// <summary>
- /// 传入的当前一级类别码
- /// </summary>
- public string TypeName
- {
- get { return _TypeName; }
- set { _TypeName = value; }
- }
- private string _Version;
- /// <summary>
- /// 旧属性设置 已用 IsLoadAllCategory 代替
- /// </summary>
- public string Version
- {
- set
- {
- if (string.IsNullOrEmpty(value))
- {
- isLoadAllCategory = true;
- }
- else
- {
- isLoadAllCategory = false;
- }
- _Version = value;
- }
- }
- bool isLoadAllCategory = true;
- /// <summary>
- /// 是否加载所有类别码
- /// </summary>
- public bool IsLoadAllCategory
- {
- get { return isLoadAllCategory; }
- set { isLoadAllCategory = value; }
- }
- /// <summary>
- /// 关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void FrmSystemSet_FormClosed(object sender, FormClosedEventArgs e)
- {
- if (isUpdate == true)
- { this.DialogResult = DialogResult.OK; }
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void FrmSystemSet_Load(object sender, EventArgs e)
- {
- BindCategoryTree();
- }
- DataTable SystemCategoryDataTable = null;
- /// <summary>
- /// 绑定类别树
- /// </summary>
- 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("父类别码参数不能为空");
- }
- }
- }
- /// <summary>
- /// 绑定子节点
- /// </summary>
- /// <param name="cNode"></param>
- /// <param name="pid"></param>
- 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"]));
- }
- }
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 点击树节点
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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); }
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- }
- }
- /// <summary>
- /// 检查指定类别是否已使用,如果已使用返回 true 不可以删除 ,如果没有使用 返回 false 可以删除
- /// </summary>
- /// <param name="classCode"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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("请选择你要删除的节点"); }
- }
- /// <summary>
- /// 选项目选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- //}
- }
- }
- }
|