Example #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            var thisMethod = MethodBase.GetCurrentMethod();

            Console.Write("****" + thisMethod.Name + "\n");

            using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter())
            {
                //The current employeeId is the current user's employee ID
                try
                {
                    string[] usr = UserPrincipal.Current.DisplayName.Split(' ');
                    _employee = dbLib.GetEmployeeByName(usr[0], usr[1]);
                }
                catch (Exception ex)
                {
                    string errHead = GetType().Name + "  " + System.Reflection.MethodBase.GetCurrentMethod().Name + "() failed. \n\n";
                    MessageBox.Show(errHead + "Source: " + ex.Source + "\n\n" + ex.Message, ProductName + " " + ProductVersion, MessageBoxButtons.OK);
                    Application.Exit();
                }
            }
            // Instantiate the forms that this MainForm controls.
            _timecardForm               = new TimecardForm(_employee);
            _timecardForm.Visible       = false;
            _taskcategoriesform         = new TaskCategoriesForm();
            _taskcategoriesform.Visible = false;
            _DefineTasksForm            = new DefineTasksForm();
            _DefineTasksForm.Visible    = false;
            _selectReportForm           = new SelectReportForm(_employee);
            _selectReportForm.Visible   = false;

            // The current active form is the one the user is working
            _currentActiveForm = null;
        }
Example #2
0
        // ----------------------------------------------------
        // Get All the task records from the DB that are still in use.
        private void GetActiveTasks()
        {
            try
            {
                //Assert wait cursor
                Application.UseWaitCursor = true;

                using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter())
                {
                    var activeTasks = new List <SsOpsDatabaseLibrary.Entity.Task>();
                    _activeTasks = dbLib.GetActiveTasks();
                }
            }
            catch (Exception ex)
            {
                Application.UseWaitCursor = false;
                string errHead = GetType().Name + "  " + System.Reflection.MethodBase.GetCurrentMethod().Name + "() failed. \n\n";
                MessageBox.Show(errHead + "Source: " + ex.Source + "\n\n" + ex.Message, ProductName + " " + ProductVersion, MessageBoxButtons.OK);
                Application.Exit();
            }
            finally
            {
                //Deny the wait cursor
                Application.UseWaitCursor = false;
            }
        }
Example #3
0
        // -----------------------------------------------
        // Get All this Employee's Timecard Detail Records into _timecardDetailsUnderGlass
        private void GetTimecardDetails()
        {
            try
            {
                //Assert wait cursor
                Application.UseWaitCursor = true;

                using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter())
                {
                    // Call OpsDataReader to get the details for the selected week
                    _tcDetailsUnderGlass = dbLib.GetTimecardDetailsByTimecardId(_timecardUnderGlass.TimecardId);
                }
            }
            catch (Exception ex)
            {
                Application.UseWaitCursor = false;
                string errHead = GetType().Name + "  " + System.Reflection.MethodBase.GetCurrentMethod().Name + "() failed. \n\n";
                MessageBox.Show(errHead + "Source: " + ex.Source + "\n\n" + ex.Message, ProductName + " " + ProductVersion, MessageBoxButtons.OK);
                Application.Exit();
            }
            finally
            {
                //Deny the wait cursor
                Application.UseWaitCursor = false;
            }
        }
Example #4
0
        // -----------------------------------------------
        // Get All this Employee's Timecard Records into _Timecards
        private void GetEmployeeTimecards()
        {
            try
            {
                //Assert wait cursor
                Application.UseWaitCursor = true;

                using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter())
                {
                    _timecards = dbLib.GetTimecardsForEmployee(_employee.EmployeeId);
                }
            }
            catch (Exception ex)
            {
                Application.UseWaitCursor = false;
                string errHead = GetType().Name + "  " + System.Reflection.MethodBase.GetCurrentMethod().Name + "() failed. \n\n";
                MessageBox.Show(errHead + "Source: " + ex.Source + "\n\n" + ex.Message, ProductName + " " + ProductVersion, MessageBoxButtons.OK);
                Application.Exit();
            }
            finally
            {
                //Deny the wait cursor
                Application.UseWaitCursor = false;
            }
        }
