DispatchListSendUpLoad.cs 5.4 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 WangToTempDb;
  9. using WdtUtils;
  10. using WdtUtils.Load;
  11. using WdtUtils.Proxy;
  12. namespace WangToTempDb
  13. { /// <summary>
  14. /// 旺店通销售发货单上传中间库
  15. /// </summary>
  16. public class DispatchListSendUpLoad : BaseUpLoad
  17. {
  18. //private string __sql = @"if not exists (select * from DispatchList a inner join DispatchLists b on a.DLID=b.DLID where a.DLID= '{0}')
  19. //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}')
  20. //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}')";
  21. 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,cDefine12,bReturnFlag,cDepCode,cDefine10,cSourceCode,ddate,cVouchType ) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','MX')";
  22. //避免只能插入一条子表数据
  23. private string sql = @" if not exists (select DLID from DispatchLists where DLID= {0}) ";
  24. 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}')";
  25. protected override Result _LoadFirstPage()
  26. {
  27. DispatchListProxy tmp = new DispatchListProxy();
  28. Result rtn = _load.Load<DispatchListProxy>(_args, ref tmp);
  29. _proxy = tmp;
  30. return rtn;
  31. }
  32. protected override void _SetLoader()
  33. {
  34. _load = new DispatchLisSendtLoad();
  35. }
  36. protected override void _ImportData()
  37. {
  38. _operType = "插入销售出库中间表数据";
  39. Stockout_List[] entitys = ((DispatchListProxy)_proxy).stockout_list;
  40. if (entitys == null || entitys.Length == 0) return;
  41. StringBuilder sb = new StringBuilder();
  42. foreach (Stockout_List item in entitys)
  43. {
  44. DbUtils.ExecuteNonQuery(string.Format("update wtu..dispatchlist set ddate='{0}' where cDLCode='{1}'", item.consign_time, item.order_no), ConnectionUtils.Instance.GetConnection());
  45. string deptcode = DbUtils.ExecuteScalar(string.Format(@" select cDepCode from {0}..person where cPersonName='{1}' ",
  46. ConnectionUtils.Instance.GetConnection().Database, item.salesman_name),
  47. ConnectionUtils.Instance.GetConnection("TempDB")).ToString();
  48. sb.AppendLine(string.Format(__sql, new object[] { item.stockout_id, _ConvertStr(item.order_no), _ConvertStr(item.customer_no), _ConvertStr(item.customer_name), _ConvertNotStr(item.salesman_no).Trim().Equals("SYSTEM") ? "0" : _ConvertNotStr(item.salesman_no), 1, _ConvertStr(item.trade_type), _ConvertStr(item.platform_id), _ConvertStr(item.shop_no), _ConvertStr(item.shop_name), _ConvertStr(item.salesman_name), 0, _ConvertStr(deptcode), _ConvertNotStr(item.paid), _ConvertStr(item.status), item.consign_time }));
  49. sb.AppendLine(string.Format(sql, new object[] { item.stockout_id }));
  50. Details_List[] dl = item.details_list;
  51. sb.AppendLine("begin");
  52. foreach (Details_List ty in dl)
  53. {
  54. sb.AppendLine(string.Format(newSql, new object[] { item.stockout_id, ty.rec_id, _ConvertStr(item.warehouse_no), _ConvertStr(ty.spec_no), _ConvertNotStr(ty.goods_count), _ConvertNotStr(ty.tax_rate), (_ConvertNotStr(ty.market_price) + (Convert.ToDouble(_ConvertNotStr(ty.market_price)) * Convert.ToDouble(_ConvertNotStr(ty.tax_rate)))), _ConvertStr(ty.remark), _ConvertStr(item.warehouse_no), _ConvertNotStr(ty.sell_price), _ConvertStr(item.src_order_no), _ConvertNotStr(ty.total_amount) }));
  55. }
  56. sb.AppendLine("end");
  57. _InsertIntoTempDb(sb.ToString(), item.order_no);
  58. }
  59. }
  60. protected override void _DeleteDup()
  61. {
  62. //_operType = "删除销售出库重复数据";
  63. ////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";
  64. //string sql1 = "delete a from {0}..DispatchList a, {1}..DispatchList b where a.DLID = b.cdefine5 ";
  65. //string sql2 = "delete a from {0}..DispatchLists a, {1}..DispatchLists b where a.DLID = b.cdefine27 ";
  66. //DbUtils.ExecuteNonQuery(string.Format(sql1, _tempDb.Database, _targetDb.Database), _tempDb);
  67. //DbUtils.ExecuteNonQuery(string.Format(sql2, _tempDb.Database, _targetDb.Database), _tempDb);
  68. }
  69. protected override void _LoadNextPage()
  70. {
  71. _proxy = _load.Load<DispatchListProxy>(_args);
  72. }
  73. }
  74. }