UCKeyBorderPay.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-08-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCKeyBorderPay.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Drawing;
  20. using System.Data;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows.Forms;
  24. namespace HZH_Controls.Controls
  25. {
  26. /// <summary>
  27. /// Class UCKeyBorderPay.
  28. /// Implements the <see cref="System.Windows.Forms.UserControl" />
  29. /// </summary>
  30. /// <seealso cref="System.Windows.Forms.UserControl" />
  31. public partial class UCKeyBorderPay : UserControl
  32. {
  33. /// <summary>
  34. /// Occurs when [number click].
  35. /// </summary>
  36. [Description("数字点击事件"), Category("自定义")]
  37. public event EventHandler NumClick;
  38. /// <summary>
  39. /// Occurs when [cancel click].
  40. /// </summary>
  41. [Description("取消点击事件"), Category("自定义")]
  42. public event EventHandler CancelClick;
  43. /// <summary>
  44. /// Occurs when [ok click].
  45. /// </summary>
  46. [Description("确定点击事件"), Category("自定义")]
  47. public event EventHandler OKClick;
  48. /// <summary>
  49. /// Occurs when [backspace click].
  50. /// </summary>
  51. [Description("删除点击事件"), Category("自定义")]
  52. public event EventHandler BackspaceClick;
  53. /// <summary>
  54. /// Occurs when [money click].
  55. /// </summary>
  56. [Description("金额点击事件"), Category("自定义")]
  57. public event EventHandler MoneyClick;
  58. /// <summary>
  59. /// Initializes a new instance of the <see cref="UCKeyBorderPay" /> class.
  60. /// </summary>
  61. public UCKeyBorderPay()
  62. {
  63. InitializeComponent();
  64. }
  65. #region 设置快速付款金额
  66. /// <summary>
  67. /// 功能描述:设置快速付款金额
  68. /// 作  者:HZH
  69. /// 创建日期:2019-03-07 11:41:04
  70. /// 任务编号:POS
  71. /// </summary>
  72. /// <param name="SorceMoney">SorceMoney</param>
  73. public void SetPayMoney(decimal SorceMoney)
  74. {
  75. List<decimal> list = new List<decimal>();
  76. decimal d = Math.Ceiling(SorceMoney);
  77. if (SorceMoney > 0m)
  78. {
  79. if (SorceMoney < 5m)
  80. {
  81. list.Add(5m);
  82. list.Add(10m);
  83. list.Add(20m);
  84. list.Add(50m);
  85. }
  86. else if (SorceMoney < 10m)
  87. {
  88. list.Add(10m);
  89. list.Add(20m);
  90. list.Add(50m);
  91. list.Add(100m);
  92. }
  93. else
  94. {
  95. int num = Convert.ToInt32(d % 10m);
  96. int num2 = Convert.ToInt32(Math.Floor(d / 10m) % 10m);
  97. int num3 = Convert.ToInt32(Math.Floor(d / 100m));
  98. int num4;
  99. if (num < 5)
  100. {
  101. num4 = num2 * 10 + 5;
  102. list.Add(num4 + num3 * 100);
  103. num4 = (num2 + 1) * 10;
  104. list.Add(num4 + num3 * 100);
  105. }
  106. else
  107. {
  108. num4 = (num2 + 1) * 10;
  109. list.Add(num4 + num3 * 100);
  110. }
  111. if (num4 >= 0 && num4 < 10)
  112. {
  113. num4 = 10;
  114. if (list.Count < 4)
  115. {
  116. list.Add(num4 + num3 * 100);
  117. }
  118. num4 = 20;
  119. if (list.Count < 4)
  120. {
  121. list.Add(num4 + num3 * 100);
  122. }
  123. num4 = 50;
  124. if (list.Count < 4)
  125. {
  126. list.Add(num4 + num3 * 100);
  127. }
  128. num4 = 100;
  129. if (list.Count < 4)
  130. {
  131. list.Add(num4 + num3 * 100);
  132. }
  133. }
  134. else if (num4 >= 10 && num4 < 20)
  135. {
  136. num4 = 20;
  137. if (list.Count < 4)
  138. {
  139. list.Add(num4 + num3 * 100);
  140. }
  141. num4 = 50;
  142. if (list.Count < 4)
  143. {
  144. list.Add(num4 + num3 * 100);
  145. }
  146. num4 = 100;
  147. if (list.Count < 4)
  148. {
  149. list.Add(num4 + num3 * 100);
  150. }
  151. }
  152. else if (num4 >= 20 && num4 < 50)
  153. {
  154. num4 = 50;
  155. if (list.Count < 4)
  156. {
  157. list.Add(num4 + num3 * 100);
  158. }
  159. num4 = 100;
  160. if (list.Count < 4)
  161. {
  162. list.Add(num4 + num3 * 100);
  163. }
  164. }
  165. else if (num4 < 100)
  166. {
  167. num4 = 100;
  168. if (list.Count < 4)
  169. {
  170. list.Add(num4 + num3 * 100);
  171. }
  172. }
  173. }
  174. }
  175. SetFastMoneyToContrl(list);
  176. }
  177. #endregion
  178. /// <summary>
  179. /// Sets the fast money to contrl.
  180. /// </summary>
  181. /// <param name="values">The values.</param>
  182. private void SetFastMoneyToContrl(List<decimal> values)
  183. {
  184. List<Label> lbl = new List<Label>() { lblFast1, lblFast2, lblFast3, lblFast4 };
  185. lblFast1.Tag = lblFast1.Text = "";
  186. lblFast2.Tag = lblFast2.Text = "";
  187. lblFast3.Tag = lblFast3.Text = "";
  188. lblFast4.Tag = lblFast4.Text = "";
  189. for (int i = 0; i < lbl.Count && i < values.Count; i++)
  190. {
  191. if (values[i].ToString("0.##").Length < 4)
  192. {
  193. lbl[i].Font = new System.Drawing.Font("Arial Unicode MS", 30F);
  194. }
  195. else
  196. {
  197. Graphics graphics = lbl[i].CreateGraphics();
  198. for (int j = 0; j < 5; j++)
  199. {
  200. SizeF sizeF = graphics.MeasureString(values[i].ToString("0.##"), new System.Drawing.Font("Arial Unicode MS", 30 - j * 5), 100, StringFormat.GenericTypographic);
  201. if (sizeF.Width <= lbl[i].Width - 20)
  202. {
  203. lbl[i].Font = new System.Drawing.Font("Arial Unicode MS", 30 - j * 5);
  204. break;
  205. }
  206. }
  207. graphics.Dispose();
  208. }
  209. lbl[i].Tag = lbl[i].Text = values[i].ToString("0.##");
  210. }
  211. }
  212. /// <summary>
  213. /// Handles the MouseDown event of the Num control.
  214. /// </summary>
  215. /// <param name="sender">The source of the event.</param>
  216. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  217. private void Num_MouseDown(object sender, MouseEventArgs e)
  218. {
  219. if (NumClick != null)
  220. NumClick((sender as Label).Tag, e);
  221. }
  222. /// <summary>
  223. /// Handles the MouseDown event of the Backspace control.
  224. /// </summary>
  225. /// <param name="sender">The source of the event.</param>
  226. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  227. private void Backspace_MouseDown(object sender, MouseEventArgs e)
  228. {
  229. if (BackspaceClick != null)
  230. BackspaceClick((sender as Label).Tag, e);
  231. }
  232. /// <summary>
  233. /// Handles the MouseDown event of the Cancel control.
  234. /// </summary>
  235. /// <param name="sender">The source of the event.</param>
  236. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  237. private void Cancel_MouseDown(object sender, MouseEventArgs e)
  238. {
  239. if (CancelClick != null)
  240. CancelClick((sender as Label).Tag, e);
  241. }
  242. /// <summary>
  243. /// Handles the MouseDown event of the OK control.
  244. /// </summary>
  245. /// <param name="sender">The source of the event.</param>
  246. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  247. private void OK_MouseDown(object sender, MouseEventArgs e)
  248. {
  249. if (OKClick != null)
  250. OKClick((sender as Label).Tag, e);
  251. }
  252. /// <summary>
  253. /// Handles the MouseDown event of the Money control.
  254. /// </summary>
  255. /// <param name="sender">The source of the event.</param>
  256. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  257. private void Money_MouseDown(object sender, MouseEventArgs e)
  258. {
  259. if (MoneyClick != null)
  260. MoneyClick((sender as Label).Tag, e);
  261. }
  262. /// <summary>
  263. /// Money1s the click.
  264. /// </summary>
  265. public void Money1Click()
  266. {
  267. Money_MouseDown(lblFast1, null);
  268. }
  269. /// <summary>
  270. /// Money2s the click.
  271. /// </summary>
  272. public void Money2Click()
  273. {
  274. Money_MouseDown(lblFast2, null);
  275. }
  276. /// <summary>
  277. /// Money3s the click.
  278. /// </summary>
  279. public void Money3Click()
  280. {
  281. Money_MouseDown(lblFast3, null);
  282. }
  283. /// <summary>
  284. /// Money4s the click.
  285. /// </summary>
  286. public void Money4Click()
  287. {
  288. Money_MouseDown(lblFast4, null);
  289. }
  290. }
  291. }