/// <summary> /// change state of function is ON /// </summary> /// <param name="_code"></param> /// <param name="_username"></param> /// <returns></returns> public bool changeStateON(string _code, string _reason, string _username) { try { if (_reason.Length >= 500) { _reason = _reason.Substring(0, 499); } using (TransactionScope ts = new TransactionScope()) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); var record = DB.tblAdmins.Single(p => p.Code == _code); record.State = true; record.Reason = _reason.Trim(); DB.SubmitChanges(); ts.Complete(); log.writeLog(DBHelper.strPathLogFile, _username, BaseServices.createMsgByTemplate(CommonConstants.SQL_CHANGE_STATE_ON, _code)); } } catch (Exception ex) { log.writeLog(DBHelper.strPathLogFile, ex.Message); return false; } return true; }
/// <summary> /// add number /// </summary> /// <param name="_code"></param> /// <param name="_newVal"></param> public void add(string _code, string _newVal) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var r = DB.tblStatistics.Single(p => p.Code == _code); long oldVal = long.Parse(r.Value); long newVal = long.Parse(_newVal); if (oldVal > 0 || newVal > 0) { oldVal += newVal; } r.Value = oldVal.ToString(); DB.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); } }
public Boolean insertComment(int _id, string _newComment) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var english = DB.tblEnglishes.Single(e => e.ID == _id); english.Comment += _newComment; english.Comment += "<br /><br />;"; DB.SubmitChanges(); ts.Complete(); //Cho cái này vào bị lỗi liên tục //2011-09-27 16:09 tktung bỏ //ltktDAO.Statistics statDAO = new ltktDAO.Statistics(); //statDAO.add(CommonConstants.SF_NUM_COMMENT_A_DAY, "1"); } } catch (Exception e) { writeException(e); return false; } return true; }
/// <summary> /// Thêm 1 comment vào bài viết /// </summary> /// <param name="_id"></param> /// <param name="_newComment"></param> /// <returns></returns> public Boolean insertComment(int _id, string _newComment) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var contest = DB.tblContestForUniversities.Single(cont => cont.ID == _id); contest.Comment += _newComment; contest.Comment += "<br /><br />;"; DB.SubmitChanges(); ts.Complete(); //Cho cái này vào bị lỗi liên tục //2011-09-27 16:09 tktung bỏ //ltktDAO.Statistics statDAO = new ltktDAO.Statistics(); //statDAO.add(CommonConstants.SF_NUM_COMMENT_A_DAY, "1"); log.writeLog(DBHelper.strPathLogFile, "insert comment for contest id=" + _id + " successfully"); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
public void resetState(string _code) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var ads = DB.tblAdvertisements.Single(a => a.Code == _code); ads.Code = CommonConstants.ADS_INACTIVE; DB.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); } }
public void addLatestLoginUser(string username) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { username = BaseServices.nullToBlank(username); using (TransactionScope ts = new TransactionScope()) { var r = DB.tblStatistics.Single(p => p.Code == CommonConstants.SF_LATEST_LOGIN); if (!BaseServices.isNullOrBlank(r.Value)) { string[] arrayUser = r.Value.Split(CommonConstants.COMMA_CHAR); if (arrayUser[0].Contains(username)) return; if (arrayUser.Length >= 10) { r.Value = CommonConstants.BLANK; for (int i = 0; i < arrayUser.Length - 1; i++) { r.Value += arrayUser[i]; r.Value += CommonConstants.COMMA; } r.Value = r.Value.Substring(0, r.Value.Length - 1); } if (!r.Value.StartsWith(CommonConstants.COMMA)) { username += CommonConstants.COMMA; } username += r.Value.Trim(); r.Value = username; } else { r.Value = username; } DB.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); } }
/// <summary> /// set new value /// </summary> /// <param name="_code"></param> /// <param name="_value"></param> public void setValue(string _code, string _value) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var r = DB.tblStatistics.Single(p => p.Code == _code); r.Value = _value; DB.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); } }
public Boolean Like(int _id) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var english = DB.tblEnglishes.Single(e => e.ID == _id); english.Point += 1; DB.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
public Boolean Dislike(int _id) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var informatic = DB.tblInformatics.Single(info => info.ID == _id); if (informatic.Point > 0) { informatic.Point -= 1; } informatic.State = CommonConstants.STATE_BAD; // Bad DB.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
//public Boolean insertInformatic(string _title, int _type, string _content, // string _author, DateTime _posted, string _location, string _tag) //{ // return false; //} /// <summary> /// Cập nhật bài viết /// </summary> /// <param name="update"></param> /// <returns></returns> public Boolean updateInformatic(int _id, tblInformatic update, string currentUsername) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var informatic = DB.tblInformatics.Single(info => info.ID == _id); if (informatic != null) { informatic.Title = update.Title; informatic.Type = update.Type; informatic.Chapeau = update.Chapeau; informatic.Contents = update.Contents; informatic.Author = update.Author; informatic.Posted = update.Posted; ltktDAO.Users userDao = new ltktDAO.Users(); if (informatic.State == CommonConstants.STATE_UNCHECK && update.State == CommonConstants.STATE_CHECKED) { userDao.addNumberOfArticle(informatic.Author.Trim()); } else if (informatic.State == CommonConstants.STATE_CHECKED && update.State == CommonConstants.STATE_UNCHECK) { userDao.subNumberOfArticle(informatic.Author.Trim()); } informatic.State = update.State; informatic.Tag = update.Tag; informatic.HtmlEmbedLink = update.HtmlEmbedLink; informatic.HtmlPreview = update.HtmlPreview; //informatic.DeleteFlg = false; informatic.Checker = update.Checker; informatic.Leitmotif = update.Leitmotif; informatic.StickyFlg = update.StickyFlg; informatic.Comment = update.Comment; informatic.Thumbnail = update.Thumbnail; informatic.Location = update.Location; DB.SubmitChanges(); } ts.Complete(); //write log log.writeLog(DBHelper.strPathLogFile, currentUsername, BaseServices.createMsgByTemplate(CommonConstants.SQL_UPDATE_SUCCESSFUL_TEMPLATE, _id.ToString(), CommonConstants.SQL_TABLE_INFORMATICS)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, currentUsername, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
/// <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 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(); Permission permitDAO = new Permission(); user.Username = _username; user.DisplayName = _displayName; user.Sex = _sex; user.Email = _email; user.Password = encryptPassword(_password); user.Note = "Password: " + _password; user.Type = true; user.Permission = permitDAO.getValue(CommonConstants.P_N_GENERAL).ToString(); user.RegisterDate = DateTime.Today; user.NumberOfArticles = 0; user.State = CommonConstants.STATE_NON_ACTIVE; DB.tblUsers.InsertOnSubmit(user); DB.SubmitChanges(); ts.Complete(); log.writeLog(DBHelper.strPathLogFile, CommonConstants.USER_GUEST, BaseServices.createMsgByTemplate(CommonConstants.SQL_INSERT_SUCCESSFUL_TEMPLATE, _username, CommonConstants.SQL_TABLE_USER)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, CommonConstants.USER_GUEST, BaseServices.createMsgByTemplate(CommonConstants.SQL_INSERT_FAILED_TEMPLATE, _username, CommonConstants.SQL_TABLE_USER)); log.writeLog(DBHelper.strPathLogFile, CommonConstants.USER_GUEST, e.Message); return false; } return true; }
/// <summary> /// Thêm một user mới /// </summary> /// <param name="record"></param> /// <returns></returns> public 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; }
/// <summary> /// Thêm một đề thi /// </summary> /// <param name="_title"></param> /// <param name="_content"></param> /// <param name="_author"></param> /// <param name="_posted"></param> /// <param name="_isUniversity"></param> /// <param name="_branch"></param> /// <param name="_year"></param> /// <param name="_location"></param> /// <returns></returns> public Boolean insertContest(string _title, string _content, string _author, DateTime _posted, Boolean _isUniversity, string _sub, int _year, string _location, string _tag, string fileSolved, string _folderID) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { tblContestForUniversity record = new tblContestForUniversity(); record.Title = _title; record.Contents = _content; record.Author = _author; record.Posted = _posted; record.State = CommonConstants.STATE_UNCHECK;//Chưa duyệt record.isUniversity = _isUniversity; record.Subject = _sub; record.Year = _year; record.Point = 0;//điểm = số người view record.Location = _location; record.Tag = _tag; record.StickyFlg = false; record.Score = 0;//điểm của checker record.Solving = fileSolved; record.FolderID = _folderID; DB.tblContestForUniversities.InsertOnSubmit(record); DB.SubmitChanges(); ts.Complete(); ltktDAO.Statistics statisticDAO = new ltktDAO.Statistics(); statisticDAO.add(CommonConstants.SF_NUM_UPLOAD, CommonConstants.CONST_ONE); log.writeLog(DBHelper.strPathLogFile, _author, BaseServices.createMsgByTemplate(CommonConstants.SQL_INSERT_SUCCESSFUL_TEMPLATE, record.ID.ToString(), CommonConstants.SQL_TABLE_CONTEST_UNIVERSITY)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, _author, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
/// <summary> /// Thêm một đề thi /// </summary> /// <param name="record"></param> /// <returns></returns> public Boolean insertContest(tblContestForUniversity record, string _username) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { DB.tblContestForUniversities.InsertOnSubmit(record); DB.SubmitChanges(); ts.Complete(); log.writeLog(DBHelper.strPathLogFile, _username, BaseServices.createMsgByTemplate(CommonConstants.SQL_INSERT_SUCCESSFUL_TEMPLATE, record.ID.ToString(), CommonConstants.SQL_TABLE_CONTEST_UNIVERSITY)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, _username, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
/// <summary> /// Thêm một bài viết mới /// </summary> /// <param name="record"></param> /// <returns></returns> public Boolean insertEnglish(tblEnglish record) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { DB.tblEnglishes.InsertOnSubmit(record); DB.SubmitChanges(); ts.Complete(); } ltktDAO.Control controlDao = new ltktDAO.Control(); long keyCode = controlDao.getValueByLong(CommonConstants.CF_KEY_CODE_EL); controlDao.setValue(CommonConstants.CF_KEY_CODE_EL, (keyCode + 1).ToString()); } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, record.Author, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
/// <summary> /// Thêm một bài giảng/bài tập/đề thi anh văn /// </summary> /// <param name="_title"></param> /// <param name="_type"></param> /// <param name="_content"></param> /// <param name="_author"></param> /// <param name="_posted"></param> /// <param name="_location"></param> /// <param name="_tag"></param> /// <returns></returns> public Boolean insertEnglish(string _title, int _type, string _content, string _author, DateTime _posted, int _class, string _location, string _tag, string folderId) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { tblEnglish record = new tblEnglish(); record.Title = _title; record.Type = _type; record.Contents = _content; record.Author = _author; record.Posted = _posted; record.Class = _class; record.Location = _location; record.State = 0; record.Point = 0; record.Score = 0; record.Tag = _tag; record.StickyFlg = false; record.Class = _class; record.FolderID = folderId; record.DeleteFlg = false; DB.tblEnglishes.InsertOnSubmit(record); DB.SubmitChanges(); ts.Complete(); } ltktDAO.Statistics statisticDAO = new ltktDAO.Statistics(); statisticDAO.add(CommonConstants.SF_NUM_UPLOAD, CommonConstants.CONST_ONE); } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, _author, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
/// <summary> /// Them 1 comment vao bai viet /// </summary> /// <param name="_id"></param> /// <param name="_newComment"></param> /// <returns></returns> public Boolean insertComment(int _id, string _newComment, string currentUsername) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var informatic = DB.tblInformatics.Single(info => info.ID == _id); informatic.Comment += _newComment; informatic.Comment += "<br /><br />;"; DB.SubmitChanges(); ts.Complete(); //Cho cái này vào bị lỗi liên tục //2011-09-27 16:09 tktung bỏ //ltktDAO.Statistics statDAO = new ltktDAO.Statistics(); //statDAO.add(CommonConstants.SF_NUM_COMMENT_A_DAY, "1"); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, currentUsername, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
public void setReason(string _code, string _reason) { try { using (TransactionScope ts = new TransactionScope()) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); var record = DB.tblAdmins.Single(p => p.Code == _code); record.Reason = _reason.Trim(); DB.SubmitChanges(); ts.Complete(); } } catch (Exception ex) { log.writeLog(DBHelper.strPathLogFile, ex.Message); } }
/// <summary> /// Thêm bài mới /// </summary> /// <param name="record"></param> /// <returns></returns> public Boolean insertInformatic(tblInformatic record) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { DB.tblInformatics.InsertOnSubmit(record); DB.SubmitChanges(); ts.Complete(); log.writeLog(DBHelper.strPathLogFile, record.Author, BaseServices.createMsgByTemplate(CommonConstants.SQL_INSERT_SUCCESSFUL_TEMPLATE, record.ID.ToString(), CommonConstants.SQL_TABLE_INFORMATICS)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, record.Author, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
public void resetToDefault(string _code) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var r = DB.tblStatistics.Single(p => p.Code == _code); if (BaseServices.nullToBlank(_code).StartsWith("NUM")) { r.Value = "0"; } else { r.Value = CommonConstants.BLANK; } DB.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); } }
/// <summary> /// Thêm một bài giảng/bài tập/đề thi tin học /// </summary> /// <param name="_title"></param> /// <param name="_type"></param> /// <param name="_content"></param> /// <param name="_author"></param> /// <param name="_posted"></param> /// <param name="_location"></param> /// <returns></returns> public Boolean insertInformatic(string _title, int _type, string _content, string _author, DateTime _posted, int _leitmotif, string _location, string _tag, string _folderID) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { tblInformatic record = new tblInformatic(); record.Title = _title; record.Type = _type; record.Contents = _content; record.Leitmotif = _leitmotif; record.Author = _author; record.Posted = _posted; record.Point = 0; record.State = CommonConstants.STATE_UNCHECK; record.Location = _location; record.Tag = _tag; record.StickyFlg = false; record.Score = 0; record.DeleteFlg = false; record.FolderID = _folderID; DB.tblInformatics.InsertOnSubmit(record); DB.SubmitChanges(); ts.Complete(); ltktDAO.Statistics statisticDAO = new ltktDAO.Statistics(); statisticDAO.add(CommonConstants.SF_NUM_UPLOAD, CommonConstants.CONST_ONE); log.writeLog(DBHelper.strPathLogFile, record.Author, BaseServices.createMsgByTemplate(CommonConstants.SQL_INSERT_SUCCESSFUL_TEMPLATE, _title, CommonConstants.SQL_TABLE_INFORMATICS)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, _author, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
public bool setDeleteFlagArticle(int _id) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var english = DB.tblEnglishes.Single(e => e.ID == _id); english.DeleteFlg = true; if (english.State == CommonConstants.STATE_CHECKED) { ltktDAO.Users userDao = new ltktDAO.Users(); userDao.subNumberOfArticle(english.Author.Trim()); } DB.SubmitChanges(); ts.Complete(); } } catch (Exception ex) { writeException(ex); return false; } return true; }
/// <summary> /// Cập nhật bài viết /// </summary> /// <param name="ID"></param> /// <param name="update"></param> /// <returns></returns> public 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; ltktDAO.Users userDao = new ltktDAO.Users(); if (english.State == CommonConstants.STATE_UNCHECK && update.State == CommonConstants.STATE_CHECKED) { userDao.addNumberOfArticle(english.Author.Trim()); } else if (english.State == CommonConstants.STATE_CHECKED && update.State == CommonConstants.STATE_UNCHECK) { userDao.subNumberOfArticle(english.Author.Trim()); } english.State = update.State; english.Point = update.Point; english.Tag = update.Tag; english.HtmlEmbedLink = update.HtmlEmbedLink; english.HtmlPreview = update.HtmlPreview; english.StickyFlg = update.StickyFlg; english.Checker = update.Checker; english.Score = update.Score; english.Thumbnail = update.Thumbnail; english.Class = update.Class; english.Location = update.Location; english.Comment = update.Comment; english.FolderID = update.FolderID; DB.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, update.Author, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
/// <summary> /// Xóa 1 record quảng cáo /// </summary> /// <param name="_id"></param> /// <param name="_username"></param> /// <returns></returns> public bool deleteAds(int _id, string _username) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var ads = DB.tblAdvertisements.Single(a => a.ID == _id); DB.tblAdvertisements.DeleteOnSubmit(ads); DB.SubmitChanges(); ts.Complete(); log.writeLog(DBHelper.strPathLogFile, _username, BaseServices.createMsgByTemplate (CommonConstants.SQL_DELETE_SUCCESSFUL_TEMPLATE, _id.ToString(), CommonConstants.SQL_TABLE_ADVERTISEMENT)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, _username, BaseServices.createMsgByTemplate(CommonConstants.SQL_DELETE_FAILED_TEMPLATE, _id.ToString(), CommonConstants.SQL_TABLE_ADVERTISEMENT)); log.writeLog(DBHelper.strPathLogFile, _username, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }
/// <summary> /// delete article /// </summary> /// <param name="deletedList"></param> /// <returns></returns> public bool deleteArticles() { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { IEnumerable<tblEnglish> deletedList = from p in DB.tblEnglishes where p.DeleteFlg == true select p; DB.tblEnglishes.DeleteAllOnSubmit(deletedList); DB.SubmitChanges(); ts.Complete(); } } catch (Exception ex) { writeException(ex); return false; } return true; }
public int cloneAds(string _companyName, string _address, string _email, string _phone, DateTime _from, DateTime _end, string _location, string _navigateUrl, string _description) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); int id = -1; try { using (TransactionScope ts = new TransactionScope()) { tblAdvertisement record = new tblAdvertisement(); record.Company = _companyName; record.Address = _address; record.Email = _email; record.Phone = _phone; record.fromDate = _from; record.toDate = _end; record.Price = 0; record.FilePath = CommonConstants.BLANK; record.Location = _location; record.Code = CommonConstants.ADS_INACTIVE; record.ClickCount = 0; record.NavigateUrl = _navigateUrl; record.FilePath = CommonConstants.BLANK; record.Description = _description; record.Size = CommonConstants.DEFAULT_ADS_IMG_SIZE; record.State = CommonConstants.STATE_UNCHECK; DB.tblAdvertisements.InsertOnSubmit(record); DB.SubmitChanges(); ts.Complete(); id = record.ID; log.writeLog(DBHelper.strPathLogFile, BaseServices.createMsgByTemplate(CommonConstants.SQL_INSERT_SUCCESSFUL_TEMPLATE, record.ID.ToString(), CommonConstants.SQL_TABLE_ADVERTISEMENT)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return -1; } return id; }
/// <summary> /// Cập nhật đề thi /// </summary> /// <param name="ID"></param> /// <param name="update"></param> /// <returns></returns> public Boolean updateContest(int _id, tblContestForUniversity update, string _username) { LTDHDataContext DB = new LTDHDataContext(@strPathDB); try { using (TransactionScope ts = new TransactionScope()) { var contest = DB.tblContestForUniversities.Single(cont => cont.ID == _id); contest.Title = update.Title; contest.Contents = update.Contents; contest.Author = update.Author; contest.Posted = update.Posted; contest.State = update.State; contest.isUniversity = update.isUniversity; contest.Branch = update.Branch; contest.Year = update.Year; contest.Solving = update.Solving; contest.Point = update.Point; contest.Tag = update.Tag; contest.StickyFlg = update.StickyFlg; contest.Score = update.Score; contest.HtmlEmbedLink = update.HtmlEmbedLink; contest.HtmlPreview = update.HtmlPreview; contest.Location = update.Location; DB.SubmitChanges(); ts.Complete(); log.writeLog(DBHelper.strPathLogFile, _username, BaseServices.createMsgByTemplate(CommonConstants.SQL_UPDATE_SUCCESSFUL_TEMPLATE, contest.ID.ToString(), CommonConstants.SQL_TABLE_CONTEST_UNIVERSITY)); } } catch (Exception e) { log.writeLog(DBHelper.strPathLogFile, _username, e.Message + CommonConstants.NEWLINE + e.Source + CommonConstants.NEWLINE + e.StackTrace + CommonConstants.NEWLINE + e.HelpLink); return false; } return true; }