/// \brief This method UpdateMileage for user
        /// \details <b>Details</b>
        /// This method will update mileage when finishing order
        /// \return  void
        public bool UpdateMileage(Mileage mileage)
        {
            using (var myConn = new MySqlConnection(connectionString))
            {
                try
                {
                    const string sqlStatement = @"  UPDATE mileage
	                                            SET startCityID = @startCityID,
                                                    endCityID = @endCityID,
		                                            distance = @distance, 
                                                    workingTime = @workingTime
	                                            WHERE mileageID = @mileageID; "    ;

                    var myCommand = new MySqlCommand(sqlStatement, myConn);

                    myCommand.Parameters.AddWithValue("@startCityID", mileage.startCityID);
                    myCommand.Parameters.AddWithValue("@endCityID", mileage.endCityID);
                    myCommand.Parameters.AddWithValue("@distance", mileage.distance);
                    myCommand.Parameters.AddWithValue("@workingTime", mileage.workingTime);
                    myCommand.Parameters.AddWithValue("@mileageID", mileage.mileageID);

                    myConn.Open();

                    myCommand.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }
        }
Esempio n. 2
0
        internal override object[] getRow()
        {
            MileageList mileageList = MileageList.getInstance();
            Mileage     mileage     = mileageList.getItem(this);
            InvoiceList invoiceList = InvoiceList.getInstance();
            Invoice     invoice     = invoiceList.getItem(this);

            PTSList ptsList = PTSList.getInstance();
            PTS     pts     = ptsList.getItem(this);

            STSList stsList = STSList.getInstance();
            STS     sts     = stsList.getItem(this);

            Regions regions    = Regions.getInstance();
            string  regionName = (invoice == null) ? regions.getItem(_idRegionUsing) : regions.getItem(Convert.ToInt32(invoice.RegionToID));

            int      mileageInt  = 0;
            DateTime mileageDate = DateTime.Today;

            if (mileage != null)
            {
                int.TryParse(mileage.Count, out mileageInt);
                mileageDate = mileage.MonthToString();
            }

            return(new object[] { ID, ID, BBNumber, Grz, Mark.Name, info.Model, vin, regionName,
                                  info.Driver.GetName(NameType.Full), pts.Number, sts.Number, Year, mileageInt,
                                  mileageDate, info.Owner, info.Guarantee, GetStatus() });
        }
Esempio n. 3
0
        private void SetMileage(Car car, string value)
        {
            int count;

            int.TryParse(value, out count);

            if (count == 0)
            {
                return;
            }

            MileageList mileageList = MileageList.getInstance();
            Mileage     mileage     = mileageList.getItem(car);

            if (count > Convert.ToInt32(mileage.Count))
            {
                if (mileage.Count != string.Empty)
                {
                    mileage = car.createMileage();
                }

                mileage.Date = new DateTime(_date.Year, _date.Month, DateTime.DaysInMonth(_date.Year, _date.Month));
                mileage.SetCount(value);
                mileage.Save();
                _mileageReportList.Add(new MileageReport(car, "Пробег загружен"));
            }
            else if (count < Convert.ToInt32(mileage.Count))
            {
                _mileageReportList.Add(new MileageReport(car, "Значение пробега меньше, чем уже внесён в систему."));
            }
            else
            {
                _mileageReportList.Add(new MileageReport(car, "Новое значение пробега равно значению пробега уже внесённому в систему."));
            }
        }
Esempio n. 4
0
        // PUT api/Server/5
        public IHttpActionResult PutMileage(int id, Mileage mileage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != mileage.Id)
            {
                return(BadRequest());
            }

            db.Entry(mileage).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MileageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 5
0
        public Decimal GetMileage(string originPostalCode, string destinationPostalCode)
        {
            //
            Decimal miles = 0;
            RateWareXLPortTypeClient client = new RateWareXLPortTypeClient();

            try {
                AuthenticationToken authToken = getAuthenticationToken();
                if (client.isReady(authToken))
                {
                    ShipmentLocale org = new ShipmentLocale();
                    org.postalCode  = originPostalCode;
                    org.countryCode = "USA";

                    ShipmentLocale dest = new ShipmentLocale();
                    dest.postalCode  = destinationPostalCode;
                    dest.countryCode = "USA";

                    Mileage mileage = new Mileage();
                    mileage.releaseVersion = "22";
                    mileage.routingType    = "P";
                    mileage.systemId       = 1;
                    mileage.origin         = org;
                    mileage.destination    = dest;

                    miles = (Decimal)client.Mileage(authToken, mileage);
                }
                client.Close();
            }
            catch (TimeoutException te) { client.Abort(); throw new ApplicationException(te.Message); }
            catch (FaultException fe) { client.Abort(); throw new ApplicationException(fe.Message); }
            catch (CommunicationException ce) { client.Abort(); throw new ApplicationException(ce.Message); }
            return(miles);
        }
Esempio n. 6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var    isMileageValid = true;
            var    date           = Convert.ToDateTime(DeliveryDateDatePicker.SelectedDate);
            double miles;

            if (!double.TryParse(MileageTotalTextbox.Text, out miles))
            {
                isMileageValid = false;
                MessageBox.Show("Milease is not a number");
            }

            if (date == DateTime.MinValue)
            {
                isMileageValid = false;
                MessageBox.Show("Selected date is invalid");
            }

            var mileage = new Mileage {
                DeliveryDate = date, Miles = miles
            };

            if (isMileageValid)
            {
                _repository.AddMileageRecord(mileage);
            }

            LoadGrid();
        }
Esempio n. 7
0
 public virtual void AdditionalInfo()
 {
     Console.WriteLine("\tCost: {0} $", Cost.ToString("#.##"));
     Console.WriteLine("\tMileage: {0} km", Mileage.ToString("#.##"));
     Console.WriteLine("\tWeight: {0} kg", Weight.ToString("#.###"));
     Console.WriteLine("\tMax speed: {0} km/h", MaxSpeed.ToString("#.##"));
 }
        /// \brief This method InsertMileage for user
        /// \details <b>Details</b>
        /// This method will insert mileage for making order
        /// \return  void
        public bool InsertMileage(Mileage mileage)
        {
            using (var myConn = new MySqlConnection(connectionString))
            {
                try
                {
                    const string sqlStatement = @"  INSERT INTO mileage (mileageID, startCityID, endCityID, distance, workingTime)
	                                            VALUES (@mileageID, @depotCity, @endCityID, @distance, @workingTime); "    ;

                    var myCommand = new MySqlCommand(sqlStatement, myConn);

                    myCommand.Parameters.AddWithValue("@startCityID", mileage.startCityID);
                    myCommand.Parameters.AddWithValue("@endCityID", mileage.endCityID);
                    myCommand.Parameters.AddWithValue("@distance", mileage.distance);
                    myCommand.Parameters.AddWithValue("@workingTime", mileage.workingTime);
                    myCommand.Parameters.AddWithValue("@mileageID", mileage.mileageID);


                    myConn.Open();

                    myCommand.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }
        }
Esempio n. 9
0
        public void Delete(int idMileage)
        {
            Mileage mileage = getItem(idMileage);

            list.Remove(mileage);

            mileage.Delete();
        }
        public IActionResult Delete(Mileage m)
        {
            _context.Mileage.Remove(m);
            _context.SaveChanges();


            return(RedirectToAction("List"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Mileage mileage = db.Mileages.Find(id);

            db.Mileages.Remove(mileage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 12
0
        public List <Mileage> calculateAverageDistance(List <Mileage> allMileages)
        {
            //bool foundOdometerValue = false;
            Mileage        previousMileage  = new Mileage();
            List <Mileage> exactDayMileages = new List <Mileage>();
            List <Mileage> result           = new List <Mileage>();

            foreach (Mileage mileage in allMileages)
            {
                if (previousMileage.OdometerMileage == 0 && mileage.OdometerMileage == 0)
                {
                    continue;
                }
                if (previousMileage.OdometerMileage == 0 && mileage.OdometerMileage > 0)
                {
                    previousMileage = mileage;
                    result.Add(mileage);
                    continue;
                }
                if (mileage.Distance > 0)
                {
                    exactDayMileages.Add(mileage);
                }
                if (mileage.OdometerMileage > 0 && mileage.OdometerMileage > previousMileage.OdometerMileage)
                {
                    //means that we have full period for odometr prediction
                    result.Add(mileage);
                    int dailyMileageKnown = 0;
                    int daysKnown         = 0;
                    foreach (Mileage mileagePerDay in exactDayMileages)
                    {
                        dailyMileageKnown += mileagePerDay.Distance;
                        daysKnown++;
                    }
                    int    daysBetween    = (mileage.Date - previousMileage.Date).Days - daysKnown;
                    int    mileageBetween = mileage.OdometerMileage - previousMileage.OdometerMileage - dailyMileageKnown;
                    double dailyMileage   = mileageBetween / daysBetween;
                    foreach (Mileage mileagePerDay in exactDayMileages)
                    {
                        if (mileagePerDay.OdometerMileage == 0)
                        {
                            int daysFromPreviousMileage = (mileagePerDay.Date - previousMileage.Date).Days;
                            int mileagePredicted        = previousMileage.OdometerMileage + (int)(dailyMileage * daysFromPreviousMileage + mileagePerDay.Distance);
                            result.Add(new Mileage(mileagePerDay.Date, mileagePredicted));
                            //allMileages.First(x => x.Id == mileagePerDay.Id).OdometerMileage = mileagePredicted;
                            if (daysFromPreviousMileage > 1)
                            {
                                mileagePredicted -= mileagePerDay.Distance;
                                result.Add(new Mileage(mileagePerDay.Date.AddDays(-1), mileagePredicted));
                            }
                        }
                    }
                    exactDayMileages = new List <Mileage>();
                    previousMileage  = mileage;
                }
            }
            return(result.OrderBy(x => x.Date).ToList());//allMileages;
        }
Esempio n. 13
0
        public void Add(Mileage mileage)
        {
            if (list.Exists(item => item == mileage))
            {
                return;
            }

            list.Add(mileage);
        }
Esempio n. 14
0
        public void GetAnswer()
        {
            Decimal Mileage, Distance, Gallons;

            Distance = Convert.ToDecimal(txtDistance.Text);
            Gallons  = Convert.ToDecimal(txtGallons.Text);
            Mileage  = Distance / Gallons;

            MessageBox.Show(Mileage.ToString(), "Answer");
        }
Esempio n. 15
0
        protected override void loadFromSql()
        {
            DataTable dt = _provider.Select("Mileage");

            foreach (DataRow row in dt.Rows)
            {
                Mileage mileage = new Mileage(row);
                Add(mileage);
            }
        }
    void Start () {
        stageMove = GameObject.FindObjectOfType<StageMove>();
        creatorsManager = GameObject.FindObjectOfType<CreatorsManager>();
        mileage = GameObject.FindObjectOfType<Mileage>();

        isMoving = false;
        currentGrid = 0;
        nextGrid = Time.time;
        interval = gridLength / stageMove.fowardSpeed;
    }
        //[Authorize(Roles = UtilityClass.AdminUserRole)]
        public IActionResult Create(Mileage m)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            _context.Mileage.Add(m);
            _context.SaveChanges();
            return(RedirectToAction("List"));
        }
Esempio n. 18
0
        public IHttpActionResult GetMileage(int id)
        {
            Mileage mileage = db.Mileages.Find(id);

            if (mileage == null)
            {
                return(NotFound());
            }

            return(Ok(mileage));
        }
Esempio n. 19
0
        protected static void Display(Mileage data, int indent, string description = null)
        {
            if (data == null)
            {
                return;
            }

            DisplayLabel(description ?? "Mileage", indent);
            DisplayValue("Miles", data.miles, indent + 1);
            DisplayValue("Method", data.method, indent + 1);
        }
        //Create a Method to calculate Mileage
        public void  GetAnswer()
        {
            //Create 3 variables to work with
            Decimal Mileage, Distance, Gallons;

            //Add code to set these values from the UI
            Distance = Convert.ToDecimal(txtDistance.Text);
            Gallons  = Convert.ToDecimal(txtGallons.Text);
            Mileage  = Distance / Gallons;

            MessageBox.Show(Mileage.ToString(), "Answer");
        }
 /// <summary>
 /// Compared the value of the <see cref="Mileage"/> property with that of another <see cref="Location"/> instance.
 /// </summary>
 /// <param name="other">A <see cref="Location"/> object to compare.</param>
 /// <returns>An integer indicating whether the <see cref="Mileage"/> property of this object is less than, equal to or greater than that of the parameter.</returns>
 public int CompareTo(Location other)
 {
     if (other is null || other.Mileage == null)
     {
         return(Mileage == null ? 0 : 1);
     }
     if (Mileage == null)
     {
         return(-1);
     }
     return(Mileage.CompareTo(other.Mileage));
 }
Esempio n. 22
0
        public IActionResult AddMileage(Mileage mileage)
        {
            //Request.Form.Keys
            if (ModelState.IsValid)
            {
                this.db.Mileages.Add(mileage);
                this.db.SaveChanges();

                return(this.RedirectToAction("Index", "Home"));
            }
            return(new EmptyResult());
        }
Esempio n. 23
0
        public IHttpActionResult PostMileage(Mileage mileage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Mileages.Add(mileage);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = mileage.Id }, mileage));
        }
 /// <summary>
 /// Compares the value of the <see cref="Mileage"/> property with a <see cref="Distance"/> parameter.
 /// </summary>
 /// <param name="other">A <see cref="Distance"/> parameter to compare.</param>
 /// <returns>An integer indicating whether the <see cref="Mileage"/> property is less than, equal to or greater than the parameter.</returns>
 public int CompareTo(Distance other)
 {
     if (other is null)
     {
         return(Mileage == null ? 0 : 1);
     }
     if (Mileage == null)
     {
         return(-1);
     }
     return(Mileage.CompareTo(other));
 }
        public IActionResult Edit(Mileage m)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            _context.Mileage.Attach(m);
            _context.Entry(m).State = EntityState.Modified;
            _context.SaveChanges();

            return(RedirectToAction("List"));
        }
Esempio n. 26
0
        private void _dgvMileage_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int idMileage = Convert.ToInt32(_dgvMileage.Rows[e.RowIndex].Cells[0].Value);

            Mileage mileage = _mileageList.getItem(idMileage);

            Mileage_AddEdit mAE = new Mileage_AddEdit(mileage);

            if (mAE.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                loadMileage();
            }
        }
Esempio n. 27
0
        private void btnAddMileage_Click(object sender, EventArgs e)
        {
            Mileage mileage = _car.createMileage();

            Mileage_AddEdit mAE = new Mileage_AddEdit(mileage);

            if (mAE.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _mileageList.Add(mileage);

                loadMileage();
            }
        }
        // GET: Mileages/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mileage mileage = db.Mileages.Find(id);

            if (mileage == null)
            {
                return(HttpNotFound());
            }
            return(View(mileage));
        }
 public ActionResult EditAdmin([Bind(Include = "ID,TravelDate,StartAddress,EndAddress,Kilometres,Feedback,StatusID,EmployeeID,ApplicationID")] Mileage mileage)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mileage).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("IndexAdmin"));
     }
     PopulateDropDownLists();
     ViewBag.ApplicationID = new SelectList(db.Applications, "ID", "Rationale", mileage.ApplicationID);
     ViewBag.EmployeeID    = new SelectList(db.Employees, "ID", "FirstName", mileage.EmployeeID);
     ViewBag.StatusID      = new SelectList(db.Statuses, "ID", "Description", mileage.StatusID);
     return(View(mileage));
 }
Esempio n. 30
0
        public IHttpActionResult DeleteMileage(int id)
        {
            Mileage mileage = db.Mileages.Find(id);

            if (mileage == null)
            {
                return(NotFound());
            }

            db.Mileages.Remove(mileage);
            db.SaveChanges();

            return(Ok(mileage));
        }
Esempio n. 31
0
        void ReleaseDesignerOutlets()
        {
            if (appraisalDate != null)
            {
                appraisalDate.Dispose();
                appraisalDate = null;
            }

            if (ContainerView != null)
            {
                ContainerView.Dispose();
                ContainerView = null;
            }

            if (Mileage != null)
            {
                Mileage.Dispose();
                Mileage = null;
            }

            if (sacComment != null)
            {
                sacComment.Dispose();
                sacComment = null;
            }

            if (SacCommentsWidth != null)
            {
                SacCommentsWidth.Dispose();
                SacCommentsWidth = null;
            }

            if (Trim != null)
            {
                Trim.Dispose();
                Trim = null;
            }

            if (Vin != null)
            {
                Vin.Dispose();
                Vin = null;
            }

            if (YearMakeModel != null)
            {
                YearMakeModel.Dispose();
                YearMakeModel = null;
            }
        }
Esempio n. 32
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //declare variables
        double price;
        double gallons;
        int miles;
        double cost=0;

        //create an instance of the service
        Mileage m = new Mileage();

        //get the values from the text boxes
        //the try parse tests the values and returns a boolean
        //true if they are valid, false if not
        //if try it assigns the value to the outside
        //variable
        bool goodPrice= double.TryParse(txtPrice.Text, out price);
        bool goodGallons = double.TryParse(txtGallons.Text, out gallons);
        bool goodMiles = int.TryParse(txtTotalMiles.Text, out miles);

        if (goodPrice && goodGallons && goodMiles)
        {
            //if everything is ok pass the values to the service method
            //and get the response
            cost = m.CalculateCostPerMile(price, gallons, miles);
        }

        else
        {
            //otherwise create a javascript alert
            Response.Write("<script type='text/JavaScript'>alert('Make sure you only enter numbers')</script>");
            return;
        }

        lblResult.Text = "Your cost per mile was " + cost.ToString("c");
    }