NewTeamForm.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Windows.Forms;
  5. using DevExpress.XtraEditors;
  6. using GCAS.Code;
  7. using GCAS.Dto;
  8. using GCAS.Localization;
  9. using GCAS.Model;
  10. namespace GCAS
  11. {
  12. public partial class NewTeamForm : XtraForm
  13. {
  14. private List<NameValue> L;
  15. public TeamModel teamModel;
  16. private TeamRepository teamRepository;
  17. public OperatorModel currentUser;
  18. private readonly ActionsRepository actionsRepository;
  19. public NewTeamForm()
  20. {
  21. InitializeComponent();
  22. actionsRepository = new ActionsRepository();
  23. L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture);
  24. }
  25. private void NewDeviceForm_Load(object sender, EventArgs e)
  26. {
  27. teamRepository = new TeamRepository();
  28. InitView();
  29. }
  30. private void InitView()
  31. {
  32. if (teamModel != null)
  33. {
  34. text_name.Text = teamModel.Name;
  35. time_starttime.EditValue = teamModel.StartTime;
  36. time_endtime.EditValue = teamModel.EndTime;
  37. }
  38. }
  39. private async void btn_save_Click(object sender, EventArgs e)
  40. {
  41. if (string.IsNullOrEmpty(text_name.Text))
  42. {
  43. XtraMessageBox.Show(L.GetString("teamNameNotNull"), L.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  44. }
  45. if (teamModel == null)
  46. {
  47. teamModel = new TeamModel();
  48. }
  49. teamModel.Name = text_name.Text;
  50. teamModel.StartTime = time_starttime.Text;
  51. teamModel.EndTime = time_endtime.Text;
  52. int result = 0;
  53. if (teamModel.Id == 0)
  54. {
  55. result = await teamRepository.Insert(teamModel);
  56. if (result > 0)
  57. {
  58. await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("addTeamLog"), teamModel.Name), Operator = currentUser.Name, RoleName = currentUser.RoleName, Time = DateTime.Now });
  59. }
  60. }
  61. else
  62. {
  63. result = await teamRepository.Update(teamModel);
  64. if (result > 0)
  65. {
  66. await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("editTeamLog"), teamModel.Name), Operator = currentUser.Name, RoleName = currentUser.RoleName, Time = DateTime.Now });
  67. }
  68. }
  69. if (result <= 0)
  70. {
  71. XtraMessageBox.Show(L.GetString("saveFailed"), L.GetString("exclamation"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  72. }
  73. else
  74. {
  75. DialogResult = DialogResult.OK;
  76. Close();
  77. }
  78. }
  79. private void text_name_Click(object sender, EventArgs e)
  80. {
  81. SoftKeyboard.ActiveSoftKeyboard(sender);
  82. }
  83. }
  84. }