天津投入产出系统后端
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.

496 lines
19 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity.Operation;
using QMAPP.ServicesAgent;
using QMAPP.MD.Entity;
using QMAPP.Entity;
using QMFrameWork.Data;
using System.Configuration;
namespace QMAPP.WinForm.Forms.Operation
{
public partial class PrintPlanLabel : Form
{
QMAPP.ServicesAgent.ServiceAgent _agent = ClientContext.GetServiceAgent();
List<QMAPP.FJC.Entity.Basic.ProcessRoute> cbsource = null;
/// <summary>
///
/// </summary>
public PrintPlanLabel()
{
InitializeComponent();
}
/// <summary>
/// 加载工艺路线
/// </summary>
private void LoadProcessRoute()
{
var routes = _agent.InvokeServiceFunction<DataResult<List<QMAPP.FJC.Entity.Basic.ProcessRoute>>>
("ProcessRouteBLL_GetProcessRouteList", new QMAPP.FJC.Entity.Basic.ProcessRoute { }).Result;
routes = routes.OrderBy(p => p.ROUTE_CODE).ToList();
cbsource = routes;
cbsource.Insert(0, new QMAPP.FJC.Entity.Basic.ProcessRoute { ROUTE_NAME = "", ROUTE_CODE = "" });
cbRoutes.DisplayMember = "ROUTE_NAME";
cbRoutes.ValueMember = "ROUTE_CODE";
cbRoutes.DataSource = cbsource;
}
#region 加载列表显示设置
/// <summary>
/// 加载列表显示设置
/// </summary>
private void LoadViewSetting()
{
#region 加载列表显示设置
string filepath = ConfigurationManager.AppSettings["SaveFilePath"];
filepath = string.Format("{0}ViewSetting.cfg", filepath);
var setting = new { ListRowcount = 20, RefreshRate = 5 };
if (System.IO.File.Exists(filepath))
{
string settingstring = System.IO.File.ReadAllText(filepath);
setting = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(settingstring, setting);
}
cbListRowcount.Text = setting.ListRowcount.ToString();
cbRefreshRate.Text = string.Format("{0}s", setting.RefreshRate);
cbPlanFilter.SelectedIndex = 1;
cbListRowcount.SelectedIndexChanged += new EventHandler(cbListRowcount_SelectedIndexChanged);
cbRefreshRate.SelectedIndexChanged += new EventHandler(cbRefreshRate_SelectedIndexChanged);
cbPlanFilter.TextChanged += new EventHandler(cbPlanFilter_SelectedIndexChanged);
#endregion
}
#endregion
#region 列表定时刷新
private void cbListRowcount_SelectedIndexChanged(object sender, EventArgs e)
{
SaveSetting();
BindPlanView();
}
/// <summary>
/// 发送指令或者接受完成指令刷新列表
/// </summary>
public void BindPlanView()
{
#region 刷新生产计划
dgvPlan.AutoGenerateColumns = false;
this.dgvPlan.DataSource = new List<FJC.Entity.ProductionPlan.WorkOrder>();
try
{
DataPage dataPage = new DataPage();
dataPage.PageSize = int.Parse(cbListRowcount.Text);
dataPage.PageIndex = 1;
dataPage.SortExpression = " ROWVALUE ASC";
#region 服务查询
var orderlist = _agent.InvokeServiceFunction<List<FJC.Entity.ProductionPlan.WorkOrder>>("WorkOrderBLL_GetOrderUnPrinted", cbRoutes.SelectedValue.ToString(), cbPlanFilter.SelectedIndex, dataPage);
#endregion
this.dgvPlan.DataSource = orderlist;
}
catch (Exception ex)
{
WriteLog.WriteError(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + ex.Message);
}
finally
{
timecounter = 0;
}
#endregion
}
private void cbRefreshRate_SelectedIndexChanged(object sender, EventArgs e)
{
SaveSetting();
}
private void cbPlanFilter_SelectedIndexChanged(object sender, EventArgs e)
{
BindPlanView();
SaveSetting();
}
private void SaveSetting()
{
string filepath = ConfigurationManager.AppSettings["SaveFilePath"];
filepath = string.Format("{0}ViewSetting.cfg", filepath);
var setting = new
{
ListRowcount = int.Parse(cbListRowcount.Text),
RefreshRate = int.Parse(cbRefreshRate.Text.Trim('s')),
//PlanFilter = cbPlanFilter.SelectedIndex
};
string settingstring = Newtonsoft.Json.JsonConvert.SerializeObject(setting);
System.IO.File.WriteAllText(filepath, settingstring);
}
int timecounter = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (!tsbOrderOperation.DropDown.Visible)
{
timecounter += 1;
if (timecounter > int.Parse(cbRefreshRate.Text.Trim('s')))//计时达到刷新时间
{
BindPlanView();
}
}
}
#endregion
private void PrintLabel(List<LabelData> labeldata)
{
#region 计划标签打印
//string xmlPath = System.Configuration.ConfigurationSettings.AppSettings["XmlName"].ToString(); ;
//BarcodeLib.BarCodeGenerate g = new BarcodeLib.BarCodeGenerate( xmlPath);
//bool b = g.PrintBarCode(_operationServiceParam.main.MAINCODE);
QM.Assist.LabelInfo ll = new QM.Assist.LabelInfo();
StringBuilder dataline=new StringBuilder();
foreach (var label in labeldata)
{
string[] texts = new string[6];
var sourcetext = label.Description.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < texts.Length && i < sourcetext.Length; i++)
{
texts[i] = sourcetext[i];
}
//OrderNo,OrderType,PlanDate,Name,Class,CarModel,Text1,Text2,Text3,Text4,Text5,Text6
dataline.AppendFormat("\"{0}\",\"{1}\",\"{2:yyyy-MM-dd HH:mm:ss}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\",\"{9}\",\"{10}\",\"{11}\"\r\n",
label.OrderNo,//计划号
label.OrderType,//计划类型(0:FIS,1:STOCK,2:INSERT)
label.PlanDate,//计划日期
label.MaterialName,//总成物料名称
label.Class,//
label.CarModel,//车型
texts[0],//装配详细信息
texts[1],//装配详细信息
texts[2],//装配详细信息
texts[3],//装配详细信息
texts[4],//装配详细信息
texts[5]//装配详细信息
);
}
ll.BarCode=dataline.ToString().TrimEnd('\r','\n');
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["PlanLabelTMPPath"].ToString
(), System.Configuration.ConfigurationManager.AppSettings["PlanLabelDATPath"].ToString
());
#endregion
}
private void PrintPlanLabel_Load(object sender, EventArgs e)
{
LoadViewSetting();
LoadProcessRoute();
//如果工位已设定
if (ClientContext.MachineInfo != null && !string.IsNullOrEmpty(ClientContext.MachineInfo.PID))
{
//this.comMachine.SelectedValue = ClientContext.MachineInfo.MACHINECODDE;
var route = _agent.InvokeServiceFunction<QMAPP.FJC.Entity.Basic.ProcessRoute>
("ProcessRouteBLL_GetRouteByMachine", ClientContext.MachineInfo.MACHINECODDE);
if (route != null)
{
this.cbRoutes.SelectedValue = route.ROUTE_CODE;
this.cbRoutes.Enabled = false;
}
else
{
this.cbRoutes.Enabled = true;
}
}
else
{
this.cbRoutes.Enabled = true;
}
BindPlanView();
cbRoutes.SelectedIndexChanged += new EventHandler(cbRoutes_SelectedIndexChanged);
}
void cbRoutes_SelectedIndexChanged(object sender, EventArgs e)
{
BindPlanView();
}
#region 工单操作
#region 取消挂起
/// <summary>
/// 取消挂起
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiCancelSuspend_Click(object sender, EventArgs e)
{
if (dgvPlan.SelectedRows.Count <= 0)
{
MessageBox.Show("请选择一条工单进行取消挂起操作!");
return;
}
List<string> ids = new List<string>();
foreach (System.Windows.Forms.DataGridViewRow row in dgvPlan.SelectedRows)
{
var order = (QMAPP.FJC.Entity.ProductionPlan.WorkOrder)row.DataBoundItem;
if (!int.Equals(order.STATE, 4))
{
MessageBox.Show("只可取消状态为挂起的工单!");
return;
}
ids.Add(order.PID);
}
_agent.InvokeServiceFunction<int>(B9IPCService.WorkOrderBLL_CancelSuspend.ToString(), ids);
BindPlanView();
}
#endregion
#region 删除工单
/// <summary>
/// 删除工单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiDeleteOrder_Click(object sender, EventArgs e)
{
if (dgvPlan.SelectedRows.Count <= 0)
{
MessageBox.Show("请选择一条工单进行删除操作!");
return;
}
List<string> ids = new List<string>();
foreach (System.Windows.Forms.DataGridViewRow row in dgvPlan.SelectedRows)
{
var order = (QMAPP.FJC.Entity.ProductionPlan.WorkOrder)row.DataBoundItem;
if (!int.Equals(order.STATE, 4))
{
MessageBox.Show("只可删除状态为挂起的工单!");
return;
}
ids.Add(order.PID);
}
_agent.InvokeServiceFunction<int>(B9IPCService.WorkOrderBLL_DeleteOrder.ToString(), ids);
BindPlanView();
}
#endregion
#region 重置工单
/// <summary>
/// 重置工单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiResetOrder_Click(object sender, EventArgs e)
{
if (dgvPlan.SelectedRows.Count <= 0)
{
MessageBox.Show("请选择一条工单进行重置操作!");
return;
}
List<string> ids = new List<string>();
foreach (System.Windows.Forms.DataGridViewRow row in dgvPlan.SelectedRows)
{
var order = (QMAPP.FJC.Entity.ProductionPlan.WorkOrder)row.DataBoundItem;
if (!int.Equals(order.STATE, 4))
{
MessageBox.Show("只可重置状态为挂起的工单!");
return;
}
ids.Add(order.PID);
}
_agent.InvokeServiceFunction<int>(B9IPCService.WorkOrderBLL_ResetOrder.ToString(), ids);
BindPlanView();
}
#endregion
#region 挂起工单
/// <summary>
/// 挂起工单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiSuspendOrder_Click(object sender, EventArgs e)
{
if (dgvPlan.SelectedRows.Count <= 0)
{
MessageBox.Show("请选择一条工单进行挂起操作!");
return;
}
List<string> ids = new List<string>();
foreach (System.Windows.Forms.DataGridViewRow row in dgvPlan.SelectedRows)
{
var order = (QMAPP.FJC.Entity.ProductionPlan.WorkOrder)row.DataBoundItem;
if (int.Equals(order.STATE, 2))
{
MessageBox.Show("不能挂起正在执行的工单!");
return;
}
ids.Add(order.PID);
}
_agent.InvokeServiceFunction<int>(B9IPCService.WorkOrderBLL_SuspendOrder.ToString(), ids);
BindPlanView();
}
#endregion
#region 回收工单
/// <summary>
/// 回收工单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiTakebackOrder_Click(object sender, EventArgs e)
{
if (dgvPlan.SelectedRows.Count <= 0)
{
MessageBox.Show("请选择一条工单进行回收操作!");
return;
}
List<string> ids = new List<string>();
foreach (System.Windows.Forms.DataGridViewRow row in dgvPlan.SelectedRows)
{
var order = (QMAPP.FJC.Entity.ProductionPlan.WorkOrder)row.DataBoundItem;
if (!int.Equals(order.STATE, 4))
{
MessageBox.Show("只可回收状态为挂起的工单!");
return;
}
ids.Add(order.PID);
}
_agent.InvokeServiceFunction<int>(B9IPCService.WorkOrderBLL_TakeBack.ToString(), ids);
BindPlanView();
}
#endregion
#endregion
#region 工单列表选择发送变化时延时自动刷新
/// <summary>
/// 工单列表选择发送变化时延时自动刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgvPlan_SelectionChanged(object sender, EventArgs e)
{
timecounter = -10;
}
#endregion
#region 设置计划工单列状态、颜色
/// <summary>
/// 设置计划工单列状态、颜色
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgvPlan_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
var WORKORDER_STATE_TEXT = new string[] { "初始", "确认", "执行中", "完成", "挂起" };
var row = dgvPlan.Rows[e.RowIndex];
var order = (FJC.Entity.ProductionPlan.WorkOrder)row.DataBoundItem;
if (order.STATE >= 0 && order.STATE < WORKORDER_STATE_TEXT.Length)
{
row.Cells[dgcState.Name].Value = WORKORDER_STATE_TEXT[order.STATE];
}
if (order.STATE == FJC.Entity.EnumGeter.WorkOrderState.Suspended.GetHashCode())
{
row.DefaultCellStyle.BackColor = Color.LightGray;
row.DefaultCellStyle.ForeColor = Color.Gray;
}
if (order.STATE == FJC.Entity.EnumGeter.WorkOrderState.Executing.GetHashCode())
{
row.DefaultCellStyle.BackColor = Color.YellowGreen;
dgvPlan.ClearSelection();
}
}
#endregion
private void tsbPrint_Click(object sender, EventArgs e)
{
if (dgvPlan.Rows.Count == 0)
{
MessageBox.Show("当前生产线没有未打印标签的计划工单!");
}
tsbPrint.Enabled = false;
var order1 = (FJC.Entity.ProductionPlan.WorkOrder)dgvPlan.Rows[0].DataBoundItem;
var order2 = new FJC.Entity.ProductionPlan.WorkOrder();
if (dgvPlan.Rows.Count > 1)
{
order2 = (FJC.Entity.ProductionPlan.WorkOrder)dgvPlan.Rows[1].DataBoundItem;
}
var orders = new List<FJC.Entity.ProductionPlan.WorkOrder>();
orders.Add(order1);
if (string.Equals(order1.SEQ, order2.SEQ))
{
orders.Add(order2);
}
List<LabelData> labels = new List<LabelData>();
foreach (var order in orders)
{
var codematch = System.Text.RegularExpressions.Regex.Match(order.PBOM_CODE, "_[LR][FR]_");
string positioncode = codematch.Success ? codematch.Value.Trim('_') : "";
var book = _agent.InvokeServiceFunction<FJC.Entity.FIS.FISPhraseBook>("FISPhraseBLL_GetFisPhraseBook", order.MATERIAL_CODE + "", positioncode);
LabelData labeldata = new LabelData();
labeldata.OrderNo = order.ORDERPLAN_NO;
labeldata.PlanDate = order.PLAN_DATE;
if (book != null)
{
labeldata.Class = " " + book.Class.Substring(0, 2);
labeldata.Description = book.Text;
}
var mcresult = _agent.InvokeServiceFunction<DataResult<Material>>("MaterialBLL_Get", new Material { MATERIAL_CODE = order.MATERIAL_CODE });
var material = mcresult.IsSuccess ? mcresult.Result : null;
if (material != null)
{
labeldata.MaterialName = material.MATERIAL_SHORT;
labeldata.CarModel = material.PROJECTCODE;
}
labels.Add(labeldata);
}
PrintLabel(labels);
foreach (var order in orders)
{
var ret = _agent.InvokeServiceFunction<int>("WorkOrderBLL_SetOrderPrinted", order.PID);
//ret = _agent.InvokeServiceFunction<int>("WorkOrderBLL_SetOrderPrinted", order1.PID);
}
BindPlanView();
tsbPrint.Enabled = true;
}
}
class LabelData
{
public string OrderNo { get; set; }
public DateTime PlanDate { get; set; }
public string Class { get; set; }
public string Description { get; set; }
public string MaterialName { get; set; }
public string CarModel { get; set; }
public object[] OrderType { get; set; }
}
}