示例#1
0
        public List <CustomerInfo> getCustomer(CustomerSeachCriteria _criteria)
        {
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                List <CustomerInfo> ListCustomer = CustomerDataLayer.GetInstance().getCustomer(connection, _criteria);
                return(ListCustomer);
            }
        }
示例#2
0
        public List <CustomerInfo> getCustomer(SqlConnection connection, CustomerSeachCriteria _criteria)
        {
            var result = new List <CustomerInfo>();

            using (var command = new SqlCommand("Select * " +
                                                " from tbl_Customer where  1 = 1 ", connection))
            {
                if (!string.IsNullOrEmpty(_criteria.CustomerID))
                {
                    command.CommandText += " and CustomerID = @CustomerID";
                    AddSqlParameter(command, "@CustomerID", _criteria.CustomerID, System.Data.SqlDbType.Int);
                }
                if (!string.IsNullOrEmpty(_criteria.CustomerCode))
                {
                    command.CommandText += " and CustomerCode = @CustomerCode";
                    AddSqlParameter(command, "@CustomerCode", _criteria.CustomerCode, System.Data.SqlDbType.NVarChar);
                }
                if (!string.IsNullOrEmpty(_criteria.CustomerName))
                {
                    command.CommandText += " and CustomerName like N'%" + _criteria.CustomerName + "%' ";
                }
                command.CommandText += " order by CustomerID  ";
                WriteLogExecutingCommand(command);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var info = new CustomerInfo();
                        info.CustomerID   = GetDbReaderValue <int>(reader["CustomerID"]);
                        info.CustomerCode = GetDbReaderValue <string>(reader["CustomerCode"]);
                        info.CustomerName = GetDbReaderValue <string>(reader["CustomerName"]);
                        info.Address      = GetDbReaderValue <string>(reader["Address"]);
                        info.Phone        = GetDbReaderValue <string>(reader["Phone"]);
                        info.Email        = GetDbReaderValue <string>(reader["Email"]);
                        info.Fax          = GetDbReaderValue <string>(reader["Fax"]);
                        info.TaxCode      = GetDbReaderValue <string>(reader["TaxCode"]);
                        info.BankNumber   = GetDbReaderValue <string>(reader["BankNumber"]);
                        info.BankName     = GetDbReaderValue <string>(reader["BankName"]);
                        info.Surrogate    = GetDbReaderValue <string>(reader["Surrogate"]);
                        info.Position     = GetDbReaderValue <string>(reader["Position"]);
                        info.UserI        = GetDbReaderValue <string>(reader["UserI"]);
                        info.InTime       = GetDbReaderValue <DateTime?>(reader["InTime"]);
                        info.UserU        = GetDbReaderValue <string>(reader["UserU"]);
                        info.UpdateTime   = GetDbReaderValue <DateTime>(reader["UpdateTime"]);
                        result.Add(info);
                    }
                }
                return(result);
            }
        }