Пример #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();
            }
        }
Пример #2
0
 private void loadUserFuels()
 {
     FuelBLL fuelBll = new FuelBLL();
     List<Fuel> fuelList =  fuelBll.GetUserFuels(_userObj.UserId);
     if (fuelList != null)
     {
         foreach (var fuel in fuelList)
         {
             _fuel.Add(fuel.FuelId, fuel.Odometer);
         }
     }
 }
Пример #3
0
        private void LoadUserFuelChart()
        {
            FuelBLL fuelBll = new FuelBLL();

            if (_userObj != null)
            {
                hcFrutas.Series.Clear();

                List<Fuel> fuelList = fuelBll.GetUserFuels(_userObj.UserId);

                if (fuelList != null)
                {
                    //Defining Axis

                    ArrayList Dates = new ArrayList();
                    ArrayList Gallons = new ArrayList();

                    foreach (var userFuel in fuelList)
                    {
                        Dates.Add(userFuel.FillDate.ToString("MMM"));
                        Gallons.Add(userFuel.AvgMilesPerGallon);
                    }

                    //Title configuration
                    hcFrutas.Title = new Title("Miles Per Gallon");
                    hcFrutas.SubTitle = new SubTitle("Fuel Data");

                    //Defining Axis
                    hcFrutas.YAxis.Add(new YAxisItem { title = new Title("Gallons"), min = 0, max = 100, tickInterval=10, allowDecimals = true });
                    hcFrutas.XAxis.Add(new XAxisItem { title = new Highchart.Core.Title("Fill Date"), categories = new object[]{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} });

                    //data
                    var series = new Collection<Serie>();
                   // series.Add(new Serie { name = DateTime.Now.ToShortDateString(), data = new object[] { 20 } });

                    //data
                    //var series = new Collection<Serie>();
                    foreach (var userFuel in fuelList)
                    {
                        ArrayList avgMilesPerGallon = new ArrayList();

                        for (int i = 1; i <= 12; i++)
                        {
                            if (i == userFuel.FillDate.Month)
                            {
                                avgMilesPerGallon.Add(userFuel.AvgMilesPerGallon);
                            }
                            else
                            {
                                avgMilesPerGallon.Add(0.0);
                            }
                        }
                        series.Add(new Serie { name = userFuel.FillDate.ToShortDateString(), data = avgMilesPerGallon.ToArray() });
                    }

                    //configuring Visual
                    hcFrutas.PlotOptions = new Highchart.Core.PlotOptions.PlotOptionsColumn { borderColor = "#dedede", borderRadius = 4 };

                    //bind
                    hcFrutas.DataSource = series;
                    hcFrutas.DataBind();

                }
            }
        }
Пример #4
0
        private void BindUserFuelDetails()
        {
            FuelBLL fuelBll = new FuelBLL();

            if (_userObj != null)
            {
                List<Fuel> fuelList = fuelBll.GetUserFuels(_userObj.UserId);

                bool isHideFirstRow = false;

                if (fuelList != null)
                {
                    gvDetails.DataSource = fuelList;
                    gvDetails.DataBind();
                }
                else
                {
                    isHideFirstRow = true;
                    List<Fuel> fuels = new List<Fuel>();
                    fuels.Add(new Fuel());
                    gvDetails.DataSource = fuels;
                    gvDetails.DataBind();
                    gvDetails.ShowFooter = true;
                }

                if (isHideFirstRow)
                {
                    //Hide the first row if it's empty
                    gvDetails.Rows[0].Visible = false;
                }
            }
        }
Пример #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();
        }
Пример #6
0
        protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int fuelId = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["FuelId"].ToString());

            FuelBLL fuelBll = new FuelBLL();

            fuelBll.DeleteUserFuel(fuelId);
            lblresult.ForeColor = Color.Red;
            lblresult.Text = " details deleted successfully";
            BindUserFuelDetails();
            LoadUserFuelChart();
        }