/// <summary> /// 更新一条数据 /// </summary> public bool Update(ExchangeVoteEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update sns_exchangeVote set "); strSql.Append("UserId=@UserId,"); strSql.Append("ExId=@ExId,"); strSql.Append("AddTime=@AddTime,"); strSql.Append("Status=@Status"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@ExId", SqlDbType.VarChar, 50), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.ExId; parameters[2].Value = model.AddTime; parameters[3].Value = model.Status; parameters[4].Value = model.Id; int rows = SqlHelper.Instance.ExecSqlNonQuery(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ExchangeVoteEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into sns_exchangeVote("); strSql.Append("UserId,ExId,AddTime,Status)"); strSql.Append(" values ("); strSql.Append("@UserId,@ExId,@AddTime,@Status)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@ExId", SqlDbType.VarChar, 50), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@Status", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.ExId; parameters[2].Value = model.AddTime; parameters[3].Value = model.Status; object obj = SqlHelper.Instance.ExecSqlScalar(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ExchangeVoteEntity DataRowToModel(DataRow row) { ExchangeVoteEntity model = new ExchangeVoteEntity(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["UserId"] != null) { model.UserId = row["UserId"].ToString(); } if (row["ExId"] != null) { model.ExId = row["ExId"].ToString(); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ExchangeVoteEntity model) { try { return(ExchangeVoteDb.Instance.Update(model)); } catch (System.Exception ex) { WriteLog.WriteError(ex); throw ex; } }
public void ProcessRequest(HttpContext context) { string index = context.Request.Form["Index"]; string id = context.Request.Form["Id"]; string userId = context.Request.Form["UserId"]; string s = ""; DataTable exTable = ExchangeVoteBll.Instance.GetList($"UserId='{userId}' AND ExId='{id}'").Tables[0]; if (exTable.Rows.Count > 0) { s = "{\"status\":\"已参与\"}"; } else { ExchangeEntity exchangeEntity = ExchangeBll.Instance.GetModel(int.Parse(id)); switch (index) { case "1": exchangeEntity.Vote1 = exchangeEntity.Vote1 + 1; break; case "2": exchangeEntity.Vote2 = exchangeEntity.Vote2 + 1; break; case "3": exchangeEntity.Vote3 = exchangeEntity.Vote3 + 1; break; } if (ExchangeBll.Instance.Update(exchangeEntity)) { ExchangeVoteEntity exchangeVoteEntity = new ExchangeVoteEntity(); exchangeVoteEntity.UserId = userId; exchangeVoteEntity.ExId = id; exchangeVoteEntity.AddTime = DateTime.Now; exchangeVoteEntity.Status = 1; if (ExchangeVoteBll.Instance.Add(exchangeVoteEntity) > 0) { s = "{\"status\":\"success\"}"; } } else { s = "{\"status\":\"error\"}"; } } context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; context.Response.Write(s); }
public object EvaluationVote(string ind, string eid, string uid) { KeyValuePair <string, string> s = new KeyValuePair <string, string>(); DataTable exTable = ExchangeVoteBll.Instance.GetList($"UserId='{uid}' AND ExId='{eid}'").Tables[0]; if (exTable.Rows.Count > 0) { s = new KeyValuePair <string, string>("status", "已参与"); } else { ExchangeEntity exchangeEntity = ExchangeBll.Instance.GetModel(int.Parse(eid)); switch (ind) { case "1": exchangeEntity.Vote1 = exchangeEntity.Vote1 + 1; break; case "2": exchangeEntity.Vote2 = exchangeEntity.Vote2 + 1; break; case "3": exchangeEntity.Vote3 = exchangeEntity.Vote3 + 1; break; } if (ExchangeBll.Instance.Update(exchangeEntity)) { ExchangeVoteEntity exchangeVoteEntity = new ExchangeVoteEntity(); exchangeVoteEntity.UserId = uid; exchangeVoteEntity.ExId = eid; exchangeVoteEntity.AddTime = DateTime.Now; exchangeVoteEntity.Status = 1; if (ExchangeVoteBll.Instance.Add(exchangeVoteEntity) > 0) { s = new KeyValuePair <string, string>("status", "success"); } } else { s = new KeyValuePair <string, string>("status", "error"); } } return(s); }
/// <summary> /// 得到一个对象实体 /// </summary> public ExchangeVoteEntity GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,UserId,ExId,AddTime,Status from sns_exchangeVote "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; ExchangeVoteEntity model = new ExchangeVoteEntity(); DataSet ds = SqlHelper.Instance.ExecSqlDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }