Пример #1
0
        /*	================================================================================
         *	Event for combo box items change
         *	- Includes display
         *	- Changes current workweek
         *	================================================================================
         */
        private void cmbWeekSpan_SelectedValueChanged(object sender, EventArgs e)
        {
            //When initialized disable buttons save, back, and forth.
            if (cmbWeekSpan.Text == "")
            {
                btnSave.Enabled  = false;
                btnBack.Enabled  = false;
                btnForth.Enabled = false;
            }
            else
            {
                btnSave.Enabled  = true;
                btnBack.Enabled  = true;
                btnForth.Enabled = true;

                //Disable forth
                DateTime cmbDate   = WorkWeek.LastBeginningOfWeek(currentWorkWeek.Week);                        //Date we are in
                DateTime cmbMonday = WorkWeek.LastBeginningOfWeek(cmbDate.ToString());

                DateTime date = UtilDotNET.StringToDate(WorkWeek.ConvertWeekSpanToBeginningOfWeek(cmbWeekSpan.Text));                   //Date we want to go to (because it change)
                //MessageBox.Show(cmbMonday + " " + date);
                //Only execute on different date selections
                if (cmbMonday != date)
                {
                    //Load corresponding week
                    int currentIndex = cmbWeekSpan.Items.IndexOf(cmbWeekSpan.Text);
                    currentWorkWeek = employeeWorkWeekList[currentIndex];
                    Display(currentWorkWeek);
                }
            }
        }
Пример #2
0
        //Update changes in cells
        //Split the string array first, before putting them in cells
        private void Display(WorkWeek workWeek)
        {
            Type type = typeof(WorkWeek);

            //Initialize grid Search for all text boxes
            for (int i = 0; i < allCells.Count(); i++)
            {
                //Reflection; get field inside employee of name stem
                PropertyInfo property = type.GetProperty(allCells[i].Name.Substring(6));                   //Calling property of name

                if (property != null && property.GetValue(workWeek, null).ToString().Trim() != String.Empty)
                {
                    string[] cellParse       = ParseCellName(allCells[i].Name);
                    string[] tempPropertyArr = (string[])property.GetValue(workWeek, null);

                    //Assign row values to grid - property based on column
                    grid[(int)WorkWeek.daysDict[cellParse[1]]][(int)WorkWeek.recsDict[cellParse[2]]] = tempPropertyArr[(int)WorkWeek.daysDict[cellParse[1]]];
                    allCells[i].Text = grid[(int)WorkWeek.daysDict[cellParse[1]]][(int)WorkWeek.recsDict[cellParse[2]]];

                    //Check for dummies and apply format to them
                    CheckForDummies((TextBox)allCells[i]);
                }
            }

            //Upgrade grid
            //UpdateGrid();

            //Display Hours
            double hrs = CalculateHours();

            lblTotal.Text = Math.Round(hrs, 1).ToString();
        }
Пример #3
0
        /*
         * Open and Save events
         */
        //Display current week of data
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (txtFirstName.Text != "" || txtLastName.Text != "")
            {
                //Update for autocompletion...
                employeeWorkWeekList = TimeSheetDatabase.GetAllWorkWeekForSingleEmployee(txtFirstName.Text, txtLastName.Text);

                //Exit on empty list
                if (employeeWorkWeekList.Count == 0)
                {
                    return;
                }

                currentWorkWeek = WorkWeek.GetCurrentWorkWeek(employeeWorkWeekList);

                //Split the string array first, before putting them in cells
                Display(currentWorkWeek);
                UpdateWeekComboBox(currentWorkWeek);

                //Display Hours
                double hrs = CalculateHours();
                lblTotal.Text = Math.Round(hrs, 3).ToString();

                //Feedback
                MessageBox.Show(string.Format("WorkWeek for employee:\n{0} {1}.", currentWorkWeek.FirstName.Trim(), currentWorkWeek.LastName.Trim()));
            }
            else
            {
                MessageBox.Show("Missing data! Please enter employee's first and last name.");
            }
        }
Пример #4
0
 //After work week modification, and change selected item
 private void UpdateWeekComboBox(WorkWeek workWeek)
 {
     //Set combo box for weeks
     cmbWeekSpan.Items.Clear();
     for (int i = 0; i < employeeWorkWeekList.Count; i++)
     {
         cmbWeekSpan.Items.Add(WorkWeek.DateToWeekSpan(employeeWorkWeekList[i].Week));                           //Call convert date before entering val
     }
     cmbWeekSpan.SelectedItem = cmbWeekSpan.Items[employeeWorkWeekList.IndexOf(workWeek)];
 }
Пример #5
0
        /*	==================================================================
         *	btnForth_click event
         *	*****************************************************************
         *	Description: Creates a new WorkWeek, only 1 above current date
         *	Notes:
         *	1. Create new WorkWeek with EmployeeID, FirstName, LastName,
         *	empty data cells (like when in EmployeeForm).
         *	2. Set Week to be +7 days from current date.
         *	3. Display (includes add to weekspan combobox)
         *	4. Only 1 week above current date allowed.
         *
         *	==================================================================
         */
        private void btnForth_Click(object sender, EventArgs e)
        {
            //Prevent logic error - user changes names but does not click 'open records'
            if (CheckValidTransition())
            {
                //Correct the error - user change dropdown list selection but did not open
                txtFirstName.Text = currentWorkWeek.FirstName;
                txtLastName.Text  = currentWorkWeek.LastName;
            }
            else
            {
                return;
            }


            //Move to next workWeek when not in last week
            int index = employeeWorkWeekList.IndexOf(currentWorkWeek);

            if (index == (employeeWorkWeekList.Count - 1))                                              //Last item
            {
                //Add new WorkWeek to table TimeSheet, with Week +7 of current week ()
                //--Update timesheet table with new employee - name and employee id, the rest of the fields empty
                DateTime dateNextWeek;
                if (DateTime.TryParse(currentWorkWeek.Week, out dateNextWeek))
                {
                    dateNextWeek = dateNextWeek.AddDays(7);
                }

                //Add to timesheet table
                TimeSheetDatabase.AddWeekWork(currentWorkWeek.EmployeeID.ToString(), currentWorkWeek.FirstName, currentWorkWeek.LastName, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.ellipsisDummy, WorkWeek.dashDummy, WorkWeek.dashDummy, dateNextWeek.ToString());

                //Update employee WorkWeek list, and set currentWorkWeek
                employeeWorkWeekList = TimeSheetDatabase.GetAllWorkWeekForSingleEmployee(txtFirstName.Text, txtLastName.Text);
                currentWorkWeek      = employeeWorkWeekList.Last();
                //MessageBox.Show(currentWorkWeek.Week.ToString());

                //Display
                UpdateWeekComboBox(currentWorkWeek);
                Display(currentWorkWeek);

                //Display Hours
                double hrs = CalculateHours();
                lblTotal.Text = Math.Round(hrs, 1).ToString();

                //Feedback
                MessageBox.Show(string.Format("Added new Time Sheet for employee {0} {1}", currentWorkWeek.FirstName, currentWorkWeek.LastName));
            }
            else
            {
                //Change combobox
                cmbWeekSpan.SelectedItem = cmbWeekSpan.Items[index + 1];
            }
        }
Пример #6
0
        //Read from table Timsheet first workweek of employee's: only need FirstName and LastName
        public static List <WorkWeek> GetAllWorkWeekForSingleEmployee(string firstName, string lastName)
        {
            string           searchStatement = "SELECT * FROM TIMESHEET WHERE FirstName = @firstName AND LastName = @lastName ORDER BY TableID";
            SQLiteConnection conn            = GetConnectionTimeSheet();
            SQLiteCommand    cmd             = new SQLiteCommand(searchStatement, conn);

            //Fill in the command parameters
            cmd.Parameters.AddWithValue("@firstName", firstName);
            cmd.Parameters.AddWithValue("@lastName", lastName);

            List <WorkWeek> workWeekList = new List <WorkWeek>();

            //Try to execute
            try
            {
                conn.Open();
                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    WorkWeek workWeek = new WorkWeek();

                    workWeek.TableID    = int.Parse(reader["TableID"].ToString());
                    workWeek.EmployeeID = reader["EmployeeID"].ToString().Trim();
                    workWeek.FirstName  = reader["FirstName"].ToString().Trim();
                    workWeek.LastName   = reader["LastName"].ToString().Trim();

                    workWeek.PunchIn  = reader["PunchIn"].ToString().Split();                   //Split
                    workWeek.PunchOut = reader["PunchOut"].ToString().Split();
                    workWeek.LunchIn  = reader["LunchIn"].ToString().Split();
                    workWeek.LunchOut = reader["LunchOut"].ToString().Split();
                    workWeek.Reason   = reader["Reason"].ToString().Split();
                    workWeek.Assoc    = reader["Assoc"].ToString().Split();
                    workWeek.Admin    = reader["Admin"].ToString().Split();

                    workWeek.Week = reader["Week"].ToString().Trim();

                    workWeekList.Add(workWeek);
                }
            }
            catch (SQLiteException exception) { throw exception; }
            finally { conn.Close(); }
            return(workWeekList);
        }
