//private void btnFOHEdit_Click(object sender, RoutedEventArgs e) //{ // if (cmbFOHEditMonth.SelectedIndex >= 0) // { // fillvalsToTextfoh(cmbFOHEditMonth, cmbFOHEditYear); // } // else // System.Windows.MessageBox.Show("Please select a year and a month to edit", "Please Select", MessageBoxButton.OK, MessageBoxImage.Warning); //} private void btnFOHDelete_Click(object sender, RoutedEventArgs e) { // If the user is authorized to perform the delete operation if (_userType.getUserLevel() == 1 || _userType.getUserLevel() == 2) { //delete function FixedOverHeadDAO fixdao = new FixedOverHeadDAO(); //get the confirmation with a message box with yes no cancel buttons if (System.Windows.MessageBox.Show("Do you want to delete " + cmbFOHEditYear.Text + " ," + cmbFOHEditMonth.Text + " months fixed overhead details?", "Confirm", MessageBoxButton.YesNoCancel, MessageBoxImage.Information) == MessageBoxResult.Yes) { int mnthx = Convert.ToInt32(cmbFOHEditMonth.Text); int yearx = Convert.ToInt32(cmbFOHEditYear.Text); String fixid; //dao method is called to delete the fix overhead fixid = fixdao.getIdByMonthNYear(mnthx, yearx); lbleditFOHID.Content = fixid; if (fixdao.deleteFixOH(fixid)) { this.fixedOverheadDataGrid.Items.Refresh(); _context.FixedOverheads.Load(); fixDAO.populateYears(cmbFOHEditYear, cmbFOHEditMonth); System.Windows.MessageBox.Show("Succesfully Deleted", "Done", MessageBoxButton.OK, MessageBoxImage.Information); resetAll(); } else System.Windows.MessageBox.Show("Faild to delete", "Faild", MessageBoxButton.OK, MessageBoxImage.Information); } } else { ModernDialog.ShowMessage("You are not privilaged to perform this action", "Access Denied!", MessageBoxButton.OK); } }
private void btnFOHAdd_Click(object sender, System.Windows.RoutedEventArgs e) { if (getvalidationsEmptyFields()) System.Windows.MessageBox.Show("Need to fill all the fields", "Empty Fields", MessageBoxButton.OK, MessageBoxImage.Warning); else { FixedOverHeadDAO fixdao = new FixedOverHeadDAO(); FixedOverHeadData fixdata = new FixedOverHeadData(); //check for the values exisit in the tabel int mx = 0; string fixID = ""; int mont = cmbFOHmonthComboBox.SelectedIndex + 1; int year1 = Convert.ToInt32(cmbFOHForMonthYear.SelectedValue.ToString()); fixID = fixdao.getmonth(mont, year1); if (fixID != null) mx = 1; //end of check //parsig values to fixed overhead data objec fixdata.Year = Convert.ToInt32(cmbFOHForMonthYear.Text); fixdata.Month = cmbFOHmonthComboBox.SelectedIndex + 1; fixdata.Elect = Convert.ToDouble(txtFOHAddElectricityCost.Text); fixdata.Tax = Convert.ToDouble(txtFOHAddTaxCost.Text); fixdata.Water = Convert.ToDouble(txtFOHAddWaterCost.Text); fixdata.Salary = Convert.ToDouble(txtFOHAddSalaryCost.Text); fixdata.Rent = Convert.ToDouble(txtFOHAddRentMortgageLeaseLoanCost.Text); fixdata.PhInt = Convert.ToDouble(txtFOHAddPhoneInternetCost.Text); fixdata.Fule = Convert.ToDouble(txtFOHAddFuleCost.Text); fixdata.Mess = Convert.ToDouble(txtFOHAddMiscellaneousCost.Text); fixdata.Ot = Convert.ToDouble(txtFOHAddOTCost.Text); decimal other; //other field is allowed be blanked. if field is blank then the value is taken as 0 if (string.IsNullOrEmpty(txtFOHAddOther.Text) || string.IsNullOrWhiteSpace(txtFOHAddOther.Text)) other = 0; else other = Convert.ToDecimal(txtFOHAddOther.Text); fixdata.Other = (double)other; //fixed overhead add // if (btnFOHAdd.Content.ToString() == "Add") { //check whether the fid overhead data for the perticular month is entered if (mx == 0) { //fix overhead data in not available if (fixdao.addFixedOverHead(fixdata)) { this.fixedOverheadDataGrid.Items.Refresh(); _context.FixedOverheads.Load(); fixDAO.populateYears(cmbFOHEditYear, cmbFOHEditMonth); System.Windows.MessageBox.Show("Succesfully Added", "Done", MessageBoxButton.OK, MessageBoxImage.Information); resetAll(); } else System.Windows.MessageBox.Show("Faild to Add", "Faild", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else if (mx > 0) { //fix overhead data available //suggest to edit fix overhead data foe the perticualar month MessageBoxResult msgresul = MessageBox.Show("Fixed Overheads details For this month are alredy exist do you want to update?", "Already exist", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); //get the confimation by the user to edit data if (msgresul == MessageBoxResult.Yes) { //fill values to the month table fillvalsToTextfohStriing(fixID); } } else { } } else //fixed overhead edit function { fixdata.Id = lbleditFOHID.Content.ToString(); try { if (fixdao.updateFixData(fixdata)) { this.fixedOverheadDataGrid.Items.Refresh(); _context.FixedOverheads.Load(); System.Windows.MessageBox.Show("Succesfully updated", "Done", MessageBoxButton.OK, MessageBoxImage.Information); // resetAll(); } else System.Windows.MessageBox.Show("Faild to update", "Faild", MessageBoxButton.OK, MessageBoxImage.Exclamation); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Exception"); } } } }