DownLoadSaleorder.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 DelHander();
  20. // public class DownLoadSaleorder : BaseDataDownLoad
  21. // {
  22. // protected override void _Init()
  23. // {
  24. // _loadSql = "select * from SO_SOMain where processflag=0";
  25. // base._Init();
  26. // }
  27. // protected override void _downLoad()
  28. // {
  29. // List<string> ids = new List<string>();
  30. // int i = 0;
  31. // DataSet temp = null;
  32. // int num = 0;
  33. // //设定开关
  34. // bool flag = false;
  35. // //获取零售平台订单个数
  36. // int sum = GetCount();
  37. // //获取最后一单数量
  38. // int counts = GetCounts();
  39. // if (_data.Rows.Count > 0)
  40. // {
  41. // temp = __GetTempData(_data.Rows[0]);
  42. // temp.Tables[0].Clear();
  43. // temp.Tables[1].Clear();
  44. // }
  45. // foreach (DataRow row in _data.Rows)
  46. // {
  47. // BusinessObject result = null;
  48. // DataSet dd = __GetTempData(row);
  49. // saleorder v = new saleorder();
  50. // DataTable dt = dd.Tables["SO_SOMain"];
  51. // v.plat_id = dt.Rows[0]["platform_id"].ToString();//平台,用于区分是否为阿里巴巴店铺
  52. // v.define1 = dt.Rows[0]["cDefine1"].ToString();//订单类型 1网店销售 2线下零售 3售后换货 4批发业务 5保修换新 6保修完成 7订单补发
  53. // if ((v.plat_id.Equals("9") && v.define1.Equals("1")) || (v.define1.Equals("7")) || (!v.define1.Equals("1") && !v.define1.Equals("7")))//不合并
  54. // {
  55. // SaleorderApi api = new SaleorderApi();
  56. // result = _ImportData(row);
  57. // api.Audit(result.Id);
  58. // string newcode = null;
  59. // //记录日志
  60. // _Log(result, Convert.ToInt32(row["sysid"]), out newcode);
  61. // }
  62. // else
  63. // {
  64. // //设置300单合并为一单
  65. // if (sum - (299 * num) < 299)
  66. // {
  67. // flag = true;
  68. // }
  69. // if (flag)
  70. // {
  71. // NewMethod(ids, ref i, temp, ref num, row, () => i == counts - 1);
  72. // }
  73. // else
  74. // {
  75. // NewMethod(ids, ref i, temp, ref num, row, () => i == 299);
  76. // }
  77. // }
  78. // }
  79. // }
  80. // private void NewMethod(List<string> ids, ref int i, DataSet temp, ref int num, DataRow row, DelHander del)
  81. // {
  82. // DataSet ds = __GetTempData(row);
  83. // //存300单的第一单
  84. // if (i == 0)
  85. // {
  86. // temp.Tables["SO_SOMain"].ImportRow(row);
  87. // }
  88. // if (del())
  89. // {
  90. // //把最后一单加上
  91. // ids.Add(row["sysid"].ToString());
  92. // foreach (DataRow item in ds.Tables["SO_SODetails"].Rows)
  93. // {
  94. // temp.Tables["SO_SODetails"].ImportRow(item);
  95. // }
  96. // //要修改的300单业务ID数据
  97. // string[] b = new string[ids.Count];
  98. // ids.CopyTo(b);
  99. // //String.Join(",", b);
  100. // //result = _ImportData(temp[0]);
  101. // SaleorderApi apiTwo = new SaleorderApi();
  102. // saleorder vv = __GetHead(temp);
  103. // vv.entry = __GetDetails(temp);
  104. // SaleorderRoot vr = new SaleorderRoot();
  105. // vr.saleorder = vv;
  106. // BusinessObject resultTwo = apiTwo.Add(JsonUtils.GetJsonString(vr));
  107. // //记录日志
  108. // string newcode = null;
  109. // _Log(resultTwo, Convert.ToInt32(temp.Tables[0].Rows[0]["sysid"]), out newcode);
  110. // if (_logFlag)
  111. // {
  112. // SaleorderApi api = new SaleorderApi();
  113. // api.Audit(newcode);
  114. // _LogSucessTwo(______id, String.Join(",", b));
  115. // }
  116. // else
  117. // {
  118. // //跳过第一条
  119. // for (int k = 1; k < b.Length; k++)
  120. // {
  121. // OperationLog.Utils.WriteErrorLog("向U8导入销售订单资料", "sysid = " + b[k] + " " + ______msg);
  122. // }
  123. // }
  124. // //清空业务表数据
  125. // temp.Tables[0].Clear();
  126. // temp.Tables[1].Clear();
  127. // i = 0;
  128. // ids.Clear();
  129. // ______id = null;
  130. // //300单加一次
  131. // num += 1;
  132. // }
  133. // else
  134. // {
  135. // ids.Add(row["sysid"].ToString());
  136. // foreach (DataRow item in ds.Tables["SO_SODetails"].Rows)
  137. // {
  138. // temp.Tables["SO_SODetails"].ImportRow(item);
  139. // }
  140. // i++;
  141. // }
  142. // }
  143. // private int GetCount()
  144. // {
  145. // return Convert.ToInt32(DbUtils.ExecuteScalar("select count(sysid) from so_somain where platform_id<>0 and platform_id<>9 ", ConnectionUtils.Instance.GetConnection("TempDB")));
  146. // }
  147. // //获取最后一单(小于300)
  148. // private int GetCounts()
  149. // {
  150. // return Convert.ToInt32(DbUtils.ExecuteScalar("select COUNT(sysid) % 300 from SO_SOMain where platform_id<>0 and platform_id<>9", ConnectionUtils.Instance.GetConnection("TempDB")));
  151. // }
  152. // private DataSet __GetTempData(DataRow row)
  153. // {
  154. // Dictionary<string, string> args = new Dictionary<string, string>();
  155. // string id = row["ID"].ToString();
  156. // args.Add("SO_SOMain", "select * from wtu..SO_SOMain where ID=" + id);
  157. // args.Add("SO_SODetails", "select * from wtu..SO_SODetails where ID=" + id);
  158. // DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection());
  159. // return ds;
  160. // }
  161. // protected override BusinessObject _ImportData(DataRow row)
  162. // {
  163. // SaleorderApi api = new SaleorderApi();
  164. // Dictionary<string, string> args = new Dictionary<string, string>();
  165. // string id = row["ID"].ToString();
  166. // args.Add("SO_SOMain", "select * from wtu..SO_SOMain where ID=" + id);
  167. // args.Add("SO_SODetails", "select * from wtu..SO_SODetails where ID=" + id);
  168. // DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection());
  169. // saleorder v = __GetHead(ds);
  170. // v.entry = __GetDetails(ds);
  171. // SaleorderRoot vr = new SaleorderRoot();
  172. // vr.saleorder = v;
  173. // BusinessObject result = api.Add(JsonUtils.GetJsonString(vr));//8724229
  174. // return result;
  175. // }
  176. // private saleorder __GetHead(DataSet ds)//(v.plat_id.Equals("9")&& v.define1.Equals("1")) || (v.define1.Equals("7")) || (!v.define1.Equals("1")&&!v.define1.Equals("7"))
  177. // {
  178. // saleorder v = new saleorder();
  179. // DataTable dt = ds.Tables["SO_SOMain"];
  180. // v.plat_id = dt.Rows[0]["platform_id"].ToString();//平台,用于区分是否为阿里巴巴店铺
  181. // v.define1 = dt.Rows[0]["cDefine1"].ToString();//订单类型 1网店销售 2线下零售 3售后换货 4批发业务 5保修换新 6保修完成 7订单补发
  182. // if ((v.plat_id.Equals("9") && v.define1.Equals("1")) || (v.define1.Equals("7")) || (!v.define1.Equals("1") && !v.define1.Equals("7")))
  183. // {
  184. // //v.custcode = AppSeting.Instance.GetValue("clientOff");//线下平台客户编码KN01
  185. // //v.define10 = dt.Rows[0]["cCusName"].ToString();
  186. // v.custcode = dt.Rows[0]["cDefine2"].ToString();//客户编号==店铺编号custcode
  187. // v.cusabbname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称cusname
  188. // v.personname = dt.Rows[0]["ccontactname"].ToString();//业务员名称
  189. // v.personcode = dt.Rows[0]["cpersoncode"].ToString();//业务员编号
  190. // }
  191. // else//合并订单不带业务员
  192. // {
  193. // // v.custcode = AppSeting.Instance.GetValue("clientRetail");//零售(其他)平台客户编码KN02
  194. // v.custcode = dt.Rows[0]["cDefine2"].ToString();//客户编号==店铺编号
  195. // v.cusabbname = dt.Rows[0]["cDefine11"].ToString();//客户名称==店铺名称
  196. // }
  197. // v.deptcode = dt.Rows[0]["cDepCode"].ToString();//部门编码
  198. // //v.code = dt.Rows[0]["cSOCode"].ToString();//订单号
  199. // v.businesstype = dt.Rows[0]["cBusType"].ToString();//业务类型
  200. // v.typecode = dt.Rows[0]["cSTCode"].ToString();//销售类型编码
  201. // DateTime date = DateTime.Parse(dt.Rows[0]["dDate"].ToString());
  202. // v.date = date.ToString("yyyy-MM-dd");
  203. // v.define5 = dt.Rows[0]["ID"].ToString();
  204. // //v.personname=dt.Rows[0]["ccontactname"].ToString();//业务员名称
  205. // //v.personcode=dt.Rows[0]["cpersoncode"].ToString();//业务员编号
  206. // //v.define6 = dt.Rows[0]["cCusName"].ToString();
  207. // return v;
  208. // }
  209. // private Entry[] __GetDetails(DataSet ds)
  210. // {
  211. // int cnt = ds.Tables["SO_SODetails"].Rows.Count;
  212. // DataTable dt = ds.Tables["SO_SODetails"];
  213. // Entry[] rtn = new Entry[cnt];
  214. // for (int i = 0; i < cnt; i++)
  215. // {
  216. // Entry e = new Entry();
  217. // e.inventorycode = dt.Rows[i]["cInvCode"].ToString().Replace(" ", "");//存货编码
  218. // e.quantity = dt.Rows[i]["iQuantity"].ToString();//数量
  219. // e.quotedprice = dt.Rows[i]["iQuotedPrice"].ToString();//报价
  220. // e.money = dt.Rows[i]["iNatMoney"].ToString();//原币无税金额
  221. // //e.bgift = dt.Rows[i]["bgift"].ToString();//赠品
  222. // //e.rowno = dt.Rows[i]["iRowNo"].ToString();//行号
  223. // e.taxrate = dt.Rows[i]["iTaxRate"].ToString();//税率
  224. // e.define27 = dt.Rows[i]["ID"].ToString();
  225. // e.rowno = (i + 1).ToString();
  226. // rtn[i] = e;
  227. // }
  228. // return rtn;
  229. // }
  230. // private bool _logFlag;
  231. // private string ______id;
  232. // private string ______msg;
  233. // protected override void _LogError(int id, string msg)
  234. // {
  235. // _logFlag = false;
  236. // ______msg = msg;
  237. // OperationLog.Utils.WriteErrorLog("向U8导入销售订单资料", "sysid = " + id.ToString() + " " + msg);
  238. // }
  239. // protected override void _LogSucess(int id, string newCode)
  240. // {
  241. // _logFlag = true;
  242. // ______id = newCode;
  243. // //string sql = "update PU_ArrivalVouch set processflag = 1,processdate = getdate() where sysid = " + id.ToString();
  244. // string sql = "update SO_SOMain set processflag = 1,processdate = getdate(),newcode='" + newCode + "'" + " where sysid = " + id.ToString();
  245. // OperationLog.Utils.UpdateTempRecord(sql);
  246. // }
  247. // protected override string _GetReturnCode(BusinessObject result)
  248. // {
  249. // //string ID = DbUtils.ExecuteScalar(string.Format("select ID from SO_SOMain where cSOCode='{0}' ", result.Id), ConnectionUtils.Instance.GetConnection("003")).ToString();
  250. // return result.Id;
  251. // }
  252. // private void _LogSucessTwo(string id, string ids)
  253. // {
  254. // //string sql = "update PU_ArrivalVouch set processflag = 1,processdate = getdate() where sysid = " + id.ToString();
  255. // string sql = "update SO_SOMain set processflag = 1,processdate = getdate(),newcode='" + id + "' where sysid in (" + ids + ")";
  256. // OperationLog.Utils.UpdateTempRecord(sql);
  257. // }
  258. // }
  259. //}