/// <summary>更新一条数据 /// /// </summary> public bool Update(Nikita.Assist.DBManager.Model.SetOrdTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Tb_SetOrdTable set "); strSql.Append("SetOrdText=@SetOrdText, SetOrdKey=@SetOrdKey, State=@State, Remark=@Remark, AllowWorkType=@AllowWorkType "); strSql.Append(" where id=@id "); SQLiteHelper h = new SQLiteHelper(GlobalHelp.SynchronizationDB); h.CreateCommand(strSql.ToString()); if (model.SetOrdText == null) { h.AddParameter("@SetOrdText", DBNull.Value); } else { h.AddParameter("@SetOrdText", model.SetOrdText); } if (model.SetOrdKey == null) { h.AddParameter("@SetOrdKey", DBNull.Value); } else { h.AddParameter("@SetOrdKey", model.SetOrdKey); } if (model.State == null) { h.AddParameter("@State", DBNull.Value); } else { h.AddParameter("@State", model.State); } if (model.Remark == null) { h.AddParameter("@Remark", DBNull.Value); } else { h.AddParameter("@Remark", model.Remark); } if (model.AllowWorkType == null) { h.AddParameter("@AllowWorkType", DBNull.Value); } else { h.AddParameter("@AllowWorkType", model.AllowWorkType); } h.AddParameter("@id", model.id); return(h.ExecuteNonQuery()); }
/// <summary>得到一个对象实体 /// /// </summary> public Nikita.Assist.DBManager.Model.SetOrdTable GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from Tb_SetOrdTable "); strSql.Append(" where id=@id "); SQLiteHelper h = new SQLiteHelper(GlobalHelp.SynchronizationDB); h.CreateCommand(strSql.ToString()); h.AddParameter("@id", id); Nikita.Assist.DBManager.Model.SetOrdTable model = null; using (IDataReader dataReader = h.ExecuteReader()) { if (dataReader.Read()) { model = ReaderBind(dataReader); } h.CloseConn(); } return(model); }
/// <summary>对象实体绑定数据 /// /// </summary> public Nikita.Assist.DBManager.Model.SetOrdTable ReaderBind(IDataReader dataReader) { Nikita.Assist.DBManager.Model.SetOrdTable model = new Nikita.Assist.DBManager.Model.SetOrdTable(); object ojb; ojb = dataReader["id"]; if (ojb != null && ojb != DBNull.Value) { model.id = int.Parse(ojb.ToString()); } model.SetOrdText = dataReader["SetOrdText"].ToString(); model.SetOrdKey = dataReader["SetOrdKey"].ToString(); ojb = dataReader["State"]; if (ojb != null && ojb != DBNull.Value) { model.State = int.Parse(ojb.ToString()); } model.Remark = dataReader["Remark"].ToString(); model.AllowWorkType = dataReader["AllowWorkType"].ToString(); return(model); }
/// <summary>根据条件得到一个对象实体 /// /// </summary> public Nikita.Assist.DBManager.Model.SetOrdTable GetModelByCond(string cond) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from Tb_SetOrdTable "); if (!string.IsNullOrEmpty(cond)) { strSql.Append(" where " + cond); } strSql.Append(" limit 1"); SQLiteHelper h = new SQLiteHelper(GlobalHelp.SynchronizationDB); h.CreateCommand(strSql.ToString()); Nikita.Assist.DBManager.Model.SetOrdTable model = null; using (IDataReader dataReader = h.ExecuteReader()) { if (dataReader.Read()) { model = ReaderBind(dataReader); } h.CloseConn(); } return(model); }
/// <summary>增加一条数据 /// /// </summary> public int Add(Nikita.Assist.DBManager.Model.SetOrdTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Tb_SetOrdTable("); strSql.Append("SetOrdText, SetOrdKey, State, Remark, AllowWorkType )"); strSql.Append(" values ("); strSql.Append("@SetOrdText, @SetOrdKey, @State, @Remark, @AllowWorkType )"); SQLiteHelper h = new SQLiteHelper(GlobalHelp.SynchronizationDB); h.CreateCommand(strSql.ToString()); if (model.SetOrdText == null) { h.AddParameter("@SetOrdText", DBNull.Value); } else { h.AddParameter("@SetOrdText", model.SetOrdText); } if (model.SetOrdKey == null) { h.AddParameter("@SetOrdKey", DBNull.Value); } else { h.AddParameter("@SetOrdKey", model.SetOrdKey); } if (model.State == null) { h.AddParameter("@State", DBNull.Value); } else { h.AddParameter("@State", model.State); } if (model.Remark == null) { h.AddParameter("@Remark", DBNull.Value); } else { h.AddParameter("@Remark", model.Remark); } if (model.AllowWorkType == null) { h.AddParameter("@AllowWorkType", DBNull.Value); } else { h.AddParameter("@AllowWorkType", model.AllowWorkType); } h.ExecuteNonQuery(); string sql2 = "select max(id) from Tb_SetOrdTable"; h.CreateCommand(sql2); int result; string obj = h.ExecuteScalar(); if (!int.TryParse(obj, out result)) { return(0); } return(result); }