12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Windows.Forms;
- using DevExpress.XtraEditors;
- using GCAS.Code;
- using GCAS.Dto;
- using GCAS.Localization;
- using GCAS.Model;
- namespace GCAS
- {
- public partial class NewEntranceForm : XtraForm
- {
- private List<NameValue> L;
- public EntranceModel entranceModel;
- private EntranceRepository entranceRepository;
- public OperatorModel currentUser;
- private ActionsRepository actionsRepository;
- public NewEntranceForm()
- {
- InitializeComponent();
- L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture);
- }
- private void NewEntranceForm_Load(object sender, EventArgs e)
- {
- actionsRepository = new ActionsRepository();
- entranceRepository = new EntranceRepository();
- InitView();
- }
- private void InitView()
- {
- if (entranceModel != null)
- {
- text_name.Text = entranceModel.Name;
- }
- }
- private async void btn_save_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(text_name.Text))
- {
- XtraMessageBox.Show(L.GetString("entranceNotNull"), L.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (entranceModel == null)
- {
- entranceModel = new EntranceModel();
- }
- entranceModel.Name = text_name.Text;
- int result = 0;
- if (entranceModel.Id == 0)
- {
- result = await entranceRepository.Insert(entranceModel);
- if (result > 0)
- {
- await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("addEntranceLog"), entranceModel.Name), Operator = currentUser.Name, RoleName = currentUser.RoleName, Time = DateTime.Now });
- }
- }
- else
- {
- result = await entranceRepository.Update(entranceModel);
- if (result > 0)
- {
- await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("editEntranceLog"), entranceModel.Name), Operator = currentUser.Name, RoleName = currentUser.RoleName, Time = DateTime.Now });
- }
- }
- if (result == 0)
- {
- XtraMessageBox.Show(L.GetString("saveFailed"), L.GetString("exclamation"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- else
- {
- DialogResult = DialogResult.OK;
- Close();
- }
- }
- private void text_name_Click(object sender, EventArgs e)
- {
- SoftKeyboard.ActiveSoftKeyboard(sender);
- }
- }
- }
|