示例#1
0
 private void UpdateVehicleType()
 {
     if (MessageBox.Show(string.Format(UpdateConfirmText, "Vehicle Type"), 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 <TVehicleType>("SELECT VTypeID, [Description], Capacity, [UID] FROM VehicleType WHERE VTypeID = @VTypeID", Vehicle, tran).First());
                 if (Vehicle.ImageSource != null && Vehicle.ImageSource.UriSource != null)
                 {
                     Vehicle.ButtonImage = Imaging.FileToBinary(Vehicle.ImageSource.UriSource.LocalPath);
                 }
                 if (Vehicle.Update(tran))
                 {
                     GlobalClass.SetUserActivityLog(tran, "Vehicle Type", "Edit", WorkDetail: "VTypeId : " + Vehicle.VTypeID, Remarks: Remarks);
                     tran.Commit();
                     MessageBox.Show("Entrance Type Updated Successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     var vehicle = VehicleTypeList.First(x => x.VTypeID == Vehicle.VTypeID);
                     vehicle.Description = Vehicle.Description;
                     vehicle.Capacity    = Vehicle.Capacity;
                     vehicle.ButtonImage = Vehicle.ButtonImage;
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("Entrance Type could not be updated.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                     tran.Rollback();
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 2601)
         {
             MessageBox.Show("Entered Entrance name already exist in the database. Enter unique name and try again", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
         }
         else
         {
             MessageBox.Show(ex.Number + " : " + ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(GlobalClass.GetRootException(ex).Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
示例#2
0
 private void ExecuteDelete(object obj)
 {
     if (MessageBox.Show(string.Format(DeleteConfirmText, "Entrance Type"), 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 <TVehicleType>("SELECT VTypeID, [Description], Capacity, [UID] FROM VehicleType WHERE VTypeID = @VTypeID", Vehicle, tran).First());
                 if (Vehicle.Delete(tran))
                 {
                     GlobalClass.SetUserActivityLog(tran, "Entrance Type", "Delete", WorkDetail: "VTypeId : " + Vehicle.VTypeID, Remarks: Remarks);
                     tran.Commit();
                     MessageBox.Show("Entrance Type Deleted successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     VehicleTypeList.Remove(VehicleTypeList.First(x => x.VTypeID == Vehicle.VTypeID));
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("Entrance Type could not be Deleted.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 547)
         {
             MessageBox.Show("Selected entrance type 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);
     }
 }