Exemplo n.º 1
0
        protected void gvDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddNew"))
            {

                TextBox txtOdometer = (TextBox)gvDetails.FooterRow.FindControl("txtFtrOdometer");
                if (_fuel.Count > 0)
                {
                    var lastitem = _fuel.Last();
                    if (Convert.ToDouble(txtOdometer.Text) < lastitem.Value)
                    {
                        lblresult.Text = "Please Enter the Odometer reading greater than the first value.";
                        txtOdometer.Text = "";
                        lblresult.ForeColor = Color.Red;
                        return;
                    }
                }

                TextBox txtGallons = (TextBox)gvDetails.FooterRow.FindControl("txtFtrGallons");
                TextBox txtPricePerGallon = (TextBox)gvDetails.FooterRow.FindControl("txtFtrPricePerGallon");
                //TextBox txtCost = (TextBox)gvDetails.FooterRow.FindControl("txtFtrCost");
                var txtCost = Convert.ToDouble((txtGallons.Text))*Convert.ToDouble((txtPricePerGallon.Text));
                TextBox txtFillDate = (TextBox)gvDetails.FooterRow.FindControl("txtFtrFillDate");
                //TextBox txtAvgMilesPerGallon = (TextBox)gvDetails.FooterRow.FindControl("txtFtrAvgMilesPerGallon");
                var txtAvgMilesPerGallon = 0.0;
                var count = _fuel.Count;
                if (_fuel.Count == 0)
                {
                     txtAvgMilesPerGallon = 0.0;
                }
                else
                {
                    var lastfuelitem = _fuel.Last();
                    txtAvgMilesPerGallon = (Convert.ToDouble(txtOdometer.Text) - (lastfuelitem.Value)) / Convert.ToDouble(txtGallons.Text);
                }

                Fuel userFuel = new Fuel();

                userFuel.UserId = _userObj.UserId;
                userFuel.Odometer = Convert.ToDouble(txtOdometer.Text);
                userFuel.Gallons = Convert.ToDouble(txtGallons.Text);
                userFuel.PricePerGallon = Convert.ToDouble(txtPricePerGallon.Text);
                userFuel.TotalCost = Convert.ToDouble(txtCost);
                userFuel.FillDate = Convert.ToDateTime(txtFillDate.Text);
                userFuel.AvgMilesPerGallon = Convert.ToDouble(txtAvgMilesPerGallon);

                FuelBLL fuelBLL = new FuelBLL();

                fuelBLL.InsertUserFuel(userFuel);

                lblresult.ForeColor = Color.Green;
                lblresult.Text = " Details inserted successfully";
                BindUserFuelDetails();
                LoadUserFuelChart();
            }
        }
Exemplo n.º 2
0
        public List<Fuel> GetUserFuels(string userId)
        {
            List<Fuel> userFuels = null;

            try
            {
                using (var cmd = new SqlCommand(StoredProcedures.SPR_GET_USER_FUEL_ITEMS, _connection))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = userId;

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            userFuels = new List<Fuel>();

                            while (reader.Read())
                            {
                                Fuel userFuel = new Fuel();

                                userFuel.UserId = reader["UserId"].ToString();
                                userFuel.FuelId = Convert.ToInt32(reader["FuelId"]);
                                userFuel.Odometer = Convert.ToDouble(reader["Odometer"]);
                                userFuel.Gallons = Convert.ToDouble(reader["Gallons"]);
                                userFuel.PricePerGallon = Convert.ToDouble(reader["PricePerGallon"]);
                                userFuel.TotalCost = Convert.ToDouble(reader["TotalCost"]);
                                userFuel.AvgMilesPerGallon = Convert.ToDouble(reader["AvgMilesPerGallon"]);
                                userFuel.FillDate = Convert.ToDateTime(reader["FillDate"]);

                                userFuels.Add(userFuel);
                            }

                        }
                    }
                }

            }
            catch (Exception ex)
            {

            }

            return userFuels;
        }
Exemplo n.º 3
0
 public void UpdateUserFuel(Fuel userFuel)
 {
     new FuelDAL().UpdateUserFuel(userFuel);
 }
Exemplo n.º 4
0
 public void InsertUserFuel(Fuel userFuel)
 {
     new FuelDAL().InsertUserFuel(userFuel);
 }
Exemplo n.º 5
0
        protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int fuelId = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Value.ToString());

            TextBox txtOdometer = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtOdometer");
            TextBox txtGallons = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtGallons");
            TextBox txtPricePerGallon = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtPricePerGallon");
            TextBox txtCost = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtCost");
            TextBox txtFillDate = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtFillDate");
            TextBox txtAvgMilesPerGallon = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtAvgMilesPerGallon");

            Fuel userFuel = new Fuel();

            userFuel.FuelId = fuelId;
            userFuel.UserId = _userObj.UserId;
            userFuel.Odometer = Convert.ToDouble(txtOdometer.Text);
            userFuel.Gallons = Convert.ToDouble(txtGallons.Text);
            userFuel.PricePerGallon = Convert.ToDouble(txtPricePerGallon.Text);
            userFuel.TotalCost = Convert.ToDouble(txtCost.Text);
            userFuel.FillDate = Convert.ToDateTime(txtFillDate.Text);
            userFuel.AvgMilesPerGallon = Convert.ToDouble(txtAvgMilesPerGallon.Text);

            FuelBLL fuelBLL = new FuelBLL();

            fuelBLL.UpdateUserFuel(userFuel);

            lblresult.ForeColor = Color.Green;
            lblresult.Text = " Details Updated successfully";
            gvDetails.EditIndex = -1;
            BindUserFuelDetails();
            LoadUserFuelChart();
        }
Exemplo n.º 6
0
        public void UpdateUserFuel(Fuel userFuel)
        {
            using (var cmd = new SqlCommand(StoredProcedures.SPR_UPDATE_FUEL_ITEM, _connection))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = userFuel.UserId;
                cmd.Parameters.Add("@Odometer", SqlDbType.Decimal).Value = userFuel.Odometer;
                cmd.Parameters.Add("@Gallons", SqlDbType.Decimal).Value = userFuel.Gallons;
                cmd.Parameters.Add("@Price", SqlDbType.Decimal).Value = userFuel.PricePerGallon;
                cmd.Parameters.Add("@TotalCost", SqlDbType.Decimal).Value = userFuel.TotalCost;
                cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = userFuel.FillDate;
                cmd.Parameters.Add("@AvgMiles", SqlDbType.Decimal).Value = userFuel.AvgMilesPerGallon;
                cmd.Parameters.Add("@FuelId", SqlDbType.Int).Value = userFuel.FuelId;

                cmd.ExecuteNonQuery();

            }
        }