DispatchListUpLoad.cs 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 DispatchListUpLoad : BaseUpLoad
  16. {
  17. //private string __sql = @"if not exists (select * from DispatchList a inner join DispatchLists b on a.DLID=b.DLID where a.DLID= '{0}')
  18. //insert into DispatchList(DLID,cDLCode,cCusCode,cCusName,cPersonCode,dDate,cexch_name,iTaxRate,direction,cVouchType,cSTCode,cDepCode,iExchRate,bFirst,bReturnFlag,bSettleAll,iVTid) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}')
  19. //insert into DispatchLists(DLID,iDLsID,cWhCode,cInvCode,iQuantity,iTaxRate,iTaxUnitPrice,cMemo,bSettleAll,bQANeedCheck,bQAUrgency,bQAChecking,bQAChecked,bcosting) values('{0}','{0}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}')";
  20. private string __sql = @"if not exists (select DLID from DispatchList where DLID= {0}) insert into DispatchList(DLID,cDLCode,cCusCode,cCusName,cPersonCode,direction,cDefine1,cDefine3,cDefine2,cDefine11,bReturnFlag,cDepCode,ddate,cVouchType) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','MX')";//cDefine12,'{21}'
  21. //避免只能插入一条子表数据
  22. private string sql = @" if not exists (select DLID from DispatchLists where DLID= {0}) ";
  23. private string newSql = @"insert into DispatchLists(DLID,iDLsID,cWhCode,cInvCode,iQuantity,iTaxRate,iTaxUnitPrice,cMemo,cCusInvCode,iQuotedPrice,cDefine28,cDefine29) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
  24. protected override Result _LoadFirstPage()
  25. {
  26. DispatchListProxy tmp = new DispatchListProxy();
  27. Result rtn = _load.Load<DispatchListProxy>(_args, ref tmp);
  28. _proxy = tmp;
  29. return rtn;
  30. }
  31. protected override void _SetLoader()
  32. {
  33. _load = new DispatchListLoad();
  34. }
  35. protected override void _ImportData()
  36. {
  37. //_operType = "插入采购退货单中间表数据";
  38. _operType = "销售出库插入发货单中间表";
  39. Stockin_List[] entitys = ((DispatchListProxy)_proxy).stockin_list;
  40. if (entitys == null || entitys.Length == 0) return;
  41. StringBuilder sb = new StringBuilder();
  42. foreach (Stockin_List item in entitys)
  43. {
  44. //单据类型编码默认05,销售类型编码默认MX,部门编码默认101
  45. sb.AppendLine(string.Format(__sql, new object[] { item.stockin_id, _ConvertStr(item.order_no), _ConvertStr(item.customer_no), _ConvertStr(item.customer_name), _ConvertStr("5"), 1, _ConvertStr(item.order_type), _ConvertStr(item.platform_id), _ConvertStr(item.shop_no), _ConvertStr(item.shop_name),1,"0",item.created_time }));//, "温春"
  46. sb.AppendLine(string.Format(sql, new object[] { item.stockin_id }));
  47. Details_List[] dl = item.details_list;
  48. sb.AppendLine("begin");
  49. foreach (Details_List ty in dl)
  50. {
  51. //item.warehouse_no = (item.warehouse_no.Length > 10) ? item.warehouse_no.Substring(0, 10) : item.warehouse_no;
  52. sb.AppendLine(string.Format(newSql, new object[] { item.stockin_id, ty.rec_id, _ConvertStr(item.warehouse_no), _ConvertStr(ty.spec_no), _ConvertStr(ty.goods_count), _ConvertStr(ty.tax), (_ConvertNotStr(ty.src_price) + (Convert.ToDouble(_ConvertNotStr(ty.src_price)) * Convert.ToDouble(_ConvertNotStr(ty.tax)))), _ConvertStr(ty.remark), _ConvertStr(item.warehouse_no),_ConvertNotStr(ty.src_price), _ConvertStr(item.src_order_no),_ConvertNotStr(ty.src_price) }));
  53. }
  54. sb.AppendLine("end");
  55. _InsertIntoTempDb(sb.ToString(), item.order_no);
  56. }
  57. }
  58. protected override void _DeleteDup()
  59. {
  60. //_operType = "删除销售出库中间表重复数据";
  61. ////string sql = "delete a from {0}..DispatchList a,DispatchLists b,{1}..DispatchList c,DispatchLists d where a.DLID = b.DLID and b.DLID=c.DLID and c.DLID=d.DLID";
  62. //string sql1 = "delete a from {0}..DispatchList a, {1}..DispatchList b where a.DLID = b.cdefine5 ";
  63. //string sql2 = "delete a from {0}..DispatchLists a, {1}..DispatchLists b where a.DLID = b.cdefine27 ";
  64. //DbUtils.ExecuteNonQuery(string.Format(sql1, _tempDb.Database, _targetDb.Database), _tempDb);
  65. //DbUtils.ExecuteNonQuery(string.Format(sql2, _tempDb.Database, _targetDb.Database), _tempDb);
  66. }
  67. protected override void _LoadNextPage()
  68. {
  69. _proxy = _load.Load<DispatchListProxy>(_args);
  70. }
  71. }
  72. }