protected void btnRemoveImgPicture3_ServerClick(object sender, EventArgs e)
        {
            if (Session["Image3"] != null)
                {
                    imageUtil = new ImageUtility();
                    string realPhysicalPath = Server.MapPath("~/img/blog/blog-thumb-1.jpg");

                        imgVehiclePicture3.Src = imageUtil.getBase64String(realPhysicalPath);
                        Session.Remove("Image3");
                        imageUtil = null;
                }
        }
        protected void repeatVehicle_ItemCreated(object sender, ListViewItemEventArgs e)
        {
            if (e.Item is ListViewDataItem)
            {
                ImageUtility imageObj = new ImageUtility();
                DataTable items = (DataTable)ViewState["VehicleItems"];
                var item = e.Item;
                HtmlImage image = (HtmlImage)item.FindControl("imgVehiclePicture1");
                int index = e.Item.DataItemIndex;

                DataRow dr = items.Rows[index];
                byte[] picture1 = DBUtility.readDBImage(dr,"Picture_1");
                if (image != null && picture1 != null)
                {
                    image.Src = imageObj.byteArrayToBase64String(picture1);
                }
            }
        }
        protected void btnSaveVehicle_ServerClick(object sender, EventArgs e)
        {
            VehicleObject obj = new VehicleObject();
            imageUtil = new ImageUtility();

            obj.AC = chkBoxAC.Checked;
            obj.Airbag = chkBoxAirbags.Checked;
            obj.AL = chkBoxAL.Checked;
            if (dateVehicleArrivalDate.Value != "")
            {
                obj.Arrival_Date = DateTime.ParseExact(dateVehicleArrivalDate.Value, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            }
            obj.Automatic_Transmission = chkBoxAL.Checked;
            obj.CD = chkBoxAL.Checked;
            obj.Chassis_Number = txtVehicleChassisNumber.Value;
            obj.CI = chkBoxCI.Checked;
            obj.Colour = txtVehicleColour.Value;
            obj.Condition = txtVehicleCondition.Value;
            obj.COR = chkBoxCOR.Checked;
            if (txtVehicleCostPrice.Value != "")
            {
                obj.Cost_Price = Convert.ToDecimal(txtVehicleCostPrice.Value);
            }
            obj.Engine_Number = txtVehicleEngineNumber.Value;
            obj.Extra_Features = txtVehicleExtraFeatures.Value;
            obj.FSH = chkBoxFSH.Checked;
            obj.Gearlock = chkBoxGearlock.Checked;
            obj.Leather = chkBoxLeather.Checked;
            obj.Location_Name = lstVehicleLocation.Value;
            obj.Mags = chkBoxMags.Checked;
            obj.Manufacturer_Name = lstVehicleManufacturerName.Value;
            if (txtVehicleMileage.Value != "")
            {
                obj.Mileage = Convert.ToInt32(txtVehicleMileage.Value);
            }
            obj.Model_Name = lstVehicleModelName.Value;
            obj.MP3 = chkBoxMP3.Checked;
            if (Session["Image1"] != null)
            {
                obj.Picture_1 = imageUtil.imageToByteArray(Session["Image1"].ToString());

            }
            if (Session["Image2"] != null)
            {
                obj.Picture_2 = imageUtil.imageToByteArray(Session["Image2"].ToString());
            }
            if (Session["Image3"] != null)
            {
                obj.Picture_3 = imageUtil.imageToByteArray(Session["Image3"].ToString());
            }
            obj.PS = chkBoxPS.Checked;
            obj.Registration_Number = txtVehicleRegistrationNumber.Value;
            if (txtVehicleRetailPrice.Value != "")
            {
                obj.Retail_Price = Convert.ToDecimal(txtVehicleRetailPrice.Value);
            }
            obj.RT = chkBoxRT.Checked;
            obj.Sports_Kit = chkBoxSportsKit.Checked;
            obj.SR = chkBoxSR.Checked;
            obj.Supplier_NameProp = lstVehicleSupplier.Value;
            obj.Vehicle_Status = lstVehicleStatus.Value;
            if (txtVehicleWholesalePrice.Value != "")
            {
                obj.Wholesale_Price = Convert.ToDecimal(txtVehicleWholesalePrice.Value);
            }

            ManageVehicle vehicleObj = new ManageVehicle();

            bool success = vehicleObj.updateAVehicle(ConfigurationManager.ConnectionStrings["MVSSqlDev2008ConnectionString"].ConnectionString,obj,(int)ViewState["id"]);

            if (success)
            {
                divSuccess.Visible = true;
            }
            else
                divFailure.Visible = true;
            imageUtil = null;
        }
 private void bindImages()
 {
     if (editVehicle.Picture_1.Length > 0)
     {
         imageUtil = new ImageUtility();
         imgVehiclePicture1.Src = imageUtil.byteArrayToBase64String(editVehicle.Picture_1);
     }
     if (editVehicle.Picture_2.Length > 0)
     {
         imageUtil = new ImageUtility();
         imgVehiclePicture2.Src = imageUtil.byteArrayToBase64String(editVehicle.Picture_2);
     }
     if (editVehicle.Picture_3.Length > 0)
     {
         imageUtil = new ImageUtility();
         imgVehiclePicture3.Src = imageUtil.byteArrayToBase64String(editVehicle.Picture_3);
     }
 }
        protected void btnUploadImgPicture1_ServerClick(object sender, EventArgs e)
        {
            if (filePicture1.HasFiles)
            {
                int count = 0;
                foreach (HttpPostedFile file in filePicture1.PostedFiles)
                {
                    count++;
                    imageUtil = new ImageUtility();
                    string realPhysicalPath = Path.Combine(Server.MapPath("~/upload/"), file.FileName);
                    file.SaveAs(realPhysicalPath);
                    //imgVehiclePicture1.Src = realPhysicalPath;

                    //imgVehiclePicture.Attributes["src"] = imageUtil.getBase64String(realPhysicalPath);
                    Session.Add("Image"+count, realPhysicalPath);
                    imageUtil.Dispose();

                    filePicture1 = null;
                    GC.Collect();

                }

                imgVehiclePicture1.Attributes["src"] = imageUtil.getBase64String(Session["Image1"].ToString());
                if (Session["Image2"] != null)
                {
                    imgVehiclePicture2.Attributes["src"] = imageUtil.getBase64String(Session["Image2"].ToString());
                }
                if (Session["Image3"] != null)
                {
                    imgVehiclePicture3.Attributes["src"] = imageUtil.getBase64String(Session["Image3"].ToString());
                }
            }
        }
        protected void grdVehicles_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if(e.Row.RowType == DataControlRowType.DataRow)
               {
                Image image = e.Row.FindControl("vehicleImage") as Image;
                DataTable vehicleList = Session["SEARCH_VEHICLES"] as DataTable;
                GridViewRow row = e.Row;
                int index = e.Row.DataItemIndex;

                if (image != null)
                {
                    DataRow dr = vehicleList.Rows[index];
                    imageUtil = new ImageUtility();
                    byte[] picture1 = DBUtility.readDBImage(dr,"Picture_1");
                    if (image != null && picture1 != null)
                    {
                        image.ImageUrl = imageUtil.byteArrayToBase64String(picture1);
                    }

                }

            }
        }