Beispiel #1
0
        private void saveButton_Click(object sender, EventArgs e)
        {            
            if(Valid())
            {
                RefillBl refillBl = new RefillBl();           
            
                //Close  previous refill
                if (Id == 0 && RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())) != null) refillBl.SetClosed(RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())));
                try
                {


                    refillBl.Save(Id, DateTime.Parse(dateTimePicker.Text), int.Parse(vehicleComboBox.SelectedValue.ToString()), decimal.Parse(amountTextBox.Text), double.Parse(litreageTextBox.Text), decimal.Parse(mileageTextBox.Text));                

                    dateTimePicker.Text = DateTime.Today.ToString();
                    amountTextBox.Text = mileageTextBox.Text = litreageTextBox.Text = "";
                    Id = 0;
                }
                catch (Exception ex) { MessageBox.Show("Error occured: " + ex.Message); }           

                RefreshGrid();
                NewVehicleCompobox();
            }
        }
Beispiel #2
0
        public static List<MasterReport> GetList()
        {
            List<MasterReport> items = new List<MasterReport>();



            foreach(var item in TripBl.GetList())
            {
                MasterReport reportData = new MasterReport();
                Refill r = new RefillBl().GetById(item.RefillId);
                Vehicle v = new VehicleBl().GetById(item.VehicleId);
                Driver d = new DriverBl().GetById(item.DriverId);

                string closed = "";

                reportData.DateTimeStart = string.Format("{0}", item.DateTimeStart.ToString("dd/MM/yy,hh:mm tt"));
                reportData.DateTimeEnd = string.Format("{0}", item.DateTimeEnd.ToString("dd/MM/yy,hh:mm tt"));
                reportData.DriverName = d.FullName;
                reportData.DriverId = d.Id;
                reportData.VehicleName = string.Format("{0}({1})", v.Name, v.RegistrationNumber);
                reportData.VehicleId = v.Id;
                reportData.Refill = string.Format("Refill No: {5}\nDate: {0}\nAmount: ${1}\nLiterage: {2}L\nPerfo': {3}km/l\nStatus: {4}", r.DateAndTime.ToString("dd/MM/yy "), r.Amount, r.Litreage, (RefillBl.TotalMileage(r.Id)/(decimal)r.Litreage).ToString("N2"), closed = r.Closed ? "Closed" : "Open", r.Id);
                reportData.RefillId = r.Id;
                reportData.MileageStart = item.MileageStart;
                reportData.MileageEnd = item.MileageEnd;
                reportData.MileageTravelled = (item.MileageEnd - item.MileageStart);
                reportData.TripDetails = item.TripDetails;
                reportData.ExpenseAccount = item.ExpenseAccount;
                reportData.Cost = (reportData.MileageTravelled / RefillBl.TotalMileage(r.Id)) * r.Amount;
                    
                items.Add(reportData);

            }

            return items;
        }   
Beispiel #3
0
        private void deleteButton_Click(object sender, EventArgs e)
        {

            if (dataGridView.SelectedCells.Count > 0)
            {
                int selectedrowindex = dataGridView.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dataGridView.Rows[selectedrowindex];

                Id = int.Parse(Convert.ToString(selectedRow.Cells["Id"].Value));

                if (MessageBox.Show(String.Format("Are you sure to delete refill on {0}?", Convert.ToString(selectedRow.Cells["Date"].Value)), "Deleting...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (TripBl.RefillInUse(Id))
                    {
                        MessageBox.Show("Refill is in use, can't be deleted.");
                        return;
                    }

                    RefillBl refillBl = new RefillBl();
                    refillBl.Delete(Id);
                    Id = 0;

                    RefreshGrid();
                }
            }
        }