コード例 #1
0
    /// <summary>
    /// This event function runs when the add user button is pressed on the UI screen. It collects the data the user has inputted into the fields
    /// and then creates an SQL statement from that data. It then checks if the user already exitst and then runs the SQL function to
    /// add it to the database.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void addMemberSubmitButton_Click(object sender, EventArgs e)
    {
        //Get all employee details
        string firstName = firstNameTextBox.Text;
        string lastName  = lastNameTextBox.Text;
        string DOB       = dateOfBirthTextBox.Text;
        string salary    = salaryTextBox.Text;
        string gender    = genderDDL.Text;

        //Create the appropriate SQL statements
        string sqlInsert          = createInsertString(firstName, lastName, DOB, salary, gender);
        string selectString       = createSelectString(firstName, lastName);
        bool   doesEmployeeExists = SQLAdapter.checkIfRecordExists(selectString);

        //If employee already exists in our database let user know
        if (doesEmployeeExists)
        {
            ((Label)Master.FindControl("validationLablel")).Text = "This user already exists in our Database";
        }
        else
        {
            try
            {
                //Try insert data into the database and provide a message to let the user know
                SQLAdapter.ChangeDBData(sqlInsert);
                ((Label)Master.FindControl("validationLablel")).Text = "Member added successfully";
                UpdateMembershipClass.updateMembershipClass();
                firstNameTextBox.Text   = "";
                lastNameTextBox.Text    = "";
                dateOfBirthTextBox.Text = "";
                salaryTextBox.Text      = "";
                genderDDL.Text          = "";
            }
            catch (SqlException ex)
            {
                ((Label)Master.FindControl("validationLablel")).Text = ex.Errors.ToString();
            }
            catch (Exception)
            {
                ((Label)Master.FindControl("validationLablel")).Text = "An Unexpected error has occured adding a member";
            }
            finally
            {
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// Will migrate 500 employees to our database.
    /// </summary>
    public static void readEmployee()
    {
        //Read all the lines from the salaries file
        string[] allLinesSalaries = File.ReadAllLines(HttpContext.Current.Server.MapPath("~/App_Data/salaries.csv"));
        //Split the data and save it to a variable
        var salaries = from line in allLinesSalaries
                       let data = line.Split('|')
                                  select data;

        //Read all the values from the employees file
        string[] allLinesEmployee = File.ReadAllLines(HttpContext.Current.Server.MapPath("~/App_Data/employees.csv"));
        //Split that data and save it in a variable
        var employees = from line in allLinesEmployee
                        let data = line.Split('|')
                                   select data;

        //For the first 500 members in the employees file get the trimmed data and insert it into the database
        for (int i = 1; i <= 500; i++)
        {
            char[]   charToTrim = { '\\', '\"' };
            string[] emp        = employees.ElementAt(i);
            string   id         = emp[ID];
            string   dob        = emp[DOB].Trim(charToTrim);
            string   firstName  = emp[Fname].Trim(charToTrim);
            string   lastName   = emp[Lname].Trim(charToTrim);
            string   gender     = emp[Gender].Trim(charToTrim);
            if (gender == "M")
            {
                gender = "Male";
            }
            if (gender == "F")
            {
                gender = "Female";
            }
            string dateJoined = emp[DateJoined].Trim(charToTrim);
            string salary     = getSalaryForID(id, allLinesSalaries);
            string sqlInsert  = createInsertString(firstName, lastName, dob, salary, gender, dateJoined);
            SQLAdapter.ChangeDBData(sqlInsert);
        }
    }
コード例 #3
0
    /// <summary>
    /// Run the migration of 500 emplopyees
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //protected void migrate(object sender, EventArgs e)
    //{
    //    //First Add the first 500 employee
    //    csv.readEmployee();

    //}

    /// <summary>
    /// This will update the membership details for every employee. Only used when initially migrating the 500 employees
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //protected void test(object sender, EventArgs e)
    //{
    //    UpdateMembershipClass.updateMembershipClass();
    //}

    /// <summary>
    /// Used to migrate members to our databse from engineering db using ID
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void migrate_employee(object sender, EventArgs e)
    {
        string id = memberShipIDTextBox.Text;

        try
        {
            string[] employeeDeatils    = csv.getEmployeebyID(id);
            string   selectString       = createSelectString(employeeDeatils[2], employeeDeatils[3]);
            bool     doesEmployeeExists = SQLAdapter.checkIfRecordExists(selectString);
            //If employee already exists in our database let user know
            if (doesEmployeeExists)
            {
                ((Label)Master.FindControl("validationLablel")).Text = "This user already exists in our Database";
            }
            else
            {
                //Get salary of employee by ID
                string salary = csv.FindSalaryByID(employeeDeatils[0]);
                //Create string to insert
                string sqlInsert = createInsertString(employeeDeatils[2], employeeDeatils[3], employeeDeatils[1], salary, employeeDeatils[4]);
                try
                {
                    SQLAdapter.ChangeDBData(sqlInsert);
                    ((Label)Master.FindControl("validationLablel")).Text = "User successfully added";
                }
                catch (Exception exception)
                {
                    ((Label)Master.FindControl("validationLablel")).Text = exception.Message.ToString();
                }
            }
        }
        catch (ArgumentOutOfRangeException exception)
        {
            ((Label)Master.FindControl("validationLablel")).Text = exception.Message.ToString();
        }
    }