Advertisement
GlobalAccessSoftware

Example of Creating Custom Data Types & Use

Jul 12th, 2017
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.01 KB | None | 0 0
  1.  
  2.  
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  4. // Person.cs & Class v4.7.5.14
  5. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  6. // For when I get time to do the data
  7. // file and DBS right and everything.
  8. // Conceived 08 Jun 17 by -JpE-
  9. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  10. // idkwtfiad! 26Jun17 Learning LoL!
  11. // v4.7.6.40 29Jun17
  12. // Data Layer for MLBB in Design.
  13. // v4.7.6.38 28Jun17 Looking Better!
  14. // v4.7.6.41 30Jun17 Awesome and ready
  15. // to begin Beta Testing real hard next
  16. // week while it's hot. I'm looking at
  17. // some of this code lately and W0W! ;-)
  18. // v5.7.6.45 06Jul17 Tested and Brought
  19. // in the relevant InfoForm Class Stuff.
  20. // 11.Jul.17 Perfected & Formatted.
  21. // *** Now it's clean & integrated! ***
  22. // v5.7.7.77 11-Aug-2017 Back2 1Project.
  23. // protected internal properties now
  24. // for ShowMeEdit.cs
  25. // v5.7.7.87 20-Aug-2017
  26. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  27. // v5.7.7.95 24-Aug-2017  OverHaul Deluxe!
  28. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  29. // NOTE: This File has parts of 3 Classes!
  30. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  31. // InfoForm / PersonForm / and the entire
  32. // Person Class. All Related2The Analyzer.
  33. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  34.  
  35. using System;
  36. using System.IO;
  37. using System.Linq;
  38. using System.Windows.Forms;
  39. using System.Globalization;
  40. using System.Collections.Generic;
  41. using System.Collections.ObjectModel;
  42.  
  43. // Aliases
  44. using PP = WhoAreYou.Person;
  45. using IF = WhoAreYou.InfoForm;
  46. using AP = WhoAreYou.Properties.AppSettings;
  47. using OS = WhoAreYou.Properties.OptionsSettings;
  48. using PS = WhoAreYou.Properties.PersonSettings;
  49. using AS = WhoAreYou.Properties.AppUserSettings;
  50. using PR = WhoAreYou.Properties.PersonResources;
  51.  
  52. namespace WhoAreYou
  53. {
  54.   public partial class InfoForm
  55.   {
  56. #region InfoForm link to PersonForm & Person Class Code.
  57.  
  58.     private void DataAnalyzerClick(
  59.       object sender, EventArgs e)
  60.     {
  61.       // todo testcode
  62.       if (!Testing) return;
  63.  
  64.       if (!OS.Default.Contributor
  65.         || !OS.Default.Elite) return;
  66.  
  67.       if (!Testing && !OS.Default.MiniVerb)
  68.         if (!AppStatic.YesNoDialog(
  69.           "Run Data Analyzer Now?",
  70.           "Are You Sure?")) return;
  71.  
  72.       bool save;
  73.       using (var p = new PersonForm())
  74.       {
  75.         p.Size = PS.Default.PF_Size;
  76.         p.Location = PS.Default.PF_Local;
  77.         p.ShowDialog(); // <-= /\/\/\/\/\/\/***
  78.         PS.Default.PF_Size = p.Size;
  79.         PS.Default.PF_Local = p.Location;
  80.         save = p.Changes;
  81.       }
  82.       PS.Default.Save();
  83.       _wasAtNum = CurrentRecord;
  84.       if (save)
  85.         SaveClick(
  86.           "Analyzer Click", EventArgs.Empty);
  87.       else
  88.         ShowCurrentRecord();
  89.     }
  90.   }
  91. #endregion InfoForm link to PersonForm & Person Class Code.
  92.   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  93.  
  94.  
  95. #region Custom Person Class Object by -JpE- v5.7.6.45 06.Jul.17
  96.  
  97.   public class Person
  98.   {
  99.     public string FirstName  { get; protected internal set; }
  100.     public string MiddleName { get; protected internal set; }
  101.     public string LastName   { get; protected internal set; }
  102.     public DateTime Birthday { get; protected internal set; }
  103.     public string Address1   { get; protected internal set; }
  104.     public string Address2   { get; protected internal set; }
  105.     public string City       { get; protected internal set; }
  106.     public string State      { get; protected internal set; }
  107.     public string Zip        { get; protected internal set; }
  108.     public string Title      { get; protected internal set; }
  109.     public string Home       { get; protected internal set; }
  110.     public string Cell       { get; protected internal set; }
  111.     public string Work       { get; protected internal set; }
  112.     public string Email1     { get; protected internal set; }
  113.     public string Email2     { get; protected internal set; }
  114.     public string W1         { get; protected internal set; }
  115.     public string W2         { get; protected internal set; }
  116.     public string W3         { get; protected internal set; }
  117.     public string Note       { get; protected internal set; }
  118.  
  119.     // Overloaded Class Constructors
  120.     public Person() { }
  121.  
  122.     public Person(ICollection<string> record)
  123.     {
  124.       if (record == null
  125.           || record.Count != AP.Default.RL)
  126.       {
  127.         const string txt =
  128.           "This record is not the right size.";
  129.         MessageBox.Show(txt);
  130.         return;
  131.       }
  132.       PopulatePerson(record);
  133.     }
  134.  
  135.     public Person(Person current)
  136.     {
  137.       PopulatePerson(current);
  138.     }
  139.     // ^ End of Class Constructor Overloads.
  140.  
  141.     // v Internal Person-Class Method. (Overloaded)
  142.     private void PopulatePerson(Person p)
  143.     {
  144.       var c = CultureInfo.InvariantCulture;
  145.       var s = new Collection<string>
  146.       {
  147.         p.FirstName,
  148.         p.MiddleName,
  149.         p.LastName,
  150.         p.Birthday.ToString(c),
  151.         p.Address1,
  152.         p.Address2,
  153.         p.City,
  154.         p.State,
  155.         p.Zip,
  156.         p.Title,
  157.         p.Home,
  158.         p.Cell,
  159.         p.Work,
  160.         p.Email1,
  161.         p.Email2,
  162.         p.W1,
  163.         p.W2,
  164.         p.W3,
  165.         p.Note
  166.       };
  167.       PopulatePerson(s);
  168.     }
  169.  
  170.     private void PopulatePerson(
  171.       ICollection<string> fields)
  172.     {
  173.       var rl = AP.Default.RL;
  174.       if (fields == null || fields.Count != rl)
  175.         throw new ArgumentException(
  176.           "Problems with people in the fields" +
  177.           " in Person >> Populate Person, etc.");
  178.       var e = new string[rl];
  179.       fields.CopyTo(e, 0);
  180.  
  181.       // Now Populate The Class Object.
  182.       var i = -1;
  183.       FirstName  = e[++i];
  184.       MiddleName = e[++i];
  185.       LastName   = e[++i];
  186.       Birthday   = Convert
  187.         .ToDateTime(e[++i]);
  188.       // NOTE: Can be any type ^
  189.       // or combination of types.
  190.       Address1   = e[++i];
  191.       Address2   = e[++i];
  192.       City       = e[++i];
  193.       State      = e[++i];
  194.       Zip        = e[++i];
  195.       Title      = e[++i];
  196.       Home       = e[++i];
  197.       Cell       = e[++i];
  198.       Work       = e[++i];
  199.       Email1     = e[++i];
  200.       Email2     = e[++i];
  201.       W1         = e[++i];
  202.       W2         = e[++i];
  203.       W3         = e[++i];
  204.       Note       = e[++i]
  205.         .Replace('~', '\n');
  206.     }
  207.   }
  208.  
  209. #endregion Custom Person Class Object v5.7.6.45 06.Jul.17
  210.   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  211.  
  212.  
  213. #region PersonForm Extension Code brought from InfoForm.
  214.  
  215.   public partial class PersonForm // <-= NOTE!
  216.   {
  217. /* NOTE: this Source Code File and Methods Test very Well! Including the Person-Class above. Implementation in MLBB may be unfeasable however as the early code was so entrenched around the 2 dimensional string array. But use it to experiment with RDBMS, DataSet and Maybe ADO.NET and some SQL Server idk? Pick a destination and get off there. LoL, But leaving this intact for now. BFD going back through all the code that involves the string[,] to do it this way, granted it's way better and how I should have done it in the first place, had I known much. But that was 2011, I was still screwing with their little demo thing. So until I can do a simple little DB App of some kind stand alone then I can maybe come back with what I know, or NOT. Otherwise leaving well enough alone here at a safe place, nice and solid and settled except for documentation. Help Files are incomplete. Work on that and clean up the About if yer done. Wait, done with MLBB? After 6 years? LoL jk do a side experiment, write an App or two. Come back home L8r on.
  218.      * ";-O */
  219.  
  220.     /// <summary> Multiple Overloads and such
  221.     /// v5.7.6.45 11.Jul.17
  222.     /// All This Brought to PersonForm & Integrated
  223.     /// v5.7.7.95 24-Aug-2017
  224.     /// </summary>
  225.     private void CreatePeople()
  226.    
  227.     {
  228.       if (!IF.Testing) // todo testcode
  229.       {
  230.         ShowPeople.Visible = false;
  231.         return;
  232.       }
  233.       People = CreatePeople(IF.Listen());
  234.     }
  235.  
  236.     /// <summary> Developed as an Alternative
  237.     /// to List[,] THIS:
  238.     /// Effectively Loads (current List ^) into
  239.     /// the newer Parallel Person Collection.
  240.     /// The hard part was I couldn't get 'there' from 'here'
  241.     /// and the way I was doing it. (to the way I should)
  242.     /// So many of these are intermediary steps as I learn
  243.     /// to get things converted while remaming parallel.
  244.     /// (i.e. without screwing up what was working.)
  245.     /// \\//
  246.     /// v5.7.7.96 24-Aug-2017
  247.     /// Brought to PersonForm from InfoForm.
  248.     /// </summary>
  249.     /// <returns>People</returns>
  250.     private static Collection<Person> // NOTE: Custom TYPE
  251.       CreatePeople(string[,] list)
  252.     {
  253.       if (list == null || list.GetLength(0) < 1
  254.           || !list.GetLength(1).Equals(AP.Default.RL))
  255.         throw new InvalidDataException(
  256.           "Create People in Person.cs");
  257.       var reclen = AP.Default.RL;
  258.       var mmbers = list.GetLength(0);
  259.       var people = new Collection<Person>();
  260.  
  261.       for (var m = 0; m < mmbers; ++m)
  262.       {
  263.         var person = new Collection<string>();
  264.         for (var r = 0; r < reclen; ++r)
  265.         {
  266.           var field = list[m, r];
  267.           if (string.IsNullOrEmpty(field)) field = "N/A";
  268.           person.Add(field);
  269.         }
  270.         people.Add(new Person(person));
  271.         // SuaWeeet! All-In-One Data Format.
  272.       }
  273.       return people;
  274.     }
  275.  
  276.     /// <summary> ShowMe the entire Object.
  277.     /// Sample Usages / Test Code (That Made It!)
  278.     /// Integrated into PersonForm instead and made perm.
  279.     /// v5.7.7.95 24-Aug-2017 by -JpE- for
  280.     /// (c) 2011-2041 Global Access Software InTl.
  281.     /// GASIT is a registered Trademark. 2011 </summary>
  282.     /// <param name="sender"></param>
  283.     /// <param name="e"></param>
  284.     private void ViewObject(object sender, EventArgs e)
  285.     {
  286.       var i = 0;
  287.       const string title = "View-All Records:";
  288.       if (People == null || People.Count < 1)
  289.       {
  290.         MessageBox.Show(PR.IF_DataAnalyzer_Null);
  291.         return;
  292.       }
  293.       var txt = People.Aggregate(
  294.         "", (current, p) => current +
  295.         string.Format(
  296.         "\nRecord {0})\n {1} {2} {3} {4}\n" +
  297.         "{5}\n{6}\n{7}\n{8}, {9}  {10}\n\n" +
  298.         "Home Phone: {11}, " +
  299.         "Cell Phone: {12}, Work Phone: {13}\n" +
  300.         "Email1: {14}, " + "Email2: {15}\n" +
  301.         "Website1: {16}, Website2: {17} " +
  302.         "Website3: {18}\n\n" +
  303.         "Comments:\n{19}\n===========\n\n",
  304.         ++i, p.Title, p.FirstName, p.MiddleName,
  305.         p.LastName, p.Birthday,
  306.         p.Address1, p.Address2, p.City, p.State, p.Zip,
  307.         p.Home, p.Cell, p.Work, p.Email1, p.Email2,
  308.         p.W1, p.W2, p.W3, p.Note));
  309.  
  310.       using (var sm = new ShowMeForm(txt, title))
  311.       {
  312.         sm.Size = AS.Default.MemReaderS;
  313.         sm.Location = AS.Default.MemReaderL;
  314.         sm.ShowDialog();
  315.         AS.Default.MemReaderS = sm.Size;
  316.         AS.Default.MemReaderL = sm.Location;
  317.       }
  318.     }
  319. #endregion PersonForm Extension brought from InfoForm.
  320.     // *** WAS: AppCode5 Part-5 v5.7.7.81 14.Aug.2017 ***/
  321.   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  322.  
  323.  
  324.   }
  325. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement