| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041 |
- /*******************************************************************************
- * Copyright(c) 2014 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_0405.cs
- * 2.功能描述:产品类别
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 冯雪 2014/09/11 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- /// <summary>
- /// 产品类别
- /// </summary>
- public partial class F_MST_0405 : FormBase
- {
- #region 成员变量
- // 窗体的单例模式
- private static F_MST_0405 _instance;
- // 产品类型Treeview改变前的状态
- private Hashtable _nodesStatus = new Hashtable();
- // 产品类型TreeView选中节点的路径
- private string _selectNodeFullPath;
- // 产品类型TreeView选中节点的名称
- private string _selectNode;
- // 产品类型TreeView选中索引
- //private int _index;
- // 产品类型TreeView选中ID
- private int _GoodsTypeID;
- // 全部产品类型的集合
- private DataTable _dtSourse;
- #endregion
- #region 属性
- /// <summary>
- /// 产品类型TreeView改变前的状态
- /// </summary>
- public Hashtable NodesStatus
- {
- get
- {
- return this._nodesStatus;
- }
- set
- {
- this._nodesStatus = value;
- }
- }
- /// <summary>
- /// 产品类型TreeView选中节点的路径
- /// </summary>
- public string SelectNodeFullPath
- {
- get
- {
- return this._selectNodeFullPath;
- }
- set
- {
- this._selectNodeFullPath = value;
- }
- }
- #endregion
- #region 构造函数
- /// <summary>
- /// 窗体的构造函数
- /// </summary>
- public F_MST_0405()
- {
- InitializeComponent();
- // 窗体标题、按钮文字
- this.Text = FormTitles.F_MST_0405;
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- }
- #endregion
- #region 单例模式
- /// <summary>
- /// 单例模式,防止重复创建窗体
- /// </summary>
- public static F_MST_0405 Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new F_MST_0405();
- }
- return _instance;
- }
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载时发生
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0405_Load(object sender, EventArgs e)
- {
- try
- {
- // 加载权限
- FormPermissionManager.FormPermissionControl(this.Name, this,
- LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- // 设置表格不自动创建列
- this.dgvGoodsType.AutoGenerateColumns = false;
- // 设置保存按钮初始是不可点击
- this.btnSave.Enabled = false;
- // 获取全部产品类别信息
- this.GetAllGoodsTypeData();
- // 生成树形产品类型结构
- this.CreateGoodsTypeTree();
- // 窗体显示的时候鼠标停在第一个子节点
- this.tvwType.SelectedNode = tvwType.Nodes[0].Nodes[0];
- this.dgvGoodsType.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 窗体关闭后,释放单例资源
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0405_FormClosed(object sender, FormClosedEventArgs e)
- {
- _instance = null;
- }
- /// <summary>
- /// 点击右上角关闭按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0405_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- // 关闭的时候需要判断是否有数据变化
- if (DataJudge.IsChange((DataTable)this.dgvGoodsType.DataSource))
- {
- DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
- MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- // 保存改变的数据
- if (dialogResult == DialogResult.Yes)
- {
- DataGridViewRow row = dgvGoodsType.CurrentRow;
- if (!row.IsNewRow)
- {
- if (row.Cells["GoodsTypeCode"].Value == null
- || string.IsNullOrEmpty(row.Cells["GoodsTypeCode"].Value + string.Empty))
- {
- MessageBox.Show(string.Format(Messages.MSG_MST_W0405),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- }
- // 异步处理
- object result = DoAsync(new BaseAsyncMethod(this.SaveGoodsTypeData));
- // 如果保存出错,不关闭窗体
- if (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
- {
- e.Cancel = true;
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品类别", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else if (Convert.ToInt32(result) == (int)Constant.RETURN_IS_EXIST)
- {
- e.Cancel = true;
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "产品类别名称"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- e.Cancel = true;
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品类别", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else if (dialogResult == DialogResult.Cancel)
- {
- e.Cancel = true;
- }
- //选择否回滚
- else
- {
- ((DataTable)this.dgvGoodsType.DataSource).RejectChanges();
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 节点收缩之后,显示关闭图标
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwType_BeforeCollapse(object sender, TreeViewCancelEventArgs e)
- {
- e.Node.SelectedImageIndex = Constant.INT_IS_ZERO;
- e.Node.ImageIndex = Constant.INT_IS_ZERO;
- }
- /// <summary>
- /// 节点展开之后,显示打开图标
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwType_BeforeExpand(object sender, TreeViewCancelEventArgs e)
- {
- e.Node.SelectedImageIndex = Constant.INT_IS_TWO;
- e.Node.ImageIndex = Constant.INT_IS_TWO;
- }
- /// <summary>
- /// 选中新行时,设置默认值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvGoodsType_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
- {
- try
- {
- // 设置有效列为选中状态
- e.Row.Cells["ValueFlag"].Value = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 选择产品类型TreeView中的节点前判断,如果数据有改变提示保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwType_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- try
- {
- // 判断数据是否被修改过,修改过需要提示保存消息
- if (DataJudge.IsChange((DataTable)this.dgvGoodsType.DataSource))
- {
- DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
- MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- if (dialogResult == DialogResult.Yes)
- {
- int rowCount = (int)DoAsync(new BaseAsyncMethod(SaveGoodsTypeData));
- // 保存数据后提示
- if (rowCount > Constant.INT_IS_ZERO)
- {
- // 保存数据成功
- GetAllGoodsTypeData();
- this._dtSourse.AcceptChanges();
- this.btnSave.Enabled = false;
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品类别", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- // 生成产品类别树形结构
- TreeNode selectedNode = this.tvwType.SelectedNode;
- // 重新加载窗体数据
- this.RefreshData();
- this.CreateGoodsTypeTree();
- this.tvwType.SelectedNode = selectedNode;
- //// 还原保存前产品类别TreeView的状态
- this.SetTreeNodesStatus(this.tvwType.Nodes);
- }
- else
- {
- // 保存数据失败
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品类别", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else if (dialogResult == DialogResult.Cancel)
- {
- e.Cancel = true;
- }
- //选择否回滚
- else
- {
- ((DataTable)this.dgvGoodsType.DataSource).RejectChanges();
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 选择产品类别TreeView中的节点,DataGridView中显示相应的数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwType_AfterSelect(object sender, TreeViewEventArgs e)
- {
- try
- {
- // 刷新DataGridView中的数据
- this.RefreshData();
- this.dgvGoodsType.Columns["GoodsTypeCode"].ReadOnly = true;
- foreach (DataGridViewRow gvrFor in this.dgvGoodsType.Rows)
- {
- if (gvrFor.IsNewRow == true)
- {
- break;
- }
- if (gvrFor.Cells["GoodsTypeCode"].Value.ToString().Length == Constant.INT_IS_THREE)
- {
- gvrFor.Cells["ValueFlag"].ReadOnly = true;
- break;
- }
- else
- {
- break;
- }
- }
- this._selectNodeFullPath = this.tvwType.SelectedNode.FullPath.Replace("\\", "→");
- this.dgvGoodsType.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 设置保存按钮的可用状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvGoodsType_CellValidated(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- this.RefreshSaveBtnStatus();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 单元格输入是否重复的校验
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvGoodsType_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- try
- {
- if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
- {
- return;
- }
- DataGridViewRow rowItem = this.dgvGoodsType.Rows[e.RowIndex];
- DataGridViewColumn columnItem = this.dgvGoodsType.Columns[e.ColumnIndex];
- if (!this.dgvGoodsType.CurrentRow.IsNewRow)
- {
- object value = rowItem.Cells[columnItem.Name].EditedFormattedValue;
- // 产品类型名称
- if ("GoodsTypeName".Equals(columnItem.Name))
- {
- if (value != null || !string.IsNullOrEmpty(value.ToString().Trim()))
- {
- if (!this.IsUnique(value.ToString(), this.dgvGoodsType.CurrentRow.Index))
- {
- // 增加单元格的错误消息
- this.dgvGoodsType.CurrentRow.ErrorText
- = string.Format(Messages.MSG_CMN_W006, "产品类别名称 ");
- e.Cancel = true;
- return;
- }
- }
- }
- else if (columnItem.Name == "ValueFlag")
- {
- if ((bool)value != true)
- {
- int isStop = SystemModuleProxy.Service.CheckGoodsTypeToUpdate(rowItem.Cells["GoodsTypeCode"].Value.ToString());
- if (isStop > Constant.INT_IS_ZERO)
- {
- // 增加单元格的错误消息
- this.dgvGoodsType.CurrentRow.ErrorText
- = "该类别包含子类别或商品,不可进行停用操作!";
- e.Cancel = true;
- return;
- }
- }
- }
- // 清除单元格的错误消息
- this.dgvGoodsType.CurrentRow.ErrorText = string.Empty;
- }
- this.dgvGoodsType.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 设置保存按钮的可用状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvGoodsType_RowValidated(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- this.RefreshSaveBtnStatus();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 行离开时校验不能为空的项目
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvGoodsType_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
- {
- try
- {
- // 按Esc键时不校验
- if (!this.dgvGoodsType.IsCurrentRowDirty)
- {
- this.dgvGoodsType.IsSetInputColumnsColor = true;
- return;
- }
- DataGridViewRow row = this.dgvGoodsType.CurrentRow;
- if (!row.IsNewRow)
- {
- // 类别名称不能为空
- if (row.Cells["GoodsTypeName"].Value == null
- || string.IsNullOrEmpty(row.Cells["GoodsTypeName"].Value.ToString().Trim()))
- {
- // 增加单元格的错误消息
- this.dgvGoodsType.CurrentRow.ErrorText
- = string.Format(Messages.MSG_CMN_W005, "产品类别名称");
- e.Cancel = true;
- return;
- }
- // 过滤多余空格
- row.Cells["GoodsTypeName"].Value = row.Cells["GoodsTypeName"].Value.ToString().Trim();
- row.Cells["Remarks"].Value = row.Cells["Remarks"].Value.ToString().Trim();
- string BoolValueFlag = row.Cells["ValueFlag"].Value.ToString();
- if (BoolValueFlag == "True")
- {
- row.Cells["ValueFlag"].Value = '1';
- }
- else if (BoolValueFlag == "False")
- {
- row.Cells["ValueFlag"].Value = '0';
- }
- // 清除单元格的错误消息
- this.dgvGoodsType.CurrentRow.ErrorText = string.Empty;
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 显示停用记录事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- this.RefreshData();
- this.dgvGoodsType.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 保存产品类型数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- int results = Conservation();
- if (results == Constant.INT_IS_ONE)
- {
- MessageBox.Show(string.Format(Messages.MSG_MST_W0405),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.btnSave.Enabled = false;
- return;
- }
- this.btnSave.Enabled = false;
- this.btnCancel.Enabled = false;
- int result = (int)DoAsync(new BaseAsyncMethod(this.SaveGoodsTypeData));
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 保存成功 2表示有数据被修改 3表示没有数据被修改
- if (result.Equals(Constant.INT_IS_TWO))
- {
- GetAllGoodsTypeData();
- this._dtSourse.AcceptChanges();
- this.btnSave.Enabled = false;
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品类别管理", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else if (result.Equals(Constant.INT_IS_FOUR))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_X001),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- ((DataTable)this.dgvGoodsType.DataSource).RejectChanges();
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品类别管理", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- // 重新加载窗体数据
- this.RefreshData();
- this.CreateGoodsTypeTree();
- }
- catch (Exception ex)
- {
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 关闭窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 取得产品类别数据
- /// </summary>
- /// <returns></returns>
- private DataSet GetGoodsTypeData()
- {
- try
- {
- return SystemModuleProxy.Service.GetGoodsTypeData(0);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据取得的产品类型数据,生成树形结构
- /// </summary>
- private void CreateGoodsTypeTree()
- {
- try
- {
- // 没有产品类型数据时,直接返回
- if (this._dtSourse == null || this._dtSourse.Rows.Count < Constant.INT_IS_ONE)
- {
- return;
- }
- // 将所有节点清除
- this.tvwType.Nodes.Clear();
- TreeNode goodsTypeNode = null;
- DataTable dtTree = this._dtSourse.Copy();
- DataRow[] goodsTypeRows = dtTree.Select(" LEN(GoodsTypeCode) = 3");
- // 显示子节点
- InitTreeView(dtTree, goodsTypeRows, goodsTypeNode);
- if (this.tvwType.SelectedNode == null)
- {
- this.tvwType.SelectedNode = this.tvwType.Nodes[0];
- }
- this.dgvGoodsType.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 保存产品类型TreeView的状态
- /// </summary>
- /// <param name="nodes"></param>
- private void SaveTreeNodesStatus(TreeNodeCollection nodes)
- {
- try
- {
- foreach (TreeNode node in nodes)
- {
- // 保存所有节点折叠,展开状态
- if (node.IsExpanded)
- {
- this.NodesStatus[node.FullPath] = true;
- }
- else
- {
- this.NodesStatus.Remove(node.FullPath);
- }
- // 当节点处于选中状态时获取根树节点到当前树节点的路径
- if (node.IsSelected)
- {
- SelectNodeFullPath = node.FullPath;
- }
- SaveTreeNodesStatus(node.Nodes);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 递归显示产品类型树形目录
- /// </summary>
- /// <param name="typeData">产品类数据源</param>
- /// <param name="rows"></param>
- /// <param name="node"></param>
- private void InitTreeView(DataTable typeData, DataRow[] rows, TreeNode node)
- {
- try
- {
- foreach (DataRow row in rows)
- {
- TreeNode sNode = null;
- if (node == null)
- {
- // 新建树节点并添加
- sNode = new TreeNode();
- sNode.Text = row["GoodsTypeName"].ToString();
- sNode.Name = row["GoodsTypeCode"].ToString();
- sNode.Tag = row["GoodsTypeID"].ToString();
- this.tvwType.Nodes.Add(sNode);
- }
- else
- {
- // 在原有树中加入节点
- sNode = node.Nodes.Add(row["GoodsTypeName"].ToString());
- sNode.Name = row["GoodsTypeCode"].ToString();
- sNode.Tag = row["GoodsTypeID"].ToString();
- }
- // 查找子节点
- string filterExpression = "GoodsTypeCode LIKE '" + row["GoodsTypeCode"].ToString()
- + "%' AND LEN(GoodsTypeCode) = " + (row["GoodsTypeCode"].ToString().Length + 3);
- DataRow[] subRows = typeData.Select(filterExpression);
- // 递归绑定子节点
- this.InitTreeView(typeData, subRows, sNode);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 保存产品类型数据
- /// </summary>
- /// <returns>影响行数</returns>
- private object SaveGoodsTypeData()
- {
- try
- {
- // 获取当前dataGoodsTypeData数据源
- DataTable dataGoodsTypeData = (DataTable)this.dgvGoodsType.DataSource;
- foreach (DataRow drFor in dataGoodsTypeData.Rows)
- {
- if (drFor["GoodsTypeFullName"] == null || drFor["GoodsTypeFullName"] == DBNull.Value)
- {
- drFor["GoodsTypeFullName"] = _selectNodeFullPath
- + "→" + drFor["GoodsTypeName"].ToString();
- }
- }
- int result = SystemModuleProxy.Service.SaveGoodsTypeData(dataGoodsTypeData);
- return result;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 还原保存前产品类型TreeView的状态
- /// </summary>
- /// <param name="nodes">节点</param>
- private void SetTreeNodesStatus(TreeNodeCollection nodes)
- {
- try
- {
- foreach (TreeNode node in nodes)
- {
- if (this.NodesStatus[node.FullPath] != null)
- {
- // 展开树节点
- node.Expand();
- }
- // 节点路径和前选中的路径相同 设置节点为选中状态
- if (node.FullPath == SelectNodeFullPath)
- {
- this.tvwType.SelectedNode = node;
- }
- SetTreeNodesStatus(node.Nodes);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 刷新DataGridView中的数据
- /// </summary>
- private object RefreshData()
- {
- try
- {
- // 获取相应节点数据
- if (this.tvwType.SelectedNode != null
- && !string.IsNullOrEmpty(this.tvwType.SelectedNode.Name.Trim()))
- {
- this._selectNode = this.tvwType.SelectedNode.Name.Trim();
- this._GoodsTypeID = Convert.ToInt32(this.tvwType.SelectedNode.Tag);
- DataSet data = (DataSet)DoAsync(new BaseAsyncMethod(GetGoodsTypeIDData));
- if (data.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- dgvGoodsType.AllowUserToAddRows = false;
- }
- else
- {
- dgvGoodsType.AllowUserToAddRows = true;
- }
- // 获取是否查询正常数据的标识
- byte valueFalg = Convert.ToByte(this.chkDisplayDisabledData.Checked);
- // 获取查询的数据集
- StringBuilder sbFilter = new StringBuilder();
- sbFilter.Append(" 1=1");
- if (valueFalg == 0)
- {
- sbFilter.Append(" and ValueFlag = '1'");
- }
- if (this._selectNode != "")
- {
- sbFilter.Append(" and GoodsTypeCode like '" + this._selectNode + "%'");
- }
- this._dtSourse.DefaultView.RowFilter = sbFilter.ToString();
- this.dgvGoodsType.AllowUserToModifyRows = true;
- // 选中新行时,自动计算产品种类编码
- this._dtSourse.TableNewRow += new DataTableNewRowEventHandler(Table_SelectNewRow);
- this.dgvGoodsType.DataSource = _dtSourse;
- this.dgvGoodsType.IsSetInputColumnsColor = true;
- }
- else
- {
- this.dgvGoodsType.AllowUserToModifyRows = false;
- }
- return Constant.INT_IS_ZERO;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 按条件取得产品类型数据
- /// </summary>
- /// <returns></returns>
- private DataSet GetGoodsTypeByGTCode()
- {
- try
- {
- byte valueFlag = Convert.ToByte(this.chkDisplayDisabledData.Checked);
- DataSet dsTemp = SystemModuleProxy.Service.GetGoodsTyperData(valueFlag, this._selectNode);
- return dsTemp;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取产品档案的ID
- /// </summary>
- /// <param name="GoodsTypeID">产品档案的ID</param>
- /// <returns></returns>
- /// <remarks>
- /// 2014.10.27 任海 新建
- /// </remarks>
- private DataSet GetGoodsTypeIDData()
- {
- try
- {
- return SystemModuleProxy.Service.GetGoodsTypeIDData(this._GoodsTypeID);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 自动生成产品类型编码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Table_SelectNewRow(object sender, DataTableNewRowEventArgs e)
- {
- try
- {
- DataTable itemTable = sender as DataTable;
- DataTable itemTableF = itemTable.Copy();
- itemTableF.DefaultView.RowFilter = " GoodsTypeCode like '" + this._selectNode + "%'";
- itemTableF = itemTableF.DefaultView.ToTable();
- if (itemTableF != null && itemTableF.Rows.Count > Constant.INT_IS_ZERO)
- {
- // 获取本级商品种类中的最大编码
- string maxValue;
- if (itemTableF.Rows.Count > Constant.INT_IS_ONE)
- {
- DataTable filterDataTable = itemTableF.Clone();
- string selectNode = this.tvwType.SelectedNode.Name.Trim();
- DataRow[] dataRows = itemTableF.Select("LEN(GoodsTypeCode) = " + (selectNode + "000").Length);
- foreach (DataRow row in dataRows)
- {
- filterDataTable.Rows.Add(row.ItemArray);
- }
- maxValue = Utility.GetStringMaxValue(filterDataTable, "GoodsTypeCode");
- }
- else
- {
- maxValue = Utility.GetStringMaxValue(itemTableF, "GoodsTypeCode");
- }
- // 如果没有下级种类,编码长度加3
- if (itemTableF.Rows.Count == Constant.INT_IS_ONE)
- {
- e.Row["GoodsTypeCode"] = maxValue + "001";
- }
- else
- {
- e.Row["GoodsTypeCode"] = maxValue.Substring(0, maxValue.Length - 3)
- + ((Convert.ToInt32(maxValue.Substring(
- maxValue.Length - 3)) + 1)).ToString().PadLeft(3, '0');
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 校验值是否重复
- /// </summary>
- /// <param name="curCellValue"></param>
- /// <param name="curRow"></param>
- /// <returns></returns>
- private bool IsUnique(string curCellValue, int curRow)
- {
- //待修改
- foreach (DataGridViewRow rowItem in this.dgvGoodsType.Rows)
- {
- if (rowItem.Index == curRow)
- {
- continue;
- }
- // 类别编码
- if (rowItem.Cells["GoodsTypeCode"].Value != null)
- {
- if (rowItem.Cells["GoodsTypeCode"].Value.ToString().TrimEnd().
- Equals(curCellValue.TrimEnd()))
- {
- return false;
- }
- }
- }
- return true;
- }
- /// <summary>
- /// 设置TreeView选中节点
- /// </summary>
- /// <param name="treeView"></param>
- /// <param name="selectStr">选中节点文本</param>
- private void SelectTreeView(TreeView treeView, string selectStr)
- {
- treeView.Focus();
- for (int i = 0; i < treeView.Nodes.Count; i++)
- {
- for (int j = 0; j < treeView.Nodes[i].Nodes.Count; j++)
- {
- if (treeView.Nodes[i].Nodes[j].Text == selectStr)
- {
- treeView.SelectedNode = treeView.Nodes[i].Nodes[j];//选中
- //treeView.Nodes[i].Nodes[j].Checked = true;
- treeView.Nodes[i].Expand();//展开父级
- return;
- }
- }
- }
- }
- /// <summary>
- /// 保存时单元格必输项不能为空
- /// </summary>
- private int Conservation()
- {
- int isConservation = Constant.INT_IS_ZERO;
- DataTable dataGoodsData = (DataTable)dgvGoodsType.DataSource;
- foreach (DataRow drproductionData in dataGoodsData.Rows)
- {
- if (drproductionData["GoodsTypeCode"].ToString() == string.Empty)
- {
- isConservation = Constant.INT_IS_ONE;
- break;
- }
- }
- return isConservation;
- }
- /// <summary>
- /// 设置保存按钮的可用状态
- /// </summary>
- private void RefreshSaveBtnStatus()
- {
- // 数据有改变时,保存按钮可用,否则不可用
- if (DataJudge.IsChange((DataTable)this.dgvGoodsType.DataSource))
- {
- this.btnSave.Enabled = true;
- }
- else
- {
- this.btnSave.Enabled = false;
- }
- }
- /// <summary>
- /// 获取全部产品类别信息绑定到数据源中
- /// </summary>
- private void GetAllGoodsTypeData()
- {
- this._dtSourse = SystemModuleProxy.Service.GetAllGoodsTypeData().Tables[0];
- }
- #endregion
- }
- }
|