/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0702.cs
* 2.功能描述:新建/编辑报表工序
* 编辑履历:
* 作者 日期 版本 修改内容
* 宋扬 2014/12/25 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.Controls;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
///
/// 新建/编辑报表工序
///
public partial class F_MST_0702 : FormBase
{
#region 成员变量
// 窗体模式ID
private Constant.FormMode _formType;
// 操作实体ID
private int? _entityId;
// 操作实体信
private RptProcedureEntity _rptProcedureEntity = new RptProcedureEntity();
// 工序数据源
private DataTable _dtProcedure = new DataTable();
// 工序
private DataSet _dsProcedure = new DataSet();
//记录数据来源Code
private string _rptProcedureCode = string.Empty;
#endregion
#region 构造函数
///
/// 窗体构造
///
/// 窗体打开模式
/// 操作实体ID
public F_MST_0702(Constant.FormMode formType, int entityId)
{
InitializeComponent();
this._formType = formType;
this._entityId = entityId;
// 窗体显示的Title
if (this._formType == Constant.FormMode.Add)
{
this.Text = FormTitles.F_MST_0702_ADD;
}
else if (this._formType == Constant.FormMode.Edit)
{
this.Text = FormTitles.F_MST_0702_EDIT;
}
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
}
#endregion
#region 事件处理
///
/// 窗体加载
///
///
///
private void F_MST_0702_Load(object sender, EventArgs e)
{
try
{
BindSelectData();
//如果是修改,要绑定选中的信息
if (this._formType == Constant.FormMode.Edit)
{
BindData();
}
//如果是新建,选项默认值设定
else if (this._formType == Constant.FormMode.Add)
{
BindPage();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 保持操作按钮事件
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (this.BindEntity())
{
if (EntityToServer() > Constant.INT_IS_ZERO)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "报表数据来源", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "报表数据来源", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 窗体关闭
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 窗体释放
///
///
///
private void F_MST_0702_FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
}
///
/// 数据来源工序变更
///
///
///
private void dgvRptSProcedure_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (this.dgvRptSProcedure.Rows.Count <= Constant.INT_IS_ONE)
{
return;
}
if (string.IsNullOrEmpty(this.dropRptProcedureType.Text))
{
return;
}
DataGridViewRow rowItem = this.dgvRptSProcedure.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvRptSProcedure.Columns[e.ColumnIndex];
// 用编号获取产品信息
if ("ProcedureCode".Equals(columnItem.Name))
{
int flag = Constant.INT_IS_ZERO;
if (this.dropRptProcedureType.SelectedValue.ToString().Equals("A0001"))
{
flag = Constant.INT_IS_ZERO;
}
else
{
flag = Constant.INT_IS_ONE;
}
DataTable dtDataSource =
FormUtility.BindtProcedureRowDataSource(this.dgvRptSProcedure,
e.RowIndex, columnItem.Name, string.Empty, flag, _dtProcedure);
if (dtDataSource != null)
{
this.dgvRptSProcedure.DataSource = dtDataSource;
}
// 设置可输入单元格的颜色
this.dgvRptSProcedure.IsSetInputColumnsColor = true;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 数据统计工序变更
///
///
///
private void dgvRptTProcedure_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (this.dgvRptTProcedure.Rows.Count <= 1)
{
return;
}
DataGridViewRow rowItem = this.dgvRptTProcedure.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvRptTProcedure.Columns[e.ColumnIndex];
// 用编号获取产品信息
if ("colProcedureCode".Equals(columnItem.Name))
{
DataTable dtDataSource =
FormUtility.BindtProcedureRowDataSource(this.dgvRptTProcedure,
e.RowIndex, columnItem.Name, string.Empty, 1, _dtProcedure);
if (dtDataSource != null)
{
this.dgvRptTProcedure.DataSource = dtDataSource;
}
// 设置可输入单元格的颜色
this.dgvRptTProcedure.IsSetInputColumnsColor = true;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 为实体绑定页面属性
///
private bool BindEntity()
{
if (string.IsNullOrEmpty(this.dropRptProcedureType.Text)
|| string.IsNullOrEmpty(this.txtRptProcedureName.Text.Trim())
|| string.IsNullOrEmpty(this.txtRptProcedureCode.Text.Trim()))
{
return false;
}
if (this._formType == Constant.FormMode.Edit)
{
this._rptProcedureEntity.RptProcedureCode = this.txtRptProcedureCode.Text.Trim();
if (!this._rptProcedureCode.Equals(this.txtRptProcedureCode.Text.Trim()))
{
if (!isCodeBool(_rptProcedureEntity))
{
return false;
}
}
}
else if (this._formType == Constant.FormMode.Add)
{
this._rptProcedureEntity.RptProcedureCode = this.txtRptProcedureCode.Text.Trim();
if (!isCodeBool(_rptProcedureEntity))
{
return false;
}
}
this._rptProcedureEntity.DisplayNo = this.txtDisplayNo.Text.Trim() == "" ? 0 : Convert.ToInt32(this.txtDisplayNo.Text.Trim());
this._rptProcedureEntity.RptProcedureName = this.txtRptProcedureName.Text.Trim();
this._rptProcedureEntity.RptProcedureTpye = this.dropRptProcedureType.SelectedValue.ToString();
return true;
}
///
/// 绑定需要操作的实体信息
///
private void BindPage()
{
try
{
DataTable dt_DataSource = new DataTable();
dt_DataSource.Columns.Add("ProcedureID", typeof(int));
dt_DataSource.Columns.Add("ProcedureCode", typeof(string));
dt_DataSource.Columns.Add("ProcedureName", typeof(string));
this.dgvRptSProcedure.DataSource = dt_DataSource;
this.dgvRptTProcedure.DataSource = dt_DataSource.Copy();
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 绑定数据来源类型
///
private void BindSelectData()
{
DataTable newdtb = new DataTable();
newdtb.Columns.Add("RptProcedureTypeId", typeof(string));
newdtb.Columns.Add("RptProcedureType", typeof(string));
DataRow newRow = newdtb.NewRow();
newRow["RptProcedureTypeId"] = "A0001";
newRow["RptProcedureType"] = "出窑统计";
newdtb.Rows.Add(newRow);
this.dropRptProcedureType.DisplayMember = "RptProcedureType";
this.dropRptProcedureType.ValueMember = "RptProcedureTypeId";
this.dropRptProcedureType.DataSource = newdtb;
//获取工序信息
SearchProductionLineEntity line = new SearchProductionLineEntity();
this._dtProcedure = SystemModuleProxy.Service.GetProdureList(line).Tables[0];
//设置表格不自动创建列
this.dgvRptSProcedure.AutoGenerateColumns = false;
this.dgvRptTProcedure.AutoGenerateColumns = false;
}
///
/// 绑定数据源
///
private void BindData()
{
try
{
if (this._entityId != Constant.INT_IS_ZERO && this._entityId != null)
{
this._rptProcedureEntity = new RptProcedureEntity();
this._rptProcedureEntity.RptProcedureID = this._entityId;
DataSet dsSearchRptProcedure = (DataSet)DoAsync(() =>
{
return SystemModuleProxy.Service.GetRptProcedureModule(_rptProcedureEntity);
});
if (dsSearchRptProcedure != null)
{
if (dsSearchRptProcedure.Tables[Constant.INT_IS_ZERO].Rows.Count > Constant.INT_IS_ZERO)
{
this.txtRptProcedureCode.Text = dsSearchRptProcedure.Tables[Constant.INT_IS_ZERO].Rows[0]["Rptprocedurecode"].ToString();
this._rptProcedureCode = this.txtRptProcedureCode.Text.Trim();
this.txtRptProcedureName.Text = dsSearchRptProcedure.Tables[Constant.INT_IS_ZERO].Rows[0]["RptprocedureName"].ToString();
this.dropRptProcedureType.SelectedValue = dsSearchRptProcedure.Tables[Constant.INT_IS_ZERO].Rows[0]["RptprocedureType"].ToString();
this._rptProcedureEntity.OPTimeStamp = Convert.ToDateTime(dsSearchRptProcedure.Tables[Constant.INT_IS_ZERO].Rows[0]["OPTimeStamp"]);
this.txtDisplayNo.Text = dsSearchRptProcedure.Tables[Constant.INT_IS_ZERO].Rows[0]["displayno"].ToString();
}
this._dsProcedure = (DataSet)DoAsync(() =>
{
return SystemModuleProxy.Service.GetRptProcedureIdByProcedureInfo(Convert.ToInt32(this._entityId));
});
if (this._dsProcedure != null)
{
if (this._dsProcedure.Tables[Constant.INT_IS_ZERO].Rows.Count > Constant.INT_IS_ZERO)
{
this.dgvRptSProcedure.DataSource = this._dsProcedure.Tables[Constant.INT_IS_ZERO];
}
if (this._dsProcedure.Tables[Constant.INT_IS_ONE].Rows.Count > Constant.INT_IS_ZERO)
{
this.dgvRptTProcedure.DataSource = this._dsProcedure.Tables[Constant.INT_IS_ONE];
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 与服务交互操作
///
///
private int EntityToServer()
{
int resultCount = Constant.INT_IS_ZERO;
if (this._formType == Constant.FormMode.Add)
{
this._dsProcedure.Tables.Add(this.dgvRptSProcedure.GetDataTable());
this._dsProcedure.Tables.Add(this.dgvRptTProcedure.GetDataTable());
resultCount = (int)DoAsync(() =>
{
return SystemModuleProxy.Service.AddRptProcedure(this._rptProcedureEntity, this._dsProcedure);
});
}
else if (this._formType == Constant.FormMode.Edit)
{
resultCount = (int)DoAsync(() =>
{
return SystemModuleProxy.Service.UpdateRptProcedure(this._rptProcedureEntity, this._dsProcedure);
});
}
return resultCount;
}
///
/// 判断编号是否存在
///
///
private bool isCodeBool(RptProcedureEntity rptProcedureEntity)
{
DataSet dsSearchRptProcedure = (DataSet)DoAsync(() =>
{
return SystemModuleProxy.Service.GetRptProcedureModule(rptProcedureEntity);
});
if (dsSearchRptProcedure.Tables[Constant.INT_IS_ZERO].Rows.Count > Constant.INT_IS_ZERO)
{
return false;
}
return true;
}
#endregion
}
}