public void LoadDataToUpdate(UpdatePrescriptionPage loadData) { try { DatabaseConnection DB = new DatabaseConnection(); DB.openConnection(); vPrescriptionId = loadData.txPrescriptionId.Text; string sqlSelectCmd = "SELECT * FROM Prescriptions WHERE prescriptionId = '" + vPrescriptionId + "'"; SqlCommand cmd = new SqlCommand(sqlSelectCmd, DatabaseConnection.dbConnection); SqlDataReader read = cmd.ExecuteReader(); read.Read(); loadData.ddCustomer.SelectedValue = read[1].ToString(); loadData.ddPhysician.SelectedValue = read[2].ToString(); loadData.ddPrescriptionStatus.SelectedValue = read[3].ToString(); loadData.ddPaymentMethod.SelectedValue = read[4].ToString(); loadData.txPrescriptionDate.Text = read[5].ToString(); read.Close(); DB.closeConnection(); } catch (Exception ex) { MessageBox.Show("Error" + ex); } }
public void UpdatePrescription(UpdatePrescriptionPage updatePrescription) { try { DatabaseConnection DB = new DatabaseConnection(); DB.openConnection(); vPrescriptionId = updatePrescription.txPrescriptionId.Text; vCustomerId = updatePrescription.ddCustomer.SelectedValue; vPhysicianId = updatePrescription.ddPhysician.SelectedValue; vStatusCode = updatePrescription.ddPrescriptionStatus.SelectedValue; vPaymentMethodCode = updatePrescription.ddPaymentMethod.SelectedValue; vIssuedDate = updatePrescription.txPrescriptionDate.Text; string sqlUpdateCmd = "UPDATE Prescriptions SET customerId = '" + vCustomerId + "', physicianId = '" + vPhysicianId + "', statusCode = '" + vStatusCode + "', paymentMethodCode = '" + vPaymentMethodCode + "', issuedDate = '" + vIssuedDate + "' WHERE prescriptionId = '" + vPrescriptionId + "'"; SqlCommand cmd = new SqlCommand(sqlUpdateCmd, DatabaseConnection.dbConnection); cmd.ExecuteNonQuery(); string sqlDeleteCmnd = "DELETE FROM PrescriptionItems WHERE prescriptionId = '" + vPrescriptionId + "'"; SqlCommand cmnd = new SqlCommand(sqlDeleteCmnd, DatabaseConnection.dbConnection); cmnd.ExecuteNonQuery(); foreach (GridViewRow row in updatePrescription.GridViewDrugItems.Rows) { vDrugId = row.Cells[1].Text; vQuantity = Convert.ToInt32(row.Cells[3].Text); vInstructions = row.Cells[4].Text; string sqlInsertCom = "INSERT INTO PrescriptionItems VALUES('" + vPrescriptionId + "', '" + vDrugId + "', '" + vQuantity + "', '" + vInstructions + "')"; SqlCommand com = new SqlCommand(sqlInsertCom, DatabaseConnection.dbConnection); com.ExecuteNonQuery(); } DB.closeConnection(); ScriptManager.RegisterClientScriptBlock(updatePrescription, this.GetType(), "SweetAlert", "swal('Success!', 'Prescription updated sucessfully', 'success').then(function(){window.location='PrescriptionsPage.aspx';})", true); } catch (Exception ex) { MessageBox.Show("Error" + ex); } }