Go Back   EN World D&D / RPG News > Blogs > Plane Sailing

Uncategorized Entries with no category
Old

ASP.Net reminders

Posted 16th April 2009 at 12:45 PM by Plane Sailing
This is some code I'm pruning from an object but which I want to keep around

Code:
		private static int EntryIdToFind;
		public List<DiaryEntry> FindByEntryId(int entry_id)
		{
			EntryIdToFind = entry_id;
			List<DiaryEntry> list = new List<DiaryEntry>();
			list.Add(DiaryEntries.Find(FindByEntryId));
			return list;
		}

		public int FindIndexOfEntryId(int entry_id)
		{
			EntryIdToFind = entry_id;
			return DiaryEntries.FindIndex(FindByEntryId);
		}

		// Search predicate returns true if 
		private static bool FindByEntryId(DiaryEntry de)
		{
			if (EntryIdToFind == de.Entry_Id) {
				return true;
			} else {
				return false;
			}
		}

		public List<DiaryEntry> SortedDiaryList(DiarySortCriteria dsc)
		{
			switch (dsc) {
				case DiarySortCriteria.Date:
					//m_DiaryEntries.Sort(delegate(DiaryEntry de1, DiaryEntry de2) { return de1.ActivityDate.CompareTo(de2.ActivityDate); });
					m_DiaryEntries.Sort(CompareByDate);
					break;
				case DiarySortCriteria.Title:
					m_DiaryEntries.Sort(delegate(DiaryEntry de1, DiaryEntry de2) { return de1.Title.CompareTo(de2.Title); });
					break;
				case DiarySortCriteria.ActivityClass:
					m_DiaryEntries.Sort(CompareByClass);
					break;
				case DiarySortCriteria.ActivityCategory:
					m_DiaryEntries.Sort(CompareByCategory);
					break;
				case DiarySortCriteria.ActivityType:
					m_DiaryEntries.Sort(CompareByType);
					break;
				case DiarySortCriteria.DiaryStatus:
					m_DiaryEntries.Sort(CompareByStatus);
					break;
				default:
					break;
			}
			return m_DiaryEntries;
		}

		private static int CompareByDate(DiaryEntry de1, DiaryEntry de2)
		{
			if (de1 == null)
				if (de2 == null)
					return 0;
				else
					return -1;
			else {
				if (de2 == null)
					return 1;
				else {
					int retval = de1.ActivityDate.CompareTo(de2.ActivityDate);
					if (retval != 0)
						return retval;
					else
						return de1.Title.CompareTo(de2.Title);
				}
			}
		}


		private static int CompareByClass(DiaryEntry de1, DiaryEntry de2)
		{
			if (de1 == null)
				if (de2 == null)
					return 0;
				else
					return -1;
			else {
				if (de2 == null)
					return 1;
				else {
					int retval = de1.DiaryClassDescription.CompareTo(de2.DiaryClassDescription);
					if (retval != 0)
						return retval;
					else {
						int retval2 = de1.ActivityDate.CompareTo(de2.ActivityDate);
						if (retval2 != 0)
							return retval2;
						else
							return de1.Title.CompareTo(de2.Title);
					}
				}
			}
		}

		private static int CompareByCategory(DiaryEntry de1, DiaryEntry de2)
		{
			if (de1 == null)
				if (de2 == null)
					return 0;
				else
					return -1;
			else {
				if (de2 == null)
					return 1;
				else {
					int retval = de1.Activity.ActivityCategory.CompareTo(de2.Activity.ActivityCategory);
					if (retval != 0)
						return retval;
					else {
						int retval2 = de1.ActivityDate.CompareTo(de2.ActivityDate);
						if (retval2 != 0)
							return retval2;
						else
							return de1.Title.CompareTo(de2.Title);
					}
				}
			}
		}

		private static int CompareByType(DiaryEntry de1, DiaryEntry de2)
		{
			if (de1 == null)
				if (de2 == null)
					return 0;
				else
					return -1;
			else {
				if (de2 == null)
					return 1;
				else {
					int retval = de1.Activity.ActivityType.CompareTo(de2.Activity.ActivityType);
					if (retval != 0)
						return retval;
					else {
						int retval2 = de1.ActivityDate.CompareTo(de2.ActivityDate);
						if (retval2 != 0)
							return retval2;
						else
							return de1.Title.CompareTo(de2.Title);
					}
				}
			}
		}

		private static int CompareByStatus(DiaryEntry de1, DiaryEntry de2)
		{
			if (de1 == null)
				if (de2 == null)
					return 0;
				else
					return -1;
			else {
				if (de2 == null)
					return 1;
				else {
					int retval = de1.DiaryEntryStatus.CompareTo(de2.DiaryEntryStatus);
					if (retval != 0)
						return retval;
					else {
						int retval2 = de1.ActivityDate.CompareTo(de2.ActivityDate);
						if (retval2 != 0)
							return retval2;
						else
							return de1.Title.CompareTo(de2.Title);
					}
				}
			}
		}
Plane Sailing's Avatar
Astral Admin - Mwahahaha!
Posted in Uncategorized
Views 222 Comments 0 Plane Sailing is offline
Old

ASP.Net Gotchas

Posted 25th July 2008 at 11:54 AM by Plane Sailing
Just jotting a few notes down here as I've resolved another annoying little asp.net 2.0 'gotcha', in this case relating to the calendar control.

I'm using a calendar control in a gridview when a row is in update mode. My database contains some null dates for 'PaperworkReceived', but the calendar control chokes on null dates so I transform them into 1/1/1900 dates so I can give them special programatic handling.

I'm connecting to an objectdatasource which provides my interface to the database.

When 'null' dates are present, I set the selected date to 1/1/1900, but I set the visible date to todays date so that the calendar is in the correct position for someone who wants to select the date if the paperwork has just been received.

The strange thing is that even if you obtain a reference to the calendar object in the _RowUpdating procedure and set the parameter to the value of the selected date, it still passes the current date to the objectdatasource (!).

I resolved this by checking in the _RowUpdating procedure and if the selectedDate is 1/1/1900 I programatically set the view date to that just before I assign the parameters. (I've also changed the Bind() to an Eval() in the gridview code).

Code:
DateTime defaultdate = new DateTime(1900, 1, 1);
Calendar c = (Calendar)gvAuditees.Rows[e.RowIndex].FindControl("calPaperwork");
if (c.SelectedDate == defaultdate) {
	c.VisibleDate = c.SelectedDate;
} 
ObjectDataSource2.UpdateParameters.Clear();
...
ObjectDataSource2.UpdateParameters.Add("PaperworkReceived", c.SelectedDate.ToLongDateString());


I also use ToLongDateString to ensure that SQL server reliably parses the date - otherwise I get faux US mmddyy conversions happening on some installations.

Cheers
Plane Sailing's Avatar
Astral Admin - Mwahahaha!
Posted in Uncategorized
Views 341 Comments 0 Plane Sailing is offline
Old

My first blog entry

Posted 27th June 2008 at 12:31 PM by Plane Sailing
Somehow it seems appropriate that it will be on ENworld

My plan is to have some storyhour elements here, some campaign discussions, perhaps some game design thoughts.

Still, all to come after the current moderation checks, eh?

Cheers
Plane Sailing's Avatar
Astral Admin - Mwahahaha!
Posted in Uncategorized
Views 1035 Comments 4 Plane Sailing is offline
And yet another word from our sponsors
Visit Our Sponsors
Visit Our Sponsors... Again
Powered by vBadvanced CMPS v3.0.1

All times are GMT +1. The time now is 09:24 PM.


Site Contents © 2008 ENWorld
PHP Ajax Multimedia Web Framework © 2008 Digital Media Graphix
Powered by vBulletin® Version 3.8.0 Beta 1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

"Vault Data" powered by VaultWiki v2.5.1.
Copyright © 2008 - 2009, Cracked Egg Studios.