Beispiel #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (BLLProductDetail bll = new BLLProductDetail())
            {
                string        prourlname = "";
                ProductDetail obj        = new ProductDetail();
                if (id > 0)
                {
                    obj    = bll.GetSingle(id);
                    obj.ID = id;
                }
                else
                {
                    obj.IsFlag = 0;
                }
                obj.ProductName = txtProName.Text.ToString();
                //obj.ProductEngName = txtProEngName.Text.ToString();
                obj.ProTypeID = Convert.ToInt32(ddlProType.SelectedValue);
                if (ddlProType.SelectedValue == null || ddlProType.SelectedValue == "0")
                {
                    return;
                }
                if (IsHaveSecondType(Convert.ToInt32(ddlProType.SelectedValue)))
                {
                    obj.ProSecondTypeID = Convert.ToInt32(ddlProSecondType.SelectedValue);
                }
                obj.ProductContent = txtContent.Value;
                obj.AutoSort       = Convert.ToInt32(txtAutoSort.Text.Trim().ToString() == "" ? "0" : txtAutoSort.Text.Trim().ToString());
                obj.Remarks        = txtRemarks.Text.ToString();
                #region   产品图片(前台产品图片来源于此)
                try
                {
                    if (this.UploadImg.HasFile)
                    {
                        string extName = Path.GetExtension(UploadImg.FileName);
                        string virFileFullName;
                        string fileName;

                        WebCommon.GetUploadRandFileName(extName, out virFileFullName, out fileName);
                        #region Add Begin
                        int    ind       = fileName.IndexOf(".");
                        string ofileName = fileName.Substring(0, ind);
                        prourlname = extName;
                        #endregion
                        UploadImg.SaveAs(StringPlus.MapPath(virFileFullName));
                        #region Add Begin
                        HttpFileCollection files = Request.Files;
                        string             path  = Server.MapPath("../../Upload");
                        HttpPostedFile     file  = files[0];
                        if (file != null && file.ContentLength > 0)
                        {
                            if (rbthasPhone.Checked == true)
                            {
                                //string filename = this.UpLoadImage(file, path + "/", Convert.ToInt32(ConfigHelper.GetAppString("CompressionWidth").Trim()), Convert.ToInt32(ConfigHelper.GetAppString("CompressionHeight").Trim()), ofileName);
                                string filename = this.UpLoadImage(file, path + "/", Convert.ToInt32(imgWidth.Text.ToString()), Convert.ToInt32(imgHeight.Text.ToString()), ofileName);
                            }
                        }
                        #endregion
                        if (IsAllowedExtension(StringPlus.MapPath(virFileFullName)))
                        {
                            if (id > 0)
                            {//新增时无需删除
                                string filename = bll.GetSingle(id).ProductPic;
                                if (File.Exists(StringPlus.MapPath(bll.GetSingle(id).ProductPic)))
                                {
                                    File.Delete(StringPlus.MapPath(bll.GetSingle(id).ProductPic));
                                }
                                if (File.Exists(StringPlus.MapPath(bll.GetSingle(id).ProductPic)))
                                {
                                    File.Delete(StringPlus.MapPath(bll.GetSingle(id).ProductPic));
                                }
                            }
                            obj.ProductPic = virFileFullName;
                        }
                        else
                        {
                            if (File.Exists(StringPlus.MapPath(virFileFullName)))
                            {
                                File.Delete(StringPlus.MapPath(virFileFullName));
                            }
                            ShowMsg("请上传正确的图片(.jpg,.gif,.bmp,.png)");
                            return;
                        }
                    }
                    else
                    {
                        obj.ProductPic = Image1.ImageUrl.ToString();
                    }
                }
                catch (DevNetException ex)
                {
                    ExceptionManager.ShowErrorMsg(this, ex);
                    return;
                }
                #endregion
                if (rbtnIsChinese.Checked == true)
                {
                    obj.IsEnglish = 1;
                }
                else if (rbtnIsEnglish.Checked == true)
                {
                    obj.IsEnglish = 2;
                }
                else
                {
                    ShowMsg("请选择语言类别!");
                    return;
                }
                bll.Save(obj);
                if (bll.IsFail)
                {
                    ExceptionManager.ShowErrorMsg(this, bll.DevNetException);
                }
                else
                {
                    JSMsg.ShowWinRedirect(this, "保存成功", "cpProductList.aspx");
                }
            }
        }
 /// <summary>
 /// 处理异常并向页面显示错误信息
 /// </summary>
 /// <param name="page"></param>
 /// <param name="ex"></param>
 public static void ShowErrorMsg(Page page, DevNetException ex)
 {
     JSMsg.ShowRegisterMsg(page, GetErrorMsg(ex));
 }
