private void ExecuteLoad(object obj) { if (obj != null) { byte id = Convert.ToByte(obj); if (!VehicleTypeList.Any(x => x.VTypeID == id)) { MessageBox.Show("Invalid Id.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } SelectedVehicle = VehicleTypeList.FirstOrDefault(x => x.VTypeID == id); } Vehicle = new VehicleType { VTypeID = SelectedVehicle.VTypeID, Description = SelectedVehicle.Description, Capacity = SelectedVehicle.Capacity, UID = SelectedVehicle.UID, ButtonImage = SelectedVehicle.ButtonImage, }; if (Vehicle.ButtonImage != null) { Vehicle.ImageSource = Imaging.BinaryToImage(Vehicle.ButtonImage); } SetAction(ButtonAction.Selected); }
public ParkingInViewModel(Dispatcher _D) { MessageBoxCaption = "Entrance"; d = _D; nepDate = new DateConverter(GlobalClass.TConnectionString); Parking = new ParkingIn(); SelectedParkingIn = new ParkingIn(); Vehicle = new VehicleType(); timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 1); timer.Tick += timer_Tick; timer.Start(); try { using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString)) { string strSql = "SELECT VTypeID, [Description],(SELECT SUM(Capacity) FROM PARKINGAREA WHERE VehicleType = VTypeID) Capacity, [UID], ButtonImage from VehicleType"; VTypeList = new ObservableCollection <VehicleType>(conn.Query <VehicleType>(strSql)); foreach (VehicleType vtype in VTypeList) { if (vtype.ButtonImage == null) { continue; } vtype.ImageSource = Imaging.BinaryToImage(vtype.ButtonImage); } PAOccupencyList = new ObservableCollection <ParkingArea>(conn.Query <ParkingArea>("SELECT PA_ID, PA_NAME, Capacity, VehicleType, MinVacantLot From ParkingArea")); foreach (ParkingArea pa in PAOccupencyList) { var VType = VTypeList.First(x => x.VTypeID == pa.VehicleType); pa.VType = VType; VType.PAOccupencyList.Add(pa); } } NewCommand = new RelayCommand(ExecuteNew); SaveCommand = new RelayCommand(ExecuteSave); UndoCommand = new RelayCommand(ExecuteUndo); RefreshDependencyCommand = new RelayCommand(RefreshDependency); PrintCommand = new RelayCommand(ExecutePrint); SetAction(ButtonAction.Init); SqlDependency.Start(GlobalClass.DataConnectionString); DoDependency(); } catch (Exception ex) { // var abc = new System.Windows.Media.Geometry(); MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error); } }