//Submit Add Form
        protected void AddPrescriptionDetailButton_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            String btnId = btn.ID;

            if (btnId.Equals("AddPrescriptionDetailButton"))
            {
                if (IsValid)
                {
                    System.Threading.Thread.Sleep(3000);
                    var presId = long.Parse(PresIdDropDown.SelectedItem.Text);
                    var drug = GetDrugID(DrugTextBox.Text)[0];
                    //Rememeber
                    var quantity = Convert.ToInt32(QuantityTextBox.Text);
                    var dose = Convert.ToInt32(DPDTextBox.Text);
                    var instruction = InstructionTextBox.Text;

                    var prescriptionDetail = new PrescriptionDetail() { prescriptionId = presId, drugId = drug, quantity = quantity, dosePerDay = dose, specialInstruction = instruction };
                    _dataContext.PrescriptionDetails.InsertOnSubmit(prescriptionDetail);
                    _dataContext.SubmitChanges();
                    PrescriptionDetailList.DataBind();

                    //Use for testing
                    //Debug.WriteLine("presID: " + presId);
                    //Debug.WriteLine("presID: " + drug);
                    //Debug.WriteLine("presID: " + quantity);
                    //Debug.WriteLine("presID: " + dose);
                    //Debug.WriteLine("presID: " + instruction);

                    ResetInputField();
                }
            }
            else if (btnId.Equals("ResetPrescriptionDetailButton"))
            {
                ResetInputField();
            }
        }
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                System.Threading.Thread.Sleep(3000);
                var editedRowIndex = PrescriptionDetailList.EditIndex;
                var lblId = PrescriptionDetailList.Rows[editedRowIndex].FindControl("EditId") as Label;
                var txtbPID = PrescriptionDetailList.Rows[editedRowIndex].FindControl("EditPID") as TextBox;
                var txtbDName = PrescriptionDetailList.Rows[editedRowIndex].FindControl("EditDName") as TextBox;
                var txtbQuantity = PrescriptionDetailList.Rows[editedRowIndex].FindControl("EditQuantity") as TextBox;
                var txtbDPD = PrescriptionDetailList.Rows[editedRowIndex].FindControl("EditDPD") as TextBox;
                var txtDescription = PrescriptionDetailList.Rows[editedRowIndex].FindControl("EditInstruction") as TextBox;

                var id = long.Parse(lblId.Text);
                var pid = long.Parse(txtbPID.Text);
                var drug = GetDrugID(txtbDName.Text)[0];
                var quantity = Convert.ToInt32(txtbQuantity.Text);
                var dpd = Convert.ToInt32(txtbDPD.Text);
                var instruction = txtDescription.Text;

                var prescriptionDetails = new PrescriptionDetail() {prescriptionDetailId = id, prescriptionId = pid, drugId = drug, quantity = quantity, dosePerDay = dpd, specialInstruction = instruction };
                _dataContext.PrescriptionDetails.Attach(prescriptionDetails);
                _dataContext.Refresh(RefreshMode.KeepCurrentValues, prescriptionDetails);
                _dataContext.SubmitChanges();
                PrescriptionDetailList.EditIndex = -1;

                //Use For Debug passed value
                //Debug.WriteLine("id: " + id);
                //Debug.WriteLine("DName: " + doctorId);
                //Debug.WriteLine("Date: " + date);
            }
        }
 partial void DeletePrescriptionDetail(PrescriptionDetail instance);
 partial void UpdatePrescriptionDetail(PrescriptionDetail instance);
 partial void InsertPrescriptionDetail(PrescriptionDetail instance);
		private void detach_PrescriptionDetails(PrescriptionDetail entity)
		{
			this.SendPropertyChanging();
			entity.Prescription = null;
		}
		private void attach_PrescriptionDetails(PrescriptionDetail entity)
		{
			this.SendPropertyChanging();
			entity.Drug = this;
		}