本文整理汇总了C#中Collection.AddItem方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.AddItem方法的具体用法?C# Collection.AddItem怎么用?C# Collection.AddItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.AddItem方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeCollection
public override Collection MakeCollection(CollectionRequestContext context)
{
var collection = new Collection();
using (SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=SalesDB;Integrated Security=True;MultipleActiveResultSets=True"))
{
using (SqlCommand command = new SqlCommand("select p.Name Product, r.Name Region, f.Price Price, o.Date Date from Facts f join Orders o on f.OrderId=o.OrderId join Products p on f.ProductId=p.ProductId join Regions r on f.RegionId=r.RegionId", connection))
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string product = reader.GetString(0);
string region = reader.GetString(1);
Decimal price = reader.GetDecimal(2);
DateTime date = reader.GetDateTime(3);
string imagePath = String.Format("http://localhost:1297/ClientBin/Images/{0}.jpg", product);
ItemImage image = new ItemImage(new Uri(imagePath, UriKind.Absolute));
collection.AddItem("", null, "", image, new Facet[] { new Facet("Регион", region), new Facet("Продукт", product), new Facet("Цена", (double)price), new Facet("Дата", date) });
}
}
}
collection.Name = "Sales Collection";
return collection;
}
示例2: MakeCollection
// Public Methods
//======================================================================
public override Collection MakeCollection(CollectionRequestContext context)
{
try
{
var crashes = db.Crashes
.Include(c => c.Light)
.Include(c => c.Weather)
.Include(c => c.CrashLocation)
.Include(c => c.SurfCondition)
.Include(c => c.CrashClass)
.Include(c => c.VehCollision)
.Include(c => c.ObjectStruck)
.Include(c => c.RoadCharacter)
.Include(c => c.ContFactor1)
.Include(c => c.ContFactor2)
.Include(c => c.CrashCategory);
Collection collection = new Collection();
collection.Name = "NPS Crashes";
foreach (var crash in crashes.Take(maxItems))
{
ItemImage image = null;
collection.AddItem(crash.IncidentNo, null, null, image, GetFacets(crash));
}
return collection;
}
catch (Exception ex)
{
return ErrorCollection.FromException(ex);
}
}
示例3: MakeCollection
public static Collection MakeCollection()
{
string folder = @"C:\Users\Public\Pictures\Sample Pictures";
string[] files = Directory.GetFiles(folder);
Collection coll = new Collection();
coll.Name = "Sample Pictures";
bool anyItems = false;
foreach (string path in files)
{
string extension = Path.GetExtension(path);
bool isJpeg = (0 == string.Compare(".jpg", extension, true));
bool isPng = (0 == string.Compare(".png", extension, true));
if (isJpeg || isPng)
{
anyItems = true;
FileInfo info = new FileInfo(path);
coll.AddItem(Path.GetFileNameWithoutExtension(path), path, null,
new ItemImage(path)
, new Facet("File name", Path.GetFileName(path)
, isJpeg ? "*.jpg" : null
, isPng ? "*.png" : null
)
, new Facet("File size", info.Length / 1000)
, new Facet("Creation time", info.CreationTime)
, new Facet("Link:", new FacetHyperlink("click to view image", path))
);
}
}
if (anyItems)
{
coll.SetFacetDisplay("Creation time", false, true, false);
coll.SetFacetFormat("File size", "#,#0 kb");
}
else
{
coll.AddItem("No pictures", null,
string.Format("The folder \"{0}\" does not contain any JPEG or PNG files.", folder),
null);
}
return coll;
}
示例4: FromException
/// <summary>
/// Create a single item collection that displays the error message from an exception.
/// </summary>
public static Collection FromException(Exception ex)
{
Collection collection = new Collection();
collection.Name = "Error";
string title = ex.Message;
string summary = (null == ex.InnerException) ? null : ex.InnerException.Message;
collection.AddItem(title, null, summary, null);
return collection;
}
示例5: WishListItemsInStock
/// <summary>
/// Returns a collection containing the items in a customer's WishList which are currently in stock
/// </summary>
/// <returns>A Collection of items on the customer's WishList which are in stock</returns>
public Collection WishListItemsInStock()
{
Collection itemsInStock = new Collection();
foreach (Item item in wishList)
{
if (DBaccess.IsItemInStock(item) == true)
{
itemsInStock.AddItem(item);
}
}
return itemsInStock;
}
示例6: MakeCollection
// Public Methods
//======================================================================
public override Collection MakeCollection(CollectionRequestContext context)
{
try
{
var crashes = db.Crashes
.Include(c => c.Light)
.Include(c => c.Weather)
.Include(c => c.CrashLocation)
.Include(c => c.SurfCondition)
.Include(c => c.CrashClass)
.Include(c => c.VehCollision)
.Include(c => c.ObjectStruck)
.Include(c => c.RoadCharacter)
.Include(c => c.ContFactor1)
.Include(c => c.ContFactor2)
.Include(c => c.CrashCategory);
Collection collection = new Collection();
collection.Name = "NPS Crashes";
foreach (var crash in crashes.Take(maxItems))
{
string imgFolder = HttpRuntime.BinDirectory.Substring(0, HttpRuntime.BinDirectory.Length - 5);
string imgName = GetImageName(crash.Category);
ItemImage image = null;
if (imgName != null)
{
image = new ItemImage(string.Format(@"{0}\Images\{1}", imgFolder, imgName));
}
collection.AddItem(crash.IncidentNo, null, null, image, GetFacets(crash));
}
// Set facet display properties
collection.SetFacetDisplay("Park Alpha", true, true, true);
collection.SetFacetDisplay("State", true, true, false);
collection.SetFacetDisplay("Crash Year", true, true, false);
collection.SetFacetDisplay("Crash Date", false, true, false);
collection.SetFacetDisplay("Crash Time", false, true, false);
collection.SetFacetDisplay("Route ID", true, true, true);
collection.SetFacetDisplay("Road Name", false, true, true);
collection.SetFacetDisplay("Node Distance (Ft)", false, true, false);
collection.SetFacetDisplay("Node Distance (Mi)", false, true, false);
collection.SetFacetDisplay("Node Direction", false, true, false);
collection.SetFacetDisplay("Node Number", false, true, false);
collection.SetFacetDisplay("Node MP", false, true, false);
collection.SetFacetDisplay("Crash MP", true, true, false);
collection.SetFacetDisplay("Light Condition", true, true, false);
collection.SetFacetDisplay("Weather Condition", true, true, false);
collection.SetFacetDisplay("Crash Location", true, true, false);
collection.SetFacetDisplay("Surface Condition", true, true, false);
collection.SetFacetDisplay("Crash Class", true, true, false);
collection.SetFacetDisplay("Vehicle Collision", true, true, false);
collection.SetFacetDisplay("Fixed Object Struck", true, true, false);
collection.SetFacetDisplay("Road Character", true, true, false);
collection.SetFacetDisplay("Contributing Factor 1", true, true, false);
collection.SetFacetDisplay("Contributing Factor 2", true, true, false);
collection.SetFacetDisplay("Contributing Factor 3", false, true, false);
collection.SetFacetDisplay("Contributing Factor 4", false, true, false);
collection.SetFacetDisplay("Contributing Factor 5", false, true, false);
collection.SetFacetDisplay("Contributing Factor 6", false, true, false);
collection.SetFacetDisplay("Category", true, true, false);
collection.SetFacetDisplay("Hit & Run", false, true, false);
collection.SetFacetDisplay("Fatal", false, true, false);
collection.SetFacetDisplay("Injured", false, true, false);
collection.SetFacetDisplay("Pedestrian Fatal", false, true, false);
collection.SetFacetDisplay("Pedestrian Injured", false, true, false);
collection.SetFacetDisplay("Bikers Fatal", false, true, false);
collection.SetFacetDisplay("Bikers Injured", false, true, false);
collection.SetFacetDisplay("Pedestrian", true, true, false);
collection.SetFacetDisplay("Comments", false, true, true);
collection.SetFacetDisplay("Spatial Location", true, true, false);
//collection.SetFacetDisplay("Case Number", false, true, false);
//collection.SetFacetDisplay("Location", false, true, false);
//collection.SetFacetDisplay("USPP/NPS Veh. Inv.", false, true, false);
//collection.SetFacetDisplay("Park Property Dest.", false, true, false);
//collection.SetFacetDisplay("Data Source", false, true, false);
//collection.SetFacetDisplay("Latitude", false, true, false);
//collection.SetFacetDisplay("Longitude", false, true, false);
//collection.SetFacetDisplay("Save Date", false, true, false);
//collection.SetFacetDisplay("RIP Cycle", false, true, false);
// Set facet formats
//collection.SetFacetFormat("List price", "$#,0.00");
return collection;
}
catch (Exception ex)
{
return ErrorCollection.FromException(ex);
}
}
示例7: SQLTableToCollection
/// <summary>
/// Gets an INVENTORY table and returns a Collection of all contained Items
/// </summary>
/// <param name="tablename">Table name of an INVENTORY type table</param>
/// <param name="sortBy">Column to sort by. (Optional)</param>
/// <param name="ascending">True: Results are sorted (A->Z), False: (Z->A). (Optional)</param>
/// <param name="searchtext">Text to narrow results to items containing this text. (Optional)</param>
/// <returns>A Collection of Items</returns>
public static Collection SQLTableToCollection(string tablename, string sortBy = "System", bool ascending = true, string searchtext = "")
{
Collection collection = new Collection();
Item item;
SearchTerms searchTerms;
// Save sorting order to string "order" (descending/ascending)
string order;
SqlCommand cmd;
if (ascending)
order = "ASC";
else
order = "DESC";
// parameters cannot be null
if (searchtext == null) searchtext = "";
if (sortBy == null) sortBy = "System";
// Check for special characters, then divide searchtext into individual terms
searchtext = CheckForSpecialCharacters(searchtext);
searchTerms = new SearchTerms(searchtext);
if (sortBy != "Name")
{
cmd = new SqlCommand("SELECT * FROM " + tablename +
" WHERE " + searchTerms.GenerateSQLSearchString() +
"ORDER BY " + sortBy + " " + order + ", Name;", connect);
}
else
{
cmd = new SqlCommand("SELECT * FROM " + tablename +
" WHERE " + searchTerms.GenerateSQLSearchString() +
"ORDER BY " + sortBy + " " + order + ";", connect);
}
try
{
connect.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read() == true)
{
item = SQLReaderToItem(reader);
if (item != null)
collection.AddItem(item);
}
}
catch (Exception e)
{
MessageBox.Show("ERROR IN SQLTableToCollection:\n" + e.Message);
}
finally
{
connect.Close();
}
return collection;
}
示例8: GetBestSellingItems
public static Collection GetBestSellingItems(string type, bool ascending = false)
{
Collection collection = new Collection();
string order;
if (ascending) order = "ASC";
else order = "DESC";
string command = "SELECT Name, System, SUM(Quantity) AS Total " +
"FROM " + TableNames.TRANSACTION +
" WHERE (Type = '" + type + "') " +
"GROUP BY Name, System " +
"ORDER BY Total " + order;
SqlCommand cmd = new SqlCommand(command, connect);
try
{
connect.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read() == true)
{
Item item = new Item(reader[0].ToString(), reader[1].ToString(), reader[2].ToString());
collection.AddItem(item);
}
connect.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
connect.Close();
}
return collection;
}
示例9: _30DayHoldToCollection
/// <summary>
/// Gets the 30-Day-Hold table and returns a Collection of all contained Items
/// </summary>
/// <param name="sortBy">Column to sort by. (Optional)</param>
/// <param name="ascending">True: Results are sorted (A->Z), False: (Z->A). (Optional)</param>
/// <param name="searchtext">Text to narrow results to items containing this text. (Optional)</param>
/// <returns>A Collection of Items</returns>
public static Collection _30DayHoldToCollection(string sortBy = "System", bool ascending = true, string searchtext = "")
{
Collection collection = new Collection();
HoldItem item;
SqlCommand cmd;
string tablename = TableNames._30DAYHOLD;
string order;
// Save sorting order to string "order" (descending/ascending)
if (ascending)
order = "ASC";
else
order = "DESC";
searchtext = CheckForSpecialCharacters(searchtext);
if (sortBy != "Name")
{
cmd = new SqlCommand("SELECT * FROM " + tablename +
" WHERE name LIKE \'%" + searchtext + "%\' OR system LIKE \'%" + searchtext + "%\' OR UPC = '" + searchtext + "'" +
" ORDER BY " + sortBy + " " + order + ", NAME;", connect);
}
else
{
cmd = new SqlCommand("SELECT * FROM " + tablename +
" WHERE name LIKE \'%" + searchtext + "%\' OR system LIKE \'%" + searchtext + "%\' " +
"ORDER BY " + sortBy + " " + order + ";", connect);
}
try
{
connect.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read() == true)
{
item = SQLReaderToHoldItem(reader);
if (item != null)
collection.AddItem(item);
}
}
catch (Exception e)
{
MessageBox.Show("ERROR IN _30DayHoldToCollection:\n" + e.Message);
}
finally
{
connect.Close();
}
return collection;
}
示例10: TransactionTableToCollection
public static Collection TransactionTableToCollection(string sortBy = "TransactionNumber", bool ascending = true)
{
TransactionItem item;
Collection collection = new Collection();
// Save sorting order to string "order" (ascending/descending)
string order;
if (ascending) order = "ASC";
else order = "DESC";
SqlCommand cmd = new SqlCommand("SELECT * FROM " + TableNames.TRANSACTION + " ORDER BY " + sortBy + " " + order, connect);
try
{
connect.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read() == true)
{
item = SQLReaderToTransactionItem(reader);
if (item != null)
collection.AddItem(item);
}
connect.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return collection;
}