Exemplo n.º 1
0
// <Snippet3>
        // Returns a collection of NorthwindEmployee objects.
        public static ICollection GetAllEmployees()
        {
            ArrayList al = new ArrayList();

            ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];

            SqlDataSource sds
                = new SqlDataSource(cts.ConnectionString, "SELECT EmployeeID FROM Employees");

            try {
                IEnumerable IDs = sds.Select(DataSourceSelectArguments.Empty);

                // Iterate through the Enumeration and create a
                // NorthwindEmployee object for each ID.
                foreach (DataRowView row in IDs)
                {
                    string            id  = row["EmployeeID"].ToString();
                    NorthwindEmployee nwe = new NorthwindEmployee(id);
                    // Add the NorthwindEmployee object to the collection.
                    al.Add(nwe);
                }
            }
            finally {
                // If anything strange happens, clean up.
                sds.Dispose();
            }

            return(al);
        }
Exemplo n.º 2
0
        // Returns a collection of NorthwindEmployee objects.
        public static ICollection GetAllEmployees()
        {
            ArrayList al = new ArrayList();

            // Use the SqlDataSource class to wrap the
            // ADO.NET code required to query the database.
            ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];

            SqlDataSource sds
                = new SqlDataSource(cts.ConnectionString,
                                    "SELECT EmployeeID FROM Employees");

            try {
                IEnumerable IDs = sds.Select(DataSourceSelectArguments.Empty);

                // Iterate through the Enumeration and create a
                // NorthwindEmployee object for each ID.
                IEnumerator enumerator = IDs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    // The IEnumerable contains DataRowView objects.
                    DataRowView       row = enumerator.Current as DataRowView;
                    int               id  = (int)row["EmployeeID"];
                    NorthwindEmployee nwe = new NorthwindEmployee(id);
                    // Add the NorthwindEmployee object to the collection.
                    al.Add(nwe);
                }
            }
            finally {
                // If anything strange happens, clean up.
                sds.Dispose();
            }

            return(al);
        }
// <snippet3>
        public static void UpdateEmployee(NorthwindEmployee ne)
        {
            bool retval = ne.Update();

            if (!retval)
            {
                throw new NorthwindDataException("Employee update failed.");
            }
        }
Exemplo n.º 4
0
        public static void InsertNewEmployee(NorthwindEmployee ne)
        {
            bool retval = ne.Save();

            if (!retval)
            {
                throw new NorthwindDataException("InsertNewEmployee failed.");
            }
        }
Exemplo n.º 5
0
        public static void DeleteEmployee(NorthwindEmployee ne)
        {
            bool retval = ne.Delete();

            if (!retval)
            {
                throw new NorthwindDataException("DeleteEmployee failed.");
            }
        }
Exemplo n.º 6
0
        public static void DeleteEmployee(NorthwindEmployee ne)
        {
            bool retval = ne.Delete();

            if (!retval)
            {
                throw new NorthwindDataException("Employee delete failed.");
            }
            // Delete the object in memory.
            ne = null;
        }
        // This method is added as a conveniece wrapper on the original
        // implementation.
        public static void UpdateEmployeeWrapper(string anID,
                                                 string anAddress,
                                                 string aCity,
                                                 string aPostalCode)
        {
            NorthwindEmployee ne = new NorthwindEmployee(anID);

            ne.Address    = anAddress;
            ne.City       = aCity;
            ne.PostalCode = aPostalCode;
            UpdateEmployee(ne);
        }
        public static NorthwindEmployee GetEmployee(object anID)
        {
            ArrayList   al         = GetAllEmployees() as ArrayList;
            IEnumerator enumerator = al.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // The IEnumerable contains initialized NorthwindEmployee objects.
                NorthwindEmployee ne = enumerator.Current as NorthwindEmployee;
                if (ne.EmpID.Equals(anID.ToString()))
                {
                    return(ne);
                }
            }
            return(null);
        }
Exemplo n.º 9
0
// <snippet3>
        // This InsertNewEmployeeWrapper method is a wrapper method that enables
        // the use of ObjectDataSource and InsertParameters, without
        // substantially rewriting the true implementation for the NorthwindEmployee
        // or the EmployeeLogic objects.
        //
        // The parameters to the method must be named the same as the
        // DataControlFields used by the GridView or DetailsView controls.
        public static void InsertNewEmployeeWrapper(string FirstName,
                                                    string LastName,
                                                    string Title,
                                                    string Courtesy,
                                                    int Supervisor)
        {
            // Build the NorthwindEmployee object and
            // call the true  implementation.
            NorthwindEmployee tempEmployee = new NorthwindEmployee();

            tempEmployee.FirstName  = FirstName;
            tempEmployee.LastName   = LastName;
            tempEmployee.Title      = Title;
            tempEmployee.Courtesy   = Courtesy;
            tempEmployee.Supervisor = Supervisor;

            // Call the true implementation.
            InsertNewEmployee(tempEmployee);
        }
Exemplo n.º 10
0
        public static void DeleteEmployee(int anID)
        {
            NorthwindEmployee tempEmp = new NorthwindEmployee(anID);

            DeleteEmployee(tempEmp);
        }
Exemplo n.º 11
0
 public static void DeleteEmployee(NorthwindEmployee ne)
 {
 }