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); }
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 {0}({1})?", Convert.ToString(selectedRow.Cells["Name"].Value), Convert.ToString(selectedRow.Cells["RegistrationNumber"].Value)), "Deleting...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (TripBl.VehicleInUse(Id) || RefillBl.VehicleInUse(Id)) { MessageBox.Show("Vehicle is in use, can't be deleted."); return; } VehicleBl vehicleBl = new VehicleBl(); vehicleBl.Delete(Id); Id = 0; RefreshGrid(); } } }
private void idBtnEdit_Click(object sender, EventArgs e) { if (IsDgvRowsPresent()) { var rowIndex = idDgvMastersVehicle.SelectedCells[0].RowIndex; var id = idDgvMastersVehicle.Rows[rowIndex].Cells[0].Value.ToString(); var ObjVehicleInfo = VehicleBl.GetVehiclePerId(id); var obj = new Vehicle(ObjVehicleInfo); obj.Show(); this.Close(); } }
private void RefreshGrid() { _dataTable = Utility.ToDataTable(VehicleBl.GetList()); bindingSource.DataSource = _dataTable; dataGridView.DataSource = bindingSource; dataGridView.Update(); dataGridView.Refresh(); dataGridView.Columns[0].Visible = false; dataGridView.Columns[1].HeaderText = "Vehicle name"; dataGridView.Columns[2].HeaderText = "Registration Number"; dataGridViewSearch.SetColumns(dataGridView.Columns); }
private void saveButton_Click(object sender, EventArgs e) { if (Valid()) { VehicleBl vehicleBl = new VehicleBl(); vehicleBl.Save(Id, nameTextBox.Text, registrationNumberTextBox.Text); nameTextBox.Text = registrationNumberTextBox.Text = ""; Id = 0; RefreshGrid(); } }
private void idBtnDelete_Click(object sender, EventArgs e) { if (IsDgvRowsPresent()) { var rowIndex = idDgvMastersVehicle.SelectedCells[0].RowIndex; var id = idDgvMastersVehicle.Rows[rowIndex].Cells[0].Value.ToString(); var Vehicle = idDgvMastersVehicle.Rows[rowIndex].Cells[1].Value.ToString(); DialogResult dialogResult = MessageBox.Show("Are you sure to delete customer : " + Vehicle + "\nThe record will be permanently deleted", "Delete Warning !...", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { VehicleBl.DeleteVehicle(id); RefreshDgv(); } } }
private void idBtnSave_Click(object sender, EventArgs e) { var objVehicleInfo = GetValueFromTextBox(); var ErrorCounter = 0; var ErrorMessage = "Following fields should not be empty \n\n"; if (string.IsNullOrEmpty(objVehicleInfo.VehicleNum)) { ErrorCounter++; ErrorMessage += ErrorCounter.ToString() + "] " + "Please Enter Vehicle Number \n"; } if (string.IsNullOrEmpty(objVehicleInfo.VehicleBrand)) { ErrorCounter++; ErrorMessage += ErrorCounter.ToString() + "] " + "Please enter Vehicle Brand / Type\n"; } if (ErrorCounter > 0) { MessageBox.Show(ErrorMessage, "Warning !..."); return; } if (string.IsNullOrEmpty(objVehicleInfo.ID)) { var IsPresent = VehicleBl.IsVehicleAlreadyPresent(objVehicleInfo.VehicleNum); if (IsPresent == true) { MessageBox.Show("Item already Exist with Name : " + objVehicleInfo.VehicleNum, "Warning !..."); return; } VehicleBl.SaveVehicle(objVehicleInfo); } else { VehicleBl.UpdateVehicle(objVehicleInfo); } FormCancelButton = true; if (InitFromMenu != true) { MastersVehicle obj = new MastersVehicle(); obj.Show(); } this.Close(); }
public static string[] GetVehicleNo(string prefixText) { VehicleBl objVehicleBl = new VehicleBl(); ApplicationResult objResult = new ApplicationResult(); string strSearchText = prefixText + "%"; List <string> result = new List <string>(); objResult = objVehicleBl.Vehicle_Search(strSearchText); if (objResult != null) { for (int i = 0; i < objResult.ResultDt.Rows.Count; i++) { string strVehicleNumber = objResult.ResultDt.Rows[i]["VehicleNumber"].ToString(); string strVehicleId = objResult.ResultDt.Rows[i]["VehicleId"].ToString(); result.Add(string.Format("{0}~{1}", strVehicleNumber, strVehicleId)); } } return(result.ToArray()); }