TradeUpLoad.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using cuidian.Common;
  2. using cuidian.Sql;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using WdtUtils;
  10. using WdtUtils.Load;
  11. using WdtUtils.Proxy;
  12. namespace WangToTempDb
  13. { /// <summary>
  14. /// 旺店通销售订单上传中间库
  15. /// </summary>
  16. public class TradeUpLoad : BaseUpLoad
  17. {
  18. //private string __sql = @"if not exists (select * from SO_SOMain as a inner join SO_SODetails as b on a.ID=b.ID where a.ID= '{0}') insert into SO_SOMain(ID,cSOCode,dDate,cCusCode,cCusName,iTaxRate,cPersonCode,cVerifier,cexch_name,direction,cSTCode,cDepCode,bReturnFlag,iVTid,cBusType) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}') insert into SO_SODetails(ID,cInvCode,iQuantity,dPreDate,iTaxRate,iQuotedPrice,iSOsID) values('{0}','{15}','{16}','{17}','{18}','{19}','{0}')";
  19. private string __sql = @"if not exists (select ID from SO_SOMain where ID= {0}) insert into SO_SOMain(ID,cSOCode,dDate,cCusCode,cCusName,iTaxRate,cPersonCode,cVerifier,cexch_name,direction,cSTCode,cDepCode,bReturnFlag,iVTid,cBusType,platform_id,ccontactname,cDefine1,cDefine2,cDefine11) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}')";
  20. //避免只能插入一条子表数据
  21. private string sql = @" if not exists (select ID from SO_SODetails where ID= {0}) ";
  22. private string newSql = @"insert into SO_SODetails(ID,cInvCode,iQuantity,dPreDate,iTaxRate,iQuotedPrice,iSOsID,iNatMoney) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')";
  23. protected override Result _LoadFirstPage()
  24. {
  25. TradeProxy tmp = new TradeProxy();
  26. Result rtn = _load.Load<TradeProxy>(_args, ref tmp);
  27. _proxy = tmp;
  28. return rtn;
  29. }
  30. protected override void _SetLoader()
  31. {
  32. _load = new TradeLoad();
  33. }
  34. protected override void _ImportData()
  35. {
  36. _operType = "插入销售订单中间表数据";
  37. Trade[] entitys = ((TradeProxy)_proxy).trades;
  38. if (entitys == null || entitys.Length == 0) return;
  39. StringBuilder sb = new StringBuilder();
  40. foreach (Trade item in entitys)
  41. {
  42. item.salesman_id = _ConvertStr(item.salesman_id);//业务员ID
  43. item.fullname = _ConvertStr(item.fullname);//业务员姓名
  44. //销售部门默认取101,销售类型默认取MX,业务类型默认取普通销售
  45. //sb.AppendLine(string.Format(__sql, new object[] { item.trade_id, item.trade_no, item.created, item.customer_no, item.buyer_nick, item.tax_rate, item.salesman_id, item.checker_id, item.currency, 1, "MX", 101, 0, 95, "普通销售", item.goods_list[0].goods_no, item.goods_list[0].num, item.goods_list[0].created, item.goods_list[0].tax_rate, item.goods_list[0].price }));
  46. sb.AppendLine(string.Format(__sql, new object[] { item.trade_id, _ConvertStr(item.trade_no), item.created, _ConvertStr(item.customer_no), _ConvertStr(item.buyer_nick),_ConvertNotStr( item.tax_rate), item.salesman_id, _ConvertStr(item.checker_id), _ConvertStr(item.currency), 1, _ConvertStr(AppSeting.Instance.GetValue("ecSTCode")), _ConvertStr(AppSeting.Instance.GetValue("ecDepCode")), 0, 95, _ConvertStr("普通销售"), _ConvertStr(item.platform_id), _ConvertStr(item.fullname), _ConvertStr(item.trade_type), _ConvertStr(item.shop_no),_ConvertStr(item.shop_name) }));
  47. sb.AppendLine(string.Format(sql, new object[] { item.trade_id }));
  48. Goods_List[] gl = item.goods_list;
  49. sb.AppendLine("begin");
  50. foreach (Goods_List ty in gl)
  51. {
  52. // sb.AppendLine(string.Format(newSql , new object[] { item.trade_id, ty.goods_no, ty.num, ty.created, ty.tax_rate, ty.price, ty.trade_id }));
  53. sb.AppendLine(string.Format(newSql, new object[] { item.trade_id, _ConvertStr(ty.spec_no), _ConvertNotStr(ty.num), ty.created, _ConvertNotStr(ty.tax_rate), _ConvertNotStr(ty.price), ty.trade_id, _ConvertNotStr(ty.order_price) }));
  54. }
  55. sb.AppendLine("end");
  56. _InsertIntoTempDb(sb.ToString(), item.trade_no);
  57. }
  58. }
  59. protected override void _DeleteDup()
  60. {
  61. _operType = "删除销售订单中间表重复数据";
  62. //string sql = "delete a from {0}..SO_SOMain a,SO_SODetails b,{1}..SO_SOMain c,SO_SODetails d where a.ID = b.ID and b.ID=c.ID and c.ID=d.ID";
  63. string sql1 = "delete a from {0}..SO_SOMain a, {1}..SO_SOMain b where a.ID = b.cdefine5";
  64. string sql2 = "delete a from {0}..SO_SODetails a, {1}..SO_SODetails 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<TradeProxy>(_args);
  71. }
  72. }
  73. }