using BWP.B3ClientService.BO;
|
|
using BWP.B3Frameworks.BO;
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using Forks.JsonRpc.Client;
|
|
using Forks.JsonRpc.Client.Data;
|
|
using Forks.Utils.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TSingSoft.WebPluginFramework;
|
|
using TSingSoft.WebPluginFramework.TimerTasks;
|
|
|
|
namespace BWP.B3ClientService.Tasks
|
|
{
|
|
public class SyncInfoFromServer : ITimerTask
|
|
{
|
|
public void Execute()
|
|
{
|
|
var serverUri = ServerHost.GetServerUrl();
|
|
if (string.IsNullOrEmpty(serverUri))
|
|
throw new Exception("请配置服务器地址");
|
|
//try
|
|
{
|
|
try
|
|
{
|
|
RpcFacade.Init(serverUri, "B3ClientServer");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex.Message != "Can only start once")
|
|
throw;
|
|
}
|
|
SyncWpfUser();
|
|
SyncUserEmployee();
|
|
SyncEmployee();
|
|
SyncEmpInfoTable();
|
|
SyncCar();
|
|
SyncLivestock();
|
|
SyncPurchaseType();
|
|
SyncSupplier();
|
|
SyncZone();
|
|
SyncFarmer();
|
|
SyncHogGrade();
|
|
SyncLiveColonyHouse();
|
|
SyncSanction();
|
|
SyncLiveVarieties();
|
|
}
|
|
//catch
|
|
{ }
|
|
}
|
|
|
|
static void SyncWpfUser()
|
|
{
|
|
var list = RpcFacade.Call<List<RpcObject>>("/MainSystem/B3ButcherManage/Rpcs/TouchScreenRpcs/GetWpfUser");
|
|
using (var context = new TransactionContext())
|
|
{
|
|
var sql1 = @"truncate table [WPF_User];SET IDENTITY_INSERT [WPF_User] ON;
|
|
";
|
|
context.Session.ExecuteSqlNonQuery(sql1);
|
|
foreach (RpcObject o in list)
|
|
{
|
|
var entity = new MinWPF_User();
|
|
entity.ID = o.Get<long>("ID");
|
|
entity.Name = o.Get<string>("Name");
|
|
entity.Stopped = o.Get<bool>("Stopped");
|
|
entity.Password = o.Get<byte[]>("Password");
|
|
entity.RoleSchema = o.Get<string>("RoleSchema");
|
|
context.Session.Insert(entity);
|
|
}
|
|
var sql2 = @"SET IDENTITY_INSERT [WPF_User] OFF;";
|
|
context.Session.ExecuteSqlNonQuery(sql2);
|
|
context.Commit();
|
|
}
|
|
}
|
|
|
|
void SyncUserEmployee()
|
|
{
|
|
var list = RpcFacade.Call<List<RpcObject>>("/MainSystem/B3ButcherManage/Rpcs/TouchScreenRpcs/GetUserEmployee");
|
|
using (var context = new TransactionContext())
|
|
{
|
|
var sql1 = @"truncate table [B3Frameworks_User_Employee];
|
|
";
|
|
context.Session.ExecuteSqlNonQuery(sql1);
|
|
foreach (RpcObject o in list)
|
|
{
|
|
var entity = new User_Employee();
|
|
entity.Employee_ID = o.Get<long>("Employee_ID");
|
|
entity.User_ID = o.Get<long>("User_ID");
|
|
context.Session.Insert(entity);
|
|
}
|
|
context.Commit();
|
|
}
|
|
}
|
|
|
|
void SyncEmployee()
|
|
{
|
|
var list = RpcFacade.Call<List<RpcObject>>("/MainSystem/B3ButcherManage/Rpcs/TouchScreenRpcs/GetEmployee");
|
|
using (var context = new TransactionContext())
|
|
{
|
|
var sql1 = @"truncate table [B3Frameworks_Employee];SET IDENTITY_INSERT [B3Frameworks_Employee] ON;
|
|
";
|
|
context.Session.ExecuteSqlNonQuery(sql1);
|
|
foreach (RpcObject o in list)
|
|
{
|
|
var entity = new MinEmployee();
|
|
entity.ID = o.Get<long>("ID");
|
|
entity.Spell = o.Get<string>("Spell");
|
|
entity.Name = o.Get<string>("Name");
|
|
entity.Code = o.Get<string>("Code");
|
|
entity.Stopped = o.Get<bool>("Stopped");
|
|
entity.Domain_ID = o.Get<long>("Domain_ID");
|
|
entity.IsLocked = false;
|
|
entity.CreateTime = DateTime.Today;
|
|
entity.ModifyTime = entity.CreateTime;
|
|
context.Session.Insert(entity);
|
|
}
|
|
var sql2 = @"SET IDENTITY_INSERT [B3Frameworks_Employee] OFF;";
|
|
context.Session.ExecuteSqlNonQuery(sql2);
|
|
context.Commit();
|
|
}
|
|
}
|
|
|
|
void SyncEmpInfoTable()
|
|
{
|
|
var list = RpcFacade.Call<List<RpcObject>>("/MainSystem/B3ButcherManage/Rpcs/TouchScreenRpcs/GetEmpInfo");
|
|
using (var context = new TransactionContext())
|
|
{
|
|
var sql1 = @"truncate table [B3ClientService_EmpInfoTable];";
|
|
context.Session.ExecuteSqlNonQuery(sql1);
|
|
foreach (RpcObject o in list)
|
|
{
|
|
var entity = new EmpInfoTable();
|
|
entity.User_ID = o.Get<long>("User_ID");
|
|
entity.User_Name = o.Get<string>("User_Name");
|
|
entity.Domain_ID = o.Get<long>("Domain_ID");
|
|
entity.Employee_ID = o.Get<long>("Employee_ID");
|
|
entity.Employee_Name = o.Get<string>("Employee_Name");
|
|
entity.Department_ID = o.Get<long?>("Department_ID");
|
|
entity.Department_Name = o.Get<string>("Department_Name");
|
|
entity.AccountingUnit_ID = o.Get<long?>("AccountingUnit_ID");
|
|
entity.AccountingUnit_Name = o.Get<string>("AccountingUnit_Name");
|
|
entity.Role = o.Get<string>("Role");
|
|
context.Session.Insert(entity);
|
|
}
|
|
context.Commit();
|
|
}
|
|
}
|
|
|
|
void SyncCar()
|
|
{
|
|
SyncBaseInfo<Car>("GetCar", "B3ClientService_Car");
|
|
}
|
|
|
|
void SyncLivestock()
|
|
{
|
|
SyncBaseInfo<Livestock>("GetLivestock", "B3ClientService_Livestock");
|
|
}
|
|
|
|
void SyncPurchaseType()
|
|
{
|
|
var list = RpcFacade.Call<List<RpcObject>>("/MainSystem/B3ButcherManage/Rpcs/TouchScreenRpcs/GetPurchaseType");
|
|
using (var context = new TransactionContext())
|
|
{
|
|
var sql1 = @"truncate table [B3ClientService_PurchaseType];
|
|
";
|
|
context.Session.ExecuteSqlNonQuery(sql1);
|
|
foreach (RpcObject o in list)
|
|
{
|
|
var entity = new PurchaseType();
|
|
entity.ID = o.Get<short>("ID");
|
|
entity.Name = o.Get<string>("Name");
|
|
context.Session.Insert(entity);
|
|
}
|
|
context.Commit();
|
|
}
|
|
}
|
|
|
|
void SyncSupplier()
|
|
{
|
|
SyncBaseInfo<Supplier>("GetSupplier", "B3ClientService_Supplier");
|
|
}
|
|
|
|
void SyncZone()
|
|
{
|
|
SyncBaseInfo<Zone>("GetZone", "B3ClientService_Zone");
|
|
}
|
|
|
|
void SyncFarmer()
|
|
{
|
|
SyncBaseInfo<Farmer>("GetFarmer", "B3ClientService_Farmer");
|
|
}
|
|
|
|
void SyncHogGrade()
|
|
{
|
|
SyncBaseInfo<HogGrade>("GetHogGrade", "B3ClientService_HogGrade");
|
|
}
|
|
|
|
void SyncLiveColonyHouse()
|
|
{
|
|
SyncBaseInfo<LiveColonyHouse>("GetLiveColonyHouse", "B3ClientService_LiveColonyHouse");
|
|
}
|
|
|
|
void SyncSanction()
|
|
{
|
|
var list = RpcFacade.Call<List<RpcObject>>("/MainSystem/B3ButcherManage/Rpcs/TouchScreenRpcs/GetSanctionSetting");
|
|
using (var context = new TransactionContext())
|
|
{
|
|
var sql1 = @"truncate table [B3ClientService_Sanction];
|
|
";
|
|
context.Session.ExecuteSqlNonQuery(sql1);
|
|
foreach (RpcObject o in list)
|
|
{
|
|
var entity = new Sanction();
|
|
entity.ID = o.Get<long>("ID");
|
|
entity.AbnormalItem_ID = o.Get<long>("AbnormalItem_ID");
|
|
entity.AbnormalItem_Name = o.Get<string>("AbnormalItem_Name");
|
|
context.Session.Insert(entity);
|
|
}
|
|
context.Commit();
|
|
}
|
|
}
|
|
|
|
void SyncLiveVarieties()
|
|
{
|
|
SyncBaseInfo<LiveVarieties>("GetLiveVarieties", "B3ClientService_LiveVarieties");
|
|
}
|
|
|
|
void SyncBaseInfo<T>(string rpcMethodName, string tableName, string rpcClassName = null)
|
|
where T : BWP.B3ClientService.BO.BaseInfo, new()
|
|
{
|
|
if (rpcClassName == null)
|
|
rpcClassName = "TouchScreenRpcs";
|
|
var list = RpcFacade.Call<List<RpcObject>>(string.Format("/MainSystem/B3ButcherManage/Rpcs/{0}/{1}", rpcClassName, rpcMethodName));
|
|
using (var context = new TransactionContext())
|
|
{
|
|
var sql1 = string.Format(@"truncate table [{0}];", tableName);
|
|
context.Session.ExecuteSqlNonQuery(sql1);
|
|
foreach (RpcObject o in list)
|
|
{
|
|
var entity = new T();
|
|
entity.ID = o.Get<long>("ID");
|
|
entity.Name = o.Get<string>("Name");
|
|
entity.Spell = o.Get<string>("Spell");
|
|
context.Session.Insert(entity);
|
|
}
|
|
context.Commit();
|
|
}
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return "从B3同步数据到Server服务器"; }
|
|
}
|
|
}
|
|
}
|