/// <summary> /// Loads the ItemTypes combobox with a list of ItemTypes from the database. /// </summary> private void PopulateMenus() { using (TeamJDBEntities context = new TeamJDBEntities()) { // Load the items combobox var itemQuery = from itemType in context.ItemTypes select itemType; foreach (var result in itemQuery) { this.itemComboBox.Items.Add(result.Type.ToString()); } // To Deselect the Combo Box this.itemComboBox.SelectedIndex = -1; // Load the sections combobox var sectionQuery = from section in context.Sections select section; foreach (var result in sectionQuery) { this.sectionComboBox.Items.Add(result.Location.ToString()); } // To Deselect the Combo Box this.sectionComboBox.SelectedIndex = -1; } }
/// <summary> /// Checks to see if the person object is already contained in the database. /// </summary> /// <param name="sender">The Person object of the class</param> /// <returns> True if the object exists in the database, false otherwise.</returns> public Boolean HasPerson(Person person) { using (TeamJDBEntities context = new TeamJDBEntities()) { var peopleQuery = from people in context.People where people.FirstName == person.FirstName && people.MiddleName == person.MiddleName && people.LastName == person.LastName && people.Addr == person.Addr && people.City == person.City && people.State == person.State && people.Zip == person.Zip && people.Phone == person.Phone && people.Email == person.Email select people; if (peopleQuery.Count() == 0) { return(false); } else { return(true); } } }
// Getting the minimum sale date and the // maximum sale date so that the user knows // the existing range of dates when entering // information private void SetPurchaseDates() { using (TeamJDBEntities context = new TeamJDBEntities()) { DateTime minDate = DateTime.Today; foreach (Sale s in context.Sales) { if (s.Date.CompareTo(minDate) == -1) { minDate = s.Date; } } DateTime maxDate = minDate; foreach (Sale s in context.Sales) { if (s.Date.CompareTo(maxDate) == 1) { maxDate = s.Date; } } this.purchaseStartDatePicker.Value = minDate; this.purchaseEndDatePicker.Value = maxDate; } }
/// <summary> /// Loads data entered into the database, enforcing mappings /// </summary> /// <param name="sender">The object that is calling the method</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void buttonUpdate_Click(object sender, EventArgs e) { using (TeamJDBEntities context = new TeamJDBEntities()) { Guid donorID; Guid recipientID; PersonInfoPanel donorPanel = (PersonInfoPanel)personInfoPanelDonor; donorPanel.savePerson(); Person donor = donorPanel.getPerson(); if (donorPanel.HasPerson(donor)) { donorID = Guid.Parse(donorPanel.GetID()); } else { donorID = donor.PersonID; context.People.AddObject(donor); } // Process the recipient information PersonInfoPanel recipientPanel = (PersonInfoPanel)personInfoPanelRecipient; recipientPanel.savePerson(); Person recipient = recipientPanel.getPerson(); if (recipientPanel.HasPerson(recipient)) { recipientID = Guid.Parse(recipientPanel.GetID()); } else { recipientID = recipient.PersonID; context.People.AddObject(recipient); } TransactionPanel salePanel = (TransactionPanel)transactionPanel1; salePanel.SaveSale(); Sale sale = salePanel.GetSale(); Item item = new Item(); item.ItemID = Guid.NewGuid(); item.ItemTypeID = salePanel.GetItemID(); sale.SaleID = Guid.NewGuid(); sale.DonorID = donorID; sale.DedicationID = recipientID; context.Sales.AddObject(sale); try { context.AcceptAllChanges(); } catch (Exception) { } } }
/// <summary> /// Sets up the query and populates the list box with the results /// </summary> /// <param name="search">Name of person to search</param> private void setSearchString(String search) { using (TeamJDBEntities context = new TeamJDBEntities()) { // Make sure list box will show new search results this.listBoxSelect.Items.Clear(); // query database for any combination of users entered var peopleQuery = from people in context.People join sale in context.Sales on people.PersonID equals sale.DonorID where (people.FirstName + people.LastName == search) || (people.LastName + people.FirstName == search) || (people.FirstName.Contains(search)) || (people.LastName.Contains(search)) || (people.LastName == search) || (people.FirstName == search) orderby sale.Date descending select new { sale, people }; // populate listbox wit results foreach (var result in peopleQuery) { this.listBoxSelect.Items.Add(result.people.FirstName + " " + result.people.LastName + " - " + result.sale.Date.ToShortDateString() + " - " + "Donor"); } peopleQuery = from people in context.People join sale in context.Sales on people.PersonID equals sale.DedicationID where (people.FirstName + people.LastName == search) || (people.LastName + people.FirstName == search) || (people.FirstName.Contains(search)) || (people.LastName.Contains(search)) || (people.LastName == search) || (people.FirstName == search) orderby sale.Date descending select new { sale, people }; // populate listbox wit results foreach (var result in peopleQuery) { this.listBoxSelect.Items.Add(result.people.FirstName + " " + result.people.LastName + " - " + result.sale.Date.ToShortDateString() + " - " + "Recipient"); } this.listBoxSelect.Sorted = true; } }
/// <summary> /// Loads the ItemTypes combobox with a list of ItemTypes from the database. /// </summary> private void LoadComboBox() { using (TeamJDBEntities context = new TeamJDBEntities()) { this.comboBoxItemType.Items.Add("<Select Item>"); var itemQuery = from itemType in context.ItemTypes select itemType; foreach (var result in itemQuery) { this.comboBoxItemType.Items.Add(result.Type.ToString()); } this.comboBoxItemType.SelectedIndex = 0; } }
/// <summary> /// Returns the ItemType ID of the item selected in the combobox /// </summary> /// <returns>The Guid ID of the ItemType</returns> public Guid GetItemID() { using (TeamJDBEntities context = new TeamJDBEntities()) { string selectedItem = this.comboBoxItemType.GetItemText(this.comboBoxItemType.SelectedItem).ToString(); var itemIDQuery = from itemID in context.ItemTypes where itemID.Type == selectedItem select itemID; foreach (var result in itemIDQuery) { return result.ItemTypeID; } return Guid.Parse(null); } }
/// <summary> /// Returns the ItemType ID of the item selected in the combobox /// </summary> /// <returns>The Guid ID of the ItemType</returns> public Guid GetItemID() { using (TeamJDBEntities context = new TeamJDBEntities()) { string selectedItem = this.comboBoxItemType.GetItemText(this.comboBoxItemType.SelectedItem).ToString(); var itemIDQuery = from itemID in context.ItemTypes where itemID.Type == selectedItem select itemID; foreach (var result in itemIDQuery) { return(result.ItemTypeID); } return(Guid.Parse(null)); } }
/// <summary> /// Gets the PersonID Guid of the Person object. /// </summary> /// <returns>The Guid ID of the person being searched for if it exists, null if it doesn't exist.</returns> public String GetID() { using (TeamJDBEntities context = new TeamJDBEntities()) { var peopleQuery = from people in context.People where people.FirstName == person.FirstName && people.MiddleName == person.MiddleName && people.LastName == person.LastName && people.Addr == person.Addr && people.City == person.City && people.State == person.State && people.Zip == person.Zip && people.Phone == person.Phone && people.Email == person.Email select people; foreach (var result in peopleQuery) return result.PersonID.ToString(); return null; } }
/// <summary> /// Sets the price field to the correct price of the type selected in the combobox of ItemTypes /// </summary> private void SetPriceField() { using (TeamJDBEntities context = new TeamJDBEntities()) { if (this.comboBoxItemType.SelectedIndex == 0) { textBoxPrice.Text = ""; } else { string selectedItem = this.comboBoxItemType.GetItemText(this.comboBoxItemType.SelectedItem).ToString(); var itemPriceQuery = from itemType in context.ItemTypes where itemType.Type == selectedItem select itemType; foreach (var result in itemPriceQuery) { this.textBoxPrice.Text = result.Price.ToString("0.00"); } } } }
/// <summary> /// Gets the PersonID Guid of the Person object. /// </summary> /// <returns>The Guid ID of the person being searched for if it exists, null if it doesn't exist.</returns> public String GetID() { using (TeamJDBEntities context = new TeamJDBEntities()) { var peopleQuery = from people in context.People where people.FirstName == person.FirstName && people.MiddleName == person.MiddleName && people.LastName == person.LastName && people.Addr == person.Addr && people.City == person.City && people.State == person.State && people.Zip == person.Zip && people.Phone == person.Phone && people.Email == person.Email select people; foreach (var result in peopleQuery) { return(result.PersonID.ToString()); } return(null); } }
private void Search() { using(TeamJDBEntities context = new TeamJDBEntities()) { } }
// Getting the minimum sale date and the // maximum sale date so that the user knows // the existing range of dates when entering // information private void SetPurchaseDates() { using (TeamJDBEntities context = new TeamJDBEntities()) { DateTime minDate = DateTime.Today; foreach (Sale s in context.Sales) if (s.Date.CompareTo(minDate) == -1) minDate = s.Date; DateTime maxDate = minDate; foreach (Sale s in context.Sales) if (s.Date.CompareTo(maxDate) == 1) maxDate = s.Date; this.purchaseStartDatePicker.Value = minDate; this.purchaseEndDatePicker.Value = maxDate; } }
private void Search() { using (TeamJDBEntities context = new TeamJDBEntities()) { } }
/// <summary> /// Checks to see if the person object is already contained in the database. /// </summary> /// <param name="sender">The Person object of the class</param> /// <returns> True if the object exists in the database, false otherwise.</returns> public Boolean HasPerson(Person person) { using (TeamJDBEntities context = new TeamJDBEntities()) { var peopleQuery = from people in context.People where people.FirstName == person.FirstName && people.MiddleName == person.MiddleName && people.LastName == person.LastName && people.Addr == person.Addr && people.City == person.City && people.State == person.State && people.Zip == person.Zip && people.Phone == person.Phone && people.Email == person.Email select people; if (peopleQuery.Count() == 0) return false; else return true; } }