Пример #1
0
        /// <summary>
        /// Method to read existing time sheet records from text file
        /// </summary>
        private static void ReadExistingTimeSheets()
        {
            try
            {
                string   line       = string.Empty;
                string   employeeID = string.Empty;
                DateTime date       = DateTime.Now;
                string   project    = string.Empty;
                double   workedHour = 0;

                // Read file line by line.
                using (System.IO.StreamReader file = new System.IO.StreamReader(_timesheetPath))
                {
                    //_timesheets.Clear();

                    while ((line = file.ReadLine()) != null)
                    {
                        int counter = 0;

                        line = line.Trim();

                        while (line != string.Empty)
                        {
                            string entry = string.Empty;
                            if (line.IndexOf('|') > 0)
                            {
                                entry = line.Substring(0, line.IndexOf('|'));
                            }
                            else
                            {
                                entry = line;
                            }
                            if (entry != string.Empty)
                            {
                                switch (counter)
                                {
                                case 0:
                                    employeeID = entry;
                                    break;

                                case 1:
                                    if (DateTime.TryParse(entry, out date))
                                    {
                                    }
                                    break;

                                case 2:
                                    project = entry;
                                    break;

                                case 3:
                                    if (!Double.TryParse(entry, out workedHour))
                                    {
                                    }
                                    line = string.Empty;
                                    break;
                                }
                                counter++;
                            }
                            line = line.Trim();
                            int index = line.IndexOf('|') + 1;
                            line = line.Substring(index, line.Length - index);
                            line = line.Trim();
                        }
                        TimeSheet record = ts.CreateTimeSheet(employeeID, date, project, workedHour);
                        if (record != null)
                        {
                            _timesheets.Add(record);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //todo
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(120, 30);
            int userSelect = 12; //dummy

            emp = new Employee();
            ts  = new TimeSheet();

            ReadExistingTimeSheets(); // Read existing time sheet records from text file
            ReadExistingEmpRecords(); // Read existing employees records from text file


            Console.WriteLine("TIME SHEET APPLICATION ");
            Console.WriteLine("=================================================================================");
            while (userSelect != 0)
            {
                Console.WriteLine("=================================================================================");
                Console.WriteLine("Please select one of the following options : ");
                Console.WriteLine(" Enter \"1\" to CREATE NEW EMPLOYEE ");
                Console.WriteLine(" Enter \"2\" to ENTER TIME SHEET FOR SELECTED EMPLOYEE ");
                Console.WriteLine(" Enter \"3\" to CALCULATE WAGE FOR SELECTED EMPLOYEE ");
                Console.WriteLine(" Enter \"4\" to DISPLAY ALL EMPLOYEE INFO ");
                Console.WriteLine(" Enter \"5\" to DISPLAY ALL TIME SHEET RECORDS FOR SELECTED EMPLOYEE ");
                Console.WriteLine(" Enter \"0\" to exit the application ");
                Console.WriteLine("=================================================================================");

                userSelect = Convert.ToInt32(Console.ReadLine());


                switch (userSelect)
                {
                case 1:
                    CreateEmployee();
                    break;

                case 2:
                    EnterTimeSheet();
                    break;

                case 3:
                    CalculateWage();
                    break;

                case 4:
                    DisplayAllEmployeeInfo();
                    break;

                case 5:
                    DisplayTimeSheetByEmployeeID();
                    break;

                case 0:
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Please try again..");
                    break;
                }
            }
        }