public frmParentReport(Parent parent, DataContainer data) { InitializeComponent(); //this.Text = title; this.parent = parent; this.data = data; }
public void loadItems() { children = dbConnection.selectAllChildren(); parents = dbConnection.selectAllParents(); employees = dbConnection.selectAllStaff(); contacts = dbConnection.selectAllContacts(); Child exampleChild1 = new Child(); Parent exampleParent1 = new Parent(); exampleParent1.FirstName = "Lewis"; exampleParent1.LastName = "Sharp"; exampleParent1.Title = "Mr"; exampleParent1.Gender = 'M'; exampleParent1.WorkPhone = "01234567890"; exampleParent1.HomePhone = "07704123874"; exampleParent1.Email = "*****@*****.**"; exampleChild1.ChildID = 12; exampleChild1.FirstName = "Gemima"; exampleChild1.LastName = "Sharp"; exampleChild1.Gender = 'F'; exampleChild1.DOB = new DateTime(2008, 04, 15); exampleChild1.FirstLanguage = "English"; exampleChild1.RoomAttending = "Teddy's Transformers"; exampleChild1.DateApplied = new DateTime(2009, 06, 17); exampleChild1.DateLeft = new DateTime(); exampleChild1.Attendance = new bool[5] { true, false, false, true, true }; exampleChild1.ExtraDays = 2; exampleChild1.Teas = 3; exampleChild1.ParentsIDs.Add(exampleParent1.ParentID); children.Add(exampleChild1); parents.Add(exampleParent1); }
public frmEditParent(String title, Parent ParentToEdit) { InitializeComponent(); this.Text = title; dbConnection = new Database(); isEdit = true; txtFirstName.Text = ParentToEdit.FirstName; txtLastName.Text = ParentToEdit.LastName; if (ParentToEdit.Gender == 'M') { cmbGender.Text = "Male"; } else if (ParentToEdit.Gender == 'F') { cmbGender.Text = "Female"; } editID = ParentToEdit.ParentID; txtTitle.Text = ParentToEdit.Title; txtHomePhone.Text = ParentToEdit.HomePhone; txtWorkPhone.Text = ParentToEdit.WorkPhone; txtMobilePhone.Text = ParentToEdit.MobilePhone; txtHomeAddress1.Text = ParentToEdit.HomeAddress.Address1; txtHomeCounty.Text = ParentToEdit.HomeAddress.County; txtHomePostCode.Text = ParentToEdit.HomeAddress.PostCode; txtHomeTown.Text = ParentToEdit.HomeAddress.City; txtWorkAddress1.Text = ParentToEdit.WorkAddress.Address1; txtWorkCounty.Text = ParentToEdit.WorkAddress.County; txtWorkPostCode.Text = ParentToEdit.WorkAddress.PostCode; txtWorkTown.Text = ParentToEdit.WorkAddress.City; }
public frmParentReport(Parent parent) { InitializeComponent(); //this.Text = title; this.parent = parent; data = new DataContainer(); }
private void btnSave_Click(object sender, EventArgs e) { Parent createdParent = new Parent(); createdParent = constructParent(); if (!isEdit) { dbConnection.insertAddress(createdParent.HomeAddress); dbConnection.insertAddress(createdParent.WorkAddress); dbConnection.insertParent(createdParent); } else if (isEdit) { dbConnection.updateParent(createdParent); } this.Close(); }
private Parent constructParent() { Parent createdParent = new Parent(); createdParent.Title = txtTitle.Text; createdParent.FirstName = txtFirstName.Text; createdParent.LastName = txtLastName.Text; createdParent.Gender = cmbGender.Text[0]; createdParent.HomePhone = txtHomePhone.Text; createdParent.WorkPhone = txtWorkPhone.Text; createdParent.MobilePhone = txtMobilePhone.Text; if (isEdit) { createdParent.ParentID = editID; } createdParent.HomeAddress = constructHomeAddress(); createdParent.WorkAddress = constructWorkAddress(); return createdParent; }
public Parent selectParent(int parentIDToSelect) { MySqlConnection connection = OpenConnection(); if (connection == null) return null; MySqlCommand selectCommand = new MySqlCommand(null, connection); selectCommand.CommandText = @"SELECT * FROM parent_guardian WHERE Parent_ID = @parentID INNER JOIN address homeAddr ON parent_guardian.Home_Address = homeAddr.Address_1 INNER JOIN address workAddr ON parent_guardian.Work_Address = wordAddr.Address_1 INNER JOIN child_has_parent_guardian ON parent_guardian.Parent_ID = child_has_parent_guardian.Parent_ID WHERE parent_guardian.Parent_ID = @parentID;"; selectCommand.Parameters.AddWithValue("@parentID", parentIDToSelect); Console.WriteLine("Executing: [ " + selectCommand.CommandText + "]."); selectCommand.Prepare(); MySqlDataReader parentReader = selectCommand.ExecuteReader(); //Package into Parent domain entity object Parent newParent = new Parent(); while (parentReader.Read()) { newParent = constructParent(parentReader); newParent.ChildrenAttending.Add(parentReader.GetInt16("Child_ID")); } parentReader.Close(); CloseConnection(connection); return newParent; }
public void linkParentChild(Child childToAdd, Parent parent) { MySqlConnection connection = OpenConnection(); if (connection == null) return; MySqlCommand insertCommand = new MySqlCommand(null, connection); insertCommand.CommandText = "INSERT INTO child_has_parent_guardian VALUES (@childID, @parentID);"; insertCommand.Parameters.AddWithValue("@childID", childToAdd.ChildID); insertCommand.Parameters.AddWithValue("@parentID", parent.ParentID); Console.WriteLine("Executing: [ " + insertCommand.CommandText + "]."); insertCommand.Prepare(); insertCommand.ExecuteNonQuery(); CloseConnection(connection); }
public void insertParent(Parent parentToAdd) { MySqlConnection connection = OpenConnection(); if (connection == null) return; MySqlCommand insertCommand = new MySqlCommand(null, connection); insertCommand.CommandText = @"INSERT INTO parent_guardian (First_Name, Last_Name, Title, Gender, Work_Phone, Home_Phone, Mobile_Phone, Home_Address, Work_Address, Spouse, Email) VALUES (@firstname, @lastname, @title, @gender, @workphone, @homephone, @mobilephone, @homeaddress, @workaddress, @spouse, @email);"; insertCommand.Parameters.AddWithValue("@firstname", parentToAdd.FirstName); insertCommand.Parameters.AddWithValue("@lastname", parentToAdd.LastName); insertCommand.Parameters.AddWithValue("@gender", parentToAdd.Gender); insertCommand.Parameters.AddWithValue("@title", parentToAdd.Title); insertCommand.Parameters.AddWithValue("@workphone", parentToAdd.WorkPhone); insertCommand.Parameters.AddWithValue("@homephone", parentToAdd.HomePhone); insertCommand.Parameters.AddWithValue("@mobilephone", parentToAdd.MobilePhone); insertCommand.Parameters.AddWithValue("@homeaddress", parentToAdd.HomeAddress.Address1); insertCommand.Parameters.AddWithValue("@workaddress", parentToAdd.WorkAddress.Address1); insertCommand.Parameters.AddWithValue("@spouse", parentToAdd.Spouse); insertCommand.Parameters.AddWithValue("@email", parentToAdd.Email); // Call Prepare after setting the Commandtext and Parameters. Console.WriteLine("Executing: [ " + insertCommand.CommandText + "]."); insertCommand.Prepare(); insertCommand.ExecuteNonQuery(); //Remember the last medical id MySqlCommand idCommand = new MySqlCommand("SELECT LAST_INSERT_ID()", connection); object test = idCommand.ExecuteScalar(); try { lastParentID = int.Parse(test.ToString()); } catch (ArgumentNullException) { } catch (FormatException) { } CloseConnection(connection); }
private Parent constructParent(MySqlDataReader parentReader) { Parent newParent = new Parent(); newParent.ParentID = parentReader.GetInt32("Parent_ID"); newParent.FirstName = parentReader.GetString("First_Name"); newParent.LastName = parentReader.GetString("Last_Name"); newParent.Title = parentReader.GetString("Title"); newParent.Gender = parentReader.GetChar("Gender"); newParent.HomePhone = parentReader.GetString("Home_Phone"); newParent.WorkPhone = parentReader.GetString("Work_Phone"); newParent.MobilePhone = parentReader.GetString("Mobile_Phone"); newParent.HomeAddress = constructMultipleAddress(parentReader, "home"); newParent.WorkAddress = constructMultipleAddress(parentReader, "work"); //newParent.Spouse = childReader.GetInt16(10); newParent.Email = SafeGetString(parentReader, "Email"); //Neglecting list of children? return newParent; }
public bool updateParent(Parent parentToUpdate) { MySqlConnection connection = OpenConnection(); if (connection == null) return false; MySqlCommand updateCommand = new MySqlCommand(null, connection); updateCommand.CommandText = @"UPDATE parent_guardian SET First_Name = @firstname, Last_Name = @lastname, Title = @title, Gender = @gender, Work_Phone = @workphone, Home_Phone = @homephone, Mobile_Phone = @mobilephone, Home_Address = @homeaddress, Work_Address = @workaddress, Spouse = @spouse, Email = @email WHERE Parent_ID = @parentid;"; updateCommand.Parameters.AddWithValue("@parentid", parentToUpdate.ParentID); updateCommand.Parameters.AddWithValue("@firstname", parentToUpdate.FirstName); updateCommand.Parameters.AddWithValue("@lastname", parentToUpdate.LastName); updateCommand.Parameters.AddWithValue("@gender", parentToUpdate.Gender); updateCommand.Parameters.AddWithValue("@title", parentToUpdate.Title); updateCommand.Parameters.AddWithValue("@workphone", parentToUpdate.WorkPhone); updateCommand.Parameters.AddWithValue("@homephone", parentToUpdate.HomePhone); updateCommand.Parameters.AddWithValue("@mobilephone", parentToUpdate.MobilePhone); updateCommand.Parameters.AddWithValue("@homeaddress", parentToUpdate.HomeAddress.Address1); updateCommand.Parameters.AddWithValue("@workaddress", parentToUpdate.WorkAddress.Address1); updateCommand.Parameters.AddWithValue("@spouse", parentToUpdate.Spouse); updateCommand.Parameters.AddWithValue("@email", parentToUpdate.Email); // Call Prepare after setting the Commandtext and Parameters. Console.WriteLine("Executing: [ " + updateCommand.CommandText + "]."); updateCommand.Prepare(); updateCommand.ExecuteNonQuery(); return (CloseConnection(connection)); }