void EditSchoolType() { try { if (olvSchoolType.SelectedObject == null) { return; } using (var dlg = new dlgSchoolType()) { var T = (SchoolType)olvSchoolType.SelectedObject; FillDialog(dlg, T); if (dlg.ShowDialog() == DialogResult.OK) { if (UpdateSchoolTypeAsync(dlg, T.ID).Result > 0) { GetData(olvSchoolType); SeekHelper.SetListItem <SchoolType, int>(T.ID, "ID", olvSchoolType); return; } throw new Exception("Aktualizacja danych nie powiodła się!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async Task <int> UpdateSchoolTypeAsync(dlgSchoolType dlg, int id) { using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(await dbs.UpdateRecordAsync(SchoolSQL.UpdateSchoolType(), CreateUpdateParams(dlg, id))); } }
private void cmdAddNew_Click(object sender, EventArgs e) { using (var dlg = new dlgSchoolType()) { dlg.IsNewMode = true; dlg.NewRecordAdded += RefreshData; dlg.ShowDialog(); dlg.NewRecordAdded -= RefreshData; } }
IDictionary <string, object> CreateUpdateParams(dlgSchoolType dlg, int id) { var sqlParamWithValue = new Dictionary <string, object>(); sqlParamWithValue.Add("@ID", id); sqlParamWithValue.Add("@Nazwa", dlg.txtNazwa.Text.Trim()); sqlParamWithValue.Add("@Opis", dlg.txtOpis.Text.Trim()); sqlParamWithValue.Add("@User", UserSession.User.Login); sqlParamWithValue.Add("@IP", AppSession.HostIP); return(sqlParamWithValue); }
private void FillDialog(dlgSchoolType dlg, SchoolType T) { dlg.txtNazwa.Text = T.Name; dlg.txtOpis.Text = T.Description; }