/// <summary>
        /// This is the function where we get the medicinestock(Called from MedicineRepo) and
        /// perform some functionalities to fetch the numberoftablets of a particular medicine
        /// and check what should be the supplycount(i.e how many medicines can be supplied to user).
        /// Try and catch blocks are handled accordingly.
        /// </summary>
        /// <param name="demand"></param>
        /// <returns>MedicineSupply or null value depending on the type of demand</returns>
        public MedicineSupply GetSupply(MedicineDemand demand, string token)
        {
            IEnumerable <MedicineStock> medicinestock = _repocontext.GetSupply(token);

            medicinestock = from m in medicinestock where m.Name == demand.MedicineName select m;
            MedicineStock medicine = medicinestock.FirstOrDefault();

            try
            {
                if (medicine != null)
                {
                    int            medicinecount  = ((medicine.numberOfTabletsInStock) / (MedicineSupplyRepo.pharmacies.Count()));
                    MedicineSupply medicinesupply = new MedicineSupply();
                    medicinesupply.MedicineName = medicine.Name;
                    medicinesupply.DemandCount  = demand.DemandCount;
                    medicinesupply.SupplyCount  = medicinecount;
                    return(medicinesupply);
                }
                else
                {
                    _log4net.Error("MedicineName not found in medicinestock " + nameof(MedicineSupplyProvider));
                    return(null);
                }
            }
            catch (Exception e)
            {
                _log4net.Error(e.Message + " from " + nameof(MedicineSupplyProvider));
                throw e;
            }
        }
        public void Save(Treatment aTreatment)
        {
            SqlQuery = "SELECT quantity FROM tbl_medicines_of_centerS WHERE center_id=" + aTreatment.CenterId +
                       " AND medicine_id=" + aTreatment.MedicineId + ";";
            DbSqlConnection = new SqlConnection(ConnectionString);
            DbSqlConnection.Open();
            DbSqlCommand    = new SqlCommand(SqlQuery, DbSqlConnection);
            DbSqlDataReader = DbSqlCommand.ExecuteReader();
            DbSqlDataReader.Read();
            var quantity = (int)DbSqlDataReader["quantity"];

            DbSqlConnection.Close();
            if (quantity >= aTreatment.Quantity)
            {
                SqlQuery = "INSERT INTO tbl_treatments VALUES('" + aTreatment.Observation + "','" + aTreatment.Date +
                           "'," +
                           aTreatment.DoctorId + "," + aTreatment.DiseaseId + "," + aTreatment.MedicineId + ",'" +
                           aTreatment.Dose + "'," + aTreatment.Quantity + ",'" + aTreatment.Note + "','" +
                           aTreatment.DoseRules + "'," + aTreatment.CenterId + "," + aTreatment.ServiceTakenId + ");";
                DbSqlConnection = new SqlConnection(ConnectionString);
                DbSqlConnection.Open();
                DbSqlCommand = new SqlCommand(SqlQuery, DbSqlConnection);
                DbSqlCommand.ExecuteNonQuery();
                DbSqlConnection.Close();
                MedicineStock aMedicineStock = new MedicineStock()
                {
                    CenterId   = aTreatment.CenterId,
                    MedicineId = aTreatment.MedicineId,
                    Quantity   = aTreatment.Quantity
                };
                aMedicineStockGateway.DecreaseMedicineQuantity(aMedicineStock);
            }
        }
コード例 #3
0
 public void DecreaseMedicineQuantity(MedicineStock aMedicineStock)
 {
     SqlQuery = "UPDATE tbl_medicines_of_centers SET quantity -=" + aMedicineStock.Quantity + " WHERE center_id=" +
                aMedicineStock.CenterId + " AND medicine_id=" + aMedicineStock.MedicineId + ";";
     DbSqlConnection = new SqlConnection(ConnectionString);
     DbSqlConnection.Open();
     DbSqlCommand = new SqlCommand(SqlQuery, DbSqlConnection);
     DbSqlCommand.ExecuteNonQuery();
     DbSqlConnection.Close();
 }
コード例 #4
0
 public void SendMedicineToCenter(MedicineStock aMedicineStock)
 {
     SqlQuery = "INSERT INTO tbl_medicines_of_centers VALUES(" + aMedicineStock.CenterId + "," +
                aMedicineStock.MedicineId + "," + aMedicineStock.Quantity + ");";
     DbSqlConnection = new SqlConnection(ConnectionString);
     DbSqlConnection.Open();
     DbSqlCommand = new SqlCommand(SqlQuery, DbSqlConnection);
     DbSqlCommand.ExecuteNonQuery();
     DbSqlConnection.Close();
 }
コード例 #5
0
 public void SendMedicineToCenter(MedicineStock aMedicineStock)
 {
     if (aMedicineStockGateway.Find(aMedicineStock) != null)
     {
         aMedicineStockGateway.IncreaseMedicineQuantity(aMedicineStock);
     }
     else
     {
         aMedicineStockGateway.SendMedicineToCenter(aMedicineStock);
     }
 }
コード例 #6
0
 protected void saveButton_Click(object sender, EventArgs e)
 {
     if (centerDropDownList.Text != string.Empty)
     {
         List <MedicineStock> medicineStocks = new List <MedicineStock>();
         var medicines  = medicineNames.Value.Split(',');
         var quantities = medicineQuantities.Value.Split(',');
         medicineQuantities.Value = "";
         medicineNames.Value      = "";
         for (int i = 0; i < medicines.Length - 1; i++)
         {
             MedicineStock aMedicineStock = new MedicineStock();
             aMedicineStock.CenterId   = Convert.ToInt32(centerDropDownList.SelectedValue);
             aMedicineStock.MedicineId = aMedicineManager.Find(medicines[i]).Id;
             aMedicineStock.Quantity   = Convert.ToInt32(quantities[i]);
             medicineStocks.Add(aMedicineStock);
         }
         aMedicineStockManager.SendMedicineToCenter(medicineStocks);
         messageLabel.Text = "Medicines sent successfully.";
     }
 }
コード例 #7
0
 public MedicineStock Find(MedicineStock aMedicineStock)
 {
     SqlQuery = "SELECT * FROM tbl_medicines_of_centers WHERE center_id=" + aMedicineStock.CenterId +
                " AND medicine_id=" + aMedicineStock.MedicineId + ";";
     DbSqlConnection = new SqlConnection(ConnectionString);
     DbSqlConnection.Open();
     DbSqlCommand    = new SqlCommand(SqlQuery, DbSqlConnection);
     DbSqlDataReader = DbSqlCommand.ExecuteReader();
     if (DbSqlDataReader.HasRows)
     {
         MedicineStock aStock = new MedicineStock();
         while (DbSqlDataReader.Read())
         {
             aStock.Id         = Convert.ToInt32(DbSqlDataReader["id"]);
             aStock.CenterId   = Convert.ToInt32(DbSqlDataReader["center_id"]);
             aStock.MedicineId = Convert.ToInt32(DbSqlDataReader["medicine_id"]);
             aStock.Quantity   = Convert.ToInt32(DbSqlDataReader["quantity"]);
         }
         DbSqlConnection.Close();
         return(aStock);
     }
     DbSqlConnection.Close();
     return(null);
 }