예제 #1
0
 private void ExecuteDelete(object obj)
 {
     if (MessageBox.Show("You are about to delete selected Staff. Do you really want to proceed?", 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 tblStaff WHERE BARCODE = @BARCODE", staff, tran).First());
                 staff.Delete(tran);
                 GlobalClass.SetUserActivityLog(tran, "Staff Registration", "Delete", WorkDetail: "BARCODE : " + staff.BARCODE, Remarks: Remarks);
                 tran.Commit();
             }
             MessageBox.Show("Staff Deleted successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
             StaffList.Remove(StaffList.First(x => x.BARCODE == staff.BARCODE));
             ExecuteUndo(null);
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 547)
         {
             MessageBox.Show("Selected Staff cannot be deleted because it has already been linked to another transaction.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
         }
         else
         {
             MessageBox.Show(ex.Number + " : " + ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }