/*******************************************************************************
* 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
{
///
/// 产品类别
///
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 属性
///
/// 产品类型TreeView改变前的状态
///
public Hashtable NodesStatus
{
get
{
return this._nodesStatus;
}
set
{
this._nodesStatus = value;
}
}
///
/// 产品类型TreeView选中节点的路径
///
public string SelectNodeFullPath
{
get
{
return this._selectNodeFullPath;
}
set
{
this._selectNodeFullPath = value;
}
}
#endregion
#region 构造函数
///
/// 窗体的构造函数
///
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 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_MST_0405 Instance
{
get
{
if (_instance == null)
{
_instance = new F_MST_0405();
}
return _instance;
}
}
#endregion
#region 事件
///
/// 窗体加载时发生
///
///
///
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);
}
}
///
/// 窗体关闭后,释放单例资源
///
///
///
private void F_MST_0405_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 点击右上角关闭按钮
///
///
///
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);
}
}
///
/// 节点收缩之后,显示关闭图标
///
///
///
private void tvwType_BeforeCollapse(object sender, TreeViewCancelEventArgs e)
{
e.Node.SelectedImageIndex = Constant.INT_IS_ZERO;
e.Node.ImageIndex = Constant.INT_IS_ZERO;
}
///
/// 节点展开之后,显示打开图标
///
///
///
private void tvwType_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
e.Node.SelectedImageIndex = Constant.INT_IS_TWO;
e.Node.ImageIndex = Constant.INT_IS_TWO;
}
///
/// 选中新行时,设置默认值
///
///
///
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);
}
}
///
/// 选择产品类型TreeView中的节点前判断,如果数据有改变提示保存
///
///
///
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);
}
}
///
/// 选择产品类别TreeView中的节点,DataGridView中显示相应的数据
///
///
///
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);
}
}
///
/// 设置保存按钮的可用状态
///
///
///
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);
}
}
///
/// 单元格输入是否重复的校验
///
///
///
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);
}
}
///
/// 设置保存按钮的可用状态
///
///
///
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);
}
}
///
/// 行离开时校验不能为空的项目
///
///
///
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);
}
}
///
/// 显示停用记录事件
///
///
///
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);
}
}
///
/// 保存产品类型数据
///
///
///
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);
}
}
///
/// 关闭窗体
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#region 私有方法
///
/// 取得产品类别数据
///
///
private DataSet GetGoodsTypeData()
{
try
{
return SystemModuleProxy.Service.GetGoodsTypeData(0);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据取得的产品类型数据,生成树形结构
///
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;
}
}
///
/// 保存产品类型TreeView的状态
///
///
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;
}
}
///
/// 递归显示产品类型树形目录
///
/// 产品类数据源
///
///
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;
}
}
///
/// 保存产品类型数据
///
/// 影响行数
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;
}
}
///
/// 还原保存前产品类型TreeView的状态
///
/// 节点
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;
}
}
///
/// 刷新DataGridView中的数据
///
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;
}
}
///
/// 按条件取得产品类型数据
///
///
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;
}
}
///
/// 获取产品档案的ID
///
/// 产品档案的ID
///
///
/// 2014.10.27 任海 新建
///
private DataSet GetGoodsTypeIDData()
{
try
{
return SystemModuleProxy.Service.GetGoodsTypeIDData(this._GoodsTypeID);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 自动生成产品类型编码
///
///
///
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);
}
}
///
/// 校验值是否重复
///
///
///
///
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;
}
///
/// 设置TreeView选中节点
///
///
/// 选中节点文本
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;
}
}
}
}
///
/// 保存时单元格必输项不能为空
///
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;
}
///
/// 设置保存按钮的可用状态
///
private void RefreshSaveBtnStatus()
{
// 数据有改变时,保存按钮可用,否则不可用
if (DataJudge.IsChange((DataTable)this.dgvGoodsType.DataSource))
{
this.btnSave.Enabled = true;
}
else
{
this.btnSave.Enabled = false;
}
}
///
/// 获取全部产品类别信息绑定到数据源中
///
private void GetAllGoodsTypeData()
{
this._dtSourse = SystemModuleProxy.Service.GetAllGoodsTypeData().Tables[0];
}
#endregion
}
}