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.

82 lines
2.9 KiB

  1. using HKLib.Dto;
  2. using HKLib.Interfaces;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace HKCardManager.UserPages
  13. {
  14. public partial class MealSegmentSetPage : UserControl
  15. {
  16. public MealSegmentSetPage()
  17. {
  18. InitializeComponent();
  19. this.SizeChanged += MealSegmentSetPage_SizeChanged;
  20. Task.Factory.StartNew(() =>
  21. {
  22. var res = HKLibHelper.GetTime();
  23. if (res != null)
  24. {
  25. this.Invoke(() =>
  26. {
  27. dateTimePicker1.Value = res.AMStartTime;
  28. dateTimePicker4.Value = res.AMEndTime;
  29. dateTimePicker2.Value = res.PMStartTime;
  30. dateTimePicker5.Value = res.PMEndTime;
  31. dateTimePicker3.Value = res.ATStartTime;
  32. dateTimePicker6.Value = res.ATEndTime;
  33. });
  34. }
  35. else MessageLogNotify.GetInstance.ShowError("获取餐段时间失败!");
  36. });
  37. }
  38. private void MealSegmentSetPage_SizeChanged(object? sender, EventArgs e)
  39. {
  40. panel1.Left = (this.Width - panel1.Width) / 2;
  41. panel1.Top = (this.Height - panel1.Height) / 2;
  42. }
  43. private void button1_Click(object sender, EventArgs e)
  44. {
  45. var data = new TimeSpilte()
  46. {
  47. AMStartTime = dateTimePicker1.Value,
  48. AMEndTime = dateTimePicker4.Value,
  49. PMStartTime = dateTimePicker2.Value,
  50. PMEndTime = dateTimePicker5.Value,
  51. ATStartTime = dateTimePicker3.Value,
  52. ATEndTime = dateTimePicker6.Value
  53. };
  54. Task.Factory.StartNew(() =>
  55. {
  56. this.Invoke(() => { button1.Enabled = false; });
  57. if (HKLibHelper.SetTime(data))
  58. {
  59. this.Invoke(() =>
  60. {
  61. dateTimePicker1.Value = data.AMStartTime;
  62. dateTimePicker4.Value = data.AMEndTime;
  63. dateTimePicker2.Value = data.PMStartTime;
  64. dateTimePicker5.Value = data.PMEndTime;
  65. dateTimePicker3.Value = data.ATStartTime;
  66. dateTimePicker6.Value = data.ATEndTime;
  67. });
  68. MessageLogNotify.GetInstance.Show("设置餐段时间成功");
  69. }
  70. else
  71. {
  72. MessageLogNotify.GetInstance.ShowError("设置时间段失败,请重试!");
  73. }
  74. this.Invoke(() => { button1.Enabled = true; });
  75. });
  76. }
  77. }
  78. }