예제 #1
0
        protected void btn_register_Click(object sender, EventArgs e)
        {
            //path file img
            string  path          = Server.MapPath("~/admin/img/");
            string  name          = txtName.Text;
            string  description   = txt_Description.Text;
            decimal price         = decimal.Parse(txt_Price.Text);
            decimal price_promo   = decimal.Parse(txt_Price_Promo.Text);
            string  thumb         = txt_thumb.Text;
            string  filename      = FileUpload1.FileName;
            string  unit          = txt_unit.Text;
            decimal percent_promo = decimal.Parse(txt_percent_promo.Text);
            int     rating        = int.Parse(txt_rating.Text);
            int     sold          = int.Parse(txt_sold.Text);
            decimal point         = decimal.Parse(txt_point.Text);
            int     type          = int.Parse(txt_type.Text);
            int     status        = int.Parse(txt_status.Text);
            string  username      = txt_UserName.Text;

            FileUpload1.SaveAs(path + filename);
            string modified = txt_modified.Text;
            Food   food     = new Food(name, description, price, price_promo, thumb, filename, unit, percent_promo, rating, sold, point, type, status, username, modified);

            if (food.AddFood())
            {
                ClientScript.RegisterStartupScript(this.GetType(), "randomkey", "alertSuccess()", true);
            }
            else
            {
            }
        }
예제 #2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (btnAdd.Text == "Thêm Food")
            {
                string sName          = exampleFoodName.Text;
                string sDescription   = exampleFoodDes.Text;
                int    sPrice         = Convert.ToInt32(exampleFoodPrice.Text);
                int    sPrice_promo   = Convert.ToInt32(examplePricePromo.Text);
                string sThumb         = FileUpload2.FileName;
                string sImg           = FileUpload1.FileName;
                string sUnit          = exampleUnit.Text;
                int    sPrecent_promo = Convert.ToInt32(examplePercent.Text);
                int    sRating        = Convert.ToInt32(exampleRating.Text);
                int    sSold          = Convert.ToInt32(exampleSold.Text);
                int    sPoint         = Convert.ToInt32(examplePoint.Text);
                int    sType          = Convert.ToInt32(DropDownList1.Text);
                int    stt            = Convert.ToInt32(DropDownList_SelectStatus.Text);
                string sUs            = (string)Session["Login"];
                Food   food           = new Food(sName, sDescription, sPrice, sPrice_promo, sThumb, sImg, sUnit, sPrecent_promo, sRating, sSold, sPoint, sType, stt, sUs, id);
                if (food.AddFood() == true)
                {
                    lbmodal.Text = "Thêm sản phẩm thành công";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
                else
                {
                    lbmodal.Text = "Thêm sản phẩm thất bại";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
            }
            if (btnAdd.Text == "Update")
            {
                string sName          = exampleFoodName.Text;
                string sDescription   = exampleFoodDes.Text;
                int    sPrice         = Convert.ToInt32(exampleFoodPrice.Text);
                int    sPrice_promo   = Convert.ToInt32(examplePricePromo.Text);
                string sThumb         = FileUpload2.FileName;
                string sImg           = FileUpload1.FileName;
                string sUnit          = exampleUnit.Text;
                int    sPrecent_promo = Convert.ToInt32(examplePercent.Text);
                int    sRating        = Convert.ToInt32(exampleRating.Text);
                int    sSold          = Convert.ToInt32(exampleSold.Text);
                int    sPoint         = Convert.ToInt32(examplePoint.Text);
                int    sType          = Convert.ToInt32(DropDownList1.Text);
                int    stt            = Convert.ToInt32(DropDownList_SelectStatus.Text);
                string sUs            = (string)Session["Login"];

                Food food = new Food(sName, sDescription, sPrice, sPrice_promo, sThumb, sImg, sUnit, sPrecent_promo, sRating, sSold, sPoint, sType, stt, sUs, id);
                if (food.UpdateFood() == true)
                {
                    lbmodal.Text = "Cập nhật thành công";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
                else
                {
                    lbmodal.Text = "Cập nhật thất bại";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
            }
        }