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); } }
private void SaveVehicleType() { if (MessageBox.Show(string.Format(SaveConfirmText, "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()) { Vehicle.VTypeID = Conn.ExecuteScalar <byte>("SELECT CAST(ISNULL(MAX(VTypeID), 0) + 1 AS TINYINT) FROM VehicleType", transaction: Tran); if (Vehicle.ImageSource != null) { Vehicle.ButtonImage = Imaging.FileToBinary(Vehicle.ImageSource.UriSource.LocalPath); } if (Vehicle.Save(Tran)) { GlobalClass.SetUserActivityLog(Tran, "Entrance Type", "New", WorkDetail: "VTypeID : " + Vehicle.VTypeID, Remarks: Vehicle.Description); Tran.Commit(); MessageBox.Show("Entrance Type Saved Successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information); VehicleTypeList.Add(new VehicleType { VTypeID = Vehicle.VTypeID, Description = Vehicle.Description, Capacity = Vehicle.Capacity, UID = GlobalClass.User.UID }); ExecuteUndo(null); } else { MessageBox.Show("Entrance Type could not be Saved.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation); } } } } 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(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error); } }