/// <summary> /// /// </summary> /// <param name="count"></param> /// <param name="sTime"></param> /// <param name="eTime"></param> /// <returns></returns> public List<HairEngineerComment> GetHairEngineerCommentsByTimeZone(int count, string sTime, string eTime) { List<HairEngineerComment> list = new List<HairEngineerComment>(); string commText = string.Empty; switch (count) { case 0: commText = "select * from HairEngineerComment where HairEngineerCommentCreateTime > '"+sTime+"' and HairEngineerCommentCreateTime<'"+eTime+"' order by HairEngineerCommentID desc"; break; default: commText = "select top " + count.ToString() + " * from HairEngineerComment where HairEngineerCommentCreateTime > '" + sTime + "' and HairEngineerCommentCreateTime<'" + eTime + "' order by HairEngineerCommentID desc"; break; } using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commText; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { while (sdr.Read()) { HairEngineerComment hairEngineerComment = new HairEngineerComment(); hairEngineerComment.CommentCreateTime = Convert.ToDateTime(sdr["HairEngineerCommentCreateTime"].ToString()); hairEngineerComment.CommentID = int.Parse(sdr["HairEngineerCommentID"].ToString()); hairEngineerComment.CommentText = sdr["HairEngineerCommentText"].ToString(); hairEngineerComment.HairEngineerID = int.Parse(sdr["HairEngineerID"].ToString()); hairEngineerComment.UserAddress = sdr["UserAddress"].ToString(); hairEngineerComment.UserID = int.Parse(sdr["UserID"].ToString()); hairEngineerComment.UserName = sdr["UserName"].ToString(); hairEngineerComment.IsGood = Convert.ToBoolean(sdr["IsGood"].ToString()); list.Add(hairEngineerComment); } } } } } return list; }
/// <summary> /// ��ȡ����ʦ�����б� /// </summary> /// <param name="userID"></param> /// <param name="count"></param> /// <param name="orderKey">����KEY ����ʱ�������պ�������������ʦ����</param> /// <returns></returns> public List<HairEngineerComment> GetHairEngineerCommentsByUserID(int userID, int count, OrderKey ok) { List<HairEngineerComment> list = new List<HairEngineerComment>(); string orderKey = " order by "; switch (ok) { case OrderKey.Good: orderKey += "IsGood desc"; break; case OrderKey.ID: orderKey += "HairEngineerID desc"; break; case OrderKey.Time: orderKey += "HairEngineerCommentCreateTime desc"; break; default: orderKey += "HairEngineerCommentID desc"; break; } string commText = string.Empty; switch (count) { case 0: commText = "select * from HairEngineerComment where UserID=" + userID.ToString() + orderKey; break; default: commText = "select top " + count.ToString() + " * from HairEngineerComment where UserID=" + userID.ToString() + orderKey; break; } using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commText; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { while (sdr.Read()) { HairEngineerComment hairEngineerComment = new HairEngineerComment(); hairEngineerComment.CommentCreateTime = Convert.ToDateTime(sdr["HairEngineerCommentCreateTime"].ToString()); hairEngineerComment.CommentID = int.Parse(sdr["HairEngineerCommentID"].ToString()); hairEngineerComment.CommentText = sdr["HairEngineerCommentText"].ToString(); hairEngineerComment.HairEngineerID = int.Parse(sdr["HairEngineerID"].ToString()); hairEngineerComment.UserAddress = sdr["UserAddress"].ToString(); hairEngineerComment.UserID = int.Parse(sdr["UserID"].ToString()); hairEngineerComment.UserName = sdr["UserName"].ToString(); hairEngineerComment.IsGood = Convert.ToBoolean(sdr["IsGood"].ToString()); list.Add(hairEngineerComment); } } } } } return list; }
/// <summary> /// ��ȡ����ʦ�����б� /// </summary> /// <param name="hairEngineerComment"></param> /// <param name="ua"></param> /// <returns></returns> public bool HairEngineerCommentCreateDeleteUpdate(HairEngineerComment hairEngineerComment, UserAction ua) { bool result = false; string commandText = string.Empty; switch (ua) { case UserAction.Create: commandText = "insert into HairEngineerComment(HairEngineerCommentText,UserID,UserName,UserAddress,IsGood,HairEngineerCommentCreateTime,HairEngineerID) values('"+hairEngineerComment.CommentText+"',"+hairEngineerComment.UserID.ToString()+",'"+hairEngineerComment.UserName+"','"+hairEngineerComment.UserAddress+"',"+hairEngineerComment.IsGood.CompareTo(false).ToString()+",'"+hairEngineerComment.CommentCreateTime.ToString()+"',"+hairEngineerComment.HairEngineerID.ToString()+")"; break; case UserAction.Delete: commandText = "delete from HairEngineerComment where HairEngineerCommentID = "+hairEngineerComment.CommentID.ToString(); break; case UserAction.Update: commandText = "update HairEngineerComment set HairEngineerCommentText ='"+hairEngineerComment.CommentText+"',UserID="+hairEngineerComment.UserID.ToString()+",UserName='******',UserAddress='"+hairEngineerComment.UserAddress+"',IsGood="+hairEngineerComment.IsGood.CompareTo(false).ToString()+",HairEngineerCommentCreateTime='"+hairEngineerComment.CommentCreateTime.ToString()+"',HairEngineerID="+hairEngineerComment.HairEngineerID.ToString()+" where HairEngineerCommentID="+hairEngineerComment.CommentID.ToString(); break; } using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commandText; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); result = true; } catch (Exception ex) { throw new Exception(ex.Message); } } } return result; }