public static bool Delete(Copy c) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Delete Copy where copyNumber = @copyNumber", cn); cmd.Parameters.AddWithValue("@copyNumber", c.CopyNumber); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Update(Copy b) { return CopyDA.Update(b); }
public static bool Insert(Copy b) { return CopyDA.Insert(b); }
public static bool Delete(Copy b) { return CopyDA.Delete(b); }
public static bool Update(Copy c) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Update Copy set bookNumber = @bookNumber, " + "sequenceNumber = @sequenceNumber, type = @type, price=@price where copyNumber = @copyNumber", cn); cmd.Parameters.AddWithValue("@copyNumber", c.CopyNumber); cmd.Parameters.AddWithValue("@bookNumber", c.BookNumber); cmd.Parameters.AddWithValue("@sequenceNumber", c.SequenceNumber); cmd.Parameters.AddWithValue("@type", c.Type); cmd.Parameters.AddWithValue("@price", c.Price); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Insert(Copy c) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Insert into Copy(copyNumber, bookNumber, sequenceNumber, type, price)" + "values(@copyNumber, @bookNumber, @sequenceNumber, @type, @price)", cn); cmd.Parameters.AddWithValue("@copyNumber", c.CopyNumber); cmd.Parameters.AddWithValue("@bookNumber", c.BookNumber); cmd.Parameters.AddWithValue("@sequenceNumber", c.SequenceNumber); cmd.Parameters.AddWithValue("@type", c.Type); cmd.Parameters.AddWithValue("@price", c.Price); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (System.Exception ex) { MessageBox.Show(ex.Message); return false; } }
private void buttonCEdit_Click(object sender, EventArgs e) { if (!isSelectedCopy()) { MessageBox.Show("Please select a copy to edit"); return; } if (buttonCEdit.Text == "Finish") { Copy c = new Copy(); c.BookNumber = int.Parse(txtBookNumber1.Text); c.CopyNumber = int.Parse(txtCopyNumber.Text); c.SequenceNumber = int.Parse(txtSequenceNumber.Text); c.Type = char.Parse(txtType.Text); c.Price = float.Parse(txtPrice.Text); CopyBL.Update(c); refreshCopy(); } else { buttonCEdit.Text = "Finish"; txtType.Enabled = true; txtPrice.Enabled = true; } }
private void buttonCDelete_Click(object sender, EventArgs e) { if (!isSelectedCopy()) { MessageBox.Show("Please select a copy to delete"); return; } Copy c = new Copy(); c.CopyNumber = int.Parse(dataGridViewCopy.SelectedRows[0].Cells["copyNumber"].Value.ToString()); CopyBL.Delete(c); refreshCopy(); }
private void buttonCAdd_Click(object sender, EventArgs e) { //Check selected book if (!isSelectedBook()) { MessageBox.Show("Please select a Book to add copy for it!"); return; } txtType.Enabled = true; txtPrice.Enabled = true; if (buttonCAdd.Text == "Finish") { //Check type: if (txtType.Text!="" && txtType.Text != "A" && txtType.Text != "R") { txtType.Clear(); MessageBox.Show("Re-enter Type of Copy : 'A' or 'R'"); txtType.Focus(); return; } //Check price if (txtPrice.Text != "") { float n; bool isNum = float.TryParse(txtPrice.Text.Trim(), out n); if (!isNum) { txtPrice.Clear(); MessageBox.Show("Wrong format, re-enter price!"); txtPrice.Focus(); return; } } Copy c = new Copy(); c.BookNumber = int.Parse(txtBookNumber1.Text); c.CopyNumber = int.Parse(txtCopyNumber.Text); c.SequenceNumber = int.Parse(txtSequenceNumber.Text); if(txtType.Text=="") c.Type=' '; else c.Type = char.Parse(txtType.Text); if (txtPrice.Text == "") c.Price = 0; else c.Price = float.Parse(txtPrice.Text); CopyBL.Insert(c); refreshCopy(); buttonCAdd.Text = "Add"; } else { buttonCAdd.Text = "Finish"; int max = ++CopyBL.copyNumberMax; txtCopyNumber.Text = max.ToString(); CopyBL.SetSequenceNumberMax(int.Parse(txtBookNumber.Text)); int maxS = ++CopyBL.sequenceNumberMax; txtSequenceNumber.Text = maxS.ToString(); txtBookNumber1.Text = txtBookNumber.Text; txtType.Focus(); } }