Browse Source

老版本 ,副产品

master
Robin_PC\robin 1 day ago
parent
commit
85c6bafa12
1 changed files with 63 additions and 23 deletions
  1. +63
    -23
      ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs

+ 63
- 23
ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs View File

@ -48,18 +48,34 @@ namespace ButcherFactory.SegmentProductionAuto_
List<GoodsIdentify> identityList; List<GoodsIdentify> identityList;
List<string> specialGoodsCodes; List<string> specialGoodsCodes;
// 优雅关闭标记
private bool _isFormClosing = false; private bool _isFormClosing = false;
public WeightDetails mCache; public WeightDetails mCache;
public Dictionary<long, List<decimal>> wDic = new Dictionary<long, List<decimal>>(); public Dictionary<long, List<decimal>> wDic = new Dictionary<long, List<decimal>>();
// -----------------------------------------------------
// 类内新增字段
private System.Windows.Forms.Timer _msgClearTimer;
// 构造函数里面加初始化
public SegmentProductionAutoForm() public SegmentProductionAutoForm()
{ {
InitializeComponent(); InitializeComponent();
butcherDateBox.Text = butcherDate.ToString("yyyy-MM-dd"); butcherDateBox.Text = butcherDate.ToString("yyyy-MM-dd");
netStateWatch1.GetConnectState = () => LoginUtil.TestConnection(500); netStateWatch1.GetConnectState = () => LoginUtil.TestConnection(500);
this.FormClosing += SegmentProductionAutoForm_FormClosing; this.FormClosing += SegmentProductionAutoForm_FormClosing;
// 消息自动清除定时器,先实例化,不启动
_msgClearTimer = new System.Windows.Forms.Timer();
_msgClearTimer.Interval = 5000;
_msgClearTimer.Tick += (s, e) =>
{
if (IsDisposed) return;
msglbl.Text = string.Empty;
_msgClearTimer.Stop();
};
workUnitSelect.SelectedIndexChanged += delegate workUnitSelect.SelectedIndexChanged += delegate
{ {
if (workUnitSelect.SelectedValue == null) if (workUnitSelect.SelectedValue == null)
@ -84,22 +100,44 @@ namespace ButcherFactory.SegmentProductionAuto_
}; };
} }
// 新增方法:显示错误,5秒自动清空
private void ShowErrorMsg(string msg)
{
if (IsDisposed) return;
this.Invoke(new Action(() =>
{
if (IsDisposed) return;
msglbl.Text = "ERROR:" + msg;
_msgClearTimer.Stop();
_msgClearTimer.Start();
}));
}
// FormClosing 里面释放定时器
void SegmentProductionAutoForm_FormClosing(object sender, FormClosingEventArgs e) void SegmentProductionAutoForm_FormClosing(object sender, FormClosingEventArgs e)
{ {
_isFormClosing = true; _isFormClosing = true;
// 等待线程自行退出,不再Abort
// 释放消息定时器
if (_msgClearTimer != null)
{
_msgClearTimer.Stop();
_msgClearTimer.Dispose();
}
if (initTask != null && initTask.IsAlive) if (initTask != null && initTask.IsAlive)
initTask.Join(1000);
initTask.Join(1500);
if (uploadData != null && uploadData.IsAlive) if (uploadData != null && uploadData.IsAlive)
uploadData.Join(1000);
uploadData.Join(1500);
if (checkInStoreState != null && checkInStoreState.IsAlive) if (checkInStoreState != null && checkInStoreState.IsAlive)
checkInStoreState.Join(1000);
checkInStoreState.Join(1500);
if (Utils.mPortOpened) if (Utils.mPortOpened)
closePort(); closePort();
} }
// -----------------------------------------------------------
protected override void OnLoad(EventArgs e) protected override void OnLoad(EventArgs e)
{ {
base.OnLoad(e); base.OnLoad(e);
@ -153,7 +191,7 @@ namespace ButcherFactory.SegmentProductionAuto_
{ {
while (!ok) while (!ok)
{ {
if (_isFormClosing) return;
if (_isFormClosing || IsDisposed) return;
try try
{ {
var changed = BaseInfoSyncRpc.SyncGoodsByTag(ApplyClient.分割品); var changed = BaseInfoSyncRpc.SyncGoodsByTag(ApplyClient.分割品);
@ -164,17 +202,18 @@ namespace ButcherFactory.SegmentProductionAuto_
if (changed || !bind) if (changed || !bind)
BindBasicInfo(); BindBasicInfo();
if (!IsDisposed && !Disposing)
if (!IsDisposed)
{ {
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
if (IsDisposed) return;
msglbl.Text = string.Empty; msglbl.Text = string.Empty;
})); }));
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
if (_isFormClosing) return;
if (_isFormClosing || IsDisposed) return;
if (!bind) if (!bind)
{ {
BindBasicInfo(); BindBasicInfo();
@ -182,11 +221,12 @@ namespace ButcherFactory.SegmentProductionAuto_
} }
var msg = ex.Message ?? string.Empty; var msg = ex.Message ?? string.Empty;
if (!IsDisposed && !Disposing)
if (!IsDisposed)
{ {
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
msglbl.Text = "ERROR:" + msg;
if (IsDisposed) return;
ShowErrorMsg(msg);
})); }));
} }
LogUtil.WriteErrorFile(msg, "分割品车间称重计数"); LogUtil.WriteErrorFile(msg, "分割品车间称重计数");
@ -200,7 +240,7 @@ namespace ButcherFactory.SegmentProductionAuto_
if (_isFormClosing || IsDisposed) return; if (_isFormClosing || IsDisposed) return;
this.BeginInvoke(new Action(() => this.BeginInvoke(new Action(() =>
{ {
if (IsDisposed || Disposing) return;
if (IsDisposed) return;
productBatchSelect.EBindComboBox<ProductBatch>(null, 6, "Date"); productBatchSelect.EBindComboBox<ProductBatch>(null, 6, "Date");
config = XmlUtil.DeserializeFromFile<NotAuto.SegmentProductionFormConfig>(); config = XmlUtil.DeserializeFromFile<NotAuto.SegmentProductionFormConfig>();
var m = config.WorkUnitID; var m = config.WorkUnitID;
@ -607,11 +647,11 @@ namespace ButcherFactory.SegmentProductionAuto_
if (_isFormClosing || IsDisposed) return; if (_isFormClosing || IsDisposed) return;
var entity = obj as SegmentProduction; var entity = obj as SegmentProduction;
var list = SegmentProductionBL.GetProductTask(batchDate ?? DateTime.Today, entity); var list = SegmentProductionBL.GetProductTask(batchDate ?? DateTime.Today, entity);
if (!IsDisposed && !Disposing)
if (!IsDisposed)
{ {
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
if (IsDisposed || Disposing) return;
if (IsDisposed) return;
taskDataGrid.DataSource = list; taskDataGrid.DataSource = list;
taskDataGrid.Refresh(); taskDataGrid.Refresh();
})); }));
@ -664,7 +704,7 @@ namespace ButcherFactory.SegmentProductionAuto_
{ {
while (true) while (true)
{ {
if (_isFormClosing) return;
if (_isFormClosing || IsDisposed) return;
try try
{ {
if (netStateWatch1.NetState) if (netStateWatch1.NetState)
@ -672,11 +712,11 @@ namespace ButcherFactory.SegmentProductionAuto_
var msg = SegmentProductionBL.UploadSegmentInfo(true); var msg = SegmentProductionBL.UploadSegmentInfo(true);
if (!string.IsNullOrEmpty(msg) && msg.EndsWith("重复上传")) if (!string.IsNullOrEmpty(msg) && msg.EndsWith("重复上传"))
{ {
if (!IsDisposed && !Disposing)
if (!IsDisposed)
{ {
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
if (IsDisposed || Disposing) return;
if (IsDisposed) return;
MessageBox.Show(msg + "请检查原因!"); MessageBox.Show(msg + "请检查原因!");
})); }));
} }
@ -695,7 +735,7 @@ namespace ButcherFactory.SegmentProductionAuto_
{ {
while (true) while (true)
{ {
if (_isFormClosing) return;
if (_isFormClosing || IsDisposed) return;
try try
{ {
if (netStateWatch1.NetState) if (netStateWatch1.NetState)
@ -713,11 +753,11 @@ namespace ButcherFactory.SegmentProductionAuto_
if (tag.Any()) if (tag.Any())
{ {
SegmentProductionBL.SetInStored(tag.Select(x => x.ID).ToList()); SegmentProductionBL.SetInStored(tag.Select(x => x.ID).ToList());
if (!IsDisposed && !Disposing)
if (!IsDisposed)
{ {
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
if (IsDisposed || Disposing) return;
if (IsDisposed) return;
var groupByTotal = tag.GroupBy(x => x.TotalCode_ID); var groupByTotal = tag.GroupBy(x => x.TotalCode_ID);
foreach (var item2 in groupByTotal) foreach (var item2 in groupByTotal)
{ {
@ -796,14 +836,14 @@ namespace ButcherFactory.SegmentProductionAuto_
} }
catch (Exception ex) catch (Exception ex)
{ {
if (_isFormClosing) return;
if (!IsDisposed && !Disposing)
if (_isFormClosing || IsDisposed) return;
if (!IsDisposed)
{ {
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
if (IsDisposed || Disposing) return;
if (IsDisposed) return;
var msg = ex.Message ?? string.Empty; var msg = ex.Message ?? string.Empty;
msglbl.Text = "ERROR:" + msg;
ShowErrorMsg(msg);
LogUtil.WriteErrorFile(msg, "分割品车间称重计数"); LogUtil.WriteErrorFile(msg, "分割品车间称重计数");
})); }));
} }


Loading…
Cancel
Save