Example #5
0
        // ------------------------------------------------
        // Create a new timecard in the DB for the given Employee and Week, then
        // copy the new TimecardId that is returned by the DB insert function
        private void CreateNewTimecard()
        {
            //Assert the wait cursor..
            Application.UseWaitCursor = true;

            try
            {
                //Create a new timecard in the DB
                using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter())
                {
                    //Instantiate a new timecard and save it in the database
                    _timecardUnderGlass            = new Timecard();
                    _timecardUnderGlass.EmployeeId = _employee.EmployeeId;
                    _timecardUnderGlass.WeekNumber = _thisWeekNumber;
                    _timecardUnderGlass.Year       = DateTime.Today.ToString("yyyy");
                    int newlyMintedTimecardID = dbLib.CreateTimeCard(_timecardUnderGlass);
                    _timecardUnderGlass.TimecardId = newlyMintedTimecardID;
                }
            }
            catch (Exception ex)
            {
                Application.UseWaitCursor = false;
                string errHead = GetType().Name + "  " + System.Reflection.MethodBase.GetCurrentMethod().Name + "() failed. \n\n";
                MessageBox.Show(errHead + "Source: " + ex.Source + "\n\n" + ex.Message, ProductName + " " + ProductVersion, MessageBoxButtons.OK);
                Application.Exit();
            }
            finally
            {
                //Deny the wait cursor
                Application.UseWaitCursor = false;
            }
        }
        private void AppendTaskCategory(TaskCategory tcat)
        {
            try
            {
                //Assert wait cursor
                Application.UseWaitCursor = true;

                using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter())
                {
                    // Call OpsDataReader to get the details for the selected week
                    int x = dbLib.CreateTaskCategory(tcat);
                }
            }
            catch (Exception ex)
            {
                Application.UseWaitCursor = false;
                string errHead = GetType().Name + "  " + System.Reflection.MethodBase.GetCurrentMethod().Name + "() failed. \n\n";
                MessageBox.Show(errHead + "Source: " + ex.Source + "\n\n" + ex.Message, ProductName + " " + ProductVersion, MessageBoxButtons.OK);
                Application.Exit();
            }
            finally
            {
                //Deny the wait cursor
                Application.UseWaitCursor = false;
            }
        }
Example #7
0
        // ----------------------------------------------------------------
        // Update the TimecardDetail records for _timecardUnderGlass
        // If the timecard was newly created, it has no existing detail records.
        // Insert any records that are within _timecardUnderGlass.DetailList.
        // Otherwise, update or remove the existing records such that they match
        // the records within _timecardUnderGlass.DetailList
        private void UpdateTimecardDetails(bool isNewTimecard)
        {
            try {
                Application.UseWaitCursor = true;

                using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter()) {
                    //If we get here with an empty timecard then delete all detail records for this timecard and exit
                    if (_timecardUnderGlass.DetailList.Count == 0 && isNewTimecard)
                    {
                        return;
                    }

                    //Get any existing rows from the DB
                    List <TimecardDetail> existingDetails = dbLib.GetTimecardDetailsByTimecardId(_timecardUnderGlass.TimecardId);

                    //If there is nothing in the database to update or delete then this is an insert only operation
                    if (existingDetails.Count == 0)
                    {
                        if (_timecardUnderGlass.DetailList.Count == 0)
                        {
                            return;
                        }
                        //Insert all items in the _timecardUnderGlass.DetailList into the DB and return
                        dbLib.CreateTimeCardDetail(_timecardUnderGlass);
                        return;
                    }
                    // The database has existing records
                    //Look for deletes first, then Updates, and lastly inserts
                    List <TimecardDetail> pendingDeletes = new List <TimecardDetail>();

                    //Now find the records that are to be deleted (records that do not exist in the grid)
                    bool isNotFoundUnderGlass;
                    foreach (TimecardDetail existingTcd in existingDetails)
                    {
                        isNotFoundUnderGlass = true;
                        foreach (TimecardDetail tcd in _timecardUnderGlass.DetailList)
                        {
                            if (tcd.Task_Name == existingTcd.Task_Name)
                            {
                                isNotFoundUnderGlass = false;
                                break;
                            }
                        }
                        if (isNotFoundUnderGlass)
                        {
                            pendingDeletes.Add(existingTcd);
                        }
                    }
                    // If we have records to delete then do it now
                    if (pendingDeletes.Count > 0)
                    {
                        dbLib.DeleteTimeCardDetail(pendingDeletes);
                    }

                    // The UpdateTimecardDetails function will update all records that are already in the DB
                    dbLib.UpdateTimeCardDetail(_timecardUnderGlass);
                    // CreateTimecardDetail will insert any records NOT yet in the DB
                    dbLib.CreateTimeCardDetail(_timecardUnderGlass);
                }
            }
            catch (Exception ex) {
                Application.UseWaitCursor = false;
                string errHead = GetType().Name + "  " + System.Reflection.MethodBase.GetCurrentMethod().Name + "() failed. \n\n";
                MessageBox.Show(errHead + "Source: " + ex.Source + "\n\n" + ex.Message, ProductName + " " + ProductVersion, MessageBoxButtons.OK);
                Application.Exit();
            }
            finally {
                //Deny the wait cursor
                Application.UseWaitCursor = false;
            }
        }
        //======================================
        #region "Helper Functions"

        private void LaunchReport(string reportname)
        {
            //MessageBox.Show(reportname);
            bool  isGood = true;
            short yearNo;
            short startWeekNo;
            short endWeekNo;
            int   employeeIdNo;

            if (reportname == TIMECARD_ROLLUP_1)
            {
                // Validate the contents of the textbox controls in the gbxTimecardRollup01 group box
                isGood      = ValidateGroupBox(gbxTimecardRollup01);
                yearNo      = Convert.ToInt16(tbxYearNumber.Text);
                startWeekNo = Convert.ToInt16(tbxStartingWeekNbr.Text);
                endWeekNo   = Convert.ToInt16(tbxEndingWeekNbr.Text);
                if (isGood)
                {
                    if (!(yearNo > 2019 && yearNo < 2030))
                    {
                        MessageBox.Show("Please enter a year between 2019 and 2030.", "Attention");
                        return;
                    }
                    if (startWeekNo < 1 || startWeekNo > 53)
                    {
                        MessageBox.Show("Starting week number must be between 1 and 53.", "Attention");
                        return;
                    }
                    if (endWeekNo < 1 || endWeekNo > 53)
                    {
                        MessageBox.Show("Ending week number must be between 1 and 53.", "Attention");
                        return;
                    }
                    if (startWeekNo >= endWeekNo)
                    {
                        MessageBox.Show("Ending week number must be bigger than starting week number.", "Attention");
                        return;
                    }
                    // Validated okay.  Now get report data from our database adapter
                    using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter()) {
                        List <ReportTimeCardRollup01> records     = dbLib.GetTimecardRollup(yearNo, startWeekNo, endWeekNo);
                        ReportTimeCardRollup01[]      rollupArray = records.ToArray();
                        // Construct the ReportDisplayForm and show it on screen.
                        string[]          parametersForReport = { tbxYearNumber.Text, tbxStartingWeekNbr.Text, tbxEndingWeekNbr.Text };
                        ReportDisplayForm displayer           = new ReportDisplayForm(rollupArray, parametersForReport);
                        Size targetSize = new Size(1000, 1000);
                        displayer.Size = targetSize;
                        displayer.Show();
                    }
                }
            }
            if (reportname == EMPLOYEES_REPORT_1)
            {
                using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter()) {
                    List <Employee>   records   = dbLib.GetAllCurrentEmployees();
                    ReportDisplayForm displayer = new ReportDisplayForm(records.ToArray());
                    Size targetSize             = new Size(800, 500);
                    displayer.Size = targetSize;
                    displayer.Show();
                }
            }
            if (reportname == ACTIVETASK_BUDGET_SUMMARY)
            {
                using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter())
                {
                    List <SsOpsDatabaseLibrary.Entity.Task> tasks = dbLib.GetActiveTasksBudgetSummary();
                    ReportDisplayForm displayer = new ReportDisplayForm(tasks.ToArray());
                    Size targetSize             = new Size(1000, 1000);
                    displayer.Size = targetSize;
                    displayer.Show();
                }
            }
            if (reportname == TIMECARD_ROLLUP_02)
            {
                isGood       = ValidateGroupBox(gbxRollup02);
                yearNo       = Convert.ToInt16(tbxYearNumber02.Text);
                startWeekNo  = Convert.ToInt16(tbxStartWeekNbr02.Text);
                endWeekNo    = Convert.ToInt16(tbxEndingWeekNbr02.Text);
                employeeIdNo = Convert.ToInt32(tbxEmployeeIdNbr.Text);
                if (isGood)
                {
                    if (!(yearNo > 2019 && yearNo < 2030))
                    {
                        MessageBox.Show("Please enter a year between 2019 and 2030.", "Attention");
                        return;
                    }
                    if (startWeekNo < 1 || startWeekNo > 53)
                    {
                        MessageBox.Show("Starting week number must be between 1 and 53.", "Attention");
                        return;
                    }
                    if (endWeekNo < 1 || endWeekNo > 53)
                    {
                        MessageBox.Show("Ending week number must be between 1 and 53.", "Attention");
                        return;
                    }
                    if (startWeekNo >= endWeekNo)
                    {
                        MessageBox.Show("Ending week number must be bigger than starting week number.", "Attention");
                        return;
                    }
                    if (employeeIdNo < 100 || employeeIdNo > 999)
                    {
                        MessageBox.Show("Employee ID number should be greater than 100 and less than 1000", "Attention");
                        return;
                    }
                    //MessageBox.Show("Validation Passed");

                    using (OpsDatabaseAdapter dbLib = new OpsDatabaseAdapter()) {
                        List <ReportTimeCardRollup01> records     = dbLib.GetTimecardRollupForEmployee(yearNo, startWeekNo, endWeekNo, employeeIdNo);
                        ReportTimeCardRollup01[]      rollupArray = records.ToArray();
                        Employee emp = dbLib.GetEmployeeById(employeeIdNo);
                        string   employeeFullName = emp.FirstName + " " + emp.LastName;
                        // Construct the ReportDisplayForm and show it on screen.
                        string[]          parametersForReport = { tbxYearNumber02.Text, tbxStartWeekNbr02.Text, tbxEndingWeekNbr02.Text, tbxEmployeeIdNbr.Text, employeeFullName };
                        ReportDisplayForm displayer           = new ReportDisplayForm(rollupArray, parametersForReport);
                        Size targetSize = new Size(1000, 1000);
                        displayer.Size = targetSize;
                        displayer.Show();
                    }
                }
            }
        }