| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958 |
- /*******************************************************************************
- * Copyright(c) 2014 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_0402.cs
- * 2.功能描述:数据字典
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 任海 2014/09/15 1.00 新建
- *******************************************************************************/
- using System;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.DataModels;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- /// <summary>
- /// 数据字典
- /// </summary>
- public partial class F_MST_0402 : FormBase
- {
- #region 成员变量
- // 窗体的单例模式
- private static F_MST_0402 _instance;
- // 相应节点数据
- private string _dictionaryType;
- // 有效标识
- private byte _valueFalg;
- // 数据字典Treeview改变前的状态
- private Hashtable _nodesStatus = new Hashtable();
- // 数据字典TreeView选中节点的路径
- private string _selectNodeFullPath;
- // 数据字典TreeView选中节点的名称
- //private string _selectNode;
- // 字典数据源
- private DataTable _dtSourse;
- #endregion
- #region 属性
- /// <summary>
- /// 数据字典TreeView改变前的状态
- /// </summary>
- public Hashtable NodesStatus
- {
- get
- {
- return _nodesStatus;
- }
- set
- {
- _nodesStatus = value;
- }
- }
- /// <summary>
- /// 数据字典TreeView选中节点的路径
- /// </summary>
- public string SelectNodeFullPath
- {
- get
- {
- return _selectNodeFullPath;
- }
- set
- {
- _selectNodeFullPath = value;
- }
- }
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_MST_0402()
- {
- InitializeComponent();
- // 窗口标题
- this.Text = FormTitles.F_MST_0402;
- // 按钮
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- }
- #endregion
- #region 单例模式
- /// <summary>
- /// 单例模式,防止重复创建窗体
- /// </summary>
- /// <returns></returns>
- public static F_MST_0402 Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new F_MST_0402();
- }
- return _instance;
- }
- }
- #endregion
- #region 事件
- /// <summary>
- /// 页面加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0402_Load(object sender, EventArgs e)
- {
- try
- {
- // 屏蔽根据数据源的实际情况,自动生成datagridview表格列
- this.dgvDataDictionary.AutoGenerateColumns = false;
- this.btnSave.Enabled = false;
- //生成树形结构
- this.CreateDataDictionaryTree();
- this.GetAllDataDictionary();
- // 窗体显示的时候鼠标停在第一个子节点
- this.tvwDictionaryType.SelectedNode = tvwDictionaryType.Nodes[0].Nodes[0];
- this.dgvDataDictionary.IsSetInputColumnsColor = true;
- //权限控制
- FormPermissionManager.FormPermissionControl(this.Name, this,
- LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- this.dgvDataDictionary.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
- }
- 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 FrmDataDictionary_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- // 关闭的时候需要判断是否有数据变化
- if (DataJudge.IsChange((DataTable)this.dgvDataDictionary.DataSource))
- {
- DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
- MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- // 保存改变的数据
- if (dialogResult == DialogResult.Yes)
- {
- // 异步处理
- int result = (int)DoAsync(new BaseAsyncMethod(SaveDataDictionaryData));
- // 如果保存出错,不关闭窗体
- if (Convert.ToInt32(result) <= Constant.INT_IS_ZERO)
- {
- e.Cancel = true;
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "数据字典", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "数据字典", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- else if (dialogResult == DialogResult.Cancel)
- {
- e.Cancel = true;
- }
- //选择否回滚
- else
- {
- ((DataTable)this.dgvDataDictionary.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 FrmDataDictionary_FormClosed(object sender, FormClosedEventArgs e)
- {
- _instance = null;
- }
- /// <summary>
- /// 节点收缩之后,显示关闭图标
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwDictionaryType_AfterCollapse(object sender, TreeViewEventArgs 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 tvwDictionaryType_AfterExpand(object sender, TreeViewEventArgs e)
- {
- e.Node.SelectedImageIndex = Constant.INT_IS_TWO;
- e.Node.ImageIndex = Constant.INT_IS_TWO;
- }
- /// <summary>
- /// 选择数据字典TreeView中的节点前判断,如果数据有改变提示保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwDictionaryType_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- try
- {
- this.dgvDataDictionary.AllowUserToAddRows = true;
- // 判断数据是否被修改过,修改过需要提示保存消息
- if (DataJudge.IsChange((DataTable)this.dgvDataDictionary.DataSource))
- {
- DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
- MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- // 保存修改内容
- if (dialogResult == DialogResult.Yes)
- {
- // 异步处理
- int result = (int)DoAsync(new BaseAsyncMethod(SaveDataDictionaryData));
- // 如果保存出错,不关闭窗体
- if (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "数据字典", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- this.btnSave.Enabled = false;
- 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.dgvDataDictionary.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 tvwDictionaryType_AfterSelect(object sender, TreeViewEventArgs e)
- {
- try
- {
- this.lblDictionaryType.Text = "当前选择的字典类型:" + e.Node.Text;
- //判断父节点是否存在,表格联动
- TreeNode node = tvwDictionaryType.SelectedNode.Parent;
- if (node != null)
- {
- this.dgvDataDictionary.ReadOnly = false;
- this._dtSourse.AcceptChanges();
- this.RefreshData();
- }
- else
- {
- this.dgvDataDictionary.DataSource = null;
- this.dgvDataDictionary.ReadOnly = true;
- this.dgvDataDictionary.AllowUserToAddRows = false;
- }
- }
- 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 dgvDataDictionary_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
- {
- try
- {
- // 只对文本框做控制
- if (e.Control is DataGridViewTextBoxEditingControl)
- {
- DataGridViewTextBoxEditingControl EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
- EditingControl.KeyPress += new KeyPressEventHandler(dgvDataDictionary_KeyPress);
- }
- }
- 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 dgvDataDictionary_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
- {
- // 设置有效属性为选中状态
- e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
- // 增加一行时,给字典类型赋值
- e.Row.Cells["DictionaryType"].Value = tvwDictionaryType.SelectedNode.Tag.ToString();
- e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
- }
- /// <summary>
- /// 屏蔽除了数字以外的输入(显示顺序)
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDictionary_KeyPress(object sender, KeyPressEventArgs e)
- {
- // 显示顺序列只允许输入数字和回格
- if ("DisplayNo".Equals(this.dgvDataDictionary.Columns[this
- .dgvDataDictionary.CurrentCell.ColumnIndex].Name))
- {
- if (e.KeyChar != '\b' && !char.IsDigit(e.KeyChar))
- {
- e.Handled = true;
- }
- }
- }
- /// <summary>
- /// 检查是否有重复的字典名称以及将为输入顺序设置成0
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDictionary_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- try
- {
- if (!dgvDataDictionary.CurrentRow.IsNewRow)
- {
- DataGridViewRow rowItem = dgvDataDictionary.Rows[e.RowIndex];
- DataGridViewColumn columnItem = dgvDataDictionary.Columns[e.ColumnIndex];
- object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
- // 字典名称
- if ("DictionaryValue".Equals(columnItem.Name))
- {
- if (columnvalue != null || !string.IsNullOrEmpty(columnvalue.ToString().Trim()))
- {
- if (!Utility.IsUnique(columnvalue.ToString(),
- dgvDataDictionary.CurrentRow.Index, this.dgvDataDictionary, "DictionaryValue"))
- {
- // 单元格的错误消息
- this.dgvDataDictionary.CurrentRow.ErrorText = string.Format(
- Messages.MSG_CMN_W006, "字典名称");
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- }
- }
- // 清除单元格的错误消息
- this.dgvDataDictionary.CurrentRow.ErrorText = string.Empty;
- this.dgvDataDictionary.IsSetInputColumnsColor = true;
- // 显示顺序为空时设置为0
- if ("DisplayNo".Equals(columnItem.Name)
- && string.IsNullOrEmpty(columnvalue.ToString()))
- {
- dgvDataDictionary.CurrentCell.Value = Constant.INT_IS_ZERO;
- dgvDataDictionary.RefreshEdit();
- }
- }
- }
- 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 dgvDataDictionary_CellValidated(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- this.SetSaveBtnStatus();
- }
- 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 dgvDataDictionary_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
- {
- try
- {
- // 按Esc键时不校验
- if (!dgvDataDictionary.IsCurrentRowDirty)
- {
- this.dgvDataDictionary.IsSetInputColumnsColor = true;
- return;
- }
- DataGridViewRow row = dgvDataDictionary.CurrentRow;
- if (!row.IsNewRow)
- {
- // 数据字典类型不能为空
- if (row.Cells["DictionaryValue"].Value == null
- || string.IsNullOrEmpty(row.Cells["DictionaryValue"].Value.ToString().Trim()))
- {
- // 单元格的错误消息
- this.dgvDataDictionary.CurrentRow.ErrorText
- = string.Format(Messages.MSG_CMN_W005, "字典名称");
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- // 显示顺序不能为空
- if (row.Cells["DisplayNo"].Value == null
- || string.IsNullOrEmpty(row.Cells["DisplayNo"].Value.ToString().Trim()))
- {
- this.dgvDataDictionary.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "显示顺序");
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- // 过滤掉数据字典名称,备注首尾的空格
- row.Cells["DictionaryValue"].Value = row.Cells["DictionaryValue"].Value.ToString().Trim();
- row.Cells["Remarks"].Value =row.Cells["Remarks"].Value==null?"": row.Cells["Remarks"].Value.ToString().Trim();
- // 清除单元格的错误消息
- this.dgvDataDictionary.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 dgvDataDictionary_RowValidated(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- this.SetSaveBtnStatus();
- }
- 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 Table_SelectNewRow(object sender, DataTableNewRowEventArgs e)
- {
- DataTable itemTable = sender as DataTable;
- //判断最大值
- if (itemTable != null)
- {
- int maxValue = Utility.GetMaxValue(itemTable.DefaultView.ToTable(), "DisplayNo");
- if (maxValue < Constant.INT_IS_ZERO)
- {
- maxValue = Constant.INT_IS_ZERO;
- }
- // 判断显示顺序
- if (Constant.S_DISPLAYNO_MAX < maxValue + Constant.INT_IS_ONE)
- {
- e.Row["DisplayNo"] = maxValue;
- }
- else
- {
- e.Row["DisplayNo"] = ++maxValue;
- }
- e.Row["DictionaryType"] = tvwDictionaryType.SelectedNode.Tag.ToString();
- }
- }
- /// <summary>
- /// 根据是否选中停用数据,加载数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- this.RefreshData();
- this.SetSaveBtnStatus();
- this.dgvDataDictionary.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
- {
- // 异步处理
- this.btnSave.Enabled = false;
- this.btnCancel.Enabled = false;
- int result = (int)DoAsync(new BaseAsyncMethod(SaveDataDictionaryData));
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 数据字典数据保存成功
- if (result > Constant.INT_IS_ZERO)
- {
- RefreshData();
- this._dtSourse.AcceptChanges();
- this.btnSave.Enabled = false;
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "数据字典", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //数据字典数据存在相同的数据
- else if (result == (int)Constant.RETURN_IS_EXIST)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "数据字典名称"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "数据字典", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- 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();
- }
- /// <summary>
- /// 单元格输入时,给自动生成的行设置颜色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDictionary_UserAddedRow(object sender, DataGridViewRowEventArgs e)
- {
- this.dgvDataDictionary.IsSetInputColumnsColor = true;
- }
- /// <summary>
- /// 排序时设置列表的颜色
- /// </summary>
- /// <returns></returns>
- private void dgvDataDictionary_Sorted(object sender, EventArgs e)
- {
- this.dgvDataDictionary.IsSetInputColumnsColor = true;
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 数据字典左侧树的数据取得
- /// </summary>
- /// <returns></returns>
- private DataSet GetDataDictionaryData()
- {
- try
- {
- return SystemModuleProxy.Service.GetDataDictionaryTreeData();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据取得的数据字典数据,生成树形结构
- /// </summary>
- private void CreateDataDictionaryTree()
- {
- try
- {
- // 取得数据字典数据
- DataSet dataDictionaryData = (DataSet)DoAsync(new BaseAsyncMethod(GetDataDictionaryData));
- // 没有数据字典数据时,直接返回
- if (dataDictionaryData == null || dataDictionaryData.Tables[0].Rows.Count < Constant.INT_IS_ONE)
- {
- return;
- }
- if (this.tvwDictionaryType.Nodes.Count > Constant.INT_IS_ZERO)
- {
- // 添加节点前,保存状态
- SaveTreeNodesStatus(this.tvwDictionaryType.Nodes);
- }
- // 将所有节点清除
- this.tvwDictionaryType.Nodes.Clear();
- //生成树形结构
- if (dataDictionaryData != null)
- {
- if (dataDictionaryData.Tables.Count >= Constant.INT_IS_TWO)
- {
- foreach (DataRow newRootRow in dataDictionaryData.Tables[0].Rows)
- {
- TreeNode rootNode = new TreeNode();
- rootNode.Name = newRootRow["DataDictionaryClass"].ToString().Trim();
- rootNode.Text = newRootRow["DataDictionaryClassName"].ToString().Trim();
- rootNode.Tag = newRootRow["DataDictionaryClass"].ToString().Trim();
- string strWhere = "DataDictionaryClass ='" + newRootRow["DataDictionaryClass"].ToString() + "'";
- DataRow[] dataDictionaryRows = dataDictionaryData.Tables[1].Select(strWhere, "DisplayNo");
- // 显示子节点
- InitTreeView(dataDictionaryData.Tables[1], dataDictionaryRows, rootNode);
- this.tvwDictionaryType.Nodes.Add(rootNode);
- }
- }
- }
- this.dgvDataDictionary.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 递归显示数据字典树形目录
- /// </summary>
- /// <param name="typeData">数据字典数据源</param>
- /// <param name="rows"></param>
- /// <param name="node"></param>
- private void InitTreeView(DataTable dtTable, DataRow[] rows, TreeNode node)
- {
- try
- {
- foreach (DataRow row in rows)
- {
- TreeNode sNode = new TreeNode();
- // 新建树节点并添加
- sNode = new TreeNode();
- sNode.Text = row["DataDictionaryTypeName"].ToString().Trim();
- sNode.Name = row["DataDictionaryType"].ToString().Trim();
- sNode.Tag = row["DataDictionaryType"].ToString().Trim();
- //节点图像索引
- sNode.ImageIndex = Constant.INT_IS_ONE;
- sNode.SelectedImageIndex = Constant.INT_IS_ONE;
- node.Nodes.Add(sNode);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 加入节点在原有树中
- /// </summary>
- private void InitTreeLeafView(DataRow[] rows, TreeNode node)
- {
- try
- {
- foreach (DataRow row in rows)
- {
- TreeNode sNode = null;
- if (node == null)
- {
- return;
- }
- else
- {
- // 加入节点在原有树中
- sNode = node.Nodes.Add(row["DataDictionaryTypeName"].ToString());
- sNode.Name = row["DataDictionaryType"].ToString();
- sNode.Tag = row["DataDictionaryType"].ToString();
- }
- }
- }
- 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>
- /// 还原保存前产品类型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.tvwDictionaryType.SelectedNode = node;
- }
- SetTreeNodesStatus(node.Nodes);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 刷新数据
- /// </summary>
- private object RefreshData()
- {
- try
- {
- // 获取相应节点数据
- this._dictionaryType = this.tvwDictionaryType.SelectedNode.Tag.ToString();
- // 获取是否查询正常数据的标识
- this._valueFalg = Convert.ToByte(this.chkDisplayDisabledData.Checked);
- // 获取查询的数据集
- base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetDictionaryDate));
- // 获取查询的数据集
- StringBuilder sbFilter = new StringBuilder();
- sbFilter.Append(" 1=1");
- if (this._valueFalg == Constant.INT_IS_ZERO)
- {
- sbFilter.Append(" and ValueFlag = 1");
- }
- if (this._dictionaryType != "")
- {
- sbFilter.Append(" and DictionaryType = '" + _dictionaryType + "'");
- }
- this._dtSourse.DefaultView.RowFilter = sbFilter.ToString();
- if (this._dtSourse.DefaultView.ToTable().Rows.Count > Constant.INT_IS_ZERO)
- {
- // 选中新行时,自动显示顺序
- this._dtSourse.TableNewRow += new DataTableNewRowEventHandler(Table_SelectNewRow);
- this.dgvDataDictionary.DataSource = this._dtSourse;
- this.dgvDataDictionary.IsSetInputColumnsColor = true;
- }
- else
- {
- this._dtSourse.TableNewRow += new DataTableNewRowEventHandler(Table_SelectNewRow);
- this.dgvDataDictionary.DataSource = this._dtSourse;
- this.dgvDataDictionary.IsSetInputColumnsColor = true;
- }
- return Constant.INT_IS_ZERO;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 设置保存按钮的可用状态
- /// </summary>
- private void SetSaveBtnStatus()
- {
- if (DataJudge.IsChange((DataTable)this.dgvDataDictionary.DataSource))
- {
- this.btnSave.Enabled = true;
- }
- else
- {
- this.btnSave.Enabled = false;
- }
- }
- /// <summary>
- /// 保存数据字典数据
- /// </summary>
- /// <returns>受影响行数</returns>
- private object SaveDataDictionaryData()
- {
- try
- {
- // 获取当前dgvDataDictionary数据源
- DataTable dataDictionaryData = (DataTable)this.dgvDataDictionary.DataSource;
- int result = SystemModuleProxy.Service.SaveDictionaryData(dataDictionaryData);
- return result;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取数据字典信息
- /// </summary>
- /// <returns></returns>
- private object GetDictionaryDate()
- {
- try
- {
- return SystemModuleProxy.Service.GetDictionaryData(_valueFalg, _dictionaryType);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取数据字典的全部数据
- /// </summary>
- /// <param name="sUserInfo">用户信息</param>
- /// <returns></returns>
- /// <remarks>
- /// 2014.10.31 任海 新建
- /// </remarks>
- private void GetAllDataDictionary()
- {
- try
- {
- DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAllDataDictionaryInfo();
- }));
- this._dtSourse = dsResultAccount.Tables[0];
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- }
- }
|