| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990 |
- /*******************************************************************************
- * Copyright(c) 2014 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_0302.cs
- * 2.功能描述:窑车管理
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 任海 2014/09/01 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_0302 : FormBase
- {
- #region 成员变量
- // 窗体的单例模式
- private static F_MST_0302 _instance;
- // 窑炉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_0302()
- {
- InitializeComponent();
- // 窗体标题文字
- this.Text = FormTitles.F_MST_0302;
- // 按钮
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- }
- #endregion
- #region 单例模式
- /// <summary>
- /// 单例模式,防止重复创建窗体
- /// </summary>
- public static F_MST_0302 Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new F_MST_0302();
- }
- return _instance;
- }
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载时发生
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0302_Load(object sender, EventArgs e)
- {
- try
- {
- FormPermissionManager.FormPermissionControl(this.Name, this,
- LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- // 设置保存按钮初始是不可点击
- this.btnSave.Enabled = false;
- // 生成窑车树形结构
- this.CreateKilnTree();
- this.GetAllKilnCar();
- this.RefreshDataGridViewData();
- this.dgvKilnCar.IsSetInputColumnsColor = true;
- this.dgvKilnCar.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 tvwKiln_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 tvwKiln_AfterExpand(object sender, TreeViewEventArgs 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 dgvKiln_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
- {
- // 设置有效列为选中状态
- e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
- // 增加一行时,给窑炉赋值
- e.Row.Cells["KilnID"].Value = tvwkiln.SelectedNode.Tag.ToString();
- }
- /// <summary>
- /// 选择窑炉TreeView中的节点前判断,如果数据有改变提示保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwKiln_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- try
- {
- // 判断数据是否被修改过,修改过需要提示保存消息
- if (DataJudge.IsChange((DataTable)this.dgvKilnCar.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(SaveKilnCarData));
- // 保存数据后提示
- if (rowCount > Constant.INT_IS_ZERO)
- {
- // 保存数据成功
- this.btnSave.Enabled = false;
- //this._dtSourse.AcceptChanges();
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "窑车", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- // 生成窑车树形结构
- TreeNode selectedNode = this.tvwkiln.SelectedNode;
- this.tvwkiln.SelectedNode = selectedNode;
- // 还原保存前窑炉TreeView的状态
- SetTreeNodesStatus(this.tvwkiln.Nodes);
- }
- else
- {
- // 保存数据失败
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "窑车", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else if (dialogResult == DialogResult.Cancel)
- {
- e.Cancel = true;
- }
- }
- }
- 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 tvwkiln_AfterSelect(object sender, TreeViewEventArgs e)
- {
- try
- {
- // 刷新DataGridView中的数据
- //this._dtSourse.AcceptChanges();
- this.GetAllKilnCar();
- this.RefreshDataGridViewData();
- this.dgvKilnCar.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 dgvKilnCar_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- try
- {
- if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
- {
- return;
- }
- //判断是否存在相同的编码
- if (!this.dgvKilnCar.CurrentRow.IsNewRow)
- {
- DataGridViewRow rowItem = this.dgvKilnCar.Rows[e.RowIndex];
- DataGridViewColumn columnItem = this.dgvKilnCar.Columns[e.ColumnIndex];
- object value = rowItem.Cells[columnItem.Name].EditedFormattedValue;
- // 窑车编码
- if ("KilnCarCode".Equals(columnItem.Name))
- {
- if (value != null || !string.IsNullOrEmpty(value.ToString().Trim()))
- {
- if (!this.IsUnique(value.ToString(), this.dgvKilnCar.CurrentRow.Index))
- {
- // 增加单元格的错误消息
- this.dgvKilnCar.CurrentRow.ErrorText
- = string.Format(Messages.MSG_CMN_W006, "窑车编码");
- e.Cancel = true;
- return;
- }
- }
- }
- // 清除单元格的错误消息
- this.dgvKilnCar.CurrentRow.ErrorText = string.Empty;
- }
- this.dgvKilnCar.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 dgvKilnCar_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
- {
- try
- {
- // 按Esc键时不校验
- if (!this.dgvKilnCar.IsCurrentRowDirty)
- {
- this.dgvKilnCar.IsSetInputColumnsColor = true;
- return;
- }
- DataGridViewRow row = this.dgvKilnCar.CurrentRow;
- if (!row.IsNewRow)
- {
- // 窑车名称不能为空
- if (row.Cells["KilnCarName"].Value == null
- || string.IsNullOrEmpty(row.Cells["KilnCarName"].Value.ToString().Trim()))
- {
- // 增加单元格的错误消息
- this.dgvKilnCar.CurrentRow.ErrorText
- = string.Format(Messages.MSG_CMN_W005, "窑车名称");
- e.Cancel = true;
- return;
- }
- // 过滤多余空格
- row.Cells["KilnCarName"].Value = row.Cells["KilnCarName"].Value.ToString().Trim();
- row.Cells["Remarks"].Value = row.Cells["Remarks"].Value.ToString().Trim();
- // 清除单元格的错误消息
- this.dgvKilnCar.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 dgvKilnCar_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 dgvKilnCar_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 chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- this.RefreshDataGridViewData();
- this.RefreshSaveBtnStatus();
- this.dgvKilnCar.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 dgvKilnCar_UserAddedRow(object sender, DataGridViewRowEventArgs e)
- {
- this.dgvKilnCar.IsSetInputColumnsColor = true;
- }
- /// <summary>
- /// 自动生成窑车种类编码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Table_SelectNewRow(object sender, DataTableNewRowEventArgs e)
- {
- try
- {
- DataTable itemTable = sender as DataTable;
- if (itemTable != null && itemTable.Rows.Count > Constant.INT_IS_ZERO)
- {
- e.Row["KilnID"] = this.tvwkiln.SelectedNode.Name;
- }
- }
- 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_CMN_W005, "窑车编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.btnSave.Enabled = false;
- return;
- }
- if (results == Constant.INT_IS_TWO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "窑车名称"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.btnSave.Enabled = false;
- return;
- }
- // 异步处理
- this.btnSave.Enabled = false;
- this.btnCancel.Enabled = false;
- int result = (int)DoAsync(new BaseAsyncMethod(SaveKilnCarData));
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 窑车数据保存成功
- if (result == Constant.INT_IS_TWO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "窑车", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- // 加载窑车管理数据
- this._dtSourse.AcceptChanges();
- this.btnSave.Enabled = false;
- }
- //存在相同窑车编码
- else if (result == Constant.INT_IS_ONE)
- {
- 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);
- }
- // 重新加载窗体数据
- //this.RefreshData();
- this.GetAllKilnCar();
- this.RefreshDataGridViewData();
- this.dgvKilnCar.IsSetInputColumnsColor = true;
- }
- 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 FrmGoodsKind_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- // 判断数据是否被修改过,如果修改过则提示保存
- if (DataJudge.IsChange((DataTable)this.dgvKilnCar.DataSource))
- {
- DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
- MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- // 保存改变的数据
- if (dialogResult == DialogResult.Yes)
- {
- DataGridViewRow row = dgvKilnCar.CurrentRow;
- if (!row.IsNewRow)
- {
- // 判断窑车编码不能为空
- if (row.Cells["KilnCarCode"].Value == null
- || string.IsNullOrEmpty(row.Cells["KilnCarCode"].Value + string.Empty))
- {
- // 错误消息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "窑车编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- // 判断窑车名称不能为空
- if (row.Cells["KilnCarName"].Value == null
- || string.IsNullOrEmpty(row.Cells["KilnCarName"].Value + string.Empty))
- {
- // 单元格的错误消息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "窑车名称"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- }
- int resultCount = (int)DoAsync(new BaseAsyncMethod(SaveKilnCarData));
- //存在相同窑车编码
- if (resultCount.Equals(Constant.INT_IS_ONE))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "窑车编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- // 保存后提示
- if (resultCount > Constant.INT_IS_ZERO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "窑车", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //存在相同窑车编码
- else if (Convert.ToInt16(dialogResult) == Constant.RETURN_IS_EXIST)
- {
- e.Cancel = true;
- btnSave.Enabled = false;
- 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;
- }
- }
- }
- 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 FrmGoodsKind_FormClosed(object sender, FormClosedEventArgs e)
- {
- _instance = null;
- }
- /// <summary>
- /// 设置排序时列表的颜色
- /// </summary>
- private void dgvKilnCar_Sorted(object sender, EventArgs e)
- {
- this.dgvKilnCar.IsSetInputColumnsColor = true;
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 取得窑炉数据
- /// </summary>
- /// <returns></returns>
- private DataSet GetKilnData()
- {
- try
- {
- return SystemModuleProxy.Service.GetKilnData(0);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 按条件取得窑车数据
- /// </summary>
- /// <returns></returns>
- private DataSet GetKilnCarByKilnID()
- {
- try
- {
- byte valueFlag = Convert.ToByte(this.chkDisplayDisabledData.Checked);
- return SystemModuleProxy.Service.GetKilnCarData(valueFlag, this._selectNode);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取窑车管理的全部数据
- /// </summary>
- /// <param name="sUserInfo">用户信息</param>
- /// <returns></returns>
- /// <remarks>
- /// 2014.10.31 任海 新建
- /// </remarks>
- private void GetAllKilnCar()
- {
- try
- {
- DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAllKilnCarInfo();
- }));
- this._dtSourse = dsResultAccount.Tables[0];
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 得到窑车信息
- /// </summary>
- /// <returns></returns>
- private void RefreshDataGridViewData()
- {
- try
- {
- StringBuilder sbstr = new StringBuilder();
- sbstr.Append(" 1=1");
- //未选中停用标识,显示正常数据
- if (this.chkDisplayDisabledData.Checked == false)
- {
- sbstr.Append(" and ValueFlag=1");
- }
- //选中树的节点把窑车Id加到查询条件中
- if (this.tvwkiln.SelectedNode != null)
- {
- sbstr.Append(" and KilnId=" + this.tvwkiln.SelectedNode.Name);
- }
- this._dtSourse.DefaultView.RowFilter = sbstr.ToString();
- this.dgvKilnCar.DataSource = this._dtSourse;
- this.btnSave.Enabled = false;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 保存窑车数据
- /// </summary>
- /// <returns>影响行数</returns>
- private object SaveKilnCarData()
- {
- try
- {
- // 获取当前datatKilnData数据源
- DataTable datatKilnCarData = (DataTable)this.dgvKilnCar.DataSource;
- int result = SystemModuleProxy.Service.SaveKilnCarData(datatKilnCarData);
- return result;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据取得的窑炉数据,生成树形结构
- /// </summary>
- private void CreateKilnTree()
- {
- try
- {
- this.tvwkiln.BeforeSelect -= tvwKiln_BeforeSelect;
- this.tvwkiln.AfterSelect -= tvwkiln_AfterSelect;
- // 取得窑炉数据
- DataSet kilnData = (DataSet)DoAsync(new BaseAsyncMethod(GetKilnData));
- // 没有窑炉数据时,直接返回
- if (kilnData == null || kilnData.Tables[0].Rows.Count < Constant.INT_IS_ONE)
- {
- return;
- }
- if (this.tvwkiln.Nodes.Count > Constant.INT_IS_ZERO)
- {
- // 添加节点前,保存状态
- this.SaveTreeNodesStatus(this.tvwkiln.Nodes);
- }
- // 将所有节点清除
- this.tvwkiln.Nodes.Clear();
- TreeNode kilnNode = null;
- DataRow[] kilnRows = kilnData.Tables[0].Select();
- // 显示子节点
- InitTreeView(kilnData.Tables[0], kilnRows, kilnNode);
- this.dgvKilnCar.IsSetInputColumnsColor = true;
- this.tvwkiln.BeforeSelect += tvwKiln_BeforeSelect;
- this.tvwkiln.AfterSelect += tvwkiln_AfterSelect;
- }
- catch (Exception ex)
- {
- this.tvwkiln.BeforeSelect += tvwKiln_BeforeSelect;
- this.tvwkiln.AfterSelect += tvwkiln_AfterSelect;
- throw ex;
- }
- }
- /// <summary>
- /// 递归显示窑炉树形目录
- /// </summary>
- /// <param name="kilnData">窑炉类数据源</param>
- /// <param name="rows"></param>
- /// <param name="node"></param>
- private void InitTreeView(DataTable kilnData, DataRow[] rows, TreeNode node)
- {
- try
- {
- foreach (DataRow row in rows)
- {
- TreeNode sNode = null;
- if (node == null)
- {
- // 新建树节点并添加
- sNode = new TreeNode();
- sNode.Text = row["KilnName"].ToString();
- sNode.Name = row["KilnID"].ToString();
- sNode.Tag = row["KilnID"].ToString();
- this.tvwkiln.Nodes.Add(sNode);
- }
- else
- {
- // 在原有树中加入节点
- sNode = node.Nodes.Add(row["KilnName"].ToString());
- sNode.Name = row["KilnID"].ToString();
- sNode.Tag = row["KilnID"].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.tvwkiln.SelectedNode = node;
- }
- SetTreeNodesStatus(node.Nodes);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 刷新DataGridView中的数据
- /// </summary>
- private void RefreshData()
- {
- try
- {
- // 获取相应节点数据
- if (this.tvwkiln.SelectedNode != null
- && !string.IsNullOrEmpty(this.tvwkiln.SelectedNode.Name.Trim()))
- {
- this._selectNode = this.tvwkiln.SelectedNode.Name.Trim();
- base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetKilnCarByKilnID));
- this.dgvKilnCar.AllowUserToAddRows = true;
- if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
- {
- // 选中新行时,自动计算窑车种类编码
- base.DataSource.Tables[0].TableNewRow +=
- new DataTableNewRowEventHandler(Table_SelectNewRow);
- this.dgvKilnCar.DataSource = this.DataSource.Tables[0];
- this.dgvKilnCar.IsSetInputColumnsColor = true;
- }
- }
- }
- catch (Exception ex)
- {
- throw 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.dgvKilnCar.Rows)
- {
- if (rowItem.Index == curRow)
- {
- continue;
- }
- // 窑车编码
- if (rowItem.Cells["KilnCarCode"].Value != null)
- {
- if (rowItem.Cells["KilnCarCode"].Value.ToString().TrimEnd().
- Equals(curCellValue.TrimEnd()))
- {
- return false;
- }
- }
- }
- return true;
- }
- /// <summary>
- /// 设置保存按钮的可用状态
- /// </summary>
- private void RefreshSaveBtnStatus()
- {
- // 数据有改变时,保存按钮可用,否则不可用
- if (DataJudge.IsChange((DataTable)this.dgvKilnCar.DataSource))
- {
- this.btnSave.Enabled = true;
- }
- else
- {
- this.btnSave.Enabled = false;
- }
- }
- /// <summary>
- /// 保存时单元格必输项不能为空
- /// </summary>
- private int Conservation()
- {
- int isConservation = Constant.INT_IS_ZERO;
- //判断窑车编码,名称不能为空
- DataTable datatJobsData = (DataTable)this.dgvKilnCar.DataSource;
- foreach (DataRow drproductionData in datatJobsData.Rows)
- {
- if (drproductionData["KilnCarCode"].ToString() == string.Empty)
- {
- isConservation = Constant.INT_IS_ONE;
- break;
- }
- if (drproductionData["KilnCarName"].ToString() == string.Empty)
- {
- isConservation = Constant.INT_IS_TWO;
- break;
- }
- }
- return isConservation;
- }
- #endregion
- private void dgvKilnCar_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
- {
- TextBox tb = (e.Control as TextBox);
- if (tb != null)
- {
- if ("KilnCarCode" == this.dgvKilnCar.Columns[this.dgvKilnCar.CurrentCell.ColumnIndex].Name)
- {
- tb.CharacterCasing = CharacterCasing.Upper;
- }
- else
- {
- tb.CharacterCasing = CharacterCasing.Normal;
- }
- }
- }
- }
- }
|