FrmOrderTakingStatus.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. namespace LYFZ.Software.MainBusiness.StatisticalInquiry
  8. {
  9. public class FrmOrderTakingStatus : LYFZ.Software.UI.StatisticalInquiry.FrmOrderTakingStatus
  10. {
  11. private delegate void UpdateControl();
  12. public FrmOrderTakingStatus()
  13. {
  14. ///赋予初始值
  15. dtpStart.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
  16. dtpEnd.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  17. cb_OrderedStatus.SelectedIndex = 0;
  18. ///查询
  19. this.btnQuery.Click += BtnQuery_Click;
  20. this.btn_Export.Click += Btn_Export_Click;
  21. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindGroupStoreName(this.cmbtreevStoreName, StrGroupKeyCode: "retailProcess", StrKeyCode: "st007");
  22. ///显示
  23. this.Shown += FrmOrderTakingStatus_Shown;
  24. }
  25. private void Btn_Export_Click(object sender, EventArgs e)
  26. {
  27. dgvOrderBeen.ExportDataTable();
  28. }
  29. private void BtnQuery_Click(object sender, EventArgs e)
  30. {
  31. ///搜索数据
  32. BindOrderDataList();
  33. }
  34. private void FrmOrderTakingStatus_Shown(object sender, EventArgs e)
  35. {
  36. BtnQuery_Click(null, null);
  37. }
  38. void BindOrderDataList()
  39. {
  40. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  41. {
  42. string statusText = cb_OrderedStatus.Text;
  43. if (statusText=="未拍照")
  44. {
  45. statusText = "NotOrdered";
  46. }
  47. else if (statusText == "拍照中")
  48. {
  49. statusText = "Ordering";
  50. }
  51. else
  52. {
  53. statusText = "Ordered";
  54. }
  55. this.dgvOrderBeen.Rows.Clear();
  56. Dictionary<string, List<dynamic>> childOrderList = new Dictionary<string, List<dynamic>>();
  57. decimal sValue = 0;
  58. decimal aValue = 0;
  59. decimal yValue = 0;
  60. decimal pValue = 0;
  61. decimal arValue = 0;
  62. Dictionary<string, int> dicOrderList = new Dictionary<string, int>();
  63. dicOrderList.Add(OrderTypeName("0"), 0);
  64. dicOrderList.Add(OrderTypeName("1"), 0);
  65. dicOrderList.Add(OrderTypeName("2"), 0);
  66. dicOrderList.Add(OrderTypeName("3"), 0);
  67. dicOrderList.Add(OrderTypeName("4"), 0);
  68. List<string> ordNumberList = new List<string>();
  69. DataTable dtList = GetServiceData(statusText,ref childOrderList,ref ordNumberList,ref dicOrderList,ref sValue,ref aValue,ref yValue,ref pValue,ref arValue);
  70. if (dtList.Rows.Count > 0)
  71. {
  72. this.Invoke(new UpdateControl(delegate ()
  73. {
  74. ///绑定DataGridView
  75. for (int t = 0; t < dtList.Rows.Count; t++)
  76. {
  77. DataRow drData = dtList.Rows[t];
  78. BindDataGridViewData(drData, statusText);
  79. }
  80. this.dgvOrderBeen.ClearSelection();
  81. txtTotalAmount.Text = sValue.ToString("0.00");
  82. txtPickUpAmount.Text = aValue.ToString("0.00");
  83. txt_TotalAllAmount.Text = yValue.ToString("0.00");
  84. txtTotalCollection.Text = pValue.ToString("0.00");
  85. txtTotalArrears.Text = arValue.ToString("0.00");
  86. string statusTempText = "";
  87. int totalCount = 0;
  88. foreach(string key in dicOrderList.Keys)
  89. {
  90. totalCount += dicOrderList[key];
  91. if (dicOrderList[key] > 0)
  92. {
  93. statusTempText += key + ":" + dicOrderList[key] + " ";
  94. }
  95. }
  96. lblCount.Text = "订单数:"+ totalCount + " \r\n "+ statusTempText;
  97. }));
  98. }
  99. else
  100. {
  101. this.Invoke(new UpdateControl(delegate ()
  102. {
  103. txtTotalAmount.Text = sValue.ToString("0.00");
  104. txtPickUpAmount.Text = aValue.ToString("0.00");
  105. txt_TotalAllAmount.Text = yValue.ToString("0.00");
  106. txtTotalCollection.Text = pValue.ToString("0.00");
  107. txtTotalArrears.Text = arValue.ToString("0.00");
  108. lblCount.Text = "订单数:0";
  109. }));
  110. }
  111. });
  112. }
  113. /// <summary>
  114. /// 获取数据集合数据
  115. /// </summary>
  116. /// <param name="statusText"></param>
  117. /// <returns></returns>
  118. DataTable GetServiceData(string statusText,ref Dictionary<string, List<dynamic>> childOrderList,
  119. ref List<string> ordNumberList, ref Dictionary<string, int> dicOrderList
  120. ,ref decimal sValue, ref decimal aValue, ref decimal yValue, ref decimal pValue, ref decimal arValue)
  121. {
  122. string shopCode = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetGroupQueryWhere(this.cmbtreevStoreName, "Ord_DividedShop");
  123. System.Data.DataTable dtList = BLL.BLL_ErpOrderView.GetData_OrdersNotBeenOrdered(shopCode, dtpStart.Value, dtpEnd.Value, statusText);
  124. ///儿童订单次数等级总值
  125. Dictionary<string, decimal> dicOrderValue = new Dictionary<string, decimal>();
  126. ///数据处理
  127. for (int t = 0; t < dtList.Rows.Count; t++)
  128. {
  129. DataRow drData = dtList.Rows[t];
  130. BindChildDataBySign(drData, ref childOrderList,ref dicOrderValue);
  131. if (!ordNumberList.Contains(drData["Ord_Number"].ToString())
  132. &&
  133. ((statusText == "NotOrdered" && drData["StatusCount"].ToString() == "0")
  134. || (statusText == "Ordered" && Convert.ToInt32(drData["StatusCount"].ToString()) > 0 && Convert.ToInt32(drData["StatusCount"].ToString()) == Convert.ToInt32(drData["PhotoCount"].ToString()))
  135. || (statusText == "Ordering" && Convert.ToInt32(drData["StatusCount"].ToString()) > 0 && Convert.ToInt32(drData["StatusCount"].ToString())< Convert.ToInt32(drData["PhotoCount"].ToString()))))
  136. {
  137. sValue += Convert.ToDecimal(drData["Ord_SeriesPrice"]);
  138. aValue += Convert.ToDecimal(drData["TwoSales"]);
  139. yValue += Convert.ToDecimal(drData["TotalValue"]);
  140. pValue += Convert.ToDecimal(drData["payAmount"]);
  141. arValue += Convert.ToDecimal(drData["ArrearsAmount"]);
  142. ordNumberList.Add(drData["Ord_Number"].ToString());
  143. dicOrderList[OrderTypeName(drData["Ord_Type"].ToString())]++;
  144. }
  145. }
  146. foreach(string ordNumber in childOrderList.Keys)
  147. {
  148. decimal totalValue = dicOrderValue[ordNumber];
  149. foreach(dynamic dyObj in childOrderList[ordNumber])
  150. {
  151. List<DataRow> drDataList = dtList.AsEnumerable().Where(p => p.Field<string>("Ordpg_ViceNumber") == dyObj.ViceNumber).ToList();
  152. if(drDataList.Count>0)
  153. {
  154. if (totalValue > 0)
  155. {
  156. decimal TCValue = 0;
  157. decimal.TryParse(dyObj.TCValue, out TCValue);
  158. drDataList[0]["Ord_SeriesPrice"] = ((Convert.ToDecimal(dyObj.SeriesPrice) / (totalValue)) * TCValue).ToString("0.00");
  159. }
  160. }
  161. }
  162. }
  163. return dtList;
  164. }
  165. /// <summary>
  166. /// 绑定DataGridView行数据
  167. /// </summary>
  168. /// <param name="drData">数据集数据</param>
  169. /// <param name="statusText">订单类型</param>
  170. void BindDataGridViewData(DataRow drData,string statusText)
  171. {
  172. #region 获取月报表
  173. DataGridViewRow dgvr = new DataGridViewRow();
  174. DataGridViewCell cell = null;
  175. //单号
  176. cell = new DataGridViewTextBoxCell();
  177. cell.Value = drData["Ord_Number"].ToString();
  178. dgvr.Cells.Add(cell);
  179. //场景好
  180. cell = new DataGridViewTextBoxCell();
  181. cell.Value = drData["Ordpg_ViceNumber"].ToString();
  182. dgvr.Cells.Add(cell);
  183. //订单号
  184. cell = new DataGridViewTextBoxCell();
  185. cell.Value = drData["Ord_SinceOrderNumber"].ToString();
  186. dgvr.Cells.Add(cell);
  187. //订单类型
  188. cell = new DataGridViewTextBoxCell();
  189. cell.Value = OrderTypeName(drData["Ord_Type"].ToString());
  190. dgvr.Cells.Add(cell);
  191. //开单人
  192. cell = new DataGridViewTextBoxCell();
  193. cell.Value = drData["Ord_OrderPersonName"].ToString();
  194. dgvr.Cells.Add(cell);
  195. //客户名称
  196. cell = new DataGridViewTextBoxCell();
  197. cell.Value = drData["Cus_Name"].ToString();
  198. dgvr.Cells.Add(cell);
  199. //客户名称
  200. cell = new DataGridViewTextBoxCell();
  201. cell.Value = drData["Cus_Telephone"].ToString();
  202. dgvr.Cells.Add(cell);
  203. //拍摄场景
  204. string sightName = drData["Ords_SightsName"].ToString();
  205. string[] sightNameList = sightName.Split(',');
  206. string strSightName = "";
  207. foreach (string sightText in sightNameList)
  208. {
  209. if (strSightName != "")
  210. {
  211. strSightName += ",";
  212. }
  213. strSightName += sightText.Split('-')[0];
  214. }
  215. cell = new DataGridViewTextBoxCell();
  216. cell.Value = strSightName;
  217. dgvr.Cells.Add(cell);
  218. //套系名称
  219. cell = new DataGridViewTextBoxCell();
  220. cell.Value = drData["Ord_SeriesName"].ToString();
  221. dgvr.Cells.Add(cell);
  222. //拍照情况
  223. cell = new DataGridViewTextBoxCell();
  224. cell.Value = drData["Ordered"].ToString();
  225. dgvr.Cells.Add(cell);
  226. //订单套系金额
  227. cell = new DataGridViewTextBoxCell();
  228. cell.Value = drData["Ord_SeriesPrice"].ToString();
  229. dgvr.Cells.Add(cell);
  230. //欠款金额
  231. cell = new DataGridViewTextBoxCell();
  232. cell.Value = drData["ArrearsAmount"].ToString();
  233. dgvr.Cells.Add(cell);
  234. //业绩金额
  235. cell = new DataGridViewTextBoxCell();
  236. cell.Value = drData["TotalValue"].ToString();
  237. dgvr.Cells.Add(cell);
  238. //加挑金额
  239. cell = new DataGridViewTextBoxCell();
  240. cell.Value = drData["TwoSales"].ToString();
  241. dgvr.Cells.Add(cell);
  242. //已付款额
  243. cell = new DataGridViewTextBoxCell();
  244. cell.Value = drData["payAmount"].ToString();
  245. dgvr.Cells.Add(cell);
  246. if (statusText == "NotOrdered" && drData["StatusCount"].ToString() == "0")
  247. {
  248. this.dgvOrderBeen.Rows.Add(dgvr);
  249. }
  250. else if (statusText == "Ordered" && Convert.ToInt32(drData["StatusCount"].ToString()) > 0 && Convert.ToInt32(drData["StatusCount"].ToString()) == Convert.ToInt32(drData["PhotoCount"].ToString()))
  251. {
  252. this.dgvOrderBeen.Rows.Add(dgvr);
  253. }
  254. else if (statusText == "Ordering" && Convert.ToInt32(drData["StatusCount"].ToString()) > 0 && Convert.ToInt32(drData["StatusCount"].ToString()) < Convert.ToInt32(drData["PhotoCount"].ToString()))
  255. {
  256. this.dgvOrderBeen.Rows.Add(dgvr);
  257. }
  258. #endregion
  259. }
  260. public void BindChildDataBySign(DataRow drData,ref Dictionary<string,List<dynamic>> childOrderList,ref Dictionary<string, decimal> dicOrderValue)
  261. {
  262. if (drData["Ord_Type"].ToString() == "1")
  263. {
  264. dynamic dyObj = new System.Dynamic.ExpandoObject();
  265. dyObj.ViceNumber = drData["Ordpg_ViceNumber"].ToString();
  266. dyObj.TCValue = drData["Ords_SightsName"].ToString().Split('-')[1];
  267. dyObj.SeriesPrice = drData["Ord_SeriesPrice"].ToString();
  268. if (childOrderList.ContainsKey(drData["Ord_Number"].ToString()))
  269. {
  270. childOrderList[drData["Ord_Number"].ToString()].Add(dyObj);
  271. decimal tcValue = 0;
  272. decimal.TryParse(drData["Ords_SightsName"].ToString().Split('-')[1],out tcValue);
  273. dicOrderValue[drData["Ord_Number"].ToString()] += tcValue;
  274. }
  275. else
  276. {
  277. List<dynamic> dicDynamicList = new List<dynamic>();
  278. dicDynamicList.Add(dyObj);
  279. childOrderList.Add(drData["Ord_Number"].ToString(), dicDynamicList);
  280. decimal tcValue = 0;
  281. decimal.TryParse(drData["Ords_SightsName"].ToString().Split('-')[1], out tcValue);
  282. dicOrderValue.Add(drData["Ord_Number"].ToString(), tcValue);
  283. }
  284. }
  285. }
  286. /// <summary>
  287. /// 订单类型
  288. /// </summary>
  289. /// <param name="typeCode"></param>
  290. /// <returns></returns>
  291. string OrderTypeName(string typeCode)
  292. {
  293. switch(typeCode)
  294. {
  295. case "0":return "婚纱订单";
  296. case "1": return "儿童订单";
  297. case "2": return "写真订单";
  298. case "3": return "服务订单";
  299. case "4": return "婚庆订单";
  300. default : return "";
  301. }
  302. }
  303. }
  304. }