PurchaseUpLoad.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 PurchaseUpLoad : BaseUpLoad
  16. {
  17. //private string __sql = @"if not exists (select * from PU_ArrivalVouch a inner join PU_ArrivalVouchs b on a.ID=b.ID where a.ID= '{0}') insert into PU_ArrivalVouch(ID,cCode,cVenCode,cBusType,cMemo,dDate,direction,iVTid,cexch_name,cMaker,bNegative,iBillType) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}') insert into PU_ArrivalVouchs(Autoid,ID,cInvCode,iQuantity,iNum,iOriTaxCost,cbMemo,iTaxRate) values('{0}','{0}','{12}','{13}','{14}','{15}','{16}','{17}')";
  18. private string __sql = @"if not exists (select ID from PU_ArrivalVouch where ID= {0}) insert into PU_ArrivalVouch(ID,cCode,cVenCode,cBusType,cMemo,dDate,direction,iVTid,cexch_name,cMaker,bNegative,iBillType) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
  19. //避免只能插入一条子表数据
  20. private string sql = @" if not exists (select ID from PU_ArrivalVouchs where ID= {0}) ";
  21. private string newSql = @"insert into PU_ArrivalVouchs(ID,Autoid,cInvCode,iQuantity,iNum,iOriTaxCost,cbMemo,iTaxRate) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')";
  22. protected override Result _LoadFirstPage()
  23. {
  24. PurchaseProxy tmp = new PurchaseProxy();
  25. Result rtn = _load.Load<PurchaseProxy>(_args, ref tmp);
  26. _proxy = tmp;
  27. return rtn;
  28. }
  29. protected override void _SetLoader()
  30. {
  31. _load = new PurchaseLoad();
  32. }
  33. protected override void _ImportData()
  34. {
  35. _operType = "插入采购退货单中间表数据";
  36. Purchase_List[] entitys = ((PurchaseProxy)_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.return_id, item.return_no, item.provider_name, "普通采购", item.remark, item.created, 1, 8169, "人民币", "demo", 1, 1, item.detail_list[0].goods_no, item.detail_list[0].num, item.detail_list[0].num2, item.detail_list[0].price, item.detail_list[0].remark, 17 }));
  42. sb.AppendLine(string.Format(__sql, new object[] { item.return_id, _ConvertStr(item.return_no), _ConvertStr(item.provider_name.Length<20? item.provider_name:item.provider_name.Substring(0,20)), _ConvertStr("普通采购"), _ConvertStr(item.remark), item.created, 1, 8169, _ConvertStr("人民币"), _ConvertStr("demo"), 1, 1 }));
  43. sb.AppendLine(string.Format(sql, new object[] { item.return_id }));
  44. Detail_List[] dl = item.detail_list;
  45. sb.AppendLine("begin");
  46. foreach (Detail_List ty in item.detail_list)
  47. {
  48. sb.AppendLine(string.Format(newSql,new object[] { item.return_id, ty.provider_goods_no, _ConvertStr(ty.spec_no),_ConvertNotStr( ty.num),_ConvertNotStr( ty.num2),_ConvertNotStr( ty.price), _ConvertStr(ty.remark), 13 }));
  49. }
  50. sb.AppendLine("end");
  51. _InsertIntoTempDb(sb.ToString(), item.return_no);
  52. }
  53. }
  54. protected override void _DeleteDup()
  55. {
  56. _operType = "删除采购退货单中间表重复数据";
  57. //string sql = "delete a from {0}..PU_ArrivalVouch a,PU_ArrivalVouchs b,{1}..PU_ArrivalVouch c,PU_ArrivalVouchs d where a.ID = b.ID and b.ID=c.ID and c.ID=d.ID";
  58. string sql1 = "delete a from {0}..PU_ArrivalVouch a, {1}..PU_ArrivalVouch b where a.ID = b.cdefine5 ";
  59. string sql2 = "delete a from {0}..PU_ArrivalVouchs a, {1}..PU_ArrivalVouchs b where a.ID = b.cdefine27 ";
  60. DbUtils.ExecuteNonQuery(string.Format(sql1, _tempDb.Database, _targetDb.Database), _tempDb);
  61. DbUtils.ExecuteNonQuery(string.Format(sql2, _tempDb.Database, _targetDb.Database), _tempDb);
  62. }
  63. protected override void _LoadNextPage()
  64. {
  65. _proxy = _load.Load<PurchaseProxy>(_args);
  66. }
  67. }
  68. }