private void LoadPreferences() { preferencesLogic = new PreferencesModel(); //Group Settings LoadGroup(); //System Settings txtFileServer.Text = preferencesLogic.GetPreferencesByName("FileServer").Value; txtThumbPath.Text = preferencesLogic.GetPreferencesByName("ThumbnailPath").Value; txtWebmasterEmail.Text = preferencesLogic.GetPreferencesByName("WebmasterEmail").Value; //Module Settings cbSearchBoxModule.Checked = Boolean.Parse(preferencesLogic.GetPreferencesByName("SearchModule").Value); cbLoginBoxModule.Checked = Boolean.Parse(preferencesLogic.GetPreferencesByName("LoginModule").Value); cbMostViewRateBoxModule.Checked = Boolean.Parse(preferencesLogic.GetPreferencesByName("MostViewMostRateModule").Value); cbRandomDownloadBoxModule.Checked = Boolean.Parse(preferencesLogic.GetPreferencesByName("RandomMostDownloadModule").Value); cbCategoryModule.Checked = Boolean.Parse(preferencesLogic.GetPreferencesByName("CategoryModule").Value); txtMostViewRateBoxModuleAmount.Text = preferencesLogic.GetPreferencesByName("MostViewMostRate_Amount").Value; txtRandomDownloadBoxModuleAmount.Text = preferencesLogic.GetPreferencesByName("RandomMostDownload_Amount").Value; }
protected void btnUpload_Click(object sender, EventArgs e) { try { if (Page.IsValid) { if (fileUpload.HasFile && IsPDFFile(fileUpload.FileName)) { prefencesLogic = new PreferencesModel(); cvLetter = new ConvertLetter(); FileName = cvLetter.ClearAccent(fileUpload.FileName).ToLower().Replace(' ', '_'); FilePath = prefencesLogic.GetPreferencesByName("FileServer").Value; FileSize = fileUpload.PostedFile.ContentLength; MaxFileSize = 50 * 1024 * 1024; //Upload Thumbnails if (thumbUpload.HasFile) { String FileExtension = System.IO.Path.GetExtension(thumbUpload.FileName).ToLower(); ThumbnailFileName = System.IO.Path.GetRandomFileName(); ThumbnailPath = prefencesLogic.GetPreferencesByName("ThumbnailPath").Value; thumbUpload.SaveAs(MapPath(new Uri(ThumbnailPath).AbsolutePath + "/" + ThumbnailFileName + FileExtension)); } //Upload Document if (FileSize < MaxFileSize) { fileUpload.SaveAs(MapPath(new Uri(FilePath + @"/" + FileName).AbsolutePath)); docLogic = new DocumentModel(); collectionLogic = new CollectionModel(); tagsLogic = new TagsModel(); int addedCollectionID = 0; int addedDocumentID = 0; //Add Document if (String.IsNullOrEmpty(txtCollectionName.Text)) { addedDocumentID = docLogic.AddDocument( txtDocumentName.Text, txtDescription.Text, ThumbnailFileName, FileName, FileSize, UserID, Int32.Parse(ddlCategory.SelectedValue), ddlCollection.Items.Count != 0 ? Int32.Parse(ddlCollection.SelectedValue) : 0 ); } else { addedCollectionID = collectionLogic.AddCollection(txtCollectionName.Text, String.Empty, UserID); addedDocumentID = docLogic.AddDocument(txtDocumentName.Text, txtDescription.Text, ThumbnailFileName, FileName, FileSize, UserID, Int32.Parse(ddlCategory.SelectedValue), addedCollectionID); } //Add Tags if (!String.IsNullOrEmpty(txtTags.Text)) { tagsLogic.AddTag(txtTags.Text, addedDocumentID, null); } else { String tmpTags = txtDocumentName.Text.Replace(" ", ","); tagsLogic.AddTag(tmpTags, addedDocumentID, null); } blInfo.Items.Add("Thêm tài liệu thành công"); } else { blInfo.Items.Add("Dung lượng file cho phép không quá 50MB"); } } else { blInfo.Items.Add("Sai định dạng file. Chỉ cho phép định dạng PDF"); } } } catch (ApplicationException ex) { blInfo.Items.Clear(); blInfo.Items.Add(ex.Message); } }