Beispiel #1
0
 private void FillDialog(dlgTeacher dlg, Teacher T)
 {
     dlg.txtTeacher.Text   = T.Name;
     dlg.cbRole.DataSource = Enum.GetNames(typeof(User.UserRole));
     dlg.cbRole.Text       = T.Role.ToString();
     dlg.chkStatus.Checked = (int)T.Status > 0;
 }
Beispiel #2
0
        void EditTeacher()
        {
            try
            {
                if (olvSubject.SelectedObject == null)
                {
                    return;
                }
                using (var dlg = new dlgTeacher())
                {
                    var T = (Teacher)olvSubject.SelectedObject;
                    FillDialog(dlg, T);

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        //IsqlCommand cmd = new SqlCommand();
                        if (UpdateTeacherAsync(dlg, T.ID).Result > 0)
                        {
                            //cmd.CommitTransaction();
                            GetData(olvSubject);
                            SeekHelper.SetListItem <Teacher, int>(T.ID, "ID", olvSubject);
                            return;
                        }
                        throw new Exception("Aktualizacja danych nie powiodła się!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
 private async Task <int> UpdateTeacherAsync(dlgTeacher dlg, int id)
 {
     using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
     {
         var dbs = scope.Resolve <IDataBaseService>();
         return(await dbs.UpdateRecordAsync(TeacherSQL.UpdateTeacher(), CreateUpdateParams(dlg, id)));
     }
 }
Beispiel #4
0
        IDictionary <string, object> CreateUpdateParams(dlgTeacher dlg, int id)
        {
            var sqlParamWithValue = new Dictionary <string, object>();

            User.UserRole R = (User.UserRole)Enum.Parse(typeof(User.UserRole), dlg.cbRole.SelectedValue.ToString());
            sqlParamWithValue.Add("@ID", id);
            sqlParamWithValue.Add("@Rola", R);
            sqlParamWithValue.Add("@Status", dlg.chkStatus.Checked);
            sqlParamWithValue.Add("@User", UserSession.User.Login);
            sqlParamWithValue.Add("@IP", AppSession.HostIP);
            return(sqlParamWithValue);
        }