using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace KstCMS.KstCMS_Manager.WebContent.products.pro
{
    public partial class EditProduct : KstCmsBase.WebPage.FrmControl
    {
        string ProID = System.Web.HttpContext.Current.Request.QueryString.Get("ProID");
        protected string SeoField, SeoFieldValue, btnNum="0", xheditorjs, OldPic3, OldPic2, OldPic1;
        protected string jstr = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            drp_SiteList.SelectedIndexChanged += new EventHandler(drp_SiteList_SelectedIndexChanged);
            drp_MenuList.SelectedIndexChanged += new EventHandler(drp_MenuList_SelectedIndexChanged);
            drp_ProLBList.SelectedIndexChanged += new EventHandler(drp_ProLBList_SelectedIndexChanged);
            OkBtn.Click += new EventHandler(OkBtn_Click);
            if (!IsPostBack)
            {
                OkBtn.OnClientClick = "return checkForm(this.form);";
                GetProductInfo();
                Set_Control();
                
            }
        }

        void OkBtn_Click(object sender, EventArgs e)
        {
            string WebPageFile = string.Empty;
            if (FileName.Value.ToLower() != txt_FileName.Text.Trim().ToLower())
            {
                string HtmlExt = KstCmsBase.Common.Fucs.GetConfigValue("htmlext");
                string PathUrl = KstCmsBase.DAL.WebSite.Get_WebSite_Info(Convert.ToInt32(drp_SiteList.SelectedValue), "SiteVer").SiteVer + "/" + KstCmsBase.DAL.WebMenu.Get_WebMenuInfo(Convert.ToInt32(drp_MenuList.SelectedValue), "MenuDiy").MenuDiy;
                PathUrl = SysRootUrl + "/" + PathUrl;
                KstCmsBase.Common.Fucs.DeleteFile(Server.MapPath(PathUrl + "/" + FileName.Value));
                WebPageFile = KstCmsBase.Common.Fucs.Replace_NoDirStr(txt_FileName.Text.Trim().ToLower() + "_" + ProID + "_" + txt_ProNo.Text.Trim().ToLower(),"_");
            }
            else{
                WebPageFile=txt_FileName.Text.Trim();
            }
            if (string.IsNullOrEmpty(WebPageFile)||WebPageFile=="")
            {
                WebPageFile = KstCmsBase.Common.Fucs.Replace_NoDirStr(ProID + "_" + txt_ProNo.Text.Trim(),"_").ToLower();
            }
            string UpPath = string.Empty;
            if (Read_Cache("productpic_path") != null)
                UpPath = Read_Cache("productpic_path").ToString();
            else
            {
                UpPath = SysRootUrl + "/" + KstCmsBase.Common.Fucs.GetConfigValue("productpic_path");
                Set_Cache("productpic_path", UpPath);
            }
            int Product_spicW = 0, Product_spicH = 0;
            int Product_mpicW = 0, Product_mpicH = 0;
            if (Read_Cache("Product_spicW") != null)
                Product_spicW = Convert.ToInt32(Read_Cache("Product_spicW"));
            else
            {
                Product_spicW = Convert.ToInt32(KstCmsBase.Common.Fucs.GetConfigValue("Product_spicW"));
                Set_Cache("Product_spicW", Product_spicW);
            }

            if (Read_Cache("Product_spicH") != null)
                Product_spicH = Convert.ToInt32(Read_Cache("Product_spicH"));
            else
            {
                Product_spicH = Convert.ToInt32(KstCmsBase.Common.Fucs.GetConfigValue("Product_spicH"));
                Set_Cache("Product_spicH", Product_spicH);
            }

            if (Read_Cache("Product_mpicW") != null)
                Product_mpicW = Convert.ToInt32(Read_Cache("Product_mpicW"));
            else
            {
                Product_mpicW = Convert.ToInt32(KstCmsBase.Common.Fucs.GetConfigValue("Product_mpicW"));
                Set_Cache("Product_mpicW", Product_mpicW);
            }

            if (Read_Cache("Product_mpicH") != null)
                Product_mpicH = Convert.ToInt32(Read_Cache("Product_mpicH"));
            else
            {
                Product_mpicH = Convert.ToInt32(KstCmsBase.Common.Fucs.GetConfigValue("Product_mpicH"));
                Set_Cache("Product_mpicH", Product_mpicH);
            }
            KstCmsBase.Common.FStream FS = new KstCmsBase.Common.FStream();
            OldPic3 = Request.Form.Get("OldPic3").ToLower();
            OldPic2 = Request.Form.Get("OldPic2");
            OldPic1 = Request.Form.Get("OldPic1");
            if (OldPic3 != txt_DefaultPic.Text.Trim().ToLower())
            {
                KstCmsBase.Common.Fucs.DeleteFile(Server.MapPath(OldPic1));
                KstCmsBase.Common.Fucs.DeleteFile(Server.MapPath(OldPic2));
                KstCmsBase.Common.Fucs.DeleteFile(Server.MapPath(OldPic3));
                OldPic3 = txt_DefaultPic.Text.Trim();
                if (!System.IO.File.Exists(Server.MapPath(OldPic3)))
                {
                    throw new Exception("默认图片不存在，请重新上传！");
                }
                OldPic1 = FS.Set_SmallImg(OldPic3, UpPath + "/small/" + DateTime.Now.ToString("yyyy-MM-dd") + "/", Product_spicW, Product_spicH);
                OldPic2 = FS.Set_SmallImg(OldPic3, UpPath + "/medium/" + DateTime.Now.ToString("yyyy-MM-dd") + "/", Product_mpicW, Product_mpicH);
            }
            int IsNew = chk_IsNew.Checked ? 1 : 0;
            int IsTj = chk_IsTj.Checked ? 1 : 0;
            int IsHot = chk_IsHot.Checked ? 1 : 0;
            string[] data = new string[]{
                drp_SiteList.SelectedValue,
                drp_MenuList.SelectedValue,
                drp_ProLBList.SelectedValue,
                txt_ProNo.Text.Trim(),
                txt_ProName.Text.Trim(),
                OldPic1,
                OldPic2,
                OldPic3,
                Request.Form.Get("txt_ProDoc"),
                txt_uTime.Text.Trim(),
                IsNew.ToString(),
                IsTj.ToString(),
                IsHot.ToString(),
                txt_SortNo.Text.Trim(),
                txt_MateKey.Text.Trim(),
                txt_MateDesc.Text.Trim(),
                WebPageFile,
                drp_TempList.SelectedValue
            };
            KstCmsBase.DAL.Product.Product.Product_Update(data, Convert.ToInt32(ProID), "SiteID", "MenuID", "LbID", "ProNo", "ProName", "Pic1", "Pic2", "Pic3", "ProDoc", "uTime", "IsNew", "IsTj", "IsHot", "SortNo", "MateKey", "MateDesc", "FileName", "TempID");
            KstCmsBase.DAL.Access db = new KstCmsBase.DAL.Access();
            db.DataDelete("PostField", "ProID", Convert.ToInt32(ProID));
            db.DataDelete("DescField", "ProID", Convert.ToInt32(ProID));
            db.Dispose();
            string FieldNameCount = Request.Form.Get("FieldNameCount");
            if (!string.IsNullOrEmpty(FieldNameCount))
            {
                string FieldName = string.Empty;
                string FieldValue = string.Empty;
                string InputType = string.Empty;
                for (int i = 0; i < Convert.ToInt32(FieldNameCount); i++)
                {
                    FieldName = Request.Form.Get("FieldName" + i);
                    FieldValue = Request.Form.Get("Field" + i);
                    InputType = Request.Form.Get("InputType" + i);
                    if (string.IsNullOrEmpty(InputType))
                        InputType = "0";
                    string[] PostField_data = new string[] { ProID, FieldName, FieldValue, InputType };
                    KstCmsBase.DAL.Product.Product.PostField_Insert(PostField_data, "ProID", "FieldName", "FieldValue", "InputType");
                }
            }
            string DescFieldCount = Request.Form.Get("DescFieldCount");
            if (!string.IsNullOrEmpty(FieldNameCount))
            {
                string FieldName = string.Empty;
                string FieldValue = string.Empty;
                for (int i = 0; i < Convert.ToInt32(DescFieldCount); i++)
                {
                    FieldName = Request.Form.Get("DescFieldName" + i);
                    FieldValue = Request.Form.Get("DescFieldValue" + i);
                    string[] DescField_data = new string[] { ProID, FieldName, FieldValue };
                    KstCmsBase.DAL.Product.Product.DescField_Insert(DescField_data, "ProID", "FieldName", "FieldValue");
                }
            }
            //ShowMsgModle("修改成功！");
            try
            {
                if (chk_create.Checked)
                {
                    string lbid = drp_ProLBList.SelectedValue;
                    lbid = lbid.Substring(0, lbid.Length - 1);
                    string classid = lbid;
                    if (lbid.IndexOf(",") != -1)
                        lbid = lbid.Substring(lbid.LastIndexOf(",") + 1);
                    KstWEB.SiteWeb.CreateProduct(Convert.ToInt32(drp_SiteList.SelectedValue), Convert.ToInt32(drp_MenuList.SelectedValue), Convert.ToInt32(lbid), classid, Convert.ToInt32(ProID));
                }
            }
            catch
            {
                throw new Exception("生成失败，请检查产品内容模板！");
            }
            finally
            {
                Response.Redirect("ProductList.aspx?ClassId=" + drp_ProLBList.SelectedValue.Substring(0, drp_ProLBList.SelectedValue.Length - 1));
            }
        }

        void drp_ProLBList_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowProductTypeData();
        }

        private void ShowProductTypeData()
        {
            string ProLBID = drp_ProLBList.SelectedValue;
            if (drp_ProLBList.SelectedValue.IndexOf(",") != -1)
            {
                ProLBID = drp_ProLBList.SelectedValue.Substring(0, drp_ProLBList.SelectedValue.Length - 1);
                if (ProLBID.IndexOf(",") != -1)
                {
                    ProLBID = ProLBID.Substring(ProLBID.LastIndexOf(",") + 1);
                }
            }
            KstCmsBase.Entities.Product.Product_Ent Product = KstCmsBase.DAL.Product.Product.GetProductInfo(Convert.ToInt32(ProID));
            KstCmsBase.Entities.Product.ProLB_Ent ProLB = KstCmsBase.DAL.Product.ProLB.Get_ProLbInfo(Convert.ToInt32(ProLBID), "TypeID");
            //如下如果切换不同的类别，初始化-显示类型产品参数。
            if (Product.TypeID != ProLB.TypeID)
            {
                ShowTypeExtFieldValue1(ProLB); //显示类别对应的类型产参数,参数选项
                ShowTypeExtFieldValue2(ProLB); //显示类别对应的类型产参数,说明产数选项
            }
            else //显示产品已保存了的类型参数
            {
                if (Product.PostFieldItems != null && Product.PostFieldItems.Count > 0)
                    ShowExtFieldValue1(Product);
                else
                    ShowTypeExtFieldValue1(ProLB);

                if(Product.DescFieldItems!=null && Product.DescFieldItems.Count>0)
                    ShowExtFieldValue2(Product);
                else
                    ShowTypeExtFieldValue2(ProLB);
            }
        }

        private void ShowTypeExtFieldValue1(KstCmsBase.Entities.Product.ProLB_Ent ProLB)
        {

            if (ProLB.Fields1 != null)
            {
                string Str = string.Empty;
                for (int i = 0; i < ProLB.Fields1.Count; i++)
                {
                    KstCmsBase.Entities.Product.Field1_Ent item = (KstCmsBase.Entities.Product.Field1_Ent)ProLB.Fields1[i];
                    Str += "<tr class=\"Linetr1\" onMouseOver=\"this.className='Linetr2';\" onMouseOut=\"this.className='Linetr1';\">";
                    Str += "<td nowrap class=\"Line\"><input type=\"hidden\" name=\"FieldName" + i + "\" value=\"" + item.FieldName + "\" />" + item.FieldName + "：</td>";
                    if (item.InputType == 1)
                    {
                        string chxstr = string.Empty;
                        if (!string.IsNullOrEmpty(item.FieldValue))
                        {

                            string[] s = item.FieldValue.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                            string[] q = s[0].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                            chxstr += "<input type=\"hidden\" name=\"InputType" + i + "\" value=\"1\" />";
                            for (int n = 0; n < q.Length; n++)
                            {

                                if (s.Length > 1)
                                {
                                    if (s[1] == n.ToString())
                                        chxstr += "<input type=\"checkbox\" name=\"Field" + i + "\" value=\"" + q[n] + "\" checked=\"checked\" />" + q[n] + " ";
                                    else
                                        chxstr += "<input type=\"checkbox\" name=\"Field" + i + "\" value=\"" + q[n] + "\" />" + q[n] + " ";
                                }
                                else
                                {
                                    chxstr += "<input type=\"checkbox\" name=\"Field" + i + "\" value=\"" + q[n] + "\" />" + q[n] + " ";
                                }
                            }

                        }
                        Str += "<td class=\"Line\">" + chxstr + "</td></tr>";
                    }
                    else
                    {
                        Str += "<td class=\"Line\"><input type=\"text\" size=\"50\" maxlength=\"250\" name=\"Field" + i + "\" value=\"" + item.FieldValue + "\" class=\"input_text\" /></td></tr>";
                    }
                }
                lit_Field.Text = Str + "<input type=\"hidden\" name=\"FieldNameCount\" value=\"" + ProLB.Fields1.Count + "\" />";
            }
            else
            {
                lit_Field.Text = "";
            }

            
        }

        private void ShowTypeExtFieldValue2(KstCmsBase.Entities.Product.ProLB_Ent ProLB)
        {
            if (ProLB.Fields2 != null)
            {
                string descStr1 = string.Empty;
                string descStr2 = string.Empty;
                for (int i = 0; i < ProLB.Fields2.Count; i++)
                {
                    KstCmsBase.Entities.Product.Field2_Ent item = (KstCmsBase.Entities.Product.Field2_Ent)ProLB.Fields2[i];
                    descStr1 += "<td id=\"btn" + i + "\" align=\"center\" nowrap=\"nowrap\" class=\"ActiveBtn1\" onclick=\"ClickBtn(this," + (ProLB.Fields2.Count + 1).ToString() + ");$(pageInit" + i + ");\">" + item.FieldName + "<input type=\"hidden\" name=\"DescFieldName" + i + "\" value=\"" + item.FieldName + "\" /></td>";
                    descStr2 += "<tbody id=\"desc" + i + "\">";
                    descStr2 += "<tr class=\"Linetr1\" onMouseOver=\"this.className='Linetr2';\" onMouseOut=\"this.className='Linetr1';\">";
                    descStr2 += "<td colspan=\"2\" class=\"Line\">";
                    descStr2 += "<textarea name=\"DescFieldValue" + i + "\" id=\"DescFieldValue" + i + "\" rows=\"20\" style=\"width: 100%\">" + item.FieldValue + "</textarea>";
                    descStr2 += "</td></tr></tbody>";
                    xheditorjs += "function pageInit" + i + "(){$('#DescFieldValue" + i + "').xheditor({ upLinkUrl: \"../../../xheditor1.1.6/UpLoad.aspx?immediate=1\", upLinkExt: \"doc,xls,ppt,pdf,zip,rar,txt\", upImgUrl: \"../../../xheditor1.1.6/UpLoad.aspx?immediate=1\", upImgExt: \"jpg,jpeg,gif,png\", upFlashUrl: \"../../../xheditor1.1.6/UpLoad.aspx?immediate=1\", upFlashExt: \"swf\", upMediaUrl: \"../../../xheditor1.1.6/UpLoad.aspx?immediate=1\", upMediaExt: \"wmv,avi,wma,mp3,mid\", shortcuts: { 'ctrl+enter': submitForm} });}";
                }
                descStr1 += "<input type=\"hidden\" name=\"DescFieldCount\" value=\"" + ProLB.Fields2.Count + "\" />";
                btnNum = (ProLB.Fields2.Count + 1).ToString();
                SeoFieldValue = "desc" + ProLB.Fields2.Count;
                SeoField = "btn" + ProLB.Fields2.Count;
                lit_descFildName.Text = descStr1;
                lit_descFieldValue.Text = descStr2;
                jstr = "ClickBtn(document.getElementById('" + SeoField + "')," + btnNum + ");";
                xheditorjs = xheditorjs + "function submitForm(){$('#form1').submit();}";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "", xheditorjs + jstr, true);

                StringBuilder js = new StringBuilder();
                js.Append("function check(){var frm = document.forms[0];if(!checkForm(frm)){return false;}else{");
                for (int i = 0; i < ProLB.Fields2.Count; i++)
                {
                    js.Append("document.getElementById(\"DescFieldValue" + i + "\").value = $('#DescFieldValue" + i + "').val();");
                }
                js.Append("return true;}}");
                OkBtn.OnClientClick = "return check();";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "checkForm", js.ToString(), true);
            }
            else
            {
                lit_descFildName.Text = "";
                lit_descFieldValue.Text = "";
                xheditorjs = "";
            }
        }

        private void ShowExtFieldValue1(KstCmsBase.Entities.Product.Product_Ent Product)
        {
            if (Product.PostFieldItems != null)
            {
                string Str = string.Empty;
                for (int i = 0; i < Product.PostFieldItems.Count; i++)
                {
                    KstCmsBase.Entities.Product.PostField_Ent item = (KstCmsBase.Entities.Product.PostField_Ent)Product.PostFieldItems[i];
                    Str += "<tr class=\"Linetr1\" onMouseOver=\"this.className='Linetr2';\" onMouseOut=\"this.className='Linetr1';\">";
                    Str += "<td nowrap class=\"Line\"><input type=\"hidden\" name=\"FieldName" + i + "\" value=\"" + item.FieldName + "\" />" + item.FieldName + "：</td>";
                    if (item.InputType == 1)
                    {
                        KstCmsBase.DAL.Access db = new KstCmsBase.DAL.Access();
                        string ProTypeFieldValue = db.getFieldValue(string.Format("select FieldValue from ProductField1 where FieldName='{0}' and TypeID={1}", item.FieldName, Product.TypeID.ToString()));
                        db.Dispose();
                        string chxstr = string.Empty;
                        if (!string.IsNullOrEmpty(ProTypeFieldValue))
                        {
                            string[] s = ProTypeFieldValue.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                            string[] q = s[0].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                            chxstr += "<input type=\"hidden\" name=\"InputType" + i + "\" value=\"1\" />";
                            for (int n = 0; n < q.Length; n++)
                            {
                                if (!string.IsNullOrEmpty(item.FieldValue))
                                {
                                    if (item.FieldValue.IndexOf(q[n]) != -1)
                                    {
                                        chxstr += "<input type=\"checkbox\" name=\"Field" + i + "\" value=\"" + q[n] + "\" checked=\"checked\" />" + q[n] + " ";
                                    }
                                    else
                                    {
                                        chxstr += "<input type=\"checkbox\" name=\"Field" + i + "\" value=\"" + q[n] + "\" />" + q[n] + " ";
                                    }
                                }
                                else
                                {
                                    chxstr += "<input type=\"checkbox\" name=\"Field" + i + "\" value=\"" + q[n] + "\" />" + q[n] + " ";
                                }

                            }

                        }
                        Str += "<td class=\"Line\">" + item.FieldValue + " [重新选择：" + chxstr + "]</td></tr>";
                    }
                    else
                    {
                        Str += "<td class=\"Line\"><input type=\"text\" size=\"50\" maxlength=\"250\" name=\"Field" + i + "\" value=\"" + item.FieldValue + "\" class=\"input_text\" /></td></tr>";
                    }
                }
                lit_Field.Text = Str + "<input type=\"hidden\" name=\"FieldNameCount\" value=\"" + Product.PostFieldItems.Count + "\" />";
            }
            else
            {
                lit_Field.Text = "";
            }
            
        }

        private void ShowExtFieldValue2(KstCmsBase.Entities.Product.Product_Ent Product)
        {
            if (Product.DescFieldItems != null)
            {
                string descStr1 = string.Empty;
                string descStr2 = string.Empty;
                for (int i = 0; i < Product.DescFieldItems.Count; i++)
                {
                    KstCmsBase.Entities.Product.DescField_Ent item = (KstCmsBase.Entities.Product.DescField_Ent)Product.DescFieldItems[i];
                    descStr1 += "<td id=\"btn" + i + "\" align=\"center\" nowrap=\"nowrap\" class=\"ActiveBtn1\" onclick=\"ClickBtn(this," + (Product.DescFieldItems.Count + 1).ToString() + ");$(pageInit" + i + ");\">" + item.FieldName + "<input type=\"hidden\" name=\"DescFieldName" + i + "\" value=\"" + item.FieldName + "\" /></td>";
                    descStr2 += "<tbody id=\"desc" + i + "\">";
                    descStr2 += "<tr class=\"Linetr1\" onMouseOver=\"this.className='Linetr2';\" onMouseOut=\"this.className='Linetr1';\">";
                    descStr2 += "<td colspan=\"2\" class=\"Line\">";
                    descStr2 += "<textarea name=\"DescFieldValue" + i + "\" id=\"DescFieldValue" + i + "\" rows=\"20\" style=\"width: 100%\">" + item.FieldValue + "</textarea>";
                    descStr2 += "</td></tr></tbody>";
                    xheditorjs += "function pageInit" + i + "(){$('#DescFieldValue" + i + "').xheditor({ upLinkUrl: \"../../../xheditor1.1.6/UpLoad.aspx?immediate=1\", upLinkExt: \"doc,xls,ppt,pdf,zip,rar,txt\", upImgUrl: \"../../../xheditor1.1.6/UpLoad.aspx?immediate=1\", upImgExt: \"jpg,jpeg,gif,png\", upFlashUrl: \"../../../xheditor1.1.6/UpLoad.aspx?immediate=1\", upFlashExt: \"swf\", upMediaUrl: \"../../../xheditor1.1.6/UpLoad.aspx?immediate=1\", upMediaExt: \"wmv,avi,wma,mp3,mid\", shortcuts: { 'ctrl+enter': submitForm} });}";
                }
                descStr1 += "<input type=\"hidden\" name=\"DescFieldCount\" value=\"" + Product.DescFieldItems.Count + "\" />";
                btnNum = (Product.DescFieldItems.Count + 1).ToString();
                SeoFieldValue = "desc" + Product.DescFieldItems.Count;
                SeoField = "btn" + Product.DescFieldItems.Count;
                lit_descFildName.Text = descStr1;
                lit_descFieldValue.Text = descStr2;
                jstr = "ClickBtn(document.getElementById('" + SeoField + "')," + btnNum + ");";
                xheditorjs = xheditorjs + "function submitForm(){$('#form1').submit();}";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "", xheditorjs + jstr, true);
                StringBuilder js = new StringBuilder();
                js.Append("function check(){var frm = document.forms[0];if(!checkForm(frm)){return false;}else{");
                for (int i = 0; i < Product.DescFieldItems.Count; i++)
                {
                    js.Append("document.getElementById(\"DescFieldValue" + i + "\").value = $('#DescFieldValue" + i + "').val();");
                }
                js.Append("return true;}}");
                OkBtn.OnClientClick = "return check();";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "checkForm", js.ToString(), true);
            }
            else
            {
                lit_descFildName.Text = "";
                lit_descFieldValue.Text = "";
                xheditorjs = "";
            }
        }

        void drp_MenuList_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowtoProLb(drp_SiteList.SelectedValue, drp_MenuList.SelectedValue);
            drp_ProLBList_SelectedIndexChanged(sender, e);
            lit_descFildName.Text = "";
            lit_Field.Text = "";
            xheditorjs = "";
        }

        void drp_SiteList_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowMenuDrp(drp_SiteList.SelectedValue);
            ShowtoProLb(drp_SiteList.SelectedValue, drp_MenuList.SelectedValue);
            drp_ProLBList_SelectedIndexChanged(sender, e);
            lit_descFildName.Text = "";
            lit_Field.Text = "";
            xheditorjs = "";
            ShowDrpTempList(Convert.ToInt32(drp_SiteList.SelectedValue));

        }

        void GetProductInfo()
        {
            KstCmsBase.Entities.Product.Product_Ent Product = KstCmsBase.DAL.Product.Product.GetProductInfo(Convert.ToInt32(ProID));
            ShowSiteDrp();
            drp_SiteList.SelectedValue = Product.SiteID.ToString();
            ShowMenuDrp(Product.SiteID.ToString());
            drp_MenuList.SelectedValue = Product.MenuID.ToString();
            ShowtoProLb(Product.SiteID.ToString(), Product.MenuID.ToString());
            drp_ProLBList.SelectedValue = Product.LbID;
            txt_ProNo.Text = Product.ProNo;
            txt_ProName.Text = Product.ProName;
            txt_DefaultPic.Text = Product.Pic3;
            OldPic3 = Product.Pic3;
            OldPic2 = Product.Pic2;
            OldPic1 = Product.Pic1;
            txt_ProDoc.Value = Product.ProDoc;
            chk_IsNew.Checked = Product.IsNew == 1 ? true : false;
            chk_IsTj.Checked = Product.IsTj == 1 ? true : false;
            chk_IsHot.Checked = Product.IsHot == 1 ? true : false;
            txt_uTime.Text = Product.uTime.ToString("yyyy-MM-dd");
            txt_SortNo.Text = Product.SortNo.ToString();
            txt_MateDesc.Text = Product.MateDesc;
            txt_MateKey.Text = Product.MateKey;
            txt_FileName.Text = Product.FileName;
            FileName.Value = Product.FileName;
            //txt_FileName.Enabled = false;
            ShowDrpTempList(Convert.ToInt32(drp_SiteList.SelectedValue));
            drp_TempList.SelectedValue = Product.TempID.ToString();
            ShowProductTypeData();
            //生成静态选项
            chk_create.Checked = WebExeute == 1;
            chk_create.Visible = WebExeute == 1;


        }

        void ShowSiteDrp()
        {
            KstCmsBase.Collection.WebSite_Collection WebSiteItems = KstCmsBase.DAL.WebSite.Get_WebSiteList(1, "SiteID", "SiteName");
            for (int i = 0; i < WebSiteItems.Count; i++)
            {
                ListItem item = new ListItem();
                item.Value = ((KstCmsBase.Entities.WebSite_ent)WebSiteItems[i]).SiteID.ToString();
                item.Text = ((KstCmsBase.Entities.WebSite_ent)WebSiteItems[i]).SiteName;
                drp_SiteList.Items.Add(item);

            }
            drp_SiteList.Items.Insert(0, new ListItem("请选择站点", "0"));
            ShowDrpTempList(Convert.ToInt32(drp_SiteList.SelectedValue));
           
        }

        void ShowMenuDrp(string SiteId)
        {
            drp_MenuList.Items.Clear();
            KstCmsBase.Collection.WebMenuCollection WebMenuItems = KstCmsBase.DAL.WebMenu.Get_MenuList(Convert.ToInt32(SiteId), 1, 1, "MenuID", "MenuName");
            for (int i = 0; i < WebMenuItems.Count; i++)
            {
                ListItem item = new ListItem();
                item.Value = ((KstCmsBase.Entities.WebMenu_ent)WebMenuItems[i]).MenuID.ToString();
                item.Text = ((KstCmsBase.Entities.WebMenu_ent)WebMenuItems[i]).MenuName;
                drp_MenuList.Items.Add(item);
            }
            drp_MenuList.Items.Insert(0, new ListItem("请选所属栏目", "0"));
        }

        void ShowtoProLb(string SiteId, string Menuid)
        {
           /* drp_ProLBList.Items.Clear();
            KstCmsBase.Common.HtmlControl.ProLB_HtmlControls drp = new KstCmsBase.Common.HtmlControl.ProLB_HtmlControls(SiteId, Menuid);
            drp.ShowDrpProductLbID(0, ref this.drp_ProLBList);
            drp_ProLBList.Items.Insert(0, new ListItem("选择产品类别", "0"));
            */
            drp_ProLBList.Items.Clear();
            string CacheName = drp_ProLBList.ClientID + SiteId.ToString() + Menuid.ToString() + "editpro";
            if (Read_Cache(CacheName) != null)
            {
                foreach (ListItem item in ((DropDownList)Read_Cache(CacheName)).Items)
                    drp_ProLBList.Items.Add(item);
            }
            else
            {
                //drp_ProLBList.Items.Clear();
                KstCmsBase.Common.HtmlControl.ProLB_HtmlControls drp = new KstCmsBase.Common.HtmlControl.ProLB_HtmlControls(SiteId, Menuid);
                drp.ShowDrpProductLbID(0, ref this.drp_ProLBList);
                drp_ProLBList.Items.Insert(0, new ListItem("选择产品类别", "0"));
                Set_Cache(CacheName, drp_ProLBList);
                //System.Web.HttpContext.Current.Cache.Add(CacheName, drp_ProLBList, null, DateTime.Now.AddMinutes(CookieTime), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null);
            }

        }

        void Set_Control()
        {
            string[] Cons = new string[] { "产品类别~!", "产品编吗~noChinese!", "产品名称~!", "上传图片~!", "更新时间~date!", "排序~int!" };
            base.Set_Control(Cons, drp_ProLBList, txt_ProNo, txt_ProName, txt_DefaultPic, txt_uTime, txt_SortNo);
            txt_SortNo.Attributes.Add("onkeydown", "IsDigit();");
            txt_uTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }

        void ShowDrpTempList(int SiteId)
        {
            drp_TempList.Items.Clear();
            KstCmsBase.Collection.TempCollection TempItems = KstCmsBase.DAL.Templates.GetTemplatesItems(KstCmsBase.DAL.Templates.TempType.ProContent, SiteId);
            foreach (KstCmsBase.Entities.Template_Ent Temp in TempItems)
            {
                ListItem item = new ListItem();
                item.Value = Temp.TempID.ToString();
                item.Text = Temp.TempName;
                if (Temp.DefaultAct == 1)
                    item.Selected = true;
                drp_TempList.Items.Add(item);
            }
            drp_TempList.Items.Insert(0, new ListItem("请选择模板", "0"));
        }
    }
}