private void Add(String recordname, String description, string year, string price) { // method for adding into db String sql = "Insert into Records(RecordName,Description,Year,Price) Values (@recordname,@description,@year,@price)"; sqlcom = new SqlCommand(sql, sqlconn); sqlcom.Parameters.AddWithValue("@recordname", recordname); sqlcom.Parameters.AddWithValue("@description", description); sqlcom.Parameters.AddWithValue("@year", year); sqlcom.Parameters.AddWithValue("@price", price); try { if (sqlconn.State == ConnectionState.Closed) { sqlconn.Open(); } if (sqlcom.ExecuteNonQuery() > 0) { MessageBox.Show("Data Successfully Added!"); } sqlconn.Close(); int recordID = GetRecordId(recordname); AddShipping(recordID, 0); Records newadd = new Records(); newadd.UserUsers = FunctionUsers; newadd.Text = "Records - Admin"; newadd.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!"); } }
public void Search() { // method for searching info using parameters based on checked checkboxes searchparams = ""; if (!chkRecord.Checked && !chkDescription.Checked && !chkYear.Checked && !chkPrice.Checked) { MessageBox.Show("Please CHECK search parameter and ENTER data into CHECKED field!", "WARNING"); return; } try { if (chkRecord.Checked) { if (string.IsNullOrEmpty(txtRecord.Text)) { MessageBox.Show("Search field \"RECORD NAME\" must not be EMPTY!", "ERROR!"); return; } if (string.IsNullOrEmpty(searchparams)) { searchparams += "RecordName like '" + txtRecord.Text + "%" + "'"; } else { searchparams += " and RecordName like '" + txtRecord.Text + "%" + "'"; } } if (chkDescription.Checked) { if (string.IsNullOrEmpty(txtDescription.Text)) { MessageBox.Show("Search field \"DESCRIPTION\" must not be EMPTY!", "ERROR!"); return; } if (string.IsNullOrEmpty(searchparams)) { searchparams += "Description like '" + txtDescription.Text + "%" + "'"; } else { searchparams += " and Description like '" + txtDescription.Text + "%" + "'"; } } if (chkYear.Checked) { if (string.IsNullOrEmpty(txtYear.Text)) { MessageBox.Show("Search field \"YEAR\" must not be EMPTY!", "ERROR!"); return; } if (string.IsNullOrEmpty(searchparams)) { searchparams += "Year like " + txtYear.Text; } else { searchparams += " and Year like " + txtYear.Text; } } if (chkPrice.Checked) { int plus1 = Convert.ToInt32(txtPrice.Text) + 1; if (string.IsNullOrEmpty(txtPrice.Text)) { MessageBox.Show("Search field \"PRICE\" must not be EMPTY!", "ERROR!"); return; } if (string.IsNullOrEmpty(searchparams)) { searchparams += "Price between " + txtPrice.Text + " and " + plus1; } else { searchparams += " and Price between " + txtPrice.Text + " and " + plus1; } } Records passdata = new Records(); passdata.Trial += searchparams; passdata.UserUsers = FunctionUsers; passdata.Text = "Records - Admin"; passdata.TrialRetrieve(); passdata.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR!"); } }