You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.7 KiB

  1. using HKLib.Dto;
  2. using HKLib.Interfaces;
  3. using HKLib.SQLHelper;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using XExten.Advance.LinqFramework;
  14. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  15. namespace HKCardManager.UserPages
  16. {
  17. public partial class MealSegmentSetPage : UserControl
  18. {
  19. public MealSegmentSetPage()
  20. {
  21. InitializeComponent();
  22. this.SizeChanged += MealSegmentSetPage_SizeChanged;
  23. Init();
  24. }
  25. private async void Init()
  26. {
  27. var res = await HKLibHelper.GetTime();
  28. var price = SqlLogic.GetPrice();
  29. if (res != null)
  30. {
  31. this.Invoke(() =>
  32. {
  33. dateTimePicker1.Value = res.AMStartTime;
  34. dateTimePicker4.Value = res.AMEndTime;
  35. dateTimePicker2.Value = res.PMStartTime;
  36. dateTimePicker5.Value = res.PMEndTime;
  37. dateTimePicker3.Value = res.ATStartTime;
  38. dateTimePicker6.Value = res.ATEndTime;
  39. textBox1.Text = price?.AM.ToString();
  40. textBox2.Text = price?.PM.ToString();
  41. textBox3.Text = price?.AT.ToString();
  42. });
  43. }
  44. else MessageLogNotify.GetInstance.ShowError("获取餐段时间失败!");
  45. }
  46. private void MealSegmentSetPage_SizeChanged(object? sender, EventArgs e)
  47. {
  48. panel1.Left = (this.Width - panel1.Width) / 2;
  49. panel1.Top = (this.Height - panel1.Height) / 2;
  50. }
  51. private async void button1_Click(object sender, EventArgs e)
  52. {
  53. decimal.TryParse(textBox1.Text.Trim(), out decimal am);
  54. decimal.TryParse(textBox2.Text.Trim(), out decimal pm);
  55. decimal.TryParse(textBox3.Text.Trim(), out decimal at);
  56. if (am == 0 || pm == 0 || at == 0)
  57. {
  58. MessageBox.Show("请输入正确的金额");
  59. return;
  60. }
  61. var data = new TimeSpilte()
  62. {
  63. AMStartTime = dateTimePicker1.Value,
  64. AMEndTime = dateTimePicker4.Value,
  65. PMStartTime = dateTimePicker2.Value,
  66. PMEndTime = dateTimePicker5.Value,
  67. ATStartTime = dateTimePicker3.Value,
  68. ATEndTime = dateTimePicker6.Value
  69. };
  70. this.Invoke(() => { button1.Enabled = false; });
  71. if (await HKLibHelper.SetTime(data))
  72. {
  73. SqlLogic.AddPrice(new HKLib.SQLHelper.Entity.PriceModel
  74. {
  75. AM = textBox1.Text.Trim().AsDecimal(),
  76. PM = textBox2.Text.Trim().AsDecimal(),
  77. AT = textBox3.Text.Trim().AsDecimal()
  78. });
  79. this.Invoke(() =>
  80. {
  81. dateTimePicker1.Value = data.AMStartTime;
  82. dateTimePicker4.Value = data.AMEndTime;
  83. dateTimePicker2.Value = data.PMStartTime;
  84. dateTimePicker5.Value = data.PMEndTime;
  85. dateTimePicker3.Value = data.ATStartTime;
  86. dateTimePicker6.Value = data.ATEndTime;
  87. });
  88. MessageLogNotify.GetInstance.Show("设置餐段时间成功");
  89. }
  90. else
  91. {
  92. MessageLogNotify.GetInstance.ShowError("设置时间段失败,请重试!");
  93. }
  94. this.Invoke(() => { button1.Enabled = true; });
  95. }
  96. }
  97. }