public JsonResult PublishNewHeart() { //发布心愿采用form方式。。。。 NewHeart newHeart = new NewHeart(); newHeart = Common.JosnDeserialize<NewHeart>(Request.Form["NewHeart"].ToString(), null); string joinerLoginName = Request.Form["joinerLoginName"].ToString(); JsonResult jr = new JsonResult(); jr.ContentType = "text/json"; jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet; if (DBTools.PubNewHeart(newHeart, joinerLoginName)) { jr.Data = new { isSuccess = true }; } else { jr.Data = new { isSuccess = false, errorMessage = "Pub Heart Error" }; } return jr; }
public static List<NewHeart> GetNewMessage(string loginName) { DataTable dt = null; List<NewHeart> list = new List<NewHeart>(); string sql = string.Format(@"select * from ht_userJoin j inner join ht_heartInfo h on j.heartId=h.heartId where joinerLoginName='{0}' and isRead='false' ", loginName); try { dt = SqlHelper.ExecuteDataset(ConnString.GetConString, CommandType.Text, sql.ToString()).Tables[0]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { NewHeart nh = new NewHeart(); nh.Contact = dt.Rows[i]["contact"].ToString(); if (string.IsNullOrEmpty(dt.Rows[i]["endDate"].ToString())) { nh.FinishDate = string.Empty; } else { nh.FinishDate = Convert.ToDateTime(dt.Rows[i]["endDate"].ToString()).ToString("yyyy-MM-dd"); } nh.HeartContent = dt.Rows[i]["content"].ToString(); nh.HeartLevel = int.Parse(dt.Rows[i]["heartLevel"].ToString()); nh.Joiner = dt.Rows[i]["participator"].ToString(); nh.Puber = dt.Rows[i]["pubName"].ToString(); nh.Title = dt.Rows[i]["title"].ToString(); nh.Station = int.Parse(dt.Rows[i]["station"].ToString()); nh.HeartId = int.Parse(dt.Rows[i]["heartId"].ToString()); list.Add(nh); } } } catch { return null; } return list; }
/// <summary> /// 发布心愿 /// </summary> /// <param name="newHeart">心愿内容</param> /// <param name="joinerLoginName">参与者登录名(可选)</param> /// <returns></returns> public static bool PubNewHeart(NewHeart newHeart, string joinerLoginName = "") { try { string sql = string.Format(@"INSERT INTO ht_heartInfo ([title] ,[pubID] ,[pubName] ,[participator] ,[contact] ,[bgImage] ,[content] ,[beginDate] ,[endDate] ,[heartLevel] ,[station] ,[isPrivate]) VALUES (@title ,@pubID ,@pubName ,@participator ,@contact ,@bgImage ,@content ,@beginDate ,@endDate ,@heartLevel ,@station ,@isPrivate)"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar), new SqlParameter("@pubID", SqlDbType.NVarChar), new SqlParameter("@pubName", SqlDbType.NVarChar), new SqlParameter("@participator", SqlDbType.NVarChar), new SqlParameter("@contact", SqlDbType.NVarChar), new SqlParameter("@bgImage", SqlDbType.NVarChar), new SqlParameter("@content", SqlDbType.NVarChar), new SqlParameter("@beginDate", SqlDbType.DateTime), new SqlParameter("@endDate", SqlDbType.DateTime), new SqlParameter("@heartLevel", SqlDbType.Int), new SqlParameter("@station", SqlDbType.Int) , new SqlParameter("@isPrivate", SqlDbType.Int) }; parameters[0].Value = newHeart.Title; parameters[1].Value = newHeart.PubId; parameters[2].Value = newHeart.Puber; parameters[3].Value = newHeart.Joiner; parameters[4].Value = newHeart.Contact; parameters[5].Value = 1;//newHeart.bgimage; parameters[6].Value = newHeart.HeartContent; parameters[7].Value = DateTime.Now; parameters[8].Value = newHeart.FinishDate == "" ? null : newHeart.FinishDate; parameters[9].Value = newHeart.HeartLevel; parameters[10].Value = 0;//newHeart.station; parameters[11].Value = newHeart.IsPrivate; object o = SqlHelper.ExecuteNonQuery(ConnString.GetConString, CommandType.Text, sql, parameters); //获取heartId string sql_maxId = "select max( heartId) from ht_heartInfo "; object id = SqlHelper.ExecuteScalar(ConnString.GetConString, CommandType.Text, sql_maxId); //绑定参与关系 BindUserJoin(int.Parse(id.ToString()), newHeart.PubId, newHeart.Joiner, joinerLoginName); } catch (Exception) { return false; } return true; }
/// <summary> /// 根据登录名获取心愿信息 /// </summary> /// <param name="loginName">登录名</param> /// <returns></returns> public static List<NewHeart> GetHeartsByLoginName(string loginName) { DataTable dt = null; List<NewHeart> list = new List<NewHeart>(); string sql = " select * from ht_heartInfo where pubId='" + loginName + "' order by heartId desc"; try { dt = SqlHelper.ExecuteDataset(ConnString.GetConString, CommandType.Text, sql.ToString()).Tables[0]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { NewHeart nh = new NewHeart(); nh.Contact = dt.Rows[i]["contact"].ToString(); if (string.IsNullOrEmpty(dt.Rows[i]["endDate"].ToString())) { nh.FinishDate = string.Empty; } else { nh.FinishDate = Convert.ToDateTime(dt.Rows[i]["endDate"].ToString()).ToString("yyyy-MM-dd"); } nh.HeartContent = dt.Rows[i]["content"].ToString(); nh.HeartLevel = int.Parse(dt.Rows[i]["heartLevel"].ToString()); nh.Joiner = dt.Rows[i]["participator"].ToString(); nh.Puber = dt.Rows[i]["pubName"].ToString(); nh.Title = dt.Rows[i]["title"].ToString(); nh.Station = int.Parse(dt.Rows[i]["station"].ToString()); nh.HeartId = int.Parse(dt.Rows[i]["heartId"].ToString()); list.Add(nh); } } } catch { return null; } return list; }