| | |
| | | using System; |
| | | using System.Configuration; |
| | | using System.IO; |
| | | using System.Runtime.CompilerServices; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using WeifenLuo.WinFormsUI.Docking; |
| | | using static Bro.Common.Helper.EnumHelper; |
| | | |
| | |
| | | { |
| | | _idleThreshold = 30; |
| | | } |
| | | |
| | | this.FormClosing += (s, e) => |
| | | { |
| | | _checkIdleTimer?.Change(-1, -1); |
| | | _checkIdleTimer?.Dispose(); |
| | | _checkIdleTimer = null; |
| | | |
| | | _idleTimer?.Change(-1, -1); |
| | | _idleTimer?.Dispose(); |
| | | _idleTimer = null; |
| | | |
| | | _downTimer?.Change(-1, -1); |
| | | _downTimer?.Dispose(); |
| | | _downTimer = null; |
| | | |
| | | _availableTimer?.Change(-1, -1); |
| | | _availableTimer?.Dispose(); |
| | | _availableTimer = null; |
| | | }; |
| | | } |
| | | |
| | | public override void OnProcessUpdated() |
| | |
| | | CurrentState = RunState.Stop; |
| | | } |
| | | |
| | | if (state == EnumHelper.DeviceState.DSClose) |
| | | { |
| | | SaveNumRecord(); |
| | | } |
| | | //if (state == EnumHelper.DeviceState.DSClose) |
| | | //{ |
| | | // SaveNumRecord(); |
| | | //} |
| | | } |
| | | |
| | | private void CheckIdle(object state) |
| | |
| | | } |
| | | |
| | | Qty_OEE++; |
| | | |
| | | Task.Run(() => |
| | | { |
| | | SaveNumRecord(Qty_OK, Qty_NG); |
| | | }); |
| | | } |
| | | |
| | | private void UpdateCT(float ctTime) |
| | |
| | | AvailableTime = AvailableTime.Add(new TimeSpan(0, 0, 1)); |
| | | } |
| | | |
| | | private void OnClearQty() |
| | | { |
| | | Qty_OK = Qty_NG = 0; |
| | | } |
| | | //private void OnClearQty() |
| | | //{ |
| | | // Qty_OK = Qty_NG = 0; |
| | | //} |
| | | |
| | | string numRecordFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Statistic.json"); |
| | | static object numLock = new object(); |
| | | private void SaveNumRecord() |
| | | |
| | | [MethodImpl(MethodImplOptions.Synchronized)] |
| | | private void SaveNumRecord(int okNum, int ngNum) |
| | | { |
| | | lock (numLock) |
| | | { |
| | | using (StreamWriter writer = new StreamWriter(numRecordFile, false, System.Text.Encoding.UTF8)) |
| | | try |
| | | { |
| | | string dataStr = JsonConvert.SerializeObject(new { Qty_OK, Qty_NG }); |
| | | writer.Write(dataStr); |
| | | writer.Flush(); |
| | | //using (StreamWriter writer = new StreamWriter(numRecordFile, false, System.Text.Encoding.UTF8)) |
| | | //{ |
| | | // if (okNum % 5 == 0) |
| | | // { |
| | | // Application.Exit(); |
| | | // throw new AccessViolationException(); |
| | | // } |
| | | // string dataStr = JsonConvert.SerializeObject(new StatisticModel() { Qty_OK = okNum, Qty_NG = ngNum }); |
| | | // if (!string.IsNullOrWhiteSpace(dataStr)) |
| | | // { |
| | | // writer.Write(dataStr); |
| | | // writer.Flush(); |
| | | // } |
| | | //} |
| | | |
| | | using (FileStream fs = new FileStream(numRecordFile, FileMode.OpenOrCreate, FileAccess.Write)) |
| | | { |
| | | fs.Seek(0, SeekOrigin.Begin); |
| | | |
| | | string dataStr = JsonConvert.SerializeObject(new StatisticModel() { Qty_OK = okNum, Qty_NG = ngNum }); |
| | | |
| | | byte[] dataBuf = System.Text.Encoding.UTF8.GetBytes(dataStr); |
| | | fs.Write(dataBuf, 0, dataBuf.Length); |
| | | fs.SetLength(dataBuf.Length); |
| | | fs.Flush(); |
| | | fs.Close(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, $"保存统计数据异常,{ex.GetExceptionMessage()}"); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | string dataStr = reader.ReadToEnd(); |
| | | |
| | | JObject data = JsonConvert.DeserializeObject<JObject>(dataStr); |
| | | //JObject data = JsonConvert.DeserializeObject<JObject>(dataStr); |
| | | |
| | | if (data != null) |
| | | //if (data != null) |
| | | //{ |
| | | // Qty_OK = data.Value<int>("Qty_OK"); |
| | | // Qty_NG = data.Value<int>("Qty_NG"); |
| | | //} |
| | | |
| | | StatisticModel model = JsonConvert.DeserializeObject<StatisticModel>(dataStr); |
| | | if (model != null) |
| | | { |
| | | Qty_OK = data.Value<int>("Qty_OK"); |
| | | Qty_NG = data.Value<int>("Qty_NG"); |
| | | Qty_OK = model.Qty_OK; |
| | | Qty_NG = model.Qty_NG; |
| | | } |
| | | else |
| | | { |
| | | //LogAsync(DateTime.Now, $"载入统计数据错误", ""); |
| | | MessageBox.Show($"载入统计数据错误"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //LogAsync(DateTime.Now, $"统计数据文件不存在", ""); |
| | | MessageBox.Show($"统计数据文件不存在"); |
| | | } |
| | | } |
| | | |
| | | private void btnClearStatistic_Click(object sender, EventArgs e) |
| | | { |
| | | //Qty_OK = Qty_NG = 0; |
| | | } |
| | | |
| | | private void tsmiClearQty_Click(object sender, EventArgs e) |
| | | { |
| | | Qty_OK = Qty_NG = 0; |
| | | } |
| | | } |
| | | |
| | | public class StatisticModel |
| | | { |
| | | public int Qty_OK { get; set; } |
| | | |
| | | public int Qty_NG { get; set; } |
| | | } |
| | | } |