private void bbiRemoveFuelCorrection_Click(object sender, EventArgs e) { try { if (DevExpress.XtraEditors.XtraMessageBox.Show(this.LookAndFeel, "Ben je zeker dat je de brandstof correctie wilt verwijderen?", "Delete?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3) == DialogResult.Yes) { //******************** // GetFuels //******************** FuelCorrectionObject fuel = (FuelCorrectionObject)this.gdvFuelCorrection.GetRow(this.gdvFuelCorrection.FocusedRowHandle); FuelObjectCollection fuels; BL.Internal.Fuel fuelBL = new BL.Internal.Fuel(); fuels = fuelBL.GetFilter(PROF_IT.Common.Convert.DateFunctions.DBDateToDate(fuel.DateFrom), PROF_IT.Common.Convert.DateFunctions.DBDateToDate(fuel.DateTo), fuel.VehiclesNotIncluded, fuel.SuppliersIncluded); if (fuels != null) { foreach (FuelObject fuelObj in fuels) { fuelObj.QuantityCorrection = fuelObj.Quantity; new BL.Internal.Fuel().Save(fuelObj); } } new BL.Internal.FuelCorrection().Remove(fuel); FillControlsCorrection(); } } catch (System.Exception exception1) { System.Exception thisException = exception1; Management.ShowException(thisException); } }
private void CalculateFuelCorrectionRows() { try { //******************** // GetFuels //******************** string vehiclesNotIncluded = ""; for (int i = 0; i < this.ccbxVehiclesNotIncluded.Properties.GetItems().Count; i++) { if (this.ccbxVehiclesNotIncluded.Properties.Items[i].CheckState == CheckState.Checked) { vehiclesNotIncluded += (string)this.ccbxVehiclesNotIncluded.Properties.Items[i].Value + "/"; } } string suppliersIncluded = ""; for (int i = 0; i < this.ccbxSuppliersIncluded.Properties.GetItems().Count; i++) { if (this.ccbxSuppliersIncluded.Properties.Items[i].CheckState == CheckState.Checked) { suppliersIncluded += (string)this.ccbxSuppliersIncluded.Properties.Items[i].Value + "/"; } } BL.Internal.Fuel fuelBL = new BL.Internal.Fuel(); _fuelCorrectionRows = fuelBL.GetFilter(dteDateFromCorrection.DateTime, dteDateToCorrection.DateTime, vehiclesNotIncluded, suppliersIncluded); //******************** // Calculate //******************** decimal totalAmountOfLiters = fuelBL.GetTotalAmountOfLiters(_fuelCorrectionRows); decimal stillToAdd = spinQuantityCorrection.Value; decimal averageToAdd = 0; string vehicle = ""; int CountLoop = 0; do { foreach (FuelObject fuel in _fuelCorrectionRows) { if (stillToAdd > 0) { averageToAdd = (fuel.Quantity / totalAmountOfLiters) * spinQuantityCorrection.Value; if (vehicle != fuel.VehicleLicensePlate) { if (stillToAdd > averageToAdd) { if (spinMaxQuantity.Value < fuel.Quantity + averageToAdd) { if (spinMaxQuantity.Value > fuel.Quantity) { fuel.QuantityCorrection = spinMaxQuantity.Value; stillToAdd -= spinMaxQuantity.Value - fuel.Quantity; } else fuel.QuantityCorrection = fuel.Quantity; } else { fuel.QuantityCorrection = fuel.Quantity + averageToAdd; stillToAdd -= averageToAdd; } } else { if (spinMaxQuantity.Value < fuel.Quantity + stillToAdd) { if (spinMaxQuantity.Value > fuel.Quantity) { fuel.QuantityCorrection = spinMaxQuantity.Value; stillToAdd -= spinMaxQuantity.Value - fuel.Quantity; } else fuel.QuantityCorrection = fuel.Quantity; } else { fuel.QuantityCorrection = fuel.Quantity + stillToAdd; stillToAdd = 0; } } vehicle = fuel.VehicleLicensePlate; } } } CountLoop += 1; } while (stillToAdd > 0 & CountLoop < 1000); if (CountLoop >= 1000) { DevExpress.XtraEditors.XtraMessageBox.Show("Niet mogelijk om de hoeveelheid te verdelen over de voertuigen!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { this.gdcFuelCorrectionCalc.DataSource = _fuelCorrectionRows; } } catch (System.Exception exception1) { System.Exception innerException = exception1; throw new System.Exception(MethodBase.GetCurrentMethod().Name, innerException); } }