/// <summary> /// 删除已移除的图片扩展字段 /// </summary> private void ThumDelete(IDbConnection conn, IDbTransaction trans, List <Model.site_channel_thum> thums, int channel_id) { List <Model.site_channel_thum> thum = new List <Model.site_channel_thum>(); thum = WriteDataBase.Query <Model.site_channel_thum>(conn, trans, Sql.Builder.Select("id").From(databaseprefix + "site_channel_thum").Where("channel_id=" + channel_id)).ToList(); foreach (var dr in thum) { Model.site_channel_thum model = thums.Find(p => p.id == dr.id); //查找对应的字段ID if (model == null) { WriteDataBase.Execute(conn, trans, "delete from " + databaseprefix + "site_channel_thum where channel_id=" + channel_id + " and id=" + dr.id);//删除该行 } } }
/// <summary> /// 将对象转换实体 /// </summary> public Model.site_channel DataRowToModel(DataRow row) { Model.site_channel model = new Model.site_channel(); if (row != null) { #region 主表信息====================== //利用反射获得属性的所有公共属性 Type modelType = model.GetType(); for (int i = 0; i < row.Table.Columns.Count; i++) { PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName); if (proInfo != null && row[i] != DBNull.Value) { proInfo.SetValue(model, row[i], null);//用索引值设置属性值 } } #endregion #region 子表信息====================== StringBuilder strSql = new StringBuilder(); strSql.Append("select * from " + databaseprefix + "site_channel_field"); strSql.Append(" where channel_id=" + model.id); DataTable dt = ReadDataBase.QueryFillDataSet(strSql.ToString()).Tables[0]; if (dt.Rows.Count > 0) { int rowsCount = dt.Rows.Count; List <Model.site_channel_field> models = new List <Model.site_channel_field>(); Model.site_channel_field modelt; for (int n = 0; n < rowsCount; n++) { modelt = new Model.site_channel_field(); Type modeltType = modelt.GetType(); for (int i = 0; i < dt.Rows[n].Table.Columns.Count; i++) { PropertyInfo proInfo = modeltType.GetProperty(dt.Rows[n].Table.Columns[i].ColumnName); if (proInfo != null && dt.Rows[n][i] != DBNull.Value) { proInfo.SetValue(modelt, dt.Rows[n][i], null); } } models.Add(modelt); } model.channel_fields = models; } #endregion #region 缩略图尺寸==================== StringBuilder strSql3 = new StringBuilder(); strSql3.Append("select id,title,class_id,channel_id,width,height,typeid,is_lock,add_time from " + databaseprefix + "site_channel_thum"); strSql3.Append(" where channel_id=" + model.id); DataTable ds3 = ReadDataBase.QueryFillDataSet(strSql3.ToString()).Tables[0]; if (ds3.Rows.Count > 0) { int i = ds3.Rows.Count; List <Model.site_channel_thum> models = new List <Model.site_channel_thum>(); Model.site_channel_thum modelt; for (int n = 0; n < i; n++) { modelt = new Model.site_channel_thum(); Type modeltType = modelt.GetType(); for (int j = 0; j < ds3.Rows[n].Table.Columns.Count; j++) { PropertyInfo proInfo = modeltType.GetProperty(ds3.Rows[n].Table.Columns[j].ColumnName); if (proInfo != null && ds3.Rows[n][j] != DBNull.Value) { proInfo.SetValue(modelt, ds3.Rows[n][j], null); } } models.Add(modelt); } model.channel_thums = models; } #endregion } return(model); }