Пример #7
0
        //Get all employees work in terms of weeks
        public static List <WorkWeek> GetAllTimeSheet()
        {
            List <WorkWeek>  workWeekList = new List <WorkWeek>();
            string           statement    = "SELECT * FROM TIMESHEET ORDER BY TableID";
            SQLiteConnection conn         = GetConnectionTimeSheet();
            SQLiteCommand    cmd          = new SQLiteCommand(statement, conn);

            //Try to read
            try
            {
                conn.Open();
                SQLiteDataReader reader = cmd.ExecuteReader();         //Read from SQLite with SQLiteDataReader
                while (reader.Read())
                {
                    WorkWeek workWeek = new WorkWeek();

                    //Initialize properties
                    workWeek.TableID    = (int)reader["TableID"];
                    workWeek.EmployeeID = reader["EmployeeID"].ToString().Trim();
                    workWeek.FirstName  = reader["FirstName"].ToString().Trim();
                    workWeek.LastName   = reader["LastName"].ToString().Trim();

                    workWeek.PunchIn  = reader["PunchIn"].ToString().Split();
                    workWeek.PunchOut = reader["PunchOut"].ToString().Split();
                    workWeek.LunchIn  = reader["LunchIn"].ToString().Split();
                    workWeek.LunchOut = reader["LunchOut"].ToString().Split();
                    workWeek.Reason   = reader["Reason"].ToString().Split();
                    workWeek.Assoc    = reader["Assoc"].ToString().Split();
                    workWeek.Admin    = reader["Admin"].ToString().Split();

                    workWeek.Week = reader["Week"].ToString().Trim();

                    //Add to list
                    workWeekList.Add(workWeek);
                }

                reader.Close();
            }
            catch (Exception exception) { throw exception; }
            finally { conn.Close(); }

            return(workWeekList);
        }
Пример #8
0
        public TimeSheetForm()
        {
            InitializeComponent();

            allEmployees = EmployeeDatabase.GetAllEmployees();
            List <Control> tempCells = UtilWinforms.GetAllControlsOfType(this, typeof(TextBox)).ToList();

            foreach (TextBox e in tempCells)
            {
                //By default Cells (grid textboxes) do have null tags
                if (e.Tag == null)
                {
                    allCells.Add(e);

                    //Hint type of cells
                    CheckForDummies(e);

                    //Event handlers assignments
                    e.Click += new EventHandler(cell_Click);
                    e.Leave += new EventHandler(cell_Leave);

                    e.Enter += new EventHandler(cell_Click);

                    //Set autocomplete for all cells
                    e.AutoCompleteMode   = AutoCompleteMode.Suggest;
                    e.AutoCompleteSource = AutoCompleteSource.CustomSource;

                    AutoCompleteStringCollection data = new AutoCompleteStringCollection();
                    data.Add("0700");
                    data.Add("0800");
                    data.Add("0800");
                    data.Add("0900");
                    data.Add("0930");
                    data.Add("1030");
                    data.Add("1100");
                    data.Add("1200");
                    data.Add("1230");
                    data.Add("1400");
                    data.Add("1430");
                    data.Add("1630");
                    data.Add("1700");
                    e.AutoCompleteCustomSource = data;

                    //Parsing cell to gather info
                    WorkWeek.GetIndexes(ref grid);
                }
                else if (e.Tag.ToString() == "Search")
                {
                    allTextBoxControlsSearch.Add(e);
                }
            }
            #region Initialize text boxes with name with autocomplete (reflection)

            //Populate first and last name text boxes autocomplete
            UtilWinforms.UpdateAutoComplete(ref allTextBoxControlsSearch, ref allEmployees);
            #endregion

            //Assign delegate events to all menu items
            foreach (ToolStripMenuItem item in menu.DropDownItems)
            {
                item.Click += new EventHandler(DropDownItemClicked);
            }

            //Event for print page, assigned to linklabel control
            lblPrint.LinkClicked += new LinkLabelLinkClickedEventHandler(lblPrint_LinkClicked);
        }