StockinUpLoad.cs 4.8 KB

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