Example #1
0
        private void OnAdd(object parameter)
        {
            if (parameter == null || !CanAdd(parameter))
            {
                return;
            }

            var obj = Activator.CreateInstance((Type)parameter);

            foreach (var property in obj.GetType().GetProperties())
            {
                if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(List <>))
                {
                    property.SetValue(obj, Activator.CreateInstance(property.PropertyType));
                }
            }

            m_rows.Add(obj);

            m_editor.ObjectsGrid.SelectedItem = obj;
            m_editor.ObjectsGrid.ScrollIntoView(obj);
            m_editor.ObjectsGrid.Focus();

            var editedObject = new EditedObject(obj, ObjectState.Added);

            m_editedObjects.Push(editedObject);
        }
Example #2
0
        private static void SaveEditedObject(EditedObject obj)
        {
            switch (obj.State)
            {
            case ObjectState.Added:
                DatabaseManager.Instance.Database.Insert(obj.Object);
                break;

            case ObjectState.Removed:
                DatabaseManager.Instance.Database.Delete(obj.Object);
                break;

            case ObjectState.Dirty:
                DatabaseManager.Instance.Database.Update(obj.Object);
                break;
            }

            obj.State = ObjectState.None;
        }
        /// <summary>
        /// Initializes a blank value row with displayed property name + adds the row if a row with the given index doesn't exist
        /// </summary>
        /// <param name="rowIndex">Index of the particular DataGridView row</param>
        /// <param name="propertyName">Name of a property to be displayed</param>
        private void initializePropertyRowWithPropertyName(int rowIndex, string propertyName)
        {
            // testing whether a row with this index exists
            if (rowIndex + 1 > this.RowCount)
            {
                this.RowCount = rowIndex + 1;
            }

            this[0, rowIndex].ReadOnly  = true;
            this[0, rowIndex].ValueType = typeof(string);
            if (EditedObject.GetType().ImplementsInterface(typeof(AlgoNature.Components.ITranslatable)))
            {
                this[0, rowIndex].Value = ((AlgoNature.Components.ITranslatable)EditedObject).TryTranslate(propertyName);
            }
            else
            {
                this[0, rowIndex].Value = propertyName;
            }
            if (this[2, rowIndex].Value == null)
            {
                this[2, rowIndex].Value = rowIndex;
            }
        }
Example #4
0
 /// <summary>
 /// This method just calls <see cref="M:Northwoods.Go.GoObject.DoEndEdit(Northwoods.Go.GoView)" /> on the
 /// <see cref="P:Northwoods.Go.GoControl.EditedObject" />.
 /// </summary>
 /// <param name="view"></param>
 public override void DoEndEdit(GoView view)
 {
     EditedObject?.DoEndEdit(view);
 }
 void SetFocused(EditedObject<DbSchemaModel> edited)
 {
     if (edited.NewState == DataState.Modified)
     {
         int index = models.IndexOf(edited.DataObject);
         gridView.ClearSelection();
         gridView.Rows[index].Cells[gridView.Columns["col"
             + edited.PropertyName].DisplayIndex].Selected = true;
     }
 }