[chronojump] exhibitionCardGenerator can process multiple persons at once
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] exhibitionCardGenerator can process multiple persons at once
- Date: Wed, 27 Feb 2019 11:39:09 +0000 (UTC)
commit 0759ec375db10695564523c75841894d3503f53b
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Feb 27 12:38:23 2019 +0100
exhibitionCardGenerator can process multiple persons at once
exhibitions/exhibitionCardGenerator.cs | 130 +++++++++++++++++++++++++--------
1 file changed, 99 insertions(+), 31 deletions(-)
---
diff --git a/exhibitions/exhibitionCardGenerator.cs b/exhibitions/exhibitionCardGenerator.cs
index df6c2459..133e07a5 100644
--- a/exhibitions/exhibitionCardGenerator.cs
+++ b/exhibitions/exhibitionCardGenerator.cs
@@ -30,8 +30,8 @@ public static class Options
{
public static int MaleStartID = 100;
public static string DbPath = ".";
- //public static string Database = "exhibitionCardGenerator.db";
- public static string Database = "prova.db";
+ public static string Database = "exhibitionCardGenerator.db";
+ //public static string Database = "prova.db";
public static ConsoleColor ColorDefault = ConsoleColor.Blue;
public static ConsoleColor ColorHigh = ConsoleColor.White;
public static bool Debug = false;
@@ -213,25 +213,78 @@ public class ExhibitionCardGenerator
private void personAdd(int schoolID, int groupID)
{
- Person.SexTypes st = Person.SexTypes.UNKNOWN;
+ Person.SexTypes st;
+ int numPersons = 0;
+ bool allOk;
do {
- printOption("\n", "F", "emale, or ");
- printOption("", "M", "ale");
- string sex = Console.ReadLine();
- st = Person.SexParse(sex);
- } while(st == Person.SexTypes.UNKNOWN);
+ st = Person.SexTypes.UNKNOWN;
+ allOk = false;
- Person p = new Person(-1, schoolID, groupID, st);
- p.Insert(dbcmd);
+ printOption("\n", "F", "emale; ");
+ printOption("", "M", "ale; ");
+ printOption("or eg. ", "5M", " (to insert 5 males) ? ");
+ string option = Console.ReadLine();
- p.PrintCard();
- Console.WriteLine();
-// string option;
-// do {
- printOption("", "(enter)", " ?");
-// option = Console.ReadLine();
- Console.ReadLine();
-// } while (option != "q");
+ if(option.EndsWith("M") || option.EndsWith("m"))
+ st = Person.SexTypes.M;
+ else if(option.EndsWith("F") || option.EndsWith("f"))
+ st = Person.SexTypes.F;
+
+ if(st != Person.SexTypes.UNKNOWN)
+ {
+ if(option.Length == 1) {
+ numPersons = 1;
+ allOk = true;
+ } else {
+ numPersons = parseNumPersonsAndSex(option);
+ allOk = (numPersons > 0);
+ }
+ }
+ } while(! allOk);
+
+ if(numPersons == 1)
+ {
+ Person p = new Person(-1, schoolID, groupID, st);
+ p.Insert(dbcmd);
+ p.PrintCard();
+ Console.WriteLine();
+ }
+ else if(numPersons > 1)
+ {
+ int min = 0;
+ int max = 0;
+ for(int i=0; i < numPersons; i++)
+ {
+ Person p = new Person(-1, schoolID, groupID, st);
+ p.Insert(dbcmd);
+
+ if(i==0)
+ min = p.ID;
+ max = p.ID;
+ }
+ Person.PrintCardMultiple(min, max, groupID, schoolID);
+ }
+
+ printOption("", "(enter)", " ?");
+ Console.ReadLine();
+ }
+
+ private bool isMale(string option)
+ {
+ return (option == "M" || option == "m");
+ }
+ private bool isFemale(string option)
+ {
+ return (option == "F" || option == "f");
+ }
+ private int parseNumPersonsAndSex(string option)
+ {
+ string optionWithoutSexLetter = option.Substring(0, option.Length -1);
+ Console.WriteLine("parsing [" + optionWithoutSexLetter + "]");
+ if(isNumber(optionWithoutSexLetter))
+ return Convert.ToInt32(optionWithoutSexLetter);
+
+ return 0; //return this if there are errors
}
private void createTables()
@@ -490,10 +543,10 @@ public class Group
public class Person
{
- int id;
- int schoolID;
- int groupID;
- SexTypes sex;
+ private int id;
+ private int schoolID;
+ private int groupID;
+ private SexTypes sex;
//string name;
static string table = "person";
@@ -561,23 +614,33 @@ public class Person
dbcmd.ExecuteNonQuery();
}
- public static SexTypes SexParse(string sex)
+ public void PrintCard()
{
- if(sex == "M" || sex == "m")
- return SexTypes.M;
- else if(sex == "F" || sex == "f")
- return SexTypes.F;
+ Console.WriteLine("\n-- Targeta --");
+ Console.ForegroundColor = Options.ColorDefault;
+ Console.Write("Codi: ");
+ Console.ForegroundColor = Options.ColorHigh;
+ Console.WriteLine(id);
+
+ Console.ForegroundColor = Options.ColorDefault;
+ Console.Write("Grup: ");
+ Console.ForegroundColor = Options.ColorHigh;
+ Console.WriteLine(groupID);
- return SexTypes.UNKNOWN;
+ Console.ForegroundColor = Options.ColorDefault;
+ Console.Write("Escola: ");
+ Console.ForegroundColor = Options.ColorHigh;
+ Console.WriteLine(schoolID);
+ Console.ForegroundColor = Options.ColorDefault;
}
- public void PrintCard()
+ public static void PrintCardMultiple(int idMin, int idMax, int groupID, int schoolID)
{
- Console.WriteLine("\n-- Targeta --");
+ Console.WriteLine("\n-- Targetes --");
Console.ForegroundColor = Options.ColorDefault;
Console.Write("Codi: ");
Console.ForegroundColor = Options.ColorHigh;
- Console.WriteLine(id);
+ Console.WriteLine(string.Format("{0}-{1}", idMin, idMax));
Console.ForegroundColor = Options.ColorDefault;
Console.Write("Grup: ");
@@ -588,5 +651,10 @@ public class Person
Console.Write("Escola: ");
Console.ForegroundColor = Options.ColorHigh;
Console.WriteLine(schoolID);
+ Console.ForegroundColor = Options.ColorDefault;
+ }
+
+ public int ID {
+ get { return id; }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]