示例#1
0
        public Guesbooks GetDataById(int Id)
        {
            Guesbooks Data = new Guesbooks();

            string sql = $@"Select * from Guestbooks Where Id = {Id}";

            try
            {
                conn.Open();
                SqlCommand    cmd = new SqlCommand(sql, conn);
                SqlDataReader dr  = cmd.ExecuteReader();
                dr.Read();
                Data.Id         = Convert.ToInt32(dr["Id"]);
                Data.Name       = dr["Name"].ToString();
                Data.Content    = dr["Content"].ToString();
                Data.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                if (!string.IsNullOrWhiteSpace(dr["Reply"].ToString()))
                {
                    Data.Reply     = dr["Reply"].ToString();
                    Data.ReplyTime = Convert.ToDateTime(dr["ReplyTime"]);
                }
            }
            catch (Exception)
            {
                Data = null;
            }
            finally
            {
                conn.Close();
            }
            return(Data);
        }
示例#2
0
 public ActionResult Reply(int Id, [Bind(Include = "Reply,ReplyTime")] Guesbooks ReplyData)
 {
     if (GuestbooksService.CheckUpdate(Id))
     {
         ReplyData.Id = Id;
         GuestbooksService.ReplyGuestbooks(ReplyData);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("Index"));
     }
 }
示例#3
0
 public ActionResult Edit(int Id, [Bind(Include = "Name,Content")] Guesbooks UpdateDate)
 {
     if (GuestbooksService.CheckUpdate(Id))
     {
         UpdateDate.Id = Id;
         GuestbooksService.UpdateGuestboooks(UpdateDate);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("Index"));
     }
 }
示例#4
0
        public List <Guesbooks> GetDataList(string Search)
        {
            List <Guesbooks> DataList = new List <Guesbooks>();
            string           sql      = string.Empty;

            if (!string.IsNullOrWhiteSpace(Search))
            {
                sql = $@"SELECT * FROM Guestbooks WHERE NAME LIKE '%{Search}%' OR Content LIKE '%{Search}%' OR Reply LIKE '%{Search}%' ; ";
            }
            else
            {
                sql = $@"SELECT * FROM Guestbooks";
            }
            try
            {
                conn.Open();
                SqlCommand    cmd = new SqlCommand(sql, conn);
                SqlDataReader dr  = cmd.ExecuteReader();

                while (dr.Read())
                {
                    Guesbooks Data = new Guesbooks();
                    Data.Id         = Convert.ToInt32(dr["Id"]);
                    Data.Name       = dr["Name"].ToString();
                    Data.Content    = dr["Content"].ToString();
                    Data.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                    if (!dr["ReplyTime"].Equals(DBNull.Value))
                    {
                        Data.Reply     = dr["Reply"].ToString();
                        Data.ReplyTime = Convert.ToDateTime(dr["ReplyTime"]);
                    }
                    DataList.Add(Data);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
            return(DataList);
        }
示例#5
0
        public void UpdateGuestboooks(Guesbooks UpdateData)
        {
            string sql = $@"UPDATE Guestbooks Set Name='{UpdateData.Name}',Content='{UpdateData.Content}' Where Id ={UpdateData.Id}";

            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
示例#6
0
        public void ReplyGuestbooks(Guesbooks ReplyData)
        {
            string sql = $@"Update Guestbooks SET Reply = '{ReplyData.Reply}', ReplyTime ='{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}' Where Id = {ReplyData.Id} ";


            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
示例#7
0
        public List <Guesbooks> GetAllDataList(ForPaging paging, string Search)
        {
            List <Guesbooks> DataList = new List <Guesbooks>();
            string           sql      = $@"Select * FROM (Select row_number() Over(order by Id)
            AS sort,* FROM Guestbooks Where Name Like '%{Search}%' OR Content LIKE
            '%{Search}%' OR Reply LIKE '%{Search}%') m WHERE m.sort Between
            {(paging.NowPage -1)*paging.ItemNum +1} AND {paging.NowPage * paging.ItemNum};";


            try
            {
                conn.Open();
                SqlCommand    cmd = new SqlCommand(sql, conn);
                SqlDataReader dr  = cmd.ExecuteReader();

                while (dr.Read())
                {
                    Guesbooks Data = new Guesbooks();
                    Data.Id         = Convert.ToInt32(dr["Id"]);
                    Data.Name       = dr["Name"].ToString();
                    Data.Content    = dr["Content"].ToString();
                    Data.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                    if (!dr["ReplyTime"].Equals(DBNull.Value))
                    {
                        Data.Reply     = dr["Reply"].ToString();
                        Data.ReplyTime = Convert.ToDateTime(dr["ReplyTime"]);
                    }
                    DataList.Add(Data);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
            return(DataList);
        }
示例#8
0
        //add message
        public void InSertGuestbooks(Guesbooks newData)
        {
            //sqlcommand
            //add time now
            string sql = $@"INSERT INTO Guestbooks(Name,Content,CreateTime) values('{newData.Name}','{newData.Content}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}');";

            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
示例#9
0
        public List <Guesbooks> GetAllDataList(ForPaging paging)
        {
            List <Guesbooks> DataList = new List <Guesbooks>();

            string sql = $@"select * from (select row_number() OVER(order By Id)As sort,* From Guestbooks) m Where m.sort BETWEEN {(paging.NowPage -1)*paging.ItemNum +1} AND {paging.NowPage * paging.ItemNum};";

            try
            {
                conn.Open();
                SqlCommand    cmd = new SqlCommand(sql, conn);
                SqlDataReader dr  = cmd.ExecuteReader();

                while (dr.Read())
                {
                    Guesbooks Data = new Guesbooks();
                    Data.Id         = Convert.ToInt32(dr["Id"]);
                    Data.Name       = dr["Name"].ToString();
                    Data.Content    = dr["Content"].ToString();
                    Data.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                    if (!dr["ReplyTime"].Equals(DBNull.Value))
                    {
                        Data.Reply     = dr["Reply"].ToString();
                        Data.ReplyTime = Convert.ToDateTime(dr["ReplyTime"]);
                    }
                    DataList.Add(Data);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
            return(DataList);
        }
示例#10
0
        public List <Guesbooks> GetDataList()
        {
            List <Guesbooks> DataList = new List <Guesbooks>();
            string           sql      = @"Select * FROM Guestbooks";

            try
            {
                conn.Open();
                SqlCommand    cmd = new SqlCommand(sql, conn);
                SqlDataReader dr  = cmd.ExecuteReader();

                while (dr.Read())
                {
                    Guesbooks Data = new Guesbooks();
                    Data.Id         = Convert.ToInt32(dr["Id"]);
                    Data.Name       = dr["Name"].ToString();
                    Data.Content    = dr["Content"].ToString();
                    Data.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                    if (!dr["ReplyTime"].Equals(DBNull.Value))
                    {
                        Data.Reply     = dr["Reply"].ToString();
                        Data.ReplyTime = Convert.ToDateTime(dr["ReplyTime"]);
                    }
                    DataList.Add(Data);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
            return(DataList);
        }
示例#11
0
        public bool CheckUpdate(int Id)
        {
            Guesbooks Data = GetDataById(Id);

            return(Data != null && Data.ReplyTime == null);
        }
示例#12
0
        public ActionResult Reply(int Id)
        {
            Guesbooks Data = GuestbooksService.GetDataById(Id);

            return(View(Data));
        }
示例#13
0
 public ActionResult Create([Bind(Include = "Name,Content")] Guesbooks Data)
 {
     GuestbooksService.InSertGuestbooks(Data);
     return(RedirectToAction("Index"));
 }