public static void addWarranty(SqlCommand cmd, int invID, Warranty warranty) { string sqlCommand = "INSERT INTO Warranty (InvID, Company, StartDate, EndDate, WarrantyType, Notes) VALUES (@InvID, @Company, @StartDate, @EndDate, @WarrantyType, @Notes)"; cmd.CommandText = sqlCommand; cmd.Parameters.AddWithValue("InvID", invID); cmd.Parameters.AddWithValue("Company", warranty.Company); cmd.Parameters.AddWithValue("StartDate", warranty.StartDate); cmd.Parameters.AddWithValue("EndDate", warranty.EndDate); cmd.Parameters.AddWithValue("WarrantyType", warranty.WarrantyType); cmd.Parameters.AddWithValue("Notes", warranty.Notes); cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); }
public static string addWarrantysComputer(List<int> ids, Warranty warranty) { StringBuilder message = new StringBuilder(); SqlConnection dbConn; string sConnection; SqlCommand dbCmd; SqlTransaction transaction; sConnection = GlobalVars.ConnectionString; dbConn = new SqlConnection(sConnection); dbConn.Open(); dbCmd = dbConn.CreateCommand(); transaction = dbConn.BeginTransaction("Transaction"); dbCmd.Transaction = transaction; try { for (int i = 0; i < ids.Count; i++) { int invId = ids[i]; string sqlCommand = "INSERT INTO Warranty (InvID, Company, StartDate, EndDate, WarrantyType, Notes) VALUES (@InvID, @Company, @StartDate, @EndDate, @WarrantyType, @Notes)"; dbCmd.CommandText = sqlCommand; dbCmd.Parameters.AddWithValue("InvID", invId); dbCmd.Parameters.AddWithValue("Company", warranty.Company); dbCmd.Parameters.AddWithValue("StartDate", warranty.StartDate); dbCmd.Parameters.AddWithValue("EndDate", warranty.EndDate); dbCmd.Parameters.AddWithValue("WarrantyType", warranty.WarrantyType); dbCmd.Parameters.AddWithValue("Notes", warranty.Notes); dbCmd.ExecuteNonQuery(); dbCmd.Parameters.Clear(); } transaction.Commit(); dbConn.Close(); message.Append("Warranties added successfully!"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); message.Append("Database Error: " + ex.ToString() + "<bR>"); transaction.Rollback(); } return message.ToString(); }
protected void btnAddWarranty_Click(object sender, EventArgs e) { Page.Validate("warranty"); List<int> ids = new List<int>(); ids = getIDs(); Warranty war = new Warranty(); war.Company = ddlWarrantyCompany.SelectedItem.ToString(); war.WarrantyType = txtBoxWarrantyType.Text; war.StartDate = txtBoxWarrantyStartDate.Text; war.EndDate = txtBoxWarrantyEndDate.Text; war.Notes = txtBoxWarrantyNotes.Text; lblWarrantyMessage.Text = Warranty.addWarrantysEquipment(ids, war); lblWarrantyMessage.Visible = true; btnWarrantyMessage_ModalPopupExtender.Show(); }
protected void btnAddWarranty_Click(object sender, EventArgs e) { Page.Validate("warranty"); Warranty war = new Warranty(); war.Company = ddlWarrantyCompany.SelectedItem.ToString(); war.WarrantyType = txtBoxWarrantyType.Text; war.StartDate = txtBoxWarrantyStartDate.Text; war.EndDate = txtBoxWarrantyEndDate.Text; war.Notes = txtBoxWarrantyNotes.Text; lblWarrantyMessage.Text = Warranty.addWarranty(Convert.ToInt32(Session["CurrentEquipment"]), war); lblWarrantyMessage.Visible = true; if (lblWarrantyMessage.Text == "Warranty added successfully!") { panelWarranty.Visible = false; btnAddWarranty.Visible = true; GridView4.Visible = true; GridView4.DataBind(); } }
public static string addWarrantysEquipment(List<int> ids, Warranty warranty) { return WarrantyDA.addWarrantysEquipment(ids, warranty); }
public static string addWarrantysComputer(List<int> ids, Warranty warranty) { return WarrantyDA.addWarrantysComputer(ids, warranty); }
public static string addWarranty(int invID, Warranty warranty) { return WarrantyDA.addWarranty(invID, warranty); }
protected void btnRemoveWarranty_Click(object sender, EventArgs e) { try { List<Warranty> warranties = new List<Warranty>(); warranties = (List<Warranty>)Session["Warranties"]; warranties.RemoveAt(lstBoxWarranties.SelectedIndex); lstBoxWarranties.Items.Clear(); for (int i = 0; i < warranties.Count; i++) { Warranty warranty = new Warranty(); warranty = (Warranty)warranties[i]; lstBoxWarranties.Items.Add(warranty.Company + ": " + warranty.StartDate + "-" + warranty.EndDate); } Session["Warranties"] = warranties; } catch { } }
protected void btnAddWarranty_Click(object sender, EventArgs e) { Page.Validate("warranty"); List<Warranty> warranties = new List<Warranty>(); Warranty war = new Warranty(); war.Company = ddlWarrantyCompany.SelectedItem.ToString(); war.WarrantyType = txtBoxWarrantyType.Text; war.StartDate = txtBoxWarrantyStartDate.Text; war.EndDate = txtBoxWarrantyEndDate.Text; war.Notes = txtBoxWarrantyNotes.Text; if (lstBoxWarranties.Items.Count == 0) { warranties.Clear(); } else { warranties = (List<Warranty>)Session["Warranties"]; } warranties.Add(war); lstBoxWarranties.Items.Clear(); for (int i = 0; i < warranties.Count; i++) { Warranty warranty = new Warranty(); warranty = (Warranty)warranties[i]; lstBoxWarranties.Items.Add(warranty.Company + ": " + warranty.StartDate + "-" + warranty.EndDate); } Session["Warranties"] = warranties; }