using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.IO.Ports;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using BO;
|
|
using BO.Utils;
|
|
using BWP.WinFormControl.WeightDataFormat;
|
|
using Forks.JsonRpc.Client;
|
|
using MaterialRequisition.Model;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace MaterialRequisition
|
|
{
|
|
public partial class MaterialRequisitionForm : Form,IAfterLogin
|
|
{
|
|
|
|
public string RoleName { get { return "领料退料"; } }
|
|
public Form Generate()
|
|
{
|
|
return this;
|
|
}
|
|
private List<MaterialRequisitionGoodsSet> mSetList;
|
|
private readonly string mDropDownSetsFileName = "MaterialRequisition_DropDownSets.xml";
|
|
private DropDownSets mDropDownSets;
|
|
#region weightNeed
|
|
SerialPort weightPort;
|
|
private IDataFormat _dataFormat;
|
|
private Thread _inQueryThread;
|
|
private bool _mainProcessIsRun;
|
|
readonly StringBuilder _dataStrBuilder = new StringBuilder();
|
|
#endregion
|
|
|
|
private readonly Thread _tdSyncLocalToMiddleDb;
|
|
private readonly Thread _tcCheckNetStatus;
|
|
private readonly Thread _tcCheckSyncStatus;
|
|
public MaterialRequisitionForm()
|
|
{
|
|
InitializeComponent();
|
|
dataGridViewUnSubmit.AutoGenerateColumns = false;
|
|
dataGridViewSubmited.AutoGenerateColumns = false;
|
|
weightPort = new SerialPort();
|
|
this.FormClosing += delegate
|
|
{
|
|
if (_inQueryThread != null && _inQueryThread.IsAlive)
|
|
{
|
|
//DisableWeight();
|
|
}
|
|
if (_tdSyncLocalToMiddleDb != null && _tdSyncLocalToMiddleDb.IsAlive)
|
|
{
|
|
_tdSyncLocalToMiddleDb.Abort();
|
|
}
|
|
if (_tcCheckNetStatus != null && _tcCheckNetStatus.IsAlive)
|
|
{
|
|
_tcCheckNetStatus.Abort();
|
|
}
|
|
if (_tcCheckSyncStatus != null && _tcCheckSyncStatus.IsAlive)
|
|
{
|
|
_tcCheckSyncStatus.Abort();
|
|
}
|
|
};
|
|
|
|
InitCombox();
|
|
InitControl();
|
|
_tdSyncLocalToMiddleDb = new Thread(SyncLocalToMiddleDb);
|
|
_tdSyncLocalToMiddleDb.Start();
|
|
|
|
_tcCheckNetStatus = new Thread(CheckNetStatus);
|
|
_tcCheckNetStatus.Start();
|
|
|
|
_tcCheckSyncStatus = new Thread(CheckSyncStatus);
|
|
_tcCheckSyncStatus.Start();
|
|
|
|
}
|
|
private void CheckSyncStatus()
|
|
{
|
|
while (true)
|
|
{
|
|
var syncSuccessed = MaterialRequisitionRecordRpc.GetInstance().IsSyncSucessed();
|
|
var png = "stop.png";
|
|
if (syncSuccessed)
|
|
png = "working.png";
|
|
var imgPath = Path.Combine(Application.StartupPath, "BWP.WinFormControl.dll");
|
|
var s = Assembly.LoadFile(imgPath).GetManifestResourceStream("BWP.WinFormControl.Images." + png);
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.BeginInvoke(new Action(() =>
|
|
{
|
|
picSyncStatus.Image = Image.FromStream(s);
|
|
picSyncStatus.Refresh();
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
picSyncStatus.Image = Image.FromStream(s);
|
|
picSyncStatus.Refresh();
|
|
}
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
|
|
private bool laseConnection = false;
|
|
|
|
private void CheckNetStatus()
|
|
{
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
var newConnection = LoginRpcUtil.TestConnection(500);
|
|
if (newConnection && laseConnection)
|
|
{
|
|
Thread.Sleep(1000);
|
|
continue;
|
|
}
|
|
var png = "stop.png";
|
|
if (newConnection)
|
|
png = "working.png";
|
|
var imgPath = Path.Combine(Application.StartupPath, "BWP.WinFormControl.dll");
|
|
var s = Assembly.LoadFile(imgPath).GetManifestResourceStream("BWP.WinFormControl.Images." + png);
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.BeginInvoke(new Action(() =>
|
|
{
|
|
picNetStatus.Image = Image.FromStream(s);
|
|
picNetStatus.Refresh();
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
picNetStatus.Image = Image.FromStream(s);
|
|
picNetStatus.Refresh();
|
|
}
|
|
laseConnection = newConnection;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//LogUtil.Error(e.ToString());
|
|
}
|
|
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
|
|
private void SyncLocalToMiddleDb()
|
|
{
|
|
while (true)
|
|
{
|
|
if (laseConnection)
|
|
{
|
|
this.BeginInvoke(new Action(() =>
|
|
{
|
|
MaterialRequisitionRecordRpc.GetInstance().SyncToServer();
|
|
}));
|
|
|
|
}
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
|
|
|
|
private void InitCombox()
|
|
{
|
|
if (LoginRpcUtil.TestConnection(500))
|
|
{
|
|
mDropDownSets = GetmDropDownSets();
|
|
XmlUtil.SerializerObjToFile(mDropDownSets, mDropDownSetsFileName);
|
|
}
|
|
else
|
|
{
|
|
mDropDownSets = XmlUtil.DeserializeFromFile<DropDownSets>(mDropDownSetsFileName);
|
|
}
|
|
var shop = mDropDownSets.Details.FirstOrDefault(x => x.Name == DropDownSets.车间);
|
|
if (shop != null)
|
|
{
|
|
cbxWorkShop.DataSource = shop.Details;
|
|
cbxWorkShop.DisplayMember = "Name";
|
|
cbxWorkShop.ValueMember = "ID";
|
|
}
|
|
|
|
var unit = mDropDownSets.Details.FirstOrDefault(x => x.Name == DropDownSets.单元);
|
|
if (unit != null)
|
|
{
|
|
cbxWorkUnit.DataSource = unit.Details;
|
|
cbxWorkUnit.DisplayMember = "Name";
|
|
cbxWorkUnit.ValueMember = "ID";
|
|
}
|
|
var store = mDropDownSets.Details.FirstOrDefault(x => x.Name == DropDownSets.仓库);
|
|
if (store != null)
|
|
{
|
|
cbxStore.DataSource = store.Details;
|
|
cbxStore.DisplayMember = "Name";
|
|
cbxStore.ValueMember = "ID";
|
|
}
|
|
var batch = mDropDownSets.Details.FirstOrDefault(x => x.Name == DropDownSets.批次);
|
|
if (batch != null)
|
|
{
|
|
cbxStore.DataSource = batch.Details;
|
|
cbxStore.DisplayMember = "Name";
|
|
cbxStore.ValueMember = "ID";
|
|
}
|
|
}
|
|
|
|
private DropDownSets GetmDropDownSets()
|
|
{
|
|
var sets = new DropDownSets();
|
|
var wrokUnitSet = GetWrokUnitSet();
|
|
var wrokShopSet = GetWrokShopSet();
|
|
var storeSet = GetStoreSet();
|
|
var batchSet = GetBatchSet();
|
|
sets.Details.Add(wrokUnitSet);
|
|
sets.Details.Add(wrokShopSet);
|
|
sets.Details.Add(storeSet);
|
|
sets.Details.Add(batchSet);
|
|
return sets;
|
|
}
|
|
|
|
private DropDownSet GetWrokShopSet()
|
|
{
|
|
var json = RpcFacade.Call<string>("/MainSystem/B3ClientService/Rpcs/BaseInfoRpc/GetWorkShopList");
|
|
var set = new DropDownSet();
|
|
set.Name = DropDownSets.车间;
|
|
foreach (var detail in JsonConvert.DeserializeObject<List<DropDownSet_Detail>>(json))
|
|
{
|
|
set.Details.Add(detail);
|
|
}
|
|
return set;
|
|
}
|
|
|
|
private DropDownSet GetStoreSet()
|
|
{
|
|
var json = RpcFacade.Call<string>("/MainSystem/B3ClientService/Rpcs/BaseInfoRpc/GetStoreList");
|
|
var set = new DropDownSet();
|
|
set.Name = DropDownSets.仓库;
|
|
foreach (var detail in JsonConvert.DeserializeObject<List<DropDownSet_Detail>>(json))
|
|
{
|
|
set.Details.Add(detail);
|
|
}
|
|
return set;
|
|
}
|
|
|
|
private DropDownSet GetBatchSet()
|
|
{
|
|
var json = RpcFacade.Call<string>("/MainSystem/B3ClientService/Rpcs/BaseInfoRpc/GetProductBatchList");
|
|
var set = new DropDownSet();
|
|
set.Name = DropDownSets.批次;
|
|
foreach (var detail in JsonConvert.DeserializeObject<List<DropDownSet_Detail>>(json))
|
|
{
|
|
set.Details.Add(detail);
|
|
}
|
|
return set;
|
|
}
|
|
|
|
private DropDownSet GetWrokUnitSet()
|
|
{
|
|
var json = RpcFacade.Call<string>("/MainSystem/B3ClientService/Rpcs/BaseInfoRpc/GetWorkUnitList");
|
|
var set = new DropDownSet();
|
|
set.Name = DropDownSets.单元;
|
|
foreach (var detail in JsonConvert.DeserializeObject<List<DropDownSet_Detail>>(json))
|
|
{
|
|
set.Details.Add(detail);
|
|
}
|
|
return set;
|
|
}
|
|
|
|
private void btnGoodsSet_Click(object sender, EventArgs e)
|
|
{
|
|
var f = new GoodsSetForm();
|
|
if (f.ShowDialog() == DialogResult.OK)
|
|
{
|
|
InitControl();
|
|
}
|
|
}
|
|
|
|
private void InitControl()
|
|
{
|
|
mSetList = XmlUtil.DeserializeFromFile<List<MaterialRequisitionGoodsSet>>(GoodsSetForm.MaterialRequisitionGoodsSetFileName).Where(x => x.IsSelected).ToList();
|
|
if (mSetList.Count < 1)
|
|
{
|
|
return;
|
|
}
|
|
flpClass.Controls.Clear();
|
|
foreach (IGrouping<string, MaterialRequisitionGoodsSet> grouping in mSetList.GroupBy(x => x.Name))
|
|
{
|
|
var btnClass = CreateClassButton(grouping.Key);
|
|
flpClass.Controls.Add(btnClass);
|
|
}
|
|
}
|
|
|
|
private Button CreateClassButton(string text)
|
|
{
|
|
var btn = new Button();
|
|
btn.Text = text;
|
|
btn.Click += Btn_Click;
|
|
btn.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
btn.BackColor = SystemColors.Control;
|
|
btn.Width = 100;
|
|
btn.Height = 60;
|
|
return btn;
|
|
}
|
|
|
|
private void Btn_Click(object sender, EventArgs e)
|
|
{
|
|
var text = (sender as Button).Text;
|
|
foreach (Button cbutton in flpClass.Controls)
|
|
{
|
|
if (cbutton.Text == text)
|
|
{
|
|
cbutton.BackColor = Color.Aqua;
|
|
}
|
|
else
|
|
{
|
|
cbutton.BackColor = SystemColors.Control;
|
|
}
|
|
}
|
|
flpGoods.Controls.Clear();
|
|
foreach (MaterialRequisitionGoodsSet set in mSetList.Where(x => x.Name == text))
|
|
{
|
|
var btnGoods = CreateGoodsButton(set);
|
|
flpGoods.Controls.Add(btnGoods);
|
|
}
|
|
}
|
|
|
|
private Button CreateGoodsButton(MaterialRequisitionGoodsSet set)
|
|
{
|
|
var btn = new Button();
|
|
btn.Text = set.Goods_Name;
|
|
btn.Tag = set;
|
|
btn.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
//btn.Click += BtnGoods_Click;
|
|
btn.BackColor = SystemColors.Control;
|
|
btn.Width = 140;
|
|
btn.Height = 80;
|
|
return btn;
|
|
}
|
|
}
|
|
}
|