protected void btnThem_Click(object sender, EventArgs e) { string url = ""; if (Page.IsValid && UploadImg.HasFile && CheckFileType(UploadImg.FileName)) { string fileName = "img/item/" + UploadImg.FileName; string filePath = MapPath(fileName); UploadImg.SaveAs(filePath); Image1.ImageUrl = fileName; url = fileName; } if (txMauSac.Text == String.Empty && txSoLuong.Text == String.Empty && txGiaBan.Text == String.Empty) { Response.Write("<script>alert('Hãy nhập đủ dữ liệu!!')</script>"); ClientScript.RegisterStartupScript(this.GetType(), "alert", "ShowAdd();", true); } else { if (checkSP(txMauSac.Text, int.Parse(DropSize.SelectedValue.ToString()))) { Response.Write("<script>alert('Đã tồn tại sản phẩm')</script>"); ClientScript.RegisterStartupScript(this.GetType(), "alert", "ShowAdd();", true); } else { String sql = "Insert into CTSP(maSp,mausac,masize,giaban,soluongton,anh) values('" + masp + "',N'" + txMauSac.Text + "',N'" + DropSize.SelectedValue + "',N'" + txGiaBan.Text + "',N'" + txSoLuong.Text + "',N'" + url + "')"; DataTable data = KetNoi.Excutequerry(sql); Response.Write("<script>alert('Thêm thành công!!')</script>"); LoadGrCTSP(); } } }
public void PS_Upload(Auth auth, UploadImg request, UploadImg_Logic logic, CommonResponse ecr, string[] token, string uri) { if (auth.AuthResult(token, uri)) { ecr.data.results = logic.upload(request); ecr.meta.code = 200; ecr.meta.message = "OK"; } else { ecr.meta.code = 401; ecr.meta.message = "Unauthorized"; } }
public ActionResult add(AdListAddViewModel _adlist) { if (ModelState.IsValid) { HttpPostedFileBase pfb = Request.Files["fileIMG"]; string outPath = ""; string msg = UploadImg.Upload(pfb, out outPath); if (msg != "") { } AdList model = new AdList() { AdPositionId = _adlist.AdPositionId, Img = _adlist.Img, IsShow = _adlist.IsShow, Src = _adlist.Src, Title = _adlist.Title }; AdPosition position = adpositionBll.Find(p => p.Id == model.AdPositionId); //判断广告数量 int count = adlistBll.Count(a => a.AdPositionId == model.AdPositionId); if (count >= position.Count) { ModelState.AddModelError("", "广告数量已满!"); } else { model = adlistBll.Add(model); if (model.Id > 0) { return(RedirectToAction("list"));//Response.Write("添加成功"); } else { ModelState.AddModelError("", "添加失败!"); } } } return(View(_adlist)); }
public async Task <IActionResult> Upload(UploadImg model) { var file = model.file; if (file.Length == 0) { return(Json(new { Result = "NullImg" })); } if (file.Length > 0) { string path = Path.Combine(_env.WebRootPath, "images"); using (var fs = new FileStream(Path.Combine(path, file.FileName), FileMode.Create)) { await file.CopyToAsync(fs); } model.Source = $"/images/{(file.FileName)}"; model.Extension = Path.GetExtension(file.FileName).Substring(1); return(Ok(model)); } return(Json(new { Result = "NullImg" })); }
public ActionResult Upload() { HttpPostedFileBase postedFile = Request.Files["file_data"]; if (postedFile == null) { return(JsAlert("没有选择文件")); } UploadImg.FileModel filemodel = UploadImg.Upload(postedFile); FileEntity fileEntity = new FileEntity() { F_FileMax = Convert.ToDouble(filemodel.FileMax) / 1024 + "kb", F_FileName = filemodel.FileName, F_RealName = filemodel.RealName, F_CreatorTime = DateTime.Now, F_CreatorUserId = OperatorProvider.Provider.GetCurrent().UserId, F_UploadDate = DateTime.Now, F_UploadUser = OperatorProvider.Provider.GetCurrent().UserId }; fileApp.SubmitForm(fileEntity, ""); return(Success("操作成功。")); }
protected void btnSubmit_Click(object sender, EventArgs e) { using (BLLComBanner bll = new BLLComBanner()) { ComBanner obj = new ComBanner(); if (id > 0) { obj = bll.GetSingle(id); obj.ID = id; } obj.ComBannerTypeID = Convert.ToInt32(ddlNewsType.SelectedValue); obj.BannerTitle = txtDLName.Text.Trim().ToString(); obj.BannerLink = txtLink.Text.Trim().ToString(); #region 产品图片(前台产品图片来源于此) 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)); if (IsAllowedExtension(StringPlus.MapPath(virFileFullName))) { if (id > 0) {//新增时无需删除 if (File.Exists(StringPlus.MapPath(bll.GetSingle(id).BannerPic))) { File.Delete(StringPlus.MapPath(bll.GetSingle(id).BannerPic)); } } obj.BannerPic = virFileFullName; } else { if (File.Exists(StringPlus.MapPath(virFileFullName))) { File.Delete(StringPlus.MapPath(virFileFullName)); } ShowMsg("请上传正确的图片(.jpg,.gif,.bmp,.png)"); return; } } else { obj.BannerPic = Image1.ImageUrl.ToString(); } } catch (DevNetException ex) { ExceptionManager.ShowErrorMsg(this, ex); return; } #endregion bll.Save(obj); if (bll.IsFail) { ExceptionManager.ShowErrorMsg(this, bll.DevNetException); } else { JSMsg.ShowWinRedirect(this, "保存成功", "cpBannerSet.aspx"); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { using (BLLProductType bll = new BLLProductType()) { ProductType obj = new ProductType(); if (id > 0) { obj = bll.GetSingle(id); obj.ID = id; } obj.ProductTypeName = txtProductTypeName.Text.Trim().ToString(); obj.AutoSort = Convert.ToInt32(txtAutoSort.Text); 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); UploadImg.SaveAs(StringPlus.MapPath(virFileFullName)); if (IsAllowedExtension(StringPlus.MapPath(virFileFullName))) { if (id > 0) {//新增时无需删除 if (File.Exists(StringPlus.MapPath(bll.GetSingle(id).ProductTypePic))) { File.Delete(StringPlus.MapPath(bll.GetSingle(id).ProductTypePic)); } } obj.ProductTypePic = virFileFullName; } else { if (File.Exists(StringPlus.MapPath(virFileFullName))) { File.Delete(StringPlus.MapPath(virFileFullName)); } ShowMsg("请上传正确的图片(.jpg,.gif,.bmp,.png)"); return; } } else { obj.ProductTypePic = 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; } if (rbhave.Checked == true) { obj.IsHaveSecondTpye = 1; } else if (rbno.Checked == true) { obj.IsHaveSecondTpye = 2; } else { ShowMsg("请是否有二级目录!"); return; } bll.Save(obj); if (bll.IsFail) { ExceptionManager.ShowErrorMsg(this, bll.DevNetException); } else { JSMsg.ShowWinRedirect(this, "保存成功", "cpProductTypeList.aspx"); } } }
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"); } } }
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"); } } }