示例#1
0
        static void Main(string[] args)
        {
            Start();

            var alice = new Employee()
            {
                Name = "Alice", Title = "Test Engineer"
            };
            var bruce = new Employee()
            {
                Name = "Bruce", Title = "Developer"
            };
            var chloe = new Manager()
            {
                Name = "Chloe", Title = "Program Manager"
            };
            var doris = new Employee()
            {
                Name = "Doris", Title = "Build Engineer"
            };
            var ethan = new Manager()
            {
                Name = "Ethan", Title = "Release Manager"
            };
            var frank = new Manager()
            {
                Name = "Frank", Title = "Director"
            };

            var organization = new Organization("DoodleSoft");

            var taxOffice         = new TaxOffice();
            var insuranceOffice   = new InsuranceOffice();
            var pensionFundOffice = new PensionFundOffice();

            insuranceOffice.Subscribe(organization);

            organization.EmployeeAdded += taxOffice.RegisterEmployee;
            organization.EmployeeAdded += pensionFundOffice.AddToPensionProgram;

            organization.AddEmployee(alice, chloe);
            organization.AddEmployee(bruce, chloe);
            organization.AddEmployee(chloe, frank);
            organization.AddEmployee(doris, ethan);
            organization.AddEmployee(ethan, frank);
            organization.AddEmployee(frank, null);
            organization.Director = frank;

            insuranceOffice.Unsubscribe(organization);

            organization.EmployeeAdded -= taxOffice.RegisterEmployee;
            organization.EmployeeAdded -= pensionFundOffice.AddToPensionProgram;

            End();
        }
示例#2
0
        static void Main(string[] args)
        {
            Start();

            var alice = new Employee()
            {
                Name = "Alice", Title = "Test Engineer"
            };
            var bruce = new Employee()
            {
                Name = "Bruce", Title = "Developer"
            };
            var chloe = new Manager()
            {
                Name = "Chloe", Title = "Program Manager"
            };
            var doris = new Employee()
            {
                Name = "Doris", Title = "Build Engineer"
            };
            var ethan = new Manager()
            {
                Name = "Ethan", Title = "Release Manager"
            };
            var frank = new Manager()
            {
                Name = "Frank", Title = "Director"
            };

            var organization = new Organization();

            organization.AddEmployee(alice, chloe);
            organization.AddEmployee(bruce, chloe);
            organization.AddEmployee(chloe, frank);
            organization.AddEmployee(doris, ethan);
            organization.AddEmployee(ethan, frank);
            organization.AddEmployee(frank, null);
            organization.Director = frank;

            Console.WriteLine(organization);

            organization.PrintEmployeeCards();

            End();
        }
示例#3
0
        static void Main(string[] args)
        {
            // Создаем много сотрудников
            var list = new List <Employee>
            {
                new FixedSalary(1, "B S D", new DateTime(DateTime.Now.Ticks), Post.HR),
                new FixedSalary(0, "A S D", new DateTime(DateTime.Now.Ticks), Post.Manager),
                new FixedSalary(2, "C S D", new DateTime(DateTime.Now.Ticks), Post.Director),
                new HourlyPay(4, "A S D", new DateTime(DateTime.Now.Ticks), Post.Manager, 1000),
                new HourlyPay(5, "B S D", new DateTime(DateTime.Now.Ticks), Post.Manager, 1000),
                new HourlyPay(3, "C S D", new DateTime(DateTime.Now.Ticks), Post.Manager, 1000),
                new HourlyPay(6, "D D D", new DateTime(DateTime.Now.Ticks), Post.Manager, 1000),
            };
            var org = new Organization();

            // Добавляем их в организацию
            org.AddEmployee(list);

            // Записываем организацию в файл
            org.SaveInFile("file.json");
            // Работаем со считанной из файла организацией
            org = Organization.ReadFromFile("file.json");
            org.Sort(new EmployeeComparer());
            for (int i = 0; i < 6; i++)
            {
                Console.WriteLine(org[i].FullName);
            }
            for (int i = org.Count - 1; i >= org.Count - 4; i--)
            {
                Console.WriteLine(org[i].Id);
            }
            for (int i = 0; i < org.Count; i++)
            {
                Console.WriteLine(org[i]);
                Console.WriteLine();
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            var organization = new Organization(1, "Sevaastol");

            organization.AddEmployee(0, "street1", "Jonny Cash", "+34966899997");
            organization.AddEmployee(2, "street2", "Maily Cert", "+3496545797");
            organization.AddEmployee(-1, "street3", "Peeter P", "+3496545644");

            foreach (var employee in organization.Employees)
            {
                Console.WriteLine(employee.ToString());
            }

            foreach (var id in organization.Employees)
            {
                bool validid = ValidationId(id);
                Console.WriteLine($"Id hass been: {validid}");
            }

            Console.WriteLine("*** Информация о домене приложения ***\n");
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var a in assemblies)
            {
                Console.WriteLine($"{a.FullName}\n");
            }

            //загружаем сбоку мтодом LoadFrom()
            Assembly asm = Assembly.LoadFrom("CNnet_Lab1.dll");

            Console.WriteLine(asm.FullName);
            // получаем все типы из сборки MyApp.dll
            Type[] types = asm.GetTypes();
            foreach (Type t in types)
            {
                Console.WriteLine($"{t.FullName}\n");
            }

            //  Получение информации о конструкторах
            var employeeType = types.Single(t => t.Name.EndsWith("Employee"));

            Console.WriteLine("Конструкторы:");
            foreach (ConstructorInfo ctor in employeeType.GetConstructors())
            {
                Console.Write(employeeType.Name + " (");
                // получаем параметры конструктора
                ParameterInfo[] parameters = ctor.GetParameters();
                for (int i = 0; i < parameters.Length; i++)
                {
                    Console.Write(parameters[i].ParameterType.Name + " " + parameters[i].Name);
                    if (i + 1 < parameters.Length)
                    {
                        Console.Write(", ");
                    }
                }
                Console.WriteLine(")");
            }


            // Используем позднее связывание
            dynamic obj = Activator.CreateInstance(employeeType, new object[] { 1, "address", "John Skirt", "telephone", "otherInfo" });

            Console.WriteLine(obj.FullName);

            Console.WriteLine("Объект создан!");
            //вызов метода
            obj = "CNnet_Lab1.dll";
            obj = new Employee(2, "street2", "Maily Cert", "+3496545797");
            obj.SetName("Maily Second");
            Console.WriteLine(obj.FullName);

            // Start Excel and get Application object.
            var excel = new Microsoft.Office.Interop.Excel.Application();

            // for making Excel visible
            excel.Visible       = false;
            excel.DisplayAlerts = false;
            // Creation a new Workbook
            var excelworkBook = excel.Workbooks.Add(Type.Missing);
            // Workk sheet
            var excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.ActiveSheet;

            excelSheet.Name = "Test work sheet";

            excelSheet.Cells[1, 1] = obj.FullName;
            excelSheet.Cells[1, 2] = obj.Address;

            excelworkBook.SaveAs(@"D:\project\Lab.xml");
            //  dynamic employee = new System.Dynamic.DynamicObject();

            Console.ReadLine();
        }