123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using cuidian.Common;
- using cuidian.Sql;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WdtUtils;
- using WdtUtils.Load;
- using WdtUtils.Proxy;
- namespace WangToTempDb
- { /// <summary>
- /// 旺店通采购退货单上传中间库
- /// </summary>
- public class PurchaseUpLoad : BaseUpLoad
- {
- //private string __sql = @"if not exists (select * from PU_ArrivalVouch a inner join PU_ArrivalVouchs b on a.ID=b.ID where a.ID= '{0}') insert into PU_ArrivalVouch(ID,cCode,cVenCode,cBusType,cMemo,dDate,direction,iVTid,cexch_name,cMaker,bNegative,iBillType) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}') insert into PU_ArrivalVouchs(Autoid,ID,cInvCode,iQuantity,iNum,iOriTaxCost,cbMemo,iTaxRate) values('{0}','{0}','{12}','{13}','{14}','{15}','{16}','{17}')";
- private string __sql = @"if not exists (select ID from PU_ArrivalVouch where ID= {0}) insert into PU_ArrivalVouch(ID,cCode,cVenCode,cBusType,cMemo,dDate,direction,iVTid,cexch_name,cMaker,bNegative,iBillType) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
- //避免只能插入一条子表数据
- private string sql = @" if not exists (select ID from PU_ArrivalVouchs where ID= {0}) ";
- private string newSql = @"insert into PU_ArrivalVouchs(ID,Autoid,cInvCode,iQuantity,iNum,iOriTaxCost,cbMemo,iTaxRate) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')";
- protected override Result _LoadFirstPage()
- {
- PurchaseProxy tmp = new PurchaseProxy();
- Result rtn = _load.Load<PurchaseProxy>(_args, ref tmp);
- _proxy = tmp;
- return rtn;
- }
- protected override void _SetLoader()
- {
- _load = new PurchaseLoad();
- }
- protected override void _ImportData()
- {
- _operType = "插入采购退货单中间表数据";
- Purchase_List[] entitys = ((PurchaseProxy)_proxy).purchase_list;
- if (entitys == null || entitys.Length == 0) return;
- StringBuilder sb = new StringBuilder();
- foreach (Purchase_List item in entitys)
- {
- //sb.AppendLine(string.Format(__sql, new object[] { item.return_id, item.return_no, item.provider_name, "普通采购", item.remark, item.created, 1, 8169, "人民币", "demo", 1, 1, item.detail_list[0].goods_no, item.detail_list[0].num, item.detail_list[0].num2, item.detail_list[0].price, item.detail_list[0].remark, 17 }));
- sb.AppendLine(string.Format(__sql, new object[] { item.return_id, _ConvertStr(item.return_no), _ConvertStr(item.provider_name.Length<20? item.provider_name:item.provider_name.Substring(0,20)), _ConvertStr("普通采购"), _ConvertStr(item.remark), item.created, 1, 8169, _ConvertStr("人民币"), _ConvertStr("demo"), 1, 1 }));
- sb.AppendLine(string.Format(sql, new object[] { item.return_id }));
- Detail_List[] dl = item.detail_list;
- sb.AppendLine("begin");
- foreach (Detail_List ty in item.detail_list)
- {
- sb.AppendLine(string.Format(newSql,new object[] { item.return_id, ty.provider_goods_no, _ConvertStr(ty.spec_no),_ConvertNotStr( ty.num),_ConvertNotStr( ty.num2),_ConvertNotStr( ty.price), _ConvertStr(ty.remark), 13 }));
-
- }
- sb.AppendLine("end");
- _InsertIntoTempDb(sb.ToString(), item.return_no);
- }
-
- }
- protected override void _DeleteDup()
- {
- _operType = "删除采购退货单中间表重复数据";
- //string sql = "delete a from {0}..PU_ArrivalVouch a,PU_ArrivalVouchs b,{1}..PU_ArrivalVouch c,PU_ArrivalVouchs d where a.ID = b.ID and b.ID=c.ID and c.ID=d.ID";
- string sql1 = "delete a from {0}..PU_ArrivalVouch a, {1}..PU_ArrivalVouch b where a.ID = b.cdefine5 ";
- string sql2 = "delete a from {0}..PU_ArrivalVouchs a, {1}..PU_ArrivalVouchs b where a.ID = b.cdefine27 ";
- DbUtils.ExecuteNonQuery(string.Format(sql1, _tempDb.Database, _targetDb.Database), _tempDb);
- DbUtils.ExecuteNonQuery(string.Format(sql2, _tempDb.Database, _targetDb.Database), _tempDb);
- }
-
- protected override void _LoadNextPage()
- {
- _proxy = _load.Load<PurchaseProxy>(_args);
- }
- }
- }
|