InvoiceItemaUpLoad.cs 5.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 cuidian.Common;
  11. namespace WangToTempDb
  12. {
  13. /// <summary>
  14. /// 将旺店通采购入库信息导入中间库
  15. /// </summary>
  16. public class InvoiceItemaUpLoad : BaseUpLoad
  17. {
  18. //private string __sql = @"if not exists (select * from RdRecord01 a inner join RdRecords01 b on a.ID=b.ID where a.ID= '{0}') insert into RdRecord01(ID,cCode,cSource,cWhCode,dModifyDate,dVeriDate,dDate,cOrderCode,cMemo,cBusType,cVenCode,bRdFlag,bTransFlag,bIsSTQc,direction,cVouchType) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}') insert into RdRecords01(AutoID,ID,cInvCode,iFlag,iQuantity,iUnitCost,iMatSettleState,iBillSettleCount) values('{16}','{0}','{17}','{18}','{19}','{20}','{21}','{22}')";
  19. private string __sql = @"if not exists (select ID from RdRecord01 where ID= {0}) insert into RdRecord01(ID,cCode,cSource,cWhCode,dModifyDate,dDate,cOrderCode,cMemo,cBusType,cVenCode,bRdFlag,bTransFlag,bIsSTQc,direction,cVouchType,cDefine12,cDefine1) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}')";
  20. //避免只能插入一条子表数据
  21. private string sql = @" if not exists (select ID from RdRecords01 where ID= {0}) ";
  22. private string newSql = @"insert into RdRecords01(ID,AutoID,cInvCode,iFlag,iQuantity,iUnitCost,iMatSettleState,iBillSettleCount,cDefine22,cDefine26) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}' )";
  23. protected override Result _LoadFirstPage()
  24. {
  25. InvoiceItemaProxy tmp = new InvoiceItemaProxy();
  26. Result rtn = _load.Load<InvoiceItemaProxy>(_args, ref tmp);
  27. _proxy = tmp;
  28. return rtn;
  29. }
  30. protected override void _SetLoader()
  31. {
  32. _load = new InvoiceItemaLoad();
  33. }
  34. protected override void _ImportData()
  35. {
  36. _operType = "插入采购入库中间表数据";
  37. Stockin_List[] entitys = ((InvoiceItemaProxy)_proxy).stockin_list;
  38. if (entitys == null || entitys.Length == 0) return;
  39. StringBuilder sb = new StringBuilder();
  40. foreach (Stockin_List item in entitys)
  41. {
  42. if (!item.status.Trim().Equals("60"))
  43. {
  44. continue;
  45. }
  46. //sb.AppendLine(string.Format(__sql, new object[] { item.stockin_id, item.order_no, "库存", warehouse, item.stockin_time, item.check_time, item.created_time, item.purchase_no, item.remark, "普通采购", item.provider_no, 1, 0, 0, 1, "01", item.details_list[0].rec_id, item.details_list[0].goods_no, 0, item.details_list[0].goods_count, item.details_list[0].src_price, 0, 0 }));
  47. //item.warehouse_no=(item.warehouse_no.Length > 10) ? item.warehouse_no.Substring(0, 10) : item.warehouse_no;
  48. sb.AppendLine(string.Format(__sql, new object[] { item.stockin_id, _ConvertStr(item.order_no), _ConvertStr("库存"), _ConvertStr(item.warehouse_no), item.stockin_time, item.created_time, _ConvertStr(item.purchase_no), _ConvertStr(item.remark), _ConvertStr("普通采购"), _ConvertStr(item.provider_no), 1, 0, 0, 1, _ConvertStr("01"), _ConvertStr(item.src_order_no), _ConvertNotStr(item.status) }));
  49. sb.AppendLine(string.Format(sql, new object[] { item.stockin_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.stockin_id, ty.rec_id, _ConvertStr(ty.spec_no), 0, _ConvertNotStr(ty.goods_count), (Convert.ToDouble(ty.total_cost) / (Convert.ToDouble(item.goods_amount) == 0 ? 1 : Convert.ToDouble(item.goods_amount))) * Convert.ToDouble(item.post_fee) / Convert.ToDouble(ty.goods_count) + Convert.ToDouble(ty.src_price), 0, 0,ty.right_cost, (Convert.ToDouble(ty.total_cost) / (Convert.ToDouble(item.goods_amount) == 0 ? 1 : Convert.ToDouble(item.goods_amount))) * Convert.ToDouble(item.post_fee)/Convert.ToDouble(ty.goods_count) + Convert.ToDouble(ty.src_price) }));
  55. // DbUtils.ExecuteNonQuery(string.Format(" update rdrecords01 set cDefine26={0} where id =(select id from rdrecord01 where ccode='{1}') and cinvcode='{2}' ", ( Convert.ToDouble(ty.total_cost)/(Convert.ToDouble(item.goods_amount)==0?1: Convert.ToDouble(item.goods_amount))) * Convert.ToDouble(item.post_fee) / Convert.ToDouble(ty.goods_count) + Convert.ToDouble(ty.src_price),item.order_no,ty.spec_no),ConnectionUtils.Instance.GetConnection());
  56. }
  57. sb.AppendLine("end");
  58. _InsertIntoTempDb(sb.ToString(), item.order_no);
  59. }
  60. }
  61. protected override void _DeleteDup()
  62. {
  63. _operType = "删除采购入库中间表重复数据";
  64. //string sql = "delete a from {0}..RdRecord01 a,RdRecords01 b,{1}..RdRecord01 c,RdRecords01 d where a.ID = b.ID and b.ID=c.ID and c.ID=d.ID";
  65. string sql1 = "delete a from {0}..RdRecord01 a, {1}..RdRecord01 b where a.ID = b.cdefine5 ";
  66. string sql2 = "delete a from {0}..RdRecords01 a, {1}..RdRecords01 b where a.ID = b.cdefine27 ";
  67. DbUtils.ExecuteNonQuery(string.Format(sql1, _tempDb.Database, _targetDb.Database), _tempDb);
  68. DbUtils.ExecuteNonQuery(string.Format(sql2, _tempDb.Database, _targetDb.Database), _tempDb);
  69. }
  70. protected override void _LoadNextPage()
  71. {
  72. _proxy = _load.Load<InvoiceItemaProxy>(_args);
  73. }
  74. }
  75. }