public int Insert(MeasureDetail obj) { /// 1: update thành công /// 0: Update ko thành công int res = 0; string queryStr = "INSERT INTO"; queryStr += " measuredetail ("; if (!string.IsNullOrEmpty(obj.MeasureId)) { queryStr += "`MeasureId`,"; } if (!string.IsNullOrEmpty(obj.IngredientId)) { queryStr += "`IngredientId`,"; } if (!string.IsNullOrEmpty(obj.MeasureQty)) { queryStr += "`MeasureQty`"; } queryStr += ") VALUES ("; if (!string.IsNullOrEmpty(obj.MeasureId)) { queryStr += string.Format("'{0}',", obj.MeasureId); } if (!string.IsNullOrEmpty(obj.IngredientId)) { queryStr += string.Format("'{0}',", obj.IngredientId); } if (!string.IsNullOrEmpty(obj.MeasureQty)) { queryStr += string.Format("'{0}'", obj.MeasureQty); } queryStr += ")"; Program.destopService.DataExecute(Program.Username, Program.Password, queryStr, ref errorString); if (string.IsNullOrEmpty(errorString)) { res = 1; } return(res); }
public int Update(MeasureDetail obj) { /// 1: update thành công /// 0: Update ko thành công int res = 0; string queryStr = "UPDATE measuredetail SET "; if (!string.IsNullOrEmpty(obj.MeasureQty)) { queryStr += string.Format(" MeasureQty = '{0}'", obj.MeasureQty); } queryStr += string.Format(" WHERE MeasureId = '{0}' AND IngredientId = '{1}'", obj.MeasureId, obj.IngredientId); Program.destopService.DataExecute(Program.Username, Program.Password, queryStr, ref errorString); if (string.IsNullOrEmpty(errorString)) { res = 1; } return(res); }
public bool WriteMeasureDetail(int rowStart, MeasureDetail measureDetail, emMeasureType MeasureType) { if (_package == null || _excelWorksheet == null) { return(false); } try { _excelWorksheet.Cells[NO + rowStart].Value = measureDetail.No; _excelWorksheet.Cells[TIME + rowStart].Value = measureDetail.Time?.ToString(cstrDateTimeFomatShow); _excelWorksheet.Cells[VALUE + rowStart].Value = measureDetail.Value; var range = string.Format("{0}{2}:{1}{2}", NO, RESULT, rowStart.ToString()); if (MeasureType == emMeasureType.AlarmTest) { _excelWorksheet.Cells[RESULT + rowStart].Value = measureDetail.Result; } else { range = string.Format("{0}{2}:{1}{2}", NO, VALUE, rowStart.ToString()); } _excelWorksheet.Cells[range].Style.Border.Top.Style = ExcelBorderStyle.Thin; _excelWorksheet.Cells[range].Style.Border.Left.Style = ExcelBorderStyle.Thin; _excelWorksheet.Cells[range].Style.Border.Right.Style = ExcelBorderStyle.Thin; _excelWorksheet.Cells[range].Style.Border.Bottom.Style = ExcelBorderStyle.Thin; return(true); } catch (Exception ex) { return(false); } }
private void HandleReceiveMeasureDetail(object senser, MeasureDetail data) { var sensorData = senser as SensorInfo; if (sensorData == null) { return; } if (!AppManager.ActualListSensorIdActive.Contains(sensorData.SensorId)) { AppManager.ActualListSensorIdActive.Add(sensorData.SensorId); } SensorInfo s = AppManager.ListSensor.FirstOrDefault(i => i.SensorId == sensorData.SensorId); s = sensorData; if (BlockActiceId != sensorData.OfBlock) { return; } if (this.pendingGraph) { return; } if (tabGraph.Controls.Count == 0) { return; } var objLayout = tabGraph.Controls[0] as GraphTypeBase; if (objLayout == null) { return; } var lbl = objLayout.GetDisplaySensorByIndex(sensorData.Ordinal_Display - 1); var graph = objLayout.GetPlotterDisplayExByIndex(sensorData.Ordinal_Display - 1); var graphName = string.Format("graph_{0}_{1}", sensorData.OfBlock, sensorData.SensorId); if (s.MeasureType == clsConst.MeasureMode_Decay) { if (s.MeasureState == MeasureState.None) { graph.AlowRefesh = false; return; } else { graph.AlowRefesh = true; } } if (lbl != null) { this.UpdateSafeControl(lbl, l => { //((DisplaySensor)l).SetSensorName(sensorData.GraphName, sensorData.Alarm); if (sensorData.Active == (int)clsConst.emBlockStatus.Active) { ((DisplaySensor)l).DisplayValueSensor(data.Actual_Value); } }); } if (sensorData.Active == (int)clsConst.emBlockStatus.Inactive) { clsSupportGraph.UpdateGraphName(graph, "", false); clsSupportGraph.ReplaceListPoint(graph, new List <cPoint>() { new cPoint() { x = 0, y = 0 } }, false); graph.Name = graphName; return; } if (graph.Name == graphName) { //clsSupportGraph.UpdateGraphName(graph, "", false); clsSupportGraph.UpdateAlarm(graph, sensorData, false); clsSupportGraph.AddPoint(graph, data.Actual_Value, false); if (sensorData.MeasureType == clsConst.MeasureMode_Decay) { var listDataPositivePoint = sensorData.GraphData.Samples.Where(i => i.PointFlag == (int)MeasureState.Positive); var listDataNegativePoint = sensorData.GraphData.Samples.Where(i => i.PointFlag == (int)MeasureState.Negative); var listDataIBPoint = sensorData.GraphData.Samples.Where(i => i.PointFlag == (int)MeasureState.Ion); var maxY = listDataPositivePoint.Max <cPoint, float?>(i => i.y) ?? 0; var maxX = listDataPositivePoint.Where(i => i.y == maxY) .OrderByDescending(i => i.x) .Select(i => i.x) .FirstOrDefault(); if (maxX > 0 && maxY >= sensorData.DecayUpperValue) { var dataProcess = listDataPositivePoint.Where(i => i.x >= maxX).ToList(); sensorData.GraphData.PositivePoint = dataProcess.Where(i => i.y <= sensorData.DecayUpperValue && i.y >= sensorData.DecayLowerValue).ToList(); graph.DataSources[graph.DataSources.Count - 1].PositivePoint = sensorData.GraphData.PositivePoint; if (sensorData.GraphData.PositivePoint.Count > 1) { var startDecay = sensorData.GraphData.PositivePoint.OrderBy(i => i.x).First(); var endDecay = sensorData.GraphData.PositivePoint.OrderBy(i => i.x).Last(); var decayTime = (endDecay.dtPoint - startDecay.dtPoint).TotalMilliseconds; if (lbl != null && sensorData.MeasureState == MeasureState.Positive) { this.UpdateSafeControl(lbl, l => { //((DisplaySensor)l).SetSensorName(sensorData.GraphName, sensorData.Alarm); if (sensorData.Active == (int)clsConst.emBlockStatus.Active) { sensorData.ActualDecayPositiveTime = decayTime / 1000; ((DisplaySensor)l).DisplayDecayValue(sensorData.ActualDecayPositiveTime, sensorData.MeasureState); } }); } //Console.WriteLine(startDecay.dtPoint.ToString("HH:mm:ss:ffff") // + " - " + endDecay.dtPoint.ToString("HH:mm:ss:ffff") // + " - " + decayTime // + " - " + startDecay.y); } } var minY = listDataNegativePoint.Min <cPoint, float?>(i => i.y) ?? 0; var minX = listDataNegativePoint.Where(i => i.y == minY) .OrderByDescending(i => i.x) .Select(i => i.x) .FirstOrDefault(); if (minX > 0 && Math.Abs(minY) >= sensorData.DecayUpperValue) { var dataProcess = listDataNegativePoint.Where(i => i.x >= minX).ToList(); sensorData.GraphData.NegativePoint = dataProcess.Where(i => Math.Abs(i.y) <= sensorData.DecayUpperValue && Math.Abs(i.y) >= sensorData.DecayLowerValue).ToList(); graph.DataSources[graph.DataSources.Count - 1].NegativePoint = sensorData.GraphData.NegativePoint; if (sensorData.GraphData.NegativePoint.Count > 1) { var startDecay = sensorData.GraphData.NegativePoint.OrderBy(i => i.x).First(); var endDecay = sensorData.GraphData.NegativePoint.OrderBy(i => i.x).Last(); var decayTime = (endDecay.dtPoint - startDecay.dtPoint).TotalMilliseconds; if (lbl != null && sensorData.MeasureState == MeasureState.Negative) { this.UpdateSafeControl(lbl, l => { //((DisplaySensor)l).SetSensorName(sensorData.GraphName, sensorData.Alarm); if (sensorData.Active == (int)clsConst.emBlockStatus.Active) { sensorData.ActualDecayNegativeTime = (decayTime / 1000); ((DisplaySensor)l).DisplayDecayValue(sensorData.ActualDecayNegativeTime, sensorData.MeasureState); } }); } //Console.WriteLine(startDecay.dtPoint.ToString("HH:mm:ss:ffff") // + " - " + endDecay.dtPoint.ToString("HH:mm:ss:ffff") // + " - " + decayTime // + " - " + startDecay.y); } } if (listDataIBPoint != null && listDataIBPoint.Count() > 0) { graph.DataSources[graph.DataSources.Count - 1].IBPoint = listDataIBPoint.ToList(); var maxIBY = listDataIBPoint.Max <cPoint, float?>(i => Math.Abs(i.y)) ?? 0; var maxIB = listDataIBPoint.Where(i => Math.Abs(i.y) == maxIBY) .OrderByDescending(i => i.x) .FirstOrDefault(); maxIonVal = maxIB.y; //if (lbl != null && sensorData.MeasureState == MeasureState.Ion) //{ // this.UpdateSafeControl(lbl, l => // { // //((DisplaySensor)l).SetSensorName(sensorData.GraphName, sensorData.Alarm); // if (sensorData.Active == (int)clsConst.emBlockStatus.Active) // { // ((DisplaySensor)l).DisplayDecayValue(maxIB.y.ToString("#,###"), sensorData.MeasureState); // } // }); //} if (maxIonVal > sensorData.IonValueCheck && sensorData.MeasureState == MeasureState.Ion) { sensorData.Result_Measure = (int)clsConst.emMeasureResult.Fail; sensorData.Alarm = true; } } } } else { clsSupportGraph.ReplaceListPoint(graph, sensorData.GraphData.Samples, false); graph.DataSources[graph.DataSources.Count - 1].PositivePoint = sensorData.GraphData.PositivePoint; graph.Name = graphName; } }
private void btnSave_Click(object sender, EventArgs e) { DataTable dtCheck = ingredientBLL.GetMeasureDetailById(this.measureId, cbbIngredient.SelectedValue.ToString()); MeasureDetail obj = new MeasureDetail(); obj.MeasureId = this.measureId; obj.IngredientId = cbbIngredient.SelectedValue.ToString(); obj.MeasureQty = txtQty.Text; if (dtCheck != null) { if (dtCheck.Rows.Count != 0) { if (CustomMessageBox.MessageBox.ShowCustomMessageBox("Bạn có muốn cập nhật nguyên liệu này cho sản phẩm?", Common.clsLanguages.GetResource("Information"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.YESNO) == DialogResult.Yes) { // Update int i = ingredientBLL.Update(obj); if (i == 1) { CustomMessageBox.MessageBox.ShowCustomMessageBox("Cập nhật nguyên liệu thành công", Common.clsLanguages.GetResource("Information"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); } else { CustomMessageBox.MessageBox.ShowCustomMessageBox("Cập nhật nguyên liệu thất bại", Common.clsLanguages.GetResource("Information"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); } } } else { if (CustomMessageBox.MessageBox.ShowCustomMessageBox("Bạn có muốn thêm nguyên liệu mới cho sản phẩm?", Common.clsLanguages.GetResource("Information"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.YESNO) == DialogResult.Yes) { // Insert int i = ingredientBLL.Insert(obj); if (i == 1) { CustomMessageBox.MessageBox.ShowCustomMessageBox("Thêm mới nguyên liệu thành công", Common.clsLanguages.GetResource("Information"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); } else { CustomMessageBox.MessageBox.ShowCustomMessageBox("Thêm mới nguyên liệu thất bại", Common.clsLanguages.GetResource("Information"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); } } } } }
private void HandleWhenReceiveDataFromBlock(object sender, string[] data) { if (!this.IsRunning) { return; } var blockData = AppManager.ListBlock.FirstOrDefault(i => i.BlockId == this.BlockData.BlockId); var lstSensorDB = AppManager.ListSensor.Where(i => i.OfBlock == this.BlockData.BlockId && i.Active == (int)clsConst.emBlockStatus.Active).ToList(); var maxLenght = 0; if (lstSensorDB != null && lstSensorDB.Count > 0) { maxLenght = lstSensorDB.Select(i => i.SensorName.Length).Max(); } foreach (var sensor in this.ListSensorChild) { //if (sensor.MeasureType == clsConst.MeasureMode_Decay && sensor.IsMeasuring == false) //{ // return; //} var sensorDB = lstSensorDB.FirstOrDefault(i => i.SensorId == sensor.SensorId); if (sensorDB == null) { continue; } var tempPoint = data[sensor.Ordinal_Display - 1]; if (data[sensor.Ordinal_Display - 1] == DSF602Const.ERR_DATA && ErrorsReceiveDataFromBlock != null) { mappingSensorProcessorException[sensor.SensorId].Add(new DSF602Exception("SensorError NaN", DSF602ExceptionStatusCode.SensorError)); tempPoint = "0"; sensor.Active = clsConst.NOT_ACTIVE; } //var keyDbName = DBManagerChild.GetDBName(sensor.SensorId); //var randomTest = new Random(); var pointGraphTemp = ConvertHelper.CnvNullToFloat(tempPoint, 0); // + randomTest.Next(-500, 500); var rateConvert = tempPoint.Replace("-", "").Length <= 7 ? 1000 : 10000; int pointGraph = 0; if (Math.Abs(pointGraphTemp * rateConvert) > int.MaxValue) { if (rateConvert == 1000) { pointGraph = 2000; } else { pointGraph = 20000; } pointGraph = pointGraphTemp > 0 ? pointGraph : -pointGraph; } else { pointGraph = (int)(pointGraphTemp * rateConvert); } //Console.WriteLine(pointGraph); int alarmVal = sensorDB.MeasureType == clsConst.MeasureMode_Ion ? clsConst.IonAlarmValue : sensorDB.Alarm_Value; var objMeasureDetail = new MeasureDetail { SensorId = sensor.SensorId, MeasureId = mappingSensorMeasureId[sensor.SensorId], DBName = DBManagerChild.GetDBName(sensor.SensorId), Samples_time = DateTime.Now, Actual_Value = pointGraph, Detail_Result = Math.Abs(pointGraph) >= alarmVal ? (int)clsConst.emMeasureResult.Fail : (int)clsConst.emMeasureResult.Pass, }; if (sensor.MeasureType != clsConst.MeasureMode_Decay) { if (objMeasureDetail.Detail_Result == (int)clsConst.emMeasureResult.Fail) { sensor.Result_Measure = (int)clsConst.emMeasureResult.Fail; sensor.Alarm = true; } } if (resetAlarm) { sensor.Alarm = false; } //mappingSensorMeasureData[sensor.SensorId].Add(objMeasureDetail); if (sensor.MeasureType != clsConst.MeasureMode_Decay || sensor.MeasureState != clsConst.MeasureState.None) { mappingSensorMeasureData[sensor.SensorId].Add(objMeasureDetail); } if (sensor.MeasureType != clsConst.MeasureMode_Decay && mappingSensorMeasureData[sensor.SensorId].Count == BATCH_PROCESS_SQL) { mappingSensorProcessorInsert[sensor.SensorId].Add(mappingSensorMeasureData[sensor.SensorId].ToList()); mappingSensorMeasureData[sensor.SensorId].Clear(); } if (sensor.MeasureType == clsConst.MeasureMode_Decay && sensor.MeasureState != clsConst.MeasureState.None) { mappingSensorProcessorInsert[sensor.SensorId].Add(mappingSensorMeasureData[sensor.SensorId].ToList()); mappingSensorMeasureData[sensor.SensorId].Clear(); } //var checkBatchProcessSql = sensor.MeasureType == clsConst.MeasureMode_Decay && sensor.MeasureState != clsConst.MeasureState.None; //checkBatchProcessSql = checkBatchProcessSql ? checkBatchProcessSql : mappingSensorMeasureData[sensor.SensorId].Count == BATCH_PROCESS_SQL; //if (checkBatchProcessSql) //{ // mappingSensorProcessorInsert[sensor.SensorId].Add(mappingSensorMeasureData[sensor.SensorId].ToList()); // mappingSensorMeasureData[sensor.SensorId].Clear(); //} if (sensor.GraphData == null) { sensor.GraphData = new DataSource(); } int x = sensor.GraphData.Samples == null ? 0 : sensor.GraphData.Samples.Count; if (sensor.MeasureType != clsConst.MeasureMode_Decay || sensor.MeasureState != clsConst.MeasureState.None) { sensor.GraphData.AddPoint(x, pointGraph, DateTime.Now, (int)sensor.MeasureState); } if (HandleReceiveMeasureDetail != null) { sensorDB.GraphData = sensor.GraphData; sensorDB.GraphName = sensorDB.SensorName.PadRight(maxLenght + 1, ' '); //Task.Factory.StartNew(() => System.Threading.ThreadPool.QueueUserWorkItem(delegate { sensorDB.ActualValue = objMeasureDetail.Actual_Value; //if (sensorDB.OfBlock == 1 && sensorDB.SensorId == 2) //{ // Console.WriteLine(sensorDB.Active); //} HandleReceiveMeasureDetail(sensorDB, objMeasureDetail); }); } } lock (_syncObjAlarm) { resetAlarm = false; } }