Ejemplo n.º 1
0
        //Updates Employee's information
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            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;
            }

            EmployeeDatabase.UpdateEmployee(txtFirstName.Text, txtLastName.Text, txtDepartment.Text, txtPhone.Text, txtEmail.Text, txtStartingDate.Text);

            MessageBox.Show(string.Format("Updated: {0} {1}", txtFirstName.Text, txtLastName.Text));

            //Update listview display
            this.Form2_Load(this, null);
        }
Ejemplo n.º 2
0
        //Remove button event
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (txtFirstName.Text == "" || txtLastName.Text == "")
            {
                MessageBox.Show("Missing data; please enter first and last name.");
                return;
            }

            Employee employee = EmployeeDatabase.GetEmployee(txtFirstName.Text, txtLastName.Text);

            if (employee.EmployeeID == 0)
            {
                MessageBox.Show("No employee found with that reference.");
                return;
            }

            EmployeeDatabase.RemoveEmployee(txtFirstName.Text, txtLastName.Text);

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

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

            //Add to timsheet table
            TimeSheetDatabase.RemoveWorkWeekWithName(employee.EmployeeID.ToString(), employee.FirstName);


            //Some more feedback on remove employee
            MessageBox.Show("Removed 1 employee.");
        }
Ejemplo n.º 3
0
        //Some housekeeping and updates
        private void Form1_Load(object sender, EventArgs e)
        {
            //Select mouse to start at txtName
            txtFirstName.Select();

            cmbEmployeeList.Items.Clear();
            allEmployees = EmployeeDatabase.GetAllEmployees();                                                  //When exit EmployeeList, load Timesheet form, and check list again
            //Populate drop down list for combobox with all employees
            for (int i = 0; i < allEmployees.Count; i++)
            {
                cmbEmployeeList.Items.Add(allEmployees[i].FirstName.Trim() + " " + allEmployees[i].LastName);
            }
        }
Ejemplo n.º 4
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);
         }
     }
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        //Updates ListView
        private void Form2_Load(object sender, EventArgs e)
        {
            listView1.Items.Clear();                                //Refresh
            try
            {
                //Load all employees
                allEmployees = EmployeeDatabase.GetAllEmployees();

                if (allEmployees.Count > 0)
                {
                    Employee employee;                              //Temp
                    for (int i = 0; i < allEmployees.Count; i++)
                    {
                        employee = allEmployees[i];

                        //Add this employee number to the list of items in view; (primary key)
                        listView1.Items.Add(employee.EmployeeID.ToString());

                        //Add also its columns
                        listView1.Items[i].SubItems.Add(employee.FirstName);
                        listView1.Items[i].SubItems.Add(employee.LastName);
                        listView1.Items[i].SubItems.Add(employee.Department);
                        listView1.Items[i].SubItems.Add(employee.Phone);
                        listView1.Items[i].SubItems.Add(employee.Email);
                        listView1.Items[i].SubItems.Add(employee.StartingDate);
                    }
                }
                else
                {
                    MessageBox.Show("No employee found.", "Alert");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, exception.GetType().ToString());
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        //Form layout
        public ScheduleForm()
        {
            allEmployees = EmployeeDatabase.GetAllEmployees();

            #region table layout calculations
            TableLayoutPanel table = new TableLayoutPanel();
            table.SuspendLayout();

            table.Location        = new Point(40, 140);
            table.Size            = new Size(800, 300);
            table.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;


            //Creating cells - TextBoxes
            TOTAL_ROWS = EmployeeDatabase.GetTotalEmployees();                  //Get total number of employees - rows
            for (int i = 0; i < TOTAL_ROWS; i++)
            {
                table.RowStyles.Add(new RowStyle(SizeType.Percent, 50.0f));
                for (int j = 0; j < TOTAL_COLS + 1; j++)
                {
                    table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50.0f));

                    table.Controls.Add(new TextBox()
                    {
                        Dock   = DockStyle.Fill,
                        Anchor = AnchorStyles.Top | AnchorStyles.Left,
                        Font   = new Font("Arial", 12, FontStyle.Regular),
                        Name   = string.Format("{0},{1}", j, i)
                    },
                                       j, i);

                    //Setting specific textboxes
                    Control c = table.GetControlFromPosition(j, i);
                    if (j == 0)
                    {
                        if (i > 0 && allEmployees[i] != null)
                        {
                            c.Text = allEmployees[i].FirstName + " " + allEmployees[i].LastName;

                            //Change column width only if text is greater that last greater text
                            int newTextSize = TextRenderer.MeasureText(c.Text, c.Font).Width - 70;
                            if (newTextSize > oldTextSize)
                            {
                                table.ColumnStyles[0].Width = newTextSize;
                                oldTextSize = newTextSize;
                            }
                        }
                        else
                        {
                            c.Text = "Employee";
                        }
                    }
                    else if (j > 0 && i == 0)                                   //Days Labels
                    {
                        c.Text = (Day)(j - 1) + "";
                    }
                }
            }

            table.ResumeLayout();
            table.Show();

            this.Controls.Add(table);
            #endregion


            #region Print linklabel control
            LinkLabel printPage = new LinkLabel();
            printPage.Text = "Print";
            printPage.Font = new Font("Arial", 10, FontStyle.Regular);

            printPage.Location = new Point(table.Bounds.Right - 50, 20);
            printPage.Bounds   = new Rectangle(printPage.Location,
                                               new Size(50, 20));

            //Assign event print
            printPage.LinkClicked += new LinkLabelLinkClickedEventHandler(lnkPrint_LinkClicked);

            this.Controls.Add(printPage);
            #endregion
        }
Ejemplo n.º 9
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!");
        }