Ejemplo n.º 1
0
        /// <summary>
        /// Lấy ngày đăng
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static DateTime getPosted(int ID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from record in DB.tblEnglishes
                      where record.ID == ID
                      select record;

            return lst.ElementAt(0).Posted;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Lấy điểm bài viết
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int getPoint(int ID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from record in DB.tblEnglishes
                      where record.ID == ID
                      select record;

            return (int)lst.ElementAt(0).Point;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Lấy nội dung bài viết
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static string getContent(int ID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from record in DB.tblInformatics
                      where record.ID == ID
                      select record;

            return lst.ElementAt(0).Contents;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Lấy tên tác giả bài viết
        /// </summary>
        /// <param name="newsID"></param>
        /// <returns></returns>
        public static string getAuthor(int newsID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from author in DB.tblUsers
                      join news in DB.tblNews on author.Username equals news.Author
                      where news.ID == newsID
                      select author;

            return lst.ElementAt(0).DisplayName;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Lấy tên tác giả
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static string getAuthor(int ID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from author in DB.tblUsers
                      join record in DB.tblEnglishes on author.Username equals record.Author
                      where record.ID == ID
                      select author;

            return lst.ElementAt(0).DisplayName;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Kiểm tra sự tồn tại của 1 tin tức
        /// </summary>
        /// <param name="newsID"></param>
        /// <returns></returns>
        public static bool checkNewsExists(int newsID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            IEnumerable<tblNew> lst = from record in DB.tblNews
                                      where record.ID == newsID
                                      select record;

            if (lst.Count() > 0)
            {
                return true;
            }
            return false;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Lấy ra đoạn tóm tắt của tin tức
        /// </summary>
        /// <param name="newsID"></param>
        /// <returns></returns>
        public static string getChapeau(int newsID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            IEnumerable<tblNew> lst = from record in DB.tblNews
                                      where record.ID == newsID
                                      select record;

            if (lst.Count() > 0)
            {
                return lst.ElementAt(0).Chapaeu;
            }

            return "Not Exists";
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Kiểm tra xem đã có email này đăng ký hay chưa?
        /// </summary>
        /// <param name="_email"></param>
        /// <returns></returns>
        public static string existedEmail(string _email)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            //tìm user trong bảng user
            IEnumerable<tblUser> user = from record in DB.tblUsers
                                        where record.Email == _email
                                        select record;

            // nếu tồn tại it nhất 1 user
            if (user.Count() > 0)
            {
                return user.ElementAt(0).Username;
            }

            return null;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Kiểm tra xem đã có username này hay chưa?
        /// </summary>
        /// <param name="_username"></param>
        /// <returns></returns>
        public static Boolean existedUser(string _username)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            //tìm user trong bảng user
            IEnumerable<tblUser> user = from record in DB.tblUsers
                                        where record.Username == _username
                                        select record;

            // nếu tồn tại it nhất 1 user
            if (user.Count() > 0)
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Tổng số user
        /// </summary>
        /// <returns></returns>
        public static int numberOfUsers()
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from record in DB.tblUsers
                      select record;

            return lst.Count();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Kiểm tra xem có phải user hay k?
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="_password"></param>
        /// <returns></returns>
        public static Boolean isUser(string _username, string _password)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            string pwd = encryptPassword(_password);

            IEnumerable<tblUser> lst = from record in DB.tblUsers
                                       where record.Username == _username && record.Password == pwd
                                       select record;
            if (lst.Count() > 0)
            {
                return true;
            }
            return false;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Thêm một user mới
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public static Boolean insertUser(tblUser record)
        {
            LTDHDataContext DB = new LTDHDataContext(strPathDB);

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    DB.tblUsers.InsertOnSubmit(record);

                    DB.SubmitChanges();

                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Lấy loại thành viên
        /// - Admin
        /// - Normal
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static string getUserType(string username)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            IEnumerable<tblUser> lst = from record in DB.tblUsers
                                       where record.Username == username
                                       select record;

            if (lst.ElementAt(0).Type == false)
            {
                return "Admin";
            }

            return "Normal";
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Lấy trạng thái của user
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static string getUserState(string username)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            IEnumerable<tblUser> lst = from record in DB.tblUsers
                                       where record.Username == username
                                       select record;

            int type = lst.ElementAt(0).State;
            string strState = "";
            switch (type)
            {
                case 0:
                    {
                        strState = "Non-Active";
                        break;
                    }
                case 1:
                    {
                        strState = "Active";
                        break;
                    }
                case 2:
                    {
                        strState = "Warning";
                        break;
                    }
                case 31:
                    {
                        strState = "KIA 3 ngày";
                        break;
                    }
                case 32:
                    {
                        strState = "KIA 1 tuần";
                        break;
                    }
                case 33:
                    {
                        strState = "KIA 2 tuần";
                        break;
                    }
                case 34:
                    {
                        strState = "KIA 3 tuần";
                        break;
                    }
                case 35:
                    {
                        strState = "KIA 1 tháng";
                        break;
                    }

                default:
                    break;
            }

            return strState;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Lấy user
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="_password"></param>
        /// <returns></returns>
        public static tblUser getUser(string _username, string _password)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            string pwd = encryptPassword(_password);

            IEnumerable<tblUser> lst = from record in DB.tblUsers
                                       where record.Username == _username && record.Password == pwd
                                       select record;

            if (lst.Count() > 0)
            {
                return lst.ElementAt(0);
            }

            return null;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Xét loại bài viết
        /// 0 - Bài giảng
        /// 1 - Đề thi
        /// 2 - Bài tập
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="_type"></param>
        /// <returns></returns>
        public static Boolean setType(int ID, int _type)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            using (TransactionScope ts = new TransactionScope())
            {
                var record = DB.tblEnglishes.Single(TB => TB.ID == ID);
                record.Type = _type;
                DB.SubmitChanges();

                ts.Complete();
            }

            return true;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Lấy số bài viết của user.
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static int getNumberOfArticles(string username)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            IEnumerable<tblUser> lst = from record in DB.tblUsers
                                       where record.Username == username
                                       select record;

            return lst.ElementAt(0).NumberOfArticles;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Cập nhật bài viết
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        public static Boolean updateInformatic(int _id, tblInformatic update)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var informatic = DB.tblInformatics.Single(info => info.ID == _id);
                    informatic.Title = update.Title;
                    informatic.Type = update.Type;
                    informatic.Chapeau = update.Chapeau;
                    informatic.Contents = update.Contents;
                    informatic.Author = update.Author;
                    informatic.Posted = update.Posted;
                    informatic.State = update.State;
                    informatic.Point = update.Point;
                    informatic.Tag = update.Tag;

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Cập nhật user
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="update"></param>
        /// <returns></returns>
        public static Boolean updateUser(string _username, tblUser update)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var user = DB.tblUsers.Single(u => u.Username == _username);

                    user.Password = update.Password;
                    user.DisplayName = update.DisplayName;
                    user.Email = update.Email;
                    user.Type = update.Type;
                    user.Role = update.Role;
                    user.Permission = update.Permission;
                    user.State = update.State;
                    user.RegisterDate = update.RegisterDate;
                    user.NumberOfArticles = update.NumberOfArticles;
                    user.Note = update.Note;

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Lấy tiêu đề
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static string getTitle(int ID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from record in DB.tblEnglishes
                      where record.ID == ID
                      select record;

            return lst.ElementAt(0).Title;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Lấy ra loại bài viết
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static string getType(int ID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from record in DB.tblEnglishes
                      where record.ID == ID
                      select record;

            int type = lst.ElementAt(0).Type;
            string strType = "";
            switch (type)
            {
                case 0:
                    {
                        strType = "Bài giảng";
                        break;
                    }
                case 1:
                    {
                        strType = "Đề thi";
                        break;
                    }
                case 2:
                    {
                        strType = "Bài tập";
                        break;
                    }
                default:
                    break;
            }

            return strType;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Cập nhật bài viết
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="update"></param>
        /// <returns></returns>
        public static Boolean updateEnglish(int _id, tblEnglish update)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var english = DB.tblEnglishes.Single(e => e.ID == _id);

                    english.Title = update.Title;
                    english.Type = update.Type;
                    english.Contents = update.Contents;
                    english.Author = update.Author;
                    english.Posted = update.Posted;
                    english.State = update.State;
                    english.Point = update.Point;
                    english.Tag = update.Tag;

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Đăng ký user mới
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="_displayName"></param>
        /// <param name="_email"></param>
        /// <param name="_sex"></param>
        /// <param name="_password"></param>
        /// <returns></returns>
        public static Boolean register(string _username,
            string _displayName,
            string _email,
            Boolean _sex,
            string _password)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    tblUser user = new tblUser();
                    user.Username = _username;
                    user.DisplayName = _displayName;
                    user.Sex = _sex;
                    user.Email = _email;
                    user.Password = encryptPassword(_password);
                    user.Note = "Password: "******"Normal";
                    user.RegisterDate = DateTime.Today;
                    user.NumberOfArticles = 0;
                    user.State = 0;

                    DB.tblUsers.InsertOnSubmit(user);
                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// lấy tên role của user
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static string getRole(string username)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            IEnumerable<tblUser> lst = from record in DB.tblUsers
                                       where record.Username == username
                                       select record;

            return lst.ElementAt(0).Role;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Lấy trạng thái bài viết
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static string getState(int ID)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            var lst = from record in DB.tblEnglishes
                      where record.ID == ID
                      select record;

            int state = lst.ElementAt(0).State;
            string strState = "";
            switch (state)
            {
                case 0:
                    {
                        strState = "Uncheck";
                        break;
                    }
                case 1:
                    {
                        strState = "Checked";
                        break;
                    }
                case 2:
                    {
                        strState = "Bad";
                        break;
                    }
                default:
                    break;
            }

            return strState;
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Xét ngày đăng tin
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="_posted"></param>
        /// <returns></returns>
        public static Boolean setPosted(int ID, DateTime _posted)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            using (TransactionScope ts = new TransactionScope())
            {
                var record = DB.tblEnglishes.Single(TB => TB.ID == ID);
                record.Posted = _posted;
                DB.SubmitChanges();

                ts.Complete();
            }

            return true;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Xét trạng thái của user
        /// 0: Non-Active (mới đăng ký thành viên)
        /// 1: Active (Trạng thái hoạt động bình thường)
        /// 2: Warning (khi gửi bài bị báo xấu)
        /// 31: KIA 3 ngày
        /// 32: KIA 1 tuần
        /// 33: KIA 2 tuần
        /// 34: KIA 3 tuần
        /// 35: KIA 1 tháng
        /// </summary>
        /// <param name="username"></param>
        /// <param name="_state"></param>
        /// <returns></returns>
        public static Boolean setUserState(string username, int _state)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            using (TransactionScope ts = new TransactionScope())
            {
                var record = DB.tblUsers.Single(TB => TB.Username == username);
                record.State = _state;
                DB.SubmitChanges();

                ts.Complete();
            }

            return true;
        }
Ejemplo n.º 28
0
 /// <summary>
 /// method of UniversityDAO
 /// </summary>
 /// <returns></returns>
 public static IEnumerable<tblContestForUniversity> getAll()
 {
     LTDHDataContext DB = new LTDHDataContext(@strPathDB);
     IEnumerable<tblContestForUniversity> lst = from p in DB.tblContestForUniversities
                                                select p;
     return lst;
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Cập nhật mật khẩu mới
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="_newPassword"></param>
        public static Boolean updateUserPassword(string _username, string _newPassword)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var user = DB.tblUsers.Single(u => u.Username == _username);

                    user.Note = "New password: " + _newPassword;
                    user.Password = encryptPassword(_newPassword);

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Lấy ra email của username
 /// </summary>
 /// <param name="username"></param>
 /// <returns></returns>
 public static string getEmail(string username)
 {
     LTDHDataContext DB = new LTDHDataContext(@strPathDB);
     IEnumerable<tblUser> lst = from record in DB.tblUsers
                                where record.Username == username
                                select record;
     if (lst.Count() > 0)
     {
         return lst.ElementAt(0).Email;
     }
     return "Not Exists";
 }