protected void Page_Load(object sender, EventArgs e) { com.adminLogin(); if (!IsPostBack) { string lbid = pg.request("lbid"); if (lbid == "") { lbid = "0"; } if (lbid != "") { lbname = clsLB.getLbname(lbid); hLbid.Value = lbid; } string act = pg.request("act"); if (act == "top") { //置顶 List <DXProd> prods = (from pro in dbContext.DXProd where pro.lbid == Int32.Parse(lbid) select pro).ToList <DXProd>(); foreach (var item in prods) { item.isTop = false; } dbContext.SubmitChanges(); DXProd pro_ = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(pg.request("id")) select pro).First <DXProd>(); pro_.isTop = true; dbContext.SubmitChanges(); return; } if (act == "IsIndex") { //置顶 DXProd pro_ = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(pg.request("id")) select pro).First <DXProd>(); pro_.isIndex = true; dbContext.SubmitChanges(); alert.showAndGo("设置成功", "Prod.aspx?lbid=" + lbid); return; } if (act == "del") { string id = pg.request("id"); DXProd pro_ = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(pg.request("id")) select pro).First <DXProd>(); //删除图片 FileSys.delFile(pro_.pic); FileSys.delFile(pro_.picSmall); FileSys.delFile(pro_.pic.Replace(".jpg", "_s.jpg")); //删除 dbContext.DXProd.DeleteOnSubmit(dbContext.DXProd.Single(c => c.Id == Int32.Parse(id))); alert.showAndGo("删除成功", "Prod.aspx?lbid=" + lbid); return; } bindGv(); } }
protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e) { string newsID = GV.DataKeys[e.RowIndex].Value.ToString(); SQLHelper_ db = new SQLHelper_(); db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + newsID; DataTable dt = db.Get_DataTable(); if (dt.Rows.Count > 0) { FileSys.delFile(dt.Rows[0]["pic"].ToString()); } //删除相册中的照片 db.sql = @"SELECT * FROM " + com.tablePrefix + "News WHERE ParentNewsID=" + newsID; dt = new DataTable(); dt = db.Get_DataTable(); foreach (DataRow dr in dt.Rows) { FileSys.delFile(dr["pic"].ToString()); } db.sql = "DELETE News WHERE ParentNewsID=" + newsID; db.ExecSql(); db.sql = "DELETE News WHERE NewsID=" + newsID; db.ExecSql(); bindGv(); alert.Show(Page, "删除成功"); }
protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e) { string newsID = GV.DataKeys[e.RowIndex].Value.ToString(); SQLHelper db = new SQLHelper(); //删除图片 db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + newsID; DataTable dt = db.Get_DataTable(); if (dt.Rows.Count > 0) { string pic = dt.Rows[0]["pic"].ToString(); FileSys.delFile(pic); } db.sql = "DELETE News WHERE NewsID=" + newsID; db.ExecSql(); bindGv(); alert.Show(Page, "删除成功"); return; }
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e) { lbid = hlbid.Value; System.Web.UI.WebControls.Button btn = e.CommandSource as System.Web.UI.WebControls.Button; if (btn == null) { return; } int index = ((System.Web.UI.WebControls.GridViewRow)btn.Parent.Parent).RowIndex; DataKey key = this.GV.DataKeys[index]; string NewsID = key.Value.ToString(); if (e.CommandName == "PicMng") { Server.Transfer("PhotoManage.aspx?lbid=" + NewsID); return; } GridViewRow gvr = GV.Rows[index]; if (e.CommandName == "upFile") { //寻找上传控件 FileUpload fu = (FileUpload)gvr.FindControl("FileUpload1"); if (fu != null) { if (fu.HasFile) { SQLHelper_ db = new SQLHelper_(); //上传图片 string pic = UpFile(fu); //删除原图 db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; string pic0 = db.Get_DataTable().Rows[0][0].ToString(); if (pic0.Length > 0) { FileSys.delFile(pic0); } //更新数据库 db.sql = "UPDATE News SET pic='" + pic + "' WHERE NewsID=" + NewsID; db.ExecSql(); bindGv(); alert.Show(Page, "图片更新成功"); } } } if (e.CommandName == "Save") { //查找 title控件 TextBox txtTitle = null; try { txtTitle = this.GV.Rows[index].Cells[1].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到图片集名称控件"); return; } TextBox txtEditTime = null; try { txtEditTime = this.GV.Rows[index].Cells[2].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到编辑日期控件"); return; } FileUpload fu = gvr.Cells[4].FindControl("FileUpload1") as FileUpload; string title = pg.GetSafeString(txtTitle.Text.Trim()); string EditTime = pg.GetSafeString(txtEditTime.Text.Trim()); if (title == "") { alert.Show(Page, "请填写图片集名称"); return; } if (EditTime == "") { EditTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); } string pic = UpFile(fu); SQLHelper_ db = new SQLHelper_(); if (NewsID.Length > 0) { if (pic != "") { //更新 db.sql = "UPDATE News SET title='" + title + "',pic='" + pic + "',editTime='" + EditTime + "' WHERE NewsID=" + NewsID; } else { //更新 db.sql = "UPDATE News SET title='" + title + "',editTime='" + EditTime + "' WHERE NewsID=" + NewsID; } if (db.ExecSql() != "1") { alert.Show(Page, "保存失败"); } else { GV.EditIndex = -1; bindGv(); } } else { //添加 NewsID = clsNews.MaxNewsid(); db.sql = "INSERT INTO News(lbid,NewsID,title,pic,EditTime,AddTime) VALUES(" + lbid + "," + NewsID + ",'" + title + "','" + pic + "','" + EditTime + "',getdate())"; if (db.ExecSql() != "1") { alert.Show(Page, "添加失败"); } else { GV.EditIndex = -1; bindGv(); } } } }
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e) { productid = hlbid.Value; System.Web.UI.WebControls.Button btn = e.CommandSource as System.Web.UI.WebControls.Button; if (btn == null) { return; } int index = ((System.Web.UI.WebControls.GridViewRow)btn.Parent.Parent).RowIndex; DataKey key = this.GV.DataKeys[index]; string NewsID = key.Value.ToString(); GridViewRow gvr = GV.Rows[index]; #region 单击上传图片按钮 if (e.CommandName == "upFile") { //寻找上传控件 FileUpload fu = (FileUpload)gvr.FindControl("FileUpload1");//原图 string pic = ""; //上传图片 pic = UpFile(fu); string picSmall = ""; if (pic != "") { picSmall = pic.ToLower().Replace(".jpg", "_s.jpg"); //ThumNail.MakeThumNail(pic, picSmall, 127, 127, "HW"); SQLHelper db = new SQLHelper(); //删除原图 db.sql = "SELECT pic,picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; DataTable dtp = db.Get_DataTable(); if (dtp.Rows.Count > 0) { string pic0 = dtp.Rows[0][0].ToString(); string pic1 = dtp.Rows[0][1].ToString(); if (pic0.Length > 0) { FileSys.delFile(pic0); } if (pic1.Length > 0) { FileSys.delFile(pic1); } } //更新数据库 db.sql = "UPDATE News SET pic='" + pic + "',picSmall='" + picSmall + "' WHERE NewsID=" + NewsID; db.ExecSql(); bindGv(); alert.Show(Page, "图片更新成功"); } } #endregion #region 保存 if (e.CommandName == "Save") { //查找 title控件 TextBox txtTitle = null; try { txtTitle = this.GV.Rows[index].Cells[1].Controls[0] as TextBox; } catch { alert.ShowAndBack(Page, "未找到标题控件"); return; } string colorid = "-1"; try { DropDownList ddlColor = (DropDownList)GV.Rows[index].FindControl("ddlColor"); colorid = ddlColor.SelectedValue; } catch (Exception) { alert.ShowAndBack(Page, "未找到颜色控件"); return; } string imgTypeid = ""; try { DropDownList ddImglType = (DropDownList)GV.Rows[index].FindControl("ddlpro_imgTypeid"); imgTypeid = ddImglType.SelectedValue; } catch (Exception) { alert.ShowAndBack(Page, "未找到图片类型控件"); return; } FileUpload fu = gvr.Cells[5].FindControl("FileUpload1") as FileUpload; string title = pg.GetSafeString(txtTitle.Text.Trim()); if (title == "") { alert.ShowAndBack(Page, "请填写标题"); return; } TextBox tbxOrder = null; try { tbxOrder = this.GV.Rows[index].Cells[6].Controls[0] as TextBox; } catch { alert.ShowAndBack(Page, "未找到排序文本框控件"); return; } string orderid = pg.GetSafeString(tbxOrder.Text.Trim()); if (orderid == "") { orderid = "0"; } string pic = UpFile(fu); string picSmall = ""; if (pic != "") { picSmall = pic.ToLower().Replace(".jpg", "_s.jpg"); } SQLHelper db = new SQLHelper(); if (NewsID.Length > 0) { //取出旧图 string oldPic = "", oldPicSmall = ""; db.sql = "SELECT pic,picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; DataTable dt = db.Get_DataTable(); if (dt.Rows.Count > 0) { oldPic = dt.Rows[0]["pic"].ToString(); oldPicSmall = dt.Rows[0]["picSmall"].ToString(); } //更新 string sql = "UPDATE News SET title='" + title + "',ColorId=" + colorid + ",pro_imgTypeid=" + imgTypeid + ",editTime=getdate(),OrderId=" + orderid; if (pic.Length > 0) { sql += " ,pic='" + pic + "'"; FileSys.delFile(oldPic); } if (picSmall.Length > 0) { sql += " ,picSmall='" + picSmall + "'"; FileSys.delFile(oldPicSmall); } sql += " WHERE NewsID=" + NewsID; db.sql = sql; if (db.ExecSql() != "1") { alert.Show(Page, "保存失败"); } else { GV.EditIndex = -1; bindGv(); } } else { //添加 NewsID = clsNews.MaxNewsid(); db.sql = "INSERT INTO News(ParentNewsID,NewsID,title,ColorId,pro_imgTypeid,pic,picSmall,EditTime,AddTime,OrderId) VALUES(" + productid + "," + NewsID + ",'" + title + "'," + colorid + "," + imgTypeid + ",'" + pic + "','" + picSmall + "',getdate(),getdate()," + orderid + ")"; if (db.ExecSql() != "1") { Response.Write("添加失败,sql=" + db.sql); //alert.Show(Page, "添加失败"); Response.End(); } else { GV.EditIndex = -1; bindGv(); } } } #endregion }
protected void Page_Load(object sender, EventArgs e) { //Session["AdminName"] = "admin"; // com.adminLogin(); if (!IsPostBack) { bindDDlLbid(); string NewsID = pg.request("id"); lbid = pg.request("lbid"); if (lbid == "") { lbid = "2"; //企业新闻 } ddlLbid.SelectedValue = lbid; if (NewsID != "") { string act = pg.request("act"); if (act == "delpic") { //由前台的jquery异步调用 string imgsrc = pg.request("imgsrc"); SQLHelper_ db = new SQLHelper_(); db.sql = "UPDATE News SET pic = replace(pic,'" + imgsrc + "','') WHERE NewsID=" + NewsID; db.ExecSql(); db.sql = "UPDATE News SET pic = replace(pic,'||','|') WHERE NewsID=" + NewsID; db.ExecSql(); FileSys.delFile(imgsrc); Response.Write("ok"); Response.End(); } else { string sql = "SELECT * FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; try { SQLHelper_ db = new SQLHelper_(); db.sql = sql; DataTable dt = db.Get_DataTable(); if (dt.Rows.Count > 0) { string title = dt.Rows[0]["title"].ToString(); string newsBody = dt.Rows[0]["NewsBody"].ToString(); string pic = dt.Rows[0]["pic"].ToString(); string addTime = dt.Rows[0]["addTime"].ToString(); string picSmall = dt.Rows[0]["picSmall"].ToString(); string desc = dt.Rows[0]["Description"].ToString(); string video = dt.Rows[0]["pic"].ToString(); if (addTime.Length > 0) { addTime = Convert.ToDateTime(addTime).ToString("yyyy-MM-dd hh:mm:ss"); } lbid = dt.Rows[0]["lbid"].ToString(); ddlLbid.SelectedValue = lbid; lbname = clsLB.getLbname(lbid); hID.Value = NewsID; //hPic.Value = pic; hSmallPic.Value = picSmall; txtTitle.Text = title; txtAddTime.Text = addTime; FCKeditor1.Value = newsBody; FCKeditor2.Value = desc; FCKeditor3.Value = video; btnAdd.Text = "修改并保存"; lblOper.Text = "修改" + lbname; } } catch (Exception ex) { Response.Write(ex.Message + "<br>" + sql); Response.End(); } } } else { lbname = clsLB.getLbname(lbid); txtAddTime.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); btnAdd.Text = "添加"; lblOper.Text = "添加" + lbname; } //txtStar.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); //txtStudentCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); //txtStudentTotalCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); } }
protected void btnAdd_Click(object sender, EventArgs e) { string lbid = ddlLbid.SelectedValue; string id = hID.Value; string title = pg.GetSafeString(txtTitle.Text); string video = FCKeditor3.Value; //string oldPic = hPic.Value; //string newPic = hPic_new.Value; string oldSmallPic = hSmallPic.Value; string newsBody = pg.GetSafeString(FCKeditor1.Value).Replace("\"", "''"); string desc = pg.GetSafeString(FCKeditor2.Value).Replace("\"", "''"); string pic = "", picSmall = hSmallPic_new.Value; string addtime = pg.GetSafeString(txtAddTime.Text); //pic = oldPic + newPic; pic = pic.Replace("||", "|"); string sql = ""; if (id.Length > 0) { if (picSmall == "") { //未上传小图 picSmall = oldSmallPic; } else { //已上传小图并且原来有图 if (picSmall != "" && oldSmallPic != "") { //删除旧图 FileSys.delFile(oldSmallPic); } } //修改 sql = "UPDATE News SET lbid=" + lbid + ",Title='" + title + "',pic = '" + video + "',Description='" + desc + "',AddTime='" + addtime + "',picSmall='" + picSmall + "',NewsBody='" + newsBody + "',Editor='" + Session["AdminName"].ToString() + "',EditTime=getdate() WHERE NewsID=" + id; SQLHelper_ db = new SQLHelper_(); db.sql = sql; string result = db.ExecSql(); if (result == "1") { //删除旧文件 //if (picSmall != oldPic) //{ // FileSys.delFile(oldPic); //} alert.showAndGo("修改成功", "News.aspx?lbid=" + lbid); } else { //alert.ShowAndBack(Page, "修改失败"); Response.Write(result + ",sql=" + sql); Response.End(); } } else { //添加 string newsid = clsNews.MaxNewsid(); sql = "INSERT INTO News(NewsID,lbid,Title,pic,Description,AddTime,picSmall,NewsBody,Creator) VALUES(" + newsid + "," + lbid + ",'" + title + "','" + video + "','" + desc + "','" + addtime + "','" + picSmall + "','" + newsBody + "','" + Session["AdminName"].ToString() + "')"; SQLHelper_ db = new SQLHelper_(); db.sql = sql; string result = db.ExecSql(); if (result == "1") { alert.showAndGo("添加成功", "News.aspx?lbid=" + lbid); } else { //Response.Write(sql); alert.ShowAndBack(Page, "添加失败" + result); } } }
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e) { lbid = hlbid.Value; System.Web.UI.WebControls.Button btn = e.CommandSource as System.Web.UI.WebControls.Button; if (btn == null) { return; } int index = ((System.Web.UI.WebControls.GridViewRow)btn.Parent.Parent).RowIndex; DataKey key = this.GV.DataKeys[index]; string NewsID = key.Value.ToString(); GridViewRow gvr = GV.Rows[index]; if (e.CommandName == "upFile") { //寻找上传控件 FileUpload fu_small = (FileUpload)gvr.FindControl("FileUpload2"); //缩略图 FileUpload fu = (FileUpload)gvr.FindControl("FileUpload1"); //原图 string pic = "", picSmall = ""; //上传图片 pic = UpFile(fu); //上传图片 //picSmall = UpFile(fu_small); if (pic != "") { picSmall = pic.ToLower().Replace(".jpg", "_s.jpg"); SQLHelper db = new SQLHelper(); //删除原图 db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; string pic0 = db.Get_DataTable().Rows[0][0].ToString(); if (pic0.Length > 0) { FileSys.delFile(pic0); } //更新数据库 db.sql = "UPDATE News SET pic='" + pic + "' WHERE NewsID=" + NewsID; db.ExecSql(); bindGv(); alert.Show(Page, "图片更新成功"); } if (picSmall != "") { SQLHelper db = new SQLHelper(); //删除原图 db.sql = "SELECT picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; string pic0 = db.Get_DataTable().Rows[0][0].ToString(); if (pic0.Length > 0) { FileSys.delFile(pic0); } //更新数据库 db.sql = "UPDATE News SET picSmall='" + picSmall + "' WHERE NewsID=" + NewsID; db.ExecSql(); bindGv(); alert.Show(Page, "图片更新成功"); } } if (e.CommandName == "Save") { //查找 title控件 TextBox txtTitle = null; try { txtTitle = this.GV.Rows[index].Cells[1].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到标题控件"); return; } TextBox txtEditTime = null; try { txtEditTime = this.GV.Rows[index].Cells[2].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到标题控件"); return; } //FileUpload fu_small = gvr.Cells[4].FindControl("FileUpload2") as FileUpload;//缩略图 FileUpload fu = gvr.Cells[4].FindControl("FileUpload1") as FileUpload; string title = pg.GetSafeString(txtTitle.Text.Trim()); string EditTime = pg.GetSafeString(txtEditTime.Text.Trim()); if (title == "") { alert.Show(Page, "请填写标题"); return; } if (EditTime == "") { EditTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); } string pic = UpFile(fu), picSmall = ""; if (pic != "") { picSmall = pic.ToLower().Replace(".jpg", "_s.jpg"); } SQLHelper db = new SQLHelper(); if (NewsID.Length > 0) { //取出旧图 string oldPic = "", oldPicSmall = ""; db.sql = "SELECT pic,picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; DataTable dt = db.Get_DataTable(); if (dt.Rows.Count > 0) { oldPic = dt.Rows[0]["pic"].ToString(); oldPicSmall = dt.Rows[0]["picSmall"].ToString(); } //更新 string sql = "UPDATE News SET title='" + title + "',editTime='" + EditTime + "'"; if (pic.Length > 0) { sql += " ,pic='" + pic + "'"; FileSys.delFile(oldPic); } if (picSmall.Length > 0) { sql += " ,picSmall='" + picSmall + "'"; FileSys.delFile(oldPicSmall); } sql += " WHERE NewsID=" + NewsID; db.sql = sql; if (db.ExecSql() != "1") { alert.Show(Page, "保存失败"); } else { GV.EditIndex = -1; bindGv(); } } else { //添加 NewsID = clsNews.MaxNewsid(); db.sql = "INSERT INTO News(ParentNewsID,NewsID,title,pic,picSmall,EditTime,AddTime) VALUES(" + lbid + "," + NewsID + ",'" + title + "','" + pic + "','" + picSmall + "','" + EditTime + "',getdate())"; if (db.ExecSql() != "1") { alert.Show(Page, "添加失败"); } else { GV.EditIndex = -1; bindGv(); } } } }
protected void Page_Load(object sender, EventArgs e) { com.adminLogin(); if (!IsPostBack) { string NewsID = pg.request("id"); pid = pg.request("pid"); pname = clsLB.getLbname(pid); lblPname.Text = pname; hPid.Value = pid; bindLbList(); bindFunctionList(); if (NewsID != "") { string act = pg.request("act"); if (act == "delpic") { //由前台的jquery异步调用 string imgsrc = pg.request("imgsrc"); SQLHelper db = new SQLHelper(); db.sql = "UPDATE News SET pic = replace(pic,'" + imgsrc + "','') WHERE NewsID=" + NewsID; db.ExecSql(); db.sql = "UPDATE News SET pic = replace(pic,'||','|') WHERE NewsID=" + NewsID; db.ExecSql(); FileSys.delFile(imgsrc); Response.Write("ok"); Response.End(); } else { string sql = "SELECT * FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; try { SQLHelper db = new SQLHelper(); db.sql = sql; DataTable dt = db.Get_DataTable(); if (dt.Rows.Count > 0) { string title = dt.Rows[0]["title"].ToString(); string bianhao = dt.Rows[0]["pro_bianhao"].ToString(); string mianliao = dt.Rows[0]["pro_mianliao"].ToString(); string newsBody = dt.Rows[0]["NewsBody"].ToString(); string desc = dt.Rows[0]["Description"].ToString(); string pic = dt.Rows[0]["pic"].ToString(); string addTime = dt.Rows[0]["addTime"].ToString(); string picSmall = dt.Rows[0]["picSmall"].ToString(); if (addTime.Length > 0) { addTime = Convert.ToDateTime(addTime).ToString("yyyy-MM-dd hh:mm:ss"); } lbid = dt.Rows[0]["lbid"].ToString(); lbList.SelectedValue = lbid; //lbname = clsLB.getLbname(lbid); hID.Value = NewsID; hPic.Value = pic; hSmallPic.Value = picSmall; txtTitle.Text = title; tbxBianhao.Text = bianhao; tbxMianliao.Text = mianliao; txtAddTime.Text = addTime; tbxBody.Text = newsBody; tbxSize.Text = desc; string func = dt.Rows[0]["pro_function"].ToString(); string[] funcArr = func.Split(','); for (int i = 0; i < functionList.Items.Count; i++) { foreach (string fun in funcArr) { if (functionList.Items[i].Value == fun) { functionList.Items[i].Selected = true; } } } btnAdd.Text = "修改并保存"; lblOper.Text = "修改" + lbname; } } catch (Exception ex) { Response.Write(ex.Message + "<br>" + sql); Response.End(); } } } else { txtAddTime.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); btnAdd.Text = "添加"; lblOper.Text = "添加" + lbname; } //txtStar.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); //txtStudentCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); //txtStudentTotalCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); } }
protected void btnAdd_Click(object sender, EventArgs e) { lbid = lbList.SelectedValue; string id = hID.Value; string title = pg.GetSafeString(txtTitle.Text); string bianhao = tbxBianhao.Text.Trim(); string mianliao = tbxMianliao.Text.Trim(); string oldPic = hPic.Value; string newPic = hPic_new.Value; string oldSmallPic = hSmallPic.Value; string newsBody = pg.GetSafeString(tbxBody.Text).Replace("\"", "''"); string size = pg.GetSafeString(tbxSize.Text).Replace("\"", "''"); string pic, picSmall = hSmallPic_new.Value; string addtime = pg.GetSafeString(txtAddTime.Text); string pid = hPid.Value; string func = ","; foreach (ListItem li in functionList.Items) { if (li.Selected == true) { func += "," + li.Value; } } if (func != ",") { func = func.Replace(",,", ""); } pic = oldPic + newPic; pic = pic.Replace("||", "|"); string sql = ""; if (id.Length > 0) { if (picSmall == "") { //未上传小图 picSmall = oldSmallPic; } else { //已上传小图并且原来有图 if (picSmall != "" && oldSmallPic != "") { //删除旧图 FileSys.delFile(oldSmallPic); } } //修改 sql = "UPDATE News SET lbid=" + lbid + ", Title='" + title + "',pro_mianliao='" + mianliao + "',pro_bianhao='" + bianhao + "',picSmall='" + picSmall + "',AddTime='" + addtime + "',Description='" + size + "',NewsBody='" + newsBody + "',Editor='" + Session["AdminName"].ToString() + "',EditTime=getdate(),pro_function='" + func + "' WHERE NewsID=" + id; SQLHelper db = new SQLHelper(); db.sql = sql; if (db.ExecSql() == "1") { //删除旧文件 //if (picSmall != oldPic) //{ // FileSys.delFile(oldPic); //} alert.showAndGo("修改成功", "Prod.aspx?pid=" + pid); } else { //alert.ShowAndBack(Page, "修改失败"); Response.Write(sql); Response.End(); } } else { //添加 string newsid = clsNews.MaxNewsid(); sql = "INSERT INTO News(NewsID,lbid,Description,Title,picSmall,pro_bianhao,pro_mianliao,AddTime,pro_function,NewsBody,Creator) VALUES(" + newsid + "," + lbid + ",'" + size + "','" + title + "','" + picSmall + "','" + bianhao + "','" + mianliao + "','" + addtime + "','" + func + "','" + newsBody + "','" + Session["AdminName"].ToString() + "')"; SQLHelper db = new SQLHelper(); db.sql = sql; string result = db.ExecSql(); if (result == "1") { alert.showAndGo("添加成功", "Prod.aspx?pid=" + pid); } else { //Response.Write(sql); alert.ShowAndBack(Page, "添加失败" + result); } } }
protected void Page_Load(object sender, EventArgs e) { com.adminLogin(); if (!IsPostBack) { string id = pg.request("id"); NewsID = id; pid = pg.request("pid"); if (pid.Length > 0) { pname = clsLB.getLbname(pid); lblPname.Text = pname; hPid.Value = pid; } string act = pg.request("act"); if (act == "delpic") { //由前台的jquery异步调用 string imgsrc = pg.request("imgsrc"); try { DXProd pd = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(id) select pro).First <DXProd>(); pd.pics = pd.pics.Replace(imgsrc, ""); pd.pics = pd.pics.Replace("||", "|"); dbContext.SubmitChanges(); FileSys.delFile(imgsrc); Response.Write("ok"); } catch (Exception ex) { Response.Write("ERROR: " + ex.Message); } Response.End(); } if (id != "") { pageInit(); } else { lbid = pg.request("lbid"); if (lbid == "") { lbid = "0"; } lbname = clsLB.getLbname(lbid); pid = clsLB.getPid(lbid); bindLbList(Int32.Parse(pid)); txtAddTime.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); btnAdd.Text = "添加"; lblOper.Text = "添加" + lbname; } //txtStar.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); //txtStudentCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); //txtStudentTotalCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}"); } }
protected void btnAdd_Click(object sender, EventArgs e) { lbid = lbList.SelectedValue; string id = hID.Value; string title = pg.GetSafeString(txtTitle.Text); string oldPic = hPic.Value; string newPic = hPic_new.Value; string oldSmallPic = hSmallPic.Value; //string newsBody = pg.GetSafeString(tbxBody.Text).Replace("\"", "''"); string newsBody = FCKeditor1.Value; string pic, picSmall = hSmallPic_new.Value; string addtime = pg.GetSafeString(txtAddTime.Text); string pid = hPid.Value; pic = oldPic + newPic; pic = pic.Replace("||", "|"); string sql = ""; if (id.Length > 0) { if (picSmall == "") { //未上传小图 picSmall = oldSmallPic; } else { //已上传小图并且原来有图 if (picSmall != "" && oldSmallPic != "") { //删除旧图 FileSys.delFile(oldSmallPic); } } DXProd pd = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(id) select pro).First <DXProd>(); pd.lbid = Int32.Parse(lbid); pd.Name = title; pd.pic = pic; pd.picSmall = picSmall; pd.Body = newsBody; pd.EditorName = Session["AdminName"].ToString(); pd.EditTime = DateTime.Now; dbContext.SubmitChanges(); alert.showAndGo("修改成功", "Prod.aspx?lbid=" + lbid); } else { try { //添加 DXProd pd = new DXProd(); pd.lbid = Int32.Parse(lbid); pd.Name = title; pd.pic = pic; pd.picSmall = picSmall; pd.Body = newsBody; pd.CreateTime = DateTime.Now; pd.EditTime = DateTime.Now; pd.CreatorName = Session["AdminName"].ToString(); pd.EditorName = Session["AdminName"].ToString(); dbContext.DXProd.InsertOnSubmit(pd); dbContext.SubmitChanges(); alert.showAndGo("添加成功", "Prod.aspx?lbid=" + lbid); } catch (Exception ex) { alert.ShowAndBack(Page, "添加失败" + ex.Message); } } }
protected void Page_Load(object sender, EventArgs e) { com.adminLogin(); if (!IsPostBack) { string lbid = pg.request("lbid"); if (lbid != "") { lbname = clsLB.getLbname(lbid); hlbid.Value = lbid; } string act = pg.request("act"); if (act == "top") { //置顶 db.ExecSql("UPDATE News SET isTop=0 WHERE lbid=" + lbid); db.ExecSql("UPDATE News SET isTop=1 WHERE NewsID=" + pg.request("id")); alert.showAndGo("设置成功", "news.aspx?lbid=" + lbid); return; } if (act == "IsIndex") { //置顶 db.ExecSql("UPDATE News SET IsIndex=" + pg.request("value") + " WHERE NewsID=" + pg.request("id")); alert.showAndGo("设置成功", "news.aspx?lbid=" + lbid); return; } if (act == "del") { string id = pg.request("id"); SQLHelper db = new SQLHelper(); db.sql = "SELECT pic,picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + id; DataTable dt = db.Get_DataTable(); if (dt.Rows.Count > 0) { //string pic = dt.Rows[0]["pic"].ToString(); //if (pic.Length > 0) //{ // string[] pics = pic.Split('|'); // foreach (string p in pics) // { // if (p.Length > 0) // File.Delete(Server.MapPath(p)); // } //} string picSmall = dt.Rows[0]["picSmall"].ToString(); if (picSmall.Length > 0) { File.Delete(Server.MapPath(picSmall)); } //删除大图 //删除相册中的照片 db.sql = @"SELECT * FROM " + com.tablePrefix + "News WHERE ParentNewsID=" + id; dt = new DataTable(); dt = db.Get_DataTable(); foreach (DataRow dr in dt.Rows) { string pic = dr["pic"].ToString().ToLower(); FileSys.delFile(pic); FileSys.delFile(pic.Replace(".jpg", "_s.jpg")); } db.sql = "DELETE News WHERE ParentNewsID=" + id; db.ExecSql(); } db.sql = "DELETE FROM " + com.tablePrefix + "News WHERE NewsID=" + id; db.ExecSql(); alert.showAndGo("删除成功", "news.aspx?lbid=" + lbid); return; } bindGv(); } }
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e) { lbid = hlbid.Value; System.Web.UI.WebControls.Button btn = e.CommandSource as System.Web.UI.WebControls.Button; if (btn == null) { return; } int index = ((System.Web.UI.WebControls.GridViewRow)btn.Parent.Parent).RowIndex; DataKey key = this.GV.DataKeys[index]; string NewsID = key.Value.ToString(); GridViewRow gvr = GV.Rows[index]; if (e.CommandName == "upFile") { //寻找上传控件 FileUpload fu = (FileUpload)gvr.FindControl("FileUpload1"); if (fu != null) { if (fu.HasFile) { SQLHelper db = new SQLHelper(); //上传图片 string pic = UpFile(fu); //删除原图 db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID; string pic0 = db.Get_DataTable().Rows[0][0].ToString(); if (pic0.Length > 0) { FileSys.delFile(pic0); } //更新数据库 db.sql = "UPDATE News SET pic='" + pic + "' WHERE NewsID=" + NewsID; db.ExecSql(); bindGv(); alert.Show(Page, "图片更新成功"); } } } if (e.CommandName == "Save") { //查找 title控件 TextBox txtTitle = null; try { txtTitle = this.GV.Rows[index].Cells[1].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到标题控件"); return; } TextBox txtEditTime = null; try { txtEditTime = this.GV.Rows[index].Cells[2].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到日期控件"); return; } TextBox txtVideoUrl = null; try { txtVideoUrl = this.GV.Rows[index].Cells[5].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到视频路径控件"); return; } TextBox txtDescription = null; try { txtDescription = this.GV.Rows[index].Cells[6].Controls[0] as TextBox; } catch { alert.Show(Page, "未找到视频描述控件"); return; } FileUpload fu = gvr.Cells[4].FindControl("FileUpload1") as FileUpload; string title = pg.GetSafeString(txtTitle.Text.Trim()); string EditTime = pg.GetSafeString(txtEditTime.Text.Trim()); string VideoUrl = pg.GetSafeString(txtVideoUrl.Text.Trim()); string Description = pg.GetSafeString(txtDescription.Text.Trim()); if (title == "") { //alert.ShowAndBack(Page, "请填写标题"); alert.Show(Page, "请填写标题"); return; } if (EditTime == "") { EditTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); } if (VideoUrl == "") { alert.Show(Page, "请填写视频路径"); return; } if (Description.Length > 500) { alert.Show(Page, "视频简介不能超过500字"); return; } string pic = UpFile(fu); SQLHelper db = new SQLHelper(); if (NewsID.Length > 0) { //更新 if (pic.Length > 0) { db.sql = "UPDATE News SET title='" + title + "',pic='" + pic + "',editTime='" + EditTime + "',VideoUrl='" + VideoUrl + "',Description='" + Description + "' WHERE NewsID=" + NewsID; } else { db.sql = "UPDATE News SET title='" + title + "',editTime='" + EditTime + "',VideoUrl='" + VideoUrl + "',Description='" + Description + "' WHERE NewsID=" + NewsID; } string result = db.ExecSql(); if (result != "1") { Response.Write(result + db.sql); Response.End(); //alert.Show(Page, "保存失败"); } else { GV.EditIndex = -1; bindGv(); } } else { //添加 NewsID = clsNews.MaxNewsid(); db.sql = "INSERT INTO News(lbid,NewsID,title,pic,EditTime,AddTime,VideoUrl,Description) VALUES(" + lbid + "," + NewsID + ",'" + title + "','" + pic + "','" + EditTime + "',getdate(),'" + VideoUrl + "','" + Description + "')"; if (db.ExecSql() != "1") { alert.Show(Page, "添加失败"); } else { GV.EditIndex = -1; bindGv(); } } } }