diff --git a/ButcherFactory.BO/Bill/WeightCountEntity.cs b/ButcherFactory.BO/Bill/WeightCountEntity.cs index ced4275..f32c6b9 100644 --- a/ButcherFactory.BO/Bill/WeightCountEntity.cs +++ b/ButcherFactory.BO/Bill/WeightCountEntity.cs @@ -34,5 +34,7 @@ namespace ButcherFactory.BO.Bill public bool Submited { get; set; } public bool ProduceOut { get; set; } + + public string BarCode { get; set; } } } diff --git a/ButcherFactory.BO/LocalBL/SegmentSaleOutBL.cs b/ButcherFactory.BO/LocalBL/SegmentSaleOutBL.cs index 2cf346f..1b91d70 100644 --- a/ButcherFactory.BO/LocalBL/SegmentSaleOutBL.cs +++ b/ButcherFactory.BO/LocalBL/SegmentSaleOutBL.cs @@ -130,30 +130,32 @@ namespace ButcherFactory.BO.LocalBL var json = JsonConvert.SerializeObject(new List() { new ExtensionObj { LongExt1 = tag.DetailID, LongExt2 = tag.WeightRecord_ID, LongExt3 = tag.ScanRecord_ID } }); RpcFacade.Call(RpcPath + "SaleOutStoreRpc/DeleteAndUpdate", json); Delete(tag.ID); - } - - public static void InsertByCode(SaleOutStore_Detail orderDetail, SegmentSaleOut_Detail detail) - { - var json = ButcherFactoryUtil.SecondUrlCall(MESPath + "SegmentSaleOutStoreRpc/GetSegmentInfo", detail.BarCode); - var scanInfo = JsonConvert.DeserializeObject(json); - if (scanInfo.StringExt1 != orderDetail.Goods_Code) - throw new Exception("扫码明细与发货明细 存货不一致!"); - detail.BillID = orderDetail.SaleOutStore_ID; - detail.DetailID = orderDetail.ID; - detail.Goods_ID = orderDetail.Goods_ID; - detail.Goods_Code = orderDetail.Goods_Code; - detail.Goods_Name = orderDetail.Goods_Name; - detail.Number = scanInfo.DecimalExt1.Value; - if (orderDetail.Number.HasValue && orderDetail.SecondNumber.HasValue && orderDetail.Number != 0) - detail.SecondNumber = decimal.Round(orderDetail.SecondNumber.Value * detail.Number / orderDetail.Number.Value, 2); - detail.Operator = "扫码发货"; - using (var session = DmoSession.New()) - { - session.Insert(detail); - - SubmitDetails(session, new SegmentSaleOut_Detail[] { detail }, orderDetail, 1); - session.Commit(); - } + } + + public static long InsertByCode(BindingList orderDetails, SegmentSaleOut_Detail detail) + { + var json = ButcherFactoryUtil.SecondUrlCall(MESPath + "SegmentSaleOutStoreRpc/GetSegmentInfo", detail.BarCode); + var scanInfo = JsonConvert.DeserializeObject(json); + var first = orderDetails.FirstOrDefault(x => x.Goods_Code == scanInfo.StringExt1); + if (first == null) + throw new Exception(string.Format("扫码存货在发货明细中不存在,存货编码{0}", scanInfo.StringExt1)); + detail.BillID = first.SaleOutStore_ID; + detail.DetailID = first.ID; + detail.Goods_ID = first.Goods_ID; + detail.Goods_Code = first.Goods_Code; + detail.Goods_Name = first.Goods_Name; + detail.Number = scanInfo.DecimalExt1.Value; + if (first.Number.HasValue && first.SecondNumber.HasValue && first.Number != 0) + detail.SecondNumber = decimal.Round(first.SecondNumber.Value * detail.Number / first.Number.Value, 2); + detail.Operator = "扫码发货"; + using (var session = DmoSession.New()) + { + session.Insert(detail); + + SubmitDetails(session, new SegmentSaleOut_Detail[] { detail }, first, 1); + session.Commit(); + } + return first.ID; } public static void InsertReadWeight(SaleOutStore_Detail orderDetail, SegmentSaleOut_Detail detail) diff --git a/ButcherFactory.BO/LocalBL/WeightCountEntityBL.cs b/ButcherFactory.BO/LocalBL/WeightCountEntityBL.cs index 635a97e..2db30ce 100644 --- a/ButcherFactory.BO/LocalBL/WeightCountEntityBL.cs +++ b/ButcherFactory.BO/LocalBL/WeightCountEntityBL.cs @@ -65,11 +65,20 @@ namespace ButcherFactory.BO.LocalBL { entity.Number = 1; entity.UserID = AppContext.Worker.ID; + CreateBarCode(session, entity); session.Insert(entity); session.Commit(); } } + static void CreateBarCode(IDmoSession session, WeightCountEntity entity) + { + var query = new DQueryDom(new JoinAlias(typeof(WeightCountEntity))); + query.Where.Conditions.Add(DQCondition.Between("CreateTime", entity.CreateTime.Date, entity.CreateTime.Date + new TimeSpan(23, 59, 59))); + query.Columns.Add(DQSelectColumn.Count()); + entity.BarCode = string.Format("{260912011{0:yyyyMMdd}{1}{2:00000}}", entity.CreateTime, AppContext.ConnectInfo.ClientCode, query.EExecuteScalar(session)); + } + public static void UpdateNumber(long id, int number) { var update = new DQUpdateDom(typeof(WeightCountEntity)); @@ -125,6 +134,7 @@ namespace ButcherFactory.BO.LocalBL query.Columns.Add(DQSelectColumn.Field("Number")); query.Columns.Add(DQSelectColumn.Field("Store_ID")); query.Columns.Add(DQSelectColumn.Field("ProduceOut")); + query.Columns.Add(DQSelectColumn.Field("BarCode")); query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Submited", true), DQCondition.EQ("Sync", false))); query.Range = SelectRange.Top(10); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); @@ -146,6 +156,7 @@ namespace ButcherFactory.BO.LocalBL obj.Number = (int)reader[8]; obj.Store_ID = (long?)reader[9]; obj.ProduceOut = (bool)reader[10]; + obj.BarCode = (string)reader[11]; upload.Add(obj); } } diff --git a/ButcherFactory.Form/SegmentSaleOut_/SegmentSaleOutForm.cs b/ButcherFactory.Form/SegmentSaleOut_/SegmentSaleOutForm.cs index f4fc6b2..e73aee6 100644 --- a/ButcherFactory.Form/SegmentSaleOut_/SegmentSaleOutForm.cs +++ b/ButcherFactory.Form/SegmentSaleOut_/SegmentSaleOutForm.cs @@ -95,8 +95,8 @@ namespace ButcherFactory.SegmentSaleOut_ if (string.IsNullOrEmpty(barCode)) throw new Exception("条码错误"); if (already) - throw new Exception("正在查看已配货记录,不允许配货"); - if (detailGridView.CurrentRow == null) + throw new Exception("正在查看已配货记录,不允许配货"); + if (details == null || details.Count == 0) throw new Exception("没有订货明细"); if (weightRecord.Any(x => x.BarCode == barCode)) throw new Exception("扫码重复"); @@ -112,7 +112,7 @@ namespace ButcherFactory.SegmentSaleOut_ void InsertDetailByScan(string barCode) { - var orderDetail = detailGridView.CurrentRow.DataBoundItem as SaleOutStore_Detail; + //var orderDetail = detailGridView.CurrentRow.DataBoundItem as SaleOutStore_Detail; var detail = new SegmentSaleOut_Detail(); detail.BarCode = barCode; if (weightRecord.Any()) @@ -120,12 +120,12 @@ namespace ButcherFactory.SegmentSaleOut_ else detail.Idx = 1; - SegmentSaleOutBL.InsertByCode(orderDetail, detail); + var detailID = SegmentSaleOutBL.InsertByCode(details, detail); weightRecord.Insert(0, detail); weightRecordGridView.FirstDisplayedScrollingRowIndex = 0; - weightRecordGridView.Refresh(); - BindDetailByLocal(orderDetail.ID); + weightRecordGridView.Refresh(); + BindDetailByLocal(detailID); } void BatchInsertByScan(string barCode) @@ -133,7 +133,7 @@ namespace ButcherFactory.SegmentSaleOut_ var results = SegmentSaleOutBL.InsertByStockUp(barCode, details); var orderDetail = detailGridView.CurrentRow.DataBoundItem as SaleOutStore_Detail; var idx = weightRecord.Any() ? weightRecord.Max(x => x.Idx) + 1 : 1; - foreach (var item in results.Where(x=>x.DetailID==orderDetail.ID)) + foreach (var item in results) { item.Idx = idx; weightRecord.Insert(0, item); @@ -400,22 +400,23 @@ namespace ButcherFactory.SegmentSaleOut_ weightRecord = SegmentSaleOutBL.GetWeightRecord((long)row.Cells["D_ID"].Value); weightRecordGridView.DataSource = weightRecord; weightRecordGridView.Refresh(); - } - - void BindDetailByLocal(long detailID) - { - var first = details.First(x => x.ID == detailID); - first.SNumber = weightRecord.Sum(x => x.Number); - first.SSecondNumber = weightRecord.Sum(x => x.SecondNumber ?? 0); - foreach (DataGridViewRow row in detailGridView.Rows) - { - if ((long)row.Cells[0].Value == detailID) - { - row.Selected = true; - break; - } - } - detailGridView.Refresh(); + } + + void BindDetailByLocal(long detailID) + { + var first = details.First(x => x.ID == detailID); + var list = weightRecord.Where(x => x.DetailID == detailID); + first.SNumber = list.Sum(x => x.Number); + first.SSecondNumber = list.Sum(x => x.SecondNumber ?? 0); + foreach (DataGridViewRow row in detailGridView.Rows) + { + if ((long)row.Cells[0].Value == detailID) + { + row.Selected = true; + break; + } + } + detailGridView.Refresh(); } void BindLabels(SaleOutStore entity) diff --git a/ButcherFactory.Form/WeightCount_/WeightCountPrint.cs b/ButcherFactory.Form/WeightCount_/WeightCountPrint.cs index 74d3de5..07ac8ff 100644 --- a/ButcherFactory.Form/WeightCount_/WeightCountPrint.cs +++ b/ButcherFactory.Form/WeightCount_/WeightCountPrint.cs @@ -1,6 +1,8 @@ using ButcherFactory.BO.Bill; +using ButcherFactory.BO.Utils; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,14 +11,43 @@ namespace ButcherFactory.WeightCount_ { public static class WeightCountPrint { + static int id = 1; const string TEMPLATE = @"PrintTemplate\WeightCountPrint.html"; + const string IMGFILE = @"TempImg\_img{0}.png"; public static void Print(WeightCountEntity entity) { var dic = new Dictionary(); dic.Add("$Goods_Name", entity.Goods_Name); - dic.Add("$Weight", string.Format("#0.##",entity.Weight)); + dic.Add("$Weight", string.Format("0:#0.##",entity.Weight)); dic.Add("$Date", DateTime.Today.ToString("yyyy/MM/dd")); + dic.Add("$BarCode", string.Format("0:#0.##", entity.Weight)); + var code = entity.BarCode; + if (code.Length > 17) + code = code.Substring(17); + dic.Add("$Code", code); + var imgUrl = string.Format(IMGFILE, id); + var url = string.Format(AppContext.ConnectInfo.TraceBackUrl + "?code={0}", entity.BarCode); + BwpClientPrint.BwpClientWebPrint.Create2DPic(url, imgUrl, 120); + + dic.Add("$ImageUrl", imgUrl); BwpClientPrint.BwpClientWebPrint.Print(TEMPLATE, dic); + AfterPrint(); + } + + static DirectoryInfo TempImage = null; + private static void AfterPrint() + { + if (id == 20) + id = 0; + id++; + if (TempImage == null) + TempImage = new DirectoryInfo("TempImg"); + var files = TempImage.GetFiles(); + if (files.Length > 10) + { + var last = files.OrderBy(x => x.CreationTime).First().FullName; + File.Delete(last); + } } } }