/*******************************************************************************
* Copyright(c) 2014 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0408.cs
* 2.功能描述:产品分级
* 编辑履历:
* 作者 日期 版本 修改内容
* 任海 2014/10/18 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
///
/// 产品分级
///
public partial class F_MST_0408 : FormBase
{
#region 成员变量
// 窗体的单例模式
private static F_MST_0408 _instance;
// 字节变量
private byte _distinguish = 1;
#endregion
#region 构造函数
///
/// 构造函数
///
public F_MST_0408()
{
InitializeComponent();
// 窗口标题
this.Text = FormTitles.F_MST_0408;
// 按钮
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
}
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_MST_0408 Instance
{
get
{
if (_instance == null)
{
_instance = new F_MST_0408();
}
return _instance;
}
}
#endregion
#region 事件
///
/// 窗体加载
///
///
///
private void F_MST_0408_Load(object sender, EventArgs e)
{
try
{
// 设置datagridview不自动创建列
this.dgvGoodsLevel.AutoGenerateColumns = false;
// 设置datagridview不自动创建行
this.dgvGoodsLevel.AllowUserToAddRows = false;
//获取数据
base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetGoodsLevelData));
//绑定数据
this.dgvGoodsLevel.DataSource = base.DataSource.Tables[0];
this.btnSave.Enabled = false;
this.SetCellColor();
//设置可输入单元格颜色
this.dgvGoodsLevel.IsSetInputColumnsColor = true;
//权限
FormPermissionManager.FormPermissionControl(this.Name, this,
LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
this.dgvGoodsLevel.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体关闭后,释放单例资源
///
///
///
private void F_MST_0408_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 点击关闭按钮
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 行校验
///
///
///
private void dgvGoodsLevel_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
// 按Esc键时不校验
if (!dgvGoodsLevel.IsCurrentRowDirty)
{
this.dgvGoodsLevel.IsSetInputColumnsColor = true;
return;
}
if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
{
// 清除单元格的错误消息
this.dgvGoodsLevel.CurrentRow.ErrorText = string.Empty;
return;
}
DataGridViewRow row = dgvGoodsLevel.CurrentRow;
if (!row.IsNewRow)
{
// 判断产品分级名称不能为空
if (row.Cells["GoodsLevelName"].Value == null
|| string.IsNullOrEmpty(row.Cells["GoodsLevelName"].Value + string.Empty))
{
// 单元格的错误消息
this.dgvGoodsLevel.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "产品分级名称");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
// 清除单元格的错误消息
this.dgvGoodsLevel.CurrentRow.ErrorText = string.Empty;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 根据数据是否变化,设置保存按钮的可用状态
///
///
///
private void dgvGoodsLevel_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 F_MST_0408_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
// 关闭的时候需要判断是否有数据变化
if (DataJudge.IsChange((DataTable)this.dgvGoodsLevel.DataSource))
{
DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
// 保存改变的数据
if (dialogResult == DialogResult.Yes)
{
DataGridViewRow row = dgvGoodsLevel.CurrentRow;
if (!row.IsNewRow)
{
// 判断产品分级名称不能为空
if (row.Cells["GoodsLevelName"].Value == null
|| string.IsNullOrEmpty(row.Cells["GoodsLevelName"].Value + string.Empty))
{
// 错误消息
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "产品分级名称"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
}
// 异步处理
object result = DoAsync(new BaseAsyncMethod(SaveGoodsLevelData));
}
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 dgvGoodsLevel_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
//判断单元checkbox控件是否选中
if (e.ColumnIndex == Constant.INT_IS_FIVE && e.RowIndex != -Constant.INT_IS_ONE)
{
string value = this.dgvGoodsLevel.Rows[this.dgvGoodsLevel.CurrentCell.RowIndex].Cells["IsSemiFinishedEx"].Value.ToString();
//如果未选中不可编辑,取消事件
if (value == Constant.INT_IS_ZERO.ToString())
{
e.Cancel = true;
}
}
if (e.ColumnIndex == Constant.INT_IS_SEVEN && e.RowIndex != -Constant.INT_IS_ONE)
{
string value = this.dgvGoodsLevel.Rows[this.dgvGoodsLevel.CurrentCell.RowIndex].Cells["IsFinishedEx"].Value.ToString();
if (value == Constant.INT_IS_ZERO.ToString())
{
e.Cancel = true;
}
}
if (e.ColumnIndex == Constant.INT_IS_ELEVEN && e.RowIndex != -Constant.INT_IS_ONE)
{
string value = this.dgvGoodsLevel.Rows[this.dgvGoodsLevel.CurrentCell.RowIndex].Cells["CanDisable"].Value.ToString();
if (value == Constant.INT_IS_ZERO.ToString())
{
e.Cancel = true;
}
}
}
///
/// 保存产品分级数据
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
// 异步处理
this.btnSave.Enabled = false;
this.btnCancel.Enabled = false;
int result = (int)DoAsync(new BaseAsyncMethod(SaveGoodsLevelData));
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);
// 加载产品分级数据
base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetGoodsLevelData));
if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
{
dgvGoodsLevel.DataSource = this.DataSource.Tables[0];
}
this.btnSave.Enabled = false;
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品分级", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
this.SetCellColor();
this.dgvGoodsLevel.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 chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
{
try
{
base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetGoodsLevelData));
if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
{
dgvGoodsLevel.DataSource = base.DataSource.Tables[0];
}
this.dgvGoodsLevel.IsSetInputColumnsColor = true;
this.btnSave.Enabled = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 设置排序时列表的颜色
///
private void dgvGoodsLevel_Sorted(object sender, EventArgs e)
{
SetCellColor();
this.dgvGoodsLevel.IsSetInputColumnsColor = true;
this.dgvGoodsLevel.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
}
#endregion
#region 私有方法
///
/// 加载产品分级管理数据
///
///
private DataSet GetGoodsLevelData()
{
try
{
return SystemModuleProxy.Service.GetGoodsLevelData(_distinguish);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 保存产品分级数据
///
/// 是否成功
///
private object SaveGoodsLevelData()
{
try
{
DataTable datatGoodsLevelData = (DataTable)this.dgvGoodsLevel.DataSource;
int result = SystemModuleProxy.Service.SaveGoodsLevelData(datatGoodsLevelData);
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 设置保存按钮的可用状态
///
private void SetSaveBtnStatus()
{
if (DataJudge.IsChange((DataTable)this.dgvGoodsLevel.DataSource))
{
this.btnSave.Enabled = true;
}
else
{
this.btnSave.Enabled = false;
}
}
///
/// 设置单元格输入状态
///
private void SetCellColor()
{
foreach (DataGridViewRow gvrFor in this.dgvGoodsLevel.Rows)
{
//判断可编辑单元格的颜色
if (gvrFor.Cells["IsSemiFinishedEx"].Value.ToString() == Constant.INT_IS_ONE.ToString())
{
gvrFor.Cells["SFEDisplayNo"].ReadOnly = false;
}
else
{
gvrFor.Cells["SFEDisplayNo"].ReadOnly = true;
}
if (gvrFor.Cells["IsFinishedEx"].Value.ToString() == Constant.INT_IS_ONE.ToString())
{
gvrFor.Cells["FEDisplayNo"].ReadOnly = false;
}
else
{
gvrFor.Cells["FEDisplayNo"].ReadOnly = true;
}
if (gvrFor.Cells["GoodsLevelTypeID"].Value.ToString() == Constant.INT_IS_TWO.ToString()
|| gvrFor.Cells["GoodsLevelTypeID"].Value.ToString() == Constant.INT_IS_FIVE.ToString()
|| gvrFor.Cells["GoodsLevelTypeID"].Value.ToString() == Constant.INT_IS_SIX.ToString())
{
gvrFor.Cells["ValueFlag"].ReadOnly = false;
}
else
{
gvrFor.Cells["ValueFlag"].ReadOnly = true;
}
}
}
#endregion
}
}