//Submit Add Form protected void AddPrescriptionGroupButton_Click(object sender, EventArgs e) { Button btn = (Button)sender; String btnId = btn.ID; if (btnId.Equals("AddPrescriptionButton")) { if (IsValid) { System.Threading.Thread.Sleep(3000); var doctorName = NameTextBox.Text; var doctorId = GetGroupId(doctorName)[0]; var dateVisited = Convert.ToDateTime(VisitedDateTextBox.Text); var prescription = new Prescription() { doctorId = doctorId, dateWritten = dateVisited }; _dataContext.Prescriptions.InsertOnSubmit(prescription); _dataContext.SubmitChanges(); PrescriptionList.DataBind(); //USe for Testing //Debug.WriteLine("Doctor Name: " + doctorId); //Debug.WriteLine("Date Visisted: " + dateVisited); ResetInputField(); } } else if (btnId.Equals("ResetPrescriptionGroupButton")) { ResetInputField(); } }
public Boolean addNewPrescription(string drugName, DateTime dateWritten, DateTime dateProcessed, DateTime dateDispensed, DateTime dateExpires, string instruction, int quantityWritten, int quantityDispensed, string drugCategory, string clientID) { try { int maxId = 0; int maxUserID = 0; int maxGpID = 0; foreach (Prescription prescription in PrescriptionList) { if (prescription.PrescriptionID > maxId) { maxId = prescription.PrescriptionID; } if (prescription.UserID > maxUserID) { maxUserID = prescription.UserID; } if (prescription.GpID > maxGpID) { maxGpID = prescription.GpID; } } IPrescription thePrescription = PrescriptionFactory.GetPrescription(maxId + 1, drugName, dateWritten, dateProcessed, dateDispensed, dateExpires, instruction, quantityDispensed, quantityWritten, drugCategory, maxUserID + 1, clientID, maxGpID + 1); // Using a Factory to create the user entity object. ie seperating object creation from business logic PrescriptionList.Add(thePrescription); // Add a reference to the newly created object to the Models UserList DataLayer.addNewPrescriptionToDB(thePrescription); //Gets the DataLayer to add the new user to the DB. return(true); } catch (System.Exception excep) { return(false); } }