コード例 #1
0
ファイル: AddressDA.cs プロジェクト: willdarwin/tta
        public List <AddressBE> GetAllAddresses()
        {
            List <AddressBE> list = new List <AddressBE>();

            dataAcess.Open();
            try
            {
                string      sql    = "select * from Address";
                IDataReader reader = dataAcess.GetReader(sql);
                while (reader.Read())
                {
                    AddressBE address = new AddressBE();
                    address.AddressId     = reader.GetInt32(0);
                    address.Country       = reader.GetString(1);
                    address.Province      = reader.GetString(2);
                    address.DetailAddress = reader.GetString(3);
                    list.Add(address);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                dataAcess.Close();
            }
            return(list);
        }
コード例 #2
0
ファイル: AddressDA.cs プロジェクト: willdarwin/tta
 public AddressBE Insert(AddressBE address)
 {
     dataAcess.Open();
     try
     {
         QueryParameter[] list = new QueryParameter[4];
         list[0] = new QueryParameter("AddressId", address.AddressId, DbType.Int32);
         list[1] = new QueryParameter("Country", address.Country, DbType.String);
         list[2] = new QueryParameter("Province", address.Province, DbType.String);
         list[3] = new QueryParameter("Address", address.DetailAddress, DbType.String);
         string sql = "insert into Address(AddressId, Country, Province, Address) OUTPUT inserted.AddressId values(@AddressId,@Country,@Province,@Address)";
         address.AddressId = Convert.ToInt32(dataAcess.ExecuteScalar(sql, list));
     }
     catch (Exception e)
     {
         //创建日志记录组件实例
         ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
         //记录错误日志
         log.Error("error", e);
     }
     finally
     {
         dataAcess.Close();
     }
     return(address);
 }
コード例 #3
0
ファイル: AddressDA.cs プロジェクト: willdarwin/tta
        public AddressBE GetById(int id)
        {
            AddressBE address = new AddressBE();

            dataAcess.Open();
            try
            {
                string         sql    = "select * from Address where AddressId=@AddressId";
                QueryParameter p      = new QueryParameter("AddressId", id, DbType.Int32);
                IDataReader    reader = dataAcess.GetReader(sql, p);
                while (reader.Read())
                {
                    address.AddressId = id;
                    address.Country   = reader.GetString(1);
                }
            }
            catch (Exception e)
            {
                //创建日志记录组件实例
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                //记录错误日志
                log.Error("error", e);
            }
            finally
            {
                dataAcess.Close();
            }
            return(address);
        }
コード例 #4
0
ファイル: CustomerDA.cs プロジェクト: willdarwin/tta
        public List <CustomerBE> GetAllCustomers()
        {
            List <CustomerBE> list = new List <CustomerBE>();

            _mDataAcess.Open();
            try
            {
                string      sql    = "select * from Customer";
                IDataReader reader = _mDataAcess.GetReader(sql);
                while (reader.Read())
                {
                    CustomerBE customer = new CustomerBE();
                    customer.CustomerId     = reader.GetInt32(0);
                    customer.CustomerName   = reader.GetString(1);
                    customer.CustomerGender = reader.GetBoolean(2);
                    int       addressId = reader.GetInt32(3);
                    AddressBE address   = (new AddressDA()).GetById(addressId);
                    customer.Address = address;
                    list.Add(customer);
                }
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", e);
            }
            finally
            {
                _mDataAcess.Close();
            }
            return(list);
        }
コード例 #5
0
ファイル: CustomerDA.cs プロジェクト: willdarwin/tta
        public CustomerBE GetById(int id)
        {
            CustomerBE customer = new CustomerBE();

            _mDataAcess.Open();
            try
            {
                string         sql    = "select * from Customer where CustomerId=@CustomerId";
                QueryParameter p      = new QueryParameter(Id, id, DbType.Int32);
                IDataReader    reader = _mDataAcess.GetReader(sql, p);
                while (reader.Read())
                {
                    customer.CustomerId     = id;
                    customer.CustomerName   = reader.GetString(1);
                    customer.CustomerGender = reader.GetBoolean(2);
                    int       addressId = reader.GetInt32(3);
                    AddressBE address   = _mAddressDA.GetById(addressId);
                    customer.Address = address;
                }
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", e);
            }
            finally
            {
                _mDataAcess.Close();
            }
            return(customer);
        }
コード例 #6
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Proxy  service = new Proxy();
            string id      = this.labId.Text;

            string     name      = this.txCustomerName.Text.ToString().Trim();
            int        genderInt = Convert.ToInt32(this.rblGender.SelectedValue);
            bool       gender    = genderInt == 1 ? true : false;
            int        addressId = Convert.ToInt32(this.dropListAddresses.SelectedValue);
            CustomerBE customer  = new CustomerBE();

            customer.CustomerName   = name;
            customer.CustomerGender = gender;
            AddressBE address = new AddressBE();

            address.AddressId     = addressId;
            address.City          = "City";
            address.Country       = "Country";
            address.DetailAddress = "Detail";
            address.Province      = "Province";
            customer.Address      = address;

            if (id != "")
            {
                customer.CustomerId = Convert.ToInt32(id);
                service.UpdateCustomer(customer);
            }
            else
            {
                service.InsertCustomer(customer);
            }
            Response.Redirect("CustomerList.aspx");
        }
コード例 #7
0
        /// <summary>
        /// Inserts the customer.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="gender">if set to <c>true</c> [gender].</param>
        /// <param name="addressId">The address id.</param>
        public void InsertCustomer()
        {
            CustomerBE customer = new CustomerBE();

            customer.CustomerName   = View.CustomerName;
            customer.CustomerGender = View.CustomerGender;
            AddressBE address = new AddressBE();

            address.AddressId     = View.CustomerAddressId;
            address.City          = "City";
            address.Country       = "Country";
            address.DetailAddress = "Detail";
            address.Province      = "Province";
            customer.Address      = address;
            _controller.InsertCustomer(customer);
        }
コード例 #8
0
ファイル: AddressDA.cs プロジェクト: willdarwin/tta
        public bool Update(AddressBE address)
        {
            bool result = true;

            dataAcess.Open();
            try
            {
                string           sql  = "update Address set Country=@Country, Province=@Province, Address=@Address where AddressId=@AddressId";
                QueryParameter[] list = new QueryParameter[4];

                list[0] = new QueryParameter("Country", address.Country, DbType.String);
                list[1] = new QueryParameter("Province", address.Province, DbType.String);
                list[2] = new QueryParameter("Address", address.DetailAddress, DbType.String);
                list[3] = new QueryParameter("AddressId", address.AddressId, DbType.Int32);
                int i = dataAcess.ExecuteNonQuery(sql, list);
                if (i == 0)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (Exception e)
            {
                //创建日志记录组件实例
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                //记录错误日志
                log.Error("error", e);
            }
            finally
            {
                dataAcess.Close();
            }
            return(result);
        }