RealtyManager.cs

Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 using HouseOver.THARM.CustomerCatalogue.Compares;
00005 using HouseOver.THARM.Search;
00006 using HouseOver.THARM.Buildings;
00007 using System.Reflection;
00008 using HouseOver.THARM.Attributes;
00009 
00010 namespace HouseOver.THARM
00011 {
00015     public class RealtyManager
00016     {
00017         private UserInterface ui = new UserInterface();
00018         private CatalogueData data;
00019         
00024         public RealtyManager(CatalogueData data)
00025         {
00026             this.data = data;
00027         }
00028 
00032         public void Run()
00033         {
00034             ShowMainMenu();
00035         }
00036 
00037         #region Functionality
00038 
00043         public IList<Customer> GetAllCustomersByEarliestSale() 
00044         {
00045             List<Customer> results = data.CustomersWithSales;
00046             results.Sort(new SalePutUpDateComparer(data));
00047             
00048             return results;
00049         }
00050 
00055         public IList<Customer> GetAllCustomersByPriciestProfile()
00056         {
00057             List<Customer> results = data.CustomersWithProfiles;
00058             results.Sort(new ProfileMaxPriceComparer(data));
00059             return results;
00060         }
00061 
00062 
00068         public List<Sale> GetAllSalesWithinMaxPrice(int maxPrice)
00069         {
00070             List<Sale> results = new List<Sale>();
00071 
00072             foreach (Sale sale in data.Sales)
00073             {
00074                 if (sale.Price <= maxPrice) results.Add(sale);
00075             }
00076 
00077             return results;
00078         }
00079 
00085         public List<Sale> FindPotentialItems(Profile p)
00086         {
00087             List<Sale> potentialSales = new List<Sale>();
00088             foreach (Sale s in data.Sales)
00089             {
00090                 if (p.SaleWithinParameters(s))
00091                     potentialSales.Add(s);
00092             }
00093             return potentialSales;
00094         }
00100         public List<Profile> FindPotentialBuyers(Sale s)
00101         {
00102             List<Profile> potentialBuyers = new List<Profile>();
00103             foreach (Profile p in data.Profiles)
00104             {
00105                 if (p.SaleWithinParameters(s))
00106                 {
00107                     potentialBuyers.Add(p);
00108                 }
00109             }
00110             potentialBuyers.Sort(SortProfileByPrice);
00111             return potentialBuyers;
00112         }
00119         public int SortProfileByPrice(Profile x, Profile y)
00120         {
00121             return y.MaxPrice.CompareTo(x.MaxPrice);
00122         }
00123 
00124         #endregion
00125 
00126         #region User Interface
00127 
00131         private void ShowMainMenu()
00132         {
00133             string mainMenu = "                      W e l c o m e   t o   T H A R M !                        ";
00134             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00135             menuItems.Add("customers", "Customers");
00136             menuItems.Add("search", "Find all sales within a maximum price");
00137             menuItems.Add("listbuyers", "Show a list of customers with profiles sorted by offer amount");
00138             menuItems.Add("listsellers", "Show a list of customers with sales sorted by earliest added");
00139 
00140             object theChoice;
00141             while (ui.DrawMenu(mainMenu, menuItems, true, out theChoice))
00142             {
00143                 switch (theChoice.ToString())
00144                 {
00145                     case "customers":
00146                         ShowCustomerMenu();
00147                         break;
00148                     case "search":
00149                         int maxPrice = ui.DrawInt("How much do you wish to pay?");
00150                         ShowMaxPriceSales(maxPrice);
00151                         break;
00152                     case "listbuyers":
00153                         ShowCustomersByBid();
00154                         break;
00155                     case "listsellers":
00156                         ShowCustomersByOldestSale();
00157                         break;
00158                     default:
00159                         ui.Draw("Show a list of customers with property for sale");
00160                         break;
00161                 }
00162             }
00163         }
00164 
00169         private void ShowMaxPriceSales(int maxPrice)
00170         {
00171             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00172             Sale selectedSale;
00173 
00174             foreach (Sale sale in GetAllSalesWithinMaxPrice(maxPrice))
00175             {
00176                 menuItems.Add(sale, sale.Item.GetType().Name + " for " + sale.Price + " at " + sale.PutUpForSale.ToLongDateString());
00177             }
00178             while (ui.DrawMenu("Find Sales by max price", menuItems, true, out selectedSale))
00179             {
00180                 ShowSale(selectedSale);
00181                 menuItems[selectedSale] = selectedSale.Item.GetType().Name + " for " + selectedSale.Price + " at " + selectedSale.PutUpForSale.ToLongDateString();
00182                 if (menuItems.Count != GetAllSalesWithinMaxPrice(maxPrice).Count)
00183                 {
00184                     menuItems.Clear();
00185                     foreach (Sale sale in GetAllSalesWithinMaxPrice(maxPrice))
00186                     {
00187                         menuItems.Add(sale, sale.Item.GetType().Name + " for " + sale.Price + " at " + sale.PutUpForSale.ToLongDateString());
00188                     }
00189                 }
00190 
00191             }
00192         }
00193 
00197         private void ShowCustomersByPotentialSales(Sale s)
00198         {
00199             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00200             Customer selectedCustomer;
00201 
00202             foreach (Profile cust in FindPotentialBuyers(s))
00203             {
00204                 if (menuItems.ContainsKey(cust.Owner) || cust.Owner == s.Seller)
00205                     continue;
00206                 menuItems.Add(cust.Owner, cust.Owner.Name + " (max price:" + cust.MaxPrice + ")");
00207             }
00208             while (ui.DrawMenu("Potential Buyers - Sorted by Max Price", menuItems, true, out selectedCustomer))
00209             {
00210                 ShowCustomer(selectedCustomer);
00211                 menuItems.Clear();
00212                 foreach (Customer cust in GetAllCustomersByEarliestSale())
00213                 {
00214                     menuItems.Add(cust, cust.Name + " (id:" + cust.ID + ")");
00215                 }
00216             }
00217         }
00218 
00222         private void ShowCustomersByOldestSale()
00223         {
00224             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00225             Customer selectedCustomer;
00226 
00227             foreach (Customer cust in GetAllCustomersByEarliestSale())
00228             {
00229                 menuItems.Add(cust, cust.Name + " (id:" + cust.ID + ")");
00230             }
00231             while (ui.DrawMenu("Customers - Sorted by oldest existing sale", menuItems, true, out selectedCustomer))
00232             {
00233                 ShowCustomer(selectedCustomer);
00234                 menuItems.Clear();
00235                 foreach (Customer cust in GetAllCustomersByEarliestSale())
00236                 {
00237                     menuItems.Add(cust, cust.Name + " (id:" + cust.ID + ")");
00238                 }
00239             }
00240         }
00241 
00245         private void ShowCustomersByBid()
00246         {
00247             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00248             Customer selectedCustomer;
00249 
00250             foreach (Customer cust in GetAllCustomersByPriciestProfile())
00251             {
00252                 menuItems.Add(cust, cust.Name + " (id:" + cust.ID + ")");
00253             }
00254             while (ui.DrawMenu("Customers - Sorted by highest bid on item", menuItems, true, out selectedCustomer))
00255             {
00256                 ShowCustomer(selectedCustomer);
00257                 menuItems.Clear();
00258                 foreach (Customer cust in GetAllCustomersByPriciestProfile())
00259                 {
00260                     menuItems.Add(cust, cust.Name + " (id:" + cust.ID + ")");
00261                 }
00262             }
00263         }
00264 
00268         private void ShowCustomerMenu()
00269         {
00270             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00271             string selection;
00272 
00273             menuItems.Add("list", "List Customers (" + data.Count + ")");
00274             menuItems.Add("add", "Add New Customer");
00275 
00276             while (ui.DrawMenu("Customers", menuItems, true, out selection))
00277             {
00278                 switch(selection) 
00279                 {
00280                     case "list":
00281                         ShowCustomerList();
00282                         break;
00283                     case "add":
00284                         AddCustomer();
00285                         break;
00286                 }
00287                 menuItems["list"] = "List Customers (" + data.Count + ")";
00288             }
00289         }
00290 
00294         private void ShowCustomerList()
00295         {
00296             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00297             Customer selectedCustomer;
00298 
00299             foreach (Customer cust in data)
00300             {
00301                 menuItems.Add(cust, cust.Name + " (id:" + cust.ID + ")");
00302             }
00303             while (ui.DrawMenu("Customers - List", menuItems, true, out selectedCustomer))
00304             {
00305                 ShowCustomer(selectedCustomer);
00306                 menuItems.Clear();
00307                 foreach (Customer cust in data)
00308                 {
00309                     menuItems.Add(cust, cust.Name + " (id:" + cust.ID + ")");
00310                 }
00311             }
00312         }
00313 
00318         private void ShowCustomer(Customer customer)
00319         {
00320             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00321             string selection;
00322 
00323             menuItems.Add("postal", "Change Postal Code (" + customer.Postalcode + ")");
00324             menuItems.Add("find", "Find all potential sales");
00325             menuItems.Add("addSale", "Add Sale");
00326             menuItems.Add("addProfile", "Add Profile");
00327             menuItems.Add("sales", "Show Sales (" + data.GetSales(customer).Count + ")");
00328             menuItems.Add("profiles", "Show Profiles (" + data.GetProfiles(customer).Count + ")");
00329             menuItems.Add("delete", "Delete customer");
00330 
00331             while (ui.DrawMenu("Customer (" +customer.Name+ ") ", menuItems, true, out selection))
00332             {
00333                 switch (selection)
00334                 {
00335                     case "postal":
00336                         string r = ui.Draw("Input new Postal Code:");
00337                         try
00338                         {
00339                             int i = Int32.Parse(r);
00340                             customer.Postalcode = i;
00341                             menuItems["postal"] = "Change Postal Code (" + customer.Postalcode + ")";
00342                          }
00343                         catch { }
00344                         break;
00345                     case "addProfile":
00346                         ShowAddProfile(customer);
00347                         menuItems["profiles"] = "Show Profiles (" + data.GetProfiles(customer).Count + ")";
00348                         break;
00349                     case "find":
00350                         ShowMatchingSales(customer);
00351                         break;
00352                     case "addSale":
00353                         ShowAddSale(customer);
00354                         menuItems["sales"] = "Show Sales (" + data.GetSales(customer).Count + ")";
00355                         break;
00356                     case "sales":
00357                         ShowSales(customer);
00358                         menuItems["sales"] = "Show Sales (" + data.GetSales(customer).Count + ")";
00359                         break;
00360                     case "profiles":
00361                         ShowProfiles(customer);
00362                         menuItems["profiles"] = "Show Profiles (" + data.GetProfiles(customer).Count + ")";
00363                         break;
00364                 }
00365                 if (selection == "delete")
00366                 {
00367                     string delete = ui.Draw("Are you certain you want to delete this customer? (Type \"YES\" to confirm)");
00368                     if (delete.ToLower() == "yes")
00369                         data.Remove(customer);
00370                     break;
00371                 }
00372             }
00373         }
00374 
00379         private void ShowSales(Customer customer)
00380         {
00381             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00382             Sale selectedSale;
00383 
00384             foreach (Sale sale in data.GetSales(customer))
00385             {
00386                 menuItems.Add(sale, sale.Item.GetType().Name + " for " + sale.Price + " at " + sale.PutUpForSale.ToLongDateString());
00387             }
00388             while (ui.DrawMenu("Customer (" + customer.Name + ") - Sales", menuItems, true, out selectedSale))
00389             {
00390                 ShowSale(selectedSale);
00391                 menuItems[selectedSale] = selectedSale.Item.GetType().Name + " for " + selectedSale.Price + " at " + selectedSale.PutUpForSale.ToLongDateString();
00392                 if (menuItems.Count != data.GetSales(customer).Count)
00393                 {
00394                     menuItems.Clear();
00395                     foreach (Sale sale in data.GetSales(customer))
00396                     {
00397                         menuItems.Add(sale, sale.Item.GetType().Name + " for " + sale.Price + " at " + sale.PutUpForSale.ToLongDateString());
00398                     }
00399                 }
00400                     
00401             }
00402         }
00403 
00408         private void ShowSale(Sale sale)
00409         {
00410             string selectedItem = null;
00411             string header = "Customer (" + sale.Seller.Name + ") - Sale (" + sale.Item.GetType().Name + " @ " + sale.PutUpForSale.ToShortDateString() + ")" + System.Environment.NewLine + System.Environment.NewLine + "   ";
00412 
00413 
00414             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00415             menuItems.Add("find", "Find Potential Buyers");
00416             menuItems.Add("details", "Change Item Details");
00417             menuItems.Add("delete", "Delete Sale");
00418 
00419             while (ui.DrawMenu(header + "Select an item:", menuItems, true, out selectedItem))
00420             {
00421                 if (selectedItem == "delete")
00422                 {
00423                     string confirm = ui.Draw("Are you sure you want to delete this sale? (type \"YES\")");
00424                     if (confirm.ToLower() == "yes")
00425                     {
00426                         data.Remove(sale);
00427                         break;
00428                     }
00429                 }
00430                 else if (selectedItem == "details")
00431                 {
00432                     ShowSaleDetails(sale);
00433                 }
00434                 else if (selectedItem == "find")
00435                 {
00436                     ShowCustomersByPotentialSales(sale);
00437                 }
00438             } 
00439         }
00440         
00445         private void ShowSaleDetails(Sale sale)
00446         {
00447             object selectedItem = null;
00448             string header = "Customer (" + sale.Seller.Name + ") - Sale Details ("+sale.Item.GetType().Name+" @ "+sale.PutUpForSale.ToShortDateString()+")" + System.Environment.NewLine + System.Environment.NewLine + "   ";
00449 
00450 
00451             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00452             menuItems.Add("price", "Set price (" + sale.Price + ")");
00453             PropertyInfo[] pis = sale.Item.GetType().GetProperties();
00454             foreach (PropertyInfo pi in pis)
00455             {
00456                 SaleCriteria sc = (SaleCriteria)Attribute.GetCustomAttribute(pi, typeof(SaleCriteria));
00457                 if (sc == null)
00458                     continue;
00459                 string propertyName = sc.HumanReadableName != null ? sc.HumanReadableName : pi.Name;
00460                 
00461                 string value = pi.GetValue(sale.Item, new object[]{}).ToString();
00462                 menuItems.Add(pi, "Set " + propertyName + " (" + value + ")");
00463             }
00464 
00465 
00466 
00467             while (ui.DrawMenu(header + "Select an item to change its value:", menuItems, true, out selectedItem))
00468             {
00469                 if (selectedItem is PropertyInfo)
00470                 {
00471                     SaleCriteria sc = (SaleCriteria)Attribute.GetCustomAttribute(selectedItem as PropertyInfo, typeof(SaleCriteria));
00472                     if (sc == null)
00473                         continue;
00474                     string propertyName = sc.HumanReadableName != null ? sc.HumanReadableName : ((PropertyInfo)selectedItem).Name;
00475 
00476                     SetValueOfProperty(selectedItem as PropertyInfo, propertyName, sale.Item, header);
00477                     menuItems[selectedItem] = "Set " + propertyName + " (" + ((PropertyInfo)selectedItem).GetValue(sale.Item, new object[] { }).ToString() + ")";
00478                 }
00479                 else if (selectedItem is string && ((string)selectedItem) == "price")
00480                 {
00481                     sale.Price = ui.DrawInt(header + "Input new price for item:");
00482                     menuItems["price"] = "Set price (" + sale.Price + ")";
00483                 }
00484             } 
00485         }
00486 
00491         private void ShowAddSale(Customer customer)
00492         {
00493             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00494 
00495             List<Type> types = Item.GetSearchableItems();
00496             foreach (Type t in types)
00497             {
00498                 menuItems.Add(t, t.Name);
00499             }
00500 
00501             string header = "Customer (" + customer.Name + ") - Add Sale" + System.Environment.NewLine + System.Environment.NewLine + "   ";
00502 
00503             Type selected;
00504             if (!ui.DrawMenu(header + "Select the type of item you are selling:", menuItems, true, out selected))
00505                 return;
00506 
00507             int price = ui.DrawInt(header + "Input selling price:");
00508             DateTime date = DateTime.Now;
00509 
00510             object instance = ShowMakeItem(header, selected);
00511             Sale sale = new Sale(price, date, (Item)instance, customer);
00512             data.Add(sale);
00513         }
00514 
00521         private object ShowMakeItem(string header, Type type)
00522         {
00523             ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes);
00524             object instance = ci.Invoke(new object[] { });
00525             
00526 
00527             PropertyInfo[] pis = type.GetProperties();
00528             foreach (PropertyInfo pi in pis)
00529             {
00530                 SaleCriteria sc = (SaleCriteria)Attribute.GetCustomAttribute(pi, typeof(SaleCriteria));
00531                 if (sc == null)
00532                     continue;
00533                 string propertyName = sc.HumanReadableName != null ? sc.HumanReadableName : pi.Name;
00534 
00535                 SetValueOfProperty(pi, propertyName, instance, header);
00536             }
00537             return instance;
00538         }
00539 
00547         private void SetValueOfProperty(PropertyInfo pi, string propertyName, object instance, string header)
00548         {
00549             if (pi.PropertyType.IsEnum)
00550             {
00551                 Dictionary<object, string> menuItems = new Dictionary<object, string>();
00552                 Enum selectedEnum;
00553 
00554                 foreach (Enum e in Enum.GetValues(pi.PropertyType))
00555                 {
00556                     menuItems.Add(e, e.ToString());
00557                 }
00558 
00559                 if (menuItems.Count > 0 && ui.DrawMenu(header + "Select " + propertyName, menuItems, false, out selectedEnum))
00560                     pi.SetValue(instance, selectedEnum, null);
00561             }
00562             else if (pi.PropertyType.FindInterfaces(Profile.MyInterfaceFilter, "System.IComparable").Length > 0)
00563             {
00564                 string s = ui.Draw(header + "Input " + propertyName + ":");
00565                 try
00566                 {
00567                     pi.SetValue(instance, Convert.ChangeType(s, pi.PropertyType), null);
00568                 }
00569                 catch
00570                 {
00571                     // darnit
00572                 }
00573             }
00574         }
00575 
00580         private void ShowProfiles(Customer customer)
00581         {
00582             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00583             Profile selectedProfile;
00584 
00585             foreach (Profile profile in data.GetProfiles(customer))
00586             {
00587                 menuItems.Add(profile, profile.Item.Name + " with a max price of " + profile.MaxPrice);
00588             }
00589             while (ui.DrawMenu("Customer (" + customer.Name + ") - Profiles", menuItems, true, out selectedProfile))
00590             {
00591                 ShowProfile(selectedProfile);
00592                 menuItems[selectedProfile] = selectedProfile.Item.Name + " with a max price of " + selectedProfile.MaxPrice;
00593                 if (menuItems.Count != data.GetProfiles(customer).Count)
00594                 {
00595                     menuItems.Clear();
00596                     foreach (Profile profile in data.GetProfiles(customer))
00597                     {
00598                         menuItems.Add(profile, profile.Item.Name + " with a max price of " + profile.MaxPrice);
00599                     }
00600                 }
00601             }
00602         }
00603 
00607         private void AddCustomer()
00608         {
00609             UserInterface ui = new UserInterface();
00610             string name;
00611             int postalcode;
00612             string step1 = "Customers - Add" + System.Environment.NewLine + System.Environment.NewLine + "   Please enter the customer's name:";
00613             string step2 = "Customers - Add" + System.Environment.NewLine + System.Environment.NewLine + "   Please enter the customer's postal code:";
00614 
00615             name = ui.Draw(step1);
00616             if (string.IsNullOrEmpty(name))
00617                 return;
00618             postalcode = ui.DrawInt(step2);
00619 
00620             Customer theCustomer = new Customer(postalcode, name);
00621             data.Add(theCustomer);
00622         }
00623 
00628         private void ShowAddProfile(Customer c)
00629         {
00630             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00631 
00632             List<Type> types = Item.GetSearchableItems();
00633             foreach (Type t in types)
00634             {
00635                 menuItems.Add(t, t.Name);
00636             }
00637             Type selected;
00638             if (!ui.DrawMenu("Customer ("+c.Name+") - Add Profile" + System.Environment.NewLine + System.Environment.NewLine + "   Select the type of item you are searching for:", menuItems, true, out selected))
00639                 return;
00640 
00641             int maxPrice = ui.DrawInt("Customer (" + c.Name + ") - Add Profile" + System.Environment.NewLine + System.Environment.NewLine + "   What is the maximum price you're willing to pay for this " + selected.Name + ":");
00642             Profile p = new Profile(c, maxPrice, selected);
00643             data.Add(p);
00644             ShowProfile(p);
00645         }
00646 
00651         private void ShowProfile(Profile profile)
00652         {
00653             string selectedItem = null;
00654             string header = "Customer (" + profile.Owner.Name + ") - Profile (" + profile.Item.Name + ")" + System.Environment.NewLine + System.Environment.NewLine + "   ";
00655 
00656 
00657             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00658             menuItems.Add("find", "Find Matching Sales");
00659             menuItems.Add("details", "Set Profile Search Criteria");
00660             menuItems.Add("delete", "Delete Profile");
00661 
00662             while (ui.DrawMenu(header + "Select an item:", menuItems, true, out selectedItem))
00663             {
00664                 if (selectedItem == "delete")
00665                 {
00666                     string confirm = ui.Draw("Are you sure you want to delete this profile? (type \"YES\")");
00667                     if (confirm.ToLower() == "yes")
00668                     {
00669                         data.Remove(profile);
00670                         break;
00671                     }
00672                 }
00673                 else if (selectedItem == "details")
00674                 {
00675                     ShowProfileDetails(profile);
00676                 }
00677                 else if (selectedItem == "find")
00678                 {
00679                     ShowMatchingSales(profile);
00680                 }
00681             } 
00682         }
00687         private void ShowMatchingSales(Customer c)
00688         {
00689             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00690             Sale selectedSale;
00691 
00692             foreach(Profile profile in data.GetProfiles(c))
00693                 foreach (Sale sale in FindPotentialItems(profile))
00694                 {
00695                     menuItems.Add(sale, sale.Item.GetType().Name + " for " + sale.Price + " at " + sale.PutUpForSale.ToLongDateString());
00696                 }
00697             while (ui.DrawMenu("Customer (" + c.Name + ") - Matching Sales", menuItems, true, out selectedSale))
00698             {
00699                 ShowSale(selectedSale);
00700                 menuItems[selectedSale] = selectedSale.Item.GetType().Name + " for " + selectedSale.Price + " at " + selectedSale.PutUpForSale.ToLongDateString();
00701             }
00702         }
00707         private void ShowMatchingSales(Profile c)
00708         {
00709             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00710             Sale selectedSale;
00711 
00712                 foreach (Sale sale in FindPotentialItems(c))
00713                 {
00714                     menuItems.Add(sale, sale.Item.GetType().Name + " for " + sale.Price + " at " + sale.PutUpForSale.ToLongDateString());
00715                 }
00716             while (ui.DrawMenu("Customer (" + c.Owner.Name + ") - Matching Sales", menuItems, true, out selectedSale))
00717             {
00718                 ShowSale(selectedSale);
00719                 menuItems[selectedSale] = selectedSale.Item.GetType().Name + " for " + selectedSale.Price + " at " + selectedSale.PutUpForSale.ToLongDateString();
00720             }
00721         }
00726         private void ShowProfileDetails(Profile p)
00727         {
00728             object check = null;
00729 
00730             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00731             menuItems.Add("price", "Max paying price (" + p.MaxPrice + ")");
00732             foreach (Check c in p.Checks.Values)
00733             {
00734                 ComparableCheck comparableCheck = c as ComparableCheck;
00735                 EnumCheck enumCheck = c as EnumCheck;
00736 
00737                 if (comparableCheck != null && comparableCheck.MinValue != null && comparableCheck.MaxValue != null && comparableCheck.FieldRequired)
00738                 {
00739                     menuItems.Add(c, comparableCheck.HumanReadableName + " (" + comparableCheck.MinValue + "-" + comparableCheck.MaxValue + ")");
00740                 }
00741                 else if (enumCheck != null && enumCheck.FieldRequired)
00742                 {
00743                     menuItems.Add(c, enumCheck.HumanReadableName + " (" + enumCheck.Value + ")");
00744                 }
00745                 else
00746                     menuItems.Add(c, c.HumanReadableName);
00747             }
00748 
00749             while (ui.DrawMenu("Customer (" + p.Owner.Name + ") - Profile Details (" + p.Item.Name + ")" + System.Environment.NewLine + System.Environment.NewLine + "   Select a criteria to set your preference:", menuItems, true, out check)) 
00750             {
00751                 Check cc;
00752                 if ((cc = check as ComparableCheck) != null)
00753                 {
00754                     SetComparableCheck(p, (ComparableCheck)check);
00755                     menuItems[check] = cc.FieldRequired ? cc.HumanReadableName + " (" + ((ComparableCheck)cc).MinValue + "-" + ((ComparableCheck)cc).MaxValue + ")" : cc.HumanReadableName;
00756                 }
00757                 else if ((cc = check as EnumCheck) != null)
00758                 {
00759                     SetEnumCheck(p, (EnumCheck)check);
00760                     menuItems[check] = cc.FieldRequired ? cc.HumanReadableName + " (" + ((EnumCheck)check).Value + ")" : cc.HumanReadableName;
00761                 }
00762                 else if (check is string && check.ToString() == "price")
00763                 {
00764                     p.MaxPrice = ui.DrawInt("Customer ({0}) - Profile ({1}) - Max paying price" + System.Environment.NewLine + System.Environment.NewLine + "   Enter maximum paying price:", p.Owner.Name, p.Item.Name);
00765                     menuItems["price"] = "Max paying price (" + p.MaxPrice + ")";
00766                 }
00767             }
00768         }
00769 
00775         private void SetComparableCheck(Profile p, ComparableCheck check)
00776         {
00777             string s = ui.Draw("Customer ({0}) - Profile ({1}) - Check ({2})" + System.Environment.NewLine + System.Environment.NewLine + "   Enter minimum value (if empty, this criteria is ignored):", p.Owner.Name, p.Item.Name, check.HumanReadableName);
00778             if (!string.IsNullOrEmpty(s))
00779             {
00780                 check.MinValue = s;
00781                 check.MaxValue = ui.Draw("Customer ({0}) - Profile ({1}) - Check ({2})" + System.Environment.NewLine + System.Environment.NewLine + "   Enter maximum value:", p.Owner.Name, p.Item.Name, check.HumanReadableName);
00782             }
00783             else
00784                 check.MinValue = null;
00785             if (check.MinValue == null || check.MaxValue == null)
00786                 check.FieldRequired = false;
00787             else
00788                 check.FieldRequired = true;
00789         }
00790 
00796         private void SetEnumCheck(Profile p, EnumCheck check)
00797         {
00798             Dictionary<object, string> menuItems = new Dictionary<object, string>();
00799             Enum selectedEnum;
00800 
00801             foreach (Enum e in Enum.GetValues(check.FieldType))
00802             {
00803                 menuItems.Add(e, e.ToString());
00804             }
00805             
00806             if (ui.DrawMenu("Customer ("+p.Owner.Name+") - Profile ("+p.Item.Name+") - Check ("+check.HumanReadableName+")", menuItems, true, out selectedEnum))
00807             {
00808                 check.Value = selectedEnum;
00809                 check.FieldRequired = true;
00810             } else
00811                 check.FieldRequired = false;
00812         }
00813         
00814         
00815         #endregion
00816     }
00817 }

Generated on Wed Jan 10 03:42:42 2007 for THARM by  doxygen 1.5.1-p1