public void DeletePerson(NSWindow window) {
			if (View.SelectedRow == -1) {
				var alert = new NSAlert () {
					AlertStyle = NSAlertStyle.Critical,
					InformativeText = "Please select the person to remove from the list of people.",
					MessageText = "Delete Person",
				};
				alert.BeginSheet (window);
			} else {
				// Grab person
				SelectedPerson = _people.GetItem<PersonModel> ((nuint)View.SelectedRow);

				// Confirm delete
				var alert = new NSAlert () {
					AlertStyle = NSAlertStyle.Critical,
					InformativeText = string.Format("Are you sure you want to delete person `{0}` from the table?",SelectedPerson.Name),
					MessageText = "Delete Person",
				};
				alert.AddButton ("Ok");
				alert.AddButton ("Cancel");
				alert.BeginSheetForResponse (window, (result) => {
					// Delete?
					if (result == 1000) {
						// Remove from database
						SelectedPerson.Delete(_conn);

						// Remove from screen
						RemovePerson(View.SelectedRow);
					}
				});
			}
		}
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();

			// Load the default person from the database
			Person = new PersonModel (Conn, "0");
	
		}
		private void LoadSelectedPerson (string id)
		{

			// Found?
			if (id != "") {
				// Yes, load requested record
				Person = new PersonModel (Conn, id);
			}
		}
		public PersonEditorSheetController (PersonModel person, bool isNew)
		{
			// Load the .xib file for the sheet
			NSBundle.LoadNib ("PersonEditSheet", this);

			CancelButton.Hidden = !isNew;

			// Save person
			Person = person;
		}
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();

			// Load only managers employees
			_conn.Open ();
			using (var command = _conn.CreateCommand ()) {
				// Create new command
				command.CommandText = "SELECT ID FROM [People] WHERE isManager = 1";

				using (var reader = command.ExecuteReader ()) {
					while (reader.Read ()) {
						// Load child and add to collection
						var childID = (string)reader [0];
						var person = new PersonModel (_conn, childID);
						AddPerson (person);
					}
				}
			}
			_conn.Close ();

		}
예제 #6
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            // Get access to database
            DatabaseConnection = GetDatabaseConnection();

            // Wire-up controls
            AddButton.Active     = false;
            AddButton.Activated += (sender, e) => {
                // Take action based on type
                switch (ViewType)
                {
                case SubviewType.TableBinding:
                    var controller = SubviewController as SubviewTableBindingController;
                    var person     = new PersonModel("Unknown", "Unknown");
                    var sheet      = new PersonEditorSheetController(person, true);

                    // Wire-up
                    sheet.PersonModified += (p) => {
                        // Save person to database
                        p.Create(DatabaseConnection);
                        controller.AddPerson(p);
                    };

                    // Display sheet
                    sheet.ShowSheet(this);
                    break;

                case SubviewType.CollectionView:
                    var collection       = SubviewController as SubviewCollectionViewController;
                    var collectionPerson = new PersonModel("Unknown", "Unknown");
                    var collectionSheet  = new PersonEditorSheetController(collectionPerson, true);

                    // Wire-up
                    collectionSheet.PersonModified += (p) => {
                        // Save person to database
                        p.Create(DatabaseConnection);
                        collection.AddPerson(p);
                    };

                    // Display sheet
                    collectionSheet.ShowSheet(this);
                    break;
                }
            };

            EditButton.Active     = false;
            EditButton.Activated += (sender, e) => {
                // Take action based on type
                switch (ViewType)
                {
                case SubviewType.TableBinding:
                    var controller = SubviewController as SubviewTableBindingController;
                    controller.EditPerson(this);
                    break;

                case SubviewType.CollectionView:
                    var collection = SubviewController as SubviewCollectionViewController;
                    collection.EditPerson(this);
                    break;
                }
            };

            DeleteButton.Active     = false;
            DeleteButton.Activated += (sender, e) => {
                // Take action based on type
                switch (ViewType)
                {
                case SubviewType.TableBinding:
                    var controller = SubviewController as SubviewTableBindingController;
                    controller.DeletePerson(this);
                    break;

                case SubviewType.CollectionView:
                    var collection = SubviewController as SubviewCollectionViewController;
                    collection.DeletePerson(this);
                    break;
                }
            };

            Search.Enabled       = false;
            Search.EditingEnded += (sender, e) => {
                // Take action based on type
                switch (ViewType)
                {
                case SubviewType.TableBinding:
                    var controller = SubviewController as SubviewTableBindingController;
                    controller.FindPerson(Search.StringValue);
                    break;

                case SubviewType.CollectionView:
                    var collection = SubviewController as SubviewCollectionViewController;
                    collection.FindPerson(Search.StringValue);
                    break;
                }
            };

            // Populate Source List
            SourceList.Initialize();

            var TableViews = new SourceListItem("Direct SQLite");

            TableViews.AddItem("Simple Binding", "shoebox.png", () => {
                DisplaySubview(new SubviewSimpleBindingController(DatabaseConnection), SubviewType.SimpleBinding);
            });
            TableViews.AddItem("Table Binding", "shoebox.png", () => {
                DisplaySubview(new SubviewTableBindingController(DatabaseConnection), SubviewType.TableBinding);
            });
            TableViews.AddItem("Outline Binding", "shoebox.png", () => {
                DisplaySubview(new SubviewOutlineBindingController(DatabaseConnection), SubviewType.OutlineBinging);
            });
            TableViews.AddItem("Collection View", "shoebox.png", () => {
                DisplaySubview(new SubviewCollectionViewController(DatabaseConnection), SubviewType.CollectionView);
            });
            SourceList.AddItem(TableViews);

            var ORMViews = new SourceListItem("SQLite.Net ORM");

            ORMViews.AddItem("Table Binding", "shoebox.png", () => {
                DisplaySubview(new SubviewTableORMController(), SubviewType.TableORM);
            });
            SourceList.AddItem(ORMViews);

            // Display Source List
            SourceList.ReloadData();
            SourceList.ExpandItem(null, true);
        }
		internal void RaisePersonModified(PersonModel person) {
			if (this.PersonModified!=null) this.PersonModified(person);
		}
예제 #8
0
		public void Load(SqliteConnection conn, string id) {
			bool shouldClose = false;

			// Clear last connection to prevent circular call to update
			_conn = null;

			// Is the database already open?
			if (conn.State != ConnectionState.Open) {
				shouldClose = true;
				conn.Open ();
			}

			// Execute query
			using (var command = conn.CreateCommand ()) {
				// Create new command
				command.CommandText = "SELECT * FROM [People] WHERE ID = @COL1";

				// Populate with data from the record
				command.Parameters.AddWithValue ("@COL1", id);

				using (var reader = command.ExecuteReader ()) {
					while (reader.Read ()) {
						// Pull values back into class
						ID = (string)reader [0];
						Name = (string)reader [1];
						Occupation = (string)reader [2];
						isManager = (bool)reader [3];
						ManagerID = (string)reader [4];
					}
				}
			}

			// Is this a manager?
			if (isManager) {
				// Yes, load children
				using (var command = conn.CreateCommand ()) {
					// Create new command
					command.CommandText = "SELECT ID FROM [People] WHERE ManagerID = @COL1";

					// Populate with data from the record
					command.Parameters.AddWithValue ("@COL1", id);

					using (var reader = command.ExecuteReader ()) {
						while (reader.Read ()) {
							// Load child and add to collection
							var childID = (string)reader [0];
							var person = new PersonModel (conn, childID);
							_people.Add (person);
						}
					}
				}
			}

			// Should we close the connection to the database
			if (shouldClose) {
				conn.Close ();
			}

			// Save last connection
			_conn = conn;
		}
예제 #9
0
		public void InsertPerson(PersonModel person, nint index) {
			WillChangeValue ("personModelArray");
			_people.Insert (person, index);
			DidChangeValue ("personModelArray");
		}
예제 #10
0
		public void AddPerson(PersonModel person) {
			WillChangeValue ("personModelArray");
			isManager = true;
			_people.Add (person);
			DidChangeValue ("personModelArray");
		}
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();

			// Configure Employee selector dropdown
			EmployeeSelector.DataSource = new ComboBoxDataSource (Conn, "People", "Name");

			// Wireup events
			EmployeeSelector.Changed += (sender, e) => {
				// Get ID
				var id = DataSource.IDForValue (EmployeeSelector.StringValue);
				LoadSelectedPerson (id);
			};

			EmployeeSelector.SelectionChanged += (sender, e) => {
				// Get ID
				var id = DataSource.IDForIndex (EmployeeSelector.SelectedIndex);
				LoadSelectedPerson (id);
			};

			// Auto select the first person
			EmployeeSelector.StringValue = DataSource.ValueForIndex (0);
			Person = new PersonModel (Conn, DataSource.IDForIndex(0));
	
		}
