Exemplo n.º 1
0
        public void Delete(string Ids)
        {
            using (var con = DbHelperSQL.GetConnection())
            {
                var tran = con.BeginTransaction();
                var ct   = new DS_ComNewsDataContext(con);
                ct.Transaction = tran;
                string[] idarray = Ids.Split(',');
                var      list    = ct.DS_ComNews.Where(a => idarray.Contains(a.ID.ToString()));
                foreach (var md in list)
                {
                    if (md.ParentID > 0)
                    {
                        var parent = ct.DS_ComNews.Single(a => a.ID == md.ParentID);
                        parent.Coment--;
                    }
                    else
                    {
                        var comlist = ct.DS_ComNews.Where(a => a.ParentID == md.ID);
                        ct.DS_ComNews.DeleteAllOnSubmit(comlist);
                    }
                }
                ct.DS_ComNews.DeleteAllOnSubmit(list);
                ct.SubmitChanges();

                tran.Commit();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 排序
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="IsUp"></param>
 public void Sort(int ID, bool IsUp)
 {
     using (var ct = new DS_ComNewsDataContext(DbHelperSQL.Connection))
     {
         var md = ct.DS_ComNews.Single(a => a.ID == ID);
         ct.ExecuteCommand("update DS_ComNews  set px=(select RowNumber from (select (ROW_NUMBER() OVER (ORDER BY px)) AS RowNumber,id from DS_ComNews where  MemberID={0}) as p2 where id=DS_ComNews.id) where MemberID={0}", md.MemberID);
         if (IsUp)
         {
             DS_ComNews p = ct.DS_ComNews.Single(a => a.ID == ID);
             DS_ComNews p1;
             if (p.Px > 1)
             {
                 p1 = ct.DS_ComNews.Single(a => a.Px == (p.Px - 1) && a.MemberID == md.MemberID);
                 p.Px--;
                 p1.Px++;
             }
         }
         else
         {
             DS_ComNews p = ct.DS_ComNews.Single(a => a.ID == ID);
             DS_ComNews p1;
             if (p.Px < ct.DS_ComNews.Where(a => a.MemberID == md.MemberID).Count())
             {
                 p1 = ct.DS_ComNews.Single(a => a.Px == (p.Px + 1) && a.MemberID == md.MemberID);
                 p.Px++;
                 p1.Px--;
             }
         }
         ct.SubmitChanges();
     }
 }
Exemplo n.º 3
0
 public void Update(DS_ComNews ComNews)
 {
     using (var ct = new DS_ComNewsDataContext(DbHelperSQL.Connection))
     {
         ct.DS_ComNews.Attach(ComNews, true);
         ct.SubmitChanges();
     }
 }
Exemplo n.º 4
0
 public void Add(DS_ComNews ComNews)
 {
     using (var ct = new DS_ComNewsDataContext(DbHelperSQL.Connection))
     {
         ct.DS_ComNews.InsertOnSubmit(ComNews);
         ct.SubmitChanges();
     }
 }
Exemplo n.º 5
0
 public void Comment(DS_ComNews ComNews)
 {
     using (var ct = new DS_ComNewsDataContext(DbHelperSQL.Connection))
     {
         ct.DS_ComNews.InsertOnSubmit(ComNews);
         var md = ct.DS_ComNews.Single(a => a.ID == ComNews.ParentID);
         md.Coment++;
         ct.SubmitChanges();
     }
 }
Exemplo n.º 6
0
        public void Delete(int ID)
        {
            using (var con = DbHelperSQL.GetConnection()) {
                var tran = con.BeginTransaction();
                var ct   = new DS_ComNewsDataContext(con);
                ct.Transaction = tran;
                var md = ct.DS_ComNews.Single(a => a.ID == ID);
                if (md.ParentID > 0)
                {
                    var parent = ct.DS_ComNews.Single(a => a.ID == md.ParentID);
                    parent.Coment--;
                }
                else
                {
                    var comlist = ct.DS_ComNews.Where(a => a.ParentID == md.ID);
                    ct.DS_ComNews.DeleteAllOnSubmit(comlist);
                }
                ct.DS_ComNews.DeleteOnSubmit(md);
                ct.SubmitChanges();

                tran.Commit();
            }
        }