本文整理汇总了C#中Tailspin.SimpleSqlRepository.SqlStatement类的典型用法代码示例。如果您正苦于以下问题:C# SqlStatement类的具体用法?C# SqlStatement怎么用?C# SqlStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlStatement类属于Tailspin.SimpleSqlRepository命名空间,在下文中一共展示了SqlStatement类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Insert
public static SqlStatement Insert(Dictionary<string,object> settings)
{
var sql=new SqlStatement("TailspinConnectionString");
StringBuilder sb=new StringBuilder();
sb.Append("INSERT INTO [dbo].[Addresses](");
int indexer=1;
foreach(string key in settings.Keys){
sb.Append(key);
if(indexer<settings.Count)
sb.Append(",");
sql.AddInsertValue(key,settings[key]);
indexer++;
}
sb.AppendLine(")");
sql.Add(sb.ToString());
return sql;
}
开发者ID:JawariSanga,项目名称:Main,代码行数:19,代码来源:SQL1.cs
示例2: Delete
public static SqlStatement Delete()
{
var sql=new SqlStatement("TailspinConnectionString");
sql.Add("DELETE FROM [dbo].[CustomerEvents]");
return sql;
}
开发者ID:JawariSanga,项目名称:Main,代码行数:6,代码来源:SQL1.cs
示例3: Update
public static SqlStatement Update(Dictionary<string,object> settings)
{
var sql=new SqlStatement("TailspinConnectionString");
sql.Add(string.Format("UPDATE {0} SET ","[dbo].[CustomerBehaviors]"));
foreach(string key in settings.Keys){
sql.AddSetting(key,settings[key]);
}
return sql;
}
开发者ID:JawariSanga,项目名称:Main,代码行数:9,代码来源:SQL1.cs
示例4: Select
public static SqlStatement Select(params string[] columns)
{
//for jon galloway
var sql=new SqlStatement("TailspinConnectionString");
StringBuilder sb=new StringBuilder();
sb.Append("SELECT ");
int indexer=1;
foreach(string s in columns){
string qualifiedName=s;
if(QualifiedColumns.ContainsKey(s))
qualifiedName=QualifiedColumns[s];
sb.AppendFormat("{0}",qualifiedName);
if(indexer<columns.Length)
sb.Append(",");
indexer++;
}
sb.AppendFormat("\r\nFROM {0} ",TABLE_NAME);
sb.AppendLine();
sql.Add(sb.ToString());
return sql;
}
开发者ID:JawariSanga,项目名称:Main,代码行数:22,代码来源:SQL1.cs
示例5: Append
public void Append(SqlStatement sql)
{
sqlList.Add(sql);
}
开发者ID:JawariSanga,项目名称:Main,代码行数:4,代码来源:SqlStatement.cs
示例6: RecordExists
public static bool RecordExists( string connStringName,string tableName, Dictionary<string, object> values)
{
var sb = new StringBuilder();
SqlStatement sql = new SqlStatement(connStringName);
sql.Add("SELECT " + values.First().Key);
sql.Add(" FROM " + tableName);
object result = null;
int indexer = 1;
foreach (string s in values.Keys) {
if (indexer == 1) {
sql.Where(s, values[s]);
} else {
sql.And(s, values[s]);
}
indexer++;
}
using (var cmd = sql.BuildCommand()) {
result = cmd.ExecuteScalar();
}
return result != null;
}
开发者ID:JawariSanga,项目名称:Main,代码行数:22,代码来源:SqlStatement.cs
示例7: GetAddressCommand
DbCommand GetAddressCommand(Address address)
{
var sql = new SqlStatement(connectionStringName);
var settings = new Dictionary<string, object>()
{
{AddressesTable.Columns.UserName, address.UserName},
{AddressesTable.Columns.FirstName, address.FirstName},
{AddressesTable.Columns.LastName, address.LastName},
{AddressesTable.Columns.Email, address.Email},
{AddressesTable.Columns.Street1, address.Street1},
{AddressesTable.Columns.Street2, address.Street2 != null ? address.Street2 : ""},
{AddressesTable.Columns.City, address.City},
{AddressesTable.Columns.StateOrProvince, address.StateOrProvince},
{AddressesTable.Columns.Zip, address.Zip},
{AddressesTable.Columns.Country, address.Country},
{AddressesTable.Columns.IsDefault, address.IsDefault}
};
if (SqlHelper.RecordExists(connectionStringName,AddressesTable.TABLE_NAME, new Dictionary<string, object>()
{
{AddressesTable.Columns.UserName,address.UserName},
{AddressesTable.Columns.Street1,address.Street1},
{AddressesTable.Columns.City,address.City},
{AddressesTable.Columns.StateOrProvince,address.StateOrProvince},
}))
{
//update
sql = AddressesTable.Update(settings)
.Where(AddressesTable.Columns.UserName, address.UserName)
.And(AddressesTable.Columns.Street1, address.Street1)
.And(AddressesTable.Columns.City, address.City)
.And(AddressesTable.Columns.StateOrProvince, address.StateOrProvince);
} else {
//insert
sql = AddressesTable.Insert(settings);
}
var cmd = sql.BuildCommand();
//add the params
return cmd;
}
开发者ID:JawariSanga,项目名称:Main,代码行数:44,代码来源:SimpleCustomerRepository.cs
示例8: GetCustomer
public Customer GetCustomer(string userName)
{
var productRepo = new SimpleProductRepository();
Customer result = null;
var batch = new BatchSql();
//see if there's a customer - if not create one
object user = CustomersTable.Select(CustomersTable.Columns.UserName)
.Where(CustomersTable.Columns.UserName, userName)
.BuildCommand()
.ExecuteScalar();
if (user == null) {
CustomersTable.Insert(
new Dictionary<string, object>() {
{CustomersTable.Columns.UserName,userName},
{CustomersTable.Columns.LanguageCode,System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName}
})
.BuildCommand()
.ExecuteNonQuery();
}
//customer
batch.Append(CustomersTable.Select()
.Where(CustomersTable.Columns.UserName, userName));
//addresses
batch.Append(AddressesTable.Select()
.Where(AddressesTable.Columns.UserName, userName));
//shopping cart
Guid orderID = GetCartID(userName);
batch.Append(OrdersTable.Select()
.Where(OrdersTable.Columns.OrderID, orderID));
//items
//avert your eyes if this bothers you
var itemSql = new SqlStatement(connectionStringName);
itemSql.Add(string.Format("SELECT {0}, {1} ", OrderItemsTable.COLUMN_LIST, ProductsTable.COLUMN_LIST));
itemSql.InnerJoin(
OrderItemsTable.TABLE_NAME,
OrderItemsTable.ColumnsQualified.SKU,
ProductsTable.TABLE_NAME,
ProductsTable.ColumnsQualified.SKU)
.Where(OrderItemsTable.Columns.OrderID, orderID);
batch.Append(itemSql);
var cmd = batch.BuildCommand(connectionStringName);
using (var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) {
//customer
if (rdr.Read()) {
result = new Customer(userName,
CustomersTable.ReadEmail(rdr),
CustomersTable.ReadFirst(rdr),
CustomersTable.ReadLast(rdr));
} else {
result = new Customer();
}
//address
result.AddressBook = new List<Address>();
if (rdr.NextResult()) {
while (rdr.Read()) {
result.AddressBook.Add(LoadAddress(rdr));
}
}
//cart
result.Cart = new ShoppingCart(userName);
if (rdr.NextResult()) {
if (rdr.Read()) {
result.Cart.ShippingAddress = result.AddressBook.SingleOrDefault(x => x.AddressID == OrdersTable.ReadShippingAddressID(rdr));
result.Cart.BillingAddress = result.AddressBook.SingleOrDefault(x => x.AddressID == OrdersTable.ReadBillingAddressID(rdr));
result.Cart.ShippingService = OrdersTable.ReadShippingService(rdr) ?? "";
result.Cart.ShippingAmount = OrdersTable.ReadShippingAmount(rdr);
result.Cart.TaxAmount = OrdersTable.ReadTaxAmount(rdr);
}
}
//items
if (rdr.NextResult()) {
while (rdr.Read()) {
var product = productRepo.LoadProduct(rdr);
result.Cart.Items.Add(new ShoppingCartItem(product, CartItemsTable.ReadQuantity(rdr), CartItemsTable.ReadDateAdded(rdr)));
}
}
}
return result;
}
开发者ID:JawariSanga,项目名称:Main,代码行数:91,代码来源:SimpleCustomerRepository.cs
示例9: SaveAddress
public int SaveAddress(Address address)
{
GetAddressCommand(address).ExecuteNonQuery();
var sql = string.Format("SELECT MAX({0}) FROM {1} WHERE {2} = @p0",
AddressesTable.ColumnsQualified.AddressID,
AddressesTable.TABLE_NAME,
AddressesTable.ColumnsQualified.UserName);
var cmd = new SqlStatement(connectionStringName).Add(sql).BuildCommand();
cmd.AddParameter("@p0", address.UserName);
object id = cmd.ExecuteScalar();
return (int)id;
}
开发者ID:JawariSanga,项目名称:Main,代码行数:13,代码来源:SimpleCustomerRepository.cs
示例10: GetOrder
public Order GetOrder(Guid orderID)
{
SimpleProductRepository productRepository = new SimpleProductRepository();
SimpleCustomerRepository customerRepository = new SimpleCustomerRepository();
Order result = null;
var batch = new BatchSql();
batch.Append(OrdersTable.Select().Where("OrderID", orderID));
//items
//products for the items
var sql = new SqlStatement(connectionStringName);
sql.Add("SELECT ");
sql.Add(ProductsTable.COLUMN_LIST);
sql.Add(OrderItemsTable.COLUMN_LIST);
sql.Add("FROM Products INNER JOIN OrderItems ON Products.SKU = OrderItems.SKU");
sql.Add("WHERE SKU IN (SELECT SKU FROM OrderItems WHERE [email protected])");
//transactions
batch.Append(TransactionsTable.Select().Where("orderid", orderID));
int shippingAddressID = 0;
int billingAddressID = 0;
int shippingMethodID=0;
//pull it
var cmd = sql.BuildCommand();
using (var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) {
if (rdr.Read()) {
result = new Order(OrdersTable.ReadOrderStatusID(rdr))
{
DateCreated =OrdersTable.ReadCreatedOn(rdr),
DateShipped = OrdersTable.ReadDateShipped(rdr),
UserName = OrdersTable.ReadUserName(rdr),
DiscountAmount = OrdersTable.ReadDiscountAmount(rdr),
DiscountReason =OrdersTable.ReadDiscountReason(rdr),
EstimatedDelivery = OrdersTable.ReadEstimatedDelivery(rdr),
ID = orderID,
OrderNumber = OrdersTable.ReadOrderNumber(rdr),
ShippingAmount = OrdersTable.ReadShippingAmount(rdr),
ShippingService=OrdersTable.ReadShippingService(rdr),
TaxAmount = OrdersTable.ReadTaxAmount(rdr),
};
billingAddressID = OrdersTable.ReadBillingAddressID(rdr);
shippingAddressID = OrdersTable.ReadShippingAddressID(rdr);
}
//load the items
result.Items = new List<OrderLine>();
if (rdr.NextResult()) {
while (rdr.Read()) {
var product = productRepository.LoadProduct(rdr);
var item = new OrderLine(OrderItemsTable.ReadDateAdded(rdr),OrderItemsTable.ReadQuantity(rdr),product);
result.Items.Add(item);
}
}
//transactions
result.Transactions = new List<Transaction>();
if (rdr.NextResult()) {
while (rdr.Read()) {
Transaction t = new Transaction(
TransactionsTable.ReadTransactionID(rdr),
orderID,
TransactionsTable.ReadAmount(rdr),
TransactionsTable.ReadTransactionDate(rdr),
TransactionsTable.ReadAuthorizationCode(rdr),
TransactionsTable.ReadNotes(rdr),
TransactionsTable.ReadProcessor(rdr));
result.Transactions.Add(t);
}
}
}
sql = new SqlStatement(connectionStringName);
//addresses
batch.Append(AddressesTable.Select().Where("addressid", shippingAddressID));
batch.Append(AddressesTable.Select().Where("addressid", billingAddressID));
//shipping method
batch.Append(ShippingMethodsTable.Select().Where("shippingmethodid", shippingMethodID));
cmd = batch.BuildCommand(connectionStringName);
using (var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) {
//shipping address
if (rdr.Read()) {
//shipping
result.ShippingAddress = customerRepository.LoadAddress(rdr);
//.........这里部分代码省略.........
开发者ID:JawariSanga,项目名称:Main,代码行数:101,代码来源:SimpleOrderRepository.cs
注:本文中的Tailspin.SimpleSqlRepository.SqlStatement类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论