예제 #12
0
 public void InsertPerson(PersonModel person, nint index)
 {
     WillChangeValue("personModelArray");
     _people.Insert(person, index);
     DidChangeValue("personModelArray");
 }
예제 #13
0
 public void AddPerson(PersonModel person)
 {
     WillChangeValue("personModelArray");
     _people.Add(person);
     DidChangeValue("personModelArray");
 }
예제 #14
0
        public void Load(SqliteConnection conn, string id)
        {
            bool shouldClose = false;

            // Clear last connection to prevent circular call to update
            _conn = null;

            // Is the database already open?
            if (conn.State != ConnectionState.Open)
            {
                shouldClose = true;
                conn.Open();
            }

            // Execute query
            using (var command = conn.CreateCommand()) {
                // Create new command
                command.CommandText = "SELECT * FROM [People] WHERE ID = @COL1";

                // Populate with data from the record
                command.Parameters.AddWithValue("@COL1", id);

                using (var reader = command.ExecuteReader()) {
                    while (reader.Read())
                    {
                        // Pull values back into class
                        ID         = (string)reader [0];
                        Name       = (string)reader [1];
                        Occupation = (string)reader [2];
                        isManager  = (bool)reader [3];
                        ManagerID  = (string)reader [4];
                    }
                }
            }

            // Is this a manager?
            if (isManager)
            {
                // Yes, load children
                using (var command = conn.CreateCommand()) {
                    // Create new command
                    command.CommandText = "SELECT ID FROM [People] WHERE ManagerID = @COL1";

                    // Populate with data from the record
                    command.Parameters.AddWithValue("@COL1", id);

                    using (var reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            // Load child and add to collection
                            var childID = (string)reader [0];
                            var person  = new PersonModel(conn, childID);
                            _people.Add(person);
                        }
                    }
                }
            }

            // Should we close the connection to the database
            if (shouldClose)
            {
                conn.Close();
            }

            // Save last connection
            _conn = conn;
        }
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();

			// Load all employees
			_conn.Open ();
			using (var command = _conn.CreateCommand ()) {
				// Create new command
				command.CommandText = "SELECT ID FROM [People]";

				using (var reader = command.ExecuteReader ()) {
					while (reader.Read ()) {
						// Load child and add to collection
						var childID = (string)reader [0];
						var person = new PersonModel (_conn, childID);
						AddPerson (person);
					}
				}
			}
			_conn.Close ();

			// Wire-up events
			View.PersonSelected += (index) => {
				try {
					SelectedPerson = _people.GetItem<PersonModel>((nuint)index);
				} catch {
					SelectedPerson = null;
				}
			};

		}
