From 86f06271d922a204af8203b8e16ec4a3ae6d0190 Mon Sep 17 00:00:00 2001
From: yibo <361071264@qq.com>
Date: Fri, 4 May 2018 10:11:28 +0800
Subject: [PATCH] =?UTF-8?q?=E7=99=BD=E6=9D=A1=E5=85=A5=E5=BA=93=E8=B0=83?=
=?UTF-8?q?=E6=95=B4=E4=B8=BA=E5=85=88=E8=BF=87=E7=A3=85=E5=90=8E=E6=89=AB?=
=?UTF-8?q?=E7=A0=81=E7=82=B9=E5=AD=98=E8=B4=A7=EF=BC=9B=E7=99=BD=E6=9D=A1?=
=?UTF-8?q?=E9=A2=86=E7=94=A8=E6=95=B0=E6=8D=AE=E5=A4=AA=E5=A4=9A=EF=BC=8C?=
=?UTF-8?q?=E5=88=86=E6=89=B9=E4=BF=9D=E5=AD=98=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ButcherFactory.BO/ButcherFactory.BO.csproj | 1 +
ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs | 54 ++++++------
ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs | 18 ++--
ButcherFactory.BO/Utils/ButcherFactoryUtil.cs | 32 +++++++
.../CarcassInStore_/CarcassInStoreForm.cs | 88 +++++++++----------
.../CarcassTakeOut_/CarcassTakeOutForm.cs | 1 +
6 files changed, 115 insertions(+), 79 deletions(-)
create mode 100644 ButcherFactory.BO/Utils/ButcherFactoryUtil.cs
diff --git a/ButcherFactory.BO/ButcherFactory.BO.csproj b/ButcherFactory.BO/ButcherFactory.BO.csproj
index 85329df..67f88ba 100644
--- a/ButcherFactory.BO/ButcherFactory.BO.csproj
+++ b/ButcherFactory.BO/ButcherFactory.BO.csproj
@@ -79,6 +79,7 @@
+
diff --git a/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs b/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs
index 9105c87..5f3166e 100644
--- a/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs
+++ b/ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs
@@ -18,34 +18,20 @@ namespace ButcherFactory.BO.LocalBL
{
const string RpcPath = @"/MainSystem/B3ClientService/Rpcs/CarcassInStoreRpc/";
- public static CarcassInStore Insert(long? workUnitID, long batchID, long goodsID, string barCode)
+ public static CarcassInStore Insert(long? workUnitID, long batchID, decimal weight)
{
using (var session = DmoSession.New())
{
- var exist = CheckExist(barCode, session);
- if (exist)
- throw new Exception("条码已使用过");
var entity = new CarcassInStore();
entity.WorkUnit_ID = workUnitID;
entity.ProductBatch_ID = batchID;
entity.UserID = AppContext.Worker.ID;
- entity.Goods_ID = goodsID;
- entity.BarCode = barCode;
+ entity.Weight = weight;
entity.RowIndex = GenerateRowIndex(session, batchID);
session.Insert(entity);
session.Commit();
return entity;
}
- }
-
- static bool CheckExist(string barCode, IDmoSession session)
- {
- if (string.IsNullOrEmpty(barCode))
- return false;
- var query = new DQueryDom(new JoinAlias(typeof(CarcassInStore)));
- query.Columns.Add(DQSelectColumn.Create(DQExpression.Value(1), "c"));
- query.Where.Conditions.Add(DQCondition.EQ("BarCode", barCode));
- return query.EExecuteScalar(session) != null;
}
static int GenerateRowIndex(IDmoSession session, long batchID)
@@ -56,13 +42,17 @@ namespace ButcherFactory.BO.LocalBL
return (query.EExecuteScalar(session) ?? 0) + 1;
}
- public static void FillWeight(long id, decimal weight)
+ public static void FillCodeAndGoods(long id, string barCode, long goodsID)
{
using (var session = DmoSession.New())
{
+ var exist = CheckExist(barCode, session);
+ if (exist)
+ throw new Exception("条码已使用过");
var update = new DQUpdateDom(typeof(CarcassInStore));
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
- update.Columns.Add(new DQUpdateColumn("Weight", weight));
+ update.Columns.Add(new DQUpdateColumn("BarCode", barCode));
+ update.Columns.Add(new DQUpdateColumn("Goods_ID", goodsID));
update.Columns.Add(new DQUpdateColumn("Sync", false));
update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1))));
session.ExecuteNonQuery(update);
@@ -70,22 +60,32 @@ namespace ButcherFactory.BO.LocalBL
}
}
+ static bool CheckExist(string barCode, IDmoSession session)
+ {
+ if (string.IsNullOrEmpty(barCode))
+ return false;
+ var query = new DQueryDom(new JoinAlias(typeof(CarcassInStore)));
+ query.Columns.Add(DQSelectColumn.Create(DQExpression.Value(1), "c"));
+ query.Where.Conditions.Add(DQCondition.EQ("BarCode", barCode));
+ return query.EExecuteScalar(session) != null;
+ }
+
public static BindingList GetLocalDataWithState(bool history)
{
var query = new DQueryDom(new JoinAlias(typeof(CarcassInStore)));
query.Columns.Add(DQSelectColumn.Field("RowIndex"));
query.Columns.Add(DQSelectColumn.Field("ID"));
- query.Columns.Add(DQSelectColumn.Field("BarCode"));
- query.Columns.Add(DQSelectColumn.Field("Goods_Name"));
+ query.Columns.Add(DQSelectColumn.Field("Weight"));
if (history)
{
- query.Columns.Add(DQSelectColumn.Field("Weight"));
+ query.Columns.Add(DQSelectColumn.Field("BarCode"));
+ query.Columns.Add(DQSelectColumn.Field("Goods_Name"));
query.Columns.Add(DQSelectColumn.Field("BeforeWeight"));
- query.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field("Weight")));
+ query.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field("Goods_ID")));
query.Range = SelectRange.Top(30);
}
else
- query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("Weight")));
+ query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("Goods_ID")));
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true));
var result = new BindingList();
using (var session = DmoSession.New())
@@ -98,11 +98,11 @@ namespace ButcherFactory.BO.LocalBL
result.Add(entity);
entity.RowIndex = (int?)reader[0];
entity.ID = (long)reader[1];
- entity.BarCode = (string)reader[2];
- entity.Goods_Name = (string)reader[3];
+ entity.Weight = (decimal)reader[2];
if (history)
{
- entity.Weight = (decimal)reader[4];
+ entity.BarCode = (string)reader[3];
+ entity.Goods_Name = (string)reader[4];
entity.BeforeWeight = (decimal?)reader[5];
}
}
@@ -182,7 +182,7 @@ namespace ButcherFactory.BO.LocalBL
query.Columns.Add(DQSelectColumn.Field("Goods_ID"));
query.Columns.Add(DQSelectColumn.Field("Weight"));
query.Columns.Add(DQSelectColumn.Field("CreateTime"));
- query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("Weight")), DQCondition.EQ("Sync", false)));
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("Goods_ID")), DQCondition.EQ("Sync", false)));
query.Range = SelectRange.Top(10);
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID"));
diff --git a/ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs b/ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs
index 2966de0..8de92a6 100644
--- a/ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs
+++ b/ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs
@@ -129,13 +129,17 @@ namespace ButcherFactory.BO.LocalBL
{
if (ids.Count() == 0)
return;
- var update = new DQUpdateDom(typeof(CarcassTakeOut));
- update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray()));
- foreach (var item in updates)
- update.Columns.Add(new DQUpdateColumn(item.Item1, item.Item2));
- update.Columns.Add(new DQUpdateColumn("Sync", false));
- update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1))));
- session.ExecuteNonQuery(update);
+ var arr = ButcherFactoryUtil.SplitList(ids.ToList(), 500);
+ foreach (var items in arr)
+ {
+ var update = new DQUpdateDom(typeof(CarcassTakeOut));
+ update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), items.Select(x => DQExpression.Value(x)).ToArray()));
+ foreach (var item in updates)
+ update.Columns.Add(new DQUpdateColumn(item.Item1, item.Item2));
+ update.Columns.Add(new DQUpdateColumn("Sync", false));
+ update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1))));
+ session.ExecuteNonQuery(update);
+ }
}
public static void Submit(decimal weight, List list)
diff --git a/ButcherFactory.BO/Utils/ButcherFactoryUtil.cs b/ButcherFactory.BO/Utils/ButcherFactoryUtil.cs
new file mode 100644
index 0000000..b41e2e0
--- /dev/null
+++ b/ButcherFactory.BO/Utils/ButcherFactoryUtil.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ButcherFactory.BO.Utils
+{
+ public static class ButcherFactoryUtil
+ {
+ public static List> SplitList(List list, int size)
+ where T : new()
+ {
+ List> result = new List>();
+ for (int i = 0; i < list.Count() / size; i++)
+ {
+ T[] clist = new T[size];
+ list.CopyTo(i * size, clist, 0, size);
+ result.Add(clist.ToList());
+ }
+
+ int r = list.Count() % size;
+ if (r != 0)
+ {
+ T[] cclist = new T[r];
+ list.CopyTo(list.Count() - r, cclist, 0, r);
+ result.Add(cclist.ToList());
+ }
+ return result;
+ }
+ }
+}
diff --git a/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs b/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs
index e5c6af7..4f32db4 100644
--- a/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs
+++ b/ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs
@@ -88,32 +88,12 @@ namespace ButcherFactory.CarcassInStore_
void ReceiveWeight(decimal weight)
{
- lock (_lock)
+ this.Invoke(new Action(() =>
{
- this.Invoke(new Action(() =>
- {
- var last = needSubmitedList.LastOrDefault();
- if (last == null)
- {
- SoundPalyUtil.PlaySound(SoundType.Error);
- return;
- }
- else
- {
- last.Weight = weight;
- CarcassInStoreBL.FillWeight(last.ID, weight);
- needSubmitedList.Remove(last);
- needSubmitGrid.Refresh();
- historyList.Insert(0, last);
- if (historyList.Count > 100)
- historyList.RemoveAt(100);
- historyDataGrid.FirstDisplayedScrollingRowIndex = 0;
- historyDataGrid.Refresh();
- checkWeight = new Thread(new ParameterizedThreadStart(CheckWeight));
- checkWeight.Start(weight);
- }
- }));
- }
+ Insert(weight);
+ checkWeight = new Thread(new ParameterizedThreadStart(CheckWeight));
+ checkWeight.Start(weight);
+ }));
}
void CheckWeight(object objWeight)
@@ -150,41 +130,59 @@ namespace ButcherFactory.CarcassInStore_
}
bool noCode = false;
+ static object _lock = new object();
void BindGoods()
{
var goods = FormClientGoodsSetBL.GetGoodsList();
foreach (var item in goods)
{
var btn = new UButton() { Width = 120, Height = 75, Text = item.Goods_Name, Tag = item.Goods_ID, Font = new Font("宋体", 15), Margin = new Padding(22, 10, 22, 30), PlaySound = true };
- btn.Click += (sender, e) =>
- {
- var code = uScanPanel1.TextBox.Text;
- if (!noCode && code.Length != 23)
- throw new Exception("条码格式不正确");
- var c = sender as UButton;
- Insert(code, (long)c.Tag, c.Text);
- if (noCode)
- {
- noCodeBtn_Click(sender, EventArgs.Empty);
- noCodeBtn.AsClicked = false;
- }
- else
- uScanPanel1.TextBox.Text = string.Empty;
- };
+ btn.Click += GoodsBtnClick;
flowLayoutPanel1.Controls.Add(btn);
}
}
- static object _lock = new object();
- void Insert(string barCode, long goodsID, string goodsName)
+ void GoodsBtnClick(object sender, EventArgs e)
+ {
+ lock (_lock)
+ {
+ var last = needSubmitedList.LastOrDefault();
+ if (last == null)
+ throw new Exception("列表无记录");
+ var code = uScanPanel1.TextBox.Text;
+ if (!noCode && code.Length != 23)
+ throw new Exception("条码格式不正确");
+ var c = sender as UButton;
+ CarcassInStoreBL.FillCodeAndGoods(last.ID, code, (long)c.Tag);
+ last.Goods_Name = c.Text;
+ last.BarCode = code;
+ needSubmitedList.Remove(last);
+ needSubmitGrid.Refresh();
+
+ historyList.Insert(0, last);
+ if (historyList.Count > 100)
+ historyList.RemoveAt(100);
+ historyDataGrid.FirstDisplayedScrollingRowIndex = 0;
+ historyDataGrid.Refresh();
+
+ if (noCode)
+ {
+ noCodeBtn_Click(sender, EventArgs.Empty);
+ noCodeBtn.AsClicked = false;
+ }
+ else
+ uScanPanel1.TextBox.Text = string.Empty;
+ }
+ }
+
+ void Insert(decimal weight)
{
lock (_lock)
{
if (batchID == null)
throw new Exception("没有批次信息");
- var entity = CarcassInStoreBL.Insert(workUnitID, batchID.Value, goodsID, barCode);
- entity.Goods_Name = goodsName;
+ var entity = CarcassInStoreBL.Insert(workUnitID, batchID.Value, weight);
needSubmitedList.Insert(0, entity);
needSubmitGrid.FirstDisplayedScrollingRowIndex = 0;
needSubmitGrid.Refresh();
@@ -253,7 +251,7 @@ namespace ButcherFactory.CarcassInStore_
private void noWeightBtn_Click(object sender, EventArgs e)
{
- ReceiveWeight(0);
+ Insert(0);
}
private void noCodeBtn_Click(object sender, EventArgs e)
diff --git a/ButcherFactory.Form/CarcassTakeOut_/CarcassTakeOutForm.cs b/ButcherFactory.Form/CarcassTakeOut_/CarcassTakeOutForm.cs
index 8c1e01c..8f79fe6 100644
--- a/ButcherFactory.Form/CarcassTakeOut_/CarcassTakeOutForm.cs
+++ b/ButcherFactory.Form/CarcassTakeOut_/CarcassTakeOutForm.cs
@@ -88,6 +88,7 @@ namespace ButcherFactory.CarcassTakeOut_
{
BaseInfoSyncRpc.SyncGoodsByTag(ApplyClient.白条出入库);
BaseInfoSyncRpc.SyncBaseInfo();
+ BaseInfoSyncRpc.SyncBaseInfo();
}
productBatchSelect.EBindComboBox(x => x.Date == DateTime.Today, 3, "Date");