//If the user clicks the item in the list view the fields of the form are automatically filled private void listViewOrder_MouseClick(object sender, MouseEventArgs e) { ListViewItem item = listViewOrder.SelectedItems[0]; textBoxOrId.Text = item.SubItems[0].Text; comboBoxOrdClient.Text = ClientDA.SearchID(Convert.ToInt32(item.SubItems[1].Text)).ClientName; comboBoxOrdISBN.Text = item.SubItems[2].Text; textBoxOrdBkQt.Text = item.SubItems[5].Text; comboBoxOrdMadeBy.Text = item.SubItems[6].Text; dateTimePickerOrder.Text = item.SubItems[7].Text; textBoxOrdTPrice.Text = item.SubItems[8].Text; }
//Enable the buttons delete and update in case of a valid entered ID private void textBoxClID_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxClID.Text)) { buttonClDel.Enabled = false; buttonClUpdate.Enabled = false; return; } if (ClientDA.SearchID(Convert.ToInt32(textBoxClID.Text)) != null) { buttonClDel.Enabled = true; buttonClUpdate.Enabled = true; return; } buttonClDel.Enabled = false; buttonClUpdate.Enabled = false; }
//Search private void buttonClSearch_Click(object sender, EventArgs e) { Client aclient = new Client(); if (!string.IsNullOrEmpty(textBoxClSearch.Text)) { switch (comboBoxClSearch.SelectedIndex) { case -1: MessageBox.Show("Please select a valid search option!"); return; case 0: int tempId; if (!int.TryParse(textBoxClSearch.Text, out tempId)) { MessageBox.Show("Please enter a valid term to be searched.", "No search information!"); return; } aclient = ClientDA.SearchID(Convert.ToInt32(textBoxClSearch.Text)); break; case 1: aclient = ClientDA.SearchName(textBoxClSearch.Text); break; } if (aclient == null) { MessageBox.Show("Client not found!", "Not found!"); textBoxClSearch.Clear(); textBoxClSearch.Focus(); return; } ClientDA.ListSearch(aclient, listViewSales); return; } MessageBox.Show("Please enter a valid term to be searched.", "No search information!"); return; }