|
|
|
@ -1,8 +1,15 @@ |
|
|
|
using Forks.EnterpriseServices.JsonRpc; |
|
|
|
using BWP.B3ClientService.BL; |
|
|
|
using BWP.B3ClientService.BO; |
|
|
|
using Forks.EnterpriseServices.BusinessInterfaces; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
|
using Forks.EnterpriseServices.JsonRpc; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using TSingSoft.WebPluginFramework; |
|
|
|
|
|
|
|
namespace BWP.B3ClientService.Rpcs.InterfaceRpc |
|
|
|
{ |
|
|
|
@ -10,5 +17,135 @@ namespace BWP.B3ClientService.Rpcs.InterfaceRpc |
|
|
|
|
|
|
|
public static class GoodsRpc |
|
|
|
{ |
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static int BatchImport(string json) |
|
|
|
{ |
|
|
|
var list = JsonConvert.DeserializeObject<List<Goods>>(json); |
|
|
|
using (new WpfSpecialUserScope(InternalUser)) |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var bl = BIFactory.Create<IGoodsBL>(session); |
|
|
|
foreach (var item in list) |
|
|
|
UpdateOrInsert(bl, session, item); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
static Goods GetGoods(string Code, IDmoSession session) |
|
|
|
{ |
|
|
|
var query = new DmoQuery(typeof(Goods)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Code", Code)); |
|
|
|
return (Goods)session.ExecuteScalar(query); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static int Stop(string code) |
|
|
|
{ |
|
|
|
using (new WpfSpecialUserScope(InternalUser)) |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var bl = BIFactory.Create<IGoodsBL>(session); |
|
|
|
var goods = GetGoods(code, session); |
|
|
|
if (goods != null) |
|
|
|
bl.Stop(goods); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static int Start(string code) |
|
|
|
{ |
|
|
|
using (new WpfSpecialUserScope(InternalUser)) |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var bl = BIFactory.Create<IGoodsBL>(session); |
|
|
|
var goods = GetGoods(code, session); |
|
|
|
if (goods != null) |
|
|
|
bl.Start(goods); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static int Delete(string code) |
|
|
|
{ |
|
|
|
using (new WpfSpecialUserScope(InternalUser)) |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var bl = BIFactory.Create<IGoodsBL>(session); |
|
|
|
var goods = GetGoods(code, session); |
|
|
|
if (goods != null) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
bl.Delete(goods); |
|
|
|
} |
|
|
|
catch { } |
|
|
|
} |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static int UpdateOrInsert(string json) |
|
|
|
{ |
|
|
|
var item = JsonConvert.DeserializeObject<Goods>(json); |
|
|
|
using (new WpfSpecialUserScope(InternalUser)) |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var bl = BIFactory.Create<IGoodsBL>(session); |
|
|
|
UpdateOrInsert(bl, session, item); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
static void UpdateOrInsert(IGoodsBL bl, IDmoSession session, Goods serverGoods) |
|
|
|
{ |
|
|
|
var goods = GetGoods(serverGoods.Code, session); |
|
|
|
if (goods == null) |
|
|
|
{ |
|
|
|
goods = new Goods(); |
|
|
|
bl.InitNewDmo(goods); |
|
|
|
goods.Code = serverGoods.Code; |
|
|
|
} |
|
|
|
goods.Name = serverGoods.Name; |
|
|
|
goods.MainUnit = serverGoods.MainUnit; |
|
|
|
goods.SecondUnit = serverGoods.SecondUnit; |
|
|
|
goods.Spec = serverGoods.Spec; |
|
|
|
goods.Remark = serverGoods.Remark; |
|
|
|
if (goods.ID == 0) |
|
|
|
bl.Insert(goods); |
|
|
|
else |
|
|
|
bl.Update(goods); |
|
|
|
} |
|
|
|
|
|
|
|
static WpfUser user; |
|
|
|
static WpfUser InternalUser |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
if (user == null) |
|
|
|
{ |
|
|
|
user = BIFactory.Create<IUserBL>().Get(WpfUser.InternalAccountName); |
|
|
|
user.UserTag = WpfUser.InternalUserTag; |
|
|
|
} |
|
|
|
return user; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |