示例#1
0
        protected void Add_Click(object sender, EventArgs e)
        {
            if (txtContent.Text.Trim().Length == 0)
            {
                Response.Write("<script>alert('内容不能为空,请填写内容!');</script>");
                return;
            }
            ExampleArticle    da = new ExampleArticle();
            ExampleArticleBLL examplearticlebll = new ExampleArticleBLL();
            string            newname           = "";

            da.Url     = newname;
            da.AddDate = Convert.ToDateTime(TxtDate.Text);
            da.Writer  = Server.HtmlEncode(TxtWriter.Text.Trim());
            da.Title   = Server.HtmlEncode(TxtTitle.Text.Trim());
            da.Content = txtContent.Text;
            if (examplearticlebll.Add(da))
            {
                Response.Write("<script>alert('添加成功');window.location.href='ExampleMgr.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('添加失败');history.back();</script>");
            }
        }
示例#2
0
        public IList <ExampleArticle> FindALLByHits()
        {
            List <ExampleArticle> list = new List <ExampleArticle>();

            sql = "select top 12 * from ExampleArticle order by hits desc";
            ds  = DbHelperSQL.GetDataSet(sql);
            if (ds == null)
            {
                return(null);
            }
            else
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ExampleArticle a = new ExampleArticle();
                    a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
                    a.Content = dr["Content"].ToString();
                    a.Id      = dr["id"];
                    a.Title   = dr["Title"].ToString();
                    a.Writer  = dr["Writer"].ToString();
                    a.Url     = dr["Url"].ToString();
                    list.Add(a);
                }
                return(list);
            }
        }
示例#3
0
        protected void Save_Click(object sender, EventArgs e)
        {
            if (txtContent.Text.Trim().Length == 0)
            {
                Response.Write("<script>alert('内容不能为空,请填写内容!');</script>");
                return;
            }
            object            id = Request.QueryString["id"];//有待改善不安全
            ExampleArticle    da = new ExampleArticle();
            ExampleArticleBLL examplearticlebll = new ExampleArticleBLL();

            da.AddDate = Convert.ToDateTime(TxtDate.Text);
            da.Writer  = Server.HtmlEncode(TxtWriter.Text.Trim());
            da.Title   = Server.HtmlEncode(TxtTitle.Text.Trim());
            da.Id      = id;
            da.Content = txtContent.Text;
            string name = this.Image1.ImageUrl.Substring(14);

            if (examplearticlebll.Update(da))
            {
                Response.Write("<script>alert('修改成功');window.location.href='ExampleMgr.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('更新失败');history.back();</script>");
            }
        }
        public void Test_List()
        {
            var context = GetMockGitDB ();

            var exampleArticle = new ExampleArticle ();

            var json = exampleArticle.ToJson ();

            var filePath = Path.Combine(Environment.CurrentDirectory, exampleArticle.TypeName + "-" + exampleArticle.Id);

            File.WriteAllText (filePath, json);

            var idsFilePath = Path.GetFullPath (exampleArticle.TypeName + "-Ids");

            File.WriteAllText (idsFilePath, exampleArticle.Id);

            var typesFilePath = Path.GetFullPath (context.TypeManager.TypesFileName);

            var typeEntry = exampleArticle.TypeName + ":" + exampleArticle.GetType ().FullName + ", " + exampleArticle.GetType ().Assembly.GetName ().Name;

            File.WriteAllText (typesFilePath, typeEntry);

            var lister = new DataLister (context.Settings, context.TypeManager, context.IdManager, context.Reader);

            var articles = lister.Get<ExampleArticle> ();

            Assert.AreEqual (1, articles.Length);

            Assert.IsNotNull (articles [0]);

            Assert.AreEqual (exampleArticle.Id, articles [0].Id);
        }
示例#5
0
        public IList <ExampleArticle> Getlist(object num)//取ExampleArticle表中前num个记录,以列表的形式返回
        {
            List <ExampleArticle> list = new List <ExampleArticle>();

            if (num != null && num.ToString() != "")
            {
                sql = "select top " + num + " * from ExampleArticle order by id desc";
            }
            else
            {
                sql = "select * from ExampleArticle where url is not null order by id desc";
            }
            ds = DbHelperSQL.GetDataSet(sql);
            if (ds == null)
            {
                return(null);
            }
            else
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ExampleArticle a = new ExampleArticle();
                    a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
                    a.Content = dr["Content"].ToString();
                    a.Id      = dr["id"];
                    a.Title   = dr["Title"].ToString();
                    a.Writer  = dr["Writer"].ToString();
                    a.Url     = dr["Url"].ToString();
                    list.Add(a);
                }
                return(list);
            }
        }
示例#6
0
        public IList <ExampleArticle> FindALL(object cid, int num)//找到cid的类中前num的列表
        {
            List <ExampleArticle> list = new List <ExampleArticle>();

            if (cid != null && cid.ToString() != "")
            {
                sql = "select top " + num + " * from ExampleArticle where cid=" + cid + " order by id desc";
            }
            else
            {
                sql = "select top " + num + " * from ExampleArticle order by id desc";
            }


            ds = DbHelperSQL.GetDataSet(sql);
            if (ds == null)
            {
                return(null);
            }
            else
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ExampleArticle a = new ExampleArticle();
                    a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
                    a.Content = dr["Content"].ToString();
                    a.Id      = dr["id"];
                    a.Title   = dr["Title"].ToString();
                    a.Writer  = dr["Writer"].ToString();
                    a.Url     = dr["Url"].ToString();
                    list.Add(a);
                }
                return(list);
            }
        }
示例#7
0
 public bool Update(ExampleArticle a)
 {
     if (DbHelperSQL.Update(a))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#8
0
 public bool Add(ExampleArticle a)
 {
     if (DbHelperSQL.Insert(a))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#9
0
        public void DateBind(object id)//绑定要修改的信息
        {
            ExampleArticleBLL examplearticle = new ExampleArticleBLL();
            ExampleArticle    da             = new ExampleArticle();

            da                   = examplearticle.GetNewsArticle(id);
            TxtTitle.Text        = da.Title;
            TxtWriter.Text       = da.Writer;
            TxtDate.Text         = da.AddDate.ToString("d");
            txtContent.Text      = da.Content.ToString();
            this.Image1.ImageUrl = "~/IndexImages/" + da.Url;
        }
        public void Test_Check()
        {
            var context = GetMockGitDB ();

            var checker = new DataChecker (context.Settings, context.Reader);

            var exampleArticle = new ExampleArticle ();

            var json = exampleArticle.ToJson ();

            var filePath = context.Saver.Namer.CreateFilePath (exampleArticle.TypeName, exampleArticle.Id);

            File.WriteAllText (filePath, json);

            var exists = checker.Exists (exampleArticle);

            Assert.IsTrue (exists);
        }
示例#11
0
        public ExampleArticle Find(object id)//从ExampleArticle找到该id的数据,返回一个ExampleArticle类生成的对象
        {
            a = new ExampleArticle();
            string sql = string.Format("select * from ExampleArticle where id='{0}'", id);

            dr = DbHelperSQL.GetDateRow(sql);
            try
            {
                a.AddDate = Convert.ToDateTime(dr["AddDate"].ToString());
                a.Content = dr["Content"].ToString();
                a.Id      = dr["id"];
                a.Title   = dr["Title"].ToString();
                a.Writer  = dr["Writer"].ToString();
                a.Url     = dr["Url"].ToString();
                return(a);
            }
            catch
            {
                return(null);
            }
        }
示例#12
0
        public IList <ExampleArticle> search(string cid)//搜索该表中,所有与关键字匹配的记录,当cid为空时,搜索整个表
        {
            if (cid == "" || cid == null)
            {
                sql = "select * from ExampleArticle order by id desc";
                ds  = DbHelperSQL.GetDataSet(sql);
            }
            else
            {
                sql = "select * from ExampleArticle where title like '%" + cid + "%' order by id desc";
                SqlParameter par = new SqlParameter("@titlesea", SqlDbType.NVarChar, 50);
                par.Value = cid;
                SqlParameter tablename = new SqlParameter("@tablename", SqlDbType.NVarChar, 50);
                tablename.Value = "ExampleArticle";
                SqlParameter[] cmdParms = { tablename, par };
                ds = DbHelperSQL.RunProcedure("ExampleSearch", cmdParms, "ExampleArticle");
            }
            List <ExampleArticle> list = new List <ExampleArticle>();

            if (ds == null)
            {
                return(null);
            }
            else
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ExampleArticle a = new ExampleArticle();
                    a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
                    a.Content = dr["Content"].ToString();
                    a.Id      = dr["id"];
                    a.Title   = dr["Title"].ToString();
                    a.Writer  = dr["Writer"].ToString();
                    list.Add(a);
                }
                return(list);
            }
        }
示例#13
0
 public bool Update(ExampleArticle news)//更新数据
 {
     return(ExampleArticleDao.Update(news));
 }
示例#14
0
 public bool Add(ExampleArticle news)//加数据
 {
     return(ExampleArticleDao.Add(news));
 }