Exemple #1
0
    public void ImportImage(FileUpload file)
    {
        DataAccess dacess = new DataAccess();

        DateTime date = Utility.GetCurrentDateTimeinUTC();

        string VendorCat  = drpVendorcategory.SelectedItem.Text;
        string Vendorname = txtvendorname.Text;
        String contact    = txtvendromobile.Text;
        String Address    = txtvendoraddress.Text;


        try
        {
            int    VendorID   = Convert.ToInt32(HiddenVendorEditID.Value);
            String VendorName = HiddenVendorName.Value;
            if (file.HasFile)
            {
                string base64      = Request.Form["imgCropped"];
                byte[] bytesImages = Convert.FromBase64String(base64.Split(',')[1]);
                String Savepath    = Request.PhysicalApplicationPath + "ImageServer\\Vendor\\";
                //Check if size is less than 2 MB
                if (bytesImages.Length < 2097152)
                {
                    VendorController vendorController = new VendorController();

                    bool result = vendorController.AddImage(bytesImages, VendorID, Savepath);
                    if (result)
                    {
                        lblstatus.Text = "";
                    }
                    else
                    {
                        lblstatus.Text = "Error Saving Image. Try again";
                    }
                }
                else
                {
                    lblstatus.Text = "Select smaller Image";
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert()", "alert('Please Select  a  image to upload')", true);
            }
        }
        catch (Exception ex)
        {
        }
        finally
        {
            RemoveFiles();
        }
    }
Exemple #2
0
    private void EditVendor()
    {
        DataAccess dacess = new DataAccess();

        // DateTime Updatedate = System.DateTime.Now;
        DateTime Updatedate     = Utility.GetCurrentDateTimeinUTC();
        String   NewvendorQuery = null;



        VendorController vendorController = new VendorController();

        try
        {
            int    VendorID   = Convert.ToInt32(HiddenVendorEditID.Value);
            String VendorName = HiddenVendorName.Value;

            if (checkEditVendor.Checked)
            {
                Vendor editVendor = new Vendor();
                editVendor.ID             = VendorID;
                editVendor.ShopCategoryID = Convert.ToInt32(drpVendorcategory.SelectedItem.Value);

                editVendor.VendorName     = txtvendorname.Text;
                editVendor.ContactNumber  = txtMobile2.Text;
                editVendor.ContactNumber2 = txtvendromobile.Text;

                editVendor.Address  = txtvendoraddress.Text;
                editVendor.Address2 = txtvendoraddress2.Text;

                vendorController.UpdateVendor(editVendor);
            }

            if (FileVendorImg.HasFile)
            {
                string base64      = Request.Form["imgCropped"];
                byte[] bytesImages = Convert.FromBase64String(base64.Split(',')[1]);
                String Savepath    = Request.PhysicalApplicationPath + "ImageServer\\Vendor\\";
                //Check if size is less than 2 MB
                if (bytesImages.Length < 2097152)
                {
                    bool result = vendorController.AddImage(bytesImages, VendorID, Savepath);
                    if (result)
                    {
                        lblstatus.Text = "";
                    }
                    else
                    {
                        lblstatus.Text = "Error Saving Image. Try again";
                    }
                }
                else
                {
                    lblstatus.Text = "Select smaller Image";
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert()", "alert('Please Select  a  image to upload')", true);
            }
        }
        catch (Exception ex)
        {
            int a = 1;
        }
    }
Exemple #3
0
    protected void btnNewvendor_Click(object sender, EventArgs e)
    {
        if (HiddenVendorEditID.Value != "" && HiddenVendorName.Value != "")
        {
            EditVendor();
            return;
        }
        else if (HiddenVendorEditID.Value == "" && HiddenVendorName.Value == "")
        {
            DataAccess           dacess      = new DataAccess();
            System.Drawing.Image EditedImage = null;
            System.Drawing.Image image       = null;
            //DateTime date = System.DateTime.Now;

            Vendor newVendor = new Vendor();

            DateTime date = Utility.GetCurrentDateTimeinUTC();
            newVendor.ShopCategoryID = Convert.ToInt32(drpVendorcategory.SelectedItem.Value);
            newVendor.VendorName     = txtvendorname.Text;
            newVendor.IconFormat     = FileVendorImg.PostedFile.ContentType;
            newVendor.ContactNumber  = txtvendromobile.Text;
            newVendor.ContactNumber2 = txtMobile2.Text;
            newVendor.Address        = txtvendoraddress.Text;
            newVendor.Address2       = txtvendoraddress2.Text;
            newVendor.InsertDate     = Utility.GetCurrentDateTimeinUTC();
            try
            {
                if (FileVendorImg.HasFile)
                {
                    if (FileVendorImg.PostedFile.ContentLength > 20728650)
                    {
                        lblstatus.Text = "Image Size is large, Please select smaller Image";
                        return;
                    }
                }

                VendorController vendorController = new VendorController();
                int VendorID = vendorController.AddVendor(newVendor);

                if (VendorID > 0)
                {
                    if (FileVendorImg.HasFile)
                    {
                        String Savepath = Request.PhysicalApplicationPath + "Images/Vendor";
                        //FileVendorImg.SaveAs(Savepath + FileVendorImg.FileName);
                        //image = System.Drawing.Image.FromFile(Savepath + FileVendorImg.FileName);

                        string imagename = Path.GetFileNameWithoutExtension(FileVendorImg.FileName);


                        string base64      = Request.Form["imgCropped"];
                        byte[] bytesImages = Convert.FromBase64String(base64.Split(',')[1]);

                        vendorController.AddImage(bytesImages, VendorID, Savepath);
                    }
                    else
                    {
                        FillVendorDataList(muser.currentResident.SocietyID, muser.currentResident.UserType);
                        ClientScript.RegisterStartupScript(this.GetType(), "alert('')", "CloseAddVendor()", true);
                    }
                }
                else
                {
                    lblstatus.Text = "Vendor Added Failed";
                }
            }

            /*
             *          try
             *          {
             *              //Condition to check if the file uploaded or not
             *              if (FileVendorImg.HasFile)
             *              {
             *                  if (FileVendorImg.PostedFile.ContentLength < 20728650)
             *                  {
             *                      //Save  the  image  to  local  folder
             *                      String Savepath = Request.PhysicalApplicationPath + "Images/Vendor";
             *                      //FileVendorImg.SaveAs(Savepath + FileVendorImg.FileName);
             *                      //image = System.Drawing.Image.FromFile(Savepath + FileVendorImg.FileName);
             *
             *                      string imagename = Path.GetFileNameWithoutExtension(FileVendorImg.FileName);
             *
             *
             *                      string base64 = Request.Form["imgCropped"];
             *                      byte[] bytesImages = Convert.FromBase64String(base64.Split(',')[1]);
             *
             *
             *
             *
             *                      using (SqlConnection con1 = new SqlConnection(Utility.SocietyConnectionString))
             *                      {
             *                          con1.Open();
             *                          // SqlCommand cmd = new SqlCommand("INSERT INTO Vendors (ShopCategory,VendorName,ContactNumber,Address,VendorIcon,VendorIconFormat) VALUES (@ShopCategory,@VendorName,@ContactNum,@Address,@VendorIcon,@VendorIconFormat)", con1);
             *                          SqlCommand cmd = new SqlCommand("Insert Into Vendors (ShopCategory,VendorName,ContactNumber,ContactNumber2,Address,Address2,VendorIcon,VendorIconFormat,date,SocietyID,CmdType) Values ('"
             + VendorCat + "','" + Vendorname + "','" + contact + "','" + contact2 + "','" + Address + "','" + Address2 + "',@VendorIcon,'" + VendorIconFormat + "','" + Utility.ChangeDateTimeLocalToSQLServerFormat(date) + "'," + SessionVariables.SocietyID + ",'Insert')", con1);
             +                          cmd.Parameters.Add("@VendorIcon", SqlDbType.Image).Value = bytesImages;
             +                          int count = cmd.ExecuteNonQuery();
             +                          con1.Close();
             +
             +                          if (count == 1)
             +                          {
             +
             +                              FillVendorDataList(muser.currentResident.SocietyID,muser.currentResident.UserType);
             +
             +                          }
             +
             +                          else
             +                          {
             +                              ClientScript.RegisterStartupScript(this.GetType(), "alert('')", "VendorActionPopup()", true);
             +                              lblstatus.Text = "Vendor Added Failed";
             +                              // lblVendrAuctionlMsg.Text = "Vendor Added Failed";
             +                          }
             +                      }
             +                  }
             +              }
             +              else
             +              {
             +                  String InsetdataQuery = "Insert Into Vendors (ShopCategory,VendorName,ContactNumber,ContactNumber2,Address,Address2,date,SocietyID, CmdType) Values ('"
             + VendorCat + "','" + Vendorname + "','" + contact + "','" + contact2 + "','" + Address + "','" + Address2 + "','" + Utility.ChangeDateTimeLocalToSQLServerFormat(date) + "'," + SessionVariables.SocietyID + ",'insert')";
             +                  bool result = dacess.Update(InsetdataQuery);
             +
             +                  if (result == true)
             +                  {
             +                      Response.AddHeader("REFRESH", "50;URL=Vendors.aspx");
             +                      Response.Redirect("Vendors.aspx", false);
             +                  }
             +
             +                  else
             +                  {
             +                      ClientScript.RegisterStartupScript(this.GetType(), "alert('')", "Showpopup()", true);
             +                      lblstatus.Text = "Vendor Added Failed";
             +                  }
             +              }
             +
             +          }
             */
            catch (Exception ex)
            {
                lblstatus.Text = ex.Message;
            }

            finally
            {
                // EditedImage.Dispose();
                // image.Dispose();
                RemoveFiles();
            }
        }
    }