/// <summary> /// 更新一条数据 /// </summary> public bool Update(MaterialCodeGenerator.Model.MaterialCode model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MaterialCode set "); strSql.Append("iMainClassID=@iMainClassID,"); strSql.Append("cMainClassName=@cMainClassName,"); strSql.Append("iLevel1ID=@iLevel1ID,"); strSql.Append("cLevel1Name=@cLevel1Name,"); strSql.Append("iLevel2ID=@iLevel2ID,"); strSql.Append("cLevel2Name=@cLevel2Name,"); strSql.Append("iLevel3ID=@iLevel3ID,"); strSql.Append("cLevel3Name=@cLevel3Name"); strSql.Append(" where "); SQLiteParameter[] parameters = { new SQLiteParameter("@iMainClassID", DbType.Int32, 8), new SQLiteParameter("@cMainClassName", DbType.String, 2147483647), new SQLiteParameter("@iLevel1ID", DbType.Int32, 8), new SQLiteParameter("@cLevel1Name", DbType.String, 2147483647), new SQLiteParameter("@iLevel2ID", DbType.Int32, 8), new SQLiteParameter("@cLevel2Name", DbType.String, 2147483647), new SQLiteParameter("@iLevel3ID", DbType.Int32, 8), new SQLiteParameter("@cLevel3Name", DbType.String, 2147483647) }; parameters[0].Value = model.iMainClassID; parameters[1].Value = model.cMainClassName; parameters[2].Value = model.iLevel1ID; parameters[3].Value = model.cLevel1Name; parameters[4].Value = model.iLevel2ID; parameters[5].Value = model.cLevel2Name; parameters[6].Value = model.iLevel3ID; parameters[7].Value = model.cLevel3Name; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public MaterialCodeGenerator.Model.MaterialCode DataRowToModel(DataRow row) { MaterialCodeGenerator.Model.MaterialCode model = new MaterialCodeGenerator.Model.MaterialCode(); if (row != null) { if (row["iMainClassID"] != null && row["iMainClassID"].ToString() != "") { model.iMainClassID = int.Parse(row["iMainClassID"].ToString()); } if (row["cMainClassName"] != null) { model.cMainClassName = row["cMainClassName"].ToString(); } if (row["iLevel1ID"] != null && row["iLevel1ID"].ToString() != "") { model.iLevel1ID = int.Parse(row["iLevel1ID"].ToString()); } if (row["cLevel1Name"] != null) { model.cLevel1Name = row["cLevel1Name"].ToString(); } if (row["iLevel2ID"] != null && row["iLevel2ID"].ToString() != "") { model.iLevel2ID = int.Parse(row["iLevel2ID"].ToString()); } if (row["cLevel2Name"] != null) { model.cLevel2Name = row["cLevel2Name"].ToString(); } if (row["iLevel3ID"] != null && row["iLevel3ID"].ToString() != "") { model.iLevel3ID = int.Parse(row["iLevel3ID"].ToString()); } if (row["cLevel3Name"] != null) { model.cLevel3Name = row["cLevel3Name"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public MaterialCodeGenerator.Model.MaterialCode DataRowToModel(DataRow row) { MaterialCodeGenerator.Model.MaterialCode model = new MaterialCodeGenerator.Model.MaterialCode(); if (row != null) { if (row["MainClassID"] != null) { model.MainClassID = row["MainClassID"].ToString(); } if (row["MainClassName"] != null) { model.MainClassName = row["MainClassName"].ToString(); } if (row["Level1ID"] != null) { model.Level1ID = row["Level1ID"].ToString(); } if (row["Level1Name"] != null) { model.Level1Name = row["Level1Name"].ToString(); } if (row["Level2ID"] != null) { model.Level2ID = row["Level2ID"].ToString(); } if (row["Level2Name"] != null) { model.Level2Name = row["Level2Name"].ToString(); } if (row["Level3ID"] != null) { model.Level3ID = row["Level3ID"].ToString(); } if (row["Level3Name"] != null) { model.Level3Name = row["Level3Name"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(MaterialCodeGenerator.Model.MaterialCode model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MaterialCode("); strSql.Append("MainClassID,MainClassName,Level1ID,Level1Name,Level2ID,Level2Name,Level3ID,Level3Name)"); strSql.Append(" values ("); strSql.Append("@MainClassID,@MainClassName,@Level1ID,@Level1Name,@Level2ID,@Level2Name,@Level3ID,@Level3Name)"); SQLiteParameter[] parameters = { new SQLiteParameter("@MainClassID", DbType.String, 2147483647), new SQLiteParameter("@MainClassName", DbType.String, 2147483647), new SQLiteParameter("@Level1ID", DbType.String, 2147483647), new SQLiteParameter("@Level1Name", DbType.String, 2147483647), new SQLiteParameter("@Level2ID", DbType.String, 2147483647), new SQLiteParameter("@Level2Name", DbType.String, 2147483647), new SQLiteParameter("@Level3ID", DbType.String, 2147483647), new SQLiteParameter("@Level3Name", DbType.String, 2147483647) }; parameters[0].Value = model.MainClassID; parameters[1].Value = model.MainClassName; parameters[2].Value = model.Level1ID; parameters[3].Value = model.Level1Name; parameters[4].Value = model.Level2ID; parameters[5].Value = model.Level2Name; parameters[6].Value = model.Level3ID; parameters[7].Value = model.Level3Name; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public MaterialCodeGenerator.Model.MaterialCode GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select iMainClassID,cMainClassName,iLevel1ID,cLevel1Name,iLevel2ID,cLevel2Name,iLevel3ID,cLevel3Name from MaterialCode "); strSql.Append(" where "); SQLiteParameter[] parameters = { }; MaterialCodeGenerator.Model.MaterialCode model = new MaterialCodeGenerator.Model.MaterialCode(); DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }