⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 posteditcontrol.ascx.cs

📁 community server 源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.Load += new System.EventHandler(this.Page_Load);
		}

		#endregion

		
		public int Save()
		{
			if (!Page.IsValid)
				return -2;

			GalleryPost post = null;

			if (context.PostID > 0)
				post = GalleryPosts.GetPicture(context.PostID);
			else
			{
				post = new GalleryPost();
				post.Username = context.User.Username;
				post.SectionID = CurrentGallery.SectionID;
				post.ParentID = 0;
				post.GalleryPostType = this.PostType;
				post.PostID = -1;

			}

			if(postName.Text.Length > 0)
			{
				GalleryThreadQuery query = new GalleryThreadQuery();

				query.PostName = postName.Text;
				query.RequireSectionIsActive = false;

				ThreadSet ts = GalleryPosts.GetPictures(query, false);

				if(ts.TotalRecords > 0)
				{
					int PostIDfromName = ((Post)ts.Threads[0]).PostID ;
					if (PostIDfromName!= post.PostID)
					{
						Status.Success = false;
						Status.ResourceName = "Weblog_Exception_DuplicatePostName";
						Status.Visible = true;
						return -2;
					}
				}
			}

			post.Name = postName.Text;
			post.Subject = ServerFriendlyFileName.Text;
			post.Excerpt = postExcerpt.Text;	
			post.Body = PostBody.Text;
			post.PostType = PostContentType.HTML;
			post.FormattedBody = null;

			PopulateFromYesNo(post);

			if (CurrentGallery.CategorizationType == CategorizationType.Album)
			{
				post.Categories = CategoryChecklist1.SelectedNodeNames();
			}
			else
			{
				post.Categories = Tags.SelectedTags;
			}

			post.ModerationType = (CommentModerationType) Enum.Parse(typeof (CommentModerationType), ModerationDDL.SelectedValue, false);

			post.UserTime = GetDate();
			post.PostDate = UserTime.ConvertToServerTime(GetDate());
			post.FeedbackNotificationType = NotificationType.SelectedValue;

			//TODO: Seperate post attachment handeling so we dont use the createpost function to update attacments
			
			PostAttachment pa = null;
			if(!Globals.IsNullorEmpty(ServeruploadtempID.Value))
			{
				GalleryAttachmentSettings fs = GalleryConfiguration.Instance().AttachmentSettings;
				Guid g = new Guid(ServeruploadtempID.Value);
				pa = PostAttachments.ToggleTemporary(g,this.ServerFriendlyFileName.Text, !fs.EnableDataStoreStorage, post.PostID,this.CurrentGallery.SectionID,context.User.UserID,0,0,true);

			}

			if(pa != null)
			{
				int diskQuota = CurrentGallery.GetActiveQuota(GalleryQuotaType.Disk);
				int imageQuota = CurrentGallery.GetActiveQuota(GalleryQuotaType.Image);
				
				bool withinDiskQuota = false;
				try{withinDiskQuota = pa.Length + CurrentGallery.DiskUsage <= diskQuota || diskQuota == -1;}
				catch{}
				
				bool withinImageQuota = imageQuota - CurrentGallery.PostCount > 0 || imageQuota == -1;

				if(withinDiskQuota && withinImageQuota)
				{
				GalleryPosts.CreatePicture(CurrentGallery.SectionID, post, pa);

				//make the thumbnail
				ImageHandling.ScalePicture(post, CurrentGallery.GetThumbnailSettings());
				}
				else
				{
					Status.Success = false;
					if(!withinDiskQuota)
					{
						Status.ResourceName = "CP_Photos_PostEdit_DiskQuota_Exceeded";
					}
					else
					{
						Status.ResourceName = "CP_Photos_PostEdit_ImageQuota_Exceeded";
					}
					Status.Visible = true;
					return -2;
				}
			}
			else
			{
				GalleryPosts.UpdatePicture(post);
			}

			//Find a relevant category to send the user to (instead of sending them to the whole picture list)
			int cid = context.GetIntFromQueryString("cid", -1); //First try the querystring for a hint
			if(cid == -1)
				cid = CategoryChecklist1.GetFirstSelectedNodeID();

			// expire the category cache if text-based categories were added
			PostCategories.ExpireCategoryCache(post.SectionID);

			return cid;

		}

		private void SetDate(DateTime dt)
		{
			DatePicker.SelectedDate = dt;
			int h = dt.Hour;
            if(h == 0)
            {
                h=12;
                AMPM.SelectedIndex = 0;
            }
			else if (h == 12)
			{
				AMPM.SelectedIndex = 1;
			}
			else if(h > 12)
            {
                h = h-12;
                AMPM.SelectedIndex = 1;
            }
			HourPicker.SetSelected(h);
			MinutePicker.SetSelected(dt.Minute);
			//AMPM.Items.FindByValue(dt.ToString("tt")).Selected = true;
		}

		private DateTime GetDate()
		{
			int minute = MinutePicker.GetSelected;
			int hour = HourPicker.GetSelected;
			if(AMPM.SelectedValue == "AM")
			{
				if(hour == 12)
					hour = 0;
			}
			else
			{
				if(hour != 12)
					hour += 12;
			}

			return new DateTime(DatePicker.SelectedDate.Year,DatePicker.SelectedDate.Month,DatePicker.SelectedDate.Day,hour,minute,0);
		}

		[AjaxMethod(IncludeControlValuesWithCallBack=false)]
		public string PreviewPost(string text)
		{
			GalleryPost post = new GalleryPost();

			post.Body = text;
			post.Subject = null;

			GalleryPosts.PreviewFormat(post);

			return post.FormattedBody;
		}

		[AjaxMethod(IncludeControlValuesWithCallBack=false)]
		public string PreviewAttachment(string AttachmentID)
		{
			string imageURL = "noimg.gif";
			string imageName = "No Image";
			int imageHeight = 200;
			int imageWidth = 300;

			string imageTag = string.Format("<img src=\"{0}\" width={1} height={2} alt=\"{3}\" />",imageURL,imageWidth, imageHeight, imageName);
			GalleryPost post;

			if(IsInteger(AttachmentID))
			{
				post = GalleryPosts.GetPicture(int.Parse(AttachmentID) ); 
				imageURL =  GalleryUrls.Instance().SecondaryThumbnailURL(post);
				imageName = post.Subject;



			}
			else
			{
				Guid guid = new Guid(AttachmentID);
				imageURL =  GalleryUrls.Instance().ViewTempAttachment(CurrentGallery.ApplicationKey, guid) ;
				imageName = "";
			}

				imageTag = string.Format("<img src=\"{0}\" alt=\"{1}\" />",imageURL, imageName);

			return imageTag;
		}

		private bool IsInteger(string i)
		{
			try
			{
				int.Parse(i);
				return true;
			}
			catch
			{
				return false;
			}
		}

		protected void ValidatePictureData(Object sender,  ServerValidateEventArgs args)
		{
			args.IsValid = ServeruploadtempID.Value.ToString().Length > 0;
		}

		private void ValidatePictureDataClient()
		{
			string script = @"<script language=""JavaScript"">
				<!--
				function CheckFileUploadID(sender, args)
				{
					var objTempID = document.getElementById('" + this.ServeruploadtempID.ClientID  + @"');
					var len = 0;
					if (objTempID != null) 
					{
						len = objTempID.value.length;
					}
	
					args.IsValid = len > 0;

				}
				// -->
				</script>";

			Page.RegisterClientScriptBlock("ValidatePictureDataClient", script) ;

		}

	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -