Пример #1
0
        private void btnCreate_Click(object sender, EventArgs e)



        {
            string rawEmpID       = txtEmpID.Text;
            int    empID          = -1;
            string rawFirstName   = txtFirstName.Text;
            string rawLastName    = txtLastName.Text;
            string rawAddress     = txtAddress.Text;
            string rawPhoneNumber = txtPhoneNumber.Text;
            string rawPosition    = cmbPosition.Text;
            string rawStartDate   = txtStartDate.Text;
            //double conFirstName;
            //double conLastName;
            string userAddress     = txtAddress.Text; //This will store the data once it has enter.
            string userPhoneNumber = txtPhoneNumber.Text;
            //int conPhoneNumber; //store number as numberic.
            string userFirstName = txtFirstName.Text;
            string userLastName  = txtLastName.Text;



            //DataValid Checker
            bool          dataIsValid = true;
            List <string> errorList   = new List <string>();

            //Make sure First Name is not empty
            if (string.IsNullOrEmpty(rawFirstName))
            {
                dataIsValid = false;
                errorList.Add("First Name Can NOT be Empty");
            }
            //Make sure Last Name is not empty
            if (string.IsNullOrEmpty(rawLastName))
            {
                dataIsValid = false;
                errorList.Add("Last Name Can NOT be Empty");
            }

            //Make sure employee ID a positive number and not a letter
            if (string.IsNullOrEmpty(rawEmpID))
            {
                dataIsValid = false;
                errorList.Add("ID Field Can NOT be Empty");
            }
            else if (!int.TryParse(rawEmpID, out empID) || empID < 1)
            {
                dataIsValid = false;
                errorList.Add("Emp ID must be Positive Numbers");
            }

            //Make sure employee ID isn't already taken
            else if (!empIDVerify(empID))
            {
                dataIsValid = false;
                errorList.Add("Employee ID is taken");
            }

            //If all data is valid, we going to add to SQL
            if (dataIsValid)
            {
                int roleCode = getRoleCodeFromPositionName(rawPosition);
                SaveNewEmployee(empID, rawFirstName, rawLastName, 0, 0, roleCode);
            }
            else
            {
                string error = null;
                foreach (string err in errorList)
                {
                    error += "\n" + err;
                }
            }

            this.Hide();
            Employees newEmpoyee = new Employees();

            newEmpoyee.ShowDialog();
        }
Пример #2
0
        private void btnBack_Click(object sender, EventArgs e)
        {
            Employees newAddEmploy = new Employees();

            newAddEmploy.ShowDialog();
        }