public int SaveMedicine(Medicine aMedicine)
 {
     if (medicineGateway.IsThisMedicineExists(aMedicine.Name))
     {
         return 0;
     }
     else
     {
         if (medicineGateway.SaveMedicine(aMedicine))
         {
             return 1;
         }
         else
         {
             return -1;
         }
     }
 }
        public List<Medicine> GetMedicine()
        {
            string searchMedicine = "SELECT * FROM tbl_medicine";
            sqlConnection.Open();
            sqlCommand.CommandText = searchMedicine;
            SqlDataReader reader = sqlCommand.ExecuteReader();
            List<Medicine> medicineList = new List<Medicine>();
            while (reader.Read())
            {
                Medicine medicine = new Medicine();
                medicine.Id = Convert.ToInt32(reader["id"].ToString());
                medicine.Name = reader["MedicineName"].ToString();
                medicineList.Add(medicine);

            }
            reader.Close();
            sqlConnection.Close();
            return medicineList;
        }
        public List<Medicine> Getreport(int centerId)
        {
            sqlConnection.Open();
            string query = "select tbl_medicine.MedicineName, tbl_send_medicine.Quentity from tbl_send_medicine join tbl_medicine on tbl_medicine.id = tbl_send_medicine.MedicineId where CenterId='" + centerId + "' ORDER BY MedicineName ASC ";
            sqlCommand.CommandText = query;
            SqlDataReader reader = sqlCommand.ExecuteReader();
            List<Medicine> medicineReportList = new List<Medicine>();
            while (reader.Read())
            {
                Medicine aMedicine = new Medicine();
                aMedicine.Name = reader["MedicineName"].ToString();
                aMedicine.Quantity = Convert.ToInt32(reader["Quentity"].ToString());

                medicineReportList.Add(aMedicine);
            }
            reader.Close();
            sqlConnection.Close();

            return medicineReportList;
        }
        public List<Medicine> GetAllMedicineInfobyCenterId(object centerId)
        {
            string query = "Select tbl_medicine.MedicineName, tbl_medicine.id from tbl_medicine join tbl_send_medicine ON tbl_medicine.id=tbl_send_medicine.MedicineId Where tbl_send_medicine.CenterId='"+centerId+"' Order By MedicineName ASC";
            sqlConnection.Open();
            sqlCommand.CommandText = query;
            sqlCommand = new SqlCommand(query, sqlConnection);
            SqlDataReader reader = sqlCommand.ExecuteReader();
            List<Medicine> medicineList = new List<Medicine>();

            while (reader.Read())
            {
                Medicine aMedicine = new Medicine();
                aMedicine.Id = (int) reader["id"];
                aMedicine.Name = reader["MedicineName"].ToString();

                medicineList.Add(aMedicine);
            }
            reader.Close();
            sqlConnection.Close();
               return medicineList;
        }
 protected void submitButton_Click(object sender, EventArgs e)
 {
     Medicine aMedicine = new Medicine();
     aMedicine.Name = medicineNameTextBox.Text;
     int message = medicineManager.SaveMedicine(aMedicine);
     if (message>0)
     {
         messageLabel.Text = "Successfully Saved";
         messageLabel.ForeColor= Color.Green;
         LoadAllMedicine();
     }
     else if (message==0)
     {
         messageLabel.Text = "This medicine name alresdy saved";
         messageLabel.ForeColor = Color.Red;
     }
     else
     {
         messageLabel.Text = "Saved Failed";
         messageLabel.ForeColor = Color.Red;
     }
 }
 public bool SaveMedicine(Medicine aMedicine)
 {
     string saveMedicine = "INSERT INTO tbl_medicine (MedicineName) VALUES(@name)";
     sqlConnection.Open();
     sqlCommand.CommandText = saveMedicine;
     sqlCommand.Parameters.AddWithValue("@name", aMedicine.Name);
     int rowAffected = sqlCommand.ExecuteNonQuery();
     sqlConnection.Close();
     if (rowAffected > 0)
     {
         return true;
     }
     return false;
 }