NewEntranceForm.cs 2.8 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 NewEntranceForm : XtraForm
  13. {
  14. private List<NameValue> L;
  15. public EntranceModel entranceModel;
  16. private EntranceRepository entranceRepository;
  17. public OperatorModel currentUser;
  18. private ActionsRepository actionsRepository;
  19. public NewEntranceForm()
  20. {
  21. InitializeComponent();
  22. L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture);
  23. }
  24. private void NewEntranceForm_Load(object sender, EventArgs e)
  25. {
  26. actionsRepository = new ActionsRepository();
  27. entranceRepository = new EntranceRepository();
  28. InitView();
  29. }
  30. private void InitView()
  31. {
  32. if (entranceModel != null)
  33. {
  34. text_name.Text = entranceModel.Name;
  35. }
  36. }
  37. private async void btn_save_Click(object sender, EventArgs e)
  38. {
  39. if (string.IsNullOrEmpty(text_name.Text))
  40. {
  41. XtraMessageBox.Show(L.GetString("entranceNotNull"), L.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  42. }
  43. if (entranceModel == null)
  44. {
  45. entranceModel = new EntranceModel();
  46. }
  47. entranceModel.Name = text_name.Text;
  48. int result = 0;
  49. if (entranceModel.Id == 0)
  50. {
  51. result = await entranceRepository.Insert(entranceModel);
  52. if (result > 0)
  53. {
  54. await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("addEntranceLog"), entranceModel.Name), Operator = currentUser.Name, RoleName = currentUser.RoleName, Time = DateTime.Now });
  55. }
  56. }
  57. else
  58. {
  59. result = await entranceRepository.Update(entranceModel);
  60. if (result > 0)
  61. {
  62. await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("editEntranceLog"), entranceModel.Name), Operator = currentUser.Name, RoleName = currentUser.RoleName, Time = DateTime.Now });
  63. }
  64. }
  65. if (result == 0)
  66. {
  67. XtraMessageBox.Show(L.GetString("saveFailed"), L.GetString("exclamation"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  68. }
  69. else
  70. {
  71. DialogResult = DialogResult.OK;
  72. Close();
  73. }
  74. }
  75. private void text_name_Click(object sender, EventArgs e)
  76. {
  77. SoftKeyboard.ActiveSoftKeyboard(sender);
  78. }
  79. }
  80. }