/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0501.cs
* 2.功能描述:产品档案
* 编辑履历:
* 作者 日期 版本 修改内容
* 庄天威 2014/09/13 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.DockPanel;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
///
/// 产品档案
///
public partial class F_MST_0501 : DockPanelBase
{
#region 成员变量
private static F_MST_0501 _instance; //单例模式
private int? _glazeTypeID = null; //釉料类别
#endregion
#region 构造函数
public F_MST_0501()
{
InitializeComponent();
this.dgvGoods.AutoGenerateColumns = false;
this.dgvGoodsSap.AutoGenerateColumns = false;
this.Text = FormTitles.F_MST_0501;
this.btnSearch.Text = ButtonText.BTN_SEARCH;
this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
this.tsbtnAttachment.Text = ButtonText.TSBTN_ATTACHMENT;
}
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_MST_0501 Instance
{
get
{
if (_instance == null)
{
_instance = new F_MST_0501();
}
return _instance;
}
}
#endregion
#region 事件
///
/// 窗体加载
///
private void F_MST_0501_Load(object sender, EventArgs e)
{
try
{
// 加载权限
FormPermissionManager.FormPermissionControl(this.Name, this,
Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
this.chkCeaseFlag.AllItemCheck();
this.chkValueFlag.AllItemCheck();
this.LoadDataSource();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 获取数据事件
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
this.dgvGoods.DataSource = null;
this.dgvGoodsSap.DataSource = null;
this._glazeTypeID = this.ddlGlazeTypeID.SelectedValue == null
? null : (int?)Convert.ToInt32(this.ddlGlazeTypeID.SelectedValue);
object obGoodsResult = DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(getGoods));
if (obGoodsResult != null)
{
DataSet dsGoods = (DataSet)obGoodsResult;
if (dsGoods.Tables.Count != Constant.INT_IS_ZERO)
{
this.dgvGoods.DataSource = dsGoods.Tables[Constant.INT_IS_ZERO];
this.dgvGoods.ReadOnly = true;
this.dgvGoodsSap.ReadOnly = true;
if (this.dgvGoods.Rows.Count == Constant.INT_IS_ZERO)
{
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 清空事件
///
private void btnClearCondition_Click(object sender, EventArgs e)
{
this.txtGoodsCode.Text = "";
this.txtGoodsModel.Text = "";
this.txtGoodsName.Text = "";
this.txtGoodsSpecification.Text = "";
this.ddlGlazeTypeID.Text = "";
this.txtRemarks.Text = "";
this.scbGoodsType.ClearValue();
this.chkCeaseFlag.AllItemCheck();
this.chkValueFlag.AllItemCheck();
}
///
/// 关闭窗体事件
///
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 自适应事件
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvGoods.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
dgvGoodsSap.AutoResizeColumns();
}
///
/// 窗体关闭事件
///
private void F_MST_0501_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 添加产品事件
///
private void tsbtnAddGoods_Click(object sender, EventArgs e)
{
try
{
F_MST_0502 frmMST0502 = new F_MST_0502(Constant.FormMode.Add, Constant.INT_IS_ZERO);
DialogResult dialogresult = frmMST0502.ShowDialog();
if (dialogresult.Equals(DialogResult.OK))
{
this.dgvGoods.DataSource = null;
object obGoodsResult = DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(getGoods));
if (obGoodsResult != null)
{
DataSet dsGoods = (DataSet)obGoodsResult;
if (dsGoods.Tables.Count != Constant.INT_IS_ZERO)
{
this.dgvGoods.DataSource = dsGoods.Tables[Constant.INT_IS_ZERO];
this.dgvGoods.ReadOnly = true;
}
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 编辑产品事件
///
private void tsbtnEditGoods_Click(object sender, EventArgs e)
{
try
{
DataGridViewRow currentRow = this.dgvGoods.CurrentRow;
if (currentRow != null)
{
int goodsId = Convert.ToInt32(currentRow.Cells["GoodsID"].Value);
F_MST_0502 frmMST0502 = new F_MST_0502(Constant.FormMode.Edit, goodsId);
DialogResult dialogresult = frmMST0502.ShowDialog();
if (dialogresult.Equals(DialogResult.OK))
{
this.dgvGoods.DataSource = null;
object obGoodsResult = DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(getGoods));
if (obGoodsResult != null)
{
DataSet dsGoods = (DataSet)obGoodsResult;
if (dsGoods.Tables.Count != Constant.INT_IS_ZERO)
{
this.dgvGoods.DataSource = dsGoods.Tables[Constant.INT_IS_ZERO];
this.dgvGoods.ReadOnly = true;
}
}
}
}
else
{
MessageBox.Show(Messages.MSG_CMN_W020, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 双击列表事件
///
private void dgvGoods_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.RowIndex == -Constant.INT_IS_ONE || e.ColumnIndex == -Constant.INT_IS_ONE)
{
return;
}
int goodsId = Convert.ToInt32(this.dgvGoods.Rows[e.RowIndex].Cells["GoodsID"].Value);
F_MST_0502 frmMST0702 = new F_MST_0502(Constant.FormMode.Edit, goodsId);
DialogResult dialogresult = frmMST0702.ShowDialog();
if (dialogresult.Equals(DialogResult.OK))
{
this.dgvGoods.DataSource = null;
object obGoodsResult = DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(getGoods));
if (obGoodsResult != null)
{
DataSet dsGoods = (DataSet)obGoodsResult;
if (dsGoods.Tables.Count != Constant.INT_IS_ZERO)
{
this.dgvGoods.DataSource = dsGoods.Tables[Constant.INT_IS_ZERO];
this.dgvGoods.ReadOnly = true;
}
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 附件按钮事件
///
///
///
private void tsbtnAttachment_Click(object sender, EventArgs e)
{
try
{
DataGridViewRow currentRow = this.dgvGoods.CurrentRow;
if (currentRow != null)
{
int goodsId = Convert.ToInt32(currentRow.Cells["GoodsID"].Value);
F_CMN_0101 frmCMN0101 = new F_CMN_0101(goodsId);
DialogResult dialogresult = frmCMN0101.ShowDialog();
if (dialogresult.Equals(DialogResult.OK))
{
}
}
else
{
MessageBox.Show(Messages.MSG_CMN_W020, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 设置产品工序
///
///
///
private void tsbtnSet_Click(object sender, EventArgs e)
{
try
{
DataTable data = this.dgvGoods.DataSource as DataTable;
if (data == null || data.Rows.Count == 0)
{
return;
}
data = data.Copy();
F_MST_0503 fMST0503 = new F_MST_0503(1, data);
fMST0503.ShowDialog();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 撤销产品工序设置
///
///
///
private void tsbtnUndo_Click(object sender, EventArgs e)
{
try
{
DataTable data = this.dgvGoods.DataSource as DataTable;
if (data == null || data.Rows.Count == 0)
{
return;
}
data = data.Copy();
F_MST_0503 fMST0503 = new F_MST_0503(2, data);
fMST0503.ShowDialog();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 根据查询条件获取数据集合
///
public DataSet getGoods()
{
try
{
GoodsEntity goods = new GoodsEntity();
goods.GoodsCode = this.txtGoodsCode.Text;
goods.GoodsModel = this.txtGoodsModel.Text;
goods.GoodsName = this.txtGoodsName.Text;
goods.GoodsSpecification = this.txtGoodsSpecification.Text;
goods.GlazeTypeID = this._glazeTypeID;
goods.Remarks = this.txtRemarks.Text;
goods.GoodsTypeCode = this.scbGoodsType.SearchedValue + "";
//判断选择框,如有选择则赋值
object[] objListCease = chkCeaseFlag.SelectedValues;
if (objListCease.Length == Constant.INT_IS_ONE)
{
goods.CeaseFlag = (int)objListCease[Constant.INT_IS_ZERO];
}
else if (objListCease.Length == Constant.INT_IS_ZERO)
{
return null;
}
object[] objListValue = chkValueFlag.SelectedValues;
if (objListValue.Length == Constant.INT_IS_ONE)
{
goods.ValueFlag = (int)objListValue[Constant.INT_IS_ZERO];
}
else if (objListValue.Length == Constant.INT_IS_ZERO)
{
return null;
}
return SystemModuleProxy.Service.SerachGoods(goods);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 加载页面所需的数据源
///
private void LoadDataSource()
{
try
{
// 绑定釉料类别
DataTable dtGlazeType = SystemModuleProxy.Service.GetDataDictionaryByType(
Constant.DictionaryType.TPC002, Constant.INT_IS_ONE);
if (dtGlazeType != null)
{
ddlGlazeTypeID.DisplayMember = "DictionaryValue";
ddlGlazeTypeID.ValueMember = "DictionaryID";
ddlGlazeTypeID.DataSource = dtGlazeType;
ddlGlazeTypeID.SelectedText = "";
ddlGlazeTypeID.Text = "";
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
private void dgvGoods_SelectionChanged(object sender, EventArgs e)
{
if (this.dgvGoods.DataSource == null || this.dgvGoods.CurrentRow == null)
{
this.dgvGoodsSap.DataSource = null;
return;
}
try
{
int goodsid = Convert.ToInt32(this.dgvGoods.CurrentRow.Cells["GoodsID"].Value);
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "MST_Goods";
cre.Name = "GetGoodsSAP";
cre.Request = goodsid;
// 调用服务器端获取数据集
ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
{
this.dgvGoodsSap.DataSource = sre.Data.Tables[0];
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
}
}