/// <summary> /// 获取数据列表 /// </summary> /// <param name="sw">参见模型</param> /// <returns>参见模型</returns> public static IEnumerable <PEST_PESTDYNAMICPROP_Model> getListModel(PEST_PESTDYNAMICPROP_SW sw) { var result = new List <PEST_PESTDYNAMICPROP_Model>(); DataTable dt = BaseDT.PEST_PESTDYNAMICPROP.getDT(sw); for (int i = 0; i < dt.Rows.Count; i++) { PEST_PESTDYNAMICPROP_Model m = new PEST_PESTDYNAMICPROP_Model(); m.PEST_PESTDYNAMICPROPID = dt.Rows[i]["PEST_PESTDYNAMICPROPID"].ToString(); m.BIOLOGICALTYPECODE = dt.Rows[i]["BIOLOGICALTYPECODE"].ToString(); m.DYNAMICPROPCODE = dt.Rows[i]["DYNAMICPROPCODE"].ToString(); m.DYNAMICPROPCONTENT = dt.Rows[i]["DYNAMICPROPCONTENT"].ToString(); result.Add(m); } dt.Clear(); dt.Dispose(); return(result); }
/// <summary> /// 获取单条记录 /// </summary> /// <param name="sw">参见模型</param> /// <returns>参见模型</returns> public static PEST_PESTDYNAMICPROP_Model getModel(PEST_PESTDYNAMICPROP_SW sw) { DataTable dt = BaseDT.PEST_PESTDYNAMICPROP.getDT(sw); PEST_PESTDYNAMICPROP_Model m = new PEST_PESTDYNAMICPROP_Model(); if (dt.Rows.Count > 0) { int i = 0; //数据库表字段 m.PEST_PESTDYNAMICPROPID = dt.Rows[i]["PEST_PESTDYNAMICPROPID"].ToString(); m.BIOLOGICALTYPECODE = dt.Rows[i]["BIOLOGICALTYPECODE"].ToString(); m.DYNAMICPROPCODE = dt.Rows[i]["DYNAMICPROPCODE"].ToString(); m.DYNAMICPROPCONTENT = dt.Rows[i]["DYNAMICPROPCONTENT"].ToString(); //扩充字段 } dt.Clear(); dt.Dispose(); return(m); }
/// <summary> /// 保存 /// </summary> /// <param name="m">参见模型</param> /// <returns>参见模型</returns> public static Message Manager(PEST_PESTDYNAMICPROP_Model m) { return(BaseDT.PEST_PESTDYNAMICPROP.Save(m)); }
/// <summary> /// 保存 /// </summary> /// <param name="m">参见模型</param> /// <returns>参见模型</returns> public static Message Save(PEST_PESTDYNAMICPROP_Model m) { List <string> sqllist = new List <string>(); string[] arrDYNAMICPROPCODE = m.DYNAMICPROPCODE.Split(','); string[] arrDYNAMICPROPCONTENT = m.DYNAMICPROPCONTENT.Split(','); if (arrDYNAMICPROPCODE.Length - 1 > 0) { #region 先删除 StringBuilder sbDelete = new StringBuilder(); sbDelete.AppendFormat("delete from PEST_PESTDYNAMICPROP where 1=1"); sbDelete.AppendFormat(" and BIOLOGICALTYPECODE='{0}'", m.BIOLOGICALTYPECODE); DataBaseClass.ExeSql(sbDelete.ToString()); #endregion #region 再更新 StringBuilder sbInsert = new StringBuilder(); sbInsert.AppendFormat("INSERT INTO PEST_PESTDYNAMICPROP(BIOLOGICALTYPECODE, DYNAMICPROPCODE, DYNAMICPROPCONTENT)"); for (int i = 0; i < arrDYNAMICPROPCODE.Length - 1; i++) { #region 更新 if (isExists(new PEST_PESTDYNAMICPROP_SW { BIOLOGICALTYPECODE = m.BIOLOGICALTYPECODE, DYNAMICPROPCODE = arrDYNAMICPROPCODE[i] })) { StringBuilder sbUpdate = new StringBuilder(); sbUpdate.AppendFormat("UPDATE PEST_PESTDYNAMICPROP SET "); sbUpdate.AppendFormat(" DYNAMICPROPCONTENT={0},", ClsSql.saveNullField(arrDYNAMICPROPCONTENT[i])); sbUpdate.AppendFormat(" where BIOLOGICALTYPECODE= '{0}'", ClsSql.EncodeSql(m.BIOLOGICALTYPECODE)); sbUpdate.AppendFormat(" and DYNAMICPROPCODE= '{0}'", ClsSql.EncodeSql(arrDYNAMICPROPCODE[i])); sqllist.Add(sbUpdate.ToString()); } #endregion #region 添加 else { sbInsert.AppendFormat(" select '{0}'", ClsSql.EncodeSql(m.BIOLOGICALTYPECODE)); sbInsert.AppendFormat(",'{0}'", ClsSql.EncodeSql(arrDYNAMICPROPCODE[i])); sbInsert.AppendFormat(",{0}", ClsSql.saveNullField(arrDYNAMICPROPCONTENT[i])); sbInsert.AppendFormat(" UNION ALL "); } #endregion } string insertStr = sbInsert.ToString(); if (insertStr.Contains(" UNION ALL ")) { insertStr = insertStr.Substring(0, insertStr.Length - 10); sqllist.Add(insertStr); } #endregion } var y = DataBaseClass.ExecuteSqlTran(sqllist); if (y >= 0) { return(new Message(true, "保存成功!", "")); } else { return(new Message(false, "保存失败,事物回滚机制!", "")); } }