Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

84 řádky
2.8 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. Init();
  21. }
  22. private async void Init()
  23. {
  24. var res = await HKLibHelper.GetTime();
  25. if (res != null)
  26. {
  27. this.Invoke(() =>
  28. {
  29. dateTimePicker1.Value = res.AMStartTime;
  30. dateTimePicker4.Value = res.AMEndTime;
  31. dateTimePicker2.Value = res.PMStartTime;
  32. dateTimePicker5.Value = res.PMEndTime;
  33. dateTimePicker3.Value = res.ATStartTime;
  34. dateTimePicker6.Value = res.ATEndTime;
  35. });
  36. }
  37. else MessageLogNotify.GetInstance.ShowError("获取餐段时间失败!");
  38. }
  39. private void MealSegmentSetPage_SizeChanged(object? sender, EventArgs e)
  40. {
  41. panel1.Left = (this.Width - panel1.Width) / 2;
  42. panel1.Top = (this.Height - panel1.Height) / 2;
  43. }
  44. private async void button1_Click(object sender, EventArgs e)
  45. {
  46. var data = new TimeSpilte()
  47. {
  48. AMStartTime = dateTimePicker1.Value,
  49. AMEndTime = dateTimePicker4.Value,
  50. PMStartTime = dateTimePicker2.Value,
  51. PMEndTime = dateTimePicker5.Value,
  52. ATStartTime = dateTimePicker3.Value,
  53. ATEndTime = dateTimePicker6.Value
  54. };
  55. //Task.Factory.StartNew(() =>
  56. //{
  57. this.Invoke(() => { button1.Enabled = false; });
  58. if (await HKLibHelper.SetTime(data))
  59. {
  60. this.Invoke(() =>
  61. {
  62. dateTimePicker1.Value = data.AMStartTime;
  63. dateTimePicker4.Value = data.AMEndTime;
  64. dateTimePicker2.Value = data.PMStartTime;
  65. dateTimePicker5.Value = data.PMEndTime;
  66. dateTimePicker3.Value = data.ATStartTime;
  67. dateTimePicker6.Value = data.ATEndTime;
  68. });
  69. MessageLogNotify.GetInstance.Show("设置餐段时间成功");
  70. }
  71. else
  72. {
  73. MessageLogNotify.GetInstance.ShowError("设置时间段失败,请重试!");
  74. }
  75. this.Invoke(() => { button1.Enabled = true; });
  76. //});
  77. }
  78. }
  79. }