Inheritance: UIX.Views.IDecorable, UIX.Views.IValidatable
        protected override void DoApply()
        {
            if ((dtNewDate == null)
                || (cbBonusType.SelectedItem == null)
                || (cbNewPrikaz.SelectedItem == null))
            {
                MessageBox.Show("Внесите все данные!");
                OKClicked = false;
                return;
            }

            //выбираем все надбавки указанного типа, которые еще действующие

            //для каждой подходящей по условиям надбавки создаем запись истории
            IEnumerable<GetBonusByBonusTypeForProlongResult> CheckedBonus = bonus.Where(bon => bon.Prolong.Value).ToArray();
            foreach (GetBonusByBonusTypeForProlongResult curBonus in CheckedBonus)
            {
                Bonus bon = KadrController.Instance.Model.Bonus.Where(bn => bn.id == curBonus.idBonus).FirstOrDefault();
                if (bon == null)
                    continue;
                BonusHistory bonHist = new BonusHistory();
                bonHist.BonusCount = curBonus.BonusCount.Value;
                bonHist.FinancingSource = FinancingSource.GetFinancingSourceByName(curBonus.BonusFinancingSourceName);
                bonHist.DateBegin = dtNewDate.Value;
                bonHist.Prikaz = cbNewPrikaz.SelectedItem as Prikaz;
                bonHist.Bonus = bon;
            }
            KadrController.Instance.SubmitChanges();
        }
        private void ApplyBtn_Click(object sender, EventArgs e)
        {
            foreach (FactStaff fcSt in KadrController.Instance.Model.FactStaffs)
            {
                if (fcSt.MonthHourCount > 0)
                {
                    FactStaffMonthHour hour = new FactStaffMonthHour();

                    hour.MonthNumber = cbMonth.SelectedIndex + 1;
                    hour.YearNumber = Convert.ToInt32(cbYear.SelectedItem);
                    hour.HourCount = Convert.ToDecimal(fcSt.MonthHourCount);
                    hour.FactStaff = fcSt;
                    fcSt.MonthHourCount = null;
                    KadrController.Instance.Model.FactStaffMonthHours.InsertOnSubmit(hour);

                    KadrController.Instance.SubmitChanges();

                    //назначаем надбавку, если почасовик работает по договору
                    if (fcSt.IsContractHourStaff)
                    {
                        Bonus bonus = new Bonus();
                        BonusHistory bonusHistory = new BonusHistory();

                        try
                        {
                            bonus.DateEnd = Convert.ToDateTime("01." + (cbMonth.SelectedIndex + 2).ToString() + '.' + cbYear.SelectedItem.ToString()).AddDays(-1);
                            bonusHistory.DateBegin = Convert.ToDateTime("01." + (cbMonth.SelectedIndex + 1).ToString() + '.' + cbYear.SelectedItem.ToString());
                        }
                        catch
                        {
                            bonus.DateEnd = null;
                        }

                        bonus.BonusType = BonusType.HourBonus;
                        bonus.Comment = tbComment.Text;

                        bonusHistory.BonusCount = hour.BonusSum.Value;
                        bonusHistory.Prikaz = cbPrikazBegin.SelectedItem as Prikaz;
                        if (cbFinancingSource.Text == "")
                            bonusHistory.FinancingSource = fcSt.FinancingSource;
                        else
                            bonusHistory.FinancingSource = cbFinancingSource.SelectedItem as FinancingSource;
                        bonusHistory.Bonus = bonus;

                        BonusFactStaff bonusFcSt = new BonusFactStaff();
                        bonusFcSt.FactStaff = fcSt.MainFactStaff;
                        bonusFcSt.Bonus = bonus;

                        KadrController.Instance.Model.Bonus.InsertOnSubmit(bonus);
                        KadrController.Instance.Model.BonusHistories.InsertOnSubmit(bonusHistory);
                        KadrController.Instance.Model.BonusFactStaffs.InsertOnSubmit(bonusFcSt);

                        KadrController.Instance.SubmitChanges();

                    }

                }

            }
        }
        private void ApplyBtn_Click(object sender, EventArgs e)
        {
            foreach (FactStaff fcSt in KadrController.Instance.Model.FactStaffs)
            {
                if (fcSt.BonusCount > 0)
                {
                    Bonus bonus = new Bonus();

                    try
                    {
                        bonus.DateEnd = Convert.ToDateTime(mtbDateEnd.Text);
                    }
                        catch
                    {
                        bonus.DateEnd = null;
                    }

                    if (cbPrikazIntermEnd.Text != "")
                        bonus.IntermediateEndPrikaz = cbPrikazIntermEnd.SelectedItem as Prikaz;
                    if (cbPrikazEnd.Text != "")
                        bonus.EndPrikaz = cbPrikazEnd.SelectedItem as Prikaz;
                    bonus.BonusType = cbBonusType.SelectedItem as BonusType;
                    bonus.Comment = tbComment.Text;

                    BonusHistory bonusHistory = new BonusHistory();
                    bonusHistory.BonusCount = fcSt.BonusCount.Value;
                    if (fcSt.BonusFinancingSourceName != null)
                        bonusHistory.FinancingSource = FinancingSource.GetFinancingSourceByName(fcSt.BonusFinancingSourceName);
                    else
                    {
                        if (cbFinancingSource.Text == "")
                            bonusHistory.FinancingSource = fcSt.FinancingSource;
                        else
                            bonusHistory.FinancingSource = cbFinancingSource.SelectedItem as FinancingSource;
                    }
                    if (fcSt.BonusDateBegin != null)
                        bonusHistory.DateBegin = fcSt.BonusDateBegin.Value;
                    else
                        bonusHistory.DateBegin = dtDateBegin.Value;
                    bonusHistory.Prikaz = cbPrikazBegin.SelectedItem as Prikaz;

                    bonusHistory.Bonus = bonus;

                    BonusFactStaff bonusFcSt = new BonusFactStaff();
                    bonusFcSt.FactStaff = fcSt;
                    bonusFcSt.Bonus = bonus;
                    fcSt.BonusCount = null;

                    KadrController.Instance.SubmitChanges();
                 }
            }
        }
        private void ApplyBtn_Click(object sender, EventArgs e)
        {
            if ((dtNewDate.Value == null)
                ||(cbBonusType.SelectedItem == null)
                || (cbNewPrikaz.SelectedItem == null))
            {
               MessageBox.Show("Внесите все данные!");
               return;
            }

             var deps = KadrController.Instance.Model.GetSubDepartmentsWithPeriod(1, dtNewDate.Value, dtNewDate.Value).ToArray();

            //выбираем все надбавки указанного типа, которые еще действующие
             var bonus = KadrController.Instance.Model.Bonus.Where(bn => bn.BonusType == cbBonusType.SelectedItem).Where(bn =>
                         (bn.DateEnd > dtNewDate.Value) || (bn.DateEnd == null)).ToArray().Where(bn => deps.Select(dep => dep.idDepartment).Contains(bn.Department.id)).ToArray();

            //для каждой подходящей по условиям надбавки создаем запись истории
            foreach (Bonus bon in bonus)
            {
                //проверяем, если сотрудник уволен к началу месяца продления надбавки, то ему не продлеваем
                if (bon.BonusFactStaff != null)
                    if (bon.BonusFactStaff.FactStaff.DateEnd <= dtNewDate.Value.AddDays(-dtNewDate.Value.Day+1))
                        continue;
                BonusHistory bonHist = new BonusHistory();
                bonHist.BonusCount = bon.LastBonusCount;
                bonHist.DateBegin = dtNewDate.Value;
                bonHist.Prikaz = cbNewPrikaz.SelectedItem as Prikaz;
                if ((chbWithFinSource.Checked) && (cbFinancingSource.SelectedItem != null))
                {
                    //если источник финансирования <не указано>
                    if ((cbFinancingSource.SelectedItem as FinancingSource).id == 0)
                    {
                        bonHist.FinancingSource = bon.ObjectFinancingSource;
                    }
                    else
                        bonHist.FinancingSource = cbFinancingSource.SelectedItem as FinancingSource;
                }
                else //если источник просто не указан, то берем источник надбавки
                {
                    bonHist.FinancingSource = bon.LastFinancingSource;
                }
                bonHist.Bonus = bon;
            }
            KadrController.Instance.SubmitChanges();
        }
        /// <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);

                    //заполнение источника финансирования
                    if (bonusObject is FactStaff)
                    {
                        dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusHistory, FinancingSource>(bonusHistory, "FinancingSource", (bonusObject as FactStaff).PlanStaff.FinancingSource, null), this);
                    }

                    if (bonusObject is PlanStaff)
                    {
                        dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusHistory, FinancingSource>(bonusHistory, "FinancingSource", (bonusObject as PlanStaff).FinancingSource, null), this);
                    }

                    if ((bonusObject is Post) || (bonusObject is Employee))
                    {
                        dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusHistory, FinancingSource>(bonusHistory, "FinancingSource", FinancingSource.DefaultFinancingSource, 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.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);
                            dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusPlanStaff, bool>(bonusPlanStaff, "ForVacancy", true, null), this);
                            dlg.CommandManager.Execute(new UIX.Commands.GenericPropertyCommand<BonusPlanStaff, bool>(bonusPlanStaff, "ForEmployee", false, 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);
                        }

                    }

                };

                dlg.UpdateObjectList = () =>
                {
                    dlg.ObjectList = KadrController.Instance.Model.Bonus;
                };

                dlg.ShowDialog();
            }
        }
 public BonusHistoryDecorator(BonusHistory bonusHistory)
 {
     this.bonusHistory = bonusHistory;
 }