Example #1
0
 private void UpdateShift()
 {
     if (MessageBox.Show(string.Format(UpdateConfirmText, "Shift"), MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction tran = Conn.BeginTransaction())
             {
                 string Remarks = Newtonsoft.Json.JsonConvert.SerializeObject(Conn.Query <Shift>("SELECT * FROM tblShift WHERE SHIFT_ID = @SHIFT_ID", shift, tran).First());
                 if (shift.Update(tran))
                 {
                     GlobalClass.SetUserActivityLog(tran, "Attendant Shift", "Edit", WorkDetail: "SHIFT_ID : " + shift.SHIFT_ID, Remarks: Remarks);
                     tran.Commit();
                     MessageBox.Show("Shift Updated Successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     var vehicle = ShiftList.First(x => x.SHIFT_ID == shift.SHIFT_ID);
                     vehicle.SHIFT_NAME   = shift.SHIFT_NAME;
                     vehicle.SHIFT_START  = shift.SHIFT_START;
                     vehicle.SHIFT_END    = shift.SHIFT_END;
                     vehicle.SHIFT_STATUS = shift.SHIFT_STATUS;
                     vehicle.UID          = GlobalClass.User.UID;
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("shift Type could not be updated.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                     tran.Rollback();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (ex is SqlException && (ex as SqlException).Number == 2601)
         {
             MessageBox.Show("Entered shift name already exist in the database. Enter unique name and try again", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
         }
         MessageBox.Show(GlobalClass.GetRootException(ex).Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #2
0
 private void ExecuteDelete(object obj)
 {
     if (MessageBox.Show(string.Format(DeleteConfirmText, "Shift"), MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction tran = Conn.BeginTransaction())
             {
                 string Remarks = Newtonsoft.Json.JsonConvert.SerializeObject(Conn.Query <Shift>("SELECT * FROM tblShift WHERE SHIFT_ID = @SHIFT_ID", shift, tran).First());
                 if (shift.Delete(tran))
                 {
                     GlobalClass.SetUserActivityLog(tran, "Attendant Shift", "Delete", WorkDetail: "SHIFT_ID : " + shift.SHIFT_ID, Remarks: Remarks);
                     tran.Commit();
                     MessageBox.Show("Shift deleted successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     ShiftList.Remove(ShiftList.First(x => x.SHIFT_ID == shift.SHIFT_ID));
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("Shift Type could not be Deleted.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                     tran.Rollback();
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 547)
         {
             MessageBox.Show("Selected shift cannot be deleted because it has already been linked to another transaction.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
         }
         MessageBox.Show(ex.Number + " : " + ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }