protected void Button1_Click(object sender, EventArgs e) { Copy c = new Copy(); c.CopyNumber = int.Parse(tbCopyNumber.Text); c.BookNumber = int.Parse(tbBookNumner.Text); c.Type = Convert.ToChar(DropDownList1.Text); c.SequenceNumber = int.Parse(tbSequeceNum.Text); c.Price = double.Parse(tbPrice.Text); if (CopyBL.Insert(c)) { Response.Redirect("CopyGUI.aspx"); } }
public static Boolean Delete(Copy c) { try { string strConn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand("delete Copy where copyNumber = @copyNumber", conn); cmd.Parameters.Add(new SqlParameter("@copyNumber", c.CopyNumber)); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Insert(Copy c) { return CopyDA.Insert(c); }
public static bool Delete(Copy c) { return CopyDA.Delete(c.CopyNumber); }
public static bool Update(Copy c) { return CopyDA.Update(c); }
public static Copy GetCopy(int copyNumber) { try { string strConn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString; SqlConnection cn = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand("select * from Copy where copyNumber = @copyNumber", cn); cmd.Parameters.AddWithValue("@copyNumber", copyNumber); cn.Open(); SqlDataReader rd = cmd.ExecuteReader(); if (rd.Read()) { Copy b = new Copy(int.Parse(rd["bookNumber"].ToString()), int.Parse(rd["copyNumber"].ToString()), int.Parse(rd["sequenceNumber"].ToString()), rd["type"].ToString()[0], double.Parse(rd["price"].ToString())); rd.Close(); cn.Close(); return b; } else { rd.Close(); cn.Close(); return null; } } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } }
public static bool Update(Copy c) { try { string strConn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand("update Copy set bookNumber = @bookNumber" + ", sequenceNumber=@sequenceNumber, type = @type, price = @price where copyNumber = @copyNumber", conn); cmd.Parameters.Add(new SqlParameter("@copyNumber", c.CopyNumber)); cmd.Parameters.Add(new SqlParameter("@bookNumber", c.BookNumber)); cmd.Parameters.Add(new SqlParameter("@sequenceNumber", c.SequenceNumber)); cmd.Parameters.Add(new SqlParameter("@type", c.Type)); cmd.Parameters.Add(new SqlParameter("@price", c.Price)); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Insert(Copy c) { try { string strConn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand("insert into copy(copyNumber, bookNumber, sequenceNumber, type, price)" + "values (@copyNumber, @bookNumber, @sequenceNumber, @type, @price)", conn); cmd.Parameters.Add(new SqlParameter("@bookNumber", c.BookNumber)); cmd.Parameters.Add(new SqlParameter("@copyNumber", c.CopyNumber)); cmd.Parameters.Add(new SqlParameter("@sequenceNumber", c.SequenceNumber)); cmd.Parameters.Add(new SqlParameter("@type", c.Type)); cmd.Parameters.Add(new SqlParameter("@price", c.Price)); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }