コード例 #1
0
ファイル: CustomerDB.cs プロジェクト: helo12/Lab6
        } //end of Retrieve()

        public object RetrieveAll(Type type)
        {
            List <CustomerProp> list   = new List <CustomerProp>();
            DBDataReader        reader = null;
            CustomerProp        props;

            try
            {
                reader = RunProcedure("usp_CustomerSelectAll");
                if (!reader.IsClosed)
                {
                    while (reader.Read())
                    {
                        props = new CustomerProp();
                        props.SetState(reader);
                        list.Add(props);
                    }
                }
                return(list);
            }
            catch (Exception e)
            {
                // log this exception
                throw;
            }
            finally
            {
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
            }
        }//end of retrieve all
コード例 #2
0
        public void TestSetState()
        {
            string xml = p.GetState();

            p1.SetState(xml);

            Assert.True(xml == p1.GetState());
        }
コード例 #3
0
ファイル: CustomerDB.cs プロジェクト: helo12/Lab6
        public IBaseProps Retrieve(Object key)
        {
            DBDataReader data    = null;
            CustomerProp props   = new CustomerProp();
            DBCommand    command = new DBCommand();

            command.CommandText = "usp_CustomersSelect";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@CustomerID", SqlDbType.Int);
            command.Parameters["@CustomerID"].Value = (Int32)key;

            try
            {
                data = RunProcedure(command);
                if (!data.IsClosed)
                {
                    if (data.Read())
                    {
                        props.SetState(data);
                    }
                    else
                    {
                        throw new Exception("Record does not exist in the database.");
                    }
                }
                return(props);
            }
            catch (Exception e)
            {
                // log this exception
                throw;
            }
            finally
            {
                if (data != null)
                {
                    if (!data.IsClosed)
                    {
                        data.Close();
                    }
                }
            }
        } //end of Retrieve()