FrmStoredReport.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. namespace LYFZ.Software.MainBusiness.StatisticalInquiry
  8. {
  9. public class FrmStoredReport : Software.UI.StatisticalInquiry.FrmStoredReport
  10. {
  11. public bool IsQueryByEmployee { get; set; } = false;
  12. public string strEmployeeId { get; set; } = "";
  13. LYFZ.BLL.BLL_ErpMemberCard memberCardBll = new BLL.BLL_ErpMemberCard();
  14. public string startTime = "";
  15. public string endTime = "";
  16. public FrmStoredReport()
  17. {
  18. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindGroupStoreName(this.cmbtreevStoreName, StrKeyCode: "qt002");
  19. this.btnQuery.Click += BtnQuery_Click;
  20. this.Load += FrmStoredReport_Load;
  21. }
  22. private void FrmStoredReport_Load(object sender, EventArgs e)
  23. {
  24. DataRow();
  25. }
  26. private void BtnQuery_Click(object sender, EventArgs e)
  27. {
  28. DataRow();
  29. }
  30. /// <summary>
  31. /// 绑定数据
  32. /// </summary>
  33. public void DataRow()
  34. {
  35. Dictionary<string, Dictionary<string, string>> tempDicList = new Dictionary<string, Dictionary<string, string>>();
  36. List<string> PayCategoryList = new List<string>();
  37. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  38. {
  39. //string startTime = dtpStart.Value.ToString("yyyy-MM-dd");
  40. //string endTime = dtpEnd.Value.ToString("yyyy-MM-dd");
  41. DataTable storeData = new DataTable();
  42. if(!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
  43. {
  44. storeData = memberCardBll.GetStoredValueCardData(startTime, endTime,IsQueryByEmployee == true ? strEmployeeId : "");
  45. }
  46. else
  47. {
  48. storeData = memberCardBll.GetStoredValueCardData(IsQueryByEmployee == true ? strEmployeeId : "");
  49. }
  50. DataTable totalStoreData = memberCardBll.GetTotalStoredValueCardData(IsQueryByEmployee == true ? strEmployeeId : "");
  51. Dictionary<string, Dictionary<string, string>> dicList = new Dictionary<string, Dictionary<string, string>>();
  52. for (int i = 0; i < storeData.Rows.Count; i++)
  53. {
  54. DataRow dr = storeData.Rows[i];
  55. Dictionary<string, string> tempColumDicList = new Dictionary<string, string>();
  56. if (dicList.ContainsKey(dr["Mcacl_Number"].ToString()))
  57. {
  58. tempColumDicList = dicList[dr["Mcacl_Number"].ToString()];
  59. }
  60. else
  61. {
  62. dicList.Add(dr["Mcacl_Number"].ToString(), tempColumDicList);
  63. }
  64. BindData(dr, ref tempColumDicList);
  65. }
  66. for (int i = 0; i < totalStoreData.Rows.Count; i++)
  67. {
  68. DataRow dr = totalStoreData.Rows[i];
  69. Dictionary<string, string> tempColumDicList = new Dictionary<string, string>();
  70. if (dicList.ContainsKey(dr["Mcacl_Number"].ToString()))
  71. {
  72. tempColumDicList = dicList[dr["Mcacl_Number"].ToString()];
  73. }
  74. else
  75. {
  76. dicList.Add(dr["Mcacl_Number"].ToString(), tempColumDicList);
  77. }
  78. BindTotalData(dr, ref tempColumDicList);
  79. }
  80. List<string> McNumber = new List<string>();
  81. foreach (string key in dicList.Keys)
  82. {
  83. McNumber.Add(key);
  84. }
  85. string searchText = txt_MemberText.Text;
  86. if (!string.IsNullOrEmpty(searchText))
  87. {
  88. searchText = " and (mc_CradNumber like '%" +
  89. searchText + "%' or cus_name like '%" +
  90. searchText + "%' or Cus_Telephone like '%" +
  91. searchText + "%') ";
  92. }
  93. else
  94. {
  95. searchText = "";
  96. }
  97. searchText += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetGroupQueryWhere(this.cmbtreevStoreName, "Mc_DividedShop");
  98. DataTable memberDataTable = memberCardBll.GetMemberCardDataValue(" Mc_Number in ('" + string.Join("','", McNumber.ToArray()) + "') " + searchText);
  99. DataTable memberCardTable = memberCardBll.GetMemberPaymentByCard(" Pay_McNumber in ('" + string.Join("','", McNumber.ToArray()) + "') ");
  100. ///分类
  101. PayCategoryList = memberCardTable.AsEnumerable().Where(p => !string.IsNullOrEmpty(p.Field<string>("twoClassName"))).Select(p => p.Field<string>("twoClassName")).Distinct().ToList();
  102. PayCategoryList.Insert(0, "订单前期");
  103. PayCategoryList.Add("礼服消费");
  104. for (int i = 0; i < memberDataTable.Rows.Count; i++)
  105. {
  106. if (dicList.ContainsKey(memberDataTable.Rows[i]["Mc_Number"].ToString()))
  107. {
  108. tempDicList.Add(memberDataTable.Rows[i]["Mc_Number"].ToString(), dicList[memberDataTable.Rows[i]["Mc_Number"].ToString()]);
  109. Dictionary<string, string> tempColumDicList = dicList[memberDataTable.Rows[i]["Mc_Number"].ToString()];
  110. if (!tempColumDicList.ContainsKey("McNumber"))
  111. {
  112. tempColumDicList.Add("McNumber", memberDataTable.Rows[i]["Mc_CradNumber"].ToString());
  113. }
  114. if (!tempColumDicList.ContainsKey("McCardHolder"))
  115. {
  116. tempColumDicList.Add("McCardHolder", memberDataTable.Rows[i]["Cus_Name"].ToString());
  117. }
  118. if (!tempColumDicList.ContainsKey("McTelephone"))
  119. {
  120. tempColumDicList.Add("McTelephone", memberDataTable.Rows[i]["Cus_Telephone"].ToString());
  121. }
  122. if (!tempColumDicList.ContainsKey("McCardMoney"))
  123. {
  124. tempColumDicList.Add("McCardMoney", memberDataTable.Rows[i]["Mc_Money"].ToString());
  125. }
  126. if (!tempColumDicList.ContainsKey("McResidualStoredValue"))
  127. {
  128. if (Convert.ToDecimal(tempColumDicList["McTotalStoredValue"].ToString()) > 0)
  129. {
  130. if (tempColumDicList.ContainsKey("McTotalConsumption") && tempColumDicList.ContainsKey("McTotalStoredValue"))
  131. {
  132. string strValue = ((-1 * Convert.ToDecimal(tempColumDicList["McTotalConsumption"].ToString()) /
  133. Convert.ToDecimal(tempColumDicList["McTotalStoredValue"].ToString())) * 100).ToString("0.00") + "%";
  134. tempColumDicList.Add("McResidualStoredValue", strValue);
  135. }
  136. else
  137. {
  138. tempColumDicList.Add("McResidualStoredValue", "");
  139. }
  140. }
  141. else
  142. {
  143. tempColumDicList.Add("McResidualStoredValue", "");
  144. }
  145. }
  146. foreach(string saleKey in PayCategoryList)
  147. {
  148. if (!tempColumDicList.ContainsKey(saleKey))
  149. {
  150. decimal totalAmount = 0;
  151. switch (saleKey)
  152. {
  153. case "订单前期":
  154. totalAmount = memberCardTable.AsEnumerable().Where(p =>
  155. p.Field<string>("Pay_McNumber") == memberDataTable.Rows[i]["Mc_Number"].ToString() &&
  156. string.IsNullOrEmpty(p.Field<string>("twoClassName")) && p.Field<string>("Pay_Category").IndexOf("后期") == -1)
  157. .Sum(p => p.Field<decimal>("Pay_AmountOf"));
  158. break;
  159. case "礼服消费":
  160. totalAmount = memberCardTable.AsEnumerable().Where(p =>
  161. p.Field<string>("Pay_McNumber") == memberDataTable.Rows[i]["Mc_Number"].ToString() &&
  162. string.IsNullOrEmpty(p.Field<string>("twoClassName")) &&
  163. p.Field<string>("Pay_Category").IndexOf("后期") != -1 &&
  164. p.Field<string>("Pay_ReceivableProject").IndexOf("礼服") > -1)
  165. .Sum(p => p.Field<decimal>("Pay_AmountOf"));
  166. break;
  167. default:
  168. totalAmount = memberCardTable.AsEnumerable().Where(p =>
  169. p.Field<string>("Pay_McNumber") == memberDataTable.Rows[i]["Mc_Number"].ToString() &&
  170. p.Field<string>("twoClassName") == saleKey).Sum(p => p.Field<decimal>("Pay_AmountOf")
  171. );
  172. break;
  173. }
  174. tempColumDicList.Add(saleKey, totalAmount.ToString());
  175. }
  176. }
  177. }
  178. //dicList[memberDataTable.Rows[i]["Mc_Number"].ToString()]
  179. }
  180. });
  181. BindGridControlData(tempDicList, PayCategoryList);
  182. }
  183. void BindGridControlData(Dictionary<string, Dictionary<string, string>> dicList,List<string> payCategoryList)
  184. {
  185. this.dgv.Rows.Clear();
  186. decimal mcmoney = 0;
  187. decimal recharge = 0;
  188. decimal giftAmount = 0;
  189. decimal withdrawals = 0;
  190. decimal consumption = 0;
  191. decimal totalStoredValue = 0;
  192. decimal totalConsumption = 0;
  193. foreach(string strKey in payCategoryList)
  194. {
  195. if(!dgv.Columns.Contains(strKey))
  196. {
  197. System.Windows.Forms.DataGridViewTextBoxColumn viewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
  198. viewColumn.Name = strKey;
  199. viewColumn.HeaderText = strKey;
  200. dgv.Columns.Insert(dgv.Columns.Count - 2, viewColumn);
  201. }
  202. }
  203. foreach (string key in dicList.Keys)
  204. {
  205. Dictionary<string, string> columList = dicList[key];
  206. int rowIndex = this.dgv.Rows.Add();
  207. this.dgv.Rows[rowIndex].Cells["McCardMoney"].Value = 0;
  208. //this.dgv.Rows[rowIndex].Cells["McRecharge"].Value = 0;
  209. this.dgv.Rows[rowIndex].Cells["McGiftAmount"].Value = 0;
  210. //this.dgv.Rows[rowIndex].Cells["McWithdrawals"].Value = 0;
  211. //this.dgv.Rows[rowIndex].Cells["McConsumption"].Value = 0;
  212. this.dgv.Rows[rowIndex].Cells["McTotalStoredValue"].Value = 0;
  213. this.dgv.Rows[rowIndex].Cells["McTotalConsumption"].Value = 0;
  214. this.dgv.Rows[rowIndex].Tag = key;
  215. foreach (string columKey in columList.Keys)
  216. {
  217. if (this.dgv.Columns.Contains(columKey))
  218. {
  219. this.dgv.Rows[rowIndex].Cells[columKey].Value = columList[columKey];
  220. }
  221. if (columKey.Equals("McCardMoney"))
  222. {
  223. mcmoney += Convert.ToDecimal(columList[columKey]);
  224. }
  225. if (columKey.Equals("McRecharge"))
  226. {
  227. recharge += Convert.ToDecimal(columList[columKey]);
  228. }
  229. if (columKey.Equals("McGiftAmount"))
  230. {
  231. giftAmount += Convert.ToDecimal(columList[columKey]);
  232. }
  233. if (columKey.Equals("McWithdrawals"))
  234. {
  235. withdrawals += Convert.ToDecimal(columList[columKey]);
  236. }
  237. if (columKey.Equals("McConsumption"))
  238. {
  239. consumption += Convert.ToDecimal(columList[columKey]);
  240. }
  241. if (columKey.Equals("McTotalStoredValue"))
  242. {
  243. totalStoredValue += Convert.ToDecimal(columList[columKey]);
  244. }
  245. if (columKey.Equals("McTotalConsumption"))
  246. {
  247. totalConsumption += Convert.ToDecimal(columList[columKey]);
  248. }
  249. }
  250. }
  251. lab_Message.Text = " 余额:" + mcmoney + " 充值金额:" + recharge + " 赠送金额:" + giftAmount +
  252. //" 提现金额:" + withdrawals * -1 +
  253. " 已消费金额:" + consumption * -1 +
  254. " 累计充值金额:" + totalStoredValue + " 累计消费金额:" + totalConsumption * -1;
  255. }
  256. /// <summary>
  257. /// 绑定表格数据
  258. /// </summary>
  259. /// <param name="dr">数据</param>
  260. /// <param name="tempColumDicList"></param>
  261. void BindData(DataRow dr, ref Dictionary<string, string> tempColumDicList)
  262. {
  263. string keyData = dr["类型"].ToString();
  264. decimal valueData = 0;
  265. string giftData = "McGiftAmount";//"McGiftAmount";
  266. decimal giftValueData = 0;
  267. switch (keyData)
  268. {
  269. case "充值":
  270. keyData = "McRecharge";
  271. valueData = Convert.ToDecimal(dr["操作金额"].ToString());
  272. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  273. break;
  274. case "提现":
  275. keyData = "McWithdrawals";
  276. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  277. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  278. break;
  279. case "取现":
  280. keyData = "McWithdrawals";
  281. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  282. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  283. break;
  284. case "删除收款扣回":
  285. keyData = "McConsumption";
  286. valueData = Convert.ToDecimal(dr["操作金额"].ToString());
  287. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  288. break;
  289. case "订单消费":
  290. keyData = "McConsumption";
  291. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  292. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  293. break;
  294. case "服务消费":
  295. keyData = "McConsumption";
  296. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  297. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  298. break;
  299. case "充值错误扣回":
  300. keyData = "McRecharge";
  301. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  302. giftValueData = -1 * Convert.ToDecimal(dr["赠送金额"].ToString());
  303. break;
  304. case "送金额":
  305. keyData = "McRecharge";
  306. giftValueData = Convert.ToDecimal(dr["操作金额"].ToString());
  307. break;
  308. case "删除储值提现扣回":
  309. keyData = "McWithdrawals";
  310. valueData = Convert.ToDecimal(dr["操作金额"].ToString());
  311. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  312. break;
  313. }
  314. ///
  315. if (tempColumDicList.ContainsKey(keyData))
  316. {
  317. tempColumDicList[keyData] = (Convert.ToDecimal(tempColumDicList[keyData]) + Convert.ToDecimal(valueData)).ToString("0.00");
  318. }
  319. else
  320. {
  321. tempColumDicList.Add(keyData, valueData.ToString("0.00"));
  322. }
  323. if (tempColumDicList.ContainsKey(giftData))
  324. {
  325. tempColumDicList[giftData] = (Convert.ToDecimal(tempColumDicList[giftData]) + Convert.ToDecimal(giftValueData)).ToString("0.00");
  326. }
  327. else
  328. {
  329. tempColumDicList.Add(giftData, giftValueData.ToString("0.00"));
  330. }
  331. }
  332. /// <summary>
  333. /// 绑定表格数据
  334. /// </summary>
  335. /// <param name="dr">数据</param>
  336. /// <param name="tempColumDicList"></param>
  337. void BindTotalData(DataRow dr, ref Dictionary<string, string> tempColumDicList)
  338. {
  339. string keyData = dr["类型"].ToString();
  340. decimal valueData = 0;
  341. string giftData = "McTotalStoredValue";// "McTotalGift";
  342. decimal giftValueData = 0;
  343. switch (keyData)
  344. {
  345. case "充值":
  346. keyData = "McTotalStoredValue";
  347. valueData = Convert.ToDecimal(dr["操作金额"].ToString());
  348. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  349. break;
  350. case "提现":
  351. //keyData = "McTotalWithdrawals";
  352. keyData = "McTotalConsumption";
  353. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  354. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  355. break;
  356. case "取现":
  357. //keyData = "McTotalWithdrawals";
  358. keyData = "McTotalConsumption";
  359. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  360. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  361. break;
  362. case "删除收款扣回":
  363. keyData = "McTotalConsumption";
  364. valueData = Convert.ToDecimal(dr["操作金额"].ToString());
  365. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  366. break;
  367. case "订单消费":
  368. keyData = "McTotalConsumption";
  369. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  370. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  371. break;
  372. case "服务消费":
  373. keyData = "McTotalConsumption";
  374. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  375. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  376. break;
  377. case "充值错误扣回":
  378. keyData = "McTotalStoredValue";
  379. valueData = -1 * Convert.ToDecimal(dr["操作金额"].ToString());
  380. giftValueData = -1 * Convert.ToDecimal(dr["赠送金额"].ToString());
  381. break;
  382. case "送金额":
  383. //keyData = "McTotalGift";
  384. keyData = "McTotalStoredValue";
  385. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  386. break;
  387. case "删除储值提现扣回":
  388. keyData = "McTotalConsumption";
  389. valueData = Convert.ToDecimal(dr["操作金额"].ToString());
  390. giftValueData = Convert.ToDecimal(dr["赠送金额"].ToString());
  391. break;
  392. }
  393. ///
  394. if (tempColumDicList.ContainsKey(keyData))
  395. {
  396. tempColumDicList[keyData] = (Convert.ToDecimal(tempColumDicList[keyData]) + Convert.ToDecimal(valueData)).ToString("0.00");
  397. }
  398. else
  399. {
  400. tempColumDicList.Add(keyData, valueData.ToString("0.00"));
  401. }
  402. if (tempColumDicList.ContainsKey(giftData))
  403. {
  404. tempColumDicList[giftData] = (Convert.ToDecimal(tempColumDicList[giftData]) + Convert.ToDecimal(giftValueData)).ToString("0.00");
  405. }
  406. else
  407. {
  408. tempColumDicList.Add(giftData, giftValueData.ToString("0.00"));
  409. }
  410. }
  411. }
  412. }