StockUpLoad.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. {
  13. /// <summary>
  14. /// 库存现存量上传中间库
  15. /// </summary>
  16. public class StockUpLoad : BaseUpLoad
  17. {
  18. private string __sql = "if not exists(select 1 from stock where cinvcode = '{0}' and cwhcode = '{1}') insert into stock(cinvcode, cwhcode, qty, price) values('{0}','{1}','{2}','{3}')";
  19. protected override Result _LoadFirstPage()
  20. {
  21. StockProxy tmp = new StockProxy();
  22. Result rtn = _load.Load<StockProxy>(_args, ref tmp);
  23. _proxy = tmp;
  24. return rtn;
  25. }
  26. protected override void _SetLoader()
  27. {
  28. _load = new StockLoad();
  29. }
  30. protected override void _ImportData()
  31. {
  32. _operType = "插入库存现存量中间表数据";
  33. Stock[] entitys = ((StockProxy)_proxy).stocks;
  34. StringBuilder sb = new StringBuilder();
  35. foreach (Stock item in entitys)
  36. {
  37. if (Convert.ToDecimal(item.stock_num) > 0)
  38. {
  39. sb.Append(string.Format(__sql, new object[] { item.spec_no, item.warehouse_no, item.stock_num, item.cost_price }));
  40. _InsertIntoTempDb(sb.ToString(), item.spec_no + "~~~" + item.warehouse_no);
  41. }
  42. }
  43. }
  44. protected override void _LoadNextPage()
  45. {
  46. _proxy = _load.Load<StockProxy>(_args);
  47. }
  48. protected override void _DeleteDup()
  49. {
  50. _operType = "删除库存现存量中间表重复数据";
  51. string sql = @"delete a from stock a,stock b where a.cinvcode = b.cinvcode and a.cwhcode = b.cwhcode and a.processflag=0 and b.processflag=1";
  52. DbUtils.ExecuteNonQuery(sql, _tempDb);
  53. }
  54. }
  55. }