public List<Medicine> GetAllMedicines() { int count = 0; List<Medicine> medicineList=new List<Medicine>(); string query = "SELECT * FROM MedicineTBL "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Medicine aMedicine=new Medicine(); aMedicine.Id = int.Parse(reader["Id"].ToString()); aMedicine.NameOfMedicine = reader["NameOfMedicine"].ToString(); count++; aMedicine.SerialNo = count; medicineList.Add(aMedicine); } reader.Close(); connection.Close(); return medicineList; }
protected void addButton_Click(object sender, EventArgs e) { Medicine aMedicine=new Medicine(); aMedicine.NameOfMedicine = selectMedicineDropDownList.SelectedItem.ToString(); aMedicine.Quantity = int.Parse(sendMedicineQuantityTextBox.Text); MedicineList.Add(aMedicine); sendMedicineGridView.DataSource = MedicineList; sendMedicineGridView.DataBind(); }
public string SaveMedicine(Medicine aMedicine) { int value = medicineGateway.SaveMedicine(aMedicine); if (value > 0) { return "Medicine has been saved!"; } else return "Failed"; }
protected void saveButton_Click(object sender, EventArgs e) { Medicine aMedicine=new Medicine(); aMedicine.NameOfMedicine = medicineEntryTextBox.Text; if (medicineManager.IsMedinineExists(aMedicine)) { msgLabel.Text = "This Medicine is already exists!"; } else { msgLabel.Text = medicineManager.SaveMedicine(aMedicine); medicineEntryGridView.DataSource = medicineManager.GetAllMedicines(); medicineEntryGridView.DataBind(); } }
public Medicine GetCenterAllMedicines(int medicineId) { Medicine aMedicine = new Medicine(); string query = "SELECT * FROM MedicineTBL WHERE Id='" + medicineId + "'"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { aMedicine.Id = int.Parse(reader["Id"].ToString()); aMedicine.NameOfMedicine = reader["NameOfMedicine"].ToString(); } reader.Close(); connection.Close(); return aMedicine; }
public List<Medicine> GetCenterAllMedicineList(int centerId) { List<Medicine> medicineList = new List<Medicine>(); string query = "SELECT * FROM CenterMedicineRelationTBL WHERE CenterId='" + centerId + "'"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { int medicineId = int.Parse(reader["MedicineId"].ToString()); Medicine aMedicine = new Medicine(); aMedicine = medicineManager.GetCenterAllMedicines(medicineId); aMedicine.Quantity=int.Parse(reader["Quantity"].ToString()); medicineList.Add(aMedicine); } reader.Close(); connection.Close(); return medicineList; }
public int SaveMedicine(Medicine aMedicine) { string query = "INSERT INTO MedicineTBL VALUES('" + aMedicine.NameOfMedicine + "')"; SqlConnection connection=new SqlConnection(connectionString); SqlCommand command=new SqlCommand(query,connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return rowAffected; }
public bool IsMedinineExists(Medicine aMedicine) { bool exists = false; string query = "SELECT * FROM MedicineTBL WHERE NameOfMedicine='" + aMedicine.NameOfMedicine + "'"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { exists = true; } reader.Close(); connection.Close(); return exists; }
public bool IsMedinineExists(Medicine aMedicine) { return medicineGateway.IsMedinineExists(aMedicine); }