using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Windows.Forms;
using QMAPP.FJC.Entity;
using QMAPP.FJC.Entity.Operation;
using QMAPP.ServicesAgent;
using QMAPP.WinForm.Common;
using QMFrameWork.Common.Serialization;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Basic;
using QM.Common;
using QMAPP.Entity;
using QMAPP.WinForm.Forms.Operation;
namespace QMAPP.WinForm.Forms.Injection
{
///
/// 模块编号:M12-3
/// 作 用:注塑打包
/// 作 者:王庆男
/// 编写日期:2015年06月11日
///
public partial class ProductBundleForm : Form
{
Product product = new Product();//编辑保存
Product searchModel = new Product();//查询条件
public ProductBundleForm()
{
InitializeComponent();
}
#region 窗体载入
private void Form_Load(object sender, EventArgs e)
{
#region 绑定下拉列表
BasicData basicData = new BasicData();
//初始化控件属性
this.DGView.AutoGenerateColumns = false;
//加载注塑设备列表
this.comMachineCode.DataSource = basicData.GetMachineInfoList(new string[] { EnumGeter.ProcessType_M.Injection.GetHashCode().ToString() }, true);
this.comMachineCode.DisplayMember = "MACHINENAME";
this.comMachineCode.ValueMember = "MACHINECODDE";
//加载操作人列表
this.comOperator.DataSource = basicData.GetOperatorInfoList(EnumGeter.MACHINETYPE.zhusu.GetHashCode().ToString(), true); ;
this.comOperator.DisplayMember = "OPERATOR";
this.comOperator.ValueMember = "OPERATORCODE";
//产品类型
ProductBasic searchModelList = new ProductBasic();
searchModelList.PRODUCTMAINTYPE = EnumGeter.PRODUCTMAINTYPE.zhusu.GetHashCode().ToString();
searchModelList.PRODUCTUNIT = EnumGeter.PRODUCTUNIT.SET.GetHashCode().ToString();
searchModelList.PRODUCTSOURCE = EnumGeter.PRODUCTSOURCE.SELFMADE.GetHashCode().ToString();
this.comProType.DataSource = basicData.GetProductBasicList(searchModelList, true);
this.comProType.DisplayMember = "PRODUCTNAME";
this.comProType.ValueMember = "PRODUCTTYPE";
this.comProTypeB.DataSource = basicData.GetProductBasicList(searchModelList, true);
this.comProTypeB.DisplayMember = "PRODUCTNAME";
this.comProTypeB.ValueMember = "PRODUCTTYPE";
#endregion
//初始化分页
this.pager1.Init();
//加载默认查询条件
SetSearchModel();
BindGirdData();
#region 打印模板拷贝
PrintTempleCopyClass printClass = new PrintTempleCopyClass();
printClass.CopyPrintTemple("ProductBundleForm");
#endregion
}
#endregion
#region 绑定数据
private DataPage BindGirdData()
{
List recorders = null;//查询结果列表
DataPage dataPage = new DataPage();
//获取前台分页设置信息
dataPage = pager1.DataPage;
try
{
#region 服务查询
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
dataPage = agent.InvokeServiceFunction(B9BasicService.ProductBLL_GetList.ToString(), searchModel, dataPage);
recorders = JsonConvertHelper.GetDeserialize>(dataPage.Result.ToString());
#endregion
this.DGView.DataSource = recorders;
this.pager1.DataPage = dataPage;
}
catch (Exception ex)
{
throw ex;
}
return dataPage;
}
#endregion
///
/// 分页事件
///
///
///
private DataPage pager1_EventPaging(Controls.EventPagingArg e)
{
return BindGirdData();
}
///
/// 查询事件
///
///
///
private void tsbSearch_Click(object sender, EventArgs e)
{
SetSearchModel();
this.pager1.Init();
BindGirdData();
}
///
/// 设置查询条件
///
private void SetSearchModel()
{
searchModel = new Product();
searchModel.PRODUCTTYPES = string.Join(",", new int[] { EnumGeter.ProductType.kaiguanzhijia.GetHashCode() });//设置零件条码表的零件类别
//操作人
if (this.comOperator.SelectedValue != null && string.IsNullOrEmpty(this.comOperator.SelectedValue.ToString().Trim()) == false)
{
searchModel.MACHINECODDE = this.comOperator.SelectedValue.ToString().Trim();
}
//条码
if (string.IsNullOrEmpty(this.txtProductCode.Text.Trim()) == false)
{
searchModel.PRODUCTCODE = this.txtProductCode.Text.Trim();
}
//零件类别
if (this.comProTypeB.SelectedValue != null && string.IsNullOrEmpty(this.comProTypeB.SelectedValue.ToString()) == false)
{
searchModel.PRODUCTTYPE = this.comProTypeB.SelectedValue.ToString();
}
}
///
/// 行序号
///
///
///
private void DG_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, this.DGView.RowHeadersWidth - 4, e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), new Font("宋体", 12, FontStyle.Bold), rectangle, this.DGView.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
///
/// 零件类别联动事件
///
///
///
private void comProType_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.comProType.SelectedValue !=null && !string.IsNullOrEmpty(this.comProType.SelectedValue.ToString()))
{
ProductBasic basic = this.comProType.SelectedItem as ProductBasic;
this.lblCount.Text = basic.CAPATITY.ToString();
this.txtCount.Text = basic.CAPATITY.ToString();
}
}
///
/// 打包
///
///
///
private void tsbAdd_Click(object sender, EventArgs e)
{
//窗体数据校验
string errorMessae = ErrorCheck();
if (errorMessae != "")
{
MessageBox.Show(errorMessae, Resource1.ConfirmTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
#region 加载保存信息
ProductBasic basic = this.comProType.SelectedItem as ProductBasic;
MachineInfo machine = this.comMachineCode.SelectedItem as MachineInfo;
string proCode = "";
if (basic.PRODUCTTYPE.Equals(EnumGeter.ProductType.gujia.GetHashCode().ToString()))
{
proCode = "B9A";
product.CURRENTPROCESS = EnumGeter.ProcessType.huoyanjiagong.GetHashCode().ToString();//需要读取该类别最后的一道工序
}
else if (basic.PRODUCTTYPE.Equals(EnumGeter.ProductType.qinangzhijia.GetHashCode().ToString()))
{
proCode = "FJC";
product.CURRENTPROCESS = EnumGeter.ProcessType.hongwaihanjie.GetHashCode().ToString();//需要读取该类别最后的一道工序
}
else if (basic.PRODUCTTYPE.Equals(EnumGeter.ProductType.fengdao.GetHashCode().ToString()))
{
proCode = "B9B";
product.CURRENTPROCESS = EnumGeter.ProcessType.maojie.GetHashCode().ToString();//需要读取该类别最后的一道工序
}
else if (basic.PRODUCTTYPE.Equals(EnumGeter.ProductType.HUDfengdao.GetHashCode().ToString()))
{
proCode = "B9C";
product.CURRENTPROCESS = EnumGeter.ProcessType.zongchengzhuangpei.GetHashCode().ToString();//需要读取该类别最后的一道工序
}
else if (basic.PRODUCTTYPE.Equals(EnumGeter.ProductType.kaiguanzhijia.GetHashCode().ToString()))
{
proCode = "B9G";
product.CURRENTPROCESS = EnumGeter.ProcessType.chaoshengbohanjie.GetHashCode().ToString();//需要读取该类别最后的一道工序
}
//if (basic.PRODUCTTYPE.Equals(EnumGeter.ProductType.qinangzhijia.GetHashCode().ToString()))
//{
// proCode += Convert.ToDateTime(DateTime.Now).ToString("yyMMddHHmmss");
// proCode += ClientContext.LoginInfo.EmployeeNo;
// proCode += machine.MACHINENUM;
// proCode += Convert.ToDateTime(DateTime.Now).ToString("ff"); ;//获取流水已经精确到秒了还要流水?
//}
//else
//{
// proCode += Convert.ToDateTime(DateTime.Now).ToString("yyMMddHHmm");
// proCode += machine.MACHINENUM;
// proCode += ClientContext.LoginInfo.EmployeeNo;
// proCode += Convert.ToDateTime(DateTime.Now).ToString("ssff"); ;//获取流水已经精确到秒了还要流水?
//}
proCode += "0";//供应商码
proCode += DateTime.Now.ToString("yyMMddHHmmss");//年月日小时分钟秒
proCode += ClientContext.produceShift.PRODUCESHIFTTCODE;//班次
proCode += "24A";//颜色代码
proCode += "01";//操作者代码
product.PRODUCTTYPE = basic.PRODUCTTYPE;
product.PRODUCTSOURCE = EnumGeter.PRODUCTSOURCE.SELFMADE.GetHashCode().ToString();
product.PRODUCTCODE = proCode;//需要生成条码
//骨架注塑条码规则,列如条码号B9A14081403301664950,其中B9A表示骨架注塑,140814表示日期,0330表示时间精确到秒,1表示机器号,66表示操作员号,4950表示流水号。
//气囊支架注塑条码规则,列如条码号B9D14081403301664950,其中B9D表示气囊支架注塑,140814表示日期,0330表示时间精确到秒,1表示机器号,66表示操作员号,4950表示流水号。
//开关支架包装盒条码规则:例如2015060908012511,其中2015表示年,06表示月,09表示日期,08表示小时,01表示分钟,25表示秒,11表示操作者号。
//风道注塑条码规则,例如条码号B9B14081403301664950,其中B9B表示风道注塑,140814表示日期,0330表示时间精确到分钟,1表示机器号,66表示操作员号,4950表示流水号。
//HUD风道注塑条码规则,例如条码号B9C14081403301664950,其中B9C表示HUD风道注塑,140814表示日期,0330表示时间精确到分钟,1表示机器号,66表示操作员号,4950表示流水号。
MachineInfo machineInfo = this.comMachineCode.SelectedItem as MachineInfo;
product.MACHINECODDE = machineInfo.MACHINECODDE;
product.MACHINENAME = machineInfo.MACHINENAME;
product.PRODUCESHIFTNAME = ClientContext.produceShift.PRODUCESHIFTNAME;//班组
product.PRODUCESHIFTTCODE = ClientContext.produceShift.PRODUCESHIFTTCODE;//班组
product.PRODUCTTYPE = basic.PRODUCTTYPE;
product.STATUS = EnumGeter.PRODUCTSTAUTS.QUALIFIED.GetHashCode().ToString();
product.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString();
product.OUTFLAG = EnumGeter.PRODUCTOUTFLAG.INLIBRARY.GetHashCode().ToString();
product.USINGSTATE = EnumGeter.PRODUCTUSESTATE.UNUSED.GetHashCode().ToString();
product.CAPACITY = Convert.ToInt32(this.txtCount.Text);
product.USINGCOUNT = 0;
#endregion
#region 保存
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
DataResult result;//判断是否成功
if (string.IsNullOrEmpty(product.PID) == true)
{
result = agent.InvokeServiceFunction>(B9BasicService.ProductBLL_InsertForBundle.ToString(), product);
}
else
{
result = agent.InvokeServiceFunction>(B9BasicService.ProductBLL_Update.ToString(), product);
}
//保存成功
if (result.IsSuccess)
{
QM.Assist.LabelInfo ll = new QM.Assist.LabelInfo();
ll.BarCode = proCode + ",*" + proCode + "*";
QM.Assist.PrintUtil.LabelList2.Add(ll);
QM.Assist.PrintUtil pu = new QM.Assist.PrintUtil();
pu.PrintLabel2(System.Configuration.ConfigurationManager.AppSettings["proPath"].ToString
(), System.Configuration.ConfigurationManager.AppSettings[basic.PRODUCTTYPE + "temPath"].ToString
(), System.Configuration.ConfigurationManager.AppSettings[basic.PRODUCTTYPE + "dataPath"].ToString
());
product = new Product();
SetSearchModel();
this.pager1.Init();
BindGirdData();
}
else
{
MessageBox.Show(result.Msg);
}
#endregion
}
///
/// 编辑
///
///
///
private void tsbEdit_Click(object sender, EventArgs e)
{
if (this.DGView.SelectedRows.Count > 0)
{
//获取ID
string selectKey = this.DGView.SelectedRows[0].Cells["Pid"].Value.ToString();
Product searchModel = new Product();
searchModel.PID = selectKey;
//获取实体
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
product = agent.InvokeServiceFunction(B9BasicService.ProductBLL_Get.ToString(), searchModel);
//显示到界面
this.comProType.SelectedValue = product.PRODUCTTYPE;
this.txtCount.Text = product.CAPACITY.ToString();
}
}
///
/// 删除
///
///
///
private void tsbDelete_Click(object sender, EventArgs e)
{
if (this.DGView.SelectedRows.Count <= 0)
return;
if (MessageBox.Show(Resource1.ConfirmDelete, Resource1.ConfirmTitle, MessageBoxButtons.OKCancel) != DialogResult.OK)
return;
#region 删除
string selectKey = this.DGView.SelectedRows[0].Cells["Pid"].Value.ToString();
//删除校验判断该投料批次号是否已经生产出产品,如果已生产出产品则不允许删除,如果不允许则弹出提示'该批次号物料已使用,不能删除!'
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
DataResult result = agent.InvokeServiceFunction>(B9BasicService.ProductBLL_Delete.ToString(), selectKey);
MessageBox.Show(result.Msg);
if (result.IsSuccess)
{
BindGirdData();
}
#endregion
}
///
///错误检测
///
///
private string ErrorCheck()
{
#region
string strMessage = "";
//设备
if (this.comProType.SelectedValue == null || this.comProType.SelectedValue == string.Empty)
{
strMessage += Resource1.ProductTypeNullValidate + "\r\n";
}
//重量
if (this.txtCount.Text == string.Empty)
{
strMessage += Resource1.NumNullValidate + "\r\n";
}
else
{
if (SysValidate.IsInt(txtCount.Text.Trim()) == false)
{
strMessage += Resource1.NumFormatValidate + "\r\n";
}
}
return strMessage;
#endregion
}
private void tsbPrint_Click(object sender, EventArgs e)
{
if (this.DGView.SelectedRows.Count <= 0)
return;
string barCode = this.DGView.SelectedRows[0].Cells["PRODUCTCODE"].Value.ToString(); ;
string type = this.DGView.SelectedRows[0].Cells["PRODUCTTYPE"].Value.ToString();
//string xmlPath = @"D:/项目文件夹/FJC_CC_B9/truck/B9/ServicesCenter/WCF/EQUIPINTERFACETEST/Biaopi.xml";
//BarcodeLib.BarCodeGenerate generate = new BarcodeLib.BarCodeGenerate();
//generate.PrintBarCode(barCode, xmlPath);
QM.Assist.LabelInfo ll = new QM.Assist.LabelInfo();
ll.BarCode = barCode + ",*" + barCode + "*";
QM.Assist.PrintUtil.LabelList2.Add(ll);
QM.Assist.PrintUtil pu = new QM.Assist.PrintUtil();
pu.PrintLabel2(System.Configuration.ConfigurationManager.AppSettings["proPath"].ToString
(), System.Configuration.ConfigurationManager.AppSettings[type +"temPath"].ToString
(), System.Configuration.ConfigurationManager.AppSettings[type +"dataPath"].ToString
());
}
}
}