/// <summary> /// Inserts the provided Construct object as a new record into the database /// </summary> /// <param name="temp">Construct object to be added to the database</param> /// <returns>True if add is successful, false otherwise</returns> public Boolean addConstruct(Construct temp) { conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Construct VALUES(" + temp.labID + ",'" + temp.name + "','" + temp.insert + "','" + temp.vector + "','" + temp.species + "','" + temp.antibioticResistance + "','" + temp.digestSite5 + "','" + temp.digestSite3 + "','" + temp.notes + "');", conn); cmd.CommandType = CommandType.Text; int i = cmd.ExecuteNonQuery(); conn.Close(); if (i > 0) return true; else return false; }
// Save changes of object protected void btnSave_click(Object sender, EventArgs e) { Construct temp = new Construct(); temp.id = int.Parse(txtid.Value); temp.labID = int.Parse(ddllabID.SelectedValue); if (ddlantibioticResistance.SelectedValue != "Other") { temp.antibioticResistance = ddlantibioticResistance.SelectedValue; } else { temp.antibioticResistance = txtantibioticResistance.Text; } String digestSite5 = ""; int i = 0; foreach (ListItem li in ddldigestSite5.Items) { if (li.Selected == true) { if (i > 0) { digestSite5 += ","; } digestSite5 += li.Value; i++; } } temp.digestSite5 = digestSite5; String digestSite3 = ""; i = 0; foreach (ListItem li in ddldigestSite3.Items) { if (li.Selected == true) { if (i > 0) { digestSite3 += ","; } digestSite3 += li.Value; i++; } } temp.digestSite3 = digestSite3; temp.insert = txtinsert.Text; temp.name = txtname.Text; temp.notes = txtnotes.Text; temp.species = txtspecies.Text; temp.vector = txtvector.Text; myConn.updateConstruct(temp); gvConstructs.DataBind(); }
// submit protected void btnSubmit_click(Object sender, EventArgs e) { Construct construct = new Construct(); construct.name = txtname.Text; construct.labID = int.Parse(ddlLabID.SelectedValue); construct.insert = txtinsert.Text; construct.species = txtSpecies.Text; construct.vector = txtvector.Text; if (ddlantibioticResistance.SelectedValue != "Other") { construct.antibioticResistance = ddlantibioticResistance.SelectedValue; } else { construct.antibioticResistance = txtantibioticResistance.Text; } String digestSite5 = ""; int i = 0; foreach (ListItem li in ddldigestSite5.Items) { if (li.Selected == true) { if (i > 0) { digestSite5 += ","; } digestSite5 += li.Value; i++; } } construct.digestSite5 = digestSite5; String digestSite3 = ""; i = 0; foreach (ListItem li in ddldigestSite3.Items) { if (li.Selected == true) { if (i > 0) { digestSite3 += ","; } digestSite3 += li.Value; i++; } } construct.digestSite3 = digestSite3; if (myConn.addConstruct(construct)) { Response.Redirect("Constructs.aspx"); } }
/// <summary> /// Compares the ID of the current Construct object to that of a provided Construct /// </summary> /// <param name="temp">Construct object to be compared to.</param> /// <returns>True if the ID's are equal (meaning the constructs are the same), false otherwise.</returns> public Boolean Equals(Construct temp) { return(this.id == temp.id); }
/// <summary> /// Updates the construct record with the matching ID /// </summary> /// <param name="temp">Construct object to be written to the database</param> public Boolean updateConstruct(Construct temp) { conn.Open(); SqlCommand cmd = new SqlCommand("UPDATE dbo.Construct SET LabID='" + temp.labID + "', Name='" + temp.name + "', [Construct].[Insert]='" + temp.insert + "', Vector='" + temp.vector + "', Species='" + temp.species + "', AntibioticResistance='" + temp.antibioticResistance + "', [Construct].[3'DigestSite]='" + temp.digestSite3 + "', [Construct].[5'DigestSite]='" + temp.digestSite5 + "', Note='" + temp.notes + "' WHERE ID=" + temp.id + ";", conn); cmd.CommandType = CommandType.Text; int i = cmd.ExecuteNonQuery(); conn.Close(); if (i > 0) return true; else return false; }
/// <summary> /// Gets the construct denoted by the provided ID /// </summary> /// <param name="id">ID of the construct to be located</param> /// <returns>Construct object if found, null if not</returns> public Construct getConstructByID(int id) { conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM Construct WHERE ID=" + id + ";", conn); SqlDataReader rdr = cmd.ExecuteReader(); Construct temp; if (rdr.Read()) temp = new Construct(Convert.ToInt32(rdr.GetValue(0)), Convert.ToInt32(rdr.GetValue(1)), rdr.GetValue(2).ToString(), rdr.GetValue(3).ToString(), rdr.GetValue(4).ToString(), rdr.GetValue(5).ToString(), rdr.GetValue(6).ToString(), rdr.GetValue(7).ToString(), rdr.GetValue(8).ToString(), rdr.GetValue(9).ToString(), null); else temp = null; conn.Close(); return temp; }
/// <summary> /// Gets every Construct record in the database, saves each one in a new Construct object, and puts it in an ArrayList. /// </summary> /// <returns>ArrayList of Construct objects</returns> public ArrayList getAllConstructs() { conn.Open(); ArrayList temp = new ArrayList(); SqlCommand cmd = new SqlCommand("dbo.getConstructRecords", conn); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Construct tempConstruct = new Construct(Convert.ToInt32(rdr.GetValue(0)), Convert.ToInt32(rdr.GetValue(1)), rdr.GetValue(2).ToString(), rdr.GetValue(3).ToString(), rdr.GetValue(4).ToString(), rdr.GetValue(5).ToString(), rdr.GetValue(6).ToString(), rdr.GetValue(7).ToString(), rdr.GetValue(8).ToString(), rdr.GetValue(9).ToString(), rdr.GetValue(11).ToString()); temp.Add(tempConstruct); } conn.Close(); return temp; }
protected void createPDF(Stream output) { //Construct tempConstruct = myConn.getConstructByID(Convert.ToInt16(Request.QueryString["id"])); Construct tempConstruct = myConn.getConstructByID(2); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=construct_" + tempConstruct.id + ".pdf"); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); //Page title and spacing iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Construct Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20)); document.Add(pageTitle); iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" "); document.Add(spacing); //Name iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph(); iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Construct Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempConstruct.name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Insert tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Insert: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.insert, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Vector tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Vector: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.vector, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Species tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.species, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Antibiotic Resistance tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Antibiotic Resistance: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.antibioticResistance, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //5' Digest Site tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("5' Digest Site: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.digestSite5, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //3' Digest Site tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Working Dilution: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.digestSite3, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Notes tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Notes: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.notes, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); document.Close(); }
/// <summary> /// Compares the ID of the current Construct object to that of a provided Construct /// </summary> /// <param name="temp">Construct object to be compared to.</param> /// <returns>True if the ID's are equal (meaning the constructs are the same), false otherwise.</returns> public Boolean Equals(Construct temp) { return this.id == temp.id; }