/*******************************************************************************
* Copyright(c) 2014 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0301.cs
* 2.功能描述:窑炉管理
* 编辑履历:
* 作者 日期 版本 修改内容
* 任海 2014/09/01 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.Client.DataModels;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
///
/// 窑炉管理
///
public partial class F_MST_0301 : FormBase
{
#region 成员变量
// 窗体的单例模式
private static F_MST_0301 _instance;
// 窑炉数据源
private DataTable _dtSourse;
// 窑炉类别
private int _KilnTypeId = Constant.INT_IS_ZERO;
#endregion
#region 构造函数
///
/// 构造函数
///
public F_MST_0301()
{
InitializeComponent();
// 窗口标题
this.Text = FormTitles.F_MST_0301;
// 按钮
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
this.btnTKDate.Text = ButtonText.BTN_SKDATE;
}
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_MST_0301 Instance
{
get
{
if (_instance == null)
{
_instance = new F_MST_0301();
}
return _instance;
}
}
#endregion
#region 事件
///
/// 窗体加载
///
///
///
private void F_MST_0301_Load(object sender, System.EventArgs e)
{
try
{
// 设置datagridview不自动创建列
this.dgvDataTonnage.AutoGenerateColumns = false;
// 加载窑炉管理数据
this.GetAllKilnt();
this.RefreshDataGridViewData();
// 绑定窑炉类型数据
DataSet setKilnType = SystemModuleProxy.Service.GetDictionaryData(0, "TPC001");
this.KilnType.ValueMember = "DictionaryID";
this.KilnType.DisplayMember = "DictionaryValue";
//把第一条数据绑定给窑炉类型
if (setKilnType != null && setKilnType.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
this._KilnTypeId = Convert.ToInt32(setKilnType.Tables[0].Rows[0]["DictionaryID"]);
}
if (setKilnType != null && setKilnType.Tables[0] != null)
{
this.KilnType.DataSource = setKilnType.Tables[0];
}
this.btnSave.Enabled = false;
this.dgvDataTonnage.IsSetInputColumnsColor = true;
//权限控制
FormPermissionManager.FormPermissionControl(this.Name, this,
LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
this.dgvDataTonnage.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 点击右上角关闭按钮
///
///
///
private void F_MST_0301_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
// 关闭的时候需要判断是否有数据变化
if (DataJudge.IsChange((DataTable)this.dgvDataTonnage.DataSource))
{
DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
// 保存改变的数据
if (dialogResult == DialogResult.Yes)
{
DataGridViewRow row = dgvDataTonnage.CurrentRow;
if (!row.IsNewRow)
{
// 判断窑炉编码不能为空
if (row.Cells["KilnCode"].Value == null
|| string.IsNullOrEmpty(row.Cells["KilnCode"].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["KilnName"].Value == null
|| string.IsNullOrEmpty(row.Cells["KilnName"].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["KilnType"].Value == null
|| string.IsNullOrEmpty(row.Cells["KilnType"].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;
}
}
// 异步处理
object result = DoAsync(new BaseAsyncMethod(SaveKilnData));
//存在相同的编码
if (result.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 (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
{
e.Cancel = true;
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "窑炉", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.btnSave.Enabled = false;
_dtSourse.AcceptChanges();
}
//存在相同的窑炉名称
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;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体关闭后,释放单例资源
///
///
///
private void F_MST_0301_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 选中新行时,设置默认值
///
///
///
private void dgvDataTonnage_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
// 设置有效属性为选中状态
e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
e.Row.Cells["KilnType"].Value = _KilnTypeId;
}
///
/// 单元格验证,检查
///
///
///
private void dgvDataTonnage_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
try
{
if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
{
return;
}
//判断是否存在相同的编码
if (!dgvDataTonnage.CurrentRow.IsNewRow)
{
DataGridViewRow rowItem = dgvDataTonnage.Rows[e.RowIndex];
DataGridViewColumn columnItem = dgvDataTonnage.Columns[e.ColumnIndex];
object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
// 窑炉编码
if ("KilnCode".Equals(columnItem.Name))
{
if (columnvalue != null && !string.IsNullOrEmpty(columnvalue + string.Empty))
{
if (!Utility.IsUnique(columnvalue.ToString(),
dgvDataTonnage.CurrentRow.Index, this.dgvDataTonnage, "KilnCode"))
{
// 单元格的错误消息
this.dgvDataTonnage.CurrentRow.ErrorText = string.Format(
Messages.MSG_CMN_W006, "窑炉编码");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
}
}
// 清除单元格的错误消息
this.dgvDataTonnage.CurrentRow.ErrorText = string.Empty;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 根据数据是否变化,设置保存按钮的可用状态
///
///
///
private void dgvDataTonnage_CellValidated(object sender, DataGridViewCellEventArgs e)
{
try
{
this.SetSaveBtnStatus();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 行校验
///
///
///
private void dgvDataTonnage_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
// 按Esc键时不校验
if (!dgvDataTonnage.IsCurrentRowDirty)
{
this.dgvDataTonnage.IsSetInputColumnsColor = true;
return;
}
if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
{
// 清除单元格的错误消息
this.dgvDataTonnage.CurrentRow.ErrorText = string.Empty;
return;
}
DataGridViewRow row = dgvDataTonnage.CurrentRow;
// 判断起窑炉编码能为空
if (row.Cells["KilnCode"].Value == null
|| string.IsNullOrEmpty(row.Cells["KilnCode"].Value + string.Empty))
{
// 单元格的错误消息
this.dgvDataTonnage.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "窑炉编码");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
// 判断窑炉名称不能为空
if (row.Cells["KilnName"].Value == null
|| string.IsNullOrEmpty(row.Cells["KilnName"].Value + string.Empty))
{
// 单元格的错误消息
this.dgvDataTonnage.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "窑炉名称");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
// 判断窑炉类别不能为空
if (row.Cells["KilnType"].Value == null
|| string.IsNullOrEmpty(row.Cells["KilnType"].Value + string.Empty))
{
// 单元格的错误消息
this.dgvDataTonnage.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "窑炉类别");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
// 清除单元格的错误消息
this.dgvDataTonnage.CurrentRow.ErrorText = string.Empty;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 根据数据是否变化,设置保存按钮的可用状态
///
///
///
private void dgvDataTonnage_RowValidated(object sender, DataGridViewCellEventArgs e)
{
try
{
this.SetSaveBtnStatus();
}
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.RefreshDataGridViewData();
this.SetSaveBtnStatus();
this.dgvDataTonnage.IsSetInputColumnsColor = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 单元格输入时,给自动生成的行设置颜色
///
///
///
private void dgvDataTonnage_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
this.dgvDataTonnage.IsSetInputColumnsColor = true;
}
///
/// 保存窑炉数据
///
///
///
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(SaveKilnData));
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);
// 加载窑炉管理数据
_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.dgvDataTonnage.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);
}
}
///
/// 点击关闭按钮
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 设置排序时列表的颜色
///
private void dgvDataTonnage_Sorted(object sender, EventArgs e)
{
this.dgvDataTonnage.IsSetInputColumnsColor = true;
}
///
/// 更新财年按钮点击事件
///
///
///
private void btnTKDate_Click(object sender, EventArgs e)
{
try
{
DataTable dtTonnage = dgvDataTonnage.DataSource as DataTable;
if (dtTonnage != null && dtTonnage.Rows.Count > 0)
{
F_MST_0303 frm = new F_MST_0303();
int skDate = 0;
int.TryParse(dtTonnage.Rows[0]["SK_Date"] + "", out skDate);
frm.SK_Date = skDate;
frm.ShowDialog();
if (frm.DialogResult == DialogResult.OK)
{
// 加载窑炉管理数据
this.GetAllKilnt();
this.RefreshDataGridViewData();
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 加载窑炉管理数据
///
///
private DataSet GetKilnData()
{
try
{
byte valueFlag = Convert.ToByte(chkDisplayDisabledData.Checked);
return SystemModuleProxy.Service.GetKilnData(valueFlag);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取窑炉的全部数据
///
/// 用户信息
///
///
/// 2014.10.30 任海 新建
///
private void GetAllKilnt()
{
try
{
DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetAllKilntInfo();
}));
this._dtSourse = dsResultAccount.Tables[0];
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 得到窑炉数据信息
///
///
private void RefreshDataGridViewData()
{
try
{
//未选中停用标识,显示正常数据
if (this.chkDisplayDisabledData.Checked == false)
{
this._dtSourse.DefaultView.RowFilter = "ValueFlag=1";
}
//选中时,显示全部数据
else
{
this._dtSourse.DefaultView.RowFilter = null;
}
this.dgvDataTonnage.DataSource = this._dtSourse;
this.btnSave.Enabled = false;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 保存窑炉数据
///
/// 是否成功
private object SaveKilnData()
{
try
{
// 获取当前datatKilnData数据源
DataTable datatKilnData = (DataTable)this.dgvDataTonnage.DataSource;
int result = SystemModuleProxy.Service.SaveKilnData(datatKilnData);
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 设置保存按钮的可用状态
///
private void SetSaveBtnStatus()
{
if (DataJudge.IsChange((DataTable)this.dgvDataTonnage.DataSource))
{
this.btnSave.Enabled = true;
}
else
{
this.btnSave.Enabled = false;
}
}
///
/// 保存时单元格必输项不能为空
///
private int Conservation()
{
int isConservation = Constant.INT_IS_ZERO;
DataTable datatKilnData = (DataTable)this.dgvDataTonnage.DataSource;
foreach (DataRow drproductionData in datatKilnData.Rows)
{
//判断窑炉编码,名称是否为空
if (drproductionData["KilnCode"].ToString() == string.Empty)
{
isConservation = Constant.INT_IS_ONE;
break;
}
if (drproductionData["KilnName"].ToString() == string.Empty)
{
isConservation = Constant.INT_IS_TWO;
break;
}
}
return isConservation;
}
#endregion
private void dgvDataTonnage_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox tb = (e.Control as TextBox);
if (tb != null)
{
if ("KilnCode" == this.dgvDataTonnage.Columns[this.dgvDataTonnage.CurrentCell.ColumnIndex].Name)
{
tb.CharacterCasing = CharacterCasing.Upper;
}
else
{
tb.CharacterCasing = CharacterCasing.Normal;
}
}
}
}
}