Exemplo n.º 1
0
 //EmployeeForm - Handles tab and enter key presses for autocomplete purposes
 private void txt_EnterKeyUp(Object obj, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab)
     {
         if (txtFirstName.Text != "" && txtLastName.Text != ""
             )
         {
             //Self auto-complete pattern
             Employee employee = EmployeeDatabase.GetEmployee(txtFirstName.Text, txtLastName.Text);
             //No employee record
             if (employee.EmployeeID == 0)
             {
                 return;
             }
             UtilWinforms.AutoCompleteEmpties(ref allTextBoxControls, employee);
         }
     }
 }
Exemplo n.º 2
0
        List <Control> allTextBoxControls;                               //Have autocomplete

        public EmployeeForm()
        {
            InitializeComponent();

            //AutoComplete
            //-Initializing Controls (TextBox)
            allTextBoxControls = UtilWinforms.GetAllControlsOfType(this, typeof(TextBox)).ToList();

            allEmployees = EmployeeDatabase.GetAllEmployees();                                         //Read table for updates

            //Textbox - Settings
            foreach (TextBox e in allTextBoxControls)
            {
                //Assign events
                e.KeyUp += new KeyEventHandler(txt_EnterKeyUp);

                //Assign a tag to all text boxes in form2
                e.Tag = "Search";
            }

            //Run AutoComplete
            UtilWinforms.UpdateAutoComplete(ref allTextBoxControls, ref allEmployees);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        //Submit button event, add employee, update auto complete, and include employee in timesheet
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //Exit this function if there is any blank text leave out
            if (txtFirstName.Text == "" || txtLastName.Text == "" || txtDepartment.Text == "" || txtPhone.Text == "" || txtEmail.Text == "")
            {
                MessageBox.Show("Missing data; please fill in all fields.");
                return;
            }

            /* ==================================================================
             * Format invariants
             * - Phone: xxx-xxx-xxxx
             * - Department: enum match
             * - Email: _@_.com
             * - Date: MM/dd/yyyy (just tryparse)
             */
            if (!UtilDotNET.IsMatch(UtilDotNET.phonePattern1, txtPhone.Text))
            {
                MessageBox.Show("Error: not a valid phone format.");
                return;
            }


            if (!UtilDotNET.IsMatch(UtilDotNET.emailPattern, txtEmail.Text))
            {
                MessageBox.Show("Error: invalid email format.");
                return;
            }


            if (!UtilDotNET.ValidateDate(txtStartingDate.Text) && txtStartingDate.Text != "")
            {
                MessageBox.Show("Invalid date format");
                return;
            }



            //Exit if employee is already in list
            Employee solicitude = EmployeeDatabase.GetEmployee(txtFirstName.Text, txtLastName.Text);

            if (solicitude == null)
            {
                MessageBox.Show(string.Format("Employee {0} {1} already in records.", solicitude.FirstName, solicitude.LastName));
                return;
            }

            EmployeeDatabase.AddEmployee(txtFirstName.Text, txtLastName.Text, txtDepartment.Text, txtPhone.Text, txtEmail.Text, txtStartingDate.Text);
            //Load all employees
            allEmployees = EmployeeDatabase.GetAllEmployees();

            UtilWinforms.UpdateAutoComplete(ref allTextBoxControls, ref allEmployees);            //Update AutoComplete values

            //Some feedback on add employee
            MessageBox.Show("Added 1 employee to Employee table.");

            //Update timesheet table with new employee - name and employee id, the rest of the fields empty
            Employee employee = EmployeeDatabase.GetEmployee(txtFirstName.Text, txtLastName.Text);

            //Add to timsheet table
            TimeSheetDatabase.AddWeekWork(employee.EmployeeID.ToString(), employee.FirstName, employee.LastName, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.ellipsisDummy, WorkWeek.dashDummy, WorkWeek.dashDummy, employee.StartingDate);

            //Clear out the form
            txtFirstName.Text    = "";
            txtLastName.Text     = "";
            txtDepartment.Text   = "";
            txtPhone.Text        = "";
            txtEmail.Text        = "";
            txtStartingDate.Text = "";

            this.Form2_Load(this, null);                                        //Update listview

            MessageBox.Show("Employee added to timesheet records.\nYou can start now updating employee's work days!");
        }