예제 #16
0
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();

			// Get access to database
			DatabaseConnection = GetDatabaseConnection ();

			// Wire-up controls
			AddButton.Active = false;
			AddButton.Activated += (sender, e) => {
				// Take action based on type
				switch(ViewType) {
				case SubviewType.TableBinding:
					var controller = SubviewController as SubviewTableBindingController;
					var person = new PersonModel("Unknown","Unknown");
					var sheet = new PersonEditorSheetController(person, true);

					// Wire-up
					sheet.PersonModified += (p) => {
						// Save person to database
						p.Create(DatabaseConnection);
						controller.AddPerson(p);
					};

					// Display sheet
					sheet.ShowSheet(this);
					break;
				case SubviewType.CollectionView:
					var collection = SubviewController as SubviewCollectionViewController;
					var collectionPerson = new PersonModel("Unknown","Unknown");
					var collectionSheet = new PersonEditorSheetController(collectionPerson, true);

					// Wire-up
					collectionSheet.PersonModified += (p) => {
						// Save person to database
						p.Create(DatabaseConnection);
						collection.AddPerson(p);
					};

					// Display sheet
					collectionSheet.ShowSheet(this);
					break;
				}
			};

			EditButton.Active = false;
			EditButton.Activated += (sender, e) => {
				// Take action based on type
				switch(ViewType) {
				case SubviewType.TableBinding:
					var controller = SubviewController as SubviewTableBindingController;
					controller.EditPerson(this);
					break;
				case SubviewType.CollectionView:
					var collection = SubviewController as SubviewCollectionViewController;
					collection.EditPerson(this);
					break;
				}
			};

			DeleteButton.Active = false;
			DeleteButton.Activated += (sender, e) => {
				// Take action based on type
				switch(ViewType) {
				case SubviewType.TableBinding:
					var controller = SubviewController as SubviewTableBindingController;
					controller.DeletePerson(this);
					break;
				case SubviewType.CollectionView:
					var collection = SubviewController as SubviewCollectionViewController;
					collection.DeletePerson(this);
					break;
				}
			};

			Search.Enabled = false;
			Search.EditingEnded += (sender, e) => {
				// Take action based on type
				switch(ViewType) {
				case SubviewType.TableBinding:
					var controller = SubviewController as SubviewTableBindingController;
					controller.FindPerson(Search.StringValue);
					break;
				case SubviewType.CollectionView:
					var collection = SubviewController as SubviewCollectionViewController;
					collection.FindPerson(Search.StringValue);
					break;
				}
			};

			// Populate Source List
			SourceList.Initialize ();

			var TableViews = new SourceListItem ("Direct SQLite");
			TableViews.AddItem ("Simple Binding", "shoebox.png", () => {
				DisplaySubview(new SubviewSimpleBindingController(DatabaseConnection), SubviewType.SimpleBinding);
			});
			TableViews.AddItem ("Table Binding", "shoebox.png", () => {
				DisplaySubview(new SubviewTableBindingController(DatabaseConnection), SubviewType.TableBinding);
			});
			TableViews.AddItem ("Outline Binding", "shoebox.png", () => {
				DisplaySubview(new SubviewOutlineBindingController(DatabaseConnection), SubviewType.OutlineBinging);
			});
			TableViews.AddItem ("Collection View", "shoebox.png", () => {
				DisplaySubview(new SubviewCollectionViewController(DatabaseConnection), SubviewType.CollectionView);
			});
			SourceList.AddItem (TableViews);

			var ORMViews = new SourceListItem ("SQLite.Net ORM");
			ORMViews.AddItem ("Table Binding", "shoebox.png", () => {
				DisplaySubview(new SubviewTableORMController(), SubviewType.TableORM);
			});
			SourceList.AddItem (ORMViews);

			// Display Source List
			SourceList.ReloadData();
			SourceList.ExpandItem (null, true);
		}
예제 #17
0
		private SqliteConnection GetDatabaseConnection() {
			var documents = Environment.GetFolderPath (Environment.SpecialFolder.Desktop);
			string db = Path.Combine (documents, "People.db3");

			// Create the database if it doesn't already exist
			bool exists = File.Exists (db);
			if (!exists)
				SqliteConnection.CreateFile (db);

			// Create connection to the database
			var conn = new SqliteConnection("Data Source=" + db);

			// Set the structure of the database
			if (!exists) {
				var commands = new[] {
					"CREATE TABLE People (ID TEXT, Name TEXT, Occupation TEXT, isManager BOOLEAN, ManagerID TEXT)"
				};
				conn.Open ();
				foreach (var cmd in commands) {
					using (var c = conn.CreateCommand()) {
						c.CommandText = cmd;
						c.CommandType = CommandType.Text;
						c.ExecuteNonQuery ();
					}
				}
				conn.Close ();

				// Build list of employees
				var Craig = new PersonModel ("0","Craig Dunn", "Documentation Manager");
				Craig.AddPerson (new PersonModel ("Amy Burns", "Technical Writer"));
				Craig.AddPerson (new PersonModel ("Joel Martinez", "Web & Infrastructure"));
				Craig.AddPerson (new PersonModel ("Kevin Mullins", "Technical Writer"));
				Craig.AddPerson (new PersonModel ("Mark McLemore", "Technical Writer"));
				Craig.AddPerson (new PersonModel ("Tom Opgenorth", "Technical Writer"));
				Craig.Create (conn);

				var Larry = new PersonModel ("1","Larry O'Brien", "API Documentation Manager");
				Larry.AddPerson (new PersonModel ("Mike Norman", "API Documentor"));
				Larry.Create (conn);
			}

			// Return new connection
			return conn;
		}
		public void EditPerson(NSWindow window) {
			if (View.SelectedRow == -1) {
				var alert = new NSAlert () {
					AlertStyle = NSAlertStyle.Informational,
					InformativeText = "Please select the person to edit from the list of people.",
					MessageText = "Edit Person",
				};
				alert.BeginSheet (window);
			} else {
				// Grab person
				SelectedPerson = _people.GetItem<PersonModel> ((nuint)View.SelectedRow);

				var sheet = new PersonEditorSheetController(SelectedPerson, false);

				// Display sheet
				sheet.ShowSheet(window);

			}
		}