public PrescriptionGlasses(int id) { SetValues(id); try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString); query = "select LensId, FrameId from PRESCRIPTION_GLASSES where ProductId=" + id; cmd = new SqlCommand(query, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { lens = new Lens((int)reader[0]); frame = new Frame((int)reader[1]); } con.Close(); } catch (SqlException ex) { Exception e = new Exception("Database Connection Error. " + ex.Message); throw e; } }
public PrescriptionGlasses(string name, decimal price, int discount, int quantity, string frameColor, string productDescription, bool stopOrder, Lens lens, Frame frame) { Product p = new Product(name, price, quantity, discount, frameColor, productDescription, stopOrder); id = p.ProductId; Name = p.Name; Price = p.Price; Quantity = p.Quantity; Discount = p.Discount; FrameColor = p.FrameColor; StopOrder = p.StopOrder; ProductDescription = p.ProductDescription; try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString); query = "INSERT INTO [PRESCRIPTION_GLASSES] ([ProductId] ,[LensId] ,[FrameId]) VALUES (" + id + " ," + lens.LensId + " ," + frame.FrameId + ")"; cmd = new SqlCommand(query, con); con.Open(); if (cmd.ExecuteNonQuery() != 1) { Exception e = new Exception("Data not inserted into the database"); throw e; } con.Close(); } catch (SqlException ex) { Exception e = new Exception("Database Connection Error. " + ex.Message); throw e; } }