DownLoadPurchasein.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 DownLoadPurchasein : BaseDataDownLoad
  19. {
  20. protected override void _Init()
  21. {
  22. _loadSql = "select * from RdRecord01 where processflag=0";
  23. base._Init();
  24. }
  25. protected override BusinessObject _ImportData(DataRow row)
  26. {
  27. PurchaseinApi api = new PurchaseinApi();
  28. Dictionary<string, string> args = new Dictionary<string, string>();
  29. string id = row["ID"].ToString();
  30. args.Add("RdRecord01", "select * from wtu..RdRecord01 where ID=" + id);
  31. args.Add("RdRecords01", "select * from wtu..RdRecords01 where ID=" + id);
  32. DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection());
  33. Purchasein v = __GetHead(ds);
  34. v.entry = __GetDetails(ds);
  35. PurchaseinRoot vr = new PurchaseinRoot();
  36. vr.purchasein = v;
  37. BusinessObject result = api.Add(JsonUtils.GetJsonString(vr));
  38. return result;
  39. }
  40. protected override void _Audit(string id)
  41. {
  42. PurchaseinApi api = new PurchaseinApi();
  43. api.Audit(id);
  44. }
  45. private Purchasein __GetHead(DataSet ds)
  46. {
  47. Purchasein v = new Purchasein();
  48. DataTable dt = ds.Tables["RdRecord01"];
  49. v.code = dt.Rows[0]["cCode"].ToString();
  50. v.departmentcode= dt.Rows[0]["cDepCode"].ToString();//部门编码
  51. v.warehousecode = dt.Rows[0]["cWhCode"].ToString();//仓库编码
  52. v.vendorcode = dt.Rows[0]["cVenCode"].ToString();//供货单位编码
  53. //v.vendorabbname = "";//供货单位名称
  54. //v.receivecode = AppSeting.Instance.GetValue("receivecode");//收发类型默认S
  55. v.receivecode = AppSeting.Instance.GetValue("receivecode");//收发类型默认MC
  56. v.receivename = "普通采购";//收发类型默认普通采购
  57. v.memory = dt.Rows[0]["cMemo"].ToString();
  58. DateTime date = DateTime.Parse(dt.Rows[0]["dDate"].ToString());
  59. v.date = date.ToString("yyyy-MM-dd");
  60. v.define12 = dt.Rows[0]["cDefine12"].ToString();//采购单号
  61. //v.maker = dt.Rows[0]["cMaker"].ToString();//制单人
  62. //define5 用友U8API中 采购入库 的 单据头自定义项5
  63. v.define5 = dt.Rows[0]["ID"].ToString();
  64. v.define1 = "来源旺店通";
  65. return v;
  66. }
  67. private Entry[] __GetDetails(DataSet ds)
  68. {
  69. int cnt = ds.Tables["RdRecords01"].Rows.Count;
  70. DataTable dt = ds.Tables["RdRecords01"];
  71. Entry[] rtn = new Entry[cnt];
  72. for (int i = 0; i < cnt; i++)
  73. {
  74. Entry e = new Entry();
  75. e.inventorycode = dt.Rows[i]["cInvCode"].ToString().Replace(" ", "");//存货编码
  76. e.quantity = dt.Rows[i]["iQuantity"].ToString();//数量
  77. e.price = dt.Rows[i]["iUnitCost"].ToString();//本币单价
  78. e.cost =( Convert.ToDouble(e.quantity) * Convert.ToDouble(e.price)).ToString(); //dt.Rows[i]["cDefine22"].ToString();//本币金额
  79. //define27 用友 U8 API中 采购入库
  80. e.define27 = dt.Rows[i]["ID"].ToString();
  81. e.define26 = dt.Rows[i]["cDefine26"].ToString();
  82. e.rowno = (i + 1).ToString();
  83. rtn[i] = e;
  84. }
  85. return rtn;
  86. }
  87. protected override void _LogError(int id, string msg)
  88. {
  89. OperationLog.Utils.WriteErrorLog("向U8导入采购入库资料", "sysid = " + id.ToString() + " " + msg);
  90. }
  91. protected override void _LogSucess(int id,string newCode)
  92. {
  93. string sql = "update RdRecord01 set processflag = 1,processdate = getdate(),newcode='" + newCode + "'" + " where sysid = " + id.ToString();
  94. sql +=string.Format(" update {0}..rdrecords01 set iOriMoney=iPrice,iOriCost=iUnitCost where id in(select id from {0}..rdrecord01 where ccode='{1}')",ConnectionUtils.Instance.GetConnection().Database,newCode);
  95. //string sql = "update RdRecord01 set processflag = 1,processdate = getdate(),newcode=(select cCode from wtu..RdRecord01 where sysid = " + id.ToString() + ") where sysid = " + id.ToString();
  96. OperationLog.Utils.UpdateTempRecord(sql);
  97. }
  98. protected override string _GetReturnCode(BusinessObject result)
  99. {
  100. //string ID = DbUtils.ExecuteScalar(string.Format("select ID from RdRecord01 where cCode='{0}' ", result.Id), ConnectionUtils.Instance.GetConnection("003")).ToString();
  101. return result.Id;
  102. }
  103. }
  104. }