StockoutUpLoad.cs 4.8 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 StockoutUpLoad : BaseUpLoad
  16. {
  17. //private string __sql = @"if not exists (select * from RdRecord09 as a inner join RdRecords09 as b on a.ID=b.ID where a.ID= '{0}')
  18. //insert into RdRecord09(ID,cCode,cSource,cWhCode,dDate,cBusType,cMemo,cMaker,bRdFlag,cVouchType,bTransFlag,bIsSTQc) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')
  19. //insert into RdRecords09(AutoID,ID,cInvCode,iFlag,iQuantity,iUnitCost) values('{12}','{0}','{13}','{14}','{15}','{16}')";
  20. private string __sql = @"if not exists (select ID from RdRecord09 where ID= {0}) insert into RdRecord09(ID,cCode,cSource,cWhCode,dDate,cBusType,cMemo,cMaker,bRdFlag,cVouchType,bTransFlag,bIsSTQc,direction,cDefine15) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',1,'{12}') ";
  21. //避免只能插入一条子表数据
  22. private string sql = @"if not exists (select * from RdRecords09 where ID= {0}) ";
  23. private string newSql = @"insert into RdRecords09(ID,AutoID,cInvCode,iFlag,iQuantity,iUnitCost) values('{0}','{1}','{2}','{3}','{4}','{5}')";
  24. protected override Result _LoadFirstPage()
  25. {
  26. StockoutProxy tmp = new StockoutProxy();
  27. Result rtn = _load.Load<StockoutProxy>(_args, ref tmp);
  28. _proxy = tmp;
  29. return rtn;
  30. }
  31. protected override void _SetLoader()
  32. {
  33. _load = new StockoutLoad();
  34. }
  35. protected override void _ImportData()
  36. {
  37. _operType = "插入其他出库单中间表数据";
  38. Stockout_List[] entitys = ((StockoutProxy)_proxy).stockout_list;
  39. if (entitys == null || entitys.Length == 0) return;
  40. StringBuilder sb = new StringBuilder();
  41. foreach (Stockout_List item in entitys)
  42. {
  43. if (item.remark.Contains("来源U8") || (!item.order_type.Equals("2") && !item.order_type.Equals("4") && !item.order_type.Equals("7")) || item.remark.Contains("库存管理"))//|| item.remark.Contains("库存管理")
  44. {
  45. continue;
  46. }
  47. //sb.AppendLine(string.Format(__sql, new object[] { item.stockout_id, item.order_no, item.src_order_no, item.warehouse_no,item.consign_time,item.order_type_name,item.remark,item.operator_name,0,"09",0,0,1, item.details_list[0].rec_id, item.details_list[0].goods_no, 0, item.details_list[0].goods_count, item.details_list[0].sell_price }));
  48. //item.warehouse_no = (item.warehouse_no.Length > 10) ? item.warehouse_no.Substring(0, 10) : item.warehouse_no;
  49. sb.AppendLine(string.Format(__sql, new object[] { item.stockout_id, _ConvertStr(item.order_no), _ConvertStr(item.src_order_no), _ConvertStr(item.warehouse_no), item.consign_time, _ConvertStr(item.order_type_name), _ConvertStr(item.remark), _ConvertStr(item.operator_name),_ConvertNotStr( item.status), _ConvertStr("09"), 0, 0,_ConvertNotStr(item.order_type) }));//cVouchType单据类型编码,bTransFlag是否传递 ,bIsSTQc库存期初标志
  50. sb.AppendLine(string.Format(sql, new object[] { item.stockout_id }));
  51. Details_List[] dl = item.details_list;
  52. sb.AppendLine("begin");
  53. foreach (Details_List ty in dl)
  54. {
  55. sb.AppendLine(string.Format(newSql, new object[] { item.stockout_id, ty.rec_id, _ConvertStr(ty.spec_no), 0,_ConvertNotStr( ty.goods_count),_ConvertNotStr(ty.cost_price) }));
  56. }
  57. sb.AppendLine("end");
  58. _InsertIntoTempDb(sb.ToString(), item.order_no);
  59. }
  60. }
  61. protected override void _DeleteDup()
  62. {
  63. //_operType = "删除其他出库单中间表重复数据";
  64. ////string sql = "delete a from {0}..RdRecord09 a,RdRecords09 b,{1}..RdRecord09 c,RdRecords09 d where a.ID = b.ID and b.ID=c.ID and c.ID=d.ID";
  65. //string sql1 = "delete a from {0}..RdRecord09 a, {1}..RdRecord09 b where a.ID = b.cdefine5 ";
  66. //string sql2 = "delete a from {0}..RdRecords09 a, {1}..RdRecords09 b where a.ID = b.cdefine27 ";
  67. //DbUtils.ExecuteNonQuery(string.Format(sql1, _tempDb.Database, _targetDb.Database), _tempDb);
  68. //DbUtils.ExecuteNonQuery(string.Format(sql2, _tempDb.Database, _targetDb.Database), _tempDb);
  69. }
  70. protected override void _LoadNextPage()
  71. {
  72. _proxy = _load.Load<StockoutProxy>(_args);
  73. }
  74. }
  75. }