本文整理汇总了C#中PetaPoco.Database.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Database.Execute方法的具体用法?C# Database.Execute怎么用?C# Database.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PetaPoco.Database
的用法示例。
在下文中一共展示了Database.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnReView_ItemClick
void btnReView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var et = gcloginfail.GetFocusedDataSource<t_loginfail>();
if (null == et)
return;
if (MsgBox.ShowYesNoMessage(null,
string.Format("确定要将 {0} MAC:{1} 审核通过吗?", et.UserName, et.LoginMAC)) == System.Windows.Forms.DialogResult.No)
return;
var usr = GetCurUser<t_user>();
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Delete("t_loginfail", "Id", et, et.Id);
db.Execute(sql_addmac, et.LoginMAC, usr.UserName, usr.Guid);
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
#if DEBUG
throw;
#endif
}
}
using (var db = new Database()) {
var etfail = db.Fetch<t_loginfail>("select * from t_loginfail");
gcloginfail.DataSource = etfail;
gcloginfail.RefreshDataSource();
var etmac = db.Fetch<t_loginfail>("select * from t_mac");
gcMac.DataSource = etmac;
gcMac.RefreshDataSource();
}
}
示例2: CreateTables
public void CreateTables()
{
using (var db = new Database("DataSource=\"test.sdf\"; Password=\"chrissiespassword\"", "System.Data.SqlServerCe.4.0")) {
db.Execute("CREATE TABLE Person (Id int IDENTITY(1,1) PRIMARY KEY, LastName nvarchar (40) NOT NULL, FirstName nvarchar (40), AddressId int NOT NULL);");
db.Execute("CREATE TABLE Address (Id int IDENTITY(1,1) PRIMARY KEY, Street nvarchar (40) NOT NULL, HouseNumber nvarchar (10));");
}
}
示例3: ResetDatabase
protected override void ResetDatabase()
{
using (var database = new Database("SQLiteTest"))
{
database.BeginTransaction();
database.Execute(new Sql("DELETE FROM Entity"));
database.Execute(new Sql("DELETE FROM sqlite_sequence WHERE name = @0", "Entity"));
database.CompleteTransaction();
}
}
示例4: SetPoints
public void SetPoints(int trackId, TrackPoint[] points)
{
var sb = new StringBuilder();
for (int i = 0; i < points.Length; i++)
{
if (i % 1000 == 0)
{
if(sb.Length>0) sb.Remove(sb.Length - 1, 1);
sb.AppendLine(";").AppendLine("insert into MR.tTrackPoint (TrackId, Idx, Lat, Lon, Elevation, PointTime) values ");
}
var p = points[i];
sb.AppendLine().Append("(")
.Append(trackId).Append(",")
.Append(i).Append(",")
.Append(p.Lat.ToString(CultureInfo.InvariantCulture)).Append(",")
.Append(p.Lon.ToString(CultureInfo.InvariantCulture)).Append(",")
.Append(p.Elevation.ToString(CultureInfo.InvariantCulture)).Append(",")
.Append("'").Append(p.PointTime.ToString("o",CultureInfo.InvariantCulture)).Append("'")
.Append("),");
}
var sql = sb.ToString().TrimEnd(',');
var db = new Database(_config.ConnectionString, "System.Data.SqlClient");
try
{
db.Execute(sql);
}
catch (SqlException ex)
{
throw new Exception(sql, ex);
}
}
示例5: deleteRoute
public static void deleteRoute(int id)
{
using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
{
db.Execute("UPDATE route SET deleted = TRUE WHERE id = @0", id);
}
}
示例6: CreateDatabaseAndStuff
public void CreateDatabaseAndStuff()
{
//creating the database
_createDatabaseConn = new Database("create_db_conn");
_createDatabaseConn.Execute("CREATE DATABASE TavernWenchTestDb");
//creating test tables
_testDatabaseConn = new Database("test_db_conn");
_testDatabaseConn.Execute(@"CREATE TABLE Fruit (
Name VARCHAR(60),
Color VARCHAR(60)
);");
_testDatabaseConn.Execute(@"CREATE TABLE Actor (
Id INT IDENTITY(1,1) NOT NULL,
LastName VARCHAR(60)
);");
}
示例7: SaveOffice
public static void SaveOffice(string catalog, string regionalDataFile, string officeCode, string officeName,
string nickName,
DateTime registrationDate, string currencyCode, string currencySymbol, string currencyName,
string hundredthName, string fiscalYearCode,
string fiscalYearName, DateTime startsFrom, DateTime endsOn,
bool salesTaxIsVat, bool hasStateSalesTax, bool hasCountySalesTax,
int quotationValidDays, decimal incomeTaxRate, int weekStartDay, DateTime transactionStartDate,
bool isPerpetual, string valuationMethod, string logo,
string adminName, string username, string password)
{
try
{
using (Database db = new Database(Factory.GetConnectionString(catalog), Factory.ProviderName))
{
using (Transaction transaction = db.GetTransaction())
{
string sql = File.ReadAllText(regionalDataFile, Encoding.UTF8);
db.Execute(sql);
sql =
"SELECT * FROM office.add_office(@0::varchar(12), @1::varchar(150), @2::varchar(50), @3::date, @4::varchar(12), @5::varchar(12), @6::varchar(48), @7::varchar(48), @8::varchar(12), @9::varchar(50), @10::date,@11::date, @12::boolean, @13::boolean, @14::boolean, @15::integer, @16::numeric, @17::integer, @18::date, @19::boolean, @20::character varying(5), @21::text, @22::varchar(100), @23::varchar(50), @24::varchar(48));";
db.Execute(sql, officeCode, officeName, nickName, registrationDate, currencyCode,
currencySymbol, currencyName, hundredthName, fiscalYearCode, fiscalYearName, startsFrom,
endsOn,
salesTaxIsVat, hasStateSalesTax, hasCountySalesTax, quotationValidDays,
incomeTaxRate, weekStartDay, transactionStartDate, isPerpetual, valuationMethod, logo,
adminName,
username, password);
transaction.Complete();
}
}
}
catch (NpgsqlException ex)
{
if (ex.Code.StartsWith("P"))
{
string errorMessage = Factory.GetDBErrorResource(ex);
throw new MixERPException(errorMessage, ex);
}
throw;
}
}
示例8: CreateDB
public void CreateDB()
{
db = new Database(_connectionStringName);
db.Execute(@"
DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS authors;
CREATE TABLE posts (
id bigint AUTO_INCREMENT NOT NULL,
title varchar(127) NOT NULL,
author bigint NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB;
CREATE TABLE authors (
id bigint AUTO_INCREMENT NOT NULL,
name varchar(127) NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB;
");
var a1 = new author();
a1.name = "Bill";
db.Insert(a1);
var a2 = new author();
a2.name = "Ted";
db.Insert(a2);
var p = new post();
p.title = "post1";
p.author = a1.id;
db.Insert(p);
p = new post();
p.title = "post2";
p.author = a1.id;
db.Insert(p);
p = new post();
p.title = "post3";
p.author = a2.id;
db.Insert(p);
}
示例9: btnOK_Click
private void btnOK_Click(object sender, EventArgs e) {
if (!dxValidationProvider1.Validate()) { return; }
if (txtPassword.Text != txtComfirmPassword.Text) {
MsgBox.ShowMessage("","两次输入的密码不一致!");
return;
}
try {
using (var db = new Database()) {
db.Execute("update t_user set [email protected] where [email protected]", Ultra.Surface.Common.Util.EncryptPwd(txtPassword.Text), this.CurUser);
}
this.DialogResult = System.Windows.Forms.DialogResult.OK;
Close();
} catch (Exception ex) {
throw ex;
}
}
示例10: SetApiKey
public void SetApiKey(int userId, string apiKey)
{
var db = new Database(_config.ConnectionString, "System.Data.SqlClient");
db.Execute("update MR.tUser set ApiKey = @1 where UserId = @0", userId, apiKey);
}
示例11: processMDCInpsections
private static void processMDCInpsections(Permit permit, Database db)
{
//Cleanup DB to bring new points for permit
Console.WriteLine("Cleaning Data from DB for Permit: " + permit.PermitNum);
db.Execute(String.Format("DELETE FROM Inspection WHERE PermitNum = '{0}'", permit.PermitNum));
db.Execute(String.Format("DELETE FROM PermitStatus WHERE PermitNum = '{0}'", permit.PermitNum));
Console.WriteLine("Getting Inspections for Permit: " + permit.PermitNum);
List<Inspection> inspections = getMDCInspections(permit.PermitNum);
DateTime? lastApprovedInspectionDate = permit.StatusDate;
if (permit.AppliedDate != null)
{
PermitStatus status = new PermitStatus();
status.PermitNum = permit.PermitNum;
status.StatusPrevious = "APPLIED";
status.StatusPreviousMapped = "Application Accepted";
status.StatusPreviousDate = permit.AppliedDate;
db.Insert("PermitStatus", "id", true, status);
permit.StatusCurrent = status.StatusPrevious;
permit.StatusCurrentMapped = status.StatusPreviousMapped;
permit.StatusDate = status.StatusPreviousDate;
}
if (permit.IssuedDate != null)
{
PermitStatus status = new PermitStatus();
status.PermitNum = permit.PermitNum;
status.StatusPrevious = "ISSUED";
status.StatusPreviousMapped = "Permit Issued";
status.StatusPreviousDate = permit.IssuedDate;
db.Insert("PermitStatus", "id", true, status);
permit.StatusCurrent = status.StatusPrevious;
permit.StatusCurrentMapped = status.StatusPreviousMapped;
permit.StatusDate = status.StatusPreviousDate;
}
if (isPermitClosed(inspections))
{
PermitStatus status = new PermitStatus();
status.PermitNum = permit.PermitNum;
status.StatusPrevious = "CLOSED";
status.StatusPreviousMapped = "Permit Finaled";
status.StatusPreviousDate = lastApprovedInspectionDate;
db.Insert("PermitStatus", "id", true, status);
permit.StatusCurrent = status.StatusPrevious;
permit.StatusCurrentMapped = status.StatusPreviousMapped;
permit.StatusDate = status.StatusPreviousDate;
permit.CompletedDate = status.StatusPreviousDate;
}
foreach (Inspection inspection in inspections)
{
db.Insert("Inspection", "Id", true, inspection);
}
}
示例12: SetPassword
public void SetPassword(string email, string passwordHash)
{
var db = new Database(_config.ConnectionString, "System.Data.SqlClient");
db.Execute("update MR.tUser set Passwd = @1 where Email = @0", email, passwordHash);
}
示例13: btnOK_Click
private void btnOK_Click(object sender, EventArgs e)
{
var items = gcItem.GetDataSource<t_instockitem>();
if (items == null || items.Count < 1) {
MsgBox.ShowMessage("", "没有商品信息,不能保存!");
return;
}
if (items.Any(K => string.IsNullOrEmpty(K.ItemNo))) {
MsgBox.ShowMessage("", "商品信息不完整!");
return;
}
if (EditMode == Web.Core.Enums.EnViewEditMode.Edit) {
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Execute("delete t_instockitem where [email protected]", InStockNo);
InStock.Remark = txtRemark.Text;
InStock.Num = items.Sum(k => k.Num);
InStock.OuterNo = txtOuterNo.Text;
db.Save(InStock);
items.ForEach(k => { k.Id = 0; db.Save(k); });
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
} else {
InStock = new t_instock();
InStock.Remark = txtRemark.Text;
InStock.Guid = GuidKey;
InStock.InStockNo = InStockNo;
InStock.OuterNo = txtOuterNo.Text;
InStock.Creator = this.CurUser;
InStock.AuditDate = InStock.CreateDate = TimeSync.Default.CurrentSyncTime;
InStock.Num = items.Sum(k => k.Num);
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Save(InStock);
items.ForEach(k => db.Save(k));
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
}
DialogResult = DialogResult.OK;
Close();
}
示例14: btnInvalid_ItemClick
void btnInvalid_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var trd = gcUnAudit.GetFocusedDataSource<t_rettrade>();
if (trd == null)
return;
using (var db = new Database()) {
db.Execute("update t_rettrade set isinvalid=1 where [email protected]", trd.Guid);
}
gcUnAudit.RemoveSelected();
}
示例15: btnReView_ItemClick
void btnReView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var trd = gcUnAudit.GetFocusedDataSource<t_rettrade>();
if (trd == null)
return;
using (var db = new Database()) {
try {
db.BeginTransaction();
//入库更新库存
db.Execute("exec p_retgoodsupdateinvt @0", trd.Guid);
db.Execute("update t_rettrade set isaudit=1 where [email protected]", trd.Guid);
db.CompleteTransaction();
gcUnAudit.RemoveSelected();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
}