コード例 #1
0
        public DateTime?GetSalesDateByDateID(int salesdateid)
        {  // will retrieve sales date from the given business date id.
           // however, it will not be a method available to an instantiated class.
            DateTime?salesdate = null;

            string sql = @"Select Top 1 SalesDate from [Bookkeeping].[SalesDate] where SalesDateID = " + salesdateid + ";";

            DBAccess      fuelDB  = new DBAccess();
            SqlConnection sqlConn = fuelDB.CreateFuelDBConnection();
            SqlCommand    sqlComm = fuelDB.SetFuelDBCommandTypeText(sqlConn, sql);

            try
            {
                sqlConn.Open();
                SqlDataReader sqlReader = sqlComm.ExecuteReader();
                //int counter = 0;
                if (sqlReader.HasRows == true)
                {
                    while (sqlReader.Read())
                    {
                        salesdate = (DateTime)sqlReader["SalesDate"];
                    }
                    sqlReader.Close();
                }
                else
                {
                    return(salesdate);
                }
            }
            catch (SqlException ex)
            {
                //salesdateid = -1; // error exists
                MessageErrorDB = ex.Message;
            }

            catch (Exception ex)
            {
                // error exists
                MessageError = ex.Message;
            }

            finally
            { fuelDB.CloseConnection(ref sqlConn); }
            return(salesdate);
        }
コード例 #2
0
        public ArrayList GetGasSalesByDateId(int salesDateId)
        {
            ArrayList gasRecordsArray = new ArrayList();

            string sqlText = @"Select GasTypeID, GallonsSold, Price, TotalDollarAmount, CostOfGas from Bookkeeping.GasSales where DateID = " + salesDateId + ";";
            //ArrayList gasRecordsArray = new ArrayList();
            DBAccess      sqlGasSales = new DBAccess();
            SqlConnection sqlConn     = sqlGasSales.CreateFuelDBConnection();
            SqlCommand    sqlCommand  = sqlGasSales.SetFuelDBCommandTypeText(sqlConn, sqlText);

            try
            {
                sqlConn.Open();
                SqlDataReader sqlreader      = sqlCommand.ExecuteReader();
                FuelData      gasSalesValues = new FuelData();
                if (sqlreader.HasRows == true)
                {
                    while (sqlreader.Read())
                    {
                        //sqlvalues += sqlreader["GallonsSold"].ToString() + ", ";
                        gasRecordsArray.Add(new FuelData()

                        {
                            FuelType     = (int)sqlreader["GasTypeId"],
                            SoldAmount   = (decimal)sqlreader["GallonsSold"],
                            Price        = (decimal)sqlreader["Price"],
                            DollarAmount = (decimal)sqlreader["TotalDollarAmount"],
                            CostOfGas    = (decimal)sqlreader["CostOfGas"]
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionsMessages = new FuelCenterDB.Exceptions(ex);
            }
            finally { sqlGasSales.CloseConnection(ref sqlConn); }

            return(gasRecordsArray);
        }