public void BarCodeScan(object obj) { try { string barCode = obj.ToString(); BarCode = ""; if (string.IsNullOrEmpty(barCode)) { return; } MaterialScanModel leftModel = LeftData.SingleOrDefault(item => item.BarCode.Equals(barCode)); if (leftModel == null) { MaterialScanModel centerModel = CenterData.SingleOrDefault(item => item.BarCode.Equals(barCode)); if (centerModel == null) { MaterialScanModel rightModel = RightData.SingleOrDefault(item => item.BarCode.Equals(barCode)); if (rightModel == null) { //查该条码为何物 var result = ApiManager.GetPartCodeAndFigureNoByBarCode(barCode); if (result.Result) { dynamic dy = JsonConvert.DeserializeObject <dynamic>(result.Data.ToString()); RightData.Add(new MaterialScanModel() { PartCode = dy.PartCode, PartFigureCode = dy.FigureNo, AlreadyScanQuantity = 1, BarCode = barCode }); ApiManager.SaveBarCodeScanLog(barCode); } else { RightData.Add(new MaterialScanModel() { PartCode = "", PartFigureCode = $"无图号({barCode})", AlreadyScanQuantity = 1, BarCode = barCode }); } } else { rightModel.AlreadyScanQuantity++; //记录扫码日志 var result = ApiManager.SaveBarCodeScanLog(rightModel.BarCode); } } else { if (centerModel.IsCrux.Equals(1)) { if (centerModel.AlreadyScanQuantity < centerModel.DemandScanQuantity) { //执行出库 var resultA = ApiManager.MaterialScanOutput(centerModel.PartCode); if (resultA.Result) { //出库成功 centerModel.AlreadyScanQuantity++; } else { //出库失败 MessageBox.Show(resultA.Msg, "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } else { centerModel.AlreadyScanQuantity++; } //记录扫码日志 var resultB = ApiManager.SaveBarCodeScanLog(centerModel.BarCode); } else { centerModel.AlreadyScanQuantity = centerModel.DemandScanQuantity; //记录扫码日志 var resultB = ApiManager.SaveBarCodeScanLog(centerModel.BarCode, centerModel.DemandScanQuantity); } } } else { LeftData.Remove(leftModel); CenterData.Add(leftModel); if (leftModel.IsCrux.Equals(1)) { //执行出库 var resultA = ApiManager.MaterialScanOutput(leftModel.PartCode); if (resultA.Result) { //出库成功 leftModel.AlreadyScanQuantity++; } else { //出库失败 MessageBox.Show(resultA.Msg, "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); } //记录扫码日志 var resultB = ApiManager.SaveBarCodeScanLog(leftModel.BarCode); } else { leftModel.AlreadyScanQuantity = leftModel.DemandScanQuantity; //记录扫码日志 var resultB = ApiManager.SaveBarCodeScanLog(leftModel.BarCode, leftModel.DemandScanQuantity); } } } catch { } }
public void BarCodeScan(object obj) { try { string barCode = obj.ToString(); BarCode = ""; LogHelper.WriteLog($"条码:{barCode}"); if (string.IsNullOrEmpty(barCode)) { return; } MaterialScanModel materialScan_Left = LeftData.SingleOrDefault(item => item.BarCode.Equals(barCode)); LogHelper.WriteLog($"正在左侧搜索..."); if (materialScan_Left == null) { MaterialScanModel materialScan_Center = CenterData.SingleOrDefault(item => item.BarCode.Equals(barCode)); LogHelper.WriteLog($"正在中间搜索..."); if (materialScan_Center == null) { MaterialScanModel materialScan_Right = RightData.SingleOrDefault(item => item.BarCode.Equals(barCode)); LogHelper.WriteLog($"正在右侧搜索..."); if (materialScan_Right == null) { //查该条码为何物 LogHelper.WriteLog($"正在调用接口搜索...\r\n{string.Format(@"http://{0}/api/Mms/WinFormClient/GetPartAndPBomByBarCode?barCode={1}", ConfigInfoModel.API, barCode)}"); var result = new MaterialInfoBLL().GetPartAndPBomByBarCode(barCode); LogHelper.WriteLog($"搜索结果:{result.Result},详情:{result.Msg ?? ""}"); if (result.Result) { RightData.Add(new MaterialScanModel() { PartCode = result.Data.GetPart.PartCode ?? "", PartFigureCode = result.Data.GetProcessBom.PartFigureCode ?? "", AlreadyScanQuantity = 1, BarCode = barCode }); var aaa = new MaterialInfoBLL().SaveBarCodeScanLog(barCode); LogHelper.WriteLog($"记录扫码日志结果:{aaa.Result} {aaa.Msg ?? ""}"); } else { RightData.Add(new MaterialScanModel() { PartCode = "", PartFigureCode = $"无图号({barCode})", AlreadyScanQuantity = 1, BarCode = barCode }); //MessageBox.Show(result.Msg, "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } else { materialScan_Right.AlreadyScanQuantity++; var aaa = new MaterialInfoBLL().SaveBarCodeScanLog(barCode); LogHelper.WriteLog($"记录扫码日志结果:{aaa.Result} {aaa.Msg ?? ""}"); } } else { if (materialScan_Center.IsCrux.Equals(1)) { if (materialScan_Center.AlreadyScanQuantity < materialScan_Center.DemandScanQuantity) { //执行出库 var result = new MaterialInfoBLL().MaterialInventory(materialScan_Center.PartCode); if (result.Result) { //出库成功 materialScan_Center.AlreadyScanQuantity++; } else { //出库失败 MessageBox.Show(result.Msg, "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } else { materialScan_Center.AlreadyScanQuantity++; } var aaa = new MaterialInfoBLL().SaveBarCodeScanLog(barCode); LogHelper.WriteLog($"记录扫码日志结果:{aaa.Result} {aaa.Msg ?? ""}"); } else { materialScan_Center.AlreadyScanQuantity = materialScan_Center.DemandScanQuantity; var aaa = new MaterialInfoBLL().SaveBarCodeScanLog(barCode, materialScan_Center.DemandScanQuantity); LogHelper.WriteLog($"记录扫码日志结果:{aaa.Result} {aaa.Msg ?? ""}"); } } } else { LeftData.Remove(materialScan_Left); CenterData.Add(materialScan_Left); if (materialScan_Left.IsCrux.Equals(1)) { //执行出库 var result = new MaterialInfoBLL().MaterialInventory(materialScan_Left.PartCode); if (result.Result) { //出库成功 materialScan_Left.AlreadyScanQuantity++; } else { //出库失败 MessageBox.Show(result.Msg, "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); } var aaa = new MaterialInfoBLL().SaveBarCodeScanLog(barCode); LogHelper.WriteLog($"记录扫码日志结果:{aaa.Result} {aaa.Msg ?? ""}"); } else { materialScan_Left.AlreadyScanQuantity = materialScan_Left.DemandScanQuantity; var aaa = new MaterialInfoBLL().SaveBarCodeScanLog(barCode, materialScan_Left.DemandScanQuantity); LogHelper.WriteLog($"记录扫码日志结果:{aaa.Result} {aaa.Msg ?? ""}"); } } } catch (Exception ex) { LogHelper.WriteLog($"扫码异常:{ex}"); } }