protected void btnSetNoImg_Click(object sender, EventArgs e) { if (Request["ProductID"] + "" == "") { Response.Redirect("RightsWarn.aspx"); } else { try { WebProject.BLL.BaseData.ZT_COM_Product bll_Product = new WebProject.BLL.BaseData.ZT_COM_Product(); WebProject.Model.BaseData.ZT_COM_Product model_Product = bll_Product.GetModel(Int32.Parse(Request["ProductID"].ToString())); if (model_Product.ProductImgUrl.ToString() != "onlinenone.jpg") { System.IO.File.Delete(Server.MapPath("IMG/" + model_Product.ProductImgUrl.ToString())); model_Product.ProductImgUrl = "onlinenone.jpg"; model_Product.LastUpdateBy = SessionUtil.GetAdminSession().AdminNo; model_Product.LastUpdateDate = DateTime.Now; bll_Product.Update(model_Product); } LogManage.WriteLog(Request.UserHostAddress, "产品管理", "删除图片", "成功", "产品名称:" + model_Product.ProductName + ", 修改人:" + SessionUtil.GetAdminSession().AdminNo); MessageBox.Show(this, "删除原图片成功!"); } catch { Response.Redirect("RightsWarn.aspx"); } } }
public void ShowData() { if (Request["ProductID"] + "" == "") { Response.Redirect("RightsWarn.aspx"); } else { try { WebProject.BLL.BaseData.ZT_COM_Product bll_Product = new WebProject.BLL.BaseData.ZT_COM_Product(); WebProject.Model.BaseData.ZT_COM_Product model_Product = bll_Product.GetModel(Int32.Parse(Request["ProductID"].ToString())); if (model_Product.TypeNo.ToString() != "") { this.txtProductType.SelectedValue = model_Product.TypeNo.ToString(); } this.txtProductInfo.Text = model_Product.ProductInfo.ToString(); this.txtProductName.Text = model_Product.ProductName.ToString(); this.txtProductOrder.Text = model_Product.ProductOrder.ToString(); } catch { Response.Redirect("RightsWarn.aspx"); } } }
protected void btnDeleteSelect_Click(object sender, EventArgs e) { if (Session["ZT_ADMIN"] == null) { Response.Redirect("Login.aspx"); } else { if (!Communal.CheckQx("ProductDelete.aspx")) { Response.Redirect("RightsWarn.aspx"); } else { string DeleteTitle = ""; foreach (GridViewRow gr in this.GridView1.Rows) { CheckBox cb = (CheckBox)gr.Cells[1].FindControl("Select"); if (cb.Checked) { //删除数据库信息 Label ll = (Label)gr.Cells[1].FindControl("lblProductID"); int ProductID = Convert.ToInt32(ll.Text); WebProject.BLL.BaseData.ZT_COM_Product bll_Product = new WebProject.BLL.BaseData.ZT_COM_Product(); DeleteTitle += bll_Product.GetModel(ProductID).ProductName + ","; bll_Product.Delete(ProductID); //删除文件夹的图片 Label l2 = (Label)gr.Cells[0].FindControl("lblProductImgUrl"); if (l2.Text != "onlinenone.jpg") { System.IO.File.Delete(Server.MapPath("IMG/" + l2.Text)); } } } LogManage.WriteLog(Request.UserHostAddress, "产品管理", "删除产品信息", "成功", "产品名称:" + DeleteTitle.TrimEnd(',') + ", 操作人:" + SessionUtil.GetAdminSession().AdminNo); ShowData(); } } }
public void ShowProductInfo() { if (Request["ProductID"] + "" == "") { Response.Redirect("ErrorPage.aspx"); } else { try { int ProductID = Convert.ToInt32(Request.QueryString["ProductID"].ToString()); WebProject.BLL.BaseData.ZT_COM_Product bll_Product = new WebProject.BLL.BaseData.ZT_COM_Product(); WebProject.Model.BaseData.ZT_COM_Product model_Product = bll_Product.GetModel(ProductID); this.ProductImgUrl.ImageUrl = "SysManage/IMG/" + model_Product.ProductImgUrl.ToString(); this.lblProductName.Text = model_Product.ProductName.ToString(); this.lblProductInfo.Text = model_Product.ProductInfo.ToString(); } catch { Response.Redirect("ErrorPage.aspx"); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Session["ZT_ADMIN"] == null) { Response.Redirect("Login.aspx"); } else { if (this.txtProductName.Text.Trim() == "") { MessageBox.Show(this, "请输入产品名称!"); return; } if (this.txtProductInfo.Text.Trim() == "") { MessageBox.Show(this, "请输入信息内容!"); return; } int ProductOrder; if (this.txtProductOrder.Text.Trim() == "") { ProductOrder = 1000; } else { double u; if (!double.TryParse(this.txtProductOrder.Text.Trim(), out u)) { MessageBox.Show(this, "排序必须为数字!"); return; } else { ProductOrder = Convert.ToInt32(this.txtProductOrder.Text.Trim()); } } Boolean fileTypeOK = false; String path = Server.MapPath("~/SysManage/IMG/"); if (txtProductImgUrl.HasFile == false) { try { WebProject.BLL.BaseData.ZT_COM_Product bll_Product = new WebProject.BLL.BaseData.ZT_COM_Product(); WebProject.Model.BaseData.ZT_COM_Product model_Product = bll_Product.GetModel(Int32.Parse(Request["ProductID"].ToString())); model_Product.LastUpdateBy = SessionUtil.GetAdminSession().AdminNo; model_Product.LastUpdateDate = DateTime.Now; if (this.txtProductType.Items.Count > 0) { model_Product.TypeName = this.txtProductType.Items[this.txtProductType.SelectedIndex].Text.ToString(); model_Product.TypeNo = this.txtProductType.SelectedValue.ToString(); } model_Product.ProductInfo = this.txtProductInfo.Text.Trim(); model_Product.ProductName = this.txtProductName.Text.Trim(); model_Product.ProductOrder = ProductOrder; bll_Product.Update(model_Product); LogManage.WriteLog(Request.UserHostAddress, "产品管理", "修改产品信息", "成功", "产品名称:" + model_Product.ProductName + ", 操作人:" + SessionUtil.GetAdminSession().AdminNo); MessageBox.ShowAndRedirect(this, "修改信息成功!", "ProductList.aspx"); } catch { Response.Redirect("RightsWarn.aspx"); } } if (txtProductImgUrl.HasFile == true) { String fileExtension = System.IO.Path.GetExtension(txtProductImgUrl.FileName).ToLower(); String[] allowedExtensions = { ".bmp", ".jpg", ".jpeg", ".png", ".gif" }; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileTypeOK = true; break; } } if (fileTypeOK == false) { MessageBox.Show(this, "你要上传的文件类型不符合要求!"); return; } if (fileTypeOK == true) { if (txtProductImgUrl.PostedFile.ContentLength > 10240000) { MessageBox.Show(this, "你选择上传的文件不能大于10M,请重新选择!"); return; } if (txtProductImgUrl.PostedFile.ContentLength <= 10240000) { try { string SaveFileName = DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + fileExtension; txtProductImgUrl.PostedFile.SaveAs(path + SaveFileName); WebProject.BLL.BaseData.ZT_COM_Product bll_Product = new WebProject.BLL.BaseData.ZT_COM_Product(); WebProject.Model.BaseData.ZT_COM_Product model_Product = bll_Product.GetModel(Int32.Parse(Request["ProductID"].ToString())); model_Product.LastUpdateBy = SessionUtil.GetAdminSession().AdminNo; model_Product.LastUpdateDate = DateTime.Now; if (this.txtProductType.Items.Count > 0) { model_Product.TypeName = this.txtProductType.Items[this.txtProductType.SelectedIndex].Text.ToString(); model_Product.TypeNo = this.txtProductType.SelectedValue.ToString(); } model_Product.ProductImgUrl = SaveFileName; model_Product.ProductInfo = this.txtProductInfo.Text.Trim(); model_Product.ProductName = this.txtProductName.Text.Trim(); model_Product.ProductOrder = ProductOrder; bll_Product.Update(model_Product); LogManage.WriteLog(Request.UserHostAddress, "产品管理", "修改产品信息", "成功", "产品名称:" + model_Product.ProductName + ", 操作人:" + SessionUtil.GetAdminSession().AdminNo); MessageBox.ShowAndRedirect(this, "修改信息成功!", "ProductList.aspx"); } catch (Exception) { MessageBox.Show(this, "文件上传失败!"); return; } } } } } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { if (Session["ZT_ADMIN"] == null) { Response.Redirect("Login.aspx"); } else { if (!Communal.CheckQx("ProductDelete.aspx")) { Response.Redirect("RightsWarn.aspx"); } else { //删除数据库的信息 Label ll = (Label)this.GridView1.Rows[e.RowIndex].Cells[1].FindControl("lblProductID"); int ProductID = Convert.ToInt32(ll.Text); WebProject.BLL.BaseData.ZT_COM_Product bll_Product = new WebProject.BLL.BaseData.ZT_COM_Product(); LogManage.WriteLog(Request.UserHostAddress, "产品管理", "删除产品信息", "成功", "产品名称:" + bll_Product.GetModel(ProductID).ProductName + ", 操作人:" + SessionUtil.GetAdminSession().AdminNo); bll_Product.Delete(ProductID); //删除文件夹的图片 Label l2 = (Label)this.GridView1.Rows[e.RowIndex].Cells[0].FindControl("lblProductImgUrl"); if (l2.Text != "onlinenone.jpg") { System.IO.File.Delete(Server.MapPath("IMG/" + l2.Text)); } //重新加载信息 ShowData(); } } }