using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using QMAPP.ServicesAgent;
using QMAPP.WinForm.Common;
using QMAPP.Entity;
using QMAPP.MD.Entity.Bucket;
using System.Threading;
using Stone.WinModuleTransWare;
namespace QMAPP.WinForm.Forms.Injection
{
///
/// 模块编号:M11-1
/// 作 用:投料记录
/// 作 者:王庆男
/// 编写日期:2015年05月26日
///
public partial class InjectionMoldingNEWEditForm : Form
{
RawMaterial recorder = new RawMaterial();//编辑保存实体
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
private bool IsCntinueSpeakMsg = true;
///
/// 新建
///
public InjectionMoldingNEWEditForm()
{
InitializeComponent();
}
///
/// 编辑
///
///
public InjectionMoldingNEWEditForm(string pid)
{
recorder.PID = pid;
InitializeComponent();
}
///
/// 窗体加载
///
///
///
private void Form_Load(object sender, EventArgs e)
{
new KeyEvent().SetKeyToTxt(this);
#region 绑定下拉列表
BasicData basicData = new BasicData();
//加载是否有条码列表
//加载搪塑设备列表
#endregion
#region 加载编辑
//判断是否为编辑加载编辑数据
if (string.IsNullOrEmpty(recorder.PID) == false)
{
recorder = agent.InvokeServiceFunction>(B9BasicService.RawMaterialBLL_Get.ToString(), recorder).Result;
//一定是存在的物料
this.txtPartCode.Text = recorder.PartCode;
this.txtBatchCode.Text = recorder.BatchCode;
this.txtSerialCode.Text = recorder.SerialCode;
this.txtBucketCode.Text = recorder.BucketCode;
}
#endregion
}
///
/// 窗体保存事件
///
///
///
private void tsbSave_Click(object sender, EventArgs e)
{
//窗体数据校验
string errorMessae = ErrorCheck();
if (errorMessae != "")
{
MessageBox.Show(errorMessae, Resource1.ConfirmTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
#region 加载保存信息
recorder.PartCode = this.txtPartCode.Text.Trim();
recorder.BatchCode = this.txtBatchCode.Text.Trim();
recorder.SerialCode = this.txtSerialCode.Text.Trim();
recorder.BucketCode = this.txtBucketCode.Text.Trim();
#endregion
#region 保存
DataResult result;//判断是否成功
if (string.IsNullOrEmpty(recorder.PID) == true)
{
result = agent.InvokeServiceFunction>(B9BasicService.RawMaterialBLL_Insert.ToString(), recorder);
}
else
{
result = agent.InvokeServiceFunction>(B9BasicService.RawMaterialBLL_Update.ToString(), recorder);
}
//保存成功
if (result.IsSuccess)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
#endregion
}
///
/// 窗体关闭
///
///
///
private void tsbClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
///错误检测
///
///
private string ErrorCheck()
{
#region 校验
string strMessage = "";
if (!string.IsNullOrEmpty(this.txtBucketCode.Text) && !string.IsNullOrEmpty(this.txtPartCode.Text))
{
var List = agent.InvokeServiceFunction>(DictService.BucketMaterialBLL_GetBucketMaterialList.ToString(), new BucketMaterial() { BucketCode = this.txtBucketCode.Text });
if (List != null && List.Count > 0)
{
var count = 0;
foreach (var t in List)
{
if (System.Text.RegularExpressions.Regex.IsMatch(this.txtPartCode.Text, t.RawMaterial))
count++;
}
if (count == 0)
{
strMessage += this.txtBucketCode.Text + "原料上料错误 \r\n";
}
}
}
//批次
if (this.txtBatchCode.Text == string.Empty)
{
strMessage += Resource1.MaterialBatchNullValidate + "\r\n";
}
//料筒
if (this.txtBucketCode.Text == string.Empty)
{
strMessage += "料筒不能为空\r\n";
}
//零件号
if (this.txtPartCode.Text == string.Empty)
{
strMessage += "零件号不能为空\r\n";
}
return strMessage;
#endregion
}
private void PartCode_TextChanged(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && (sender as TextBox).Name == "txtPartCode")
{
if (!string.IsNullOrEmpty(this.txtBucketCode.Text) && !string.IsNullOrEmpty(this.txtPartCode.Text))
{
var List = agent.InvokeServiceFunction>(DictService.BucketMaterialBLL_GetBucketMaterialList.ToString(), new BucketMaterial() { BucketCode = this.txtBucketCode.Text });
if (List != null && List.Count > 0)
{
var count = 0;
foreach (var t in List)
{
if (this.txtPartCode.Text == t.RawMaterial)
count++;
}
if (count == 0)
{
IsCntinueSpeakMsg = true;
timer1.Enabled = true;
_Msg = this.txtBucketCode.Text + "号筒,原料上料错误";
InjectionMoldingPasswordForm psd = new InjectionMoldingPasswordForm(_Msg);
var result = psd.ShowDialog();
if (result.ToString() == "OK")
{
IsCntinueSpeakMsg = false;
txtPartCode.Focus();
this.txtPartCode.Text = "";
timer1.Enabled = false;
}
}
else
txtBatchCode.Focus();
}
else
txtBatchCode.Focus();
}
else
{
MessageBox.Show("请优先扫描料筒号", Resource1.ConfirmTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtBucketCode.Focus();
}
}
}
private void BucketCode_TextChanged(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && (sender as TextBox).Name == "txtBucketCode")
{
txtPartCode.Focus();
}
}
private void BatchCode_TextChanged(object sender, KeyEventArgs e)
{
//MessageBox.Show(e.KeyValue.ToString());
if (e.KeyCode == Keys.Enter && (sender as TextBox).Name == "txtBatchCode")
{
var List = agent.InvokeServiceFunction>(DictService.RawMaterialBLL_GetListRaw.ToString(), new RawMaterial() { BucketCode = this.txtBucketCode.Text, PartCode = this.txtPartCode.Text });
if (List != null && List.Count > 0)
{
var list = List.Where(p=>p.BatchCode == this.txtBatchCode.Text);
if (list.Count() == 0)
{
string state = string.Empty;
IsCntinueSpeakMsg = true;
timer1.Enabled = true;
_Msg = this.txtBucketCode.Text + "号筒,批次号变更";
//弹出输入密码
InjectionMoldingPasswordForm psd = new InjectionMoldingPasswordForm(_Msg);
var result = psd.ShowDialog();
if (result.ToString() == "OK")
{
IsCntinueSpeakMsg = false;
timer1.Enabled = false;
txtSerialCode.Focus();
}
else
{
this.txtBatchCode.Text = "";
IsCntinueSpeakMsg = false;
timer1.Enabled = false;
txtBatchCode.Focus();
}
}
else
txtSerialCode.Focus();
}
else
txtSerialCode.Focus();
}
}
private string _Msg = String.Empty;
private void buttonRecord_Click()
{
if (IsCntinueSpeakMsg)
{
new Form1().Speek(_Msg);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Thread thread = new Thread(buttonRecord_Click);
thread.Start();
}
}
}