Browse Source

someChange.

master
yibo 7 years ago
parent
commit
38dcad5494
7 changed files with 455 additions and 3 deletions
  1. +15
    -0
      ButcherFactory.BO/Base/SimpleBackObjs.cs
  2. +1
    -1
      ButcherFactory.BO/Base/SyncBill.cs
  3. +5
    -0
      ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs
  4. +29
    -2
      ButcherFactory.BO/Bill/CarcassInStore.cs
  5. +3
    -0
      ButcherFactory.BO/ButcherFactory.BO.csproj
  6. +131
    -0
      ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs
  7. +271
    -0
      ButcherFactory.BO/Utils/Extensions.cs

+ 15
- 0
ButcherFactory.BO/Base/SimpleBackObjs.cs View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ButcherFactory.BO
{
public class IDRowVersion
{
public long ID { get; set; }
public int RowVersion { get; set; }
}
}

+ 1
- 1
ButcherFactory.BO/Base/SyncBill.cs View File

@ -16,7 +16,7 @@ namespace ButcherFactory.BO
public int RowVersion { get; set; }
[DbColumn(DbType = SqlDbType.DateTime)]
public DateTime CreateTime { get; set; }
public DateTime? CreateTime { get; set; }
public long UserID { get; set; }


+ 5
- 0
ButcherFactory.BO/BaseInfo/ClientGoodsSet.cs View File

@ -27,6 +27,11 @@ namespace ButcherFactory.BO
public long Goods_ID { get; set; }
[NonDmoProperty]
[ReferenceTo(typeof(Goods), "Name")]
[Join("Goods_ID", "ID")]
public string Goods_Name { get; set; }
public decimal? StandardWeight { get; set; }
public decimal? StandardWeightUp { get; set; }


+ 29
- 2
ButcherFactory.BO/Bill/CarcassInStore.cs View File

@ -10,11 +10,16 @@ namespace ButcherFactory.BO
[MapToTable("Butcher_CarcassInStore")]
public class CarcassInStore : SyncBill
{
public CarcassInStore()
{
CreateTime = DateTime.Now;
}
public string BarCode { get; set; }
public long WorkUnit_ID { get; set; }
public long? WorkUnit_ID { get; set; }
public long ProductBatch_ID { get; set; }
public long? ProductBatch_ID { get; set; }
public long Goods_ID { get; set; }
@ -24,8 +29,30 @@ namespace ButcherFactory.BO
public decimal? BeforeWeight { get; set; }
[NonDmoProperty]
public decimal? Discont
{
get
{
if (Weight.HasValue && BeforeWeight.HasValue)
return BeforeWeight.Value - Weight.Value;
return null;
}
}
public bool FromPad { get; set; }
[ReferenceTo(typeof(Goods), "Name")]
[Join("Goods_ID", "ID")]
public string Goods_Name { get; set; }
}
public class PadCarcassInStore
{
public long ID { get; set; }
public long Goods_ID { get; set; }
public string BarCode { get; set; }
public int RowVersion { get; set; }
}
}

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

@ -59,6 +59,7 @@
<Compile Include="BaseInfo\ClientGoodsSet.cs" />
<Compile Include="Base\BaseInfo.cs" />
<Compile Include="BaseInfo\ProductBatch.cs" />
<Compile Include="Base\SimpleBackObjs.cs" />
<Compile Include="Enums\ApplyClient.cs" />
<Compile Include="Enums\DriveType.cs" />
<Compile Include="Base\SyncBill.cs" />
@ -68,10 +69,12 @@
<Compile Include="Base\WorkerGoodsSetProfile.cs" />
<Compile Include="Bill\CarcassInStore.cs" />
<Compile Include="LocalBL\BaseInfoBL.cs" />
<Compile Include="LocalBL\CarcassInStoreBL.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Rpcs\BaseInfoSyncRpc.cs" />
<Compile Include="Utils\AppContext.cs" />
<Compile Include="Utils\DbUtil.cs" />
<Compile Include="Utils\Extensions.cs" />
<Compile Include="Utils\FormUtil.cs" />
<Compile Include="Utils\LoginUtil.cs" />
<Compile Include="Utils\XmlUtil.cs" />


+ 131
- 0
ButcherFactory.BO/LocalBL/CarcassInStoreBL.cs View File

