protected void LinkButtonEdat_Command(object sender, CommandEventArgs e)
    {
        this.EditPanel.Visible = true;
        this.AddPanel.Visible  = false;
        this.ShowPanel.Visible = false;

        long ID = long.Parse(e.CommandArgument.ToString());

        CommonClassLibrary.Category cate = innofood.Categories.Where(x => x.Id == ID).First();
        this.Labelidname.Text        = cate.Name;
        this.Image_category.ImageUrl = "Image/" + cate.ImageURL;
        this.aaa_TextBox.Text        = ID.ToString();

        CommonClassLibrary.TypeCate typecate = innofood.TypeCates.Where(x => x.Id == cate.TypeId).First();
        RadioButtonList.SelectedValue = typecate.Id.ToString();

        long Idtext = long.Parse(cate.Name);

        CommonClassLibrary.TextContent textc = innofood.TextContents.Where(x => x.Id == Idtext).First();

        editName_TextBox.Text   = textc.Thai;
        editNameEN_TextBox.Text = textc.English;
    }
    protected void LinkButtonDelete_Command(object sender, CommandEventArgs e)
    {
        long ID = long.Parse(e.CommandArgument.ToString());

        try {
            CommonClassLibrary.Category cate = innofood.Categories.Where(x => x.Id == ID).First();
            cate.Status = 0;
            innofood.SaveChanges();
            //this.SuccessPanel.Visible = true;
            //this.ErrorPanel.Visible = false;
            //this.SuccessLabel.Text = "ลบข้อมูลสำเร็จ";
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "ลบข้อมูลสำเร็จ" + "');", true);
        }
        catch (Exception ex)
        {
            //this.SuccessPanel.Visible = false;
            //this.ErrorPanel.Visible = true;
            //this.ErrorLabel.Text = "ลบข้อมูลไม่สำเร็จ";

            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "ลบข้อมูลไม่สำเร็จ" + "');", true);
        }
        this.Showdata();
    }
    public void saveImage()
    {
        int            Type          = int.Parse(Request.QueryString["Type"]);
        HttpPostedFile UpFileProduct = Picture_FileUpload.PostedFile;

        string UpFilePro = System.IO.Path.GetExtension(UpFileProduct.FileName);

        if (this.Picture_FileUpload.PostedFile.FileName.ToString() != "")
        {
            long IDProduct1 = (long)new CommonClassLibrary.CommonDataSetTableAdapters.TextContentTableAdapter().InsertQuery(Name_TextBox.Text, NameEN_TextBox.Text, " ", DateTime.Now, DateTime.Now, 1);


            if (UpFilePro == ".jpg" || UpFilePro == ".png" || UpFilePro == ".JPG" || UpFilePro == ".PNG" || UpFilePro == ".jpeg" || UpFilePro == ".JPEG")
            {
                string imageFileName = "IMF" + "_" + DateTime.Now.ToString("ddMMyyyy-HHmmss");
                imageFileName += ".jpg";
                string aaa  = imageFileName;
                string path = System.IO.Path.Combine(Server.MapPath("~/Image/"), imageFileName);
                // string path = System.IO.Path.Combine(Server.MapPath("D:/OWP/DigitalServicesRestaurant/ManagementWebSite/Image/"), imageFileName);
                UpFileProduct.SaveAs(path);

                try
                {
                    CommonClassLibrary.Category tc = new CommonClassLibrary.Category()
                    {
                        Name        = IDProduct1.ToString(),
                        ImageURL    = aaa,
                        CreatedDate = DateTime.Now,
                        LastUpdated = DateTime.Now,
                        Status      = 1,
                        TypeId      = Type
                    };
                    innofood.Categories.Add(tc);
                    innofood.SaveChanges();


                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "บันทึกข้อมูลสำเร็จ" + "');", true);

                    //this.SuccessPanel.Visible = true;
                    //this.ErrorPanel.Visible = false;
                    //this.SuccessLabel.Text = "บันทึกข้อมูลสำเร็จ";
                }
                catch (Exception ex)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "บันทึกข้อมูลไม่สำเร็จ" + "');", true);

                    //this.SuccessPanel.Visible = false;
                    //this.ErrorPanel.Visible = true;
                    //this.ErrorLabel.Text = "บันทึกข้อมูลไม่สำเร็จ";
                }


                //if (new CommonClassLibrary.CommonDataSetTableAdapters.CategoryTableAdapter().Insert(IDProduct1.ToString(), aaa, DateTime.Now, DateTime.Now, 1) == 1)
                //{
                //    this.SuccessLabel.Text = "บันทึกข้อมูลสำเร็จ";
                //    Response.Redirect("~/AddCategory.aspx");
                //}
                //else
                //{

                //    FileInfo DeleteImage = new FileInfo(@"C:/FTP/Imilk/Image/" + aaa);
                //    DeleteImage.Delete();
                //    this.SuccessPanel.Visible = false;
                //    this.ErrorPanel.Visible = true;
                //    this.ErrorLabel.Text = "บันทึกข้อมูลไม่สำเร็จ";
                //}

                this.Name_TextBox.Text   = "";
                this.NameEN_TextBox.Text = "";
            }
        }
        else
        {
            //this.SuccessPanel.Visible = false;
            //this.ErrorPanel.Visible = true;
            //this.ErrorLabel.Text = "บันทึกข้อมูลไม่สำเร็จ กรุณาเลือกรูปภาพ";

            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "บันทึกข้อมูลไม่สำเร็จ กรุณาเลือกรูปภาพ" + "');", true);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string img    = "";
        int    ID     = int.Parse(Labelidname.Text);
        int    IdCate = int.Parse(aaa_TextBox.Text);

        try
        {
            CommonClassLibrary.Category cate1 = innofood.Categories.Where(x => x.Id == IdCate).First();

            cate1.TypeId = int.Parse(RadioButtonList.SelectedItem.Value);

            CommonClassLibrary.TextContent o = innofood.TextContents.Where(x => x.Id == ID).First();

            o.Thai        = editName_TextBox.Text;
            o.English     = editNameEN_TextBox.Text;
            o.LastUpdated = DateTime.Now;

            innofood.SaveChanges();
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "แก้ไขข้อมูลสำเร็จ" + "');", true);
            //this.SuccessPanel.Visible = true;
            //this.ErrorPanel.Visible = false;
            //this.SuccessLabel.Text = "แก้ไขข้อมูลสำเร็จ";
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "แก้ไขข้อมูลไม่สำเร็จ" + "');", true);
            //this.SuccessPanel.Visible = false;
            //this.ErrorPanel.Visible = true;
            //this.ErrorLabel.Text = "แก้ไขข้อมูลไม่สำเร็จ";
        }

        if (this.EditFileUpload.HasFile)
        {
            HttpPostedFile UpFileProduct = EditFileUpload.PostedFile;

            string UpFilePro = System.IO.Path.GetExtension(UpFileProduct.FileName);


            if (UpFilePro == ".jpg" || UpFilePro == ".png" || UpFilePro == ".JPG" || UpFilePro == ".PNG" || UpFilePro == ".jpeg" || UpFilePro == ".JPEG")
            {
                string imageFileName = "IMF" + "_" + DateTime.Now.ToString("ddMMyyyy-HHmmss");
                imageFileName += ".jpg";
                img            = imageFileName;
                string path = System.IO.Path.Combine(Server.MapPath("~/Image/"), imageFileName);
                // string path = System.IO.Path.Combine(Server.MapPath("D:/OWP/DigitalServicesRestaurant/ManagementWebSite/Image/"), imageFileName);
                UpFileProduct.SaveAs(path);

                try
                {
                    CommonClassLibrary.Category oo = innofood.Categories.Where(x => x.Id == IdCate).First();

                    oo.ImageURL = img;

                    innofood.SaveChanges();
                    //this.SuccessPanel.Visible = true;
                    //this.ErrorPanel.Visible = false;
                    //this.SuccessLabel.Text = "แก้ไขข้อมูลสำเร็จ";

                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "แก้ไขข้อมูลสำเร็จ" + "');", true);
                }
                catch (Exception ex)
                {
                    //this.SuccessPanel.Visible = false;
                    //this.ErrorPanel.Visible = true;
                    //this.ErrorLabel.Text = "แก้ไขข้อมูลไม่สำเร็จ";
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "แก้ไขข้อมูลไม่สำเร็จ" + "');", true);
                }
            }
        }
    }