public void Bind() { string typeName = "盛大开幕图片"; List <Img> list = ImgBll.GetImgbytypeName(typeName); if (list.Count > 0) { hfImgId.Value = list[0].ImgId.ToString(); imgOpen.ImageUrl = "../" + list[0].ImgUrl; hfImgUrl.Value = list[0].ImgUrl; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["typeId"] != null && Request.QueryString["typeId"] != "") { int imgTypeId = Convert.ToInt32(Request.QueryString["typeId"]); hfTypeId.Value = imgTypeId.ToString(); hlnkList.NavigateUrl = "Img.aspx?typeId=" + imgTypeId; txtTimer.Value = DateTime.Now.ToString("yyyy-MM-dd"); List <ImgType> list = ImgTypeBll.GetImgTypebyId(imgTypeId); if (list.Count > 0) { lblType.Text = list[0].TypeName; ltlTitle.Text = "添加" + list[0].TypeName; hlnkList.Text = "查看" + list[0].TypeName + "列表"; } else { lblType.Text = ""; ltlTitle.Text = "添加图片"; hlnkList.Text = "查看图片列表"; } } else if (Request.QueryString["id"] != null && Request.QueryString["id"] != "") { int id = Convert.ToInt32(Request.QueryString["id"]); hfId.Value = id.ToString(); List <Model.Img> list = ImgBll.GetImgbyId(id); if (list.Count > 0) { txtTitle.Text = list[0].Title; txtImg.Text = list[0].ImgUrl; txtLink.Text = list[0].LinkUrl; txtRank.Text = list[0].Rank.ToString(); txtTimer.Value = list[0].CreateTime; chkShow.Checked = Convert.ToBoolean(list[0].IsShow); List <ImgType> list_imgType = ImgTypeBll.GetImgTypebyId(list[0].ImgTypeId); if (list_imgType.Count > 0) { lblType.Text = list_imgType[0].TypeName; ltlTitle.Text = "添加" + list_imgType[0].TypeName; hlnkList.Text = "查看" + list_imgType[0].TypeName + "列表"; } else { lblType.Text = ""; } hlnkList.NavigateUrl = "Img.aspx?typeId=" + list[0].ImgTypeId; } } } }
protected void btnSave_Click(object sender, EventArgs e) { if (hfImgId.Value != "") { int imgId = Convert.ToInt32(hfImgId.Value); string imgUrl = hfImgUrl.Value; try { ImgBll.UpdateImgUrl(imgId, imgUrl); MessageBox.Alert("保存成功!", Page); Bind(); } catch (Exception) { MessageBox.Alert("保存失败!", Page); } } else { Img img = new Img(); img.Title = "首页盛大开幕图片"; img.Rank = 1; img.ImgUrl = hfImgUrl.Value; string typeName = "盛大开幕图片"; List <ImgType> list = ImgTypeBll.GetImgTypebyName(typeName); if (list.Count > 0) { img.ImgTypeId = list[0].ImgTypeId; } else { img.ImgTypeId = 3; } img.IsShow = 1; img.LinkUrl = "#"; img.Remark = ""; img.CreateTime = DateTime.Now.ToString("yyyy-MM-dd"); try { ImgBll.AddImg(img); Bind(); MessageBox.Alert("保存成功!", Page); } catch (Exception) { MessageBox.Alert("保存失败!", Page); } } }
protected void dgBanner_ItemCommand(object source, DataGridCommandEventArgs e) { if (e.CommandName.ToLower() == "status") { int imgId = Convert.ToInt32(e.CommandArgument); List <Model.Img> list = ImgBll.GetImgbyId(imgId); if (list.Count > 0) { int status = 0; if (list[0].IsShow == 0) { status = 1; } else { status = 0; } try { ImgBll.UpdateStatus(imgId, status); BindData(); } catch (Exception ex) { MessageBox.Alert("未知错误:" + ex, Page); /*throw;*/ } } } else if (e.CommandName.ToLower() == "del") { int id = Convert.ToInt32(e.CommandArgument); try { ImgBll.DeleteImg(id); MessageBox.Alert("删除成功!", Page); BindData(); } catch (Exception) { MessageBox.Alert("删除失败!", Page); /*throw;*/ } } }
public void BindData() { int typeId = Convert.ToInt32(hfTypeId.Value); DataTable dt = ImgBll.getImgbytypeId(typeId); if (dt.Rows.Count > 0) { AspNetPager1.RecordCount = dt.Rows.Count; PagedDataSource pds = new PagedDataSource(); pds.DataSource = dt.DefaultView; pds.PageSize = AspNetPager1.PageSize; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; dgBanner.DataSource = pds; dgBanner.DataBind(); } else { dgBanner.DataSource = null; dgBanner.DataBind(); } }
protected void btnDelSelect_Click(object sender, EventArgs e) { int selectNum = 0; for (int i = 0; i < dgBanner.Items.Count; i++) { CheckBox chk = dgBanner.Items[i].FindControl("chkSelect") as CheckBox; if (chk.Checked) { selectNum++; } } if (selectNum == 0) { MessageBox.Alert("请选择要删除的项!", Page); } else { for (int i = 0; i < dgBanner.Items.Count; i++) { CheckBox chk = dgBanner.Items[i].FindControl("chkSelect") as CheckBox; if (chk.Checked) { int sId = Convert.ToInt32(dgBanner.DataKeys[i]); try { ImgBll.DeleteImg(sId); } catch (Exception) { MessageBox.Alert("删除失败!", Page); break; } } } } BindData(); }
protected void btnSave_Click(object sender, EventArgs e) { Model.Img img = new Model.Img(); if (txtTitle.Text == "") { MessageBox.Alert("标题不能为空!", Page); txtTitle.Focus(); } else if (hfId.Value == "" && hfTypeId.Value == "") { Response.Redirect("right.aspx"); } else { img.Title = txtTitle.Text.Trim(); img.IsShow = Convert.ToInt32(chkShow.Checked); img.LinkUrl = txtLink.Text; img.Remark = ""; if (txtTimer.Value == "") { img.CreateTime = DateTime.Now.ToString("yyyy-MM-dd"); } else { img.CreateTime = txtTimer.Value; } if (txtRank.Text == "") { img.Rank = 0; } else { try { img.Rank = Convert.ToInt32(txtRank.Text); } catch (Exception) { img.Rank = 0; /*throw;*/ } } //判断缩略图的值 if (txtImg.Text == "" && hfImgUrl.Value == "") { img.ImgUrl = ""; } else if (txtImg.Text != "" && hfImgUrl.Value == "") { img.ImgUrl = txtImg.Text; } else if (txtImg.Text == "" && hfImgUrl.Value != "") { img.ImgUrl = hfImgUrl.Value; } else if (txtImg.Text != hfImgUrl.Value) { img.ImgUrl = hfImgUrl.Value; } else { img.ImgUrl = txtImg.Text; } if (hfTypeId.Value != "") { img.ImgTypeId = Convert.ToInt32(hfTypeId.Value); try { ImgBll.AddImg(img); MessageBox.AlertAndRedirect("添加成功!", "Img.aspx?typeId=" + img.ImgTypeId, Page); } catch (Exception) { MessageBox.Alert("添加失败!", Page); /*throw;*/ } } else if (hfId.Value != "") { img.ImgId = Convert.ToInt32(hfId.Value); List <Model.Img> list = ImgBll.GetImgbyId(img.ImgId); if (list.Count > 0) { img.ImgTypeId = list[0].ImgTypeId; try { ImgBll.UpdateImg(img); MessageBox.AlertAndRedirect("修改成功!", "Img.aspx?typeId=" + img.ImgTypeId, Page); } catch (Exception) { MessageBox.Alert("修改失败!", Page); /*throw;*/ } } } } }