private void cmdDelete_Click(object sender, EventArgs e) { if (olvObsada.CheckedObjects.Count == 0) { return; } if (MessageBox.Show("Czy na pewno chcesz usunąć wskazane pozycje?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { try { var recordCount = 0; var sqlParamWithValue = new HashSet <Tuple <string, object> >(); foreach (SubjectSchemeModel ss in olvObsada.CheckedObjects) { sqlParamWithValue.Add(new Tuple <string, object>("@ID", ss.ID)); } using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); recordCount = dbs.RemoveManyRecordsAsync(SubjectSchemeSQL.DeleteScheme(), sqlParamWithValue).Result; } RefreshData(); MessageBox.Show($"{recordCount} rekordów zostało usuniętych.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
async Task <IEnumerable <SubjectSchemeImport> > GetSubjectList() { try { var PreviousSchoolYear = string.Concat(nudStartYear.Value, "/", nudEndYear.Value); var CurrentSchoolYearDateRange = new DateRange(); var CurrentClassList = dlgObsada.GetClassList().Result.ToList(); string CurrentClassString = null; CurrentClassList.ForEach(x => CurrentClassString += $"'{x.ClassCode}',"); CurrentClassString = CurrentClassString.Trim(','); using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(await dbs.FetchRecordSetAsync(SubjectSchemeSQL.SelectScheme(UserSession.User.Settings.SchoolID.ToString(), PreviousSchoolYear, CurrentClassString), (R) => new SubjectSchemeImport { ClassName = R["NazwaKlasy"].ToString(), SubjectName = R["Nazwa"].ToString(), Group = (YesNo)Convert.ToInt64(R["Grupa"]), SubjectCategory = R["Kategoria"].ToString(), ToAvg = (YesNo)Convert.ToInt64(R["GetToAverage"]), StartDate = CurrentSchoolYearDateRange.StartDate, EndDate = CurrentSchoolYearDateRange.EndDate, LessonCount = Convert.ToSingle(R["LiczbaGodzin"]), ClassID = CurrentClassList.Where(x => x.ClassCode == R["KodKlasy"].ToString()).First().ID, SubjectID = Convert.ToInt32(R["Przedmiot"]) })); } } catch (Exception) { throw; } }
private async Task <int> UpdateSubjectAsync(dlgObsada dlg, SubjectSchemeModel P) { using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(await dbs.UpdateRecordAsync(SubjectSchemeSQL.UpdateScheme(), CreateUpdateParams(dlg, P))); } }
private async Task <IEnumerable <SubjectSchemeModel> > GetSubjectList() { try { using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(await dbs.FetchRecordSetAsync(SubjectSchemeSQL.SelectScheme(UserSession.User.Settings.SchoolID.ToString(), UserSession.User.Settings.SchoolYear), SubjectSchemeModel.Create)); } } catch (Exception) { throw; } }
async Task <(int, long)> AddSubjectScheme(List <int> ClassId) { try { var sqlString = SubjectSchemeSQL.InsertScheme(); var sqlParamWithValue = new HashSet <IDictionary <string, object> >(); foreach (var ID in ClassId) { sqlParamWithValue.Add(CreateSubjectParams(ID)); } using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(await dbs.AddManyRecordsAsync(sqlString, sqlParamWithValue)); } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return(0, -1); } }