FrmStoredValueReport.cs 20 KB

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