本文整理汇总了C#中DBHelper类的典型用法代码示例。如果您正苦于以下问题:C# DBHelper类的具体用法?C# DBHelper怎么用?C# DBHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DBHelper类属于命名空间,在下文中一共展示了DBHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryTest
public void QueryTest()
{
// Arrange-测试设置,创建对象
DBHelper db = new DBHelper();
Customer customer = new Customer()
{
UserName = "User-1",
Password = "PWDHASH-1 ",
Email = "EMAIL-1 ",
PhoneNumber = "PHONE-1 ",
IsFirstTimeLogin = false,
AccessFailedCount = 0,
CreationDate = DateTime.Now,
IsActive = false
};
int count = 0;
List<Customer> customerList = new List<Customer>();
// 拼接字符串的时候要注意标量的名字要与类中的成员变量名一样(可忽略字母的大小写)
// 例如:此处sql中的@Password中的Password就必须与Customer类中的成员变量Password名称一样(可忽略大小写)
string querySQL = @"SELECT * FROM dbo.CICUser WHERE [email protected] AND [email protected]";
// Act-测试行为,使用功能
customerList = db.Query<Customer>(querySQL, customer).ToList();
count = customerList.Count;
// Assert-测试结果,验证结果
Assert.AreEqual(1,count);
}
示例2: clearDB
public void clearDB(Context context)
{
dbHelper = new DBHelper(context);
SQLiteDatabase db = dbHelper.WritableDatabase;
db.Delete("general", null, null);
db.Delete("records", null, null);
}
示例3: getRecordsInfo
public RecordInfo getRecordsInfo(String difficulty, Context context)
{
dbHelper = new DBHelper(context);
SQLiteDatabase db = dbHelper.WritableDatabase;
SQLiteCursor gc = (SQLiteCursor)db.Query("general", null, "difficulty = ?", new String[]{difficulty}, null, null, null);
int avgTimeColIndex = gc.GetColumnIndex("avgTime");
int gamesCountColIndex = gc.GetColumnIndex("gamesCount");
int avgTime = 0;
int gamesCount = 0;
if (gc.MoveToFirst()){
avgTime = gc.GetInt(avgTimeColIndex);
gamesCount = gc.GetInt(gamesCountColIndex);
}
RecordInfo result = new RecordInfo(avgTime, gamesCount, new Java.Lang.String(difficulty));
SQLiteCursor c = (SQLiteCursor)db.Query("records", null, " difficulty = ?", new String[]{difficulty}, null, null, null);
if (c.MoveToFirst()) {
int timeColIndex = c.GetColumnIndex("time");
result.addRecord(c.GetInt(timeColIndex));
while (c.MoveToNext()) {
result.addRecord(c.GetInt(timeColIndex));
}
}
return result;
}
示例4: ImportItem
public ImportItem(IProject project, DBHelper dbHelper)
{
this._TheProject = project;
this.DBHelper = dbHelper;
this.TheProject.TargetDateChanged += this.OnDateChanged;
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
#region 标签信息
string strTagInfo = "";
try
{
string sql = "select * from [tb_tag] where tag_ispublic=1";
DataTable dt = new DataTable();
DBHelper dbh = new DBHelper(config.DBConn);
dt = dbh.ExecuteDataTable("", sql);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
strTagInfo += "<a href=\"default.aspx?id=" + dt.Rows[i]["tag_id"].ToString() + "\" class=\"tag\" target=\"_blank\">" + dt.Rows[i]["tag_name"].ToString() + "</a>";
}
}
dbh.Dispose();
dt.Dispose();
}
catch (Exception ex)
{
strTagInfo = ex.ToString();
}
this.tagBall.InnerHtml = strTagInfo;
#endregion
}
示例6: GetYourDates
internal DateTime[] GetYourDates(DBHelper db_, TZ tz_)
{
string tableName = "eventTimesGMT";
switch (tz_)
{
case TZ.HK: tableName = "eventTimesHK"; break;
case TZ.LN: tableName = "eventTimesLN"; break;
case TZ.NY: tableName = "eventTimesNY"; break;
case TZ.GMT: tableName = "eventTimesGMT"; break;
}
var sql = string.Format("select eventTimeLocal from {1} where eventID={0} order by eventTimeGMT", EventID, tableName);
var ds = db_.Execute(sql);
if (DBHelper.HasData(ds))
{
var list = new List<DateTime>();
foreach (DataRow row in ds.Tables[0].Rows)
list.Add((DateTime)row[0]);
return list.ToArray();
}
return null;
}
示例7: GetUserID
public List<string> GetUserID(string mode, string user_id)
{
List<string> lst = new List<string>();
DBHelper helper = new DBHelper();
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter(CONSTANT.MODE, mode);
param[1] = new SqlParameter(CONSTANT.USER_ID, user_id);
DataSet ds = helper.executeSelectQuery(PROCEDURES.DELETE_USER_OPERTAION, param);
if (ds != null)
{
foreach (DataRow item in ds.Tables[0].Rows)
{
lst.Add(item[0].ToString());
}
}
return lst;
}
示例8: HoborAsker
//const double AllowRange = 0.5;
public static HoborModel HoborAsker(DBHelper DBHelper, double XAxis, double YAxis)
{
HoborModel result=new HoborModel();
double AllowRange = GetConfig.GetAllowRange();
double xAxisAbove = XAxis + AllowRange
, xAxisBelow = XAxis - AllowRange
, yAxisAbove = YAxis + AllowRange
, yAxisBelow = YAxis - AllowRange;
string commandText = "SELECT * FROM Hobor WHERE XAxis BETWEEN @XAxis1 AND @XAxis2 AND YAxis Between @YXias1 AND @YXias2";
System.Data.DataTable dt = DBHelper.GetData(commandText, new List<Parameter>()
{
new Parameter("@XAxis1",xAxisBelow)
,new Parameter("@XAxis2",xAxisAbove)
,new Parameter("@YXias1",yAxisBelow)
,new Parameter("@YXias2", yAxisAbove)
});
if (dt != null && dt.Rows.Count > 0)
{
result.IsExist = true;
result.CountryName = dt.Rows[0]["CountryName"].ToString();
result.Name = dt.Rows[0]["Name"].ToString();
result.XAxis = Common.ConvertToDouble(dt.Rows[0]["XAxis"]);
result.YAxis = Common.ConvertToDouble(dt.Rows[0]["YAxis"]);
result.Info = dt.Rows[0]["Info"].ToString();
}
return result;
}
示例9: ListHitViewer
public ListHitViewer()
{
InitializeComponent();
db = new DBHelper();
//load up the app bar
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Minimized;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBar.IsMenuEnabled = true;
//get the item from the phone state! woo!
if (PhoneApplicationService.Current.State.ContainsKey("CurrentItem") && PhoneApplicationService.Current.State["CurrentItem"] != null)
{
_item = PhoneApplicationService.Current.State["CurrentItem"] as OldItem;
//only show share if the _item is not null
ApplicationBarIconButton btnShareAppBar = new ApplicationBarIconButton();
btnShareAppBar.IconUri = new Uri("/Assets/AppBarIcons/share.png", UriKind.Relative);
btnShareAppBar.Text = "Tap To Share";
ApplicationBar.Buttons.Add(btnShareAppBar);
btnShareAppBar.Click += new EventHandler(btnShareAppBar_Click);
}
//feedback button
ApplicationBarIconButton btnFeedbackAppBar = new ApplicationBarIconButton();
btnFeedbackAppBar.IconUri = new Uri("/Assets/AppBarIcons/questionmark.png", UriKind.Relative);
btnFeedbackAppBar.Text = "Feedback";
ApplicationBar.Buttons.Add(btnFeedbackAppBar);
btnFeedbackAppBar.Click += new EventHandler(btnFeedbackAppBar_Click);
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (string.IsNullOrWhiteSpace(Request.QueryString["Exhibition"])) return;
string strExhibitionId = Request.QueryString["Exhibition"];
DBHelper objHelper = new DBHelper();
General objGen = new General();
string strSQL = @"SELECT EXHIBITION_NAME,
EXHIBITION_DETAILS,
EXHIBITON_TEXT,
EXHIBITION_IMAGE
FROM INSTA_MST_EXHIBITION
WHERE EXHIBITION_ID =" + objGen.gReplaceQuotes(strExhibitionId);
IDataReader reader = objHelper.gExecuteReader(CommandType.Text, strSQL);
while (reader.Read())
{
img.Src = "../../upload/images/Exhibition/" + Convert.ToString(reader["EXHIBITION_IMAGE"]);
ltHeading.Text = Convert.ToString(reader["EXHIBITION_NAME"]) + Convert.ToString(reader["EXHIBITION_DETAILS"]);
ltDetail.Text = Convert.ToString(reader["EXHIBITON_TEXT"]);
}
reader.Close();
reader.Dispose();
}
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Url.Host.ToLower() == "localhost")
{
//base.login_user_id = 40123; //user
//base.login_user_id = 40110; //exec producer -- skip
//base.login_user_id = 272; //producer -- elyse
//base.login_user_id = 205; //coordinator
base.login_user_id = 144; //administrator -- randy
theader.Visible = false;
aheader.Visible = false;
levaNav.Visible = false;
tfooter.Visible = false;
levbNav.Visible = false;
groupTest = this.TestGroupMembership;
}
else
{
base.Page_Load("/newallocations/LockAllocations.aspx");
groupTest = base.testmembership;
}
DBHelper db = new DBHelper();
if (!groupTest.Invoke(ref db, "A3Coordinator") && !groupTest.Invoke(ref db, "A2Administrator"))
Response.Redirect("/permitError.html");
int week_num = RGA.Allocations.Data.Utility.CurrectWeek() + 1;
WeekNumber.Value = week_num.ToString();
Week.Text = RGA.Allocations.Data.Utility.CurrectWeekStartDate(week_num).ToString("MM/dd/yy");
}
示例12: AddBudget
DBHelper helper; // 和数据库打交道
public AddBudget(string name)
{
InitializeComponent();
currentUser = name;
helper = new DBHelper();
initialize();
}
示例13: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
IsInGroup groupTest = null;
if (Request.Url.Host.ToLower() == "localhost")
{
//base.login_user_id = _UserId = 40123; //user
//base.login_user_id = _UserId = 40110; //exec producer -- skip
//base.login_user_id = _UserId = 272; //producer -- elyse
//base.login_user_id = _UserId = 205; //coordinator
base.login_user_id = _UserId = 144; //administrator -- randy
theader.Visible = false;
aheader.Visible = false;
levaNav.Visible = false;
tfooter.Visible = false;
levbNav.Visible = false;
groupTest = TestGroupMembership;
}
else
{
base.Page_Load("/newallocations/TeamAllocation.aspx");
_UserId = base.login_user_id;
groupTest = base.testmembership;
}
// determine if the user's group and set a variable to use when printing out allocations
DBHelper db = new DBHelper();
if (groupTest.Invoke(ref db, "A3Coordinator"))
_secType = RgaWeb.SecurityType.EditAll;
if (groupTest.Invoke(ref db, "A2Administrator"))
_secType = RgaWeb.SecurityType.EditAll;
if (groupTest.Invoke(ref db, "A8Producer"))
_secType = RgaWeb.SecurityType.EditUpcoming;
if (groupTest.Invoke(ref db, "A5ExecProducer"))
_secType = RgaWeb.SecurityType.EditUpcoming;
if (!Page.IsPostBack)
{
LoadRegions();
LoadDepartments();
// retrieve current week and date
_StartWeek = RgaData.Utility.CurrectWeek();
_StartDate = RgaData.Utility.CurrectWeekStartDate(_StartWeek);
// setup week picker
ctlWeekPicker.CurrentWeek = _StartWeek;
ctlWeekPicker.CurrectWeekStartDate = _StartDate;
}
else
{
// set start week
_StartWeek = ctlWeekPicker.CurrentWeek;
}
// set up delegate to rebind the grid when week selection is changed
DelSelectWeek delSelectWeek = new DelSelectWeek(this.ctlWeekPicker_SelectedIndexChanged);
ctlWeekPicker.UpdateCurrentWeek = delSelectWeek;
}
示例14: Test
public bool Test()
{
SqlParameter[] param = new SqlParameter[1];
DBHelper helper = new DBHelper();
param[0] = new SqlParameter(CONSTANT.CAT_ID, "ZCVV");
bool ds = helper.InsertQuery(PROCEDURES.CAT_INSERT, param);
return ds;
}
示例15: putRecord
public void putRecord(long time, String difficulty, Context context)
{
dbHelper = new DBHelper(context);
ContentValues cv = new ContentValues();
SQLiteDatabase db = dbHelper.WritableDatabase;
SQLiteCursor c = (SQLiteCursor)db.Query("records", null, " difficulty = ?", new String[]{difficulty}, null, null, null);
int count = 1;
if (c.MoveToFirst()) {
int idColIndex = c.GetColumnIndex("id");
int timeColIndex = c.GetColumnIndex("time");
int maxDBindex = c.GetInt(idColIndex);
int maxDBtime = c.GetInt(timeColIndex);
count++;
while (c.MoveToNext()) {
if (c.GetInt(timeColIndex) > maxDBtime){
maxDBtime = c.GetInt(timeColIndex);
maxDBindex = c.GetInt(idColIndex);
}
count++;
}
if (count == 6){
if (time < maxDBtime){
db.Delete("records", " id = ?", new String[]{maxDBindex + ""});
} else {
c.Close();
db.Close();
return;
}
}
}
cv.Put("time", time);
cv.Put("difficulty", difficulty);
db.Insert("records", null, cv);
cv.Clear();
SQLiteCursor gc = (SQLiteCursor)db.Query("general", null, "difficulty = ?", new String[]{difficulty}, null, null, null);
gc.MoveToFirst();
int avgTimeColIndex = gc.GetColumnIndex("avgTime");
int gamesCountColIndex = gc.GetColumnIndex("gamesCount");
int avgTime = 0;
int gamesCount = 0;
if (gc.MoveToFirst()){
avgTime = gc.GetInt(avgTimeColIndex);
gamesCount = gc.GetInt(gamesCountColIndex);
}
int newGamesCount = gamesCount + 1;
int newAvgTime = (avgTime * gamesCount / newGamesCount) + (int)(time / newGamesCount);
cv.Put("difficulty", difficulty);
cv.Put("avgTime", newAvgTime);
cv.Put("gamesCount", newGamesCount);
db.Delete("general", " difficulty = ?", new String[]{difficulty});
db.Insert("general", null, cv);
db.Close();
c.Close();
gc.Close();
}