private void btnSave_Click(object sender, EventArgs e) { try { FuelMember.Employee = cmbEmployee.Text; FuelMember.FuelType = (Framework.Common.Enumeration.Fuel.FuelType)Enum.Parse(typeof(Framework.Common.Enumeration.Fuel.FuelType), cmbFuelType.Text); FuelMember.Supplier = cmbSupplier.Text; FuelMember.VehicleLicensePlate = cmbVehicle.Text; FuelMember.Date = dteDate.DateTime; FuelMember.InvoiceOK = cbxInvoiceOK.Checked; FuelMember.InvoiceReceived = cbxInvoiceReceived.Checked; FuelMember.PrivateTanking = cbxPrivate.Checked; FuelMember.UnityPrice = calcUnityPrice.Value; FuelMember.Quantity = calcQuantity.Value; FuelMember.TotalPrice = calcQuantity.Value * calcUnityPrice.Value; TIS.BL.Internal.Fuel fuelBL = new BL.Internal.Fuel(); fuelBL.Save(FuelMember); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch (System.Exception exception1) { System.Exception thisException = exception1; Management.ShowException(thisException); } }
private void FindAll() { try { string[] suppliers = new BL.Internal.Fuel().GetSuppliers(); foreach (string supplier in suppliers) { this.cmbSupplier.Properties.Items.Add(supplier); } string[] vehicles = new BL.Internal.Fuel().GetVehicles(); foreach (string vehicle in vehicles) { this.cmbVehicle.Properties.Items.Add(vehicle); } string[] employees = new BL.Internal.Fuel().GetEmployees(); foreach (string employee in employees) { this.cmbEmployee.Properties.Items.Add(employee); } foreach (string fuelType in Enum.GetNames(typeof(Framework.Common.Enumeration.Fuel.FuelType))) { this.cmbFuelType.Properties.Items.Add(fuelType); } } catch (System.Exception exception1) { System.Exception innerException = exception1; throw new System.Exception(MethodBase.GetCurrentMethod().Name, innerException); } }
private void FillControls() { try { string[] suppliers = new BL.Internal.Fuel().GetSuppliers(); foreach (string supplier in suppliers) { this.cmbSupplier.Properties.Items.Add(supplier); this.ccbxSuppliersIncluded.Properties.Items.Add(supplier); } string[] vehicles = new BL.Internal.Fuel().GetVehicles(); foreach (string vehicle in vehicles) { this.cmbVehicle.Properties.Items.Add(vehicle); this.ccbxVehiclesNotIncluded.Properties.Items.Add(vehicle); } string[] employees = new BL.Internal.Fuel().GetEmployees(); foreach (string employee in employees) { this.cmbEmployee.Properties.Items.Add(employee); } foreach (string fuelType in Enum.GetNames(typeof(Framework.Common.Enumeration.Fuel.FuelType))) { this.cmbFuel.Properties.Items.Add(fuelType); } dteDateFrom.DateTime = DateTime.Now.Subtract(TimeSpan.FromDays(1)); dteDateTo.DateTime = DateTime.Now; } catch (System.Exception exception1) { System.Exception innerException = exception1; throw new System.Exception(MethodBase.GetCurrentMethod().Name, innerException); } }
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 ClearFuelCorrectionControls() { try { this.ccbxSuppliersIncluded.Properties.Items.Clear(); string[] suppliers = new BL.Internal.Fuel().GetSuppliers(); foreach (string supplier in suppliers) { this.ccbxSuppliersIncluded.Properties.Items.Add(supplier); } this.ccbxVehiclesNotIncluded.Properties.Items.Clear(); string[] vehicles = new BL.Internal.Fuel().GetVehicles(); foreach (string vehicle in vehicles) { this.ccbxVehiclesNotIncluded.Properties.Items.Add(vehicle); } dteDateFromCorrection.Text = ""; dteDateToCorrection.Text = ""; _fuelCorrection = new FuelCorrectionObject(); this.gdcFuelCorrectionCalc.DataSource = null; _saveEnable = true; btnSaveCorrection.Enabled = false; btnCancelCorrection.Enabled = false; } catch (System.Exception exception1) { System.Exception innerException = exception1; throw new System.Exception(MethodBase.GetCurrentMethod().Name, innerException); } spinMaxQuantity.Value = 0; spinQuantityCorrection.Value = 0; }
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); } }
private void btnImportTotal_Click(object sender, EventArgs e) { try { try { OpenFileDialog ofdImport = new OpenFileDialog(); ofdImport.Title = "Select file"; ofdImport.Filter = "Excel Sheet(*.xlsx)|*.xlsx|Excel Sheet 2003(*.xls)|*.xls|All Files(*.*)|*.*"; ofdImport.FilterIndex = 1; ofdImport.RestoreDirectory = true; if (ofdImport.ShowDialog() != DialogResult.OK) return; string connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; data source={0}; Extended Properties=Excel 12.0;", ofdImport.FileName); OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [Download factuur in Excel$]", connectionString); DataSet ds = new DataSet(); adapter.Fill(ds); foreach (DataRow dr in ds.Tables[0].Rows) { if (dr[18].ToString() == "" || dr[18].ToString().Trim() == "hoeveelheid") // Do not import header or empty rows from Excel continue; Enumeration.Fuel.FuelType fuelType; switch(dr[17].ToString().ToLower()) { case "adblue": fuelType = Enumeration.Fuel.FuelType.Unknown ; break; case "diesel 10 ppm": fuelType = Enumeration.Fuel.FuelType.Diesel ; break; case "excellium diesel": fuelType = Enumeration.Fuel.FuelType.Diesel ; break; default: fuelType = Enumeration.Fuel.FuelType.Unknown; break; } string currency = dr[28].ToString().ToLower().Trim(); if (currency.ToLower() != "eur" && currency.ToLower() != "pln") { XtraMessageBox.Show("Wisselkoers niet gekend", "De wisselkoers " + currency + "is niet gekend!" , MessageBoxButtons.OK, MessageBoxIcon.Warning); continue; } if (fuelType == Enumeration.Fuel.FuelType.Diesel) { string licenseplate = ""; string employeename = ""; if (dr[12].ToString() != "") { int space1 = dr[12].ToString().IndexOf(' '); licenseplate = dr[12].ToString().Substring(0, space1); employeename = dr[12].ToString().Substring(space1 + 1); } TIS.DL.Internal.Fuel.FuelObject fuelObj = new FuelObject(); fuelObj.Btw = Convert.ToDecimal(dr[21].ToString()); fuelObj.CompanyTanking = false; fuelObj.Date = Convert.ToDateTime(dr[15].ToString()); fuelObj.Employee = employeename; fuelObj.EmployeeName = employeename; fuelObj.FuelType = fuelType; fuelObj.InvoiceOK = false; fuelObj.InvoiceReceived = false; fuelObj.Location = dr[26].ToString() + " -- " + dr[30].ToString(); fuelObj.PrivateTanking = false; fuelObj.Quantity = Convert.ToDecimal(dr[18].ToString()); fuelObj.QuantityCorrection = 0; fuelObj.Supplier = "TOTAL"; fuelObj.TotalPrice = Convert.ToDecimal(dr[20].ToString()); fuelObj.UnityPrice = Convert.ToDecimal(dr[20].ToString()) / Convert.ToDecimal(dr[18].ToString()); fuelObj.VehicleKilometreCounter = Convert.ToInt32(Math.Round(Convert.ToDecimal(dr[31].ToString()),0)); fuelObj.VehicleLicensePlate = licenseplate; if (currency == "pln") { decimal pln = Convert.ToDecimal(txtPLNCurrency.Text); fuelObj.Btw = fuelObj.Btw / pln; fuelObj.TotalPrice = fuelObj.TotalPrice / pln; fuelObj.UnityPrice = fuelObj.UnityPrice / pln; } TIS.BL.Internal.Fuel fuelBL = new BL.Internal.Fuel(); fuelBL.Save(fuelObj); } } XtraMessageBox.Show("Geïmporteerd", "Bestand is geïmporteerd.", MessageBoxButtons.OK, MessageBoxIcon.Warning); Filter(); } catch (System.Exception excepion1) { System.Exception thisException = excepion1; Management.ShowException(thisException); } } catch (System.Exception excepion1) { System.Exception thisException = excepion1; Management.ShowException(thisException); } }