Exemplo n.º 1
0
        }//End of method

        protected bool DALayer_Delete(string key)
        {
            //Start Error Trapping
            try
            {
                //Use DAL object Factory to get the SQL Server FACTORY Data Access Object
                DALObjectFactoryBase objSQLDAOFactory =
                    DALObjectFactoryBase.GetDataSourceDAOFactory(DALObjectFactoryBase.SQLSERVER);
                //now that you have the sql FACTORY data access object
                //call the correct Data Access Object to perform the Data Access
                CreditCardDAO objCreditCardDAO = objSQLDAOFactory.GetCreditCardDAO();
                //call the CreditCardDAO Data Access Object to do the work
                bool deleted = objCreditCardDAO.Delete(key);
                //Test if delete to database was successful & MARK the object as NEW since
                //deleted from database and NEW in memory and return a true, otherwise return false
                if (deleted == true)
                {
                    //Returns a true since this class object has been deleted & marked as NEW.
                    return(true);
                }
                else
                {
                    //No record deleted, return a false
                    return(false);
                }
            }//End of try
             //Traps for general exception.
            catch (Exception objE)
            {
                //Re-Throw an general exceptions
                throw new Exception("Unexpected Error in DALayer_Update() Method: {0} " + objE.Message);
            }
        }//End of method
Exemplo n.º 2
0
 protected bool DALayer_Load(string key)
 {
     //Start Error Trapping
     try
     {
         //Use DAL object Factory to get the SQL Server FACTORY Data Access Object
         DALObjectFactoryBase objSQLDAOFactory =
             DALObjectFactoryBase.GetDataSourceDAOFactory(DALObjectFactoryBase.SQLSERVER);
         //now that you have the sql FACTORY data access object
         //call the correct Data Access Object to perform the Data Access
         CreditCardDAO objCreditCardDAO = objSQLDAOFactory.GetCreditCardDAO();
         //call the CreditCardDAO Data Access Object to do the work
         CreditCardDTO objCreditCardDTO = objCreditCardDAO.GetRecordByID(key);
         //test if DTO object exists & populate this object with DTO object's properties
         //and return a true or return a False if no DTO object exists.
         if (objCreditCardDTO != null)
         {
             //get the data from the Data Transfer Object
             this.CardNumber    = objCreditCardDTO.CardNumber;
             this.CardOwnerName = objCreditCardDTO.CardOwnerName;
             this.MerchantName  = objCreditCardDTO.MerchantName;
             this.ExpDate       = Convert.ToDateTime(objCreditCardDTO.ExpirationDate);
             this.AddressLines1 = objCreditCardDTO.AddressLine1;
             this.AddressLines2 = objCreditCardDTO.AddressLine2;
             this.City          = objCreditCardDTO.City;
             this.State         = objCreditCardDTO.State;
             this.ZipCode       = objCreditCardDTO.ZipCode;
             this.Country       = objCreditCardDTO.Country;
             this.CreditLimit   = objCreditCardDTO.CreditLimit;
             //this.ActivationStatus = objCreditCardDTO.ActivationStatus;
             //Handle activation status accordingly using methods
             //since ActivationStutus property is read only
             if (objCreditCardDTO.ActivationStatus == true)
             {
                 this.Activate();
             }
             else
             {
                 this.Deactivate();
             }
             //Returns a true since this class object has been populated.
             return(true);
         }
         else
         {
             //No object returned from DALayer, return a false
             return(false);
         }
     }//End of try
      //Traps for general exception.
     catch (Exception objE)
     {
         //Re-Throw an general exceptions
         throw new Exception("Unexpected Error in DALayer_Load(key) Method: {0} " + objE.Message);
     }
 }//End of method
Exemplo n.º 3
0
        }//End of method

        protected bool DALayer_Update()
        {
            //Start Error Trapping
            try
            {
                //Use DAL object Factory to get the SQL Server FACTORY Data Access Object
                DALObjectFactoryBase objSQLDAOFactory =
                    DALObjectFactoryBase.GetDataSourceDAOFactory(DALObjectFactoryBase.SQLSERVER);
                //now that you have the sql FACTORY data access object
                //call the correct Data Access Object to perform the Data Access
                CreditCardDAO objCreditCardDAO = objSQLDAOFactory.GetCreditCardDAO();
                //Create new Data Transfer Object to send to DA Later for DATA ACCESS LAYER
                CreditCardDTO objCreditCardDTO = new CreditCardDTO();
                //POPULATE the Data Transfer Object with data from THIS OBJECT to send to database
                objCreditCardDTO.CardNumber       = this.CardNumber;
                objCreditCardDTO.CardOwnerName    = this.CardOwnerName;
                objCreditCardDTO.MerchantName     = this.MerchantName;
                objCreditCardDTO.ExpirationDate   = this.ExpDate;
                objCreditCardDTO.AddressLine1     = this.AddressLines1;
                objCreditCardDTO.AddressLine2     = this.AddressLines2;
                objCreditCardDTO.City             = this.City;
                objCreditCardDTO.State            = this.State;
                objCreditCardDTO.ZipCode          = this.ZipCode;
                objCreditCardDTO.Country          = this.Country;
                objCreditCardDTO.CreditLimit      = this.CreditLimit;
                objCreditCardDTO.ActivationStatus = this.ActivationStatus;
                //call the CreditCardDAO Data Access Object to do the work
                bool updated = objCreditCardDAO.Update(objCreditCardDTO);
                //test if update to database was successful & MARK the object as old return true,
                //otherwise return false
                if (updated == true)
                {
                    //Returns a true since this class object has been updated.
                    return(true);
                }
                else
                {
                    //No record updated, return a false
                    return(false);
                }
            }//End of try
             //Traps for general exception.
            catch (Exception objE)
            {
                //Re-Throw an general exceptions
                throw new Exception("Unexpected Error in DALayer_Update() Method: {0} " + objE.Message);
            }
        }//End of method
        /// <summary> Retrieves Entity rows in a datatable which match the specified filter. It will always create a new connection to the database.</summary>
        /// <param name="selectFilter">A predicate or predicate expression which should be used as filter for the entities to retrieve.</param>
        /// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return with this retrieval query.</param>
        /// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified, no sorting is applied.</param>
        /// <param name="relations">The set of relations to walk to construct to total query.</param>
        /// <param name="pageNumber">The page number to retrieve.</param>
        /// <param name="pageSize">The page size of the page to retrieve.</param>
        /// <returns>DataTable with the rows requested.</returns>
        public static DataTable GetMultiAsDataTable(IPredicate selectFilter, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, int pageNumber, int pageSize)
        {
            CreditCardDAO dao = DAOFactory.CreateCreditCardDAO();

            return(dao.GetMultiAsDataTable(maxNumberOfItemsToReturn, sortClauses, selectFilter, relations, pageNumber, pageSize));
        }