DownLoadPurchasereturn.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 DownLoadPurchasereturn : BaseDataDownLoad
  19. {
  20. protected override void _Init()
  21. {
  22. _loadSql = "select * from PU_ArrivalVouch where processflag=0";
  23. base._Init();
  24. }
  25. protected override BusinessObject _ImportData(DataRow row)
  26. {
  27. PurchasereturnApi api = new PurchasereturnApi();
  28. Dictionary<string, string> args = new Dictionary<string, string>();
  29. string id = row["ID"].ToString();
  30. args.Add("PU_ArrivalVouch", "select * from wtu..PU_ArrivalVouch where ID=" + id);
  31. args.Add("PU_ArrivalVouchs", "select * from wtu..PU_ArrivalVouchs where ID=" + id);
  32. DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection());
  33. Purchasereturn v = __GetHead(ds);
  34. v.entry = __GetDetails(ds);
  35. PurchasereturnRoot vr = new PurchasereturnRoot();
  36. vr.purchasereturn = v;
  37. BusinessObject result = api.Add(JsonUtils.GetJsonString(vr));
  38. return result;
  39. }
  40. protected override void _Audit(string id)
  41. {
  42. PurchasereturnApi api = new PurchasereturnApi();
  43. api.Audit(id);
  44. }
  45. private Purchasereturn __GetHead(DataSet ds)
  46. {
  47. Purchasereturn v = new Purchasereturn();
  48. DataTable dt = ds.Tables["PU_ArrivalVouch"];
  49. v.code = dt.Rows[0]["cCode"].ToString();
  50. v.purchasetypecode = AppSeting.Instance.GetValue("purchasetypecode");//采购类型编码默认MC
  51. v.businesstype = dt.Rows[0]["cBusType"].ToString();
  52. string vencode;
  53. if (dt.Rows[0]["cVenCode"].ToString() != "")
  54. {
  55. //旺店通无供应商编号,把供应商名称存到编号中,现转换为编号
  56. vencode = dt.Rows[0]["cVenCode"].ToString();
  57. string sql =string.Format( "select * from {0}..Vendor where cVenName= '" + vencode + "'",ConnectionUtils.Instance.GetConnection().Database);
  58. string tabl = DbUtils.ExecuteScalar(sql, ConnectionUtils.Instance.GetConnection()).ToString();
  59. v.vendorcode = tabl.ToString();
  60. }
  61. v.departmentcode = "0";//部门编码默认101
  62. v.personcode = "0";//业务员编码默认100
  63. v.foreigncurrency = dt.Rows[0]["cexch_name"].ToString();
  64. v.foreigncurrencyrate = AppSeting.Instance.GetValue("foreigncurrencyrate");//汇率默认1
  65. v.memory = dt.Rows[0]["cMemo"].ToString();
  66. v.billtype = dt.Rows[0]["bNegative"].ToString();//负发票标志
  67. DateTime date = DateTime.Parse(dt.Rows[0]["dDate"].ToString());
  68. v.date = date.ToString("yyyy-MM-dd");
  69. v.cmodifydate= date.ToString("yyyy-MM-dd");
  70. v.define5 = dt.Rows[0]["ID"].ToString();
  71. return v;
  72. }
  73. private Entry[] __GetDetails(DataSet ds)
  74. {
  75. int cnt = ds.Tables["PU_ArrivalVouchs"].Rows.Count;
  76. DataTable dt = ds.Tables["PU_ArrivalVouchs"];
  77. Entry[] rtn = new Entry[cnt];
  78. for (int i = 0; i < cnt; i++)
  79. {
  80. Entry e = new Entry();
  81. e.inventorycode = dt.Rows[i]["cInvCode"].ToString().Replace(" ", "");
  82. e.quantity = "-"+dt.Rows[i]["iQuantity"].ToString();
  83. e.originaltaxedprice = dt.Rows[i]["iOriTaxCost"].ToString();
  84. e.taxrate = dt.Rows[i]["iTaxRate"].ToString();
  85. e.cbmemo = dt.Rows[i]["cbMemo"].ToString();
  86. e.cost = dt.Rows[i]["cDefine22"].ToString();
  87. e.define27 = dt.Rows[i]["ID"].ToString();
  88. e.ivouchrowno = (i + 1).ToString();
  89. rtn[i] = e;
  90. }
  91. return rtn;
  92. }
  93. protected override void _LogError(int id, string msg)
  94. {
  95. OperationLog.Utils.WriteErrorLog("向U8导入采购退货资料", "sysid = " + id.ToString() + " " + msg);
  96. }
  97. protected override void _LogSucess(int id,string newCode)
  98. {
  99. string sql = "update PU_ArrivalVouch set processflag = 1,processdate = getdate(),newcode='" + newCode + "'" + " where sysid = " + id.ToString();
  100. //string sql = "update PU_ArrivalVouch set processflag = 1,processdate = getdate() where sysid = " + id.ToString();
  101. //string sql = "update PU_ArrivalVouch set processflag = 1,processdate = getdate(),newcode=(select cCode from wtu..PU_ArrivalVouch where sysid = " + id.ToString() + ") where sysid = " + id.ToString();
  102. OperationLog.Utils.UpdateTempRecord(sql);
  103. }
  104. protected override string _GetReturnCode(BusinessObject result)
  105. {
  106. //string ID = DbUtils.ExecuteScalar(string.Format("select ID from PU_ArrivalVouch where cCode='{0}' ", result.Id), ConnectionUtils.Instance.GetConnection("003")).ToString();
  107. return result.Id;
  108. }
  109. }
  110. }