using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Windows.Forms;
using QMAPP.FJC.Entity;
using QMAPP.FJC.Entity.Injection;
using QMAPP.FJC.Entity.Operation;
using QMAPP.ServicesAgent;
using QMAPP.WinForm.Common;
using QMFrameWork.Common.Serialization;
using QMFrameWork.Data;
using QMAPP.Entity;
using QMAPP.FJC.Entity.ProduceManage;
using System.Data;
using QMAPP.WinForm.Forms.Operation;
namespace QMAPP.WinForm.Forms.Mend
{
///
/// 模块编号:M15-1
/// 作 用:返修件查询
/// 作 者:王丹丹
/// 编写日期:2015年07月7日
///
public partial class MendRecorderForm : Form
{
MendRecorder searchModel = new MendRecorder();//查询条件
public MendRecorderForm()
{
InitializeComponent();
}
#region 窗体载入
private void Form_Load(object sender, EventArgs e)
{
//初始化控件属性
this.DGMendRecorder.AutoGenerateColumns = false;
#region 绑定下拉列表
BasicData basicData = new BasicData();
////产品类别
//this.comPRODUCTTYPE.DataSource = basicData.GetDictionaryList("PRODUCTTYPE");
//this.comPRODUCTTYPE.DisplayMember = "value";
//this.comPRODUCTTYPE.ValueMember = "key";
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
DataTable recorder = agent.InvokeServiceFunction(B9IPCService.DefectTypeBLL_GetDefectType.ToString());
List list = new List();
list.Add(new QM.Common.ListItem("",""));
foreach (DataRow dr in recorder.Rows)
{
string keyvalue = dr["DEFECTKEY"].ToString();
string defectValue = dr["DEFECTVALUE"].ToString();
list.Add(new QM.Common.ListItem(keyvalue.ToString(), defectValue));
}
//返修原因
this.comMENDREASON.DataSource = list;
this.comMENDREASON.DisplayMember = "value";
this.comMENDREASON.ValueMember = "key";
//修改下拉宽度
basicData.AdjustComboBoxDropDownListWidth(comMENDREASON);
////返修方式
//this.comMENDTYPE.DataSource = basicData.GetDictionaryList("MENDTYPE");
//this.comMENDTYPE.DisplayMember = "value";
//this.comMENDTYPE.ValueMember = "key";
//返修结果
this.comMENDRESULT.DataSource = basicData.GetDictionaryList("MENDRESULT");
this.comMENDRESULT.DisplayMember = "value";
this.comMENDRESULT.ValueMember = "key";
#endregion
//初始化条件
this.dtpCREATEDATESTART.ValueX = DateTime.Now.AddDays(-10);
this.dtpCREATEDATEEND.ValueX = DateTime.Now;
//初始化分页
this.pager1.Init();
//加载默认查询条件
SetSearchModel();
BindGirdData();
#region 打印模板拷贝
PrintTempleCopyClass printClass = new PrintTempleCopyClass();
printClass.CopyPrintTemple("MendRecorderForm");
#endregion
}
#endregion
#region 绑定数据
///
/// 绑定数据列表
///
///
public DataPage BindGirdData()
{
List recorders = null;//查询结果列表
DataPage dataPage = new DataPage();
//获取前台分页设置信息
dataPage = pager1.DataPage;
try
{
#region 服务查询
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
dataPage = agent.InvokeServiceFunction(B9IPCService.MendRecorderBLL_GetList.ToString(), searchModel, dataPage);
recorders = JsonConvertHelper.GetDeserialize>(dataPage.Result.ToString());
#endregion
this.DGMendRecorder.DataSource = recorders;
this.pager1.DataPage = dataPage;
}
catch (Exception ex)
{
throw ex;
}
return dataPage;
}
#endregion
#region 事件
///
/// 分页事件
///
///
///
private DataPage pager1_EventPaging(Controls.EventPagingArg e)
{
return BindGirdData();
}
///
/// 查询事件
///
///
///
private void tsbSearch_Click(object sender, EventArgs e)
{
//查询条件校验
bool issuccess =ExistSearchModel();
if (issuccess)
{
//设置查询条件
SetSearchModel();
this.pager1.Init();
BindGirdData();
}
}
///
/// 登记按钮
///
///
///
private void tsbAdd_Click(object sender, EventArgs e)
{
SpecifyForm newfrom = new SpecifyForm();
DialogResult result = newfrom.ShowDialog();
SetSearchModel();
this.pager1.Init();
BindGirdData();
}
///
/// 返修按钮
///
///
///
private void tsbMend_Click(object sender, EventArgs e)
{
if (this.DGMendRecorder.SelectedRows.Count > 0)
{
string selectKey = this.DGMendRecorder.SelectedRows[0].Cells["Pid"].Value.ToString();
//条码
var PRODUCTCODE = this.DGMendRecorder.SelectedRows[0].Cells["InjectionTerminal"].Value;
if (PRODUCTCODE == null)
{
MessageBox.Show("没有条码信息!");
return;
}
string PRODUCTCODEs = PRODUCTCODE.ToString();
//PRODUCTCODEs.Length=8的是批量报废的批次号
if (PRODUCTCODEs.Length<9)
{
MessageBox.Show("没有条码信息!");
return;
}
//物料类型
var material = this.DGMendRecorder.SelectedRows[0].Cells["CURRENTPROCESS"].Value;
if (material==null)
{
MessageBox.Show("没有物料类型信息!");
return;
}
string materialType = material.ToString();
if (materialType == "DP_ASSY_LF" || materialType == "DP_ASSY_LR" ||
materialType == "DP_ASSY_RF" || materialType == "DP_ASSY_RR" ||
materialType == "IP_ASSY")
{
SpecifyForm specifyForm = new SpecifyForm(selectKey, materialType);
specifyForm.ShowDialog();
}
else
{
MessageBox.Show("物料类型不匹配!");
}
}
}
#endregion
#region 设置查询条件
///
/// 设置查询条件
///
public void SetSearchModel()
{
searchModel = new MendRecorder();
//searchModel.MACHINETYPE = EnumGeter.MACHINETYPE.tangsu.GetHashCode().ToString();//默认条件
//条码
if (string.IsNullOrEmpty(this.txtPRODUCTCODE.Text.Trim()) == false)
{
searchModel.PRODUCTCODE = this.txtPRODUCTCODE.Text.Trim();
}
//产品类别
//if (this.comPRODUCTTYPE.SelectedValue != null && string.IsNullOrEmpty(this.comPRODUCTTYPE.SelectedValue.ToString().Trim()) == false)
//{
// searchModel.PRODUCTTYPE = this.comPRODUCTTYPE.SelectedValue.ToString().Trim();
//}
//返修原因
if (this.comMENDREASON.SelectedValue != null && string.IsNullOrEmpty(this.comMENDREASON.SelectedValue.ToString().Trim()) == false)
{
searchModel.MENDREASON = this.comMENDREASON.SelectedValue.ToString().Trim();
}
//返修方式
//if (this.comMENDTYPE.SelectedValue != null && string.IsNullOrEmpty(this.comMENDTYPE.SelectedValue.ToString().Trim()) == false)
//{
// searchModel.MENDTYPE = this.comMENDTYPE.SelectedValue.ToString().Trim();
//}
//返修结果
if (this.comMENDRESULT.SelectedValue != null && string.IsNullOrEmpty(this.comMENDRESULT.SelectedValue.ToString().Trim()) == false)
{
searchModel.MENDRESULT = this.comMENDRESULT.SelectedValue.ToString().Trim();
}
//操作开始时间
if (string.IsNullOrEmpty(this.dtpCREATEDATESTART.Text.Trim()) == false)
{
searchModel.CREATEDATESTART = Convert.ToDateTime(this.dtpCREATEDATESTART.Text).ToString("yyyy-MM-dd") + " 00:00:00";
}
//操作结束时间
if (string.IsNullOrEmpty(this.dtpCREATEDATEEND.Text.Trim()) == false)
{
searchModel.CREATEDATEEND = Convert.ToDateTime(this.dtpCREATEDATEEND.Text).ToString("yyyy-MM-dd") + " 23:59:59";
}
}
#endregion
///
/// 行序号
///
///
///
private void DG_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, this.DGMendRecorder.RowHeadersWidth - 4, e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), new Font("宋体", 12, FontStyle.Bold), rectangle, this.DGMendRecorder.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
#region 查询条件校验
///
/// 查询条件校验
///
private bool ExistSearchModel()
{
//操作开始时间
if (!string.IsNullOrEmpty(this.dtpCREATEDATESTART.Text.Trim()) && !string.IsNullOrEmpty(this.dtpCREATEDATEEND.Text.Trim()))
{
DateTime startTime = Convert.ToDateTime(this.dtpCREATEDATESTART.Text);
DateTime endTime = Convert.ToDateTime(this.dtpCREATEDATEEND.Text);
if (startTime > endTime)
{
MessageBox.Show(Resource1.DateTimeValidate, Resource1.DateTimeValidate, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
}
return true;
}
#endregion
private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
var form = new MendRecorderWasteForm();
form.ShowDialog();
SetSearchModel();
this.pager1.Init();
BindGirdData();
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
MendStaticForm form = new MendStaticForm();
form.ShowDialog();
}
}
}