Beispiel #1
0
        /*
         * **************************************** My changes STOP here ************************************************
         */

        #endregion



        #region Overrides of BaseObject

        /// <summary>
        /// Maps the Data row to properties
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public override bool MapData(DataRow row)
        {
            try
            {
                this.StudentID      = GetString(row, "StudentId");
                this.Last4SSN       = GetString(row, "Last4SSN");
                this.FirstName      = GetString(row, "FirstName");
                this.LastName       = GetString(row, "LastName");
                this.GraduationDate = GetDateTime(row, "GraduationDate");
                this.GPA            = GetDecimal(row, "GPA");
                this.Email          = GetString(row, "Email");
                this.PhoneCell      = GetString(row, "PhoneCell");
                this.PhoneDay       = GetString(row, "PhoneDay");
                this.PhoneEvening   = GetString(row, "PhoneEvening");
                this.Address        = GetString(row, "Address");
                this.City           = GetString(row, "City");
                this.State          = GetString(row, "State");
                this.Zipcode        = GetString(row, "Zipcode");

                //Load Internship Requirement Object
                this.InternshipRequirement = InternshipRequirement.Load(_studentID);

                //Load Employer Object
                this.Employer = Employer.Load(_studentID);
                return(true);
            }

            catch (Exception ex)
            {
                // throw new System.Exception(ex.Message);
                throw new System.Exception("Exception: '" + ex.Message + "' occured while mapping student data!");
            }
        }
Beispiel #2
0
        public static InternshipRequirement Load(string studentId)
        {
            try
            {
                InternshipRequirementDataService dataService = new InternshipRequirementDataService();
                DataSet ds = dataService.Load(studentId);

                InternshipRequirement objRequirement = new InternshipRequirement();

                return(objRequirement.MapData(ds) ? objRequirement : null);
            } catch
            {
                throw;
            }
        }
Beispiel #3
0
        /*
         * <summary>
         * Search and display student records from Database
         * </summary>
         * <param name="stdID"></param>
         * <returns></returns>
         */



        public void Fetch(String stdID)
        {
            SqlConnection connection = null;
            // SqlCommand command = null;
            //SqlDataReader reader = null;
            String errorMessage = String.Empty;

            // Start Error Trapping
            try
            {
                // Open connection
                connection.Open();

                // Create SQL string
                String strSQL = "SELECT * FROM Students WHERE StudentId=@StudentID";

                // Create Command object, pass query (SQL string) & Add paramters
                SqlCommand command = null;
                command.Parameters.Clear();
                //command.CommandText = strSQL;
                command = new SqlCommand(strSQL, connection);

                command.Parameters.AddWithValue("@StudentID", SqlDbType.VarChar).Value = stdID;

                // Create DATAREADER object & Execute Query
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow);

                // Test to make sure there is data in the DataReader Object
                if (reader.HasRows)
                {
                    // Call Read() Method to point and read the first record
                    reader.Read();

                    // Left side is my program variable and right side is the SQL DB variable
                    // Extract data from a row & Populate Yourself
                    this.StudentID      = reader["StudentId"].ToString();
                    this.Last4SSN       = reader["Last4SSN"].ToString();
                    this.FirstName      = reader["FirstName"].ToString();
                    this.LastName       = reader["LastName"].ToString();
                    this.PhoneCell      = reader["PhoneCell"].ToString();
                    this.PhoneDay       = reader["PhoneDay"].ToString();
                    this.PhoneEvening   = reader["PhoneEvening"].ToString();
                    this.Email          = reader["Email"].ToString();
                    this.Address        = reader["Address"].ToString();
                    this.City           = reader["City"].ToString();
                    this.State          = reader["State"].ToString();
                    this.Zipcode        = reader["Zipcode"].ToString();
                    this.GPA            = System.Convert.ToDecimal(reader["GPA"]);
                    this.GraduationDate = (DateTime)reader["GraduationDate"];
                    // Convert.ToDateTime(reader["GraduationDate"]).ToString("yyyy/MM/dd");

                    /*// Convert from string in "dd-MMM-yyyy" format to DateTime.
                     * DateTime dt = DateTime.ParseExact("20-Oct-2012", "dd-MMM-yyyy", null);
                     *
                     * // Convert from DateTime to string in "yyyy/MM/dd" format.
                     * string str = dt.ToString("yyyy/MM/dd");*/

                    // Enum type conversion. Enum2 value2 = (Enum2) Enum.Parse(typeof(Enum2), value.ToString());
                    // If you mean by numeric value, you can usually just cast: Enum2 value2 = (Enum2)value;
                    this.InternshipRequirement = (InternshipRequirement)Enum.Parse(typeof(InternshipRequirement), InternshipRequirement.ToString());
                    //this.InternshipRequirement = reader["InternshipRequirement"].ToString();

                    this.Employer = (Employer)Enum.Parse(typeof(Employer), Employer.ToString());
                    //this.Employer = reader["Employer"].ToString();


                    /*
                     * You can parse user input like this:
                     * DateTime enteredDate = DateTime.Parse(enteredString);
                     *
                     * If you have a specific format for the string, you should use the other method:
                     * DateTime loadedDate = DateTime.ParseExact(loadedString, "d", null);
                     *
                     */

                    /*
                     * DataTable dt = new DataTable();
                     * dt.Load(dr);
                     * dataGridView1.DataSource = dt;
                     */
                }

                else
                {
                    // No data returned, Record not found!
                    throw new System.Exception("Load Error! Record Not Found!");
                }
                // errorMessage = "Student does not exist.";
            }

            // Trap for Exceptions
            catch (SqlException ex)
            {
                // throw new System.Exception(ex.Message);
                throw new System.Exception("SQL Exception: '" + ex.Message + "' occured while fetching data with StudentID!");
            }

            catch (Exception ex)
            {
                // throw new System.Exception(ex.Message);
                throw new System.Exception("Exception: '" + ex.Message + "' occured while fetching data with StudentID!");
            }

            finally
            {
                // Terminate connection
                connection.Close();
                connection.Dispose();
                connection = null;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Parameterised Constructor
 /// </summary>
 public Student(string studentId, string last4Ssn, string firstname, string lastname, string address, string city, string state, string zipcode,
                string cellphone, string dayphone, string eveningPhone, decimal gpa, string email, DateTime graduationDate, InternshipRequirement intRequirement,
                Employer employer)
 {
     this.StudentID             = studentId;
     this.Last4SSN              = last4Ssn;
     this.FirstName             = firstname;
     this.LastName              = lastname;
     this.Address               = address;
     this.City                  = city;
     this.State                 = state;
     this.Zipcode               = zipcode;
     this.PhoneCell             = cellphone;
     this.PhoneDay              = dayphone;
     this.PhoneEvening          = eveningPhone;
     this.GPA                   = gpa;
     this.Email                 = email;
     this.GraduationDate        = graduationDate;
     this.InternshipRequirement = intRequirement;
     this.Employer              = employer;
 }