Example #1
0
 public void Parse(string input, string output)
 {
     var parser = new TimeParser();
      NUF.Assert.That(parser.Parse(input), NUF.Is.EqualTo(output));
 }
        private void CalculateTime()
        {
            string minute = null;
            string hour = null;
            string preposition = null;
            string amPm = null;

            var times = new string[4];

            try
            {

                if (MinutesScroll.SelectedIndex != -1)
                {
                minute = MinutesScroll.Items[MinutesScroll.SelectedIndex];
                    times[0] = minute;
                }

                if (HourScroll.SelectedIndex != -1)
                {
                hour = HourScroll.Items[HourScroll.SelectedIndex];
                    times[2] = hour;
                }

                if (PastPresentScroll.SelectedIndex != -1)
                {
                preposition = PastPresentScroll.Items[PastPresentScroll.SelectedIndex];
                    times[1] = preposition;
                }

                if (AmPmPicker.SelectedIndex != -1)
                {
                amPm = AmPmPicker.Items[AmPmPicker.SelectedIndex];
                    times[3] = amPm;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            //CHECK IF HALV
            PastPresentScroll.IsEnabled = true;
            PastPresentScroll.BackgroundColor = Color.White;
            if (minute != null && minute.ToLower().Equals("halv"))
            {
                PastPresentScroll.IsEnabled = false;
                PastPresentScroll.BackgroundColor = Color.Silver;
                PastPresentScroll.SelectedIndex = -1;
                times[1] = "";
            }

            if (hour == null)
            {
                return;
            }

            try
            {
                string totalTime = "";
                for (int i = 0; i < times.Count() - 1; i++)
                {
                    if (times[i] != null)
                    {
                        totalTime += times[i];
                        //Dont add an empty space on last number
                        if (i != times.Count() - 2)
                        totalTime += " ";
                    }
                }
                bool am = !amPm.ToLower().Equals("eftermiddag");

                var timeObject = new TimeParser().ParseTime(totalTime.ToLower(), am);
                CalculatedTimeLabel.Text = timeObject.DispalyString;
                CalculatedTimeLabel.TextColor = Color.Black;
            }
            catch
            {
            }
        }
Example #3
0
        public static void Main(string[] args)
        {
            var options = new Options();
             CommandLine.ICommandLineParser cmdParser =
               new CommandLine.CommandLineParser(new CommandLine.CommandLineParserSettings(System.Console.Error));

             if (cmdParser.ParseArguments(args, options)) {
            string connectionString = string.Format("URI=file:{0}", options.Database);

            #if (NET)
            var connection = new System.Data.SQLite.SQLiteConnection(connectionString);
            #else
            var connection = new Mono.Data.Sqlite.SqliteConnection(connectionString);
            #endif

            connection.Open();
            var command = connection.CreateCommand();
            command.CommandText =
              "CREATE TABLE IF NOT EXISTS at (id INTEGER PRIMARY KEY  NOT NULL,name VARCHAR,surname VARCHAR,year INTEGER,gender CHAR,time VARCHAR)";
            command.ExecuteNonQuery();
            var repo = new AthleteRepository(command);
            switch (options.Action) {
               case Action.Module: {
                  // 10mm d=> 28pt
                  // 15mm => 42pt
                  //float marginLeft, float marginRight, float marginTop, float marginBottom
                  var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36);
                  iTextSharp.text.pdf.PdfWriter.GetInstance(document,
                                                            new System.IO.FileStream("./module.pdf", System.IO.FileMode.Create));
                  document.Open();
                  var builder = new ModuleBuilder(document, options.YearEdition, 10);
                  for (int page = 0; page < 10; page++) {
                     builder.AddPage();
                  }
                  document.Close();
                  break;
               }
               case Action.Insert: {
                  System.Console.WriteLine("Drop all results?[y/N]?");
                  string yes  = System.Console.ReadLine();
                  if (yes == "y") {
                     FileHelpers.FileHelperEngine<Athlete> engine = new FileHelpers.FileHelperEngine<Athlete>();
                     Athlete[] athletes = engine.ReadFile(options.Input);

                     repo.DeleteAll();
                     foreach (var a in athletes) {
                        System.Console.WriteLine(a.Name);
                        repo.Insert(a);
                     }
                  }
                  break;
               }
               case Action.CreateList:
               case Action.CreateResult: {
                  string catFileName = GetCatFileName(options);
                  string reportFileName = GetReportFileName(options);
                  var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36);
                  iTextSharp.text.pdf.PdfWriter.GetInstance(document,
                                                            new System.IO.FileStream(reportFileName, System.IO.FileMode.Create));
                  document.Open();
                  IBuilder builder = null;

                  if (options.Action == Action.CreateList) {
                     builder = new ListBuilder(document);
                  } else {
                     builder = new PdfBuilder(document);
                  }

                  Category[] cats = GetCategories(catFileName);
                  foreach (Category cat in cats) {
                     if (log.IsDebugEnabled) log.Debug("parse" + cat.Id);
                     builder.BeginReport(cat.Title, options.YearEdition);
                     var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition));
                     foreach (Athlete athlete in athletes) {
                        builder.Add(athlete);
                     }
                     builder.EndReport();
                  }
                  document.Close();
                  break;
               }
               case Action.Interactive: {
                  Category[] cats = GetCategories(GetCatFileName(options));
                  var parser = new TimeParser();
                  foreach (Category cat in cats) {
                     System.Console.WriteLine("========{0}=========", cat.Id);
                     var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition));
                     foreach (Athlete athlete in athletes) {
                        System.Console.Write("{0:00} {1}\t{2}({3}):", athlete.Id, athlete.Surname, athlete.Name, athlete.Gender);
                        string time = string.Empty;
                        string fmt = string.Empty;
                        do {
                           time = System.Console.ReadLine();
                           fmt = parser.Parse(time);
                           if (!string.IsNullOrEmpty(fmt) ) {
                              System.Console.WriteLine(fmt);
                              repo.UpdateTime(athlete.Id, fmt);
                           } else {
                              if (time != "s") {
                                 System.Console.WriteLine("invalid..");
                              }
                           }
                        } while (string.IsNullOrEmpty(fmt) && time != "s");
                     }
                  }
                  break;
               }
            }
            connection.Close();
             }
        }