public int SaveTreatment(Treatment aTreatment)
 {
     string query = "INSERT INTO tbl_treatment VALUES ('" + aTreatment.Observation + "','" +aTreatment.ServiceDate+ "','" +
         aTreatment.DoctorId + "','" + aTreatment.DiseaseId + "', '" +aTreatment.MedicineId+ "', '" +
         aTreatment.Dose+ "', '" +aTreatment.Quantity+ "', '" +aTreatment.Note+ "', '" +aTreatment.DoseType+ "', '" +
         aTreatment.CenterId+ "', '" +aTreatment.ServiceTakenId+ "')";
     ASqlConnection.Open();
     ASqlCommand = new SqlCommand(query, ASqlConnection);
     //ASqlCommand.Parameters.Add("@serviceDate", SqlDbType.DateTime).Value = aTreatment.ServiceDate;
     int rowAffected = ASqlCommand.ExecuteNonQuery();
     ASqlConnection.Close();
     return rowAffected;
 }
 public void SaveTreatment(Treatment aTreatment)
 {
     aTreatmentDbGateway.SaveTreatment(aTreatment);
 }
        protected void saveButton_Click(object sender, EventArgs e)
        {
            Patient aPatient = new Patient();

            var diseaseList = diseaseName.Value;
            diseaseName.Value = "";
            string[] disease = diseaseList.Split(',');

            var medicineList = medicineName.Value;
            medicineName.Value = "";
            string[] medicine = medicineList.Split(',');

            var doseList = medicineDose.Value;
            medicineDose.Value = "";
            string[] dose = doseList.Split(',');

            var doseRuleList = medicineDoseType.Value;
            medicineDoseType.Value = "";
            string[] doseRule = doseRuleList.Split(',');

            var quantityList = medicineQuantityGiven.Value;
            medicineQuantityGiven.Value = "";
            string[] quantity = quantityList.Split(',');

            var noteList = notes.Value;
            notes.Value = "";
            string[] note = noteList.Split(',');

            string[] address = addressTextBox.Text.Split(' ');
            string districtName = address[address.Length - 1];

            aPatient.VoterId = Convert.ToInt64(voterIdTextBox.Text);
            aPatient.DistrictId = aDistrictAndThanaManager.FindDistrict(districtName).Id;

            aPatientManager.SaveService(aPatient);

            Treatment aTreatment = new Treatment();

            aTreatment.ServiceTakenId = aPatientManager.GetServiceTakenId();
            aTreatment.Observation = observationTextBox.Text;
            aTreatment.ServiceDate = DateTime.Parse(dateTextBox.Value);
            aTreatment.DoctorId = Convert.ToInt32(doctorDropDownList.SelectedValue);
            aTreatment.CenterId = Convert.ToInt32(Session["CenterId"]);

            for (int i = 0; i < disease.Length - 1; i++)
            {
                Disease aDisease = aDiseaseManager.Find(disease[i]);
                aTreatment.DiseaseId = aDisease.Id;
                Medicine aMedicine = aMedicineManager.Find(medicine[i]);
                aTreatment.MedicineId = aMedicine.Id;
                aTreatment.Dose = dose[i];
                aTreatment.DoseType = doseRule[i];
                aTreatment.Quantity = Convert.ToInt32(quantity[i]);
                aTreatment.Note = note[i];
                aTreatmentManager.SaveTreatment(aTreatment);

                MedicineStockInCenter aMedicineStockInCenter = new MedicineStockInCenter();
                aMedicineStockInCenter.MedicineId = aTreatment.MedicineId;
                aMedicineStockInCenter.Quantity = aTreatment.Quantity;
                aMedicineStockInCenter.CenterId = aTreatment.CenterId;

                aMedicineManager.DeductMedicineFromCenter(aMedicineStockInCenter);
            }
        }