@ -0,0 +1,131 @@
using ButcherFactory.BO.Utils;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.EnterpriseServices.SqlDoms;
using Forks.JsonRpc.Client;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TSingSoft.WebPluginFramework;
namespace ButcherFactory.BO.LocalBL
{
public static class CarcassInStoreBL
{
const string RpcPath = @"/MainSystem/B3ClientService/Rpcs/CarcassInStoreRpc/";
public static bool DoWithPadData(long? workUnitID, long? productBatch)
{
bool changed = false;
var json = RpcFacade.Call<string>(RpcPath + "GetUnSyncPadData");
var data = JsonConvert.DeserializeObject<List<PadCarcassInStore>>(json).OrderBy(x => x.ID);
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
foreach (var item in data)
{
if (UpdateIfExist(item, session))
continue;
changed = true;
var entity = new CarcassInStore();
entity.FromPad = true;
entity.WorkUnit_ID = workUnitID;
entity.ProductBatch_ID = productBatch;
entity.UserID = AppContext.Worker.ID;
entity.BarCode = item.BarCode;
entity.Goods_ID = item.Goods_ID;
session.Insert(entity);
}
session.Commit();
}
var backInfo = data.Select(x => new IDRowVersion { ID = x.ID, RowVersion = x.RowVersion });
RpcFacade.Call<int>(RpcPath + "SetPadDataSync", JsonConvert.SerializeObject(backInfo));
return changed;
}
static bool UpdateIfExist(PadCarcassInStore data, IDmoSession session)
{
var query = new DQueryDom(new JoinAlias(typeof(CarcassInStore)));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Where.Conditions.Add(DQCondition.EQ("BarCode", data.BarCode));
var id = (long?)session.ExecuteScalar(query);
if (id == null)
return false;
Update(id.Value, "Goods_ID", data.Goods_ID, session);
return true;
}
public static void Update(long id, string fileName, object value, IDmoSession session)
{
var update = new DQUpdateDom(typeof(CarcassInStore));
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
update.Columns.Add(new DQUpdateColumn(fileName, value));
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 long Insert(CarcassInStore entity)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
session.Insert(entity);
session.Commit();
return entity.ID;
}
}
public static BindingList<CarcassInStore> GetLocalDataWithState(bool submit)
{
var query = new DQueryDom(new JoinAlias(typeof(CarcassInStore)));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Columns.Add(DQSelectColumn.Field("BarCode"));
query.Columns.Add(DQSelectColumn.Field("Goods_Name"));
if (submit)
{
query.Columns.Add(DQSelectColumn.Field("Weight"));
query.Columns.Add(DQSelectColumn.Field("BeforeWeight"));
query.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field("Weight")));
query.Range = SelectRange.Top(30);
}
else
query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("Weight")));
var result = new BindingList<CarcassInStore>();
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
{
var entity = new CarcassInStore();
result.Add(entity);
entity.ID = (long)reader[0];
entity.BarCode = (string)reader[1];
entity.Goods_Name = (string)reader[2];
if (submit)
{
entity.Weight = (decimal)reader[3];
entity.BeforeWeight = (decimal?)reader[4];
}
}
}
}
return result;
}
public static IEnumerable<ClientGoodsSet_Detail> GetGoodsList()
{
var main = new JoinAlias(typeof(ClientGoodsSet));
var detail = new JoinAlias(typeof(ClientGoodsSet_Detail));
var query = new DQueryDom(main);
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "ClientGoodsSet_ID"));
query.Columns.Add(DQSelectColumn.Field("Goods_ID", detail));
query.Columns.Add(DQSelectColumn.Field("Goods_Name", detail));
query.OrderBy.Expressions.Add(DQOrderByExpression.Create(detail, "Goods_ID"));
var list = query.EExecuteList<long, string>();
return list.Select(x => new ClientGoodsSet_Detail { Goods_ID = x.Item1, Goods_Name = x.Item2 });
}
}
}

+ 271
- 0
ButcherFactory.BO/Utils/Extensions.cs View File

