DownLoadSellReturn.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using cuidian.Common;
  8. using cuidian.OpenApi.Api;
  9. using cuidian.OpenApi.Model;
  10. using cuidian.OpenApi.Utils;
  11. using OperationLog;
  12. using cuidian.Sql;
  13. namespace TempDbToUfida.OpenApi
  14. {
  15. /// <summary>
  16. /// 从中间库将销售订单资料下载到U8数据库
  17. /// </summary>
  18. ///
  19. public delegate bool DelHanderTwo();
  20. public class DownLoadSellReturn : BaseDataDownLoad
  21. {
  22. protected override void _Init()
  23. {
  24. //_loadSql = "select * from DispatchList where processflag=0 and bReturnFlag=1 ";
  25. //base._Init();
  26. }
  27. private int ___bReturnFlag;
  28. protected override void _downLoad()
  29. {
  30. _loadSql = "select * from DispatchList where processflag=0 and bReturnFlag=1 ";
  31. _data = DbUtils.Fill(_loadSql, ConnectionUtils.Instance.GetConnection("TempDB"));
  32. List<string> ids = new List<string>();
  33. int i = 0;
  34. DataSet temp = null;
  35. int num = 0;
  36. //设定开关
  37. bool flag = false;
  38. //获取零售平台订单个数
  39. //int sum = GetCount();
  40. ////获取最后一单数量
  41. //int counts = GetCounts();
  42. //if (_data.Rows.Count > 0)
  43. //{
  44. // temp = __GetTempData(_data.Rows[0]);
  45. // temp.Tables[0].Clear();
  46. // temp.Tables[1].Clear();
  47. //}
  48. #region 不合并订单
  49. foreach (DataRow row in _data.Rows)
  50. {
  51. BusinessObject result = null;
  52. DataSet dd = __GetTempData(row);
  53. Consignment v = new Consignment();
  54. DataTable dt = dd.Tables["DispatchList"];
  55. v.define3 = dt.Rows[0]["cDefine3"].ToString();//平台,用于区分是否为阿里巴巴店铺
  56. v.define1 = dt.Rows[0]["cDefine1"].ToString();//订单类型 1网店销售 2线下零售 3售后换货 4批发业务 5保修换新 6保修完成 7订单补发
  57. string str = dt.Rows[0]["bReturnFlag"].ToString();
  58. v.bReturnFlag = Convert.ToBoolean(dt.Rows[0]["bReturnFlag"]) ? "1" : "0";//退货标识
  59. ___bReturnFlag = Convert.ToInt32(v.bReturnFlag);
  60. #region
  61. if (!v.define3.Equals("9") && v.define1.Equals("1") && v.bReturnFlag.Equals("0")) //(((v.define3.Equals("9") && v.define1.Equals("1")) || (v.define1.Equals("7")) || (!v.define1.Equals("1") && !v.define1.Equals("7")))||v.bReturnFlag.Equals("0")||v.bReturnFlag.Equals("1"))//不合并
  62. {
  63. #region 注释
  64. //if (sum - (99 * num) < 99)
  65. //{
  66. // flag = true;
  67. //}
  68. //if (flag)
  69. //{
  70. // NewMethod(ids, ref i, temp, ref num, row, () => i == counts - 1);
  71. //}
  72. //else
  73. //{
  74. // NewMethod(ids, ref i, temp, ref num, row, () => i == 99);
  75. //}
  76. // i = Convert.ToInt32(DbUtils.ExecuteScalar(string.Format("select count(1) from DispatchList where cDefine3<>'9' and cDefine1<>'1' and cDefine2='{0}' ", dt.Rows[0]["cDefine2"].ToString()), ConnectionUtils.Instance.GetConnection("TempDB")));
  77. #endregion
  78. }
  79. else
  80. {
  81. BasicApi api = null;
  82. if (___bReturnFlag == 0)
  83. {
  84. api = new ConsignmentApi();
  85. }
  86. else
  87. {
  88. api = new ReturnorderApi();
  89. }
  90. result = _ImportData(row);
  91. api.Audit(result.Id);
  92. string newcode = null;
  93. //记录日志
  94. _Log(result, Convert.ToInt32(row["sysid"]), out newcode);
  95. }
  96. #endregion
  97. }
  98. #endregion
  99. //Merge();
  100. }
  101. #region 注释
  102. /// <summary>
  103. /// 合并单专用
  104. /// </summary>
  105. /// <returns></returns>
  106. private void NewMethod(List<string> ids, ref int i, DataSet temp, ref int num, DataRow row, DelHanderTwo del)
  107. {
  108. DataSet ds = __GetTempData(row);
  109. //存300单的第一单
  110. if (i == 0)
  111. {
  112. temp.Tables["DispatchList"].ImportRow(row);
  113. }
  114. if (del())//合并无退货单
  115. {
  116. //把最后一单加上
  117. ids.Add(row["sysid"].ToString());
  118. foreach (DataRow item in ds.Tables["DispatchLists"].Rows)
  119. {
  120. temp.Tables["DispatchLists"].ImportRow(item);
  121. }
  122. //要修改的300单业务ID数据
  123. string[] b = new string[ids.Count];
  124. ids.CopyTo(b);
  125. //String.Join(",", b);
  126. //result = _ImportData(temp[0]);
  127. ConsignmentApi apiTwo = new ConsignmentApi();
  128. Consignment vv = __GetHead(temp);
  129. vv.entry = __GetDetails(temp);
  130. ReturnorderRoot vr = new ReturnorderRoot();
  131. vr.consignment = vv;
  132. BusinessObject resultTwo = apiTwo.Add(JsonUtils.GetJsonString(vr));
  133. //记录日志
  134. string newcode = null;
  135. _Log(resultTwo, Convert.ToInt32(temp.Tables[0].Rows[0]["sysid"]), out newcode);
  136. if (_logFlag)
  137. {
  138. ConsignmentApi api = new ConsignmentApi();
  139. api.Audit(newcode);
  140. _LogSucessTwo(______id, String.Join(",", b));
  141. }
  142. else
  143. {
  144. //跳过第一条
  145. //for (int k = 1; k < b.Length; k++)
  146. //{
  147. // OperationLog.Utils.WriteErrorLog("向U8导入销售出库资料", "sysid = " + b[k] + " " + ______msg);
  148. //}
  149. }
  150. //清空业务表数据
  151. temp.Tables[0].Clear();
  152. temp.Tables[1].Clear();
  153. i = 0;
  154. ids.Clear();
  155. ______id = null;
  156. //300单加一次
  157. num += 1;
  158. }
  159. else
  160. {
  161. ids.Add(row["sysid"].ToString());
  162. foreach (DataRow item in ds.Tables["DispatchLists"].Rows)
  163. {
  164. temp.Tables["DispatchLists"].ImportRow(item);
  165. }
  166. i++;
  167. }
  168. }
  169. #endregion
  170. //合并单专用方法
  171. public void Merge()
  172. {
  173. DataTable dtMg = DbUtils.Fill("select distinct cDefine2 from DispatchList where cDefine3<>'9' and cDefine1='1' and bReturnFlag='0' and processflag='0' ",
  174. ConnectionUtils.Instance.GetConnection("TempDB"));
  175. if (dtMg.Rows.Count <= 0)
  176. {
  177. return;
  178. }
  179. foreach (DataRow mgRow in dtMg.Rows)
  180. {
  181. List<string> ids = new List<string>();
  182. int i = 0;
  183. DataSet temp = null;
  184. int num = 0;
  185. //设定开关
  186. bool flag = false;
  187. DataTable mgTb = null;
  188. mgTb = __GetTempDataMerge(mgRow[0].ToString()).Tables["DispatchList"];
  189. if (dtMg.Rows.Count > 0)
  190. {
  191. temp = __GetTempDataMerge(mgRow[0].ToString());
  192. temp.Tables[0].Clear();
  193. temp.Tables[1].Clear();
  194. }
  195. //获取零售平台订单个数
  196. int sum = GetCount(mgRow[0].ToString());
  197. //获取最后一单数量
  198. int counts = 0; //GetCounts(mgRow[0].ToString());
  199. if (sum % 100 == 0 && sum != 0)
  200. {
  201. counts = 100;
  202. }
  203. else
  204. {
  205. counts = sum % 100;
  206. }
  207. foreach (DataRow mgSingle in mgTb.Rows)
  208. {
  209. if (sum - (99 * num) < 99)
  210. {
  211. flag = true;
  212. }
  213. if (flag)
  214. {
  215. NewMethod(ids, ref i, temp, ref num, mgSingle, () => i == counts - 1);
  216. }
  217. else
  218. {
  219. NewMethod(ids, ref i, temp, ref num, mgSingle, () => i == 99);
  220. }
  221. }
  222. }
  223. }
  224. //合并单专用
  225. private DataSet __GetTempDataMerge(string cDefine2)
  226. {
  227. Dictionary<string, string> args = new Dictionary<string, string>();
  228. args.Add("DispatchList", string.Format("select * from DispatchList where cDefine2 = '{0}' and cDefine3 <> '9' and cDefine1 = '1' and bReturnFlag = '0' and processflag = '0'", cDefine2));
  229. args.Add("DispatchLists", string.Format(@"select *from DispatchLists where dlid in(select dlid from DispatchList where cDefine2='{0}' and cDefine3<>'9' and cDefine1='1' and bReturnFlag='0' and processflag='0')
  230. ", cDefine2));
  231. DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection("TempDB"));
  232. args.Remove("DispatchList");
  233. args.Remove("DispatchLists");
  234. return ds;
  235. }
  236. private int GetCount(string cDefine2)
  237. {
  238. return Convert.ToInt32(DbUtils.ExecuteScalar(string.Format("select count(1) from DispatchList where cDefine2='{0}' and cDefine3<>'9' and cDefine1='1' and bReturnFlag='0' and processflag='0' ", cDefine2), ConnectionUtils.Instance.GetConnection("TempDB")));
  239. }
  240. //获取最后一单(小于300)
  241. private int GetCounts(string lastCDefine2)
  242. {
  243. return Convert.ToInt32(DbUtils.ExecuteScalar(string.Format("select count(1)%100 from DispatchList where cDefine2='{0}' and cDefine3<>'9' and cDefine1='1' and bReturnFlag='0' and processflag='0' ", lastCDefine2), ConnectionUtils.Instance.GetConnection("TempDB")));
  244. }
  245. private DataSet __GetTempData(DataRow row)
  246. {
  247. Dictionary<string, string> args = new Dictionary<string, string>();
  248. string id = row["DLID"].ToString();
  249. args.Add("DispatchList", "select * from wtu..DispatchList where DLID=" + id);
  250. args.Add("DispatchLists", "select * from wtu..DispatchLists where DLID=" + id);
  251. DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection());
  252. return ds;
  253. }
  254. /// <summary>
  255. /// 不合并单据
  256. /// </summary>
  257. /// <param name="row"></param>
  258. /// <returns></returns>
  259. protected override BusinessObject _ImportData(DataRow row)
  260. {
  261. BasicApi api = null;
  262. if (___bReturnFlag == 0)
  263. {
  264. api = new ConsignmentApi();
  265. }
  266. else
  267. {
  268. api = new ReturnorderApi();
  269. }
  270. Dictionary<string, string> args = new Dictionary<string, string>();
  271. string id = row["DLID"].ToString();
  272. args.Add("DispatchList", "select * from wtu..DispatchList where DLID=" + id);
  273. args.Add("DispatchLists", "select * from wtu..DispatchLists where DLID=" + id);
  274. DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection());
  275. BusinessObject result = null;
  276. if (___bReturnFlag == 0)
  277. {
  278. Consignment v = __GetHead(ds);
  279. v.entry = __GetDetails(ds);
  280. ReturnorderRoot vr = new ReturnorderRoot();
  281. vr.consignment = v;
  282. result = api.Add(JsonUtils.GetJsonString(vr));
  283. }
  284. else
  285. {
  286. Returnorder v = __GetHeadTwo(ds);
  287. v.entry = __GetDetails(ds);
  288. ReturnorderRoot vr = new ReturnorderRoot();
  289. vr.returnorder = v;
  290. result = api.Add(JsonUtils.GetJsonString(vr));
  291. }
  292. return result;
  293. }
  294. /// <summary>
  295. /// 发货
  296. /// </summary>
  297. /// <param name="ds"></param>
  298. /// <returns></returns>
  299. private Consignment __GetHead(DataSet ds)//(v.plat_id.Equals("9")&& v.define1.Equals("1")) || (v.define1.Equals("7")) || (!v.define1.Equals("1")&&!v.define1.Equals("7"))
  300. {
  301. Consignment v = new Consignment();
  302. DataTable dt = ds.Tables["DispatchList"];
  303. v.code = dt.Rows[0]["cDLCode"].ToString();
  304. v.define3 = dt.Rows[0]["cDefine3"].ToString();//平台,用于区分是否为阿里巴巴店铺
  305. v.define1 = dt.Rows[0]["cDefine1"].ToString();//订单类型 1网店销售 2线下零售 3售后换货 4批发业务 5保修换新 6保修完成 7订单补发
  306. #region 备注平台和销售类型
  307. v.remark = v.define3.Equals("9") ? "阿里巴巴" : "非阿里巴巴" + ",";
  308. if (v.define1.Equals("1"))
  309. {
  310. v.remark += "网店销售";
  311. }
  312. else if (v.define1.Equals("2"))
  313. {
  314. v.remark += "线下零售";
  315. }
  316. else if (v.define1.Equals("3"))
  317. {
  318. v.remark += "售后换货";
  319. }
  320. else if (v.define1.Equals("4"))
  321. {
  322. v.remark += "批发业务";
  323. }
  324. else if (v.define1.Equals("5"))
  325. {
  326. v.remark += "保修换新";
  327. }
  328. else if (v.define1.Equals("6"))
  329. {
  330. v.remark += "保修完成";
  331. }
  332. else if (v.define1.Equals("7"))
  333. {
  334. v.remark += "订单补发";
  335. }
  336. #endregion
  337. v.bReturnFlag = Convert.ToBoolean(dt.Rows[0]["bReturnFlag"]) ? "1" : "0";
  338. if (!v.define3.Equals("9") && v.define1.Equals("1") && v.bReturnFlag.Equals("0"))//合并订单不带业务员 //((v.define3.Equals("9") && v.define1.Equals("1")) || (v.define1.Equals("7")) || (!v.define1.Equals("1") && !v.define1.Equals("7")))
  339. {
  340. // v.custcode = AppSeting.Instance.GetValue("clientRetail");//零售(其他)平台客户编码KN02
  341. v.custcode = dt.Rows[0]["cDefine2"].ToString();//客户编号==店铺编号
  342. v.cusname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称
  343. v.cusabbname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称
  344. }
  345. else
  346. {
  347. //if(!v.define1.Equals("1") && !v.define1.Equals("7") && !v.bReturnFlag.Equals("1"))//手工建单
  348. //{
  349. // v.custcode = dt.Rows[0]["cCusCode"].ToString();//客户编号==店铺编号
  350. // v.cusname = dt.Rows[0]["cCusName"].ToString();//客户名称==店铺名称
  351. // v.cusabbname = dt.Rows[0]["cCusName"].ToString();//客户名称==店铺名称
  352. //}
  353. //else
  354. //{
  355. v.custcode = dt.Rows[0]["cDefine2"].ToString();//客户编号==店铺编号
  356. v.cusname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称
  357. v.cusabbname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称
  358. //}
  359. //v.custcode = AppSeting.Instance.GetValue("clientOff");//线下平台客户编码KN01
  360. //v.define10 = dt.Rows[0]["cCusName"].ToString();
  361. v.define10 = dt.Rows[0]["cCusName"].ToString();
  362. v.define11 = dt.Rows[0]["cCusCode"].ToString();
  363. if (v.bReturnFlag.Equals("0"))
  364. {
  365. //v.personname = dt.Rows[0]["cDefine12"].ToString();//业务员名称
  366. //v.define12 = dt.Rows[0]["cDefine12"].ToString();//业务员名称
  367. v.personcode = dt.Rows[0]["cPersonCode"].ToString();//业务员编号
  368. }
  369. else
  370. {
  371. v.personcode = DbUtils.ExecuteScalar(string.Format(@" select cpersoncode from {0}..person where cPersonName='{1}' ",
  372. ConnectionUtils.Instance.GetConnection().Database, dt.Rows[0]["cDefine12"].ToString()),
  373. ConnectionUtils.Instance.GetConnection("TempDB")).ToString();
  374. }
  375. //v.bReturnFlag.Equals("0");
  376. //v.deptcode = DbUtils.ExecuteScalar(string.Format(@" select cDepCode from {0}..person where cpersoncode='{1}' ",
  377. // ConnectionUtils.Instance.GetConnection().Database, "salesman_no"),
  378. // ConnectionUtils.Instance.GetConnection("TempDB")).ToString();
  379. //------------------------------------------
  380. }
  381. //v.deptcode = dt.Rows[0]["cDepCode"].ToString();//部门编码
  382. //v.code = dt.Rows[0]["cSOCode"].ToString();//订单号
  383. //v.operation_type = dt.Rows[0]["cBusType"].ToString();//业务类型//dt.Rows[0]["cSTCode"].ToString();//销售类型编码
  384. //string bReturnFlag = dt.Rows[0]["bReturnFlag"].ToString();
  385. //if (bReturnFlag.Equals("0"))
  386. //{
  387. v.operation_type = "普通销售";
  388. v.saletype = "MX";
  389. //}
  390. //else
  391. //{
  392. // v.saletypename = "退货入库";
  393. //}
  394. //DateTime date = DateTime.Parse(dt.Rows[0]["dDate"].ToString());
  395. //v.date = date.ToString("yyyy-MM-dd");
  396. v.define5 = dt.Rows[0]["DLID"].ToString();
  397. v.deptcode = dt.Rows[0]["cDepCode"].ToString();
  398. //v.personname=dt.Rows[0]["ccontactname"].ToString();//业务员名称
  399. //v.personcode=dt.Rows[0]["cpersoncode"].ToString();//业务员编号
  400. //v.define6 = dt.Rows[0]["cCusName"].ToString();
  401. return v;
  402. }
  403. /// <summary>
  404. /// 退货
  405. /// </summary>
  406. /// <param name="ds"></param>
  407. /// <returns></returns>
  408. private Returnorder __GetHeadTwo(DataSet ds)//(v.plat_id.Equals("9")&& v.define1.Equals("1")) || (v.define1.Equals("7")) || (!v.define1.Equals("1")&&!v.define1.Equals("7"))
  409. {
  410. Returnorder v = new Returnorder();
  411. DataTable dt = ds.Tables["DispatchList"];
  412. v.define3 = dt.Rows[0]["cDefine3"].ToString();//平台,用于区分是否为阿里巴巴店铺
  413. v.define1 = dt.Rows[0]["cDefine1"].ToString();//订单类型 1网店销售 2线下零售 3售后换货 4批发业务 5保修换新 6保修完成 7订单补发
  414. v.code = dt.Rows[0]["cDLCode"].ToString();
  415. #region 备注平台和销售类型
  416. v.remark = v.define3.Equals("9") ? "阿里巴巴" : "非阿里巴巴" + ",";
  417. if (v.define1.Equals("1"))
  418. {
  419. v.remark += "网店销售";
  420. }
  421. else if (v.define1.Equals("2"))
  422. {
  423. v.remark += "线下零售";
  424. }
  425. else if (v.define1.Equals("3"))
  426. {
  427. v.remark += "售后换货";
  428. }
  429. else if (v.define1.Equals("4"))
  430. {
  431. v.remark += "批发业务";
  432. }
  433. else if (v.define1.Equals("5"))
  434. {
  435. v.remark += "保修换新";
  436. }
  437. else if (v.define1.Equals("6"))
  438. {
  439. v.remark += "保修完成";
  440. }
  441. else if (v.define1.Equals("7"))
  442. {
  443. v.remark += "订单补发";
  444. }
  445. #endregion
  446. v.bReturnFlag = Convert.ToBoolean(dt.Rows[0]["bReturnFlag"]) ? "1" : "0";
  447. if (!v.define3.Equals("9") && v.define1.Equals("1") && v.bReturnFlag.Equals("0"))//合并订单不带业务员 //((v.define3.Equals("9") && v.define1.Equals("1")) || (v.define1.Equals("7")) || (!v.define1.Equals("1") && !v.define1.Equals("7")))
  448. {
  449. // v.custcode = AppSeting.Instance.GetValue("clientRetail");//零售(其他)平台客户编码KN02
  450. v.custcode = dt.Rows[0]["cDefine2"].ToString();//客户编号==店铺编号
  451. v.cusname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称
  452. v.cusabbname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称
  453. }
  454. else
  455. {
  456. //v.custcode = AppSeting.Instance.GetValue("clientOff");//线下平台客户编码KN01
  457. //v.define10 = dt.Rows[0]["cCusName"].ToString();
  458. v.custcode = dt.Rows[0]["cDefine2"].ToString();//客户编号==店铺编号custcode
  459. v.cusname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称
  460. v.cusabbname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称cusname
  461. v.define10 = dt.Rows[0]["cCusName"].ToString();
  462. v.define11 = dt.Rows[0]["cCusCode"].ToString();
  463. if (v.bReturnFlag.Equals("0"))
  464. {
  465. // v.personname = dt.Rows[0]["cDefine12"].ToString();//业务员名称
  466. //v.define12 = dt.Rows[0]["cDefine12"].ToString();//业务员名称
  467. v.personcode = dt.Rows[0]["cPersonCode"].ToString();//业务员编号
  468. }
  469. else
  470. {
  471. // v.personcode = DbUtils.ExecuteScalar(string.Format(@" select cpersoncode from {0}..person where cPersonName='{1}' ",
  472. //ConnectionUtils.Instance.GetConnection().Database, dt.Rows[0]["cDefine12"].ToString()),
  473. //ConnectionUtils.Instance.GetConnection("TempDB")).ToString();
  474. }
  475. v.state = "Approved";
  476. v.deptcode = dt.Rows[0]["cDepCode"].ToString();
  477. //v.bReturnFlag.Equals("0");
  478. //v.deptcode = DbUtils.ExecuteScalar(string.Format(@" select cDepCode from {0}..person where cpersoncode='{1}' ",
  479. // ConnectionUtils.Instance.GetConnection().Database, "salesman_no"),
  480. // ConnectionUtils.Instance.GetConnection("TempDB")).ToString();
  481. //------------------------------------------
  482. }
  483. //v.deptcode = dt.Rows[0]["cDepCode"].ToString();//部门编码
  484. //v.code = dt.Rows[0]["cSOCode"].ToString();//订单号
  485. //v.operation_type = dt.Rows[0]["cBusType"].ToString();//业务类型//dt.Rows[0]["cSTCode"].ToString();//销售类型编码
  486. string bReturnFlag = dt.Rows[0]["bReturnFlag"].ToString();
  487. //if (bReturnFlag.Equals("0"))
  488. //{
  489. v.operation_type = "普通销售";
  490. v.saletype = AppSeting.Instance.GetValue("cSTCode");
  491. //}
  492. //else
  493. //{
  494. // v.saletypename = "退货入库";
  495. //}
  496. //DateTime date = DateTime.Parse(dt.Rows[0]["dDate"].ToString());
  497. //v.date = date.ToString("yyyy-MM-dd");
  498. v.define5 = dt.Rows[0]["DLID"].ToString();
  499. //v.personname=dt.Rows[0]["ccontactname"].ToString();//业务员名称
  500. //v.personcode=dt.Rows[0]["cpersoncode"].ToString();//业务员编号
  501. //v.define6 = dt.Rows[0]["cCusName"].ToString();
  502. return v;
  503. }
  504. private Entry[] __GetDetails(DataSet ds)
  505. {
  506. int cnt = ds.Tables["DispatchLists"].Rows.Count;
  507. DataTable dt = ds.Tables["DispatchLists"];
  508. Entry[] rtn = new Entry[cnt];
  509. for (int i = 0; i < cnt; i++)
  510. {
  511. Entry e = new Entry();
  512. e.inventory_code = dt.Rows[i]["cInvCode"].ToString().Replace(" ", "");//存货编码
  513. if (___bReturnFlag == 0)
  514. {
  515. e.quantity = dt.Rows[i]["iQuantity"].ToString();//数量
  516. //e.price = dt.Rows[i]["iQuotedPrice"].ToString();//单价
  517. e.taxprice = dt.Rows[i]["iQuotedPrice"].ToString();//含税单价
  518. }
  519. else
  520. {
  521. e.quantity = (Convert.ToInt32(dt.Rows[i]["iQuantity"]) * (-1)).ToString();
  522. //e.price = dt.Rows[i]["iQuotedPrice"].ToString();
  523. e.taxprice = dt.Rows[i]["iQuotedPrice"].ToString();//含税单价
  524. }
  525. e.define29 = dt.Rows[i]["cDefine29"].ToString();
  526. e.define28 = dt.Rows[i]["cDefine28"].ToString();//销售订单单号
  527. //e.quotedprice = dt.Rows[i]["iQuotedPrice"].ToString();//报价
  528. //e.money = dt.Rows[i]["iNatMoney"].ToString();//原币无税金额
  529. //e.bgift = dt.Rows[i]["bgift"].ToString();//赠品
  530. //e.rowno = dt.Rows[i]["iRowNo"].ToString();//行号
  531. e.taxrate = AppSeting.Instance.GetValue("taxrate"); //dt.Rows[i]["iTaxRate"].ToString();//税率
  532. e.warehouse_code = dt.Rows[i]["cCusInvCode"].ToString();
  533. e.define27 = dt.Rows[i]["DLID"].ToString();
  534. e.rowno = (i + 1).ToString();
  535. rtn[i] = e;
  536. }
  537. return rtn;
  538. }
  539. private bool _logFlag;
  540. private string ______id;
  541. private string ______msg;
  542. protected override void _LogError(int id, string msg)
  543. {
  544. _logFlag = false;
  545. ______msg = msg;
  546. OperationLog.Utils.WriteErrorLog("向U8导入销售出库资料", "sysid = " + id.ToString() + " " + msg);
  547. }
  548. protected override void _LogSucess(int id, string newCode)
  549. {
  550. _logFlag = true;
  551. ______id = newCode;
  552. //string sql = "update PU_ArrivalVouch set processflag = 1,processdate = getdate() where sysid = " + id.ToString();
  553. string sql = "update DispatchList set processflag = 1,processdate = getdate(),newcode='" + newCode + "'" + " where sysid = " + id.ToString();
  554. OperationLog.Utils.UpdateTempRecord(sql);
  555. }
  556. protected override string _GetReturnCode(BusinessObject result)
  557. {
  558. //string ID = DbUtils.ExecuteScalar(string.Format("select ID from DispatchList where cSOCode='{0}' ", result.Id), ConnectionUtils.Instance.GetConnection("003")).ToString();
  559. return result.Id;
  560. }
  561. private void _LogSucessTwo(string id, string ids)
  562. {
  563. //string sql = "update PU_ArrivalVouch set processflag = 1,processdate = getdate() where sysid = " + id.ToString();
  564. string sql = "update DispatchList set processflag = 1,processdate = getdate(),newcode='" + id + "' where sysid in (" + ids + ")";
  565. OperationLog.Utils.UpdateTempRecord(sql);
  566. }
  567. }
  568. }