12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WdtUtils;
- using WdtUtils.Proxy;
- using WdtUtils.Load;
- using cuidian.Sql;
- using cuidian.Common;
- namespace WangToTempDb
- {
- /// <summary>
- /// 将旺店通采购入库信息导入中间库
- /// </summary>
- public class InvoiceItemaUpLoad : BaseUpLoad
- {
- //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}')";
- 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}')";
- //避免只能插入一条子表数据
- private string sql = @" if not exists (select ID from RdRecords01 where ID= {0}) ";
- 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}' )";
- protected override Result _LoadFirstPage()
- {
- InvoiceItemaProxy tmp = new InvoiceItemaProxy();
- Result rtn = _load.Load<InvoiceItemaProxy>(_args, ref tmp);
- _proxy = tmp;
- return rtn;
- }
- protected override void _SetLoader()
- {
- _load = new InvoiceItemaLoad();
- }
- protected override void _ImportData()
- {
- _operType = "插入采购入库中间表数据";
- Stockin_List[] entitys = ((InvoiceItemaProxy)_proxy).stockin_list;
- if (entitys == null || entitys.Length == 0) return;
- StringBuilder sb = new StringBuilder();
- foreach (Stockin_List item in entitys)
- {
- if (!item.status.Trim().Equals("60"))
- {
- continue;
- }
- //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 }));
- //item.warehouse_no=(item.warehouse_no.Length > 10) ? item.warehouse_no.Substring(0, 10) : item.warehouse_no;
- 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) }));
- sb.AppendLine(string.Format(sql, new object[] { item.stockin_id }));
- Details_List[] dl = item.details_list;
- sb.AppendLine("begin");
- foreach (Details_List ty in dl)
- {
-
- 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) }));
- // 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());
- }
- sb.AppendLine("end");
- _InsertIntoTempDb(sb.ToString(), item.order_no);
- }
- }
- protected override void _DeleteDup()
- {
- _operType = "删除采购入库中间表重复数据";
- //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";
- string sql1 = "delete a from {0}..RdRecord01 a, {1}..RdRecord01 b where a.ID = b.cdefine5 ";
- string sql2 = "delete a from {0}..RdRecords01 a, {1}..RdRecords01 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<InvoiceItemaProxy>(_args);
- }
- }
- }
|