Ejemplo n.º 1
0
        //[Serializable]
        //[XmlRoot("EmployeeCollection")]
        //public class EmployeeContainer
        //{
        //    [XmlArray("Employees")]
        //    [XmlArrayItem("Employee")]
        //    public List<Employee> Employees = new List<Employee>();
        //}
        public void saveEmployee()
        {
            Hourly       hr  = new Hourly();
            Salaried     sal = new Salaried();
            Commissioned com = new Commissioned();

            System.IO.Stream FileStream = File.Create(@"C:\Users\Public\TestFolder\WriteLines.xml");
            //XmlSerializer serializer = new XmlSerializer(typeof(Account[]));
            BinaryFormatter serializer = new BinaryFormatter();

            //XmlSerializer serializer = new XmlSerializer(typeof(Account[]));
            serializer.Serialize(FileStream, empArray);
            FileStream.Close();

            //Write array to text file
            //hr.hourlyExport();
            //sal.salaryExport();
            //com.commissionedExport();

            Console.WriteLine("\nYour changes have been saved.  Goodbye.");

            //var serializer = new XmlSerializer(typeof(EmployeeContainer));
            //var stream = new FileStream(path, FileMode.Create);
            //serializer.Serialize(stream, this);
            //stream.Close();
            Thread.Sleep(3000);
            Environment.Exit(0);
        }
Ejemplo n.º 2
0
        public void populateEmployees()
        {
            Employee em = new Employee();

            Console.WriteLine("Please fill out the attributes for the employees you wish to add\n");

            for (int i = 0; i < empArray.Length; i++)
            {
                if (i == 0)
                {
                    //Hourly employee
                    empArray[i] = new Hourly();
                    Console.WriteLine("Hourly employee:\nHow many hours?");
                    input             = Convert.ToInt32(Console.ReadLine());
                    empArray[0].hours = input;
                    Console.WriteLine("Pay rate:");
                    input            = Convert.ToInt32(Console.ReadLine());
                    empArray[0].rate = input;
                }
                else if (i == 1)
                {
                    //Salaried employees
                    empArray[i] = new Salaried();
                    Console.WriteLine("\nSalary employee:\nStaff or executive? (1 or 9)");
                    input = Convert.ToInt32(Console.ReadLine());
                    if (input == 1)
                    {
                        empArray[1].gross = 50000;
                    }
                    else if (input == 9)
                    {
                        empArray[1].gross = 100000;
                    }
                }
                else if (i == 2)
                {
                    //Commissioned employee
                    empArray[i] = new Commissioned();
                    Console.WriteLine("\nCommissioned employee:\nNumber of items sold?");
                    input       = Convert.ToInt32(Console.ReadLine());
                    numberItems = input;
                    Console.WriteLine("Unit price of items sold?");
                    input             = Convert.ToInt32(Console.ReadLine());
                    empArray[2].gross = 0.5f * (input * numberItems);
                }
                else
                {
                }
            }

            employeesExist = true;
        }