Exemplo n.º 1
0
        // get one dataset using one call to db for combobox population
        // this will populate the 'global' variable so that you can access data within the set at any time.
        //


        private bool PopulateGasSalesForm()
        {
            //  PopulateGasSalesForm():
            //  Populating this form should occur on_load, when salesdate has changed,
            bool updateCompleted = true;
            // Retrieves an ArrayList of FuelData objs then will cycle through them to update the text boxes.
            ArrayList  arrGasSales = new ArrayList();
            GasSalesDB getGasSales = new GasSalesDB();

            arrGasSales = getGasSales.GetGasSalesByDateId(SalesDateId);

            if (arrGasSales != null)
            // only update the form if there are any no errors.
            {
                foreach (var fueldataitem in arrGasSales)
                {
                    FuelData fdGasSales = (FuelData)fueldataitem;
                    //lblResults.Text += fdGasSales.ReturnFuelDataClass() + "\n";
                    if (fdGasSales.FuelType == 1)
                    { // udpate the unleaded box
                        txtUnleaded.Text             = fdGasSales.SoldAmount.ToString();
                        txtPriceUnleaded.Text        = String.Format("{0:C3}", fdGasSales.Price);
                        txtTotalDollarsUnleaded.Text = String.Format("{0:C3}", fdGasSales.DollarAmount);
                        txtCostUnleaded.Text         = String.Format("{0:C3}", fdGasSales.CostOfGas);
                    }
                    else if (fdGasSales.FuelType == 3)
                    { // udpate all the plus text boxes
                      //txtPlus.Text = fdGasSales.SoldAmount.ToString();
                        txtPlus.Text             = fdGasSales.SoldAmount.ToString();
                        txtPricePlus.Text        = String.Format("{0:C3}", fdGasSales.Price);
                        txtTotalDollarsPlus.Text = String.Format("{0:C3}", fdGasSales.DollarAmount);
                        txtCostPlus.Text         = String.Format("{0:C3}", fdGasSales.CostOfGas);
                    }
                    else if (fdGasSales.FuelType == 2)
                    {
                        //txtPlus.Text = fdGasSales.SoldAmount.ToString();
                        txtPremium.Text             = fdGasSales.SoldAmount.ToString();
                        txtPricePremium.Text        = String.Format("{0:C3}", fdGasSales.Price);
                        txtTotalDollarsPremium.Text = String.Format("{0:C3}", fdGasSales.DollarAmount);
                        txtCostPremium.Text         = String.Format("{0:C3}", fdGasSales.CostOfGas);
                    }
                }
            }
            else
            {
                DisplayErrorMessage(lblGasSalesErrorMessage, getGasSales.ExceptionsMessages.Message);
            }
            hasDataChanged = false; // delete flag that indicates taht the data has changed.
            return(updateCompleted);
        }
        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);
        }