Browse Source

白条入库调整为先过磅后扫码点存货;白条领用数据太多,分批保存。

master
yibo 7 years ago
parent
commit
86f06271d9
6 changed files with 115 additions and 79 deletions
  1. +1
    -0
      ButcherFactory.BO/ButcherFactory.BO.csproj
  2. +27
    -27
      ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs
  3. +11
    -7
      ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs
  4. +32
    -0
      ButcherFactory.BO/Utils/ButcherFactoryUtil.cs
  5. +43
    -45
      ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs
  6. +1
    -0
      ButcherFactory.Form/CarcassTakeOut_/CarcassTakeOutForm.cs

+ 1
- 0
ButcherFactory.BO/ButcherFactory.BO.csproj View File

@ -79,6 +79,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Rpcs\BaseInfoSyncRpc.cs" />
<Compile Include="Utils\AppContext.cs" />
<Compile Include="Utils\ButcherFactoryUtil.cs" />
<Compile Include="Utils\DbUtil.cs" />
<Compile Include="Utils\Extensions.cs" />
<Compile Include="Utils\FormUtil.cs" />


+ 27
- 27
ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs View File

@ -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<int?>(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<CarcassInStore> 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<CarcassInStore>();
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"));


+ 11
- 7
ButcherFactory.BO/LocalBL/CarcassTakeOutBL.cs View File

@ -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<long>(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<CarcassTakeOut> list)


+ 32
- 0
ButcherFactory.BO/Utils/ButcherFactoryUtil.cs View File

@ -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<List<T>> SplitList<T>(List<T> list, int size)
where T : new()
{
List<List<T>> result = new List<List<T>>();
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;
}
}
}

+ 43
- 45
ButcherFactory.Form/CarcassInStore_/CarcassInStoreForm.cs View File

@ -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)


+ 1
- 0
ButcherFactory.Form/CarcassTakeOut_/CarcassTakeOutForm.cs View File

@ -88,6 +88,7 @@ namespace ButcherFactory.CarcassTakeOut_
{
BaseInfoSyncRpc.SyncGoodsByTag(ApplyClient.);
BaseInfoSyncRpc.SyncBaseInfo<WorkUnit>();
BaseInfoSyncRpc.SyncBaseInfo<ProductBatch>();
}
productBatchSelect.EBindComboBox<ProductBatch>(x => x.Date == DateTime.Today, 3, "Date");


Loading…
Cancel
Save