private void AddPersonRow(Person newPerson)
        {
            datatablePersons.NRows = RowNum + 1;

            Gtk.Label labelSurame = new Gtk.Label ("Фамилия:");
            datatablePersons.Attach (labelSurame, (uint)0, (uint)1, RowNum, RowNum + 1, (AttachOptions)0, (AttachOptions)0, (uint)0, (uint)0);

            var nameDataEntry = new yEntry ();
            nameDataEntry.Binding.AddBinding(newPerson, e => e.Lastname, w => w.Text).InitializeFromSource();
            nameDataEntry.WidthChars = 20;
            datatablePersons.Attach (nameDataEntry, (uint)1, (uint)2, RowNum, RowNum + 1, AttachOptions.Expand | AttachOptions.Fill, (AttachOptions)0, (uint)0, (uint)0);

            Gtk.Label labelName = new Gtk.Label ("Имя:");
            datatablePersons.Attach (labelName, (uint)2, (uint)3, RowNum, RowNum + 1, (AttachOptions)0, (AttachOptions)0, (uint)0, (uint)0);

            var surnameDataEntry = new yEntry ();
            surnameDataEntry.Binding.AddBinding(newPerson, e => e.Name, w => w.Text).InitializeFromSource();
            surnameDataEntry.WidthChars = 20;
            datatablePersons.Attach (surnameDataEntry, (uint)3, (uint)4, RowNum, RowNum + 1, AttachOptions.Expand | AttachOptions.Fill, (AttachOptions)0, (uint)0, (uint)0);

            Gtk.Label labelPatronymic = new Gtk.Label ("Отчество:");
            datatablePersons.Attach (labelPatronymic, (uint)4, (uint)5, RowNum, RowNum + 1, (AttachOptions)0, (AttachOptions)0, (uint)0, (uint)0);

            var patronymicDataEntry = new yEntry ();
            patronymicDataEntry.Binding.AddBinding(newPerson, e => e.PatronymicName, w => w.Text).InitializeFromSource();
            patronymicDataEntry.WidthChars = 20;
            datatablePersons.Attach (patronymicDataEntry, (uint)5, (uint)6, RowNum, RowNum + 1, AttachOptions.Expand | AttachOptions.Fill, (AttachOptions)0, (uint)0, (uint)0);

            Gtk.Button deleteButton = new Gtk.Button ();
            Gtk.Image image = new Gtk.Image ();
            image.Pixbuf = Stetic.IconLoader.LoadIcon (this, "gtk-delete", global::Gtk.IconSize.Menu);
            deleteButton.Image = image;
            deleteButton.Clicked += OnButtonDeleteClicked;
            datatablePersons.Attach (deleteButton, (uint)6, (uint)7, RowNum, RowNum + 1, (AttachOptions)0, (AttachOptions)0, (uint)0, (uint)0);

            datatablePersons.ShowAll ();

            RowNum++;
        }
        /// <summary>
        /// Запуск простого диалога редактирования справочника
        /// </summary>
        /// <returns>Возвращает экземпляр сохраненного объекта, загруженного в сессии диалога. То есть не переданный объект.
        /// Если пользователь отказался от сохранения возвращаем null.
        /// </returns>
        /// <param name="editObject">Объект для редактирования. Если null создаем новый объект.</param>
        public static object RunSimpleDialog(Window parent, System.Type objectType, object editObject)
        {
            using (IUnitOfWork uow = UnitOfWorkFactory.CreateWithoutRoot ())
            {
                //Создаем объект редактирования
                object tempObject;
                if(editObject == null)
                {
                    tempObject = Activator.CreateInstance (objectType);
                }
                else
                {
                    if(editObject is IDomainObject)
                    {
                        tempObject = uow.GetById(objectType, (editObject as IDomainObject).Id);
                    }
                    else
                    {
                        throw new InvalidCastException ("У объекта переданного для запуска простого диалога, нет интерфейса IDomainObject, объект не может быть открыт.");
                    }
                }

                //Создаем диалог
                Dialog editDialog = new Dialog("Редактирование", parent, Gtk.DialogFlags.Modal);
                editDialog.AddButton("Отмена", ResponseType.Cancel);
                editDialog.AddButton("Сохранить", ResponseType.Ok);
                Gtk.Table editDialogTable = new Table(1, 2, false);
                Label LableName = new Label("Название:");
                LableName.Justify = Justification.Right;
                editDialogTable.Attach(LableName, 0, 1, 0, 1);
                yEntry inputNameEntry = new yEntry();
                inputNameEntry.WidthRequest = 300;
                inputNameEntry.Binding.AddBinding(tempObject, "Name", w => w.Text).InitializeFromSource ();
                editDialogTable.Attach(inputNameEntry, 1, 2, 0, 1);
                editDialog.VBox.Add(editDialogTable);

                //Запускаем диалог
                editDialog.ShowAll();
                int result = editDialog.Run();
                if (result == (int)ResponseType.Ok) {
                    string name = (string)tempObject.GetPropertyValue ("Name");
                    if (String.IsNullOrWhiteSpace (name)) {
                        var att = DomainHelper.GetSubjectNames (tempObject);
                        string subjectName = att != null ? att.Accusative : null;
                        string msg = String.Format ("Название {0} пустое и не будет сохранено.",
                                         string.IsNullOrEmpty (subjectName) ? "элемента справочника" : subjectName
                                     );
                        MessageDialogWorks.RunWarningDialog (msg);
                        logger.Warn (msg);
                        editDialog.Destroy ();
                        return null;
                    }
                    var list = uow.Session.CreateCriteria (objectType)
                        .Add (Restrictions.Eq ("Name", name))
                        .Add (Restrictions.Not (Restrictions.IdEq (DomainHelper.GetId (tempObject))))
                        .List ();
                    if (list.Count > 0) {
                        var att = DomainHelper.GetSubjectNames (tempObject);
                        string subjectName = att != null ? StringWorks.StringToTitleCase (att.Nominative) : null;
                        string msg = String.Format ("{0} с таким названием уже существует.",
                                         string.IsNullOrEmpty (subjectName) ? "Элемент справочника" : subjectName
                                     );
                        MessageDialogWorks.RunWarningDialog (msg);
                        logger.Warn (msg);
                        editDialog.Destroy ();
                        return list [0];
                    }
                    uow.TrySave (tempObject);
                    uow.Commit ();
                    OrmMain.NotifyObjectUpdated (tempObject);
                }
                else
                    tempObject = null;

                editDialog.Destroy();
                return tempObject;
            }
        }
        private void AddPhoneRow(Phone newPhone)
        {
            datatablePhones.NRows = RowNum + 1;

            var phoneDataCombo = new yListComboBox();
            phoneDataCombo.WidthRequest = 100;
            phoneDataCombo.SetRenderTextFunc((PhoneType x) => x.Name);
            phoneDataCombo.ItemsList = phoneTypes;
            phoneDataCombo.Binding.AddBinding(newPhone, e => e.NumberType, w => w.SelectedItem).InitializeFromSource();
            datatablePhones.Attach (phoneDataCombo, (uint)0, (uint)1, RowNum, RowNum + 1, AttachOptions.Fill | AttachOptions.Expand, (AttachOptions)0, (uint)0, (uint)0);

            Gtk.Label textPhoneLabel = new Gtk.Label ("+7");
            datatablePhones.Attach (textPhoneLabel, (uint)1, (uint)2, RowNum, RowNum + 1, (AttachOptions)0, (AttachOptions)0, (uint)0, (uint)0);

            var phoneDataEntry = new yValidatedEntry ();
            phoneDataEntry.ValidationMode = ValidationType.phone;
            phoneDataEntry.WidthChars = 19;
            phoneDataEntry.Binding.AddBinding(newPhone, e => e.Number, w => w.Text).InitializeFromSource();
            datatablePhones.Attach (phoneDataEntry, (uint)2, (uint)3, RowNum, RowNum + 1, AttachOptions.Expand | AttachOptions.Fill, (AttachOptions)0, (uint)0, (uint)0);

            Gtk.Label textAdditionalLabel = new Gtk.Label ("доб.");
            datatablePhones.Attach (textAdditionalLabel, (uint)3, (uint)4, RowNum, RowNum + 1, (AttachOptions)0, (AttachOptions)0, (uint)0, (uint)0);

            var additionalDataEntry = new yEntry ();
            additionalDataEntry.WidthRequest = 50;
            additionalDataEntry.MaxLength = 10;
            additionalDataEntry.Binding.AddBinding(newPhone, e => e.Additional, w => w.Text).InitializeFromSource();
            datatablePhones.Attach (additionalDataEntry, (uint)4, (uint)5, RowNum, RowNum + 1, AttachOptions.Expand | AttachOptions.Fill, (AttachOptions)0, (uint)0, (uint)0);

            Gtk.Button deleteButton = new Gtk.Button ();
            Gtk.Image image = new Gtk.Image ();
            image.Pixbuf = Stetic.IconLoader.LoadIcon (this, "gtk-delete", global::Gtk.IconSize.Menu);
            deleteButton.Image = image;
            deleteButton.Clicked += OnButtonDeleteClicked;
            datatablePhones.Attach (deleteButton, (uint)5, (uint)6, RowNum, RowNum + 1, (AttachOptions)0, (AttachOptions)0, (uint)0, (uint)0);

            datatablePhones.ShowAll ();

            RowNum++;
        }