private void Edit(int Id, string nrecordname, string ndescription, string nyear, string nprice) { // method for editing info string sql = "Update Records Set RecordName = '" + nrecordname + "', Description = '" + ndescription + "', Year = '" + nyear + "', Price = '" + nprice + "' where RecordId = " + Id + ""; sqlcom = new SqlCommand(sql, sqlconn); try { if (sqlconn.State == ConnectionState.Closed) { sqlconn.Open(); } sqladapt = new SqlDataAdapter(sqlcom); sqladapt.UpdateCommand = sqlconn.CreateCommand(); sqladapt.UpdateCommand.CommandText = sql; if (sqladapt.UpdateCommand.ExecuteNonQuery() > 0) { MessageBox.Show("Data Successfully Updated!"); } sqlconn.Close(); Records bago = new Records(); bago.UserUsers = functionUsers; bago.Text = "Records - Admin"; bago.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
private void RecordsToolStripMenuItem_Click(object sender, EventArgs e) { // show records form to admin Records recs = new Records(); recs.Text = "Records - Admin"; this.Hide(); recs.UserUsers = HomeUser; recs.Show(); }
private void BtnExit_Click(object sender, EventArgs e) { // opens new object if form is search or edit, otherwise form closes if (this.Text == "SEARCH" || this.Text == "EDIT" || this.Text == "ADD") { Records new1 = new Records(); new1.UserUsers = FunctionUsers; new1.Text = "Records - Admin"; new1.Show(); this.Close(); } this.Close(); }
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!"); } }