/// <summary> /// 更新一条数据 /// </summary> public bool Update(KryptonAccessController.SQLite.Model.UserRelation.CardInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CardInfo set "); strSql.Append("CardVersion=@CardVersion,"); strSql.Append("CardType=@CardType,"); strSql.Append("CardLevel=@CardLevel,"); strSql.Append("CardPassword=@CardPassword,"); strSql.Append("CardIssueDateTime=@CardIssueDateTime,"); strSql.Append("CardValidDateTime=@CardValidDateTime,"); strSql.Append("StateFlag=@StateFlag"); strSql.Append(" where CardID=@CardID "); SQLiteParameter[] parameters = { new SQLiteParameter("@CardVersion", DbType.String), new SQLiteParameter("@CardType", DbType.Int32,4), new SQLiteParameter("@CardLevel", DbType.String), new SQLiteParameter("@CardPassword", DbType.String), new SQLiteParameter("@CardIssueDateTime", DbType.String), new SQLiteParameter("@CardValidDateTime", DbType.String), new SQLiteParameter("@StateFlag", DbType.String), new SQLiteParameter("@CardID", DbType.String) }; parameters[0].Value = model.CardVersion; parameters[1].Value = model.CardType; parameters[2].Value = model.CardLevel; parameters[3].Value = model.CardPassword; parameters[4].Value = model.CardIssueDateTime; parameters[5].Value = model.CardValidDateTime; parameters[6].Value = model.StateFlag; parameters[7].Value = model.CardID; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public KryptonAccessController.SQLite.Model.UserRelation.CardInfo DataRowToModel(DataRow row) { KryptonAccessController.SQLite.Model.UserRelation.CardInfo model = new KryptonAccessController.SQLite.Model.UserRelation.CardInfo(); if (row != null) { if (row["CardID"] != null) { model.CardID = row["CardID"].ToString(); } if (row["CardVersion"] != null) { model.CardVersion = row["CardVersion"].ToString(); } if (row["CardType"] != null && row["CardType"].ToString() != "") { model.CardType = int.Parse(row["CardType"].ToString()); } if (row["CardLevel"] != null) { model.CardLevel = row["CardLevel"].ToString(); } if (row["CardPassword"] != null) { model.CardPassword = row["CardPassword"].ToString(); } if (row["CardIssueDateTime"] != null) { model.CardIssueDateTime = row["CardIssueDateTime"].ToString(); } if (row["CardValidDateTime"] != null) { model.CardValidDateTime = row["CardValidDateTime"].ToString(); } if (row["StateFlag"] != null) { model.StateFlag = row["StateFlag"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(KryptonAccessController.SQLite.Model.UserRelation.CardInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CardInfo("); strSql.Append("CardID,CardVersion,CardType,CardLevel,CardPassword,CardIssueDateTime,CardValidDateTime,StateFlag)"); strSql.Append(" values ("); strSql.Append("@CardID,@CardVersion,@CardType,@CardLevel,@CardPassword,@CardIssueDateTime,@CardValidDateTime,@StateFlag)"); SQLiteParameter[] parameters = { new SQLiteParameter("@CardID", DbType.String), new SQLiteParameter("@CardVersion", DbType.String), new SQLiteParameter("@CardType", DbType.Int32,4), new SQLiteParameter("@CardLevel", DbType.String), new SQLiteParameter("@CardPassword", DbType.String), new SQLiteParameter("@CardIssueDateTime", DbType.String), new SQLiteParameter("@CardValidDateTime", DbType.String), new SQLiteParameter("@StateFlag", DbType.String) }; parameters[0].Value = model.CardID; parameters[1].Value = model.CardVersion; parameters[2].Value = model.CardType; parameters[3].Value = model.CardLevel; parameters[4].Value = model.CardPassword; parameters[5].Value = model.CardIssueDateTime; parameters[6].Value = model.CardValidDateTime; parameters[7].Value = model.StateFlag; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public KryptonAccessController.SQLite.Model.UserRelation.CardInfo GetModel(string CardID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select CardID,CardVersion,CardType,CardLevel,CardPassword,CardIssueDateTime,CardValidDateTime,StateFlag from CardInfo "); strSql.Append(" where CardID=@CardID "); SQLiteParameter[] parameters = { new SQLiteParameter("@CardID", DbType.String) }; parameters[0].Value = CardID; KryptonAccessController.SQLite.Model.UserRelation.CardInfo model = new KryptonAccessController.SQLite.Model.UserRelation.CardInfo(); DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void kryptonButtonTestJson_Click(object sender, EventArgs e) { KryptonAccessController.SQLite.Model.UserRelation.CardInfo modelCardInfo = JSON.parse <KryptonAccessController.SQLite.Model.UserRelation.CardInfo>("{CardId:'000000',CardVersion:'1',CardType:0,CardLevel:'E',CardPassword:000000,CardIssueDate:'2014-09-01',CardValidDate:'2016-09-01',StateFlag:'1'}"); }
/// <summary> /// 得到一个对象实体 /// </summary> public KryptonAccessController.SQLite.Model.UserRelation.CardInfo DataRowToModel(DataRow row) { KryptonAccessController.SQLite.Model.UserRelation.CardInfo model=new KryptonAccessController.SQLite.Model.UserRelation.CardInfo(); if (row != null) { if(row["CardID"]!=null) { model.CardID=row["CardID"].ToString(); } if(row["CardVersion"]!=null) { model.CardVersion=row["CardVersion"].ToString(); } if(row["CardType"]!=null && row["CardType"].ToString()!="") { model.CardType=int.Parse(row["CardType"].ToString()); } if(row["CardLevel"]!=null) { model.CardLevel=row["CardLevel"].ToString(); } if(row["CardPassword"]!=null) { model.CardPassword=row["CardPassword"].ToString(); } if(row["CardIssueDateTime"]!=null) { model.CardIssueDateTime=row["CardIssueDateTime"].ToString(); } if(row["CardValidDateTime"]!=null) { model.CardValidDateTime=row["CardValidDateTime"].ToString(); } if(row["StateFlag"]!=null) { model.StateFlag=row["StateFlag"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public KryptonAccessController.SQLite.Model.UserRelation.CardInfo GetModel(string CardID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select CardID,CardVersion,CardType,CardLevel,CardPassword,CardIssueDateTime,CardValidDateTime,StateFlag from CardInfo "); strSql.Append(" where CardID=@CardID "); SQLiteParameter[] parameters = { new SQLiteParameter("@CardID", DbType.String) }; parameters[0].Value = CardID; KryptonAccessController.SQLite.Model.UserRelation.CardInfo model=new KryptonAccessController.SQLite.Model.UserRelation.CardInfo(); DataSet ds=DbHelperSQLite.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }