Exemple #1
0
        static void Main(string[] args)
        {
            // Create a new Scanner object (defined on line 280) which handles the collection
            // of user input and includes limited validation for types string and double
            Scanner InputScanner = new Scanner();

            // Create a list of Software Developers as Employee objects
            List <Employee> Employees = new List <Employee>();

            Console.WriteLine("D. Paul Barden, POS/408, Week 5");
            Console.WriteLine("Welcome to Software Development, LLC");
            Console.WriteLine("=================================");
            Console.WriteLine("");

            // create a counter to hold the number of developers to increase for loop below
            int counter = 0;

            while (counter < 5)
            {
                Console.WriteLine("Please enter the number of developers (must be at least 5):");
                counter = Convert.ToInt16(Console.ReadLine());
            }

            // actions are performed n times, one for each employee
            // as per the application requirements
            for (int n = 0; n < counter; n++)
            {
                // Use the Scanner object to read user input. The user prompt is passed in.
                // InputScanner() returns a string which is assigned to the UserInput string variable
                string UserInput = InputScanner.Read("Please enter a name for employee " + (n + 1) + " (Software Developer): ");

                // Create a new Employee object using the name assigned to the UserInput variable above
                // Employee SoftwareDeveloper = new Employee(UserInput);
                Employees.Add(new Employee(UserInput));

                // InputScanner() returns a string which is assigned to the UserInput string variable
                UserInput = InputScanner.Read("Please enter the employment type for " + Employees[n].GetName() + ": ");
                bool EmpTypeCheck = false;

                // checks for possible variations of W-2 and correct them
                if ((UserInput.ToUpper() == "W2") || (UserInput.ToUpper() == "W-2"))
                {
                    // correct user input and set the boolean to true to bypass the while loop below
                    UserInput    = "W-2";
                    EmpTypeCheck = true;
                }

                // if the user input is acceptable, set the boolean to true to bypass the while loop below
                if ((UserInput == "1099") || (UserInput == "W-2"))
                {
                    EmpTypeCheck = true;
                }

                // if input wasn't acceptable and the boolean wasn't set, this loop executes until
                // the user inputs an acceptable answer for the employment type
                while (!EmpTypeCheck)
                {
                    // display error message to user
                    Console.WriteLine("Incorrect format. Please enter '1099' or 'W-2'.");
                    Console.WriteLine("");

                    // prompt for another entry and perform checks/corrections
                    UserInput = InputScanner.Read("Please enter the employment type for " + Employees[n].GetName() + ": ");
                    if ((UserInput.ToUpper() == "W2") || (UserInput.ToUpper() == "W-2"))
                    {
                        UserInput    = "W-2";
                        EmpTypeCheck = true;
                    }
                    else if (UserInput == "1099")
                    {
                        EmpTypeCheck = true;
                    }
                }

                // set employee type if it passes the above error checks
                Employees[n].SetEmploymentType(UserInput);

                // InputScanner() returns a string which is assigned to the UserInput string variable
                UserInput = InputScanner.Read("Please enter an address for " + Employees[n].GetName() + ": ");

                // Use UserInput to assign a new address to the employee
                Employees[n].SetAddress(UserInput);

                // InputScanner() returns a double which is assigned to the UserNumInput double variable
                double UserNumInput = InputScanner.ReadDouble("Please enter a monthly pay rate for " + Employees[n].GetName() + ": ");
                Employees[n].SetMonthlyGrossPay(UserNumInput);

                if (Employees[n].GetEmploymentType() == "W-2")
                {
                    // Sets a tax rate for W-2 employees
                    Employees[n].SetTaxRate(7.0);
                }

                // Create space bwtween sets of input for easier viewing
                Console.WriteLine("");
            }

            // create array to store csv line values
            string[] CommaDelimitedValues = new string[counter];
            string   BuildCSV             = "";

            for (int n = 0; n < counter; n++)
            {
                // Display all employee information stored
                // Now updated to display each employee's info
                string _Name        = Employees[n].GetName();
                string _EmpType     = Employees[n].GetEmploymentType();
                string _Addr        = Employees[n].GetAddress();
                double _GrossMo     = Employees[n].GetMonthlyGrossPay();
                double _GrossYr     = Employees[n].GetYearlyGrossPay();
                double _TaxRate     = Employees[n].GetTaxRate();
                double _MoTaxPaid   = Employees[n].GetTaxesPaid();
                double _NetMo       = Employees[n].GetNetPay();
                double _YrTaxesPaid = Employees[n].GetYearlyTaxesPaid();
                double _NetYr       = Employees[n].GetYearlyNetPay();

                Console.WriteLine("");
                Console.WriteLine("Employee " + (n + 1) + " Role: Software Developer");
                Console.WriteLine("=================================");
                Console.WriteLine("Name: {0}", _Name);
                Console.WriteLine("Employment Type: {0}", _EmpType);
                Console.WriteLine("Address: {0}", _Addr);
                Console.WriteLine("Monthly Gross Pay: ${0:n2}", _GrossMo);
                Console.WriteLine("Yearly Gross Pay: ${0:n2}", _GrossYr);
                Console.WriteLine("Tax Rate: {0}%", _TaxRate);
                Console.WriteLine("Monthly Taxes Paid: ${0:n2}", _MoTaxPaid);
                Console.WriteLine("Monthly Net Pay: ${0:n2}", _NetMo);
                Console.WriteLine("Yearly Taxes Paid: ${0:n2}", _YrTaxesPaid);
                Console.WriteLine("Yearly Net Pay: ${0:n2}", _NetYr);
                Console.WriteLine("");

                // format data for csv
                BuildCSV = _Name + ", " + _EmpType + ", " + _Addr + ", " + _GrossMo + ", " + _GrossYr + ", " + _TaxRate + ", " + _MoTaxPaid + ", " + _NetMo + ", " + _YrTaxesPaid + ", " + _NetYr + ", ";
                CommaDelimitedValues[n] = BuildCSV;
            }

            // collect file path from the user
            string FilePath = InputScanner.Read("Please enter the CSV output path (enter the folder name, not the expected file name): ");

            // append file name
            FilePath += "\\data.txt";

            // create csv and add data for each array item by index
            using (System.IO.StreamWriter MyCSV = new System.IO.StreamWriter(@FilePath))
            {
                for (int n = 0; n < counter; n++)
                {
                    MyCSV.WriteLine(CommaDelimitedValues[n]);
                }
                MyCSV.Close();
            }

            // read the csv that was just created
            int    LineCounter = 0;
            string NextLine;

            string[] SplitLine = new string[10];

            // read the file and display the information back onto the screen
            System.IO.StreamReader MyCSVInput = new System.IO.StreamReader(@FilePath);
            while ((NextLine = MyCSVInput.ReadLine()) != null)
            {
                SplitLine = NextLine.Split(',');

                Console.WriteLine("");
                Console.WriteLine("Employee Role: Software Developer");
                Console.WriteLine("=================================");
                Console.WriteLine("Name: {0}", SplitLine[0]);
                Console.WriteLine("Employment Type: {0}", SplitLine[1]);
                Console.WriteLine("Address: {0}", SplitLine[2]);
                Console.WriteLine("Monthly Gross Pay: ${0:n2}", Convert.ToDouble(SplitLine[3]));
                Console.WriteLine("Yearly Gross Pay: ${0:n2}", Convert.ToDouble(SplitLine[4]));
                Console.WriteLine("Tax Rate: {0}%", Convert.ToDouble(SplitLine[5]));
                Console.WriteLine("Monthly Taxes Paid: ${0:n2}", Convert.ToDouble(SplitLine[6]));
                Console.WriteLine("Monthly Net Pay: ${0:n2}", Convert.ToDouble(SplitLine[7]));
                Console.WriteLine("Yearly Taxes Paid: ${0:n2}", Convert.ToDouble(SplitLine[8]));
                Console.WriteLine("Yearly Net Pay: ${0:n2}", Convert.ToDouble(SplitLine[9]));
                Console.WriteLine("");

                LineCounter++;
            }

            MyCSVInput.Close();

            // Added to prevent the application from closing until user has a chance to view information output above
            Console.WriteLine("Press ENTER to exit the program.");
            string NewInput = Console.ReadLine();
        }
Exemple #2
0
        // This will run when the form is loaded
        private void Form1_Load(object sender, EventArgs e)
        {
            // Holds the file path for the base directory (the same one containing the .exe file)
            string DataPath = AppDomain.CurrentDomain.BaseDirectory + "\\data.txt";

            // These will be used to store and assign values to CSV data
            string NextLine;

            string[] SplitLine = new string[7];
            int      HeadCount = 0;

            string[] Headers = new string[7];

            // This creates a new list to store Developer objects
            List <Developer> Developers = new List <Developer>();

            // This will read the .txt file and create developer objects with the data in comma delimited format
            System.IO.StreamReader CommaDelimitedInput = new System.IO.StreamReader(@DataPath);
            while ((NextLine = CommaDelimitedInput.ReadLine()) != null)
            {
                SplitLine = NextLine.Split(',');

                // Stores the first line as header information for the table
                if (HeadCount != 1)
                {
                    for (int n = 0; n < SplitLine.Length; n++)
                    {
                        Headers[n] = SplitLine[n].Trim();
                    }
                    HeadCount++;
                }
                // Otherwise, create a new Developer object using the data
                else
                {
                    Developers.Add(new Developer(SplitLine[0].Trim(), SplitLine[1].Trim(), Convert.ToInt32(SplitLine[2].Trim()), Convert.ToDouble(SplitLine[3].Trim()), SplitLine[4].Trim(), SplitLine[5].Trim(), SplitLine[6].Trim()));
                }
            }

            // Closes the data.txt file since the information needed is stored appropriately
            CommaDelimitedInput.Close();

            // Create information for a new DataTable and add header information from the file specifying the data type
            DataTable EmployeeDataTable = new DataTable();

            EmployeeDataTable.Columns.Add(Headers[0], typeof(string));
            EmployeeDataTable.Columns.Add(Headers[1], typeof(string));
            EmployeeDataTable.Columns.Add(Headers[2], typeof(int));
            EmployeeDataTable.Columns.Add(Headers[3], typeof(double));
            EmployeeDataTable.Columns.Add(Headers[4], typeof(string));
            EmployeeDataTable.Columns.Add(Headers[5], typeof(string));
            EmployeeDataTable.Columns.Add(Headers[6], typeof(string));

            // Add entries for each developer object that was read and stored from the data.txt file
            foreach (Developer _dev in Developers)
            {
                EmployeeDataTable.Rows.Add(_dev.Name, _dev.Address, _dev.Age, _dev.GrossPay, _dev.Department, _dev.DeveloperType, _dev.TaxType);
            }

            // Finally, populate the data grid in the form using the information above
            dataGridView1.DataSource = EmployeeDataTable;
        }
Exemple #3
0
        public bool Run(params object[] args)
        {
            string NextLine;
            double result     = 0;
            double lastValue  = 0;
            int    numberLine = 0;
            string outInfo;
            char   operationType;
            var    mathBuffer    = (ValuesBuffer)args[0];
            var    historyBuffer = (HistoryOperations)args[2];
            Socket socket        = (Socket)args[3];

            ServerIO _ServerIO = new ServerIO(socket);

            mathBuffer.variables.Clear();
            mathBuffer.TopValue = 0;

            _ServerIO.WriteLine("Enter file name without extension:");
            string pathFile = Directory.GetCurrentDirectory() + "\\" + _ServerIO.ReadString() + ".txt";

            if (!File.Exists(pathFile))
            {
                _ServerIO.WriteLine("Such file does not exist");
                return(true);
            }


            using (var file = new StreamReader(pathFile))
            {
                while ((NextLine = file.ReadLine()) != null)
                {
                    numberLine++;
                    string[] ParseLine = NextLine.Split(' ');

                    switch (ParseLine.Length)
                    {
                    case 1:
                        outInfo = ParseLine[0];
                        if (Double.TryParse(outInfo, out result))
                        {
                            _ServerIO.WriteLine($"[#{numberLine}] - {result}");
                            mathBuffer.HideSaveValue(result);
                        }
                        else
                        {
                            result = ConvertToInteger(outInfo);
                            _ServerIO.WriteLine($"[#{numberLine}] - {outInfo} = {result}");
                            mathBuffer.HideSaveValue(result);
                        }
                        break;

                    case 3:
                        outInfo       = ParseLine[0];
                        operationType = Convert.ToChar(ParseLine[1]);
                        result        = Convert.ToDouble(ParseLine[2]);
                        lastValue     = SearchLastValue(operationType, mathBuffer.ReturnTopValue(), result);
                        _ServerIO.WriteLine($"[#{numberLine}] - {outInfo} {operationType} {lastValue} = " +
                                            $"{mathBuffer.ReturnTopValue()} {operationType} {lastValue} = {result}");
                        mathBuffer.HideSaveValue(result);
                        break;

                    default:
                        _ServerIO.Write("Parse error!\n");
                        break;
                    }
                }
            }


            return(true);
        }