Example #1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        DBLL.clsProduct    clProduct = new DBLL.clsProduct();
        DBLL.OptionSysDBLL option    = new DBLL.OptionSysDBLL();
        //bool _Result = clProduct.update_tb_ProductBynProductID(int.Parse(hfID.Value), ddlProductCateTreelist21.nSelectProductCategoryID, cbbHot.Checked, "", txtsProductNameCN.Text, txtsProductNameEN.Text, CKEditorControl3.Text, CKEditorControl4.Text, CKEditorControl1.Text, CKEditorControl2.Text, Session["user"].ToString(), DateTime.Now, true, int.Parse(txtnSorting.Text), "", txtsEnsitivityCN.Text, txtsEnsitivityEN.Text, txtsChannelBalanceCN.Text, txtsChannelBalanceEN.Text, txtsImpedanceCN.Text, txtsImpedanceEN.Text, txtsFrequencyCN.Text, txtsFrequencyEN.Text, txtsRatedPowerCN.Text, txtsRatedPowerEN.Text, txtsMaximumPowerCN.Text, txtsMaximumPowerEN.Text, txtsBrandNameCN.Text, txtsBrandNameEN.Text);
        bool _Result = clProduct.update_tb_ProductBynProductID(int.Parse(hfID.Value), ddlProductCateTreelist21.nSelectProductCategoryID, cbbHot.Checked, "", txtsProductNameCN.Text, txtsProductNameEN.Text, CKEditorControl3.Text, CKEditorControl4.Text, CKEditorControl1.Text, CKEditorControl2.Text, Session["user"].ToString(), DateTime.Now, true, int.Parse(txtnSorting.Text), "", "", "", "", "", "", "", "", "", "", "", "", "", txtsBrandNameCN.Text, txtsBrandNameEN.Text);

        if (_Result)
        {
            string sSaveFolderFullPath = Server.MapPath(Image3.ImageUrl);
            if (File.Exists(sSaveFolderFullPath))
            {
                //如果存在则删除
                File.Delete(sSaveFolderFullPath);

                System.IO.DirectoryInfo dir  = new System.IO.DirectoryInfo(sSaveFolderFullPath.Substring(0, sSaveFolderFullPath.LastIndexOf("\\")).ToString());
                System.IO.FileInfo[]    dirs = dir.GetFiles();
                if (dirs.Length > 0)
                {
                    //有子文件夹
                }
                else
                {
                    Directory.Delete(sSaveFolderFullPath.Substring(0, sSaveFolderFullPath.LastIndexOf("\\")).ToString());
                }
            }
            lblsImagePath.Visible = true;
            MutileUploaderUserControl31.Visible = true;
            Label2.Visible  = false;
            Button1.Visible = false;
            Image3.Visible  = false;
            Image3.ImageUrl = "";
            Image4.ImageUrl = "";
        }
    }
