private void UpdateProjectProjectNameComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { DB1 = new DBManager(); projects p = DB1.GetProjects("SELECT * FROM projects WHERE project_name = '" + ((ComboBox)sender).SelectedItem.ToString() + "'").First(); clients c = DB1.GetClients("SELECT a.* FROM clients a , projects b WHERE a.client_id = b.client_id AND a.client_id = " + p.client_id).First(); Debug.WriteLine("SELECT a.* FROM clients a , projects b WHERE a.client_id = b.client_id AND a.client_id = " + p.client_id); //populate fields with values this.UpdateProjectProjectNameTextBox.Text = p.project_name; this.UpdateProjectDescriptionTextBox.Text = p.description; this.UpdateProjectLocationTextBox.Text = p.location; this.UpdateProjectStartDatePicker.SelectedDate = p.start_date; this.UpdateProjectEndDatePicker.SelectedDate = p.end_date; this.UpdateProjectClientTextBox.Text = c.client_name; } catch { } }
private void UpdateProjectButton_Click(object sender, RoutedEventArgs e) { try { // check for empty ness CheckForEmpty(this.UpdateProjectGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } DB1 = new DBManager(); Container Entity1 = new Container(); Entity1._project.project_id = DB1.GetProjects("SELECT * FROM projects WHERE project_name = '" + this.UpdateProjectProjectNameComboBox.SelectedItem.ToString() + "'").First().project_id; Entity1._project.project_name = this.UpdateProjectProjectNameTextBox.Text; Entity1._project.location = this.UpdateProjectLocationTextBox.Text; Entity1._project.description = this.UpdateProjectDescriptionTextBox.Text; Entity1._project.end_date = (DateTime)this.UpdateProjectEndDatePicker.SelectedDate; Entity1._project.start_date = (DateTime)this.UpdateProjectStartDatePicker.SelectedDate; // get the client try { List<clients> cc = DB1.GetClients(""); var result = from item in cc where item.client_name.ToLower().Contains(this.RegisterProjectClientTextBox.Text.ToLower()) select item; if (result != null) { Entity1._project.client_id = Convert.ToInt32(((List<clients>)result.ToList()).First().client_id); } } catch { } if (DB1.UpdateProject(Entity1._project)) { MessageBox.Show("Project Successfully updated"); EmptyAllfields(this.UpdateProjectGrid); Initialization(); //this.UpdateProjectProjectNameComboBox = new ComboBox(); //ComboboxPopulating(this.UpdateProjectProjectNameComboBox, null); } } catch { } }