PO_PomainUpLoad.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using cuidian.Common;
  2. using cuidian.Sql;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using WdtUtils;
  9. using WdtUtils.Load;
  10. using WdtUtils.Proxy;
  11. namespace WangToTempDb
  12. { /// <summary>
  13. /// 旺店通采购订单上传中间库
  14. /// </summary>
  15. public class PO_PomainUpLoad : BaseUpLoad
  16. {
  17. //private string __sql = @"if not exists (select * from PO_Pomain a inner join PO_Podetails b on a.POID=b.POID where a.POID= '{0}') insert into PO_Pomain(POID,cPOID,cState,cVenCode,cAuditDate,cMemo,dPODate,cModifyTime,direction,iVTid) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}') insert into PO_Podetails(ID,POID,cInvCode,iQuantity,iTaxPrice,iPerTaxRate) values('{10}','{0}','{11}','{12}','{13}','{14}')";
  18. private string __sql = @"if not exists (select POID from PO_Pomain where POID= {0}) insert into PO_Pomain(POID,cPOID,cState,cVenCode,cMemo,dPODate,cModifyTime,direction,iVTid) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')";
  19. //避免只能插入一条子表数据
  20. private string sql = @" if not exists (select POID from PO_Podetails where POID= {0}) ";
  21. private string newSql = @"insert into PO_Podetails(POID,ID,cInvCode,iQuantity,iTaxPrice,iPerTaxRate) values('{0}','{1}','{2}','{3}','{4}','{5}')";
  22. protected override Result _LoadFirstPage()
  23. {
  24. PO_PomainProxy tmp = new PO_PomainProxy();
  25. Result rtn = _load.Load<PO_PomainProxy>(_args, ref tmp);
  26. _proxy = tmp;
  27. return rtn;
  28. }
  29. protected override void _SetLoader()
  30. {
  31. _load = new PO_PomainLoad();
  32. }
  33. protected override void _ImportData()
  34. {
  35. _operType = "插入采购订单中间表数据";
  36. Purchase_List[] entitys = ((PO_PomainProxy)_proxy).purchase_list;
  37. if (entitys == null || entitys.Length == 0) return;
  38. StringBuilder sb = new StringBuilder();
  39. foreach (Purchase_List item in entitys)
  40. {
  41. //sb.AppendLine(string.Format(__sql, new object[] { item.purchase_id,item.purchase_no,0,item.provider_no,item.check_time,item.remark ,item.created ,item.modified,1,8173,item.details_list[0].rec_id,item.details_list[0].spec_no,item.details_list[0].num ,item.details_list[0].price,item.details_list[0].tax }));
  42. //item.check_time= Convert.ToInt32(item.check_time.Split('-')[0]) < 1753 ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : item.check_time;
  43. sb.AppendLine(string.Format(__sql, new object[] { item.purchase_id, _ConvertStr(item.purchase_no), 0, _ConvertStr(item.provider_no), _ConvertStr(item.remark), item.created, item.modified, 1, "8173" }));
  44. sb.AppendLine(string.Format(sql, new object[] { item.purchase_id }));
  45. Details_List[] dl = item.details_list;
  46. int dlCount = 1;
  47. double dlSum = Convert.ToDouble(item.goods_amount)+ Convert.ToDouble(item.post_fee);
  48. if (dl.Length==0)
  49. {
  50. continue;
  51. }
  52. sb.AppendLine("begin");
  53. foreach (Details_List ty in dl)
  54. {
  55. if (dlCount != dl.Count())
  56. {
  57. double dlPrice = Convert.ToDouble(((Convert.ToDouble(ty.amount) / (Convert.ToDouble(item.goods_amount) == 0 ? 1 : Convert.ToDouble(item.goods_amount))) * Convert.ToDouble(item.post_fee) / Convert.ToDouble(ty.num) + Convert.ToDouble(ty.price)).ToString("f4"));
  58. dlSum = dlSum - dlPrice * Convert.ToDouble(ty.num);
  59. sb.AppendLine(string.Format(newSql, new object[] { item.purchase_id, ty.rec_id, _ConvertStr(ty.spec_no), _ConvertNotStr(ty.num), dlPrice, _ConvertNotStr(ty.tax) }));
  60. }else
  61. {
  62. sb.AppendLine(string.Format(newSql, new object[] { item.purchase_id, ty.rec_id, _ConvertStr(ty.spec_no), _ConvertNotStr(ty.num), (Convert.ToDouble(dlSum) / (Convert.ToDouble(ty.num)==0?1: Convert.ToDouble(ty.num))), _ConvertNotStr(ty.tax) }));
  63. }
  64. dlCount = dlCount + 1;
  65. }
  66. sb.AppendLine("end");
  67. _InsertIntoTempDb(sb.ToString(), item.purchase_no);
  68. }
  69. }
  70. protected override void _DeleteDup()
  71. {
  72. _operType = "删除采购订单中间表重复数据";
  73. //string sql = "delete a from {0}..PO_Pomain a,PO_Podetails b,{1}..PO_Pomain c,PO_Podetails d where a.POID = b.POID and b.POID=c.POID and c.POID=d.POID";
  74. string sql1 = "delete a from {0}..PO_Pomain a, {1}..PO_Pomain b where a.POID = b.cdefine5 ";
  75. string sql2 = "delete a from {0}..PO_Podetails a, {1}..PO_Podetails b where a.POID = b.cdefine27 ";
  76. DbUtils.ExecuteNonQuery(string.Format(sql1, _tempDb.Database, _targetDb.Database), _tempDb);
  77. DbUtils.ExecuteNonQuery(string.Format(sql2, _tempDb.Database, _targetDb.Database), _tempDb);
  78. }
  79. protected override void _LoadNextPage()
  80. {
  81. _proxy = _load.Load<PO_PomainProxy>(_args);
  82. }
  83. }
  84. }