| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043 |
- /*******************************************************************************
- * 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();
- dtTree.DefaultView.RowFilter = "valueflag = '1'";
- dtTree = dtTree.DefaultView.ToTable();
- 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
- }
- }
|