点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 留言本类>> 三层个人网站小程序(Ajax)>> 源文件浏览
[免费版 Free] WebForm,下载次数:5635 次 | 关键字: 多层开发 Ajax-Atlas Access ORM框架 atlas 博客 XML

源码截图

源码目录树

当前路径:DAL/Access.cs     using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using Model;
using IDAL;

namespace DAL
{
    /// <summary>
    /// Access留言本数据访问层
    /// </summary>
    public class AccessGuestBook : Iguestbook //继承Iguestbook接口
    {
        private string connectionString =  System.Configuration.ConfigurationSettings.AppSettings["accessConectionString"] + System.Web.HttpContext.Current.Server.MapPath("/App_Data/myPage.mdb");
        

        /// <summary>
        /// 读取数据库中所有留言
        /// </summary>
        /// <returns>返回guestbool数组</returns>
        public guestbook[] getListGuestBook()
        {
            using (OleDbConnection oleConn = new OleDbConnection(connectionString))
            {
                OleDbCommand oleCmd = new OleDbCommand("select * from guestbook order by id desc", oleConn);
                oleConn.Open();
                
                ArrayList guest = new ArrayList();
                OleDbDataReader oleDdr = oleCmd.ExecuteReader();
                while (oleDdr.Read())
                {
                    guestbook gb = new guestbook();
                    gb.Id = oleDdr["id"].ToString();
                    gb.Name = oleDdr["name"].ToString();
                    gb.Time =DateTime.Parse (oleDdr["times"].ToString());
                    gb.Ip = oleDdr["ip"].ToString();
                    gb.Content = oleDdr["content"].ToString();
                    gb.Recontent = oleDdr["recontent"].ToString();
                    gb.Pic = oleDdr["pic"].ToString();
                    gb.Email = oleDdr["email"].ToString();
                    guest.Add(gb);
                }
                oleDdr.Close();
            
            return (guestbook[])guest.ToArray(typeof(guestbook));
            }

        }

        /// <summary>
        /// 读取一条留言内容
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public guestbook[] getOnly(string id)
        {
            using (OleDbConnection oleConn = new OleDbConnection(connectionString))
            {
                OleDbCommand oleCmd = new OleDbCommand("select * from guestbook where id=" + id, oleConn);
                oleConn.Open();

                ArrayList guest = new ArrayList();
                OleDbDataReader oleDdr = oleCmd.ExecuteReader();
                while (oleDdr.Read())
                {
                    guestbook gb = new guestbook();
                    gb.Id = oleDdr["id"].ToString();
                    gb.Name = oleDdr["name"].ToString();
                    gb.Time =DateTime .Parse ( oleDdr["times"].ToString());
                    gb.Ip = oleDdr["ip"].ToString();
                    gb.Content = oleDdr["content"].ToString();
                    gb.Recontent = oleDdr["recontent"].ToString();
                    gb.Pic = oleDdr["pic"].ToString();
                    gb.Email = oleDdr["email"].ToString();
                    guest.Add(gb);
                }
                oleDdr.Close();

                return (guestbook[])guest.ToArray(typeof(guestbook));
            }
        }

        /// <summary>
        /// 添加留言内容
        /// </summary>
        /// <param name="gb">留言实体对像</param>
       public  void setGuestBook(guestbook gb)
        {
           using(OleDbConnection oleCon=new OleDbConnection (this.connectionString ))
           {
               string sql = "insert into guestbook (name,times,ip,content,pic,email) values ( @name , @times , @ip , @content , @pic ,@email)";
               OleDbParameter oleParam0 = new OleDbParameter("@name", gb.Name);
               OleDbParameter oleParam1 = new OleDbParameter("@times", gb.Time);
               OleDbParameter oleParam2 = new OleDbParameter("@ip", gb.Ip);
               OleDbParameter oleParam3 = new OleDbParameter("@content", gb.Content );
               OleDbParameter oleParam4 = new OleDbParameter("@pic",gb.Pic );
               OleDbParameter oleParam5 = new OleDbParameter("@email", gb.Email );
               OleDbCommand oleCmd = new OleDbCommand();
               oleCmd.CommandText = sql;

               oleCmd.Parameters.Add(oleParam0);
               oleCmd.Parameters.Add(oleParam1);
               oleCmd.Parameters.Add(oleParam2);
               oleCmd.Parameters.Add(oleParam3);
               oleCmd.Parameters.Add(oleParam4);
               oleCmd.Parameters.Add(oleParam5);
               oleCon.Open();
               oleCmd.Connection = oleCon;
               oleCmd.ExecuteNonQuery();
           }
        }

       /// <summary>
       /// 回复留言
       /// </summary>
       /// <param name="Regb"></param>
       public void setReGuestBook(guestbook Regb)
        {
            using (OleDbConnection oleCon = new OleDbConnection(this.connectionString))
            {
                string sql = "update guestbook set  recontent=@recontent where id=" + Regb.Id;
                OleDbParameter oleParam0 = new OleDbParameter("@recontent", Regb.Recontent);
                OleDbCommand oleCmd = new OleDbCommand();
                oleCmd.CommandText = sql;
                oleCmd.Parameters.Add(oleParam0);
                oleCon.Open();
                oleCmd.Connection = oleCon;
                oleCmd.ExecuteNonQuery();
            }
        }

        /// <summary>
        /// 删除留言
        /// </summary>
        /// <param name="id">留言id号</param>
        /// <returns></returns>
       public  bool delGuestBook(string id)
       {
           using (OleDbConnection oleCon = new OleDbConnection(this.connectionString))
           {
               string sql = "delete from [guestbook] where id=@id";
               OleDbParameter oleParam0 = new OleDbParameter("@id", id);
               OleDbCommand oleCmd = new OleDbCommand();
               oleCmd.CommandText = sql;
               oleCmd.Parameters.Add(oleParam0);
               oleCon.Open();
               oleCmd.Connection = oleCon;
               try
               {
                   oleCmd.ExecuteNonQuery();
                   return true;
               }
               catch
               {
                   return false;
               }
           }
           
       }
    }
}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途) 企业QQ:2852517674
地址:北京市海淀区中关村鼎好大厦A座二层 邮编:100080
Room A-801,Dinghao Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2015. 京ICP备09089570号 | 京公网安备11010702000869号
分享该页面
关闭侧边栏