You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.6 KiB
117 lines
3.6 KiB
4 years ago
|
using System;
|
||
|
using System.ComponentModel;
|
||
|
using System.Linq;
|
||
|
using CK.SCP.Models;
|
||
|
using CK.SCP.Models.Enums;
|
||
|
using CK.SCP.Models.UniApiEntity;
|
||
|
using CK.SCP.GrupUniApi.Controller;
|
||
|
using System.Transactions;
|
||
|
namespace CK.SCP.GrupUniApi
|
||
|
{
|
||
|
public class QadOdbcApi : IApi
|
||
|
{
|
||
|
private readonly BackgroundWorker _bgwGet = new BackgroundWorker();
|
||
|
private readonly BackgroundWorker _bgwPut = new BackgroundWorker();
|
||
|
|
||
|
public QadOdbcApi()
|
||
|
{
|
||
|
InitBgw();
|
||
|
}
|
||
|
|
||
|
private void InitBgw()
|
||
|
{
|
||
|
_bgwGet.DoWork += BgwGetDoWork;
|
||
|
_bgwGet.RunWorkerCompleted += BgwGetRunWorkerCompleted;
|
||
|
//回传给QAD
|
||
|
_bgwPut.DoWork += BgwPutDoWork;
|
||
|
_bgwPut.RunWorkerCompleted += BgwPutRunWorkerCompleted;
|
||
|
|
||
|
}
|
||
|
|
||
|
private void BgwPutRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||
|
{
|
||
|
Console.WriteLine(@"Odbc接口数据发送完成<<<<<<<<<<");
|
||
|
}
|
||
|
|
||
|
private void BgwPutDoWork(object sender, DoWorkEventArgs e)
|
||
|
{
|
||
|
var idb = EntitiesFactory.CreateUniApiInstance();
|
||
|
var wdb = EntitiesFactory.CreateScpInstance();
|
||
|
try
|
||
|
{
|
||
|
var apiList = UniApiController.GetNewInterfaceList(wdb);
|
||
|
OdbcApiScpController.PutAll(wdb, idb, apiList);
|
||
|
apiList = apiList.Where(p => p.State == (int)FormState.关闭).ToList();
|
||
|
var apiHisList = apiList.Select(uniApi => uniApi.ToHis()).ToList();
|
||
|
using (var scope =
|
||
|
new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
|
||
|
{
|
||
|
IsolationLevel = System.Transactions.IsolationLevel.Serializable,
|
||
|
Timeout = new TimeSpan(0, 20, 0)
|
||
|
}))
|
||
|
{
|
||
|
UniApiController.AddHisList(wdb, apiHisList);
|
||
|
UniApiController.RemoveList(wdb, apiList);
|
||
|
EntitiesFactory.SaveDb(idb);
|
||
|
EntitiesFactory.SaveDb(wdb);
|
||
|
scope.Complete();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
Console.WriteLine(ex);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
private void BgwGetRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||
|
{
|
||
|
Console.WriteLine(@"Odbc接口数据接收完成<<<<<<<<<<");
|
||
|
}
|
||
|
|
||
|
private void BgwGetDoWork(object sender, DoWorkEventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
OdbcApiQadController.GetNewCtrlList(); //取QAD数据
|
||
|
OdbcApiWmsController.GetNewCtrlList(); //取WMS数据
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
Console.WriteLine(string.Format("错误:{0}", ex.Message));
|
||
|
// MessageHelper.ShowError(ex);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Get()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (_bgwGet.IsBusy) return;
|
||
|
Console.WriteLine(@"Odbc接口数据接收开始>>>>>>>>>>");
|
||
|
_bgwGet.RunWorkerAsync();
|
||
|
}
|
||
|
catch (ScpException ex)
|
||
|
{
|
||
|
Console.WriteLine(ex);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Put()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (_bgwPut.IsBusy) return;
|
||
|
Console.WriteLine(@"Odbc接口数据发送开始>>>>>>>>>>");
|
||
|
_bgwPut.RunWorkerAsync();
|
||
|
}
|
||
|
catch (ScpException ex)
|
||
|
{
|
||
|
Console.WriteLine(ex);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|