Пример #1
0
        private static int SavePerson(Employee employeeToSave)
        {
            Person tempPerson = new Person();
            tempPerson.PersonId = employeeToSave.PersonId;

            if (employeeToSave.FirstName != null)
            {
                tempPerson.FirstName = employeeToSave.FirstName;
            }
            if (employeeToSave.MiddleName != null)
            {
                tempPerson.MiddleName = employeeToSave.MiddleName;
            }
            if (employeeToSave.LastName != null)
            {
                tempPerson.LastName = employeeToSave.LastName;
            }
            if (employeeToSave.SocialSecurityNumber != null)
            {
                tempPerson.SocialSecurityNumber = employeeToSave.SocialSecurityNumber;
            }
            if (employeeToSave.BirthDate != DateTime.MinValue)
            {
                tempPerson.BirthDate = employeeToSave.BirthDate;
            }

            return PersonBLL.Save(tempPerson);
        }
Пример #2
0
        public static int Save(Employee employeeToSave)
        {
            int personId = SavePerson(employeeToSave);
            employeeToSave.PersonId = personId;

            return EmployeeDAL.Save(employeeToSave);
        }
        private void ProcessFormValues()
        {
            //Create string builder object and then append the string values to that object
            StringBuilder myStringBuilder = new StringBuilder();

            //string variables for the web form controls
            string firstName = txtFirstName.Text;
            string middleName = txtMiddleName.Text;
            string lastName = txtLastName.Text;
            string socialSecurityNum = txtSSN.Text;

            DateTime birthDate = Convert.ToDateTime(txtBirthDate.Text);
            DateTime hireDate = Convert.ToDateTime(txtDateOfHire.Text);
            DateTime termDate = Convert.ToDateTime(txtDateOfTermination.Text);

            string categoryText = DropDownCategory.SelectedItem.Text;
            string tierLevelText = DropDownTierLevel.SelectedItem.Text;
            string laptopText = DropDownLaptop.SelectedItem.Text;
            string background = txtBackground.Text;

            int categoryValue = Convert.ToInt32(DropDownCategory.SelectedValue);
            int tierLevelValue = Convert.ToInt32(DropDownTierLevel.SelectedValue);
            int laptopValue = Convert.ToInt32(DropDownLaptop.SelectedValue);
            int payRate = Convert.ToInt32(txtPayRate.Text);

            //Set Employee Properties
            Employee employeeToSave = new Employee();

            //Person specific properties
            employeeToSave.FirstName = firstName;
            employeeToSave.MiddleName = middleName;
            employeeToSave.LastName = lastName;
            employeeToSave.SocialSecurityNumber = socialSecurityNum;
            employeeToSave.BirthDate = birthDate;

            //Employee Specific Properties
            employeeToSave.HireDate = hireDate;
            employeeToSave.TermDate = termDate;
            employeeToSave.PayRate = payRate;
            employeeToSave.Background = background;

            //Complex properties
            employeeToSave.Category = new EntityType { EntityTypeId = categoryValue };
            employeeToSave.TierLevel = new EntityType { EntityTypeId = tierLevelValue };
            employeeToSave.Laptop = new EntityType { EntityTypeId = laptopValue };

            //Set Id's from hidden fields
            employeeToSave.EmployeeId = Convert.ToInt32(EmployeeId.Value);
            employeeToSave.PersonId = Convert.ToInt32(PersonId.Value);

            //Call BLL to save to database
            int employeeId = EmployeeBLL.Save(employeeToSave);

            //Prints a page message if it is a success
            if (employeeToSave.PersonId > 0 && employeeToSave.EmployeeId > 0)
            {
                this.DisplayLocalMessage("Update was successful.");
            }
            else
            {
                //Insert was successful - redirect back
                Response.Redirect("EmployeeBasic.aspx?EmployeeId=" + employeeId.ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the Game class and fills it with the data from the IDataRecord
        /// </summary>
        /// <param name="myDataRecord"></param>
        /// <returns></returns>
        private static Employee FillDataRecord(IDataRecord myDataRecord)
        {
            Employee myEmployeeObject = new Employee();
            Entity myEntityObject = new Entity();
            EntityType myEntityTypeObject = new EntityType();

            myEmployeeObject.EmployeeId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("employeeId"));
            myEmployeeObject.PersonId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("personId"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("payRate")))
            {
                myEmployeeObject.PersonId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("personId"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("firstName")))
            {
                myEmployeeObject.FirstName = myDataRecord.GetString(myDataRecord.GetOrdinal("firstName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("middleName")))
            {
                myEmployeeObject.MiddleName = myDataRecord.GetString(myDataRecord.GetOrdinal("middleName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("lastName")))
            {
                myEmployeeObject.LastName = myDataRecord.GetString(myDataRecord.GetOrdinal("lastName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("socialSecurityNumber")))
            {
                myEmployeeObject.SocialSecurityNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("socialSecurityNumber"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("payRate")))
            {
                myEmployeeObject.PayRate = myDataRecord.GetInt32(myDataRecord.GetOrdinal("payRate"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("background")))
            {
                myEmployeeObject.Background = myDataRecord.GetString(myDataRecord.GetOrdinal("background"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("driversLicenseNumber")))
            {
                myEmployeeObject.DriversLicenseNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("driversLicenseNumber"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("birthDate")))
            {
                myEmployeeObject.BirthDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("birthDate"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("hireDate")))
            {
                myEmployeeObject.HireDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("hireDate"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("termDate")))
            {
                myEmployeeObject.TermDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("termDate"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("driversLicenceExpireDate")))
            {
                myEmployeeObject.DriversLicenseExpireDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("driversLicenceExpireDate"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Category Entity Id")))
            {
                myEntityTypeObject.Category = myDataRecord.GetInt32(myDataRecord.GetOrdinal("Category Entity Id"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Tier Level Entity Id")))
            {
                myEntityTypeObject.TierLevel = myDataRecord.GetInt32(myDataRecord.GetOrdinal("Tier Level Entity Id"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Laptop Entity Id")))
            {
                myEntityTypeObject.Laptop = myDataRecord.GetInt32(myDataRecord.GetOrdinal("Laptop Entity Id"));
            }
            return myEmployeeObject;
        }
Пример #5
0
        public static int Save(Employee employeeToSave)
        {
            ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;
            int result = 0;

            if (employeeToSave.EmployeeId > 0)
            {
                queryId = ExecuteTypeEnum.UpdateItem;
            }

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_ExecuteEmployee", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", queryId);
                    myCommand.Parameters.AddWithValue("@PersonId", employeeToSave.PersonId);
                    myCommand.Parameters.AddWithValue("@EmployeeId", employeeToSave.EmployeeId);

                    if (employeeToSave.HireDate != DateTime.MinValue)
                    {
                        myCommand.Parameters.AddWithValue("@HireDate", employeeToSave.HireDate);
                    }
                    if (employeeToSave.TermDate != DateTime.MinValue)
                    {
                        myCommand.Parameters.AddWithValue("@TermDate", employeeToSave.TermDate);
                    }
                    if (employeeToSave.PayRate != null)
                    {
                        myCommand.Parameters.AddWithValue("@PayRate", employeeToSave.PayRate);
                    }
                    if (employeeToSave.Background != null)
                    {
                        myCommand.Parameters.AddWithValue("@Background", employeeToSave.Background);
                    }

                    //Complex properties
                    if (employeeToSave.Category != null && employeeToSave.Category.EntityTypeId > 0)
                    {
                        myCommand.Parameters.AddWithValue("@Category", employeeToSave.Category.EntityTypeId);
                    }
                    if (employeeToSave.TierLevel != null && employeeToSave.TierLevel.EntityTypeId > 0)
                    {
                        myCommand.Parameters.AddWithValue("@TierLevel", employeeToSave.TierLevel.EntityTypeId);
                    }
                    if (employeeToSave.Laptop != null && employeeToSave.Laptop.EntityTypeId > 0)
                    {
                        myCommand.Parameters.AddWithValue("@Laptop", employeeToSave.Laptop.EntityTypeId);
                    }

                    //add return output parameter to command object
                    myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("ReturnValue"));

                    myConnection.Open();
                    myCommand.ExecuteNonQuery();

                    //Get return value from stored procedure and return Id
                    result = (int)myCommand.Parameters["@ReturnValue"].Value;
                }
                myConnection.Close();
            }
            return result;
        }
Пример #6
0
        private static void LessonSerialize()
        {
            Employee myEmployee = new Employee("Jesse", "Peterson");
            XmlSerializer serializer = new XmlSerializer(typeof(Employee));

            string xml;

            using (StringWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, myEmployee);
                xml = writer.ToString();
            }

            System.Console.WriteLine(xml);
            System.Console.ReadLine();
        }
Пример #7
0
 private static void LessonInheritance()
 {
     Employee myEmployee = new Employee();
     myEmployee.EmployeeId = 1;
     myEmployee.FirstName = "Bobby";
 }
Пример #8
0
        private static void LessonConstructors()
        {
            string firstName = "";
            string lastName = "";
            Employee myEmployee = new Employee(firstName, lastName);

            Console.WriteLine(myEmployee.DisplayFullName());
            Console.Read();
        }