public ActionResult Edit(VehicleTypeList model)
        {
            SetActiveMenuItem();
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                //Set our updater name
                var FullName = Request.Cookies["userInfo"]["FullName"];

                //Now update the record
                VehicleTypeBLL.UpdateVehicleType(model, FullName);

                //Take our ID with us to the confirmation form
                ViewBag.Id = model.Id;

                //Determine the kind of SQL transaction we have performed
                ViewBag.Message = "updated";

                //We can now safely go to the confirmation view
                return(View("AddUpdateConfirm"));
            }
            catch (Exception ex)
            {
                TempData["ErrorMessage"] = ex.Message;
                return(Redirect("~/Admin/Home/Error"));
            }
        }
Beispiel #2
0
 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 ActionResult Create(VehicleTypeList model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                //Set our initial return value
                var returnValue = 0;
                //Set our updater name
                var FullName = Request.Cookies["userInfo"]["FullName"];
                //Attempt to add our record
                VehicleTypeBLL.AddVehicleType(model, FullName, out returnValue);

                //Take our ID with us to the confirmation form
                ViewBag.Id = returnValue;

                //Determine the kind of SQL transaction we have performed
                ViewBag.Message = "added";

                //We can now safely go to the confirmation view
                return(View("AddUpdateConfirm"));
            }
            catch (Exception ex)
            {
                TempData["ErrorMessage"] = ex.Message;
                return(Redirect("~/Admin/Home/Error"));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            VehicleTypeList vehicleTypeList = db.VehicleTypeLists.Find(id);

            db.VehicleTypeLists.Remove(vehicleTypeList);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #5
0
 private void AddNewVehicle()
 {
     SelectedDriver  = null;
     SelectedVehicle = new VehicleDTO
     {
         Type   = (VehicleTypes)VehicleTypeList.FirstOrDefault().Value,
         Number = _vehicleService.GetVehicleCode()
     };
 }
 public ActionResult Edit([Bind(Include = "Id,VehicleType,RequredSpace")] VehicleTypeList vehicleTypeList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vehicleTypeList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vehicleTypeList));
 }
Beispiel #7
0
        public static VehicleTypeList GetVehicleType(int VehicleTypeID)
        {
            var model = new VehicleTypeList();
            var dt    = VehicleTypeDAL.GetVehicleType(VehicleTypeID);
            var dr    = dt.Rows[0];

            model.Id      = (int)dr["VehicleTypeID"];
            model.Display = dr["VehicleType"].ToString();
            return(model);
        }
        public ActionResult Create([Bind(Include = "Id,VehicleType,RequredSpace")] VehicleTypeList vehicleTypeList)
        {
            if (ModelState.IsValid)
            {
                db.VehicleTypeLists.Add(vehicleTypeList);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vehicleTypeList));
        }
Beispiel #9
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);
     }
 }
Beispiel #10
0
 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);
     }
 }
        // GET: VehicleTypeLists/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VehicleTypeList vehicleTypeList = db.VehicleTypeLists.Find(id);

            if (vehicleTypeList == null)
            {
                return(HttpNotFound());
            }
            return(View(vehicleTypeList));
        }
