using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
using picmark;

namespace PanRoor
{
    public partial class WTOSYSadmin_Products_Products : XMLX
    {
        //图片上传
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["WtoRightName"] == null)
            {
                Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
            }
            if (!IsPostBack)
            {
                Doadmin.ddldatabind(Brand, "select * from Brand", "BrandName", "id");
                Doadmin.ddldatabind(BigProduct, "select * from BigProductCategory order by Sort", "BigCategory", "id");
                Doadmin.ddldatabind(smalllb, "select * from SmallProductCategory where BigCategoryId=" + BigProduct.SelectedValue.ToString().Trim(), "SmallCategory", "id");
                SqlConnection conn = CDatabase.wtoconn();
                conn.Open();
                SqlCommand smd = new SqlCommand("select mobantext from productmoban where defaultmoban='y'", conn);
                this.Content.Text =Server.HtmlDecode(Convert.ToString(smd.ExecuteScalar()));
                conn.Close();
            }
        }

        //保存
        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            //取值------------------------------------------------------------------------------------------------------------------
            //第一标签[基本信息] Products|产品名称$　ProductsNo|货号 ISPublished|open/close|是否发布 ISpf|批发 Brand|品牌 Description|简单描述
            //Unit|计量单位 Unitweight|单位重量 Stockvolume|库存量 StockWarning|isy/isns|库存警告 IsNew|最新 IsHot|最热 IsRecommended|推荐 IsSpecials|特价
            //Nature|商品属性 Content|详细信息
            #region 第一标签取值
            string Products, ProductsNo, ISPublished, ISpf, Brand, Description, Unit, Unitweight, Stockvolume, StockWarning, IsNew, IsHot, IsRecommended, IsSpecials, Nature, Content;
            Products = Request["Products"].ToString().Trim();
            ProductsNo = Request["ProductsNo"].ToString().Trim();
            if (this.open.Checked)
            {
                ISPublished = "y";
            }
            else
            {
                ISPublished = "n";
            }
            ISpf = "0";
            Brand = this.Brand.SelectedItem.Value;
            Description = Request["Description"].ToString().Trim();
            Unit = Request["Unit"].ToString().Trim();
            Unitweight = Request["Unitweight"].ToString().Trim();
            Stockvolume = Request["Stockvolume"].ToString().Trim();
            StockWarning = "y";
            if (this.IsNew.Checked)
            {
                IsNew = "y";
            }
            else
            {
                IsNew = "n";
            }
            if (this.IsHot.Checked)
            {
                IsHot = "y";
            }
            else
            {
                IsHot = "n";
            }
            if (this.IsRecommended.Checked)
            {
                IsRecommended = "y";
            }
            else
            {
                IsRecommended = "n";
            }
            if (this.IsSpecials.Checked)
            {
                IsSpecials = "y";
            }
            else
            {
                IsSpecials = "n";
            }

            if (this.isS.Checked)
            {
                Nature = "1";
            }
            else
            {
                if (this.isK.Checked)
                {
                    Nature = "2";
                }
                else
                {
                    Nature = "3";
                }
            }
            Content = Server.HtmlEncode(this.Content.Text.Replace("'", "''"));
            #endregion

            //第二标签取值开始
            //BigProduct|商品大类 SmlProduct|小类   
            //商品属性值确认表 ddlFL|属性列表大类 小类数组值
            //sale|销售价 CountALL|确认销售价  Sprice|市场价 CostPrice|成本价 CjVipPrice|初级会员价 MiddleVIPPrice|中级会员价 HiVipPrice|高级会员价
            //VIPPrice|VIP会员价
            #region 第二标签取值开始
            string BigProductID, SmallProductId, SalePrice, Marketprice, CostPrice, CjVipPrice, MiddleVIPPrice, HiVipPrice, VIPPrice,strall,sale;
            BigProductID = this.BigProduct.SelectedValue.ToString().Trim();
            SmallProductId =this.smalllb.SelectedValue.ToString();
            SalePrice =this.CountALL.Text.Trim();
            sale = "0";
            Marketprice = this.Sprice.Text.Trim();
            CostPrice = "0";
            CjVipPrice = "0";
            MiddleVIPPrice = "0";
            HiVipPrice = "0";
            VIPPrice = this.vipprice.Text.Trim();
            strall = "0";
            int  intj =Convert.ToInt32(this.intj.Text);
            //以上是商品表中内容.属性表还未填
            #endregion

            #region 第三标签取值开始------------------------------------------------------------------------------------------------------------------
            //  isslpic|开启本地上传缩略图 ThumbnailsPic|本地上传缩略图 fup_img|清晰图 RemotePicURLt|缩略图远程链接地址 RemotePicURLc|清晰图远程链接地址
            //更多图片:存放在商品图片更多表中[取数组值]
            //OriginalPic|原始图
            string fpath, ftype, fname, dot;
            string ThumbnailsPic, ClearPic, OriginalPic, RemotePicURLt, RemotePicURLc;
            string isSL = "";

                //取缩略图片
                string picPath = Server.MapPath("~/upfile");
                HttpPostedFile file = this.ThumbnailsPic.PostedFile;

                string hz = this.ThumbnailsPic.PostedFile.FileName;           
                if (hz != "")
                {

                    string S_hz = (hz.Substring(hz.LastIndexOf(".") + 1)).ToLower().Trim();
                    string stpt = "";
                    string stfilename = "";
                    if (S_hz == "jpg" || S_hz == "gif")
                    {
                        stfilename = DateTime.Now.ToString("yyyyMMddHHmmssffffMM");
                        stpt = Server.MapPath("~/upfile/") + stfilename + "." + S_hz;
                        file.SaveAs(stpt);

                    }
                    else
                    {
                        Response.Write("<script>alert('文件格式错误！');</script>");
                        Response.End();
                    }

                    ThumbnailsPic = stfilename + "." + S_hz;
                    isSL = "Y";
                }
                else
                {
                    ThumbnailsPic = "nopic.jpg";
                }

            #region 图片上传
            fname = this.fup_imgb.FileName;
            fpath = this.fup_imgb.PostedFile.FileName;
            ftype = this.fup_imgb.PostedFile.ContentType;
            string[] type = ftype.Split('/');
            string[] fn = fname.Split('.');
            dot = "." + fn[1].ToString();
            if (type[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                string filename = DateTime.Now.ToString("yyyyMMddHHffmmssffffss");
                string pt = Server.MapPath("~/upfile/") + filename + dot;
                fup_imgb.SaveAs(pt);
                fup_imgb.Dispose();
                if (XMLRead("NoAndOff") == "true")
                {
                    picmark.ImageModification wm = new ImageModification();
                    wm.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                    wm.ModifyImagePath = pt;    //图片的路径
                    wm.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                    wm.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                    wm.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                    wm.OutPath = Server.MapPath("~/upfile/") + filename + "_new" + dot;
                    wm.DrawImage();
                    if (File.Exists(pt))
                    {
                        File.Delete(pt);
                    }
                    ClearPic = filename + "_new" + dot;
                }
                else
                {
                    ClearPic = filename+ dot;
                }
                
            #endregion

                //接着取值
                RemotePicURLt = Request["RemotePicURLt"].ToString().Trim();
                RemotePicURLc = Request["RemotePicURLc"].ToString().Trim();
                if (RemotePicURLt == "")
                {
                    RemotePicURLt = "nopic.jpg";
                }
                if (RemotePicURLc == "")
                {
                    RemotePicURLc = "nopic.jpg";

                }
                OriginalPic = "nopic.jpg";//暂定为无图，如果有保留原始图，则为filename直接加上.jpg就OK了

                //更多图片上传取值开始
               string picstrSZ="";
               #region 第一个图上传
                string fpath1, ftype1, fname1, dot1, filename1, pt1;
                fname1 = this.Mpic1.FileName;
                fpath1 = this.Mpic1.PostedFile.FileName;
                if (fpath1 != "")
                {
                    ftype1 = this.Mpic1.PostedFile.ContentType;
                    string[] type1 = ftype1.Split('/');
                    string[] fn1 = fname.Split('.');
                    dot1 = "." + fn1[1].ToString();
                    if (type1[0].ToString() != "image")
                    {
                        Response.Write("文件格式错误！");
                    }
                    else
                    {
                        filename1 = DateTime.Now.ToString("yyyyMMssddHHmmssffffss");
                        pt1 = Server.MapPath("~/upfile/") + filename1 + dot1;
                        Mpic1.SaveAs(pt1);
                        Mpic1.Dispose();
                        if (XMLRead("NoAndOff") == "true")
                        {
                            picmark.ImageModification wm1 = new ImageModification();
                            wm1.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                            wm1.ModifyImagePath = pt1;    //图片的路径
                            wm1.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                            wm1.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                            wm1.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                            wm1.OutPath = Server.MapPath("~/upfile/") + filename1 + "_new" + dot1;
                            wm1.DrawImage();
                            if (File.Exists(pt1))
                            {
                                File.Delete(pt1);
                            }
                            picstrSZ += filename1 + "_new.jpg$";
                        }
                        else
                        {
                            picstrSZ += filename1 + ".jpg$";
                        }
                    }
                }


               #endregion
               #region 第二个图上传
                string fpath2, ftype2,fname2, dot2, filename2, pt2;
                    fname2 = this.Mpic2.FileName;
                    fpath2 = this.Mpic2.PostedFile.FileName;
                    if (fpath2 != "")
                    {
                        ftype2 = this.Mpic2.PostedFile.ContentType;
                        string[] type2 = ftype2.Split('/');
                        string[] fn2 = fname.Split('.');
                        dot2 = "." + fn2[1].ToString();
                        if (type2[0].ToString() != "image")
                        {
                            Response.Write("文件格式错误！");
                        }
                        else
                        {
                            filename2 = DateTime.Now.ToString("yyyyddMMddHHmmssffffss");
                            pt2 = Server.MapPath("~/upfile/") + filename2 + dot2;
                            Mpic2.SaveAs(pt2);
                            Mpic2.Dispose();
                            if (XMLRead("NoAndOff") == "true")
                            {
                                picmark.ImageModification wm2 = new ImageModification();
                                wm2.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                wm2.ModifyImagePath = pt2;    //图片的路径
                                wm2.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                wm2.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                wm2.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                wm2.OutPath = Server.MapPath("~/upfile/") + filename2 + "_new" + dot2;
                                wm2.DrawImage();
                                if (File.Exists(pt2))
                                {
                                    File.Delete(pt2);
                                }
                                
                                picstrSZ += filename2 + "_new.jpg$";
                            }
                            else
                            {
                                picstrSZ += filename2 + ".jpg$";
                            }

                        }
                    }


                    #endregion
               #region 第三个图上传
                        string fpath3,ftype3, fname3, dot3, filename3, pt3;
                        fname3 = this.Mpic3.FileName;
                        fpath3 = this.Mpic3.PostedFile.FileName;
                        if (fpath3 != "")
                        {
                            ftype3 = this.Mpic3.PostedFile.ContentType;
                            string[] type3 = ftype3.Split('/');
                            string[] fn3 = fname.Split('.');
                            dot3 = "." + fn3[1].ToString();
                            if (type3[0].ToString() != "image")
                            {
                                Response.Write("文件格式错误！");
                            }
                            else
                            {
                                filename3 = DateTime.Now.ToString("yyyyssMMddHHmmssssffff");
                                pt3 = Server.MapPath("~/upfile/") + filename3 + dot3;
                                Mpic3.SaveAs(pt3);
                                Mpic3.Dispose();
                                if (XMLRead("NoAndOff") == "true")
                                {
                                    picmark.ImageModification wm3 = new ImageModification();
                                    wm3.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                    wm3.ModifyImagePath = pt3;    //图片的路径
                                    wm3.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                    wm3.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                    wm3.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                    wm3.OutPath = Server.MapPath("~/upfile/") + filename3 + "_new" + dot3;
                                    wm3.DrawImage();
                                    if (File.Exists(pt3))
                                    {
                                        File.Delete(pt3);
                                    }
                                    picstrSZ += filename3 + "_new.jpg$";
                                }
                                else
                                {
                                    picstrSZ += filename3 + ".jpg$";
                                }

                            }
                        }

                        #endregion
               #region 第四个图上传
                            string fpath4,ftype4,fname4, dot4, filename4, pt4;
                            fname4 = this.Mpic4.FileName;
                            fpath4 = this.Mpic4.PostedFile.FileName;
                            if (fpath4 != "")
                            {
                                ftype4 = this.Mpic4.PostedFile.ContentType;
                                string[] type4 = ftype4.Split('/');
                                string[] fn4 = fname.Split('.');
                                dot4 = "." + fn4[1].ToString();
                                if (type4[0].ToString() != "image")
                                {
                                    Response.Write("文件格式错误！");
                                }
                                else
                                {
                                    filename4 = DateTime.Now.ToString("ssyyyyMMddHHmmffff");
                                    pt4 = Server.MapPath("~/upfile/") + filename4 + dot4;
                                    Mpic4.SaveAs(pt4);
                                    Mpic4.Dispose();
                                    if (XMLRead("NoAndOff") == "true")
                                    {
                                        picmark.ImageModification wm4 = new ImageModification();
                                        wm4.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                        wm4.ModifyImagePath = pt4;    //图片的路径
                                        wm4.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                        wm4.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                        wm4.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                        wm4.OutPath = Server.MapPath("~/upfile/") + filename4 + "_new" + dot4;
                                        wm4.DrawImage();
                                        if (File.Exists(pt4))
                                        {
                                            File.Delete(pt4);
                                        }
                                        
                                        picstrSZ += filename4 + "_new.jpg$";
                                    }
                                    else
                                    { 
                                    picstrSZ += filename4 + ".jpg$";
                                    }
                                }
                            }
                            #endregion
               #region 第五个图上传
                            string fpath5, ftype5,fname5, dot5, filename5, pt5;
                                fname5 = this.Mpic5.FileName;
                                fpath5 = this.Mpic5.PostedFile.FileName;
                                if (fpath5 != "")
                                {
                                    ftype5 = this.Mpic5.PostedFile.ContentType;
                                    string[] type5 = ftype5.Split('/');
                                    string[] fn5 = fname.Split('.');
                                    dot5 = "." + fn5[1].ToString();
                                    if (type5[0].ToString() != "image")
                                    {
                                        Response.Write("文件格式错误！");
                                    }
                                    else
                                    {
                                        filename5 = DateTime.Now.ToString("yyyyssMMssddHHffff");
                                        pt5 = Server.MapPath("~/upfile/") + filename5 + dot5;
                                        Mpic5.SaveAs(pt5);
                                        Mpic5.Dispose();
                                        if (XMLRead("NoAndOff") == "true")
                                        {
                                            picmark.ImageModification wm5 = new ImageModification();
                                            wm5.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                            wm5.ModifyImagePath = pt5;    //图片的路径
                                            wm5.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                            wm5.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                            wm5.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                            wm5.OutPath = Server.MapPath("~/upfile/") + filename5 + "_new" + dot5;
                                            wm5.DrawImage();
                                            if (File.Exists(pt5))
                                            {
                                                File.Delete(pt5);
                                            }
                                         
                                            picstrSZ += filename5 + "_new.jpg$";
                                        }
                                        else
                                        { 
                                           picstrSZ += filename5 + ".jpg$";
                                        }
                                    }
                                }
                                #endregion
               #region 第六个图上传
                                    string fpath6,ftype6,fname6, dot6, filename6, pt6;
                                    fname6 = this.Mpic6.FileName;
                                    fpath6 = this.Mpic6.PostedFile.FileName;
                                    if (fpath6 != "")
                                    {
                                        ftype6 = this.Mpic6.PostedFile.ContentType;
                                        string[] type6 = ftype6.Split('/');
                                        string[] fn6 = fname.Split('.');
                                        dot6 = "." + fn6[1].ToString();
                                        if (type6[0].ToString() != "image")
                                        {
                                            Response.Write("文件格式错误！");
                                        }
                                        else
                                        {
                                            filename6 = DateTime.Now.ToString("yyyyMMddHHssssss");
                                            pt6 = Server.MapPath("~/upfile/") + filename6 + dot6;
                                            Mpic6.SaveAs(pt6);
                                            Mpic6.Dispose();
                                            if (XMLRead("NoAndOff") == "true")
                                            {
                                                picmark.ImageModification wm6 = new ImageModification();
                                                wm6.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                                wm6.ModifyImagePath = pt6;    //图片的路径
                                                wm6.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                                wm6.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                                wm6.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                                wm6.OutPath = Server.MapPath("~/upfile/") + filename6 + "_new" + dot6;
                                                wm6.DrawImage();
                                                if (File.Exists(pt6))
                                                {
                                                    File.Delete(pt6);
                                                }
                                               
                                                picstrSZ += filename6 + "_new.jpg$";
                                            }
                                            else
                                            { 
                                             picstrSZ += filename6 + ".jpg$";
                                            }

                                        }
                                    }
                                    #endregion
               #region 第七个图上传
                                        string fpath7,ftype7,fname7, dot7, filename7, pt7;
                                        fname7 = this.Mpic7.FileName;
                                        fpath7 = this.Mpic7.PostedFile.FileName;
                                        if (fpath7 != "")
                                        {
                                            ftype7 = this.Mpic7.PostedFile.ContentType;
                                            string[] type7 = ftype7.Split('/');
                                            string[] fn7 = fname.Split('.');
                                            dot7 = "." + fn7[1].ToString();
                                            if (type7[0].ToString() != "image")
                                            {
                                                Response.Write("文件格式错误！");
                                            }
                                            else
                                            {
                                                filename7 = DateTime.Now.ToString("yyyyssddHssssssffff");
                                                pt7 = Server.MapPath("~/upfile/") + filename7 + dot7;
                                                Mpic7.SaveAs(pt7);
                                                Mpic7.Dispose();
                                                if (XMLRead("NoAndOff") == "true")
                                                {
                                                    picmark.ImageModification wm7 = new ImageModification();
                                                    wm7.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                                    wm7.ModifyImagePath = pt7;    //图片的路径
                                                    wm7.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                                    wm7.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                                    wm7.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                                    wm7.OutPath = Server.MapPath("~/upfile/") + filename7 + "_new" + dot7;
                                                    wm7.DrawImage();
                                                    if (File.Exists(pt7))
                                                    {
                                                        File.Delete(pt7);
                                                    }
                                                    
                                                    picstrSZ += filename7 + "_new.jpg$";
                                                }
                                                else
                                                { 
                                                picstrSZ += filename7 + ".jpg$";
                                                }

                                            }
                                        }


                                        #endregion
               #region 第八个图上传
                                            string fpath8,ftype8, fname8, dot8, filename8, pt8;
                                            fname8 = this.Mpic8.FileName;
                                            fpath8 = this.Mpic8.PostedFile.FileName;
                                            if (fpath8 != "")
                                            {
                                                ftype8 = this.Mpic8.PostedFile.ContentType;
                                                string[] type8 = ftype8.Split('/');
                                                string[] fn8 = fname.Split('.');
                                                dot8 = "." + fn8[1].ToString();
                                                if (type8[0].ToString() != "image")
                                                {
                                                    Response.Write("文件格式错误！");
                                                }
                                                else
                                                {
                                                    filename8 = DateTime.Now.ToString("ssssMMssHHmmssss");
                                                    pt8 = Server.MapPath("~/upfile/") + filename8 + dot8;
                                                    Mpic8.SaveAs(pt8);
                                                    Mpic8.Dispose();
                                                    if (XMLRead("NoAndOff") == "true")
                                                    {
                                                        picmark.ImageModification wm8 = new ImageModification();
                                                        wm8.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                                        wm8.ModifyImagePath = pt8;    //图片的路径
                                                        wm8.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                                        wm8.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                                        wm8.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                                        wm8.OutPath = Server.MapPath("~/upfile/") + filename8 + "_new" + dot8;
                                                        wm8.DrawImage();
                                                        if (File.Exists(pt8))
                                                        {
                                                            File.Delete(pt8);
                                                        }
                                                        
                                                        picstrSZ += filename8 + "_new.jpg$";
                                                    }
                                                    else
                                                    { 
                                                    picstrSZ += filename8 + ".jpg$";
                                                    }
                                                }
                                            }


                                            #endregion
               #region 第九个图上传
                                                string fpath9,ftype9, fname9, dot9, filename9, pt9;
                                                fname9 = this.Mpic9.FileName;
                                                fpath9 = this.Mpic9.PostedFile.FileName;
                                                if (fpath9 != "")
                                                {
                                                    ftype9 = this.Mpic9.PostedFile.ContentType;
                                                    string[] type9 = ftype9.Split('/');
                                                    string[] fn9 = fname.Split('.');
                                                    dot9 = "." + fn9[1].ToString();
                                                    if (type9[0].ToString() != "image")
                                                    {
                                                        Response.Write("文件格式错误！");
                                                    }
                                                    else
                                                    {
                                                        filename9 = DateTime.Now.ToString("ssssyyyyMMssssddHH");
                                                        pt9 = Server.MapPath("~/upfile/") + filename9 + dot9;
                                                        Mpic9.SaveAs(pt9);
                                                        Mpic9.Dispose();
                                                        if (XMLRead("NoAndOff") == "true")
                                                        {
                                                            picmark.ImageModification wm9 = new ImageModification();
                                                            wm9.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                                            wm9.ModifyImagePath = pt9;    //图片的路径
                                                            wm9.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                                            wm9.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                                            wm9.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                                            wm9.OutPath = Server.MapPath("~/upfile/") + filename9 + "_new" + dot9;
                                                            wm9.DrawImage();
                                                            if (File.Exists(pt9))
                                                            {
                                                                File.Delete(pt9);
                                                            }
                                                            
                                                            picstrSZ += filename9 + "_new.jpg$";
                                                        }
                                                        else
                                                        { 
                                                             picstrSZ += filename9 + ".jpg$";
                                                        }

                                                    }
                                                }

                                                #endregion
               #region 第十个图上传
                                                    string fpath10, ftype10,fname10, dot10, filename10, pt10;
                                                    fname10 = this.Mpic10.FileName;
                                                    fpath10 = this.Mpic10.PostedFile.FileName;
                                                    if (fpath10 != "")
                                                    {
                                                        ftype10 = this.Mpic10.PostedFile.ContentType;
                                                        string[] type10 = ftype10.Split('/');
                                                        string[] fn10 = fname.Split('.');
                                                        dot10 = "." + fn10[1].ToString();
                                                        if (type10[0].ToString() != "image")
                                                        {
                                                            Response.Write("文件格式错误！");
                                                        }
                                                        else
                                                        {
                                                            filename10 = DateTime.Now.ToString("yyyyMMssyymmddss");
                                                            pt10 = Server.MapPath("~/upfile/") + filename10 + dot10;
                                                            Mpic10.SaveAs(pt10);
                                                            Mpic10.Dispose();
                                                            if (XMLRead("NoAndOff") == "true")
                                                            {
                                                                picmark.ImageModification wm10 = new ImageModification();
                                                                wm10.DrawedImagePath = Server.MapPath("~/upfile/Watermark/logo_cn.gif"); //水印图片
                                                                wm10.ModifyImagePath = pt10;    //图片的路径
                                                                wm10.RightSpace = Convert.ToInt32(XMLRead("RightSpace"));          //水印位置 宽 相对图片右下角
                                                                wm10.BottoamSpace = Convert.ToInt32(XMLRead("BottoamSpace"));       //水印位置 高
                                                                wm10.LucencyPercent = Convert.ToInt32(XMLRead("LucencyPercent"));      //透明度
                                                                wm10.OutPath = Server.MapPath("~/upfile/") + filename10 + "_new" + dot10;
                                                                wm10.DrawImage();
                                                                if (File.Exists(pt10))
                                                                {
                                                                    File.Delete(pt10);
                                                                }
                                                               
                                                                picstrSZ += filename10 + "_new.jpg$";
                                                            }
                                                            else
                                                            { 
                                                             picstrSZ += filename10 + ".jpg$";
                                                            }

                                                        }
                                                    }
                                                    #endregion


                                                        //图片上传完成

    
              #endregion
            //第四标签[暂留]---------------------------------------------------------------------------------------------------------              

            #region 第五标签---------------------------------------------------------------------------------------------------------------
                                                        string PageTitle, META_KEYWORDS, META_DESCRIPTION;
                                                        PageTitle = Request["PageTitle"].ToString();
                                                        META_KEYWORDS = Request["META_KEYWORDS"].ToString();
                                                        META_DESCRIPTION = Request["META_DESCRIPTION"].ToString();
                                                        #endregion

            #region 整合上传
                                                        string sqlstrWTO;
                                                        sqlstrWTO = "insert into ProductInfo(BigProductID,SmallProductId,Products,ProductsNo,ISPublished,ISpf,Brand,Description,Unit,Unitweight,Stockvolume,StockWarning,IsNew,IsHot,IsRecommended,IsSpecials,Nature,Marketprice,SalePrice,CostPrice,CjVipPrice,MiddleVIPPrice,HiVipPrice,VIPPrice,ThumbnailsPic,ClearPic,OriginalPic,RemotePicURLt,RemotePicURLc,PageTitle,META_KEYWORDS,META_DESCRIPTION,Content,Picmore,XX,AddDate,Language,ljprice,times,intj,enddate)";
                                                        sqlstrWTO += " values (" + BigProductID + "," + SmallProductId + ",'" + Products + "','" + ProductsNo + "','" + ISPublished + "','" + ISpf + "','" + Brand + "','" + Description + "','" + Unit + "','" + Unitweight + "'," + Stockvolume + ",'" + StockWarning + "','" + IsNew + "','" + IsHot + "','" + IsRecommended + "','" + IsSpecials + "','" + Nature + "'";
                                                        sqlstrWTO += "," + Convert.ToDecimal(Marketprice) + "," + Convert.ToDecimal(SalePrice) + "," + Convert.ToDecimal(CostPrice) + "," + Convert.ToDecimal(CjVipPrice) + "," + Convert.ToDecimal(MiddleVIPPrice) + "," + Convert.ToDecimal(HiVipPrice) + "," + Convert.ToDecimal(VIPPrice) + ",'" + ThumbnailsPic + "','" + ClearPic + "','" + OriginalPic + "','" + RemotePicURLt + "','" + RemotePicURLc + "','" + PageTitle + "','" + META_KEYWORDS + "','" + META_DESCRIPTION + "','" + Content + "','" + picstrSZ + "','" + strall + "','"+System.DateTime.Now.ToString()+"','china',"+Convert.ToDecimal(sale)+",0,"+intj+",'"+this.TextBox1.Text+"')";
                                                        if (Doadmin.Exec(sqlstrWTO))
                                                        {
                                                            string[] txtre=Session["revalue"].ToString().Split('$');
                                                            string[] txt;
                                                            SqlConnection conn = CDatabase.wtoconn();
                                                            conn.Open();
                                                            SqlCommand smd;
                                                            int k;
                                                            int idd;
                                                            int sid;
                                                            string stxt;
                                                            string txtva = (Session["revalue"].ToString().Replace("1#","")).Replace("2#","") ;
                                                            smd = new SqlCommand("select max(id) from ProductInfo", conn);
                                                            idd =Convert.ToInt32(smd.ExecuteScalar());
                                                            Doadmin.Execsql("update productInfo set Related='"+txtva+"' where id="+idd);
                                                            for (int j = 0; j < txtre.Length - 1; j++)
                                                            {
                                                                txt = txtre[j].Split('#');//分离成; txt[0]单或双向  txt[1]产品ID号;
                                                                if (txt[0].ToString() == "2")
                                                                {
                                                                    smd = new SqlCommand("select Related from ProductInfo where id="+txt[1].ToString().Trim(),conn);
                                                                    stxt = Convert.ToString(smd.ExecuteScalar())+idd+'$';
                                                                    Doadmin.Execsql("update productInfo set Related='"+stxt+"' where id="+txt[1].ToString().Trim());
                                                                }
                                                            }
                                                            Response.Write("<script>alert('添加成功')</script>");
                                                            conn.Close();
                                                            
                                                        }
                                                        else
                                                        {
                                                            Response.Write("<script>alert('添加失败')</script>");
                                                        }
                                                        #endregion


                                   
                               
                      }
              }
        #region  验格式
        public bool IsAllowedExtension(HtmlInputFile hifile)
        {
            string strOldFilePath = "", strExtension = "";
            string[] arrExtension = { ".gif", ".jpg", ".jpeg", ".bmp", ".png" };
            if (hifile.PostedFile.FileName != string.Empty)
            {
                strOldFilePath = hifile.PostedFile.FileName;
                strExtension = strOldFilePath.Substring(strOldFilePath.LastIndexOf("."));
                for (int i = 0; i < arrExtension.Length; i++)
                {
                    if (strExtension.Equals(arrExtension[i]))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        #endregion
        protected void BigProduct_SelectedIndexChanged(object sender, EventArgs e)
        {
            Doadmin.ddldatabind(smalllb, "select * from SmallProductCategory where BigCategoryId=" + BigProduct.SelectedValue.ToString().Trim(), "SmallCategory", "id");

        }
}

 }
