DownLoadPurchaseorder.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using cuidian.Common;
  8. using cuidian.OpenApi.Api;
  9. using cuidian.OpenApi.Model;
  10. using cuidian.OpenApi.Utils;
  11. using OperationLog;
  12. using cuidian.Sql;
  13. namespace TempDbToUfida.OpenApi
  14. {
  15. /// <summary>
  16. /// 从中间库将采购订单资料下载到U8数据库
  17. /// </summary>
  18. public class DownLoadPurchaseorder : BaseDataDownLoad
  19. {
  20. protected override void _Init()
  21. {
  22. _loadSql = "select * from PO_Pomain where processflag=0";
  23. base._Init();
  24. }
  25. protected override BusinessObject _ImportData(DataRow row)
  26. {
  27. PurchaseorderApi api = new PurchaseorderApi();
  28. Dictionary<string, string> args = new Dictionary<string, string>();
  29. string poid = row["POID"].ToString();
  30. args.Add("PO_Pomain", "select * from wtu..PO_Pomain where POID=" + poid);
  31. args.Add("PO_Podetails", "select * from wtu..PO_Podetails where POID=" + poid);
  32. DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection());
  33. Purchaseorder v = __GetHead(ds);
  34. v.entry = __GetDetails(ds);
  35. PurchaseorderRoot vr = new PurchaseorderRoot();
  36. vr.purchaseorder = v;
  37. BusinessObject result = api.Add(JsonUtils.GetJsonString(vr));
  38. return result;
  39. }
  40. protected override void _Audit(string id)
  41. {
  42. PurchaseorderApi api = new PurchaseorderApi();
  43. api.Audit(id);
  44. }
  45. private Purchaseorder _____v;
  46. private Purchaseorder __GetHead(DataSet ds)
  47. {
  48. Purchaseorder v = new Purchaseorder();
  49. DataTable dt = ds.Tables["PO_Pomain"];
  50. v.code = dt.Rows[0]["cPOID"].ToString();
  51. //v.date = dt.Rows[0]["dPODate"].ToString();
  52. v.operation_type_code = AppSeting.Instance.GetValue("operation_type_code");//采购业务类型,默认普通采购
  53. v.purchase_type_code = AppSeting.Instance.GetValue("purchase_type_code");//采购类型编码,默认MC
  54. v.vendorcode = dt.Rows[0]["cVenCode"].ToString();
  55. v.maker = dt.Rows[0]["cMaker"].ToString();
  56. v.currency_name = AppSeting.Instance.GetValue("currency_name");//外币名称,默认人民币
  57. v.remark = dt.Rows[0]["cMemo"].ToString();
  58. v.define5 = dt.Rows[0]["POID"].ToString();
  59. _____v = v;
  60. return v;
  61. }
  62. private Entry[] __GetDetails(DataSet ds)
  63. {
  64. int cnt = ds.Tables["PO_Podetails"].Rows.Count;
  65. DataTable dt = ds.Tables["PO_Podetails"];
  66. Entry[] rtn = new Entry[cnt];
  67. for (int i = 0; i < cnt; i++)
  68. {
  69. Entry e = new Entry();
  70. e.inventorycode = dt.Rows[i]["cInvCode"].ToString().Replace(" ", "");
  71. e.quantity = dt.Rows[i]["iQuantity"].ToString();
  72. e.taxrate = dt.Rows[i]["iPerTaxRate"].ToString();
  73. e.taxprice = dt.Rows[i]["iTaxPrice"].ToString();
  74. e.define27 = dt.Rows[i]["POID"].ToString();
  75. e.rowno = (i + 1).ToString();
  76. rtn[i] = e;
  77. }
  78. return rtn;
  79. }
  80. protected override void _LogError(int id, string msg)
  81. {
  82. OperationLog.Utils.WriteErrorLog("向U8导入采购订单资料", "sysid = " + id.ToString() + " " + msg);
  83. }
  84. protected override void _LogSucess(int id,string newCode)
  85. {
  86. string sql = "update PO_Pomain set processflag = 1,processdate = getdate(),newcode='" + newCode + "'" + " where sysid = " + id.ToString();
  87. //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();
  88. OperationLog.Utils.UpdateTempRecord(sql);
  89. }
  90. protected override string _GetReturnCode(BusinessObject result)
  91. {
  92. 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();
  93. return cPOID;
  94. }
  95. }
  96. }