Example #2
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        //判断session
        if (Session["User"] == null || Session["User"].ToString().Length < 1)
        {
            Response.Redirect(Request.RawUrl);
        }
        try
        {
            int nID = 0;
            if (int.TryParse(hfID.Value.ToString(), out nID) && nID > 0)
            {
                //更新
                if (ValiEdit())
                {
                    DBLL.clsProduct    Product = new DBLL.clsProduct();
                    DBLL.OptionSysDBLL option  = new DBLL.OptionSysDBLL();

                    string sSavepath = "";
                    //生成缩略图
                    HttpFileCollection postedFiles = Request.Files;
                    if (postedFiles.Count > 0)
                    {
                        if (postedFiles[0].ContentLength > 0)
                        {
                            System.Drawing.Image image, newimage; //定义image类的对象
                            string imagePath;                     //图片路径
                            string imageType;                     //图片类型
                            string imageName;                     //图片名称
                            //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行
                            //如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false
                            System.Drawing.Image.GetThumbnailImageAbort callb = null;


                            string basepath = "~/ProductsUpload" + "/temp/" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +
                                              DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
                                              DateTime.Now.Second.ToString() + "/";

                            string sSaveFolderFullPath = Server.MapPath(basepath);

                            if (!System.IO.Directory.Exists(sSaveFolderFullPath))
                            {
                                Directory.CreateDirectory(sSaveFolderFullPath);
                            }


                            string thbasepath = "~/ProductsUpload" + "/thumb/" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +
                                                DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
                                                DateTime.Now.Second.ToString() + "/";

                            string thsSaveFolderFullPath = Server.MapPath(thbasepath);

                            if (!System.IO.Directory.Exists(thsSaveFolderFullPath))
                            {
                                Directory.CreateDirectory(thsSaveFolderFullPath);
                            }


                            imagePath = postedFiles[0].FileName;
                            //取得图片类型
                            imageType = imagePath.Substring(imagePath.LastIndexOf(".") + 1);
                            //取得图片名称
                            imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1);
                            Stream imgStream = postedFiles[0].InputStream;   //流文件,准备读取上载文件的内容
                            int    imgLen    = postedFiles[0].ContentLength; //上载文件大小
                            //string imgName = txtImageName.Text;                   //图片名称


                            //string imgnm = txtImageName.Text;
                            byte[] imgBinaryData = new byte[imgLen];//


                            int n = imgStream.Read(imgBinaryData, 0, imgLen);



                            //保存到虚拟路径
                            postedFiles[0].SaveAs(sSaveFolderFullPath + "\\" + imageName);
                            ////显示原图
                            //imageSource.ImageUrl = "upFile/" + imageName;
                            //为上传的图片建立引用
                            image = System.Drawing.Image.FromFile(sSaveFolderFullPath + "\\" + imageName);

                            //int smallW = 100;//小图片宽
                            //int smallH = smallW * image.Height / image.Width;//小图片高

                            int smallH = 100;
                            int smallW = smallH * image.Width / image.Height;
                            //生成缩略图
                            newimage = image.GetThumbnailImage(smallW, smallH, callb, new System.IntPtr());
                            //把缩略图保存到指定的虚拟路径
                            newimage.Save(thsSaveFolderFullPath + "\\" + imageName);
                            //释放image对象占用的资源
                            image.Dispose();
                            //释放newimage对象的资源
                            newimage.Dispose();

                            sSavepath = thbasepath + imageName;
                        }
                    }
                    bool _Result = false;
                    if (Image3.ImageUrl != "")
                    {
                        _Result = Product.update_tb_ProductBynProductID(nID, ddlProductCateTreelist21.nSelectProductCategoryID, cbbHot.Checked, Image3.ImageUrl, txtsProductNameCN.Text, txtsProductNameEN.Text, CKEditorControl3.Text, CKEditorControl4.Text, CKEditorControl1.Text, CKEditorControl2.Text, Session["user"].ToString(), DateTime.Now, true, int.Parse(txtnSorting.Text), Image4.ImageUrl, "", "", "", "", "", "", "", "", "", "", "", "", txtsBrandNameCN.Text, txtsBrandNameEN.Text);
                    }
                    else
                    {
                        if (sSavepath != "")
                        {
                            MutileUploaderUserControl31.SavePath();
                            _Result = Product.update_tb_ProductBynProductID(nID, ddlProductCateTreelist21.nSelectProductCategoryID, cbbHot.Checked, MutileUploaderUserControl31.filepathlist[0].ToString(), txtsProductNameCN.Text, txtsProductNameEN.Text, CKEditorControl3.Text, CKEditorControl4.Text, CKEditorControl1.Text, CKEditorControl2.Text, Session["user"].ToString(), DateTime.Now, true, int.Parse(txtnSorting.Text), sSavepath, "", "", "", "", "", "", "", "", "", "", "", "", txtsBrandNameCN.Text, txtsBrandNameEN.Text);
                        }
                        else
                        {
                            _Result = Product.update_tb_ProductBynProductID(nID, ddlProductCateTreelist21.nSelectProductCategoryID, cbbHot.Checked, "", txtsProductNameCN.Text, txtsProductNameEN.Text, CKEditorControl3.Text, CKEditorControl4.Text, CKEditorControl1.Text, CKEditorControl2.Text, Session["user"].ToString(), DateTime.Now, true, int.Parse(txtnSorting.Text), "", "", "", "", "", "", "", "", "", "", "", "", "", txtsBrandNameCN.Text, txtsBrandNameEN.Text);
                        }
                    }
                    if (_Result == true)
                    {
                        ShowMsg1.InnerContent = option.GetOptionValue("FormatSetting", "CommandControl", "UpdateSuccess");
                        ShowMsg1.Show();
                    }
                    else
                    {
                        //失败就一条
                        ShowMsg1.InnerContent = option.GetOptionValue("FormatSetting", "CommandControl", "UpdateFail");
                        ShowMsg1.Show();
                    }
                }
                else
                {
                    ShowMsg1.Show();
                }
            }
        }
        catch (Exception)
        {
            throw;
        }
    }
