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 NewTeamForm : XtraForm
- {
- private List<NameValue> L;
- public TeamModel teamModel;
- private TeamRepository teamRepository;
- public OperatorModel currentUser;
- private readonly ActionsRepository actionsRepository;
- public NewTeamForm()
- {
- InitializeComponent();
- actionsRepository = new ActionsRepository();
- L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture);
- }
- private void NewDeviceForm_Load(object sender, EventArgs e)
- {
- teamRepository = new TeamRepository();
- InitView();
- }
- private void InitView()
- {
- if (teamModel != null)
- {
- text_name.Text = teamModel.Name;
- time_starttime.EditValue = teamModel.StartTime;
- time_endtime.EditValue = teamModel.EndTime;
- }
- }
- private async void btn_save_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(text_name.Text))
- {
- XtraMessageBox.Show(L.GetString("teamNameNotNull"), L.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (teamModel == null)
- {
- teamModel = new TeamModel();
- }
- teamModel.Name = text_name.Text;
- teamModel.StartTime = time_starttime.Text;
- teamModel.EndTime = time_endtime.Text;
- int result = 0;
- if (teamModel.Id == 0)
- {
- result = await teamRepository.Insert(teamModel);
- if (result > 0)
- {
- await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("addTeamLog"), teamModel.Name), Operator = currentUser.Name, RoleName = currentUser.RoleName, Time = DateTime.Now });
- }
- }
- else
- {
- result = await teamRepository.Update(teamModel);
- if (result > 0)
- {
- await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("editTeamLog"), teamModel.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);
- }
- }
- }
|