@ -0,0 +1,271 @@
using ButcherFactory.BO.Utils;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ButcherFactory.BO
{
public static class Extensions
{
public static Tuple<T1, T2> EExecuteScalar<T1, T2>(this DQueryDom query, IDmoSession session)
{
var list = query.EExecuteList<T1, T2>(session);
if (list.Count == 0)
{
return null;
}
#if DEBUG
if (list.Count > 1)
{
throw new Exception(string.Format("期望返回1条记录实际返回{0}条", list.Count));
}
#endif
return list[0];
}
public static Tuple<T1, T2> EExecuteScalar<T1, T2>(this DQueryDom query)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return query.EExecuteScalar<T1, T2>(session);
}
}
public static Tuple<T1, T2, T3> EExecuteScalar<T1, T2, T3>(this DQueryDom query, IDmoSession session)
{
var list = query.EExecuteList<T1, T2, T3>(session);
if (list.Count == 0)
{
return null;
}
#if DEBUG
if (list.Count > 1)
{
throw new Exception(string.Format("期望返回1条记录实际返回{0}条", list.Count));
}
#endif
return list[0];
}
public static Tuple<T1, T2, T3> EExecuteScalar<T1, T2, T3>(this DQueryDom query)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return query.EExecuteScalar<T1, T2, T3>(session);
}
}
public static T EExecuteScalar<T>(this DmoQuery query) where T : class
{
var result = query.EExecuteList();
if (result.Count == 0)
{
return default(T);
}
if (result.Count > 1)
{
throw new Exception("ExecuteScalar返回多个数据");
}
return (T)result[0];
}
public static List<T> EExecuteList<T>(this DQueryDom query, IDmoSession session)
{
var list = new List<T>();
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
{
list.Add((T)reader[0]);
}
}
return list;
}
public static List<T> EExecuteList<T>(this DQueryDom query)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return query.EExecuteList<T>(session);
}
}
public static List<TDmo> EExecuteDmoList<TDmo>(this DQueryDom query, IDmoSession session, params string[] fields) where TDmo : new()
{
var type = typeof(TDmo);
PCheck.IsTrue(query.From.RootSource.Alias.DmoSource == DmoInfo.Get(type));
var dmoInfo = DmoInfo.Get(type);
if (fields.Length == 0)
{
fields = dmoInfo.Fields
.Select((item) => item.Name).ToArray();
}
#if DEBUG
else
{
foreach (var filed in fields)
{
if (!dmoInfo.Fields.Contains(filed))
{
throw new Exception(string.Format("对象{0}上不存在字段{1}的定义", type.Name, filed));
}
}
}
#endif
if (query.Columns.Count == 0)
{
foreach (var filed in fields)
{
query.Columns.Add(DQSelectColumn.Field(filed));
}
}
else if (query.Columns.Count != fields.Length)
{
throw new Exception("查询字段数量不匹配");
}
var indexSetDic = fields.ToDictionary((item) => Array.IndexOf<string>(fields, item), (item) => type.GetProperty(item).GetSetMethod());
var list = new List<TDmo>();
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
{
var dmo = new TDmo();
list.Add(dmo);
foreach (var pair in indexSetDic)
{
pair.Value.Invoke(dmo, new object[] { reader[pair.Key] });
}
}
}
return list;
}
public static List<TDmo> EExecuteDmoList<TDmo>(this DQueryDom query, params string[] fields) where TDmo : new()
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return query.EExecuteDmoList<TDmo>(session, fields);
}
}
public static List<Tuple<T1, T2>> EExecuteList<T1, T2>(this DQueryDom query, IDmoSession session)
{
var list = new List<Tuple<T1, T2>>();
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
{
var value = new Tuple<T1, T2>(
(T1)reader[0],
(T2)reader[1]);
list.Add(value);
}
}
return list;
}
public static List<Tuple<T1, T2>> EExecuteList<T1, T2>(this DQueryDom query)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return query.EExecuteList<T1, T2>(session);
}
}
public static List<Tuple<T1, T2, T3>> EExecuteList<T1, T2, T3>(this DQueryDom query, IDmoSession session)
{
var list = new List<Tuple<T1, T2, T3>>();
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
{
var value = new Tuple<T1, T2, T3>(
(T1)reader[0],
(T2)reader[1],
(T3)reader[2]);
list.Add(value);
}
}
return list;
}
public static List<Tuple<T1, T2, T3>> EExecuteList<T1, T2, T3>(this DQueryDom query)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return query.EExecuteList<T1, T2, T3>(session);
}
}
public static List<Tuple<T1, T2, T3, T4>> EExecuteList<T1, T2, T3, T4>(this DQueryDom query)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return query.EExecuteList<T1, T2, T3, T4>(session);
}
}
public static List<Tuple<T1, T2, T3, T4>> EExecuteList<T1, T2, T3, T4>(this DQueryDom query, IDmoSession session)
{
var list = new List<Tuple<T1, T2, T3, T4>>();
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
{
var value = new Tuple<T1, T2, T3, T4>(
(T1)reader[0],
(T2)reader[1],
(T3)reader[2], (T4)reader[3]);
list.Add(value);
}
}
return list;
}
public static List<Tuple<T1, T2, T3, T4, T5>> EExecuteList<T1, T2, T3, T4, T5>(this DQueryDom query)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return query.EExecuteList<T1, T2, T3, T4, T5>(session);
}
}
public static List<Tuple<T1, T2, T3, T4, T5>> EExecuteList<T1, T2, T3, T4, T5>(this DQueryDom query, IDmoSession session)
{
var list = new List<Tuple<T1, T2, T3, T4, T5>>();
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
{
var value = new Tuple<T1, T2, T3, T4, T5>(
(T1)reader[0],
(T2)reader[1],
(T3)reader[2], (T4)reader[3], (T5)reader[4]);
list.Add(value);
}
}
return list;
}
public static IList EExecuteList(this DmoQuery query)
{
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
{
return session.ExecuteList(query);
}
}
}
}

Loading…
Cancel
Save