Exemple #1
0
        /// <summary>
        /// Calls the method which gets the dieselprice from the DB
        /// </summary>
        /// <returns></returns>
        public ClassDieselPrice GetDieselPriceFromDB()
        {
            ClassDieselPrice res = new ClassDieselPrice();

            res = classLuxYachtDieselDB.GetOilPriceFromDB();
            return(res);
        }
Exemple #2
0
        /// <summary>
        /// This method inserts our dieselprice to the DB
        /// </summary>
        /// <param name="inDiesel"></param>
        public void SaveOilPriceToDB(ClassDieselPrice inDiesel)
        {
            SqlCommand command = new SqlCommand();             //

            command.Connection  = con;                         // Tell which db to connect to, con is declared in ClassDbCon
            command.CommandType = CommandType.StoredProcedure; // Declare which type of command we want to run
            command.CommandText = "spDieselPrice_Insert";      // Name of our stored procedure

            // Our parameters for
            command.Parameters.Add("@price", SqlDbType.Decimal).Value = inDiesel.price;
            command.Parameters.Add("@date", SqlDbType.DateTime).Value = inDiesel.date;


            MakeCallToStoredProcedure(command); // Call method with our command as paramter. Is returned as a datatable
        }
Exemple #3
0
        /// <summary>
        /// This method gets the oilprice from the DB
        /// </summary>
        /// <returns>ClassDieselPrice</returns>
        public ClassDieselPrice GetOilPriceFromDB()
        {
            ClassDieselPrice priceRes = new ClassDieselPrice();
            SqlCommand       command  = new SqlCommand();

            command.Connection  = con;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "spDieselPrice_GetCurrent";
            command.Parameters.Add("@dateNow", SqlDbType.DateTime).Value = DateTime.Now;
            DataTable dtRes = MakeCallToStoredProcedure(command);

            foreach (DataRow row in dtRes.Rows)
            {
                priceRes.Id    = Convert.ToInt32(row["Id"]);
                priceRes.date  = Convert.ToDateTime(row["date"]);
                priceRes.price = Convert.ToDouble(row["price"]);
            }

            return(priceRes);
        }
Exemple #4
0
        /// <summary>
        /// This method gets data from the DB by calling a stored procedure.
        /// It calls the method MakeCallToStoredProcedure and sends command as a parametre.
        /// Command contains con(our connection string), the command type and the name of the stored procedure.
        /// As this method needs to get everthing from the table in the DB, we get several sets of data,
        /// hence we put the result of the call in a List.
        /// </summary>
        /// <returns>List<ClassDieselPrice></returns>
        public List <ClassDieselPrice> GetAllOilPriceFromDB()
        {
            List <ClassDieselPrice> listDieselPriceRes = new List <ClassDieselPrice>();
            SqlCommand command = new SqlCommand();

            command.Connection  = con;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "spDieselPrice_GetAll";
            DataTable dataTable = MakeCallToStoredProcedure(command);

            foreach (DataRow row in dataTable.Rows)
            {
                ClassDieselPrice dieselPrice = new ClassDieselPrice(); // Initialize a new empty instance of ClassPerson

                // Insert the values from the current row into each ones respective instance of ClassPerson
                dieselPrice.Id    = Convert.ToInt32(row["Id"]);
                dieselPrice.date  = Convert.ToDateTime(row["date"].ToString());
                dieselPrice.price = Convert.ToDouble(row["price"].ToString());

                listDieselPriceRes.Add(dieselPrice); // Instance of ClassPerson is inserted into listPersonRes which is of the datatype List<ClassPerson>
            }
            return(listDieselPriceRes);
        }
Exemple #5
0
 /// <summary>
 /// This method handles the user regretting creating a new price for the diesel
 /// </summary>
 public void RegretNewDieselPriceForDB()
 {
     dieselPrice = new ClassDieselPrice();
 }