예제 #1
0
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            if (Session[CommonConstants.SES_ID] == null)
            {
                string message = CommonConstants.MSG_E_RESOURCE_NOT_FOUND;
                message += CommonConstants.TEMP_BR_TAG;
                message += BaseServices.createMsgByTemplate(CommonConstants.MSG_E_ACTION_FAILED, CommonConstants.ACT_EDIT);
                showErrorMessage(message);
                return;
            }
            string sError = validateForm();
            if (!BaseServices.isNullOrBlank(sError))
            {
                showErrorMessage(sError);
                return;
            }
            tblEnglish item = new tblEnglish();
            item.Contents = txtChapeau.Text.Trim();
            item.Posted = BaseServices.getDateTimeFromString(txtPosted.Text) ;
            item.Title = txtTitle.Text.Trim();
            item.Tag = txtTag.Text.Trim();
            item.Location = txtLocation.Text.Trim();
            item.Author = txtAuthor.Text;
            int score = BaseServices.convertStringToInt( ddlScore.SelectedValue);
            item.Score = score;
            //get checker when score > 0.
            if (score != 0)
            {
                if (BaseServices.isNullOrBlank(txtChecker.Text))
                {
                    item.Checker = getCurrentUser();
                }
                else
                {
                    item.Checker = txtChecker.Text.Trim();
                }
            }
            else
            {
                item.Checker = null;
            }
            item.Comment = txtComment.Text.Trim();
            item.Thumbnail = txtThumbnail.Text.Trim();
            item.HtmlEmbedLink = txtHtmlEmbbed.Text.Trim();
            item.HtmlPreview = txtHtmlPreviewLink.Text.Trim();
            int type = BaseServices.convertStringToInt(ddlType.SelectedValue.ToString());
            item.Type = type;
            item.Class = BaseServices.convertStringToInt(ddlClass.SelectedValue.ToString());
            item.FolderID = txtFolderId.Text.Trim();
            //sticky item
            if (ddlSticky.SelectedValue.ToString() == CommonConstants.CONST_ZERO)
            {
                item.StickyFlg = false;
            }
            else
            {
                int stickied = englishDAO.countStickyArticle();
                int noOfEnglishOnPage = control.getValueByInt(CommonConstants.CF_NUM_ARTICLE_ON_EL);
                if (stickied > noOfEnglishOnPage / 2)
                {
                    showErrorMessage(BaseServices.createMsgByTemplate(CommonConstants.MSG_E_OVER_NUMBER,
                        CommonConstants.TXT_STICKY,
                        stickied.ToString(),
                        CommonConstants.TXT_ONE_HALF +
                        CommonConstants.SPACE +
                        CommonConstants.CF_NUM_ARTICLE_ON_EL_NAME,
                        noOfEnglishOnPage.ToString()));
                    return;
                }
                item.StickyFlg = true;
            }
            //state
            string sState = ddlState.SelectedValue.ToString();
            int iState = BaseServices.convertStringToInt(sState);
            if (iState == CommonConstants.STATE_CHECKED && item.Class == CommonConstants.AT_UNCLASSIFIED)
            {
                string message = BaseServices.createMsgByTemplate(CommonConstants.MSG_E_PLEASE_INPUT_DATA, CommonConstants.TXT_SUBJECT);
                showErrorMessage(message);
                return;
            }
            item.State = iState;

            int id = (Int32)Session[CommonConstants.SES_ID];
            //upload file
            string _fileContentSave = BaseServices.nullToBlank(txtLocation.Text);
            string _fileThumbnailSave = BaseServices.nullToBlank(txtThumbnail.Text);
            string _fileContent = CommonConstants.BLANK;
            string _fileThumbnail = CommonConstants.BLANK;
            string _folderID = txtFolderId.Text.Trim();
            bool _fileContentGood = false;
            bool _fileThumbnailGood = false;
            //root folder
            string rootFolder = Server.MapPath("~") + "/" + CommonConstants.FOLDER_EL + _folderID;
            //file type allow
            string fileTypes = control.getValueString(CommonConstants.CF_FILE_TYPE_ALLOW);

            //size in MB
            int fileSizeMax = control.getValueByInt(CommonConstants.CF_MAX_FILE_SIZE); ;
            fileSizeMax = 1024 * 1024 * fileSizeMax;

            //upload file content
            if (fileContent.HasFile)
            {
                //check file existed: keep both
                _fileContent = bs.fileNameToSave(rootFolder + "/" + fileContent.FileName);
                //filename = newFileName;

                //check filetype
                if (!bs.checkFileType(fileContent.FileName, fileTypes))
                {
                    showErrorMessage(CommonConstants.MSG_E_FILE_SIZE_IS_NOT_ALLOW);
                    return;
                }
                //check filesize max (MB)
                if (fileContent.PostedFile.ContentLength > fileSizeMax)
                {
                    showErrorMessage(CommonConstants.MSG_E_FILE_SIZE_IS_TOO_LARGE);
                    return;
                }
                _fileContentSave = _fileContent.Substring(_fileContent.LastIndexOf(CommonConstants.FOLDER_DATA));
                _fileContentGood = true;
                item.Location = _fileContentSave;
            }
            else
            {
                if (_fileContentSave.LastIndexOf("/") > 0)
                    _fileContent = rootFolder + _fileContentSave.Substring(_fileContentSave.LastIndexOf("/"));
                else
                    _fileContent = rootFolder + _fileContentSave.Substring(_fileContentSave.LastIndexOf("\\"));

                if (!File.Exists(_fileContent))
                {
                    string src = Server.MapPath("~") + "/" + _fileContentSave;
                    File.Copy(src, _fileContent);
                    File.Delete(src);
                    _fileContentSave = _fileContent.Substring(_fileContent.LastIndexOf(CommonConstants.FOLDER_DATA));
                    item.Location = _fileContentSave;
                }
            }

            //upload thumbnail
            if (fileThumbnail.HasFile)
            {
                //check file existed: keep both
                _fileThumbnail = Path.GetFileNameWithoutExtension(_fileContentSave) +
                            "_thumbnail" + Path.GetExtension(fileThumbnail.FileName);

                _fileThumbnail = bs.fileNameToSave(rootFolder + "/" + _fileThumbnail);
                //filename = rootFolder + newFileName;

                //check filetype
                fileTypes = control.getValueString(CommonConstants.CF_IMG_FILE_TYPE_ALLOW);
                if (!bs.checkFileType(fileThumbnail.FileName, fileTypes))
                {
                    showErrorMessage(CommonConstants.MSG_E_FILE_SIZE_IS_NOT_ALLOW);
                    return;
                }
                //check filesize max (KB)
                fileSizeMax = control.getValueByInt(CommonConstants.CF_IMG_FILE_SIZE_MAX);
                fileSizeMax = 1024 * fileSizeMax;
                if (fileThumbnail.PostedFile.ContentLength > fileSizeMax)
                {
                    showErrorMessage(CommonConstants.MSG_E_FILE_SIZE_IS_TOO_LARGE);
                    return;
                }
                _fileThumbnailSave = _fileThumbnail.Substring(_fileContent.LastIndexOf(CommonConstants.FOLDER_DATA));
                _fileThumbnailGood = true;
                item.Thumbnail = _fileThumbnailSave;
            }
            else if (_fileThumbnailSave != CommonConstants.BLANK)
            {
                if (!_fileThumbnailSave.Contains(CommonConstants.FOLDER_DEFAULT_IMG))
                {
                    if (_fileThumbnailSave.LastIndexOf("/") > 0)
                        _fileThumbnail = rootFolder + _fileThumbnailSave.Substring(_fileThumbnailSave.LastIndexOf("/"));
                    else
                        _fileThumbnail = rootFolder + _fileThumbnailSave.Substring(_fileThumbnailSave.LastIndexOf("\\"));

                    if (!File.Exists(_fileThumbnail))
                    {
                        string src = Server.MapPath("~") + "/" + _fileThumbnailSave;
                        File.Copy(src, _fileThumbnail);
                        File.Delete(src);
                        _fileThumbnailSave = _fileThumbnail.Substring(_fileThumbnail.LastIndexOf(CommonConstants.FOLDER_DATA));
                        item.Thumbnail = _fileThumbnailSave;
                    }
                }
            }

            //end
            bool isOk = false;

            try
            {
                isOk = englishDAO.updateEnglish(id, item);
            }
            catch (Exception ex)
            {
                writeException(ex);
            }

            if (isOk)
            {
                if (_fileContentGood)
                {
                    string folder = Path.GetDirectoryName(_fileContent);
                    if (!Directory.Exists(folder))
                        Directory.CreateDirectory(folder);

                    fileContent.SaveAs(_fileContent);
                }
                if (_fileThumbnailGood)
                {
                    string folder = Path.GetDirectoryName(_fileThumbnail);
                    if (!Directory.Exists(folder))
                        Directory.CreateDirectory(folder);

                    fileThumbnail.SaveAs(_fileThumbnail);
                }

                int stickiedArticle = englishDAO.countStickyArticle();
                statDAO.setValue(CommonConstants.SF_NUM_STICKED_ON_EL, stickiedArticle.ToString());
                Session[CommonConstants.SES_INFORM] = BaseServices.createMsgByTemplate(CommonConstants.MSG_I_ACTION_SUCCESSFUL, CommonConstants.ACT_EDIT);
            }
            else
            {
                Session[CommonConstants.SES_INFORM] = BaseServices.createMsgByTemplate(CommonConstants.MSG_E_ACTION_FAILED, CommonConstants.ACT_EDIT);
            }
            Response.Redirect(CommonConstants.PAGE_ADMIN_ENGLISH);
        }
예제 #2
0
        /// <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;
        }
예제 #3
0
        /// <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;
        }
예제 #4
0
		private void detach_tblEnglishes1(tblEnglish entity)
		{
			this.SendPropertyChanging();
			entity.tblUser1 = null;
		}
예제 #5
0
        /// <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;
        }
예제 #6
0
		private void attach_tblEnglishes(tblEnglish entity)
		{
			this.SendPropertyChanging();
			entity.tblUser = this;
		}
예제 #7
0
 partial void DeletetblEnglish(tblEnglish instance);
예제 #8
0
 partial void UpdatetblEnglish(tblEnglish instance);
예제 #9
0
 partial void InserttblEnglish(tblEnglish instance);
예제 #10
0
        /// <summary>
        /// build article for english
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private string buildArticleForEnglish(tblEnglish item)
        {
            string data = CommonConstants.BLANK;
            try
            {

                BaseServices bs = new BaseServices();
                data += "              <div class='block_details'>\n"
                        + "                <div class='block_details_img'>\n"
                        + "                    <span title='" + item.Title + "'>"
                        + BaseServices.createMsgByTemplate(CommonConstants.TEMP_IMG_THUMBNAIL, bs.getThumbnail(item.Thumbnail, item.Location),item.Title.Trim())
                        + "</span>\n"
                        + "                </div>\n"
                        + "                <div class='block_details_title'>\n"
                        + "                    <span title='" + item.Title + "'>"
                        + BaseServices.createMsgByTemplate(CommonConstants.TEMP_ARTICLE_DETAILS_LINK, CommonConstants.SEC_ENGLISH_CODE, item.ID.ToString(), bs.subString(item.Title))
                        + "                </div>\n"
                        + "            </div>\n";
            }
            catch (Exception ex)
            {
                log.writeLog(Server.MapPath(CommonConstants.PATH_LOG_FILE), ex.Message
                                                                            + CommonConstants.NEWLINE
                                                                            + ex.Source
                                                                            + CommonConstants.NEWLINE
                                                                            + ex.StackTrace
                                                                            + CommonConstants.NEWLINE
                                                                            + ex.HelpLink);
                Session[CommonConstants.SES_ERROR] = CommonConstants.MSG_E_COMMON_ERROR_TEXT;
                Response.Redirect(CommonConstants.PAGE_ERROR);
            }
            return data;
        }