Esempio n. 1
0
        bool AddPrivilege()
        {
            try
            {
                long recordId          = 0;
                int  recordCount       = 0;
                var  sqlString         = PrivilegeSQL.InsertPrivilege();
                var  sqlParamWithValue = new HashSet <IDictionary <string, object> >();
                foreach (Privilege P in olvObsada.CheckedObjects)
                {
                    sqlParamWithValue.Add(CreatePrivilegeParams(P));
                }

                using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
                {
                    var dbs   = scope.Resolve <IDataBaseService>();
                    var value = dbs.AddManyRecordsAsync(sqlString, sqlParamWithValue).Result;
                    recordCount = value.RecordCount;
                    recordId    = value.InsertedRecordId;
                }

                NewRecordAdded?.Invoke(recordId);
                MessageBox.Show($"{recordCount} rekordów zostało dodanych.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Esempio n. 2
0
 void DeleteExclusion()
 {
     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 <IDictionary <string, object> >();
             foreach (ExclusionDetails E in olvExclusion.SelectedObjects)
             {
                 sqlParamWithValue.Add(new Dictionary <string, object>()
                 {
                     { "@AllocationID", E.AllocationID },
                     { "@PrivilegeID", E.PrivilegeID }
                 });
             }
             using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
             {
                 var dbs = scope.Resolve <IDataBaseService>();
                 recordCount = dbs.RemoveManyRecordsAsync(PrivilegeSQL.DeleteExclusion(), sqlParamWithValue).Result;
             }
             MessageBox.Show($"{recordCount} rekordów zostało usuniętych.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
             GetData(olvExclusion, GetExclusionListAsync((olvUser.SelectedObject as Teacher).ID).Result);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Esempio n. 3
0
 private async Task <int> UpdatePrivilegeAsync(dlgPrivilegeEdition dlg, int ID)
 {
     using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
     {
         var dbs = scope.Resolve <IDataBaseService>();
         return(await dbs.UpdateRecordAsync(PrivilegeSQL.UpdatePrivilege(), CreateUpdateParams(dlg, ID)));
     }
 }
Esempio n. 4
0
 private async Task <int> UpdateExclusionAsync(dlgExclusionEdition dlg, int AllocationId, int PrivilegeId)
 {
     using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
     {
         var dbs = scope.Resolve <IDataBaseService>();
         return(await dbs.UpdateRecordAsync(PrivilegeSQL.UpdateExclusion(), CreateUpdateParams(dlg, AllocationId, PrivilegeId)));
     }
 }
Esempio n. 5
0
 private async Task <IEnumerable <ExclusionDetails> > GetExclusionListAsync(int TeacherId)
 {
     try
     {
         using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
         {
             var dbs = scope.Resolve <IDataBaseService>();
             return(await dbs.FetchRecordSetAsync(PrivilegeSQL.SelectExclusion(TeacherId, UserSession.User.Settings.SchoolYear), ExclusionDetails.CreateExclusionDetails));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 6
0
 private async Task <IEnumerable <Teacher> > GetTeacherListAsync()
 {
     try
     {
         using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
         {
             var dbs = scope.Resolve <IDataBaseService>();
             return(await dbs.FetchRecordSetAsync(PrivilegeSQL.SelectTeacher(UserSession.User.Settings.SchoolID.ToString()), TeacherModel));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 7
0
 private bool AddNewExclusion()
 {
     try
     {
         int recordCount       = 0;
         var sqlString         = PrivilegeSQL.InsertExclusion();
         var sqlParamWithValue = new HashSet <IDictionary <string, object> >();
         foreach (StudentAllocation S in olvStudent.CheckedObjects)
         {
             sqlParamWithValue.Add(new Dictionary <string, object>
             {
                 { "@AllocationID", S.ID },
                 { "@PrivilegeID", privilege.ID },
                 { "@StartDate", S.StartDate },
                 { "@EndDate", S.EndDate },
                 { "@Owner", S.Creator.Owner },
                 { "@User", S.Creator.User },
                 { "@IP", S.Creator.IP }
             });
         }
         using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
         {
             var dbs = scope.Resolve <IDataBaseService>();
             recordCount = dbs.AddManyRecordsAsync(sqlString, sqlParamWithValue).Result.RecordCount;
         }
         if (recordCount > 0)
         {
             MessageBox.Show($"{recordCount} rekordów zostało dodanych.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
             NewRecordAdded?.Invoke(new Exclusion
             {
                 AllocationID = (int)sqlParamWithValue.Last().Where(x => x.Key == "@AllocationID").First().Value,
                 PrivilegeID  = (int)sqlParamWithValue.Last().Where(x => x.Key == "@PrivilegeID").First().Value
             });
             return(true);
         }
         throw new Exception($"Wystąpił błąd podczas dodawania wykluczenia.\nOperacja została anulowana.");
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 8
0
 private async Task <IEnumerable <StudentAllocation> > GetStudentListAsync(int ClassID, int PrivilegeID)
 {
     try
     {
         using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
         {
             var dbs = scope.Resolve <IDataBaseService>();
             return(await dbs.FetchRecordSetAsync(PrivilegeSQL.SelectStudent(ClassID, PrivilegeID), (R) =>
             {
                 int.TryParse(R["NrwDzienniku"].ToString(), out int Nr);
                 var startDate = new DateTime[2];
                 var endDate = new DateTime[2];
                 startDate[0] = privilege.StartDate;
                 endDate[0] = privilege.EndDate;
                 DateTime.TryParse(R["DataAktywacji"].ToString(), out startDate[1]);
                 DateTime.TryParse(R["DataDeaktywacji"].ToString(), out endDate[1]);
                 return new StudentAllocation
                 {
                     ID = Convert.ToInt32(R["ID"]),
                     StudentNo = Nr,
                     Student = new Student {
                         LastName = R["Nazwisko"].ToString(), FirstName = R["Imie"].ToString()
                     },
                     StartDate = startDate.Max(),
                     EndDate = endDate.Min(),
                     Status = (User.UserStatus)Convert.ToInt64(R["StatusAktywacji"]),
                     Creator = new Signature()
                     {
                         Owner = UserSession.User.Login,
                         User = UserSession.User.Login,
                         IP = AppSession.HostIP
                     }
                 };
             }));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 9
0
        private static async Task <IEnumerable <Privilege> > LoadUserPrivilegesAsync(AppUser user)
        {
            if (user.Role > User.UserRole.Operator)
            {
                return(null);
            }
            Task <IEnumerable <Privilege> > p = default;

            using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
            {
                var dbs = scope.Resolve <IDataBaseService>();
                foreach (var s in user.SchoolTokenList)
                {
                    if (s.UserRole == User.UserRole.Operator)
                    {
                        continue;
                    }
                    p = dbs.FetchRecordSetAsync(PrivilegeSQL.SelectPrivilege(s.UserID, UserSession.User.Settings.SchoolYear), Privilege.CreatePrivilege);
                }
            }
            return(await p);
        }