Beispiel #12
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);
     }
 }
        public override void Update(ViewModelReturnData VMReturnData)
        {
            if (VMReturnData.NewCardType_Active)
            {
                View.Visibility = Visibility.Visible;

                #region Navigation Bar details
                VMReturnData.ViewTitle         = VMReturnData.EditCard ? "Edit Card" : "New Card";
                VMReturnData.SubTitle          = "Vehicle Type details";
                VMReturnData.CurrentPageNumber = 3;
                VMReturnData.TotalPageNumber   = 4;
                VMReturnData.MenuButtonEnabled = Visibility.Collapsed;
                VMReturnData.HelpButtonEnabled = Visibility.Visible;
                #endregion

                if (!OneTimeRead)
                {
                    VehicleTypeList    = new ObservableCollection <string>();
                    VehicleTypeList2   = new ObservableCollection <string>();
                    DisplayVehicleList = new ObservableCollection <string>();
                    index = 0;

                    foreach (var item in TagTypesL.MernokAssetType)
                    {
                        if (item.IsLicensable)
                        {
                            VehicleTypeList.Add(item.TypeName);
                        }
                    }

                    OneTimeRead    = true;
                    VehicleTypenum = 0;
                }

                if (Bypassed)
                {
                    DisplayVehicleList = new ObservableCollection <string> {
                        "All Vehicle Types"
                    };
                    ByEnabled = BtnAddEnabled = false;
                    VMReturnData.VMCardDetails.VehicleLicenceType = Enumerable.Repeat((uint)255, 30).ToArray();
                    VMReturnData.VMCardDetails.ByPassBits         = VMReturnData.VMCardDetails.ByPassBits | 0x04;
                    VMReturnData.NextButtonEnabled = true;
                }
                else
                {
                    DisplayVehicleList = VehicleTypeList2;
                    for (int i = 0; i < index; i++)
                    {
                        VMReturnData.VMCardDetails.VehicleLicenceType[i] = (byte)(TagTypesL.MernokAssetType.IndexOf(TagTypesL.MernokAssetType.Where(p => p.TypeName == VehicleTypeList2[i]).FirstOrDefault()) + 1);
                    }

                    ByEnabled = BtnAddEnabled = true;
                    VMReturnData.NextButtonEnabled        = VehicleTypeList2.Count() > 0 ? true : false;
                    VMReturnData.VMCardDetails.ByPassBits = (uint)(VMReturnData.VMCardDetails.ByPassBits & ~0b00000100);
                }

                if (AddbtnPressed)
                {
                    AddbtnPressed = false;
                    if (VehicleTypeList2.Count < 15)
                    {
                        VMReturnData.VMCardDetails.VehicleLicenceType[index] = (byte)(TagTypesL.MernokAssetType.IndexOf(TagTypesL.MernokAssetType.Where(p => p.TypeName == VehicleTypeList[VehicleTypenum]).FirstOrDefault()) + 1);
                        VehicleTypeList2.Add(VehicleTypeList[VehicleTypenum]);
                        index++;
                        VehicleTypeList.RemoveAt(VehicleTypenum);
                        VehicleTypenum = 0;
                    }
                    else
                    {
                        BtnAddEnabled = false;
                    }
                }

                if (RemovebtnPressed)
                {
                    RemovebtnPressed = false;
                    if (VehicleTypeList2.Count() > 0)
                    {
                        BtnremoveEnabled = true;
                        index--;
                        VMReturnData.VMCardDetails.VehicleLicenceType[index] = 0;
                        VehicleTypeList.Add(VehicleTypeList2.Last());
                        VehicleTypeList2.RemoveAt(VehicleTypeList2.Count - 1);
                    }
                }

                if (VehicleTypeList.Count > 0)
                {
                    ByEnabled = BtnAddEnabled = true;
                }
                else
                {
                    BtnAddEnabled = false;
                }

                if (VehicleTypeList2.Count() > 0)
                {
                    BtnremoveEnabled = true;
                }
                else
                {
                    BtnremoveEnabled = false;
                }
            }
            else
            {
                //View is not visible, do not update
                //Stop any animations on this vieModel
                OneTimeRead          = false;
                this.View.Visibility = Visibility.Collapsed;
            }
        }
Beispiel #14
0
 public static void AddVehicleType(VehicleTypeList model, string UpdatedBy, out int returnValue)
 {
     VehicleTypeDAL.AddVehicleType(model.Display, UpdatedBy, out returnValue);
 }
Beispiel #15
0
 public static void UpdateVehicleType(VehicleTypeList model, string UpdatedBy)
 {
     VehicleTypeDAL.UpdateVehicleType(model.Id, model.Display, UpdatedBy);
 }