Beispiel #3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string prourlname = "";

            using (BLLSuccessStories bll = new BLLSuccessStories())
            {
                SuccessStories obj = new SuccessStories();
                if (id > 0)
                {
                    obj = bll.GetSingle(id);
                }
                obj.SSType    = Convert.ToInt32(ddlSuccessStoriesType.SelectedValue);
                obj.SSName    = txtNewsTitle.Text.ToString();
                obj.SSContent = txtContent.Value;
                obj.Remarks   = txtRemarks.Text.ToString();
                obj.AutoSort  = Convert.ToInt32(txtAutoSort.Text.Trim().ToString() == "" ? "0" : txtAutoSort.Text.Trim().ToString());
                obj.AddTime   = Convert.ToDateTime(System.DateTime.Now.ToShortDateString());
                try
                {
                    if (this.UploadImg.HasFile)
                    {
                        string extName = Path.GetExtension(UploadImg.FileName);
                        string virFileFullName;
                        string fileName;
                        WebCommon.GetUploadRandFileName(extName, out virFileFullName, out fileName);
                        UploadImg.SaveAs(StringPlus.MapPath(virFileFullName));
                        int    ind       = fileName.IndexOf(".");
                        string ofileName = fileName.Substring(0, ind);
                        prourlname = extName;
                        UploadImg.SaveAs(StringPlus.MapPath(virFileFullName));
                        HttpFileCollection files = Request.Files;
                        string             path  = Server.MapPath("../../Upload");
                        HttpPostedFile     file  = files[0];
                        if (file != null && file.ContentLength > 0)
                        {
                            if (rbthasPhone.Checked == true)
                            {
                                //string filename = this.UpLoadImage(file, path + "/", Convert.ToInt32(ConfigHelper.GetAppString("CompressionWidth").Trim()), Convert.ToInt32(ConfigHelper.GetAppString("CompressionHeight").Trim()), ofileName);
                                string filename = this.UpLoadImage(file, path + "/", Convert.ToInt32(imgWidth.Text.ToString()), Convert.ToInt32(imgHeight.Text.ToString()), ofileName);
                            }
                        }
                        if (IsAllowedExtension(StringPlus.MapPath(virFileFullName)))
                        {
                            if (id > 0)
                            {//新增时无需删除
                                if (File.Exists(StringPlus.MapPath(bll.GetSingle(id).SSPic)))
                                {
                                    File.Delete(StringPlus.MapPath(bll.GetSingle(id).SSPic));
                                }
                            }
                            obj.SSPic = virFileFullName;
                        }
                        else
                        {
                            if (File.Exists(StringPlus.MapPath(virFileFullName)))
                            {
                                File.Delete(StringPlus.MapPath(virFileFullName));
                            }
                            ShowMsg("请上传正确的图片(.jpg,.gif,.bmp,.png)");
                            return;
                        }
                    }
                    else
                    {
                        obj.SSPic = Image1.ImageUrl.ToString();
                    }
                }
                catch (DevNetException ex)
                {
                    ExceptionManager.ShowErrorMsg(this, ex);
                    return;
                }
                if (rbtnIsChinese.Checked == true)
                {
                    obj.IsEnglish = 1;
                }
                else if (rbtnIsEnglish.Checked == true)
                {
                    obj.IsEnglish = 2;
                }
                else
                {
                    ShowMsg("请选择语言类别!");
                    return;
                }

                bll.Save(obj);

                if (bll.IsFail)
                {
                    ExceptionManager.ShowErrorMsg(this, bll.DevNetException);
                }
                else
                {
                    JSMsg.ShowWinRedirect(this, "保存成功", "cpSuccessStoriesList.aspx");
                }
            }
        }