本文整理汇总了C#中Database类的典型用法代码示例。如果您正苦于以下问题:C# Database类的具体用法?C# Database怎么用?C# Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Database类属于命名空间,在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int id;
if (!int.TryParse(Request.QueryString["id"], out id))
{
Response.Redirect("~/MediaCenter.aspx");
}
Database db = new Database();
Lang lang = new Lang();
db.AddParameter("@lang", lang.getCurrentLang());
db.AddParameter("@id", id);
DataTable dt = db.ExecuteDataTable("select top(3) * from Report where [email protected] and (not [email protected]) Order by id desc");
Repeater1.DataSource = dt;
Repeater1.DataBind();
db.AddParameter("@lang", lang.getCurrentLang());
dt = db.ExecuteDataTable("select top(3) * from SocialEvent where [email protected] Order by id desc");
Repeater2.DataSource = dt;
Repeater2.DataBind();
db.AddParameter("@lang", lang.getCurrentLang());
db.AddParameter("@id", id);
dt = db.ExecuteDataTable("select * from Report where [email protected] and [email protected]");
Repeater3.DataSource = dt;
Repeater3.DataBind();
if (dt.Rows.Count == 0)
{
Response.Redirect("~/MediaCenter.aspx");
}
}
}
示例2: CreateDbAsync
public async Task CreateDbAsync()
{
db = new Database(_connectionStringName);
var all = Utils.LoadTextResource(string.Format("AsyncPoco.Tests.{0}_init.sql", _connectionStringName));
foreach(var sql in all.Split(';').Select(s => s.Trim()).Where(s => s.Length > 0))
await db.ExecuteAsync(sql);
}
示例3: runExtension
public override void runExtension(Database db)
{
foreach (DBItem result in db.getSpawnableItems()) {
// If this item can be made by other items, create a symmetric "Makes" property
if (!result.propertyExists("madeby"))
continue;
foreach (KeyValuePair<string, string> ingredients in (List<KeyValuePair<string, string>>)result.getProperty("madeby")) {
string ingredient1 = ingredients.Key;
string ingredient2 = ingredients.Value;
if (!db.itemExists(ingredient1) || !db.itemExists(ingredient2))
continue;
DBItem dbIng1 = db.getItem(ingredient1);
DBItem dbIng2 = db.getItem(ingredient2);
if (!dbIng1.propertyExists("makes"))
dbIng1.setProperty("makes", new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>(ingredient2, result.ClassName) });
else
(dbIng1.getProperty("makes") as List<KeyValuePair<string, string>>).Add(new KeyValuePair<string, string>(ingredient2, result.ClassName));
if (!dbIng2.propertyExists("makes"))
dbIng2.setProperty("makes", new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>(ingredient1, result.ClassName) });
else
(dbIng2.getProperty("makes") as List<KeyValuePair<string, string>>).Add(new KeyValuePair<string, string>(ingredient1, result.ClassName));
}
}
}
示例4: HandleParameter
public static string HandleParameter( string name, object value, Database db, ref List<Parameter> ps )
{
string ret = db.DelimColumn( name );
if( value != null && value.GetType() == typeof(SpecialValue) )
{
// Special Handling
var sv = (SpecialValue)value;
switch( sv.Name )
{
case "is-null":
ret += " IS NULL";
return ret;
case "is-not-null":
ret += " IS NOT NULL";
return ret;
case "lit-value":
var lv = (LiteralValue)sv;
ret += " = " + lv.TextValue;
return ret;
default:
throw new ArgumentOutOfRangeException( "value", "Unhandled Special Value passed in." );
}
}
var pname = "auto_"+name+"_"+ps.Count.ToString();
ret += " = " + db.DelimParameter( pname );
ps.Add( new Parameter( pname, value ) );
return ret;
}
示例5: SetUp
public void SetUp()
{
var home = _context.CurrentDatabase.GetItem("/sitecore/content/home");
var contentRootItem = TestUtil.CreateContentFromFile("TestResources\\items in workflow.xml", _testRoot);
_publishableItem = contentRootItem.Axes.GetChild("publishable");
_itemInWorkflow = contentRootItem.Axes.GetChild("in draft");
_noWorkflow = contentRootItem.Axes.GetChild("no workflow");
_noWorkflow.Editing.BeginEdit();
_noWorkflow[FieldIDs.Workflow] = string.Empty;
_noWorkflow[FieldIDs.WorkflowState] = string.Empty;
_noWorkflow.Editing.EndEdit();
// publish the root item only so publishing on any item works
var dbs = new Database[]{ Sitecore.Configuration.Factory.GetDatabase("web")};
var langs = new Language[]{ Sitecore.Context.Language};
var handle = PublishManager.PublishItem(_testRoot, dbs, langs, false, true);
PublishManager.PublishItem(contentRootItem, dbs, langs, false, true);
var jobs = from j in Sitecore.Jobs.JobManager.GetJobs()
where j.Name.Contains("Publish") && j.Name.Contains("web")
select j;
foreach (var job in jobs)
job.Wait();
}
示例6: GenerateAnalyticObject
public static GameObject GenerateAnalyticObject(Database database, int analyticType)
{
//Make sure to generate the correct type of harness (disk harness)
GameObject currentHarness = Generate((int)View_Type.DiskHarness);
Transform harnessTransform = currentHarness.transform;
List<DatabaseUtilities.Table> tableInfo = database.tables;
int tableCount = tableInfo.Count;
GameObject[] anaObjects = new GameObject[tableCount];
if(analyticType == 1)
{
DatabaseUtilities.Table infoObject = tableInfo[0];
List<DatabaseUtilities.Column> dataTypes = infoObject.columns;
int dataTypeSize = dataTypes.Count;
GameObject[] disks = new GameObject[dataTypeSize];
for(int i = 0; i < dataTypeSize; i++)
{
disks[i] = GenerateDiskObj(dataTypes[i], harnessTransform);
}
currentHarness.GetComponent<DiskHarness>().Initialize(disks, dataTypes);
}
return currentHarness;
}
示例7: ClearPanelsAkrFromDrawing
public void ClearPanelsAkrFromDrawing(Database db)
{
SelectionBlocks sel = new SelectionBlocks(db);
sel.SelectAKRPanelsBtr();
List<ObjectId> idsBtrPanelsAkr = sel.IdsBtrPanelAr.ToList();
idsBtrPanelsAkr.AddRange(sel.IdsBtrPanelSb);
List<ObjectId> idsBtrOther = new List<ObjectId>();
foreach (ObjectId idBtrPanel in idsBtrPanelsAkr)
{
using (var btrPanel = idBtrPanel.Open(OpenMode.ForRead) as BlockTableRecord)
{
foreach (ObjectId idBlRefPanel in btrPanel.GetBlockReferenceIds(false, true))
{
using (var blRefPanel = idBlRefPanel.Open(OpenMode.ForWrite, false, true) as BlockReference)
{
blRefPanel.Erase();
}
}
foreach (ObjectId idEnt in btrPanel)
{
using (var blRef = idEnt.Open(OpenMode.ForRead, false, true) as BlockReference)
{
if (blRef == null) continue;
idsBtrOther.Add(blRef.BlockTableRecord);
}
}
}
}
eraseIdsDbo(idsBtrPanelsAkr);
eraseIdsDbo(idsBtrOther);
}
示例8: Start
private IEnumerator Start () {
Debug.LogFormat ("Data path = {0}", Application.persistentDataPath);
#if UNITY_EDITOR_WIN
Log.SetLogger(new UnityLogger());
#endif
_db = Manager.SharedInstance.GetDatabase ("spaceshooter");
_pull = _db.CreatePullReplication (GameController.SYNC_URL);
_pull.Continuous = true;
_pull.Start ();
while (_pull != null && _pull.Status == ReplicationStatus.Active) {
yield return new WaitForSeconds(0.5f);
}
var doc = _db.GetExistingDocument ("player_data");
if (doc != null) {
//We have a record! Get the ship data, if possible.
string assetName = String.Empty;
if(doc.UserProperties.ContainsKey("ship_data")) {
assetName = doc.UserProperties ["ship_data"] as String;
}
StartCoroutine(LoadAsset (assetName));
} else {
//Create a new record
doc = _db.GetDocument("player_data");
doc.PutProperties(new Dictionary<string, object> { { "ship_data", String.Empty } });
}
doc.Change += DocumentChanged;
_push = _db.CreatePushReplication (new Uri ("http://127.0.0.1:4984/spaceshooter"));
_push.Start();
}
示例9: FailIfSeedDoesNotMatch
public void FailIfSeedDoesNotMatch()
{
var dataspec = new DatabaseSpec();
dataspec.AddSchema<Employees>();
var database = new Database(ConnectionString);
Assert.That(database.Satisfies(dataspec), Is.False);
}
示例10: FailIfIncrementDoesNotMatch
public void FailIfIncrementDoesNotMatch()
{
var dataspec = new DatabaseSpec();
dataspec.AddSchema<Shippers>();
var database = new Database(ConnectionString);
Assert.That(database.Satisfies(dataspec), Is.False);
}
示例11: UpdateStatus
public static void UpdateStatus(int id, string tableName, string fileName,string title, int archiveId, IQueryTable toTable, QueryColumn toStatus, QueryColumn toPrimary)
{
NBearLite.DbProviders.DbProvider provider =
NBearLite.DbProviders.DbProviderFactory.CreateDbProvider(
null,
"System.Data.SqlServerCe",
@"Data Source=enforce.sdf;
Encrypt Database=True;
Password=enforce_123456;
File Mode=shared read;
Persist Security Info=False;");
Database database = new Database(provider);
UpdateSqlSection section = new UpdateSqlSection(database, toTable);
section.AddColumn(toStatus, 2); // 2 代表已归档
section.Where(toPrimary == id);
section.Execute();
InsertSqlSection insert = new InsertSqlSection(database, DataBases.ArchiveExt);
insert.AddColumn(DataBases.ArchiveExt.ArchiveID, archiveId);
insert.AddColumn(DataBases.ArchiveExt.TableName, tableName);
insert.AddColumn(DataBases.ArchiveExt.PrimaryValue, id);
insert.AddColumn(DataBases.ArchiveExt.FileName, fileName);
insert.AddColumn(DataBases.ArchiveExt.Title, title);
insert.AddColumn(DataBases.ArchiveExt.CreateTime, DateTime.Now);
insert.AddColumn(DataBases.ArchiveExt.ExchangeGUID, CommonInvoke.NewGuid);
insert.Execute();
}
示例12: GetAll
public IEnumerable<object> GetAll(string typeName, string sortColumn, string sortOrder)
{
var currentType = Type.GetType(typeName);
var tableName = (TableNameAttribute)Attribute.GetCustomAttribute(currentType, typeof(TableNameAttribute));
var uioMaticAttri = (UIOMaticAttribute)Attribute.GetCustomAttribute(currentType, typeof(UIOMaticAttribute));
var strTableName = tableName.Value;
var db = (Database)DatabaseContext.Database;
if(!string.IsNullOrEmpty(uioMaticAttri.ConnectionStringName))
db = new Database(uioMaticAttri.ConnectionStringName);
if (strTableName.IndexOf("[") < 0)
{
strTableName = "[" + strTableName + "]";
}
var query = new Sql().Select("*").From(strTableName);
if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortOrder))
{
var strSortColumn = sortColumn;
if (strSortColumn.IndexOf("[") < 0)
{
strSortColumn = "[" + strSortColumn + "]";
}
query.OrderBy(strSortColumn + " " + sortOrder);
}
foreach (dynamic item in db.Fetch<dynamic>(query))
{
// get settable public properties of the type
var props = currentType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(x => x.GetSetMethod() != null);
// create an instance of the type
var obj = Activator.CreateInstance(currentType);
// set property values using reflection
var values = (IDictionary<string, object>)item;
foreach (var prop in props)
{
var columnAttri =
prop.GetCustomAttributes().Where(x => x.GetType() == typeof(ColumnAttribute));
var propName = prop.Name;
if (columnAttri.Any())
propName = ((ColumnAttribute)columnAttri.FirstOrDefault()).Name;
if(values.ContainsKey(propName))
prop.SetValue(obj, values[propName]);
}
yield return obj;
}
}
示例13: SaleProcessor
public SaleProcessor(Database database, IOutgoingCommandEnvelopeRouter envelopeRouter, SaleRepository saleRepository, InventoryRepository inventoryRepository)
{
this.database = database;
this.envelopeRouter = envelopeRouter;
this.saleRepository = saleRepository;
this.inventoryRepository = inventoryRepository;
}
示例14: CodeAction
public void CodeAction(BonoboGitServerContext context)
{
_db = context.Database;
if (UpgradeHasAlreadyBeenRun())
{
return;
}
using (var trans = context.Database.BeginTransaction())
{
try
{
RenameTables();
CreateTables();
CopyData();
AddRelations();
DropRenamedTables();
trans.Commit();
}
catch (Exception)
{
trans.Rollback();
throw;
}
}
}
示例15: CreateSnaphot
public void CreateSnaphot(string SnapshotName, string SourceDatabase, string SnapshotLocation)
{
Database SrcDatabase = _Server.Databases[SourceDatabase];
Database SnapshotDatabase = new Database(_Server, SnapshotName);
SnapshotDatabase.DatabaseSnapshotBaseName = SourceDatabase;
foreach (FileGroup Group in SrcDatabase.FileGroups)
{
SnapshotDatabase.FileGroups.Add(new FileGroup(SnapshotDatabase, Group.Name));
foreach (DataFile File in Group.Files)
{
SnapshotDatabase.FileGroups[Group.Name].Files.Add(
new DataFile(
SnapshotDatabase.FileGroups[Group.Name],
File.Name,
SnapshotLocation + @"\" + SnapshotName + "_" + File.Name + ".ss")
);
}
}
DropSnapshot(SnapshotName);
SnapshotDatabase.Create();
_Repository.Connection.ChangeDatabase(SourceDatabase);
}