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 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); } } }