protected void btnCreateCustomer(object sender, EventArgs e)
    {
        try
        {
            tb_Customer info = new tb_Customer();
            string      customerGrouptemp = Request.Form["ipcustomerGroupSelection"];
            int         customerGroup     = 0;
            if (customerGrouptemp != null)
            {
                customerGroup = int.Parse(customerGrouptemp);
            }
            string customerCode        = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerCode"];
            string customerLastname    = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerLastname"];
            string customerFirstname   = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerFirstname"];
            string customerEmail       = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerEmail"];
            string customerUsername    = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerUsername"];
            string customerPass        = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerPassword"];
            string customerPhoneNumber = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerPhoneNumber"];
            string customerAddress     = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerAddress"];
            string customerDesc        = Request.Form["ctl00$ContentPlaceHolder1$ipcustomerDesc"];

            string customerAvatar = Path.GetFileName(ipcustomerAvatarFile.FileName);
            string path           = Server.MapPath("~/image_customer/");

            ipcustomerAvatarFile.SaveAs(path + customerAvatar);
            info.Avatar        = "../image_customer/" + customerAvatar;
            info.CustomerNo    = customerCode;
            info.FirstName     = customerFirstname;
            info.LastName      = customerLastname;
            info.UserName      = customerUsername;
            info.Password      = customerPass;
            info.Phone         = customerPhoneNumber;
            info.Address       = customerAddress;
            info.Email         = customerEmail;
            info.Description   = customerDesc;
            info.CustomerGroup = customerGroup;
            info.CreateDate    = DateTime.Now;
            db.tb_Customer.Add(info);
            db.SaveChanges();
            Response.Write("<script>alert('tạo khách hàng mới thành công !')</script>");
            getCustomerList();
        }
        catch (Exception)
        {
            Response.Write("<script>alert('Khởi tạo không thành công, vui lòng thử lại !')</script>");
        }
    }
    protected void btnMain_banner(object sender, EventArgs e)
    {
        //Bẫy lỗi kiểu file
        string filename = Path.GetFileName(ipSliderFile.FileName);
        // var sliderLanding = $('#ipSliderLanding').val();
        var Extension = filename.Substring(filename.LastIndexOf('.') + 1).ToLower();

        if (Extension != "gif" && Extension != "png" && Extension != "jpg")
        {
            return;
        }

        if (filename != null && filename.Length > 0)
        {
            string path = Server.MapPath("~/image_banner/");
            try
            {
                tb_HomeMainBanner img            = new tb_HomeMainBanner();
                string            fileName       = filename;
                string            mSliderLanding = Request.Form["ctl00$ContentPlaceHolder1$ipSliderLanding"];
                string            mSliderHeader1 = Request.Form["ctl00$ContentPlaceHolder1$ipSliderHeader1"];
                string            mSliderHeader2 = Request.Form["ctl00$ContentPlaceHolder1$ipSliderHeader2"];
                string            mSliderSort    = Request.Form["ctl00$ContentPlaceHolder1$ipSliderSort"];
                int slidesort = 0;
                if (mSliderSort != null)
                {
                    slidesort = int.Parse(mSliderSort);
                }

                ipSliderFile.SaveAs(path + fileName);
                img.BannerPath        = "../image_banner/" + fileName;
                img.BannerUpload      = DateTime.Now;
                img.BannerLandingpage = mSliderLanding;
                img.BannerHeader1     = mSliderHeader1;
                img.BannerHeader2     = mSliderHeader2;
                img.SortArr           = slidesort;
                db.tb_HomeMainBanner.Add(img);
                db.SaveChanges();
                Response.Write("<script>alert('Upload Complete !')</script>");
                getBannerMainSlider();
            }
            catch (Exception)
            {
                Response.Write("<script>alert('False !')</script>");
            }
        }
    }
示例#3
0
    protected void InsertImage(object sender, EventArgs e)
    {
        //Bẫy lỗi kích thước
        int iFileSize = f_Upload.PostedFile.ContentLength;

        if (iFileSize > 30000000)  // 3MB approx (actually less though)
        {
            return;
        }

        //Bẫy lỗi kiểu file
        string filename  = Path.GetFileName(f_Upload.FileName);
        var    Extension = filename.Substring(filename.LastIndexOf('.') + 1).ToLower();

        if (Extension != "gif" && Extension != "png" && Extension != "jpg")
        {
            return;
        }

        if (filename != null && filename.Length > 0)
        {
            string path = Server.MapPath("~/image_banner/");
            try
            {
                tb_GetLinkImage img      = new tb_GetLinkImage();
                string          fileName = filename;
                f_Upload.SaveAs(path + fileName);
                img.imgPath   = "http://savinaweb.siyosa.net/image_banner/" + fileName;
                img.imgUpload = DateTime.Now;
                db.tb_GetLinkImage.Add(img);
                db.SaveChanges();
                Response.Write("<script>alert('Upload Complete !')</script>");
                loadlinkimg();
            }
            catch (Exception)
            {
                Response.Write("<script>alert('False !')</script>");
            }
        }
    }
示例#4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string action = Request.QueryString["action"].ToString();
            switch (action)
            {
                #region CREATE SUBCATE2
            case "createSubCate2":
            {
                String html = "";
                try
                {
                    String subCate2Name = Request.QueryString["subCate2Name"].ToString();
                    String subCate2Desc = Request.QueryString["subCate2Desc"].ToString();
                    byte   subCate2Sort = 0;
                    if (Request.QueryString["subCate2Sort"].ToString() != null)
                    {
                        subCate2Sort = byte.Parse(Request.QueryString["subCate2Sort"].ToString());
                    }
                    int mainCateID = 0;
                    if (Request.QueryString["mainCateID"].ToString() != null)
                    {
                        mainCateID = int.Parse(Request.QueryString["mainCateID"].ToString());
                    }
                    int subCate1ID = 0;
                    if (Request.QueryString["subCate1ID"].ToString() != null)
                    {
                        subCate1ID = int.Parse(Request.QueryString["subCate1ID"].ToString());
                    }

                    //Insert to Database
                    tb_CategorySub2 subCat1 = new tb_CategorySub2();
                    subCat1.SubCate1ID   = subCate1ID;
                    subCat1.SubCate2Name = subCate2Name;
                    subCat1.SubCate2Desc = subCate2Desc;
                    subCat1.Sort         = subCate2Sort;
                    subCat1.CreateDate   = DateTime.Now;
                    subCat1.IsDeleted    = false;
                    subCat1.IsDisplay    = true;
                    db.tb_CategorySub2.Add(subCat1);
                    db.SaveChanges();

                    html = adGenerate.getSubCate2List();
                }
                catch (Exception exp)
                {
                    html = "error";
                }
                Response.Write(html);
            }
            break;
                #endregion

                #region DELETE SUBCATE2
            case "deleteSubCate2":
            {
                String subCate2HTML = "";
                try
                {
                    int subCate2ID = 0;
                    if (Request.QueryString["subCate2ID"].ToString() != null)
                    {
                        subCate2ID = int.Parse(Request.QueryString["subCate2ID"].ToString());
                        tb_CategorySub2 t = (tb_CategorySub2)db.tb_CategorySub2.Where(b => b.SubCate2ID == subCate2ID).First();
                        db.tb_CategorySub2.Remove(t);
                        db.SaveChanges();
                    }

                    subCate2HTML = adGenerate.getSubCate2List();
                }
                catch (Exception exp)
                {
                    subCate2HTML = "error";
                }
                Response.Write(subCate2HTML);
            }
            break;
                #endregion

                #region EDIT SUBCATE1
            case "editSubCate1":
            {
                String html = "";
                try
                {
                    String subCat1Name = Request.QueryString["subCat1Name"].ToString();
                    String subCat1Desc = Request.QueryString["subCat1Desc"].ToString();
                    byte   subCat1Sort = 0;
                    if (Request.QueryString["subCat1Sort"].ToString() != null)
                    {
                        subCat1Sort = byte.Parse(Request.QueryString["subCat1Sort"].ToString());
                    }
                    int mainCatID = 0;
                    if (Request.QueryString["mainCatID"].ToString() != null)
                    {
                        mainCatID = int.Parse(Request.QueryString["mainCatID"].ToString());
                    }
                    int subCate1ID = 0;
                    if (Request.QueryString["subCate1ID"].ToString() != null)
                    {
                        subCate1ID = int.Parse(Request.QueryString["subCate1ID"].ToString());
                    }

                    //update to Database
                    var update = db.tb_CategorySub1.Where(t => t.SubCate1ID == subCate1ID).FirstOrDefault();
                    update.SubCate1Name = subCat1Name;
                    update.SubCate1Desc = subCat1Desc;
                    update.Sort         = subCat1Sort;
                    update.MainCateID   = mainCatID;
                    db.SaveChanges();

                    html = adGenerate.getSubCat1List();
                }
                catch (Exception exp)
                {
                    html = "error";
                }
                Response.Write(html);
            }
            break;
                #endregion

                #region CREATE SUBCATE1
            case "createSubCate1":
            {
                String html = "";
                try
                {
                    String subCat1Name = Request.QueryString["subCat1Name"].ToString();
                    String subCat1Desc = Request.QueryString["subCat1Desc"].ToString();
                    byte   subCat1Sort = 0;
                    if (Request.QueryString["subCat1Sort"].ToString() != null)
                    {
                        subCat1Sort = byte.Parse(Request.QueryString["subCat1Sort"].ToString());
                    }
                    int mainCatID = 0;
                    if (Request.QueryString["mainCatID"].ToString() != null)
                    {
                        mainCatID = int.Parse(Request.QueryString["mainCatID"].ToString());
                    }

                    //Insert to Database
                    tb_CategorySub1 subCat1 = new tb_CategorySub1();
                    subCat1.MainCateID   = mainCatID;
                    subCat1.SubCate1Name = subCat1Name;
                    subCat1.SubCate1Desc = subCat1Desc;
                    subCat1.Sort         = subCat1Sort;
                    subCat1.CreateDate   = DateTime.Now;
                    subCat1.IsDeleted    = false;
                    subCat1.IsDisplay    = true;
                    db.tb_CategorySub1.Add(subCat1);
                    db.SaveChanges();

                    html = adGenerate.getSubCat1List();
                }catch (Exception exp)
                {
                    html = "error";
                }
                Response.Write(html);
            }
            break;
                #endregion

                #region DELETE SUBCATE1
            case "deleteSubCate1":
            {
                String subCate1HTML = "";
                try
                {
                    int subCate1ID = 0;
                    if (Request.QueryString["subCate1ID"].ToString() != null)
                    {
                        subCate1ID = int.Parse(Request.QueryString["subCate1ID"].ToString());
                        tb_CategorySub1 t = (tb_CategorySub1)db.tb_CategorySub1.Where(b => b.SubCate1ID == subCate1ID).First();
                        db.tb_CategorySub1.Remove(t);
                        db.SaveChanges();
                    }

                    subCate1HTML = adGenerate.getSubCat1List();
                }
                catch (Exception exp)
                {
                    subCate1HTML = "error";
                }
                Response.Write(subCate1HTML);
            }
            break;
                #endregion

                #region FETCH SUBCATE1
            case "fetchSubCate1":
            {
                String subCate1ListHTML = "";
                try
                {
                    int mainCateID = 0;
                    if (Request.QueryString["mainCateID"].ToString() != null)
                    {
                        mainCateID       = int.Parse(Request.QueryString["mainCateID"].ToString());
                        subCate1ListHTML = adGenerate.getSubCate1List(mainCateID);
                    }
                }
                catch (Exception exp)
                {
                    subCate1ListHTML = "error";
                }
                Response.Write(subCate1ListHTML);
            }
            break;
                #endregion

                #region FETCH MAINCATE
            case "fetchMainCate":
            {
                String mainCateListHTML = "";
                try
                {
                    //Reload list maincate
                    List <tb_CategoryMain> mainCateList = adGenerate.getMainCateList();
                    if (mainCateList.Count() != 0)
                    {
                        mainCateListHTML = adGenerate.generateHTMLMainCateSelect(mainCateList);
                    }
                }catch (Exception exp)
                {
                    mainCateListHTML = "error";
                }
                Response.Write(mainCateListHTML);
            }
            break;
                #endregion

                #region DELETE MAINCATE
            case "deleteMainCate":
            {
                String mainCateListHTML = "";
                try
                {
                    int cateID = 0;
                    if (Request.QueryString["cateID"].ToString() != null)
                    {
                        cateID = int.Parse(Request.QueryString["cateID"].ToString());
                        tb_CategoryMain t = (tb_CategoryMain)db.tb_CategoryMain.Where(b => b.MainCateID == cateID).First();
                        db.tb_CategoryMain.Remove(t);
                        db.SaveChanges();
                    }

                    List <tb_CategoryMain> mainCateList = adGenerate.getMainCateList();
                    if (mainCateList.Count() != 0)
                    {
                        mainCateListHTML = adGenerate.generateHTMLMainCate(mainCateList);
                    }
                }
                catch (Exception exp)
                {
                    mainCateListHTML = "error";
                }
                Response.Write(mainCateListHTML);
            }
            break;
                #endregion

                #region EDIT MAINCATE
            case "editMainCate":
            {
                String mainCateListHTML = "";
                try
                {
                    string cateName = Request.QueryString["cateName"].ToString();
                    string desc     = Request.QueryString["desc"].ToString();
                    int    cateSort = 0;
                    if (Request.QueryString["cateSort"].ToString() != null)
                    {
                        cateSort = int.Parse(Request.QueryString["cateSort"].ToString());
                    }
                    int cateID = 0;
                    if (Request.QueryString["cateID"].ToString() != null)
                    {
                        cateID = int.Parse(Request.QueryString["cateID"].ToString());
                    }

                    //update to Database
                    var update = db.tb_CategoryMain.Where(t => t.MainCateID == cateID).FirstOrDefault();
                    update.MainCateName = cateName;
                    update.MainCateDesc = desc;
                    update.Sort         = cateSort;
                    db.SaveChanges();

                    //Reload list maincate
                    List <tb_CategoryMain> mainCateList = adGenerate.getMainCateList();
                    if (mainCateList.Count() != 0)
                    {
                        mainCateListHTML = adGenerate.generateHTMLMainCate(mainCateList);
                    }
                }
                catch (Exception exp)
                {
                    mainCateListHTML = "error";
                }
                Response.Write(mainCateListHTML);
            }
            break;
                #endregion

                #region CREATE MAINCATE
            case "createMainCate":
            {
                String mainCateListHTML = "";
                try
                {
                    string cateName = Request.QueryString["cateName"].ToString();
                    string desc     = Request.QueryString["desc"].ToString();
                    int    cateSort = 0;
                    if (Request.QueryString["cateSort"].ToString() != null)
                    {
                        cateSort = int.Parse(Request.QueryString["cateSort"].ToString());
                    }

                    //Insert to Database
                    tb_CategoryMain tbMainCate = new tb_CategoryMain();
                    tbMainCate.MainCateName = cateName;
                    tbMainCate.MainCateDesc = desc;
                    tbMainCate.Sort         = cateSort;
                    tbMainCate.CreateDate   = DateTime.Now;
                    tbMainCate.IsDisplay    = true;
                    tbMainCate.IsDeleted    = false;
                    tbMainCate.Sort         = cateSort;
                    db.tb_CategoryMain.Add(tbMainCate);
                    db.SaveChanges();

                    //Reload list maincate
                    List <tb_CategoryMain> mainCateList = adGenerate.getMainCateList();
                    if (mainCateList.Count() != 0)
                    {
                        mainCateListHTML = adGenerate.generateHTMLMainCate(mainCateList);
                    }
                }catch (Exception exp)
                {
                    mainCateListHTML = "error";
                }
                Response.Write(mainCateListHTML);
            }
            break;
                #endregion
            }
        }
    }
示例#5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string action = Request.QueryString["action"].ToString();
            switch (action)
            {
                #region getCategoryList
            case "getCategoryList":
            {
                string html = Generate.getCategoryList();
                Response.Write(html);
            }
            break;
                #endregion ;

                #region LoginNow
            case "LoginNow":
            {
                string customerLoginHTML = "";
                string cusEmail          = Request.QueryString["cusEmail"].ToString();
                string cusPass           = Request.QueryString["cusPass"].ToString();
                var    customerInfo      = db.tb_Customer.Where(t => t.Email == cusEmail).FirstOrDefault();
                var    tblEmail          = customerInfo.Email;
                var    tblPass           = customerInfo.Password;
                // if (cusEmail.Equals(customerInfo.Email))
                if (cusEmail == tblEmail)
                {
                    //if (cusPass.Equals(customerInfo.Password))
                    if (cusPass == tblPass)
                    {
                        //long cusId = customerInfo.CustomerID;
                        // Session["cusID"] = cusId;
                        //login success
                        Session["cusName"] = customerInfo.FirstName;
                        //Response.Write("1");
                        customerLoginHTML = "1";
                    }
                    else
                    {
                        //password wrong
                        //Response.Write("2");
                        customerLoginHTML = "2";
                    }
                }
                else
                {
                    //email not existing
                    //Response.Write("3");
                    customerLoginHTML = "error";
                }
                Response.Write(customerLoginHTML);
            }
            break;
                #endregion

                #region Registernew
            case "Registernew":
            {
                String customerRegisterHTML = "";
                try
                {
                    string regFirstName = Request.QueryString["regFirstName"].ToString();
                    string regLastName  = Request.QueryString["regLastName"].ToString();
                    string regEmail     = Request.QueryString["regEmail"].ToString();
                    string regPassword  = Request.QueryString["regPassword"].ToString();
                    //insert to database
                    tb_Customer thlCustomer = new tb_Customer();
                    thlCustomer.FirstName     = regFirstName;
                    thlCustomer.LastName      = regLastName;
                    thlCustomer.Email         = regEmail;
                    thlCustomer.Password      = regPassword;
                    thlCustomer.CustomerGroup = 3;
                    thlCustomer.CustomerNo    = "cusfront2018";
                    thlCustomer.CreateDate    = DateTime.Now;
                    db.tb_Customer.Add(thlCustomer);
                    db.SaveChanges();
                    Response.Write("<script>alert('tạo khách hàng mới thành công !')</script>");
                }
                catch (Exception)
                {
                    customerRegisterHTML = "error";
                }
                Response.Write(customerRegisterHTML);
            }
            break;
                #endregion

                #region [Xu ly from contact]
            case "ContactInsert":
                ContactInsert(); break;
                #endregion
            }
        }
    }
示例#6
0
    protected void btnCreate_click(object sender, EventArgs e)
    {
        string productCode            = Request.Form["ctl00$ContentPlaceHolder1$productCode"];
        string getproductAvailability = Request.Form["ctl00$ContentPlaceHolder1$productAvailability"];

        if (getproductAvailability == "ProductStatus1")
        {
            getproductAvailability = "1";
        }
        if (getproductAvailability == "ProductStatus2")
        {
            getproductAvailability = "2";
        }
        if (getproductAvailability == "ProductStatus3")
        {
            getproductAvailability = "3";
        }
        var IDMainCateSelected = this.data_MainCate.SelectedValue;
        var IDSubCate1Selected = this.data_SubCate1.SelectedValue;
        var IDSubCate2Selected = this.data_SubCate2.SelectedValue;

        string productName     = Request.Form["ctl00$ContentPlaceHolder1$productName"];
        string priceByBlockStr = this.priceByBlock.Value;
        double priceByBlock    = 0;

        if (priceByBlockStr == "" || priceByBlockStr == null)
        {
            priceByBlock = 0;
        }
        else
        {
            priceByBlock = double.Parse(priceByBlockStr);
        }
        //double priceByBlock = double.Parse(Request.Form["ctl00$ContentPlaceHolder1$priceByBlock"]);

        string priceByDayStr = this.priceByDay.Value;
        double priceByDay    = 0;

        if (priceByDayStr == "" || priceByDayStr == null)
        {
            priceByDay = 0;
        }
        else
        {
            priceByDay = double.Parse(priceByDayStr);;
        }
        //double priceByDay = double.Parse(Request.Form["ctl00$ContentPlaceHolder1$priceByDay"]);
        string productDescription = Request.Form["ctl00$ContentPlaceHolder1$productDescription"];
        string productStatusStr   = Request.Form["ctl00$ContentPlaceHolder1$productStatus"];
        int    productStatus      = 0;

        if (productStatusStr == "" || productStatusStr == null)
        {
            productStatus = 0;
        }
        else
        {
            productStatus = int.Parse(productStatusStr);
        }
        byte   productAvailability = byte.Parse(getproductAvailability);
        string productValueStr     = this.productValue.Value;
        double productValue        = 0;

        if (productValueStr == "" || productValueStr == null)
        {
            productValue = 0;
        }
        else
        {
            productValue = double.Parse(productValueStr);
        }
        //double productValue = double.Parse(Request.Form["ctl00$ContentPlaceHolder1$productValue"]);
        string productFullDesc        = this.content_PrFullDesc.Value;    // Request.Form["ctl00$ContentPlaceHolder1$content_PrFullDesc"];
        string productFullSpec        = this.content_PrSpec.Value;        // Request.Form["ctl00$ContentPlaceHolder1$content_PrSpec"];
        string productFullInstruction = this.content_PrInstruction.Value; // Request.Form["ctl00$ContentPlaceHolder1$content_PrInstruction"];

        int productMainCate = 0;

        if (IDMainCateSelected == "" || IDMainCateSelected == null)
        {
            productMainCate = 0;
        }
        else
        {
            productMainCate = int.Parse(IDMainCateSelected);;
        }

        int productSubCate1 = 0;

        if (IDSubCate1Selected == "" || IDSubCate1Selected == null)
        {
            productSubCate1 = 0;
        }
        else
        {
            productSubCate1 = int.Parse(IDSubCate1Selected);
        }
        int productSubCate2 = 0;

        if (IDSubCate2Selected == "" || IDSubCate2Selected == null)
        {
            productSubCate2 = 0;
        }
        else
        {
            productSubCate2 = int.Parse(IDSubCate2Selected);
        }
        string productAvatar = Path.GetFileName(productAvatarFile.FileName);
        string path          = Server.MapPath("~/image_product/");
        string youtubeLink   = Request.Form["ctl00$ContentPlaceHolder1$productYoutube"];

        try
        {
            tb_Product info = new tb_Product();


            productAvatarFile.SaveAs(path + productAvatar);
            info.ProductAvatar        = "../image_product/" + productAvatar;
            info.ProductCode          = productCode;
            info.ProductName          = productName;
            info.PricePerBlock        = priceByBlock;
            info.PricePerDay          = priceByDay;
            info.ShortDescription     = productDescription;
            info.StatusPercentage     = productStatus;
            info.StatusAvailability   = productAvailability;
            info.ProductValue         = productValue;
            info.ProductMainCate      = productMainCate;
            info.ProductSubCate1      = productSubCate1;
            info.ProductSubCate2      = productSubCate2;
            info.FullDescription      = productFullDesc;
            info.ProductSpecification = productFullSpec;
            info.ProductInstruction   = productFullInstruction;
            info.YoutubeLink          = youtubeLink;
            info.CreateDate           = DateTime.Now;
            db.tb_Product.Add(info);
            db.SaveChanges();

            string productIDStr    = info.ProductID.ToString();
            int    productIDInTime = int.Parse(productIDStr);

            // add product accompany
            string IDProAccompanySelected = Request["ipProductAccompanySelection"];
            if (IDProAccompanySelected == null || IDProAccompanySelected == "")
            {
            }
            else
            {
                string[] IDProAccompanySelectedMultiple = IDProAccompanySelected.Split(',');
                for (int i = 0; i < IDProAccompanySelectedMultiple.Length; i++)
                {
                    tb_ProductAccompany tb_productAccompany = new tb_ProductAccompany();
                    tb_productAccompany.ProductID = productIDInTime;
                    int IDProAccompanySelectedMultipleID = int.Parse(IDProAccompanySelectedMultiple[i]);
                    var productAccompanyDb = (from pl in db.tb_Product
                                              where pl.ProductID == IDProAccompanySelectedMultipleID
                                              select new
                    {
                        pl.ProductID,
                        pl.ProductCode,
                        pl.ProductName,
                        pl.ProductAvatar
                    }
                                              ).OrderByDescending(p => p.ProductID).FirstOrDefault();
                    tb_productAccompany.ProductCode      = productAccompanyDb.ProductCode;
                    tb_productAccompany.ProductName      = productAccompanyDb.ProductName;
                    tb_productAccompany.productAccAvatar = productAccompanyDb.ProductAvatar;
                    try
                    {
                        this.db.tb_ProductAccompany.Add(tb_productAccompany);
                        this.db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        Response.Write("<script>alert('Khởi tạo không thành công, vui lòng thử lại !')</script>");
                    }
                }
            }

            // add product Accessory
            string IDProAccessorySelected = Request["ipProductAccessorySelection"];
            if (IDProAccessorySelected == null || IDProAccessorySelected == "")
            {
            }
            else
            {
                string[] IDProAccessorySelectedMultiple = IDProAccessorySelected.Split(',');
                for (int i = 0; i < IDProAccessorySelectedMultiple.Length; i++)
                {
                    tb_ProductAccessorySelection tb_productAccessory = new tb_ProductAccessorySelection();
                    tb_productAccessory.ProductID = productIDInTime;
                    int IDProAccessorySelectedMultipleID = int.Parse(IDProAccessorySelectedMultiple[i]);
                    var productAccessoryDb = (from pl in db.tb_Product
                                              where pl.ProductID == IDProAccessorySelectedMultipleID
                                              select new
                    {
                        pl.ProductID,
                        pl.ProductCode,
                        pl.ProductName,
                        pl.ProductAvatar,
                        pl.PricePerBlock,
                        pl.PricePerDay,
                        pl.ProductValue
                    }
                                              ).OrderByDescending(p => p.ProductID).FirstOrDefault();
                    tb_productAccessory.ProductCode   = productAccessoryDb.ProductCode;
                    tb_productAccessory.ProductName   = productAccessoryDb.ProductName;
                    tb_productAccessory.PricePerBlock = productAccessoryDb.PricePerBlock;
                    tb_productAccessory.PricePerDay   = productAccessoryDb.PricePerDay;
                    tb_productAccessory.ProductValue  = productAccessoryDb.ProductValue;
                    try
                    {
                        this.db.tb_ProductAccessorySelection.Add(tb_productAccessory);
                        this.db.SaveChanges();
                    }

                    catch (Exception)
                    {
                        Response.Write("<script>alert('Khởi tạo không thành công, vui lòng thử lại !')</script>");
                    }
                }
            }

            //add product gallery
            tb_ProductGallery tb_productGallery = new tb_ProductGallery();
            tb_productGallery.ProductID = productIDInTime;
            string pathGallery = Server.MapPath("~/image_product/");
            if (productGalleryFile.HasFiles)
            {
                foreach (HttpPostedFile uploadedGAllery in productGalleryFile.PostedFiles)
                {
                    try
                    {
                        uploadedGAllery.SaveAs(System.IO.Path.Combine(pathGallery, uploadedGAllery.FileName));
                        tb_productGallery.ImagePath = "../image_product/" + uploadedGAllery.FileName;
                        this.db.tb_ProductGallery.Add(tb_productGallery);
                        this.db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        Response.Write("<script>alert('Khởi tạo không thành công, vui lòng thử lại !')</script>");
                    }
                }
            }
        }

        catch (Exception)
        {
            Response.Write("<script>alert('Khởi tạo không thành công, vui lòng thử lại !')</script>");
        }
        Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "RefreshPage()", true);
    }
    protected void btnGr1_banner1(object sender, EventArgs e)
    {
        //Check input type
        string filename  = Path.GetFileName(fileGr1_banner1.FileName);
        var    Extension = filename.Substring(filename.LastIndexOf('.') + 1).ToLower();

        if (Extension != "gif" && Extension != "png" && Extension != "jpg")
        {
            return;
        }
        if (filename != null && filename.Length > 0)
        {
            string path = Server.MapPath("~/image_banner/");
            try
            {
                string fileName = filename;
                fileGr1_banner1.SaveAs(path + fileName);
                var update = db.tb_HomeBanner.Where(t => t.HomeBannerID == 1).FirstOrDefault();
                update.BannerPath   = "../image_banner/" + fileName;
                update.BannerUpload = DateTime.Now;
                db.SaveChanges();
                Response.Write("<script>alert('Upload Complete !')</script>");
                getBannerGroup1();
            }
            catch (Exception)
            {
                Response.Write("<script>alert('Upload fail !')</script>");
            }
        }
    }