protected void btnStart_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[1] = (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"] = "repairStarted"; // 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 btnCreate_Click(object sender, EventArgs e) { if (Servicevalidation()) { try { DataRow service = RepairsDataSet.service.NewRow(); // Create a new row of service table in memory //update record with user's input service[1] = this.txtName.Text; service[2] = this.txtDescription.Text; service[3] = this.txtPrice.Text; RepairsDataSet.service.Rows.Add(service); // add the rows to the dataset serviceTableAdapter daService = new serviceTableAdapter(); daService.Update(service); // 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 //Refresh the page to show the record being deleted // Response.Redirect("Services.aspx"); // Redirect the user to dexpage on to show created data this.Label1.Visible = true; this.Label1.Text = "✔ Record Successfully Created"; this.Label1.ForeColor = Color.Green; } catch { this.Label1.Visible = true; this.Label1.Text = "❌ Record Creation Failed"; this.Label1.ForeColor = Color.Red; } } }
//Edit Button click protected void btnCreate_Click(object sender, EventArgs e) { //check a record has been selected if (id != -1 && Servicevalidation()) { DataRow record = repairsDataSet.service.FindByid(id); // find the related Record try { //update record with user's input record[1] = this.txtName.Text; record[2] = this.txtDescription.Text; record[3] = Convert.ToDecimal(this.txtPrice.Text); serviceTableAdapter daservice = new serviceTableAdapter(); daservice.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 this.Label1.Visible = true; Label1.Text = "✔ Record Successfully Updated"; // Response.Redirect("Services.aspx"); // Redirect the user to Edit page on btn click } catch { this.Label1.ForeColor = Color.Red; this.Label1.Visible = true; Label1.Text = "❌ Record Updation Failed"; } } }
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; } } }
protected void btnDeleteConfirm_Click(object sender, EventArgs e) { if (id != -1) { try { DataRow record = RepairsDataSet.service.FindByid(id); // Find and add the record to tbe record variable record.Delete(); // Deletes the record in memory serviceTableAdapter daservice = new serviceTableAdapter(); // table adapter to service table (Service adapter) daservice.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 //Refresh the page to show the record being deleted Session["deleteMsg"] = "true"; this.Label1.Text = "✔ Record Deleted Successfully"; } catch (Exception ex) { if (ex.Message.Contains("constraint")) { Session["deleteMsg"] = "false"; } else { this.Label1.Text = "❌ Record Deletion Failed"; this.Label1.ForeColor = Color.Red; } } finally { Response.Redirect(Request.RawUrl); } } }