static void Main(string[] args) { Employee e = new Employee(); BonusEmployee b1 = new BonusEmployee(); try { e.Id = 12; e.LastName = "Smith"; Console.WriteLine(e.Greeting("Becky")); //setting salary e.Salary = 2500000; Console.WriteLine(" Congratulations your salary is {0}", e.Salary.ToString("C")); } catch (ApplicationException ex) { Console.WriteLine("An error occured - looks like a bad salary value", ex.Message); } catch (InvalidOperationException ex) { Console.WriteLine("An error occured - caught by invalid op exception", ex.Message); } catch (Exception ex) { Console.WriteLine($"An error occured- caught by parent", ex.Message); } finally { Console.WriteLine($"This runs all the time"); } }
/// <summary> /// Добавление надбавки /// </summary> /// <param name="bonusObject">объект, которому добавляем</param> /// <param name="bonusBindingSource">BindingSource</param> public void AddBonus(object bonusObject, BindingSource bonusBindingSource) { using (Kadr.UI.Common.PropertyGridDialogAdding<Bonus> dlg = new Kadr.UI.Common.PropertyGridDialogAdding<Bonus>()) { dlg.ObjectList = KadrController.Instance.Model.Bonus; dlg.BindingSource = bonusBindingSource; dlg.UseInternalCommandManager = true; dlg.PrikazButtonVisible = true; dlg.InitializeNewObject = (x) => { //создаем историю надбавки BonusHistory bonusHistory = new BonusHistory(); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusHistory, Bonus>(bonusHistory, "Bonus", x, null), this); if ((dlg.SelectedObjects != null) && (dlg.SelectedObjects.Length == 1)) { Bonus prev = dlg.SelectedObjects[0] as Bonus; dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusHistory, Prikaz>(bonusHistory, "Prikaz", prev.PrikazBegin, null), this); } else { dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusHistory, Prikaz>(bonusHistory, "Prikaz", NullPrikaz.Instance, null), this); } dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<Bonus, BonusType>(x, "BonusType", NullBonusType.Instance, null), this); if (bonusObject is FactStaff) dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusHistory, System.DateTime>(bonusHistory, "DateBegin", DateTime.Today.AddDays(1 - DateTime.Today.Day), null), this); else dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusHistory, System.DateTime>(bonusHistory, "DateBegin", DateTime.Today, null), this); }; dlg.CreateRelatedObject = (x) => { if ((dlg.SelectedObjects != null) && (dlg.SelectedObjects.Length == 1)) { Bonus prev = dlg.SelectedObjects[0] as Bonus; if (bonusObject is FactStaff) { BonusFactStaff bonusFactStaff = new BonusFactStaff(); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusFactStaff, Bonus>(bonusFactStaff, "Bonus", prev, null), this); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusFactStaff, FactStaff>(bonusFactStaff, "FactStaff", bonusObject as FactStaff, null), this); } if (bonusObject is PlanStaff) { BonusPlanStaff bonusPlanStaff = new BonusPlanStaff(); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusPlanStaff, Bonus>(bonusPlanStaff, "Bonus", prev, null), this); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusPlanStaff, PlanStaff>(bonusPlanStaff, "PlanStaff", bonusObject as PlanStaff, null), this); } if (bonusObject is Post) { BonusPost bonusPost = new BonusPost(); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusPost, Bonus>(bonusPost, "Bonus", prev, null), this); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusPost, Post>(bonusPost, "Post", bonusObject as Post, null), this); } if (bonusObject is Employee) { BonusEmployee bonusEmployee = new BonusEmployee(); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusEmployee, Bonus>(bonusEmployee, "Bonus", prev, null), this); dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusEmployee, Employee>(bonusEmployee, "Employee", bonusObject as Employee, null), this); } } }; dlg.UpdateObjectList = () => { dlg.ObjectList = KadrController.Instance.Model.Bonus; }; dlg.ShowDialog(); } }