InventoryUpLoad.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using WdtUtils;
  7. using WdtUtils.Proxy;
  8. using WdtUtils.Load;
  9. using cuidian.Sql;
  10. using Logs;
  11. namespace WangToTempDb
  12. {
  13. /// <summary>
  14. /// 将旺店通存货信息导入中间库
  15. /// </summary>
  16. public class InventoryUpLoad : BaseUpLoad
  17. { //d.spec_no,item.brand_name,d.lowest_price,item.spec_count,item.barcode,d.retail_price,d.length,d.width,d.height,d.weight //
  18. private string __sql = "if not exists (select 1 from inventory where cinvcode = '{0}') insert into inventory(cinvcode,cinvname,cinvstd,itaxrate,bPurchase,cInvDefine4,cInvDefine7,cInvDefine13,cInvDefine10,cInvDefine9,fRetailPrice,cInvDefine1,cInvDefine2,cInvDefine3,cInvDefine14,cInvDefine5,cInvDefine6,cInvDefine8) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}')";
  19. protected override Result _LoadFirstPage()
  20. {
  21. InventoryProxy tmp = new InventoryProxy();
  22. Result rtn = _load.Load<InventoryProxy>(_args, ref tmp);
  23. _proxy = tmp;
  24. return rtn;
  25. }
  26. protected override void _SetLoader()
  27. {
  28. _load = new InventoryLoad();
  29. }
  30. protected override void _ImportData()
  31. {
  32. _operType = "插入存货中间表数据";
  33. Goods_List[] entitys = ((InventoryProxy)_proxy).goods_list;
  34. if (entitys == null || entitys.Length == 0) return ;
  35. //LogHelper.Debug("inventory entitys length = " + entitys.Length.ToString());
  36. StringBuilder sb = new StringBuilder();
  37. int i = 0;
  38. foreach (Goods_List item in entitys)
  39. {
  40. foreach (Spec_List d in item.spec_list)
  41. {
  42. try
  43. {
  44. item.prop4 = Convert.ToDecimal(item.prop4).ToString();
  45. }
  46. catch
  47. {
  48. item.prop4 = "0";
  49. }
  50. i++;
  51. sb.AppendLine(string.Format(__sql, new object[] { _ConvertStr(d.spec_no), _ConvertStr(item.goods_name), _ConvertStr(d.spec_name), _ConvertNotStr(d.tax_rate), 1, _ConvertStr(d.spec_no), _ConvertStr(item.brand_name), item.prop4, _ConvertNotStr(item.prop5), _ConvertNotStr(d.barcode).Replace("'", "''"), _ConvertNotStr(d.retail_price) , _ConvertStr(d.length), _ConvertStr(d.width), _ConvertStr(d.height), _ConvertNotStr(d.weight) , _ConvertStr(item.prop1), _ConvertStr(item.prop2), _ConvertStr(item.prop3).Length<60? _ConvertStr(item.prop3):_ConvertStr(item.prop3).Substring(0,60) }));
  52. _InsertIntoTempDb(sb.ToString(), item.spec_no);
  53. }
  54. }
  55. //LogHelper.Debug("inventory Goods_List length = " + i.ToString());
  56. }
  57. protected override void _DeleteDup()
  58. {
  59. _operType = "删除存货中间表重复数据";
  60. //string sql = "delete a from {0}..inventory a,{1}..inventory b where a.cinvcode = b.cinvcode and processflag = '0'";
  61. string sql = @"delete a from {0}..inventory a,{1}..inventory b where a.cinvcode = b.cinvcode and processflag = '0'";
  62. //where not exists(select cInvCode from {1}..inventory where cinvcode = a.cinvcode)";
  63. DbUtils.ExecuteNonQuery(string.Format(sql, _tempDb.Database, _targetDb.Database), _tempDb);
  64. }
  65. protected override void _LoadNextPage()
  66. {
  67. _proxy = _load.Load<InventoryProxy>(_args);
  68. }
  69. }
  70. }