private void Button_Click(object sender, RoutedEventArgs e) { if (sender == btn_next) { index = index + 1 >= data.Rows.Count ? 0 : index + 1; } else if (sender == btn_prev) { index = index <= 0 ? data.Rows.Count - 1 : index - 1; } else if (sender == btn_reject) { string rowConstraints = "EmployeeID = " + tb_employeeID.Text + " AND LeaveType = '" + tb_leaveType.Text.Replace("'", "''") + "' AND LeavingDate = '" + tb_leavingDate.Text + "' AND JoiningDate = '" + tb_joiningDate.Text + "' AND LeaveDescription = '" + tb_description.Text.Replace("'", "''") + "'"; LeaveApplications.RejectApplications(rowConstraints); if (index + 1 == data.Rows.Count) { index--; } } else { MainPage mainPage = baseControl as MainPage; LeaveAssignmentPage leaveAssignmentPage = mainPage.LeaveAssignmentPage; mainPage.JobStack.Push(this); mainPage.Container.Navigate(leaveAssignmentPage); leaveAssignmentPage.icb_employees.Text = tb_employeeName.Text; leaveAssignmentPage.icb_employeeID.Text = tb_employeeID.Text; leaveAssignmentPage.icb_leaveTypes.Text = tb_leaveType.Text; leaveAssignmentPage.dp_leavingDate.Text = tb_leavingDate.Text; leaveAssignmentPage.dp_joiningDate.Text = tb_joiningDate.Text; // (baseControl as MainPage).LeaveAssignmentPage.AssignLeave( tb_employeeID.Text, tb_leaveType.Text, new DateString( tb_leavingDate.Text ).ToDateTime( ), new DateString( tb_joiningDate.Text ).ToDateTime( )); index = 0; return; } Reload( ); }
private void Button_Click(object sender, RoutedEventArgs e) { MainPage mainPage = baseControl as MainPage; Stack <Page> jobStack = mainPage.JobStack; if (icb_employeeID.Text.Length == 0 || icb_leaveTypes.Text.Length == 0 || dp_leavingDate.SelectedDate == null || dp_joiningDate.SelectedDate == null) { MessageBox.Show("Please fill in the required fields.", "Incomplete", MessageBoxButton.OK, MessageBoxImage.Asterisk); return; } if (lb_message.Visibility == System.Windows.Visibility.Visible) { MessageBox.Show(lb_message.Content.ToString( ) + "!", "Invalid Interval", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (dp_leavingDate.SelectedDate.Value < DateTime.Today) { MessageBox.Show("Leaving date cannot be a past date.", "Date Past", MessageBoxButton.OK, MessageBoxImage.Error); return; } DataTable data = LeavePeriods.GetLeavePeriods( ); string startingDate = ""; string endingDate = ""; bool leavingDateIsValid = false; bool joiningDateIsValid = false; foreach (DataRow row in data.Rows) { if (dp_leavingDate.SelectedDate.Value >= new DateString(row[0])) { startingDate = row[0].ToString( ); leavingDateIsValid = true; break; } } foreach (DataRow row in data.Rows) { if (dp_joiningDate.SelectedDate.Value.AddDays(-1) <= new DateString(row[1])) { endingDate = row[1].ToString( ); joiningDateIsValid = true; break; } } if (!leavingDateIsValid || !joiningDateIsValid) { MessageBox.Show("The leave period is not valid. Please enter a valid one or reconfigure.", "Invalid Leave Period", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (lb_balance.Content.ToString( ) == "!!") { MessageBox.Show("The interval you entered exceeds the bounds!", "Too Big Interval", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (lb_balance.Content.ToString( ).Length == 0) { if (MessageBox.Show("No balance available. Do you wish to entitle?", "No Balance", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { EntitlementsAdder entitlementsAdder = mainPage.EntitlementsAdder; jobStack.Push(this); mainPage.Container.Navigate(entitlementsAdder); entitlementsAdder.icb_employees.Text = icb_employees.Text; entitlementsAdder.icb_employeeID.Text = icb_employeeID.Text; entitlementsAdder.icb_leaveTypes.Text = icb_leaveTypes.Text; entitlementsAdder.icb_validFrom.Text = startingDate; entitlementsAdder.icb_validTo.Text = endingDate; } else { MessageBox.Show("Leave Not Assigned!", "Failure", MessageBoxButton.OK, MessageBoxImage.Information); } return; } if (double.Parse(lb_balance.Content.ToString( )) < 0) { MessageBoxResult result = MessageBox.Show("Balance is insufficient! Do you wish to update entitlement?", "Insufficient Balance", MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation); if (result != MessageBoxResult.No) { if (result == MessageBoxResult.Yes) { EntitlementsViewer entitlementsViewer = mainPage.EntitlementsViewer; mainPage.JobStack.Push(this); mainPage.Container.Navigate(entitlementsViewer); entitlementsViewer.icb_employeeID.Text = icb_employeeID.Text; entitlementsViewer.icb_employees.Text = icb_employees.Text; entitlementsViewer.icb_leaveTypes.Text = icb_leaveTypes.Text; entitlementsViewer.icb_validFrom.Text = startingDate; entitlementsViewer.icb_validTo.Text = endingDate; } return; } } string values = icb_employeeID.Text + ", '" + icb_leaveTypes.Text + "', '" + new DateString(dp_leavingDate.SelectedDate.Value) + "', '" + new DateString(dp_joiningDate.SelectedDate.Value) + "', " + lostBalance + ", '" + tb_commentBox.Text.Replace("'", "''") + "'"; string changes = "Balance = " + lb_balance.Content; StringBuilder rowConstraints = new StringBuilder("EmployeeID = " + icb_employeeID.Text + " AND LeaveType = '" + icb_leaveTypes.Text + "'"); StringBuilder dateConstraints = new StringBuilder( ); try { Entitlements.UpdateEntitlementInfo(changes, rowConstraints.ToString( )); LeaveList.AssignLeave(values); data = LeaveApplications.FetchDetails("LeavingDate, JoiningDate", rowConstraints.ToString( )); foreach (DataRow row in data.Rows) { if (new DateString(row[0].ToString( )) >= dp_leavingDate.SelectedDate && new DateString(row[1].ToString( )) <= dp_joiningDate.SelectedDate) { dateConstraints.Append("LeavingDate = '" + row[0] + "' AND JoiningDate = '" + row[1] + "' OR "); } } dateConstraints.Append("1 = 2"); rowConstraints.Append(" AND (" + dateConstraints.ToString( ) + ")"); LeaveApplications.RejectApplications(rowConstraints.ToString( )); MessageBox.Show("Leave Assigned Successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } catch (System.Data.SqlClient.SqlException exception) { MessageBox.Show(exception.Message); } if (jobStack.Count > 0) { mainPage.Container.Navigate(jobStack.Pop( )); } }