public MainPage(UIElement baseControl, string username, string password, string userrole, string employeeID)
        {
            InitializeComponent();
            page_container      = Container;
            entitlementsViewer  = new EntitlementsViewer(this);
            entitlementsAdder   = new EntitlementsAdder(this);
            leaveAssignmentPage = new LeaveAssignmentPage(this);
            sendApplication     = new SendApplication(this);
            viewApplication     = new ViewApplication(this);
            jobStack            = new Stack <Page>( );
            this.baseControl    = baseControl;
            this.username       = username;
            this.password       = password;
            this.userrole       = userrole;
            this.employeeID     = employeeID;
            this.userIsLoggedIn = true;
            MainWindow mainWindow = baseControl as MainWindow;

            this.Height = mainWindow.Frame.Height;
            this.Width  = mainWindow.Frame.Width;
            (baseControl as MainWindow).Frame.NavigationUIVisibility = NavigationUIVisibility.Visible;
        }
示例#2
0
        public void Add_Entitlements_Event(object sender, RoutedEventArgs e)
        {
            Page page = new EntitlementsAdder(Container.Height, Container.Width);

            Container.Navigate(page);
        }
示例#3
0
        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( ));
            }
        }