//save change to database private bool Save() { equipmentModifyTableAdapter equipmentModifyTableAdapter = new equipmentModifyTableAdapter(); order_lineTableAdapter order_LineTableAdapter = new order_lineTableAdapter(); service_orderTableAdapter service_OrderTableAdapter = new service_orderTableAdapter(); receiptModifyTableAdapter receiptModifyTableAdapter = new receiptModifyTableAdapter(); customerModifyTableAdapter customerModifyTableAdapter = new customerModifyTableAdapter(); try { order_LineTableAdapter.Update(dsSales.order_line); service_OrderTableAdapter.Update(dsSales.service_order); receiptModifyTableAdapter.Update(dsSales.receiptModify); equipmentModifyTableAdapter.Update(dsSales.equipmentModify); customerModifyTableAdapter.Update(dsSales.customerModify); dsSales.AcceptChanges(); dsSales.customerModify.Clear(); dsSales.receiptModify.Clear(); dsSales.order_line.Clear(); dsSales.service_order.Clear(); dsSales.equipmentModify.Clear(); customerModifyTableAdapter.Fill(dsSales.customerModify); receiptModifyTableAdapter.Fill(dsSales.receiptModify); order_LineTableAdapter.Fill(dsSales.order_line); service_OrderTableAdapter.Fill(dsSales.service_order); equipmentModifyTableAdapter.Fill(dsSales.equipmentModify); return(true); } catch { dsSales.RejectChanges(); return(false); } }
protected void btnStop_Click(object sender, EventArgs e) { if (id != -1) { try { service_orderTableAdapter daService_order = new service_orderTableAdapter(); daService_order.Fill(repairsDataSet.service_order); DataRow record = repairsDataSet.service_order.FindByid(id); // find the related Record //update the record with user's input record[2] = (DateTime.Now).ToString(); service_orderTableAdapter daServiceOrder = new service_orderTableAdapter(); daServiceOrder.Update(record); // Call update method on the service adapter so it updates the table in memory ( All changes made are applied - CRUD) repairsDataSet.AcceptChanges(); // Call accept method on the dataset so it update the chanmges to the database //Send Id to details view HttpCookie cID = new HttpCookie("ID"); // Cokkie variable named cID to hold a value cID.Value = id.ToString(); Response.Cookies.Add(cID); Session["editRedirect"] = "repairStoped"; // session for details view to see if its a redirect or not Response.Redirect("details.aspx"); // Redirect the user to Edit page on btn click } catch { this.Label1.Visible = true; this.Label1.Text = "❌ Record Updation Failed"; this.Label1.ForeColor = Color.Red; } } }
protected void btnDeleteConfirm_Click(object sender, EventArgs e) { if (deleteId != -1) { try { DataRow record = repairsDataSet.service_order.FindByid(deleteId); // Find the requested record record.Delete(); // Deletes the record in memory service_orderTableAdapter daServiceOrder = new service_orderTableAdapter(); // table adapter to Repair table (Repair adapter) daServiceOrder.Update(record); // Call update method on the Repair adapter so it updates the table in memory ( All changes made are applied - CRUD) repairsDataSet.AcceptChanges(); // Call accept method on the dataset so it update the chanmges to the database redirectMsg.Text = "✔ Record deleted"; //Refresh the page to show the record being deleted Session["deleteMsg"] = "true"; } catch { Session["deleteMsg"] = "false"; redirectMsg.Text = "❌ Record not deleted"; this.redirectMsg.ForeColor = Color.Red; } finally { Response.Redirect("default.aspx"); } } }
protected void btnCreate_Click(object sender, EventArgs e) { if (Repairvalidation()) { try { DataRow serviceOrder = RepairsDataSet.service_order.NewRow(); // Create a new row of service_order table in memory //update record with user's input serviceOrder[3] = this.txtIssue.Text; if (this.radInWarranty.Checked) { serviceOrder[4] = 1; } else { serviceOrder[4] = 0; } serviceOrder[5] = this.ddlReceipt.SelectedValue; serviceOrder[6] = this.ddlService.SelectedValue; serviceOrder[7] = this.ddlEquipment.SelectedValue; serviceOrder[8] = this.ddlEmployee.SelectedValue; RepairsDataSet.service_order.Rows.Add(serviceOrder); // add the rows to the dataset service_orderTableAdapter daSericeOrder = new service_orderTableAdapter(); daSericeOrder.Update(serviceOrder); // Call update method on the service adapter so it updates the table in memory ( All changes made are applied - CRUD) RepairsDataSet.AcceptChanges(); // Call accept method on the dataset so it update the chanmges to the database //Send Id to details view to show added record HttpCookie cID = new HttpCookie("ID"); // Cokkie variable named cID to hold a value cID.Value = serviceOrder[0].ToString(); // get the id of the newly added row/record Response.Cookies.Add(cID); Session["createRedirect"] = true; // session for details view to see if its a redirect or not Response.Redirect("details.aspx"); } catch { this.lblStatus.Visible = true; this.lblStatus.Text = "❌ Record Creation Failed"; } } }
//Edit btn protected void btnCreate_Click(object sender, EventArgs e) { //check a record has been selected if (id != -1 && Repairvalidation()) { try { DataRow record = repairsDataSet.service_order.FindByid(id); // find the related Record //update the record with user's input record[3] = this.txtIssue.Text; if (this.radInWarranty.Checked) { record[4] = 1; } else { record[4] = 0; } record[5] = this.ddlReceipt.SelectedValue; record[6] = this.ddlService.SelectedValue; record[7] = this.ddlEquipment.SelectedValue; record[8] = this.ddlEmployee.SelectedValue; service_orderTableAdapter daServiceOrder = new service_orderTableAdapter(); daServiceOrder.Update(record); // Call update method on the service adapter so it updates the table in memory ( All changes made are applied - CRUD) repairsDataSet.AcceptChanges(); // Call accept method on the dataset so it update the chanmges to the database //Send Id to details view HttpCookie cID = new HttpCookie("ID"); // Cokkie variable named cID to hold a value cID.Value = id.ToString(); Response.Cookies.Add(cID); Session["editRedirect"] = "true"; // session for details view to see if its a redirect or not Response.Redirect("details.aspx"); // Redirect the user to Edit page on btn click } catch { this.Label1.Visible = true; this.Label1.Text = "❌ Record Updation Failed"; this.Label1.ForeColor = Color.Red; } } }