天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
7.2 KiB

3 years ago
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using QMAPP.FJC.Entity.Injection;
using QMAPP.ServicesAgent;
using QMAPP.FJC.Entity.BZD;
using DCS.Common;
using QMAPP.FJC.Entity.Basic;
using QMAPP.WinForm.Common;
namespace QMAPP.WinForm.Forms.Injection
{
/// <summary>
///
/// </summary>
public partial class InjectPrintForm : Form
{
//获取服务代理
QMAPP.ServicesAgent.ServiceAgent _agent = ClientContext.GetServiceAgent();
List<BZDConfig> _bzdConfig = null;
//string txtMaterialCode = "";
//string textMaterialName = "";
//Product _CurrentProduct = null;
private InjectPasswordForm _InjectPasswordForm;
/// <summary>
///
/// </summary>
public InjectPrintForm(InjectPasswordForm InjectPasswordForm)
{
InitializeComponent();
LoadMachineList();
infolabel.Text = "";
infolabel.ForeColor = Color.Red;
_InjectPasswordForm = InjectPasswordForm;
}
#region 打印按钮
/// <summary>
/// 打印按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtProductCode.Text))
{
infolabel.Text = "请扫描或填写装配码!";
txtProductCode.Focus();
return;
}
//*****************************
_agent.InvokeServiceFunction<int>(B9IPCService.BarCodeReplacementBLL_Insert.ToString(), new BarCodeReplacement() { ProductCode = txtProductCode.Text,Type="注塑条码补打" });
Print(txtProductCode.Text,true);
txtProductCode.Text = "";
//txtMaterialCode = "";
//textMaterialName = "";
}
catch (Exception exception)
{
txtProductCode.Text = "";
MessageBox.Show("打印失败!");
throw;
}
}
#endregion
private void Print(string code, bool IsManual)
{
var MachineCode = "";
List<PrintTemplate.InjectLabel> labels = new List<PrintTemplate.InjectLabel>();
string shiftCode = ClientContext.produceShift.PRODUCESHIFTTCODE;
var selectmachine = comMachine.SelectedItem as MachineInfo;
if (selectmachine != null && !string.IsNullOrEmpty(selectmachine.PID))
{
MachineCode = selectmachine.MACHINECODDE;
}
//打印条码
string typeTem = "InjectLabel100x30";
PrintTemplate.InjectLabel label = new PrintTemplate.InjectLabel
{
CreateDate = DateTime.Now,
MachineCode = MachineCode,
MaterialCode = textMaterialName.Text.ToString(),
MaterialName = txtMaterialCode.Text.ToString(),
ModelCode = cbMould.SelectedValue.ToString(),
SerialNumber = code,
ShiftCode = shiftCode,
IsManualPrint = IsManual
};
labels.Add(label);
string path = System.Configuration.ConfigurationManager.AppSettings["Template_Local_Path"];
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
FastReport.Report fr = new FastReport.Report();
fr.RegisterData(labels, "Labels");
if (!System.IO.File.Exists(string.Format("{0}\\{1}.frx", path, typeTem)))
{
if (System.IO.File.Exists(string.Format("PrintTemplate\\{1}.frx", path, typeTem)))
{
System.IO.File.Copy(string.Format("PrintTemplate\\{1}.frx", path, typeTem)
, string.Format("{0}\\{1}.frx", path, typeTem));
}
else
{
fr.FileName = string.Format("{0}\\{1}.frx", path, typeTem);
fr.Design(true);
fr.Save(string.Format("{0}\\{1}.frx", path, typeTem));
}
}
fr.Load(string.Format("{0}\\{1}.frx", path, typeTem));
fr.Design(true);
//fr.PrintSettings.ShowDialog = false;
//fr.Print();
fr.Dispose();
//QM.Assist.PrintUtil pu = new QM.Assist.PrintUtil();
//pu.PrintLabel2(System.Configuration.ConfigurationManager.AppSettings["proPath"].ToString
// (), System.Configuration.ConfigurationManager.AppSettings[typeTem + "temPath"].ToString
// (), System.Configuration.ConfigurationManager.AppSettings[typeData + "dataPath"].ToString
// ());
}
#region 点击选择零件信息
/// <summary>
/// 点击选择零件信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnChoiceMaterial_Click(object sender, EventArgs e)
{
MaterialTreeForm materialForm = new MaterialTreeForm();
var ret = materialForm.ShowDialog();
if (ret == DialogResult.OK)
{
this.txtMaterialCode.Text = materialForm.MaterialCode;
this.textMaterialName.Text = materialForm.MaterialName;
//bool maintype = materialForm.MainType;
//if (maintype)
//{
// this.groupBox3.Enabled = true;
//}
//else
//{
// this.groupBox3.Enabled = false;
//}
}
}
#endregion
#region 加载设备列表
/// <summary>
/// 加载设备列表
/// </summary>
private void LoadMachineList()
{
#region
BasicData basicData = new BasicData();
var machinelist = basicData.GetMachineInfoAndModelList(new string[] { "1" }, true);
this.comMachine.DataSource = machinelist;
this.comMachine.DisplayMember = "MACHINENAME";
this.comMachine.ValueMember = "MACHINECODDE";
comMachine_SelectedIndexChanged(null, null);
#endregion
}
#endregion
private void comMachine_SelectedIndexChanged(object sender, EventArgs e)
{
var selectmachine = comMachine.SelectedItem as MachineInfo;
if (selectmachine != null && !string.IsNullOrEmpty(selectmachine.PID))
{
var mouldList = _agent.InvokeServiceFunction<List<MachineInfoModels>>(B9BasicService.MachineInfoModelBLL_GetAllList.ToString(), new MachineInfoModels { MID = "INJ_MODEL" });
mouldList.Insert(0, new MachineInfoModels { });
cbMould.DisplayMember = "MODELNAME";
cbMould.ValueMember = "MODELCODE";
cbMould.DataSource = mouldList;
}
}
}
}