protected void GetHerbName(string herbRefNum) { string message; string constr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { SqlCommand command = new SqlCommand("spGetHerbName", con); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@herbRefNum", herbRefNum); con.Open(); SqlDataReader rdr = command.ExecuteReader(); try { while (rdr.Read()) { herb = new HerbInStock(); herb.HerbName = (rdr["HerbName"].ToString()); } } catch (Exception ex) { message = "Error! " + ex; divAlertWarning.Visible = true; divAlertWarning.Focus(); lblAlertWarning.Text = message; message = ""; } finally { con.Close(); } } }
protected void CheckBatch(string herbRefNum, decimal totalHerbQuantity) { List <int> herbsInStockIDs = new List <int>(); List <decimal> herbInStockQuantity = new List <decimal>(); List <string> herbInStockBatchNum = new List <string>(); List <decimal> Ratio = new List <decimal>(); //List<DateTime> ExpiryDate = new List<DateTime>(); //HerbStock hs; //List<HerbStock> hsList = new List<HerbStock>(); string message; string constr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { SqlCommand command = new SqlCommand("spAllStocksIDOfHerb", con); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@herbRefNum", herbRefNum); con.Open(); SqlDataReader rdr = command.ExecuteReader(); try { while (rdr.Read()) { //hs = new HerbStock(); //hs.HerbStockID = Convert.ToInt32(rdr["HerbStockID"].ToString()); //hs.Quantity = Convert.ToDecimal(rdr["Quantity"].ToString()); //hs.BatchNum = rdr["BatchNum"].ToString(); //hs.HerbRawToGranRatio = Convert.ToInt32(rdr["HerbRawToGranRatio"].ToString()); //hs.ExpiryDate = Convert.ToDateTime(rdr["ExpiryDate"]); //hsList.Add(hs); herbsInStockIDs.Add(Convert.ToInt32(rdr["HerbStockID"].ToString())); herbInStockQuantity.Add(Convert.ToDecimal(rdr["Quantity"].ToString())); herbInStockBatchNum.Add(rdr["BatchNum"].ToString()); Ratio.Add(Convert.ToDecimal(rdr["HerbRawToGranRatio"].ToString())); //ExpiryDate.Add(Convert.ToDateTime(rdr["ExpiryDate"])); } } catch (Exception ex) { message = "Error! " + ex; divAlertError.Visible = true; lblError.Text = message; message = ""; } finally { con.Close(); } } HerbInStock resultHerbInStock; for (int i = 0; i < herbsInStockIDs.Count; i++) { if (herbInStockQuantity[i] >= totalHerbQuantity) { resultHerbInStock = new HerbInStock(); resultHerbInStock.HerbStockID = herbsInStockIDs[i]; resultHerbInStock.BatchNum = herbInStockBatchNum[i]; resultHerbInStock.Quantity = totalHerbQuantity; resultHerbInStock.HerbRawQty = (totalHerbQuantity * Ratio[i]) / numOfDosageDays; listHerbInSock.Add(resultHerbInStock); break; } else { resultHerbInStock = new HerbInStock(); resultHerbInStock.HerbStockID = herbsInStockIDs[i]; resultHerbInStock.BatchNum = herbInStockBatchNum[i]; resultHerbInStock.Quantity = herbInStockQuantity[i]; resultHerbInStock.HerbRawQty = (herbInStockQuantity[i] * Ratio[i]) / numOfDosageDays; if (herbInStockQuantity[i] > 0) { listHerbInSock.Add(resultHerbInStock); totalHerbQuantity -= herbInStockQuantity[i]; } } } }
protected void CheckBatch(string herbRefNum, decimal totalHerbQuantity, decimal herbProcentage, int bQuantity) { List <int> herbsInStockIDs = new List <int>(); List <decimal> herbInStockQuantity = new List <decimal>(); List <string> herbInStockBatchNum = new List <string>(); string message; string constr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { SqlCommand command = new SqlCommand("spAllStocksIDOfHerb", con); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@herbRefNum", herbRefNum); con.Open(); SqlDataReader rdr = command.ExecuteReader(); try { while (rdr.Read()) { herbsInStockIDs.Add(Convert.ToInt32(rdr["HerbStockID"].ToString())); herbInStockQuantity.Add(Convert.ToDecimal(rdr["Quantity"].ToString())); herbInStockBatchNum.Add(rdr["BatchNum"].ToString()); } } catch (Exception ex) { message = "Error! " + ex; divAlertWarning.Visible = true; lblAlertWarning.Text = message; message = ""; } finally { con.Close(); } } decimal totalHerbQtyNeeded = totalHerbQuantity * bQuantity; HerbInStock resultHerbInStock; for (int i = 0; i < herbsInStockIDs.Count; i++) { if (herbInStockQuantity[i] >= totalHerbQtyNeeded) { resultHerbInStock = new HerbInStock(); resultHerbInStock.HerbStockID = herbsInStockIDs[i]; resultHerbInStock.BatchNum = herbInStockBatchNum[i]; resultHerbInStock.Quantity = totalHerbQtyNeeded; resultHerbInStock.HerbRefNum = herbRefNum; resultHerbInStock.HerbProcentage = herbProcentage; listHerbInSock.Add(resultHerbInStock); break; } else { resultHerbInStock = new HerbInStock(); resultHerbInStock.HerbStockID = herbsInStockIDs[i]; resultHerbInStock.BatchNum = herbInStockBatchNum[i]; resultHerbInStock.Quantity = herbInStockQuantity[i]; resultHerbInStock.HerbRefNum = herbRefNum; resultHerbInStock.HerbProcentage = herbProcentage; if (resultHerbInStock.Quantity > 0) { listHerbInSock.Add(resultHerbInStock); totalHerbQtyNeeded -= herbInStockQuantity[i]; } } } }