Example #3
0
    protected void BtnUpdate_Click(object sender, EventArgs e)
    {
        //判断session
        if (Session["User"] == null || Session["User"].ToString().Length < 1) Response.Redirect(Request.RawUrl);
        try
        {
            if (ValiEdit())
            {
                DBLL.clsProduct Product = new DBLL.clsProduct();
                DBLL.OptionSysDBLL option = new DBLL.OptionSysDBLL();


                string sSavepath = "";
                //生成缩略图 
                HttpFileCollection postedFiles = Request.Files;
                if (postedFiles.Count > 0)
                {
                    if (postedFiles[0].ContentLength > 0)
                    {
                        System.Drawing.Image image, newimage; //定义image类的对象
                        string imagePath;   //图片路径
                        string imageType;   //图片类型
                        string imageName;   //图片名称
                        //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行
                        //如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false
                        System.Drawing.Image.GetThumbnailImageAbort callb = null;


                        string basepath = "~/ProductsUpload" + "/temp/" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +
                            DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
                            DateTime.Now.Second.ToString() + "/";

                        string sSaveFolderFullPath = Server.MapPath(basepath);

                        if (!System.IO.Directory.Exists(sSaveFolderFullPath))
                        {
                            Directory.CreateDirectory(sSaveFolderFullPath);
                        }


                        string thbasepath = "~/ProductsUpload" + "/thumb/" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +
                            DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
                            DateTime.Now.Second.ToString() + "/";

                        string thsSaveFolderFullPath = Server.MapPath(thbasepath);

                        if (!System.IO.Directory.Exists(thsSaveFolderFullPath))
                        {
                            Directory.CreateDirectory(thsSaveFolderFullPath);
                        }


                        imagePath = postedFiles[0].FileName;
                        //取得图片类型
                        imageType = imagePath.Substring(imagePath.LastIndexOf(".") + 1);
                        //取得图片名称
                        imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1);
                        Stream imgStream = postedFiles[0].InputStream;//流文件,准备读取上载文件的内容
                        int imgLen = postedFiles[0].ContentLength;    //上载文件大小
                        //string imgName = txtImageName.Text;                   //图片名称


                        //string imgnm = txtImageName.Text;
                        byte[] imgBinaryData = new byte[imgLen];//


                        int n = imgStream.Read(imgBinaryData, 0, imgLen);



                        //保存到虚拟路径
                        postedFiles[0].SaveAs(sSaveFolderFullPath + "\\" + imageName);
                        ////显示原图
                        //imageSource.ImageUrl = "upFile/" + imageName;
                        //为上传的图片建立引用
                        image = System.Drawing.Image.FromFile(sSaveFolderFullPath + "\\" + imageName);

                        //int smallW = 100;//小图片宽
                        //int smallH = smallW * image.Height / image.Width;//小图片高

                        int smallH = 100;
                        int smallW = smallH * image.Width / image.Height;
                        //生成缩略图
                        newimage = image.GetThumbnailImage(smallW, smallH, callb, new System.IntPtr());
                        //把缩略图保存到指定的虚拟路径
                        newimage.Save(thsSaveFolderFullPath + "\\" + imageName);
                        //释放image对象占用的资源
                        image.Dispose();
                        //释放newimage对象的资源
                        newimage.Dispose();

                        sSavepath = thbasepath + imageName;
                    }
                }


                bool _Result = Product.update_tb_ProductBynProductID(int.Parse(hfProductUpdateID.Value), ddlProductCateTreelist2.nSelectProductCategoryID, cbbHot.Checked, sSavepath, txtsProductNameCN.Text, txtsProductNameEN.Text, txtsSummaryCN.Text, txtsSummaryEN.Text, txtsPlaceoforiginCN.Text, txtsPlaceoforiginEN.Text, txtsModelNoCN.Text, txtsModelNoEN.Text, txtsPriceTermsCN.Text, txtsPriceTermsEN.Text, txtsPaymentTermsCN.Text, txtsPaymentTermsEN.Text, txtsPackageCN.Text, txtsPackageEN.Text, txtsMinimumOrderCN.Text, txtsMinimumOrderEN.Text, txtsDeliveryTimeCN.Text, txtsDeliveryTimeEN.Text, txtsBrandNameCN.Text, txtsBrandNameEN.Text, CKEditorControl1.Text, CKEditorControl2.Text, Session["User"].ToString(), DateTime.Now, true, int.Parse(ddlnSorting.SelectedValue));
                if (_Result == true)
                {
                    int _ImageResult = 0;
                    MutileUploaderUserControl1.sNewName = txtsProductNameCN.Text;
                    MutileUploaderUserControl1.SavePath();
                    if (MutileUploaderUserControl1.filepathlist.Count > 0)
                    {
                        for (int i = 0; i < MutileUploaderUserControl1.filepathlist.Count; i++)
                        {
                            //Response.Write(MutileUploaderUserControl1.filepathlist[i]);
                            DBLL.clsProductImage ProductImage = new DBLL.clsProductImage();
                            _ImageResult = ProductImage.insert_tb_ProductImage(int.Parse(hfProductUpdateID.Value), MutileUploaderUserControl1.filenamelist[i].ToString(), txtsProductNameEN.Text, MutileUploaderUserControl1.filepathlist[i].ToString(), Session["User"].ToString(), DateTime.Now, Session["User"].ToString(), DateTime.Now, true, 1);
                        }
                    }
                    else
                    {
                        _ImageResult = 1;
                    }
                    if (_ImageResult > 0)
                    {
                        ShowMsg1.InnerContent = option.GetOptionValue("FormatSetting", "CommandControl", "InsertSuccess");
                        ShowMsg1.Show();
                        MultiView1.ActiveViewIndex = 0;
                        ReBindPageList();
                    }
                    else
                    {
                        ShowMsg1.InnerContent = option.GetOptionValue("FormatSetting", "CommandControl", "InsertFail");
                        ShowMsg1.Show();
                    }
                    MultiView1.ActiveViewIndex = 0;
                    ReBindPageList();
                }
                else
                {
                    //失败就一条
                    ShowMsg1.InnerContent = option.GetOptionValue("FormatSetting", "CommandControl", "UpdateFail");
                    ShowMsg1.Show();
                }
            }
        }
        catch (Exception)
        {

            throw;
        }
    }