//删除操作 protected void List_RowDeleting(object sender, GridViewDeleteEventArgs e) { int zhuanTiId = Int32.Parse(List.DataKeys[e.RowIndex].Value.ToString()); ZhuanTiEntity zhuanTi = ZhuanTiAccess.GetZhuanTiListById(zhuanTiId, userId); zhuanTi.ZhuanTiLive = 0; zhuanTi.Synchronize = 1; bool success = ZhuanTiAccess.DeleteZhuanTi(zhuanTiId, userId); if (success) { success = ZhuanTiAccess.UpdateZhuanTi(zhuanTi); if (success) { Utility.Alert(this, "删除成功。"); List.EditIndex = -1; BindGrid(); } } else { Utility.Alert(this, "删除失败!"); } }
//取专题列表根据专题ID// public static ZhuanTiEntity GetZhuanTiListById(int zhuanTiId, int userId) { DbCommand comm = GenericDataAccess.CreateCommand(); comm.CommandText = "GetZhuanTiListById_v4"; DbParameter param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiID"; param.Value = zhuanTiId; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@UserID"; param.Value = userId; param.DbType = DbType.Int32; comm.Parameters.Add(param); ZhuanTiEntity zhuanTi = new ZhuanTiEntity(); DataTable dt = GenericDataAccess.ExecuteCommand(comm); if (dt.Rows.Count > 0) { zhuanTi.ZhuanTiID = Int32.Parse(dt.Rows[0]["ZTID"].ToString()); zhuanTi.ZhuanTiName = dt.Rows[0]["ZhuanTiName"].ToString(); zhuanTi.ZhuanTiImage = dt.Rows[0]["ZhuanTiImage"].ToString(); zhuanTi.ZhuanTiLive = Int32.Parse(dt.Rows[0]["ZhuanTiLive"].ToString()); zhuanTi.Synchronize = Int32.Parse(dt.Rows[0]["Synchronize"].ToString()); zhuanTi.ZhuanTiDate = dt.Rows[0]["ZhuanTiDate"].ToString(); zhuanTi.ZhuanTiShouRu = Double.Parse(dt.Rows[0]["ZhuanTiShouRu"].ToString()); zhuanTi.ZhuanTiZhiChu = Double.Parse(dt.Rows[0]["ZhuanTiZhiChu"].ToString()); } return(zhuanTi); }
//添加操作 protected void Button1_Click(object sender, EventArgs e) { string zhuanTiImage = ""; if (this.ZhuanTiImageIns.HasFile) { string imageExt = ImageHelper.GetImageExt(this.ZhuanTiImageIns.FileName); if (imageExt != ".jpg" && imageExt != ".png" && imageExt != ".bmp" && imageExt != ".gif") { Utility.Alert(this, "图片文件格式不支持!"); return; } zhuanTiImage = "zt_" + userId + "_" + Utility.GetRandomNumber(1000, 9999) + imageExt; string imagePath = Server.MapPath("/Images/ZhuanTi/") + zhuanTiImage; try { this.ZhuanTiImageIns.SaveAs(imagePath); ImageHelper.SaveImage(imagePath, 200, 200); } catch { Utility.Alert(this, "专题图片上传失败!"); return; } } else { Utility.Alert(this, "专题图片未选择!"); return; } string zhuanTiName = this.ZhuanTiNameIns.Text.Trim(); if (zhuanTiName == "") { Utility.Alert(this, "专题名称未填写!"); return; } ZhuanTiEntity zhuanTi = new ZhuanTiEntity(); zhuanTi.ZhuanTiName = zhuanTiName; zhuanTi.ZhuanTiImage = zhuanTiImage; zhuanTi.ZhuanTiLive = 1; zhuanTi.Synchronize = 1; zhuanTi.UserID = userId; bool success = ZhuanTiAccess.InsertZhuanTi(zhuanTi); if (success) { Utility.Alert(this, "添加成功。", "UserZhuanTi.aspx"); } else { Utility.Alert(this, "添加失败!"); } }
//更新专题// public static bool UpdateZhuanTi(ZhuanTiEntity zhuanTi) { DbCommand comm = GenericDataAccess.CreateCommand(); comm.CommandText = "UpdateZhuanTi_v4"; DbParameter param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiName"; param.Value = zhuanTi.ZhuanTiName; param.DbType = DbType.String; param.Size = 20; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiImage"; param.Value = zhuanTi.ZhuanTiImage; param.DbType = DbType.String; param.Size = 200; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiID"; param.Value = zhuanTi.ZhuanTiID; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiLive"; param.Value = zhuanTi.ZhuanTiLive; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@Synchronize"; param.Value = zhuanTi.Synchronize; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@UserID"; param.Value = zhuanTi.UserID; param.DbType = DbType.Int32; comm.Parameters.Add(param); int result = -1; try { result = GenericDataAccess.ExecuteNonQuery(comm); } catch { } return(result != -1); }
protected void BindGrid() { DataTable dt = ZhuanTiAccess.GetZhuanTiListDetail(zhuanTiId, userId); List.DataSource = dt; List.DataBind(); ZhuanTiEntity zhuanTi = ZhuanTiAccess.GetZhuanTiListById(zhuanTiId, userId); this.ZhuanTiDate.Text = zhuanTi.ZhuanTiDate; this.ZhuanTiShouRu.Text = zhuanTi.ZhuanTiShouRu.ToString("0.0##"); this.ZhuanTiZhiChu.Text = zhuanTi.ZhuanTiZhiChu.ToString("0.0##"); }
protected void Page_Load(object sender, EventArgs e) { int ztId = Int32.Parse(Request.Form["ztid"].ToString()); string ztName = Request.Form["ztname"].ToString(); string ztImage = Request.Form["ztimage"].ToString(); int ztLive = Int32.Parse(Request.Form["ztlive"].ToString()); int userId = Int32.Parse(Request.Form["userid"].ToString()); ZhuanTiEntity zhuanTi = new ZhuanTiEntity(); zhuanTi.ZhuanTiID = ztId; zhuanTi.ZhuanTiName = ztName; zhuanTi.ZhuanTiImage = ztImage; zhuanTi.UserID = userId; zhuanTi.ZhuanTiLive = ztLive; zhuanTi.Synchronize = 0; bool success = SyncHelper.SyncCheckZhuanTiIsExists(ztId, userId); if (success) { success = SyncHelper.SyncZhuanTiUpdate(zhuanTi); } else { success = SyncHelper.SyncZhuanTiInsert(zhuanTi); } string result = "{"; if (success) { result += "\"result\":\"ok\""; } else { result += "\"result\":\"error\""; } result += "}"; Response.Write(result); Response.End(); }
//更新专题// public static bool SyncZhuanTiUpdate(ZhuanTiEntity zhuanTi) { DbCommand comm = GenericDataAccess.CreateCommand(); comm.CommandText = "SyncZhuanTiUpdate_v4"; DbParameter param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiID"; param.Value = zhuanTi.ZhuanTiID; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiName"; param.Value = zhuanTi.ZhuanTiName; param.DbType = DbType.String; param.Size = 20; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiImage"; param.Value = zhuanTi.ZhuanTiImage; param.DbType = DbType.String; param.Size = 200; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@UserID"; param.Value = zhuanTi.UserID; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiLive"; param.Value = zhuanTi.ZhuanTiLive; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@Synchronize"; param.Value = zhuanTi.Synchronize; param.DbType = DbType.Int32; comm.Parameters.Add(param); int result = -1; try { result = GenericDataAccess.ExecuteNonQuery(comm); } catch { } return (result != -1); }
//取专题列表根据专题ID// public static ZhuanTiEntity GetZhuanTiListById(int zhuanTiId, int userId) { DbCommand comm = GenericDataAccess.CreateCommand(); comm.CommandText = "GetZhuanTiListById_v4"; DbParameter param = comm.CreateParameter(); param.ParameterName = "@ZhuanTiID"; param.Value = zhuanTiId; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@UserID"; param.Value = userId; param.DbType = DbType.Int32; comm.Parameters.Add(param); ZhuanTiEntity zhuanTi = new ZhuanTiEntity(); DataTable dt = GenericDataAccess.ExecuteCommand(comm); if (dt.Rows.Count > 0) { zhuanTi.ZhuanTiID = Int32.Parse(dt.Rows[0]["ZTID"].ToString()); zhuanTi.ZhuanTiName = dt.Rows[0]["ZhuanTiName"].ToString(); zhuanTi.ZhuanTiImage = dt.Rows[0]["ZhuanTiImage"].ToString(); zhuanTi.ZhuanTiLive = Int32.Parse(dt.Rows[0]["ZhuanTiLive"].ToString()); zhuanTi.Synchronize = Int32.Parse(dt.Rows[0]["Synchronize"].ToString()); zhuanTi.ZhuanTiDate = dt.Rows[0]["ZhuanTiDate"].ToString(); zhuanTi.ZhuanTiShouRu = Double.Parse(dt.Rows[0]["ZhuanTiShouRu"].ToString()); zhuanTi.ZhuanTiZhiChu = Double.Parse(dt.Rows[0]["ZhuanTiZhiChu"].ToString()); } return zhuanTi; }
//更新操作 protected void List_RowUpdating(object sender, GridViewUpdateEventArgs e) { int zhuanTiId = Int32.Parse(List.DataKeys[e.RowIndex].Value.ToString()); string zhuanTiImage = ((HiddenField)List.Rows[e.RowIndex].FindControl("ZhuanTiImageHid")).Value; FileUpload zhuanTiImageUpload = (FileUpload)List.Rows[e.RowIndex].FindControl("ZhuanTiImageUpload"); if (zhuanTiImageUpload.HasFile) { string imageExt = ImageHelper.GetImageExt(zhuanTiImageUpload.FileName); string imageName = ImageHelper.GetImageName(zhuanTiImage); if (imageExt != ".jpg" && imageExt != ".png" && imageExt != ".bmp" && imageExt != ".gif") { Utility.Alert(this, "图片文件格式不支持!"); return; } if (imageName == "none") { imageName = "zt_" + userId + "_" + Utility.GetRandomNumber(1000, 9999); } zhuanTiImage = imageName + imageExt; string imagePath = Server.MapPath("/Images/ZhuanTi/") + zhuanTiImage; try { zhuanTiImageUpload.SaveAs(imagePath); ImageHelper.SaveImage(imagePath, 200, 200); } catch { Utility.Alert(this, "专题图片上传失败!"); return; } } TextBox zhuanTiNameBox = (TextBox)List.Rows[e.RowIndex].FindControl("ZhuanTiNameBox"); string zhuanTiName = zhuanTiNameBox.Text.Trim(); if (zhuanTiName == "") { Utility.Alert(this, "专题名称未填写!"); return; } ZhuanTiEntity zhuanTi = ZhuanTiAccess.GetZhuanTiListById(zhuanTiId, userId); zhuanTi.ZhuanTiImage = zhuanTiImage; zhuanTi.ZhuanTiName = zhuanTiName; zhuanTi.UserID = userId; bool success = ZhuanTiAccess.UpdateZhuanTi(zhuanTi); if (success) { Utility.Alert(this, "更新成功。"); List.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "更新失败!"); } }