using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using cuidian.Common; using cuidian.OpenApi.Api; using cuidian.OpenApi.Model; using cuidian.OpenApi.Utils; using OperationLog; using cuidian.Sql; namespace TempDbToUfida.OpenApi { /// /// 从中间库将采购订单资料下载到U8数据库 /// public class DownLoadPurchaseorder : BaseDataDownLoad { protected override void _Init() { _loadSql = "select * from PO_Pomain where processflag=0"; base._Init(); } protected override BusinessObject _ImportData(DataRow row) { PurchaseorderApi api = new PurchaseorderApi(); Dictionary args = new Dictionary(); string poid = row["POID"].ToString(); args.Add("PO_Pomain", "select * from wtu..PO_Pomain where POID=" + poid); args.Add("PO_Podetails", "select * from wtu..PO_Podetails where POID=" + poid); DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection()); Purchaseorder v = __GetHead(ds); v.entry = __GetDetails(ds); PurchaseorderRoot vr = new PurchaseorderRoot(); vr.purchaseorder = v; BusinessObject result = api.Add(JsonUtils.GetJsonString(vr)); return result; } protected override void _Audit(string id) { PurchaseorderApi api = new PurchaseorderApi(); api.Audit(id); } private Purchaseorder _____v; private Purchaseorder __GetHead(DataSet ds) { Purchaseorder v = new Purchaseorder(); DataTable dt = ds.Tables["PO_Pomain"]; v.code = dt.Rows[0]["cPOID"].ToString(); //v.date = dt.Rows[0]["dPODate"].ToString(); v.operation_type_code = AppSeting.Instance.GetValue("operation_type_code");//采购业务类型,默认普通采购 v.purchase_type_code = AppSeting.Instance.GetValue("purchase_type_code");//采购类型编码,默认MC v.vendorcode = dt.Rows[0]["cVenCode"].ToString(); v.maker = dt.Rows[0]["cMaker"].ToString(); v.currency_name = AppSeting.Instance.GetValue("currency_name");//外币名称,默认人民币 v.remark = dt.Rows[0]["cMemo"].ToString(); v.define5 = dt.Rows[0]["POID"].ToString(); _____v = v; return v; } private Entry[] __GetDetails(DataSet ds) { int cnt = ds.Tables["PO_Podetails"].Rows.Count; DataTable dt = ds.Tables["PO_Podetails"]; Entry[] rtn = new Entry[cnt]; for (int i = 0; i < cnt; i++) { Entry e = new Entry(); e.inventorycode = dt.Rows[i]["cInvCode"].ToString().Replace(" ", ""); e.quantity = dt.Rows[i]["iQuantity"].ToString(); e.taxrate = dt.Rows[i]["iPerTaxRate"].ToString(); e.taxprice = dt.Rows[i]["iTaxPrice"].ToString(); e.define27 = dt.Rows[i]["POID"].ToString(); e.rowno = (i + 1).ToString(); rtn[i] = e; } return rtn; } protected override void _LogError(int id, string msg) { OperationLog.Utils.WriteErrorLog("向U8导入采购订单资料", "sysid = " + id.ToString() + " " + msg); } protected override void _LogSucess(int id,string newCode) { string sql = "update PO_Pomain set processflag = 1,processdate = getdate(),newcode='" + newCode + "'" + " where sysid = " + id.ToString(); //string sql = "update PO_Pomain set processflag = 1,processdate = getdate(),newcode=(select cPOID from wtu..PO_Pomain where sysid = " + id.ToString() + ") where sysid = " + id.ToString(); OperationLog.Utils.UpdateTempRecord(sql); } protected override string _GetReturnCode(BusinessObject result) { string cPOID = DbUtils.ExecuteScalar(string.Format("select cPOID from {1}..PO_Pomain where cDefine5='{0}'", _____v.define5,ConnectionUtils.Instance.GetConnection().Database), ConnectionUtils.Instance.GetConnection("TempDB")).ToString(); return cPOID; } } }