Ejemplo n.º 1
0
    protected string renameFilePath()
    {
        string str       = "";
        int    index     = Session["User_ID"].ToString().IndexOf("@");
        String imageName = Session["User_ID"].ToString().Substring(0, index);

        if (FileUploadImage.HasFile)
        {
            string relativePath = @"/propertyImages/" + imageName + Path.GetExtension(FileUploadImage.FileName);
            FileUploadImage.SaveAs(Server.MapPath(relativePath));

            //FileUploadImage.SaveAs("~/propertyImages/" + Session["User_ID"].ToString() + ".png");
            //str += "/propertyImages/" + Session["User_ID"].ToString() + ".jpg";
            return(relativePath);
        }
        else
        {
            str += "/propertyImages/error.png";
        }

        return(str);
    }
Ejemplo n.º 2
0
        private string GravarImagemNoDisco()
        {
            if (FileUploadImage.HasFile)
            {
                try
                {
                    var caminho  = $"{AppDomain.CurrentDomain.BaseDirectory}Content\\ImagensJogos\\";
                    var fileName = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}_{FileUploadImage.FileName}";
                    FileUploadImage.SaveAs($"{caminho}{fileName}");

                    return(fileName);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
    protected void ButtonUpload_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection();

        conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        SqlCommand cmd = new SqlCommand();

        cmd.Connection = conn;

        cmd.CommandText = @"INSERT INTO pages (page_text, page_images, page_headings, opening_hours, opening_changes, contact_info) VALUES (@p_text, @p_image, @p_heading, @opening_hours, @opening_changes, @contact_info)";
        cmd.Parameters.AddWithValue("@p_heading", TextBoxTitle.Text);
        cmd.Parameters.AddWithValue("@p_text", TextBoxDescription.Text.Replace(Environment.NewLine, "<br>"));
        cmd.Parameters.AddWithValue("@opening_changes", TextBoxOpeningChanges.Text.Replace(Environment.NewLine, "<br>"));
        cmd.Parameters.AddWithValue("@opening_hours", TextBoxOpeningHours.Text.Replace(Environment.NewLine, "<br>"));
        cmd.Parameters.AddWithValue("@contact_info", TextBoxContactInfo.Text.Replace(Environment.NewLine, "<br>"));

        #region image1
        //database sti til billede
        string bill_sti = "intetbillede.jpg";
        if (FileUploadImage.HasFile)
        {
            //NewGuid danner uniq navn for billeder
            bill_sti = Guid.NewGuid() + Path.GetExtension(FileUploadImage.FileName);
            // Opret
            String UploadeMappe = Server.MapPath("~/images/frontpage/");
            String Filnavn      = DateTime.Now.ToFileTime() + FileUploadImage.FileName;
            bill_sti = Filnavn;
            //Gem det orginale Billede
            FileUploadImage.SaveAs(UploadeMappe + Filnavn);
        }
        // Tildel parameter-værdierne, fra input felterne.
        cmd.Parameters.AddWithValue("@p_image", bill_sti);
        #endregion

        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
        Response.Redirect("FrontpageEditing.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String        con        = "Server=.;Database=OnlineNoteBook; Integrated Security=true";
        SqlConnection connection = new SqlConnection(con);

        if (FileUploadImage.HasFile)
        {
            FileUploadImage.SaveAs(Server.MapPath("~/Gallery/") + Path.GetFileName(FileUploadImage.FileName));
            string link = "~/Gallery/" + Path.GetFileName(FileUploadImage.FileName);

            connection.Open();
            string _queryString;
            _queryString = "Insert into ImagGallery(Date,Location,ShortDerscription,Image,UserEmail) values('" + DateTime.UtcNow.Date.ToString("yyyy-M-d") + "','" + TextBoxLocation.Text + "','" + TextBoxShortDescription.Text + "', '" + link + "','" + Session["email"].ToString() + "');";
            SqlCommand cmd = new SqlCommand(_queryString, connection);
            cmd.ExecuteNonQuery();
            Response.Redirect("ImageGallery.aspx");
            Label5.Text = "Save successfully";
        }
        else
        {
            Label4.Text = "Image is required";
        }
    }
Ejemplo n.º 5
0
        protected void BtAddDish_Click(object sender, EventArgs e)
        {
            bool state = true;

            if (TxtState.Text.ToLower().Trim() == "habilitado")
            {
                state = true;
            }
            else
            {
                state = false;
            }
            BLDish newDish = new BLDish(TxtName.Text.Trim(), TxtDescription.Text.Trim(), decimal.Parse(TxtPrice.Text.ToLower().Trim()), state, FileUploadImage.FileName);

            FileUploadImage.SaveAs(Server.MapPath("../DishesPicture/").ToString() + FileUploadImage.FileName);
            newDish.addDish(newDish);

            addDishForm.Visible = false;
            String css    = successRegistration.Attributes["class"];
            String newCss = css.Replace("hidden", "");

            successRegistration.Attributes.Add("class", newCss);
        }
Ejemplo n.º 6
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        String        con        = "Server=.;Database=OnlineNoteBook; Integrated Security=true";
        SqlConnection connection = new SqlConnection(con);

        if (FileUploadImage.HasFile)
        {
            FileUploadImage.SaveAs(Server.MapPath("~/RegImage/") + Path.GetFileName(FileUploadImage.FileName));
            string link = "~/RegImage/" + Path.GetFileName(FileUploadImage.FileName);
            connection.Open();
            //updating the record
            SqlCommand cmd = new SqlCommand("Update Registration set Name='" + TextBoxName.Text + "', Phone='" + TextBoxPhone.Text + "',Address='" + TextBoxAddress.Text + "', Image='" + link + "' where Email='" + Session["email"].ToString() + "'", connection);
            cmd.ExecuteNonQuery();
            connection.Close();
        }
        else
        {
            connection.Open();
            //updating the record
            SqlCommand cmd = new SqlCommand("Update Registration set Name='" + TextBoxName.Text + "', Phone='" + TextBoxPhone.Text + "',Address='" + TextBoxAddress.Text + "' where Email='" + Session["email"].ToString() + "'", connection);
            cmd.ExecuteNonQuery();
            connection.Close();
        }
    }
Ejemplo n.º 7
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtFoodname.Text != null && txtPrice.Text != null && ddlMenuCategory.SelectedIndex != -1 && txtDescription.Text != null)
         {
             string ext = System.IO.Path.GetExtension(this.FileUploadImage.PostedFile.FileName).ToLower();
             if (!(ext.Equals(".jpg") || ext.Equals(".png") || ext.Equals(".gif") || ext.Equals(".jpeg")))
             {
                 //if (ext != ".jpg" || ext != ".png" || ext != ".gif" || ext != ".jpeg")
                 Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Please choose only .jpg, .png and .gif image types!')", true);
             }
             else
             {
                 if (btnSubmit.Text != "Update")
                 {
                     DataTable dt = menu.CheckImageInDatabase(FileUploadImage.FileName);
                     if (dt.Rows.Count != 0)
                     {
                         ltlMsg.Text = "There is another image with same name ! ";
                     }
                     else
                     {
                         int i = menu.CreateMenu(txtFoodname.Text, Convert.ToInt32(ddlMenuCategory.SelectedItem.Value), Convert.ToDecimal(txtPrice.Text), FileUploadImage.FileName, txtDescription.Text);
                         if (i > 0)
                         {
                             FileUploadImage.SaveAs(Server.MapPath("~/MenuImages/" + FileUploadImage.FileName));
                             ltlMsg.Text = "Successfully added menu.";
                             ClearFields();
                         }
                         else
                         {
                             ltlMsg.Text = "Failed to add menu.";
                             ClearFields();
                         }
                     }
                 }
                 else
                 {
                     DataTable dt = menu.CheckImageInDatabase(FileUploadImage.FileName);
                     if (dt.Rows.Count != 0)
                     {
                         ltlMsg.Text = "There is another image with same name !";
                     }
                     else
                     {
                         string fileName;
                         string oldfileName = "";
                         if (FileUploadImage.HasFile)
                         {
                             DataTable dtImage = menu.GetFileName(Convert.ToInt32(HiddenField1.Value));
                             oldfileName = dtImage.Rows[0]["Image"].ToString();
                             fileName    = FileUploadImage.FileName;
                         }
                         else
                         {
                             fileName = lblImageName.Text;
                         }
                         int i = menu.UpdateMenu(txtFoodname.Text, Convert.ToInt32(ddlMenuCategory.SelectedItem.Value), Convert.ToDecimal(txtPrice.Text), fileName, txtDescription.Text, Convert.ToInt32(HiddenField1.Value));
                         if (i > 0)
                         {
                             if (oldfileName != null && oldfileName != fileName)
                             {
                                 if (File.Exists(Server.MapPath("~/Images/" + oldfileName)))
                                 {
                                     File.Delete(Server.MapPath("~/Images/" + oldfileName));
                                 }
                             }
                             ltlMsg.Text = "Successfully Updated.";
                             ClearFields();
                         }
                         else
                         {
                             ltlMsg.Text = "Failed to update.";
                             ClearFields();
                         }
                     }
                 }
             }
         }
         else
         {
             ltlMsg.Text = "All fields required.";
         }
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }
Ejemplo n.º 8
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtFirstName.Text != null && txtFirstName.Text != null && txtDOB.Text != null && ddlGender.SelectedIndex != 0 && ddlClass.SelectedIndex != 0)
            {
                if (FileUploadImage.HasFile)
                {
                    string ext = System.IO.Path.GetExtension(this.FileUploadImage.PostedFile.FileName).ToLower();
                    if (!(ext.Equals(".jpg") || ext.Equals(".png") || ext.Equals(".gif") || ext.Equals(".jpeg")))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Please choose only .jpg, .png and .gif image types!')", true);
                        return;
                    }
                }
                if (btnSubmit.Text != "Update")
                {
                    if (string.IsNullOrEmpty(this.FileUploadImage.PostedFile.FileName))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Please upload image')", true);
                        return;
                    }
                    //DataTable dt = _bllMenu.CheckFoodNameInDatabase(txtFoodname.Text);
                    //if (dt.Rows.Count != 0)
                    //{
                    //    ltlMsg.ForeColor = Color.Red;
                    //    ltlMsg.Text = "The Food Name with same name already exists.";
                    //}
                    else
                    {
                        string imageExtension = System.IO.Path.GetExtension(FileUploadImage.FileName).ToLower();
                        cc.SaveChild(txtFirstName.Text, txtLastName.Text, txtDOB.Text, ddlGender.Text, ddlClass.Text, txtFirstName.Text.Replace("", "-") + imageExtension);
                        string s = Server.MapPath("~/ChildImages/");
                        FileUploadImage.SaveAs(Path.Combine(s, txtFirstName.Text.Replace(" ", "-") + imageExtension));
                        ltlMsg.ForeColor = Color.Green;
                        ltlMsg.Text      = "Child Successfully Added.";
                        ClearFields();
                    }
                }
            }
            else
            {
                string oldImageName = lblImageName.Text;
                string imageName    = lblImageName.Text;

                if (FileUploadImage.HasFile)
                {
                    var    name           = txtFirstName.Text.Replace(" ", "-");
                    string imageExtension = System.IO.Path.GetExtension(FileUploadImage.FileName).ToLower();
                    imageName = name + imageExtension;
                    int value = Convert.ToInt16(HiddenField1.Value);
                    cc.UpdateChild(value, txtFirstName.Text, txtLastName.Text, txtDOB.Text, ddlGender.Text, ddlClass.Text, txtFirstName.Text.Replace("", "-") + imageExtension);
                    string s = Server.MapPath("~/ChildImages/");
                    if (File.Exists(Path.Combine(s, oldImageName)))
                    {
                        File.Delete(Path.Combine(s, oldImageName));
                    }
                    FileUploadImage.SaveAs(Path.Combine(s, imageName));
                    ltlMsg.Text = "Child Successfully Updated.";
                    ClearFields();
                }
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert(" + ex.Message + ");window.location.replace('Child.aspx');", true);
        }
    }
Ejemplo n.º 9
0
        protected void btn_Update_Click(object sender, EventArgs e)
        {
            lbl_intro.ForeColor = Color.Red;

            if (TextBoxTitle.Text.Length == 0 || TextBoxTitle.Text.Length > 50)
            {
                lbl_intro.Text = "Length of Title should be 1-50";
                return;
            }

            if (ddl_category.SelectedIndex == -1)
            {
                lbl_intro.Text = "Please Choose Category!";
                return;
            }

            if (TextBoxAuthor.Text.Length < 3)
            {
                lbl_intro.Text = "Author is too short!";
                return;
            }
            int year;
            if (!int.TryParse(TextBoxYear.Text, out year))
            {
                lbl_intro.Text = "Please enter year correctly!";
                return;
            }
            if (year > DateTime.Now.Year || year < 1600)
            {
                lbl_intro.Text = "Year should be 1600-" + DateTime.Now.Year.ToString();
                return;
            }

            if (TextBoxPublisher.Text.Length < 3)
            {
                lbl_intro.Text = "Publisher is too short!";
                return;
            }

            if (TextBoxDesc.Text.Length < 50)
            {
                lbl_intro.Text = "Desc is too short!";
                return;
            }

            if (!regexValidator.IsValid)
            {
                lbl_intro.Text = "Please Choose only .jpg .jpeg .png";
                return;
            }


            string id = Request.QueryString["bid"];
            var item = from u in db.tbl_Books
                       where u.BookId == int.Parse(id)
                       select u;
            foreach (var z in item)
            {
                z.Author = TextBoxAuthor.Text;
                z.BookDesc = TextBoxDesc.Text;
                z.BookTitle = TextBoxTitle.Text;
                z.CategoryID = int.Parse(ddl_category.SelectedValue.ToString());
                z.Publisher = TextBoxPublisher.Text;
                z.Year = year;
                if (FileUploadImage.HasFile)
                {
                    z.ImagePath = "~/images/" + FileUploadImage.FileName;
                    FileUploadImage.SaveAs(Server.MapPath("~/images/" + FileUploadImage.FileName));
                }
                db.SubmitChanges();

                lbl_intro.ForeColor = Color.Green;
                lbl_intro.Text = z.BookTitle + " Has Been Updated Successfully";
            }


            
            
        }
        private void Save(string strLink = "")
        {
            try
            {
                var Product = _ProductRepo.GetById(id);
                if (id > 0 && Product != null)
                {
                    Product.CODE       = txtCode.Text;
                    Product.SHAPE_CODE = ddlShape.SelectedValue;
                    if (FileUploadImage.Visible && FileUploadImage.HasFile)
                    {
                        string imgName     = Product.IMAGE;
                        string productPath = Server.MapPath(Cost.PRODUCTPATH) + imgName;
                        if (File.Exists(productPath))
                        {
                            File.Delete(productPath);
                        }

                        imgName     = Product.ID + Path.GetExtension(FileUploadImage.FileName);
                        productPath = Server.MapPath(Cost.PRODUCTPATH) + imgName;
                        FileUploadImage.SaveAs(productPath);

                        Product.IMAGE = imgName;
                    }
                    _ProductRepo.Update(Product);

                    strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-san-pham.aspx?id=" + id : strLink;
                }
                else
                {
                    Product            = new PRODUCT();
                    Product.CODE       = txtCode.Text;
                    Product.SHAPE_CODE = ddlShape.SelectedValue;
                    //Product.CREATOR_ID = Utils.CIntDef(Session["Userid"]);
                    //Product.CREATED_DATE = DateTime.Now;
                    _ProductRepo.Create(Product);

                    Product = _ProductRepo.GetById(Product.ID);
                    if (Product.ID > 0 && Product != null)
                    {
                        if (FileUploadImage.Visible && FileUploadImage.HasFile)
                        {
                            string imgName = Product.ID + Path.GetExtension(FileUploadImage.FileName);
                            FileUploadImage.SaveAs(Server.MapPath(Cost.PRODUCTPATH) + imgName);

                            Product.IMAGE = imgName;

                            _ProductRepo.Update(Product);
                        }
                    }
                    strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-san-pham.aspx?id=" + Product.ID : strLink;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (!string.IsNullOrEmpty(strLink))
                {
                    Response.Redirect(strLink);
                }
            }
        }
Ejemplo n.º 11
0
        protected void btn_add_Click(object sender, EventArgs e)
        {
            lbl_intro.ForeColor = Color.Red;

            if (TextBoxTitle.Text.Length == 0 || TextBoxTitle.Text.Length > 50)
            {
                lbl_intro.Text = "Length of Title should be 1-50";
                return;
            }

            if (ddl_category.SelectedIndex == -1)
            {
                lbl_intro.Text = "Please Choose Category!";
                return;
            }

            if (TextBoxAuthor.Text.Length < 3)
            {
                lbl_intro.Text = "Author is too short!";
                return;
            }
            int year;

            if (!int.TryParse(TextBoxYear.Text, out year))
            {
                lbl_intro.Text = "Please enter year correctly!";
                return;
            }
            if (year > DateTime.Now.Year || year < 1600)
            {
                lbl_intro.Text = "Year should be 1600-" + DateTime.Now.Year.ToString();
                return;
            }

            if (TextBoxPublisher.Text.Length < 3)
            {
                lbl_intro.Text = "Publisher is too short!";
                return;
            }

            if (TextBoxDesc.Text.Length < 50)
            {
                lbl_intro.Text = "Desc is too short!";
                return;
            }

            if (!regexValidator.IsValid)
            {
                lbl_intro.Text = "Please Choose only .jpg .jpeg .png";
                return;
            }


            tbl_Book newBook = new tbl_Book();

            newBook.Author     = TextBoxAuthor.Text;
            newBook.BookDesc   = TextBoxDesc.Text;
            newBook.BookTitle  = TextBoxTitle.Text;
            newBook.CategoryID = int.Parse(ddl_category.SelectedValue.ToString());
            newBook.Publisher  = TextBoxPublisher.Text;
            newBook.Year       = year;
            newBook.ImagePath  = "~/images/" + FileUploadImage.FileName;
            if (FileUploadImage.HasFile)
            {
                FileUploadImage.SaveAs(Server.MapPath("~/images/" + FileUploadImage.FileName));
            }
            db.tbl_Books.InsertOnSubmit(newBook);
            db.SubmitChanges();

            lbl_intro.ForeColor = Color.Green;
            lbl_intro.Text      = newBook.BookTitle + " Has Been Added Successfully";



            Response.Redirect("AdminBooks.aspx");
        }
Ejemplo n.º 12
0
    protected void EnterItem_Click(object sender, EventArgs e)
    {
        if (TxtItemName.Text == "" || TxtPrice.Text == "" || TxtPrice.Text == "" || TxtDescriptionItem.Text == "" || TxtCategoryItem.Text == "")
        {
            return;
        }
        MultiView2.ActiveViewIndex = 1;
        decimal parsedValue;

        if (!decimal.TryParse(TxtPrice.Text, out parsedValue))
        {
            return;
        }

        string enterItem = Operations.EnterItem(TxtItemName.Text, decimal.Parse(TxtPrice.Text), FileUploadImage.ToString(), TxtDescriptionItem.Text, int.Parse(TxtCategoryItem.Text));

        if (enterItem == null)
        {
            LblItemName.Text        = "Item Exists";
            LblItemPrice.Text       = "Item Exists";
            LblItemPrice.Text       = "Item Exists";
            LblDescriptionItem.Text = "Item Exists";
            LblCatgoryItem.Text     = "Item Exists";
        }
        else
        {
            LblItemName.Text        = TxtItemName.Text;
            LblItemPrice.Text       = TxtPrice.Text;
            LblItemPrice.Text       = TxtPrice.Text;
            LblDescriptionItem.Text = TxtDescriptionItem.Text;
            LblCatgoryItem.Text     = TxtCategoryItem.Text;
        }
    }