private void btnWli_search_Click(object sender, EventArgs e) { if (validateNonRepItem_search()) { Buisness_Logic.nonRepairable_Item prd = new Buisness_Logic.nonRepairable_Item(); Buisness_Logic.nonRepairableItem_repository nrirep = new Buisness_Logic.nonRepairableItem_repository(); bool x = nrirep.searchWL_Items((string.IsNullOrEmpty(txtwl_code.Text) ? 0 : int.Parse(txtwl_code.Text)), txtwl_name.Text.ToString(), prd); if (x) { MessageBox.Show("Record found.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtwl_name.Text = prd.name; txtwl_qty.Text = prd.qty.ToString(); txtwl_price.Text = prd.price.ToString(); txtwl_make.Text = prd.make.ToString(); txtwl_weight.Text = prd.weight.ToString(); txtwl_model.Text = prd.model; txtwl_code.Text = prd.invID.ToString(); picboxWli.SizeMode = PictureBoxSizeMode.StretchImage; MemoryStream ms = new MemoryStream(prd.photo); ms.Read(prd.photo, 0, prd.photo.Length); picboxWli.Image = Image.FromStream(ms); } else { MessageBox.Show("No record found.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnwliUpdate_Click(object sender, EventArgs e) { if (validateInvUpdate_weightLifting()) { Buisness_Logic.nonRepairableItem_repository nrirepo = new Buisness_Logic.nonRepairableItem_repository(); Buisness_Logic.nonRepairable_Item prd = new Buisness_Logic.nonRepairable_Item(); int newq = (string.IsNullOrEmpty(txtwl_Newqty.Text) ? 0 : int.Parse(txtwl_Newqty.Text)) + int.Parse(txtwl_qty.Text); prd.name = txtwl_name.Text; prd.make = txtwl_make.Text; prd.model = txtwl_model.Text; prd.qty = newq; prd.price = double.Parse(txtwl_price.Text); prd.weight = double.Parse(txtwl_weight.Text); prd.invID = int.Parse(txtwl_code.Text); MemoryStream ms = new MemoryStream(); picboxWli.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] photo_prod = ms.ToArray(); prd.photo = photo_prod; if (nrirepo.updateWeightLiftingItems(prd)) { MessageBox.Show("Record update succesfull.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtwl_qty.Text = prd.qty.ToString(); } } }
public bool updateWeightLiftingItems(Buisness_Logic.nonRepairable_Item prd) { DataLayer.dbConnect con = new DataLayer.dbConnect(); con.openConnection(); bool temp = false; SqlTransaction trn = con.getConnection().BeginTransaction(); try { string qry1 = "update tbl_inventory set name=@name,make=@make,model=@model,price=@price,photo=@photo where invID=@id"; SqlCommand cmd = new SqlCommand(qry1, con.getConnection()); cmd.Parameters.AddWithValue("@name", prd.name); cmd.Parameters.AddWithValue("@make", prd.make); cmd.Parameters.AddWithValue("@model", prd.model); cmd.Parameters.AddWithValue("@price", prd.price); cmd.Parameters.AddWithValue("@photo", prd.photo); cmd.Parameters.AddWithValue("@id", prd.invID); cmd.Transaction = trn; cmd.ExecuteNonQuery(); string qry2 = "update tbl_non_repairable set qty=@qty,weight=@weight where invetoryID=@invid"; SqlCommand cmd2 = new SqlCommand(qry2, con.getConnection()); cmd2.Parameters.AddWithValue("@weight", prd.weight); cmd2.Parameters.AddWithValue("@qty", prd.qty); cmd2.Parameters.AddWithValue("@invid", prd.invID); cmd2.Transaction = trn; cmd2.ExecuteNonQuery(); trn.Commit(); temp = true; con.closeConnection(); } catch (Exception dsa) { trn.Rollback(); throw; } if (temp == true) { return(true); } else { return(false); } }
public bool searchWL_Items(int id, string pname, Buisness_Logic.nonRepairable_Item prd) { // Buisness_Logic.product prd = new Buisness_Logic.product(); bool temp = false; DataLayer.dbConnect con = new DataLayer.dbConnect(); con.openConnection(); try { string qr = "select * from view_nonRepItems where invID=@id or name=@name"; SqlCommand cmd = new SqlCommand(qr, con.getConnection()); cmd.Parameters.AddWithValue("@id", id); cmd.Parameters.AddWithValue("@name", pname); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { prd.invID = (int)dt.Rows[0]["invID"]; prd.name = dt.Rows[0]["name"].ToString(); prd.make = dt.Rows[0]["make"].ToString(); prd.qty = (int)dt.Rows[0]["qty"]; prd.price = (double)dt.Rows[0]["price"]; prd.weight = (double)dt.Rows[0]["weight"]; prd.model = dt.Rows[0]["model"].ToString(); prd.photo = (byte[])dt.Rows[0]["photo"]; temp = true; } } catch (Exception pt) { throw; } if (temp == true) { return(true); } else { return(false); } }
private void btnsave_Int1_Click(object sender, EventArgs e) { if (validateInvAdd()) { try { Buisness_Logic.inventory inv = new Buisness_Logic.inventory(); if (radio_nonRep.Checked) { Buisness_Logic.nonRepairable_Item nr = new Buisness_Logic.nonRepairable_Item(); //initialize image MemoryStream memt1p1 = new MemoryStream(); pictureBox_i2.Image.Save(memt1p1, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] photo_inv = memt1p1.ToArray(); nr.name = txtI1_iname.Text; nr.make = txtI1_imake.Text; nr.model = txtI1_imodel.Text; nr.price = double.Parse(txtI1_iprice.Text); nr.qty = int.Parse(txtInv_1qty.Text); nr.weight = double.Parse(txtInv1Weight.Text); nr.photo = photo_inv; Buisness_Logic.nonRepairableItem_repository nrir = new Buisness_Logic.nonRepairableItem_repository(); if (nrir.addNonRepairabItems(nr)) { MessageBox.Show("Success", "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Information); txtI1_icode.Text = nr.invID.ToString(); } else { MessageBox.Show("Data insertion failed.", "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (radio_repItems.Checked) { Buisness_Logic.repairablerable_Items repi = new Buisness_Logic.repairablerable_Items(); MemoryStream memt1p1 = new MemoryStream(); pictureBox_i2.Image.Save(memt1p1, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] photo_inv = memt1p1.ToArray(); repi.name = txtI1_iname.Text; repi.make = txtI1_imake.Text; repi.model = txtI1_imodel.Text; repi.price = double.Parse(txtI1_iprice.Text); repi.photo = photo_inv; Buisness_Logic.repairableItem_repository repirep = new Buisness_Logic.repairableItem_repository(); if (repirep.addRepItems(repi)) { MessageBox.Show("Success", "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Information); txtI1_icode.Text = repi.invID.ToString(); } else { MessageBox.Show("Data insertion failed.", "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Select either Repair or non Repair button.", "Caution", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception EX) { MessageBox.Show(EX.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } }