/*******************************************************************************
* Copyright(c) 2016 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_1103.cs
* 2.功能描述:工艺配置
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2016/07/22 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
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;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
///
/// 工艺配置
///
public partial class F_MST_1103 : FormBase
{
#region 成员变量
// 配置ID
private int _ptid = 0;
//需要添加的成型线明细集合
public List _addDetailList = new List();
//需要添加的成型工号明细集合
public List _addDetailUserList = new List();
//
private string _procedureNameValue; // 工序名称
private string _perProcedureNameValue; // 前工序名称
private string _inNameValue; // 工艺部门(入)
private string _outNameValue; // 工艺部门(出)
// 工序数据源
private DataTable _dtProcedure = new DataTable();
// 组织机构数据源
private DataTable _dtOrganization = new DataTable();
private bool _ShowFlag = true;
#endregion
#region 构造函数
public F_MST_1103(int ptid)
{
InitializeComponent();
if (ptid > 0)
{
this.Text = "编辑工艺配置";
}
else if (ptid < 0)
{
this.Text = "复制工艺配置";
}
else
{
this.Text = "新建工艺配置";
}
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
this.dgvTransferSetting.AutoGenerateColumns = false;
this._ptid = ptid;
}
#endregion
#region 事件
///
/// 关闭窗体
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 提交新建
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
int ErrorId = ValidationText();
if (ErrorId != Constant.INT_IS_ZERO)
{
string errorAddress = "";
switch (ErrorId)
{
case 1:
this.txtName.Focus();
errorAddress = "配置名称";
break;
case 2:
this.dkproductionLineSearchBox1.Focus();
errorAddress = "生产线";
break;
case 3:
this.txtDisplayNo.Focus();
errorAddress = "显示顺序";
break;
default:
break;
};
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
return;
}
DataTable dtTransferSetting = this.dgvTransferSetting.DataSource as DataTable;
dtTransferSetting.TableName = "dtTransferSetting";
dtTransferSetting.AcceptChanges();
if (dtTransferSetting.Rows.Count == Constant.INT_IS_ZERO)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "配置明细"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.dgvTransferSetting.IsSetInputColumnsColor = true;
//this.tabControl1.SelectTab(0);
return;
}
else
{
// 判断必埴项目是否都添写了
bool isError = false;
for (int i = 0; i < dtTransferSetting.Rows.Count; i++)
{
if (dtTransferSetting.Rows[i]["PROCEDUREID"].ToString() == "")
{
isError = true;
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工序名称"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.dgvTransferSetting.IsSetInputColumnsColor = true;
break;
}
if (dtTransferSetting.Rows[i]["INTECDEPID"].ToString() == "")
{
isError = true;
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工艺部门(入)"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.dgvTransferSetting.IsSetInputColumnsColor = true;
break;
}
if (dtTransferSetting.Rows[i]["DisplayNo"].ToString() == "")
{
isError = true;
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "显示顺序"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.dgvTransferSetting.IsSetInputColumnsColor = true;
break;
}
// wangx 2016-10-12
DataRow[] dr = dtTransferSetting.Select("PROCEDUREID=" + dtTransferSetting.Rows[i]["PROCEDUREID"]);
if (dr.Length == 1)
{
// 工序唯一,前置工序必须为空 PERPROCEDUREID
if (dtTransferSetting.Rows[i]["PERPROCEDUREID"].ToString() != string.Empty)
{
isError = true;
MessageBox.Show("【" + dtTransferSetting.Rows[i]["PROCEDURENAME"].ToString() + "】工序唯一,前置工序必须为空", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.dgvTransferSetting.IsSetInputColumnsColor = true;
break;
}
}
else if (dr.Length > 1)
{
// 多来源工序
// 1先判断前置工序是否为空
foreach (DataRow r in dr)
{
if (r["PERPROCEDUREID"].ToString() == string.Empty)
{
isError = true;
MessageBox.Show("【" + r["PROCEDURENAME"].ToString() + "】工序不唯一,前置工序必须不为空", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.dgvTransferSetting.IsSetInputColumnsColor = true;
break;
}
}
/* delete by chenxy 潮州工序流程
if (!isError)
{
// 2如果工艺出重复,提示错误消息
int orgCount = dr.Length;//查出几条数据
DataTable dtNew = dr.CopyToDataTable();
DataView dv = dtNew.DefaultView;
DataTable dtDiff = dv.ToTable(true, "OUTTECDEPID");
if (dr.Length != dtDiff.Rows.Count)
{
isError = true;
MessageBox.Show("多来源工序【" + dtTransferSetting.Rows[i]["PROCEDURENAME"].ToString() + "】的工艺部门(出)不能重复。", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.dgvTransferSetting.IsSetInputColumnsColor = true;
break;
}
}
*/
if (!isError)
{
// 3如果工艺入不一致,提示错误消息
DataTable dtInNew = dr.CopyToDataTable();
DataView dv2 = dtInNew.DefaultView;
DataTable dtInDiff = dv2.ToTable(true, "INTECDEPID");
if (dtInDiff.Rows.Count > 1)
{
isError = true;
MessageBox.Show("多来源工序【" + dtTransferSetting.Rows[i]["PROCEDURENAME"].ToString() + "】的工艺部门(入)必须一致。", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.dgvTransferSetting.IsSetInputColumnsColor = true;
break;
}
}
}
if (isError)
{
break;
}
// wangx 2016-10-12 end
}
if (isError)
{
return;
}
}
TecDepEntity tecDepEntity = new TecDepEntity();
tecDepEntity.PTID = this._ptid;
tecDepEntity.Name = this.txtName.Text.Trim();
tecDepEntity.LineID = Convert.ToInt32(this.dkproductionLineSearchBox1.ProductionLineID);
tecDepEntity.DisplayNo = Convert.ToInt32(this.txtDisplayNo.Text);
tecDepEntity.ValueFlag = chkVYes.Checked ? 1 : 0;
tecDepEntity.Remarks = this.txtRemarks.Text.Trim();
if (this.chkGdate.Checked)
{
tecDepEntity.GroutingDateBegin = this.dtpGdate.Value.Date;
}
if (tecDepEntity.TransferSetting == null)
{
tecDepEntity.TransferSetting = new DataSet();
}
tecDepEntity.TransferSetting.Tables.Add(dtTransferSetting.Copy());
int myReturn = (int)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.SaveTransfer(tecDepEntity);
}));
if (myReturn > 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)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 开始编辑事件
///
///
///
private void dgvTransferSetting_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
if (this.dkproductionLineSearchBox1.ProductionLineID == null)
{
this.dkproductionLineSearchBox1.Focus();
e.Cancel = true;
return;
}
else
{
//获取工序信息
if (this._dtProcedure.Rows.Count == 0)
{
ProductionLineEntity line = new ProductionLineEntity();
line.ProductionLineID = Convert.ToInt32(this.dkproductionLineSearchBox1.ProductionLineID);
DataTable dt = PCModuleProxy.Service.SearchProductionLine(line).Tables[1];
if (!dt.Columns.Contains("Sel"))
{
DataColumn column = new DataColumn();
column.ColumnName = "Sel";
column.DefaultValue = 0;
column.DataType = typeof(int);
dt.Columns.Add(column);
}
if (dt.Columns.Contains("displayno"))
{
dt.Columns.Remove("displayno");
}
this._dtProcedure = dt;
}
}
if (this.dgvTransferSetting.Rows.Count <= 1)
{
return;
}
DataGridViewColumn columnItem = this.dgvTransferSetting.Columns[e.ColumnIndex];
if ("ProcedureName".Equals(columnItem.Name))
{
_procedureNameValue = this.dgvTransferSetting.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
else if ("PerProcedureName".Equals(columnItem.Name))
{
_perProcedureNameValue = this.dgvTransferSetting.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
else if ("InName".Equals(columnItem.Name))
{
_inNameValue = this.dgvTransferSetting.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
else if ("outName".Equals(columnItem.Name))
{
_outNameValue = this.dgvTransferSetting.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 单元格值改变事件
///
///
///
private void dgvTransferSetting_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (this.dgvTransferSetting.Rows.Count <= 1 || !_ShowFlag)
{
return;
}
DataGridViewRow rowItem = this.dgvTransferSetting.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvTransferSetting.Columns[e.ColumnIndex];
// 用工序名称获取信息
if ("ProcedureName".Equals(columnItem.Name))
{
_ShowFlag = false;
FormUtility.BindtTransferProcedureRowDataSource(this.dgvTransferSetting,
e.RowIndex, columnItem.Name, _procedureNameValue, 1, _dtProcedure);
// 设置可输入单元格的颜色
this.dgvTransferSetting.IsSetInputColumnsColor = true;
}
else if ("PerProcedureName".Equals(columnItem.Name))
{
_ShowFlag = false;
FormUtility.BindtTransferProcedureRowDataSource(this.dgvTransferSetting,
e.RowIndex, columnItem.Name, _perProcedureNameValue, 0, _dtProcedure);
// 设置可输入单元格的颜色
this.dgvTransferSetting.IsSetInputColumnsColor = true;
}
else if ("outName".Equals(columnItem.Name))
{
_ShowFlag = false;
FormUtility.BindtTransferOutOrganizationRowDataSource(this.dgvTransferSetting,
e.RowIndex, columnItem.Name, _outNameValue, 0, _dtOrganization);
// 设置可输入单元格的颜色
this.dgvTransferSetting.IsSetInputColumnsColor = true;
}
else if ("InName".Equals(columnItem.Name))
{
_ShowFlag = false;
FormUtility.BindtTransferInOrganizationRowDataSource(this.dgvTransferSetting,
e.RowIndex, columnItem.Name, _inNameValue, 0, _dtOrganization);
// 设置可输入单元格的颜色
this.dgvTransferSetting.IsSetInputColumnsColor = true;
}
_ShowFlag = true;
}
catch (Exception ex)
{
//_ShowFlag = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体加载事件
///
///
///
private void F_MST_1103_Load(object sender, EventArgs e)
{
try
{
bool isCopy = (this._ptid < 0);
int ptid = this._ptid;
if (isCopy)
{
ptid = 0 - ptid;
this._ptid = 0;
}
this.dgvTransferSetting.IsSetInputColumnsColor = true;
this.txtName.BackColor = System.Drawing.SystemColors.Window;
if (ptid > 0)
{
DataSet dsTransfer = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetTransferEditInfo(ptid);
}));
if (dsTransfer != null)
{
this.dgvTransferSetting.DataSource = dsTransfer.Tables[1];
this.txtName.Text = dsTransfer.Tables[0].Rows[0]["Name"].ToString();
this.txtDisplayNo.Text = dsTransfer.Tables[0].Rows[0]["DisplayNo"].ToString();
this.chkVYes.Checked = Convert.ToBoolean(Convert.ToInt32(dsTransfer.Tables[0].Rows[0]["ValueFlag"]));
this.txtRemarks.Text = dsTransfer.Tables[0].Rows[0]["Remarks"].ToString();
this.dkproductionLineSearchBox1.ProductionLineID = Convert.ToInt32(dsTransfer.Tables[0].Rows[0]["LineID"]);
this.dkproductionLineSearchBox1.Text = dsTransfer.Tables[0].Rows[0]["ProductionLineName"].ToString();
object gdb = dsTransfer.Tables[0].Rows[0]["GroutingDateBegin"];
if (gdb != null && gdb != DBNull.Value)
{
this.dtpGdate.Value = Convert.ToDateTime(gdb);
this.chkGdate.Checked = true;
}
}
}
else
{
DataTable dtNew = new DataTable("table1");
dtNew.Columns.Add("PROCEDUREID", typeof(int));
dtNew.Columns.Add("PERPROCEDUREID", typeof(int));
dtNew.Columns.Add("OUTTECDEPID", typeof(int));
dtNew.Columns.Add("INTECDEPID", typeof(int));
dtNew.Columns.Add("ProcedureName");
dtNew.Columns.Add("PerProcedureName");
dtNew.Columns.Add("outName");
dtNew.Columns.Add("InName");
dtNew.Columns.Add("DisplayNo", typeof(int));
this.dgvTransferSetting.DataSource = dtNew;
}
DataTable dtOrganizaion = SystemModuleProxy.Service.GetAllTecDepInfo().Tables[0];
DataView dv = dtOrganizaion.DefaultView;
dv.RowFilter = "ValueFlag=1";
this._dtOrganization = dv.ToTable();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体加载后显示事件
///
///
///
private void F_PC_0102_1_1_Shown(object sender, EventArgs e)
{
//dgvDetail.IsSetInputColumnsColor = true;
dgvTransferSetting.IsSetInputColumnsColor = true;
}
///
/// 工号排序事件
///
///
///
private void dgvUser_Sorted(object sender, EventArgs e)
{
this.dgvTransferSetting.IsSetInputColumnsColor = true;
}
///
/// 窗口切换事件
///
///
///
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
this.dgvTransferSetting.IsSetInputColumnsColor = true;
}
private void chkGdate_CheckedChanged(object sender, EventArgs e)
{
this.dtpGdate.Enabled = this.chkGdate.Checked;
}
private void dgvTransferSetting_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
}
#endregion
#region 私有方法
///
/// 验证添加项
///
protected int ValidationText()
{
int ErrorId = 0;
if (this.txtName.Text.Trim() == string.Empty)
{
ErrorId = 1;
return ErrorId;
}
if (this.dkproductionLineSearchBox1.ProductionLineID == null)
{
ErrorId = 2;
return ErrorId;
}
if (this.txtDisplayNo.Text.Trim() == string.Empty)
{
ErrorId = 3;
return ErrorId;
}
return ErrorId;
}
#endregion
}
}