/// <summary> /// 增加一条数据 /// </summary> public int Add(TF.RunSafty.Model.TAB_FileGroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into TAB_FileGroup("); strSql.Append("strTypeGUID,strTypeName,strType)"); strSql.Append(" values ("); strSql.Append("@strTypeGUID,@strTypeName,@strType)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@strTypeGUID", SqlDbType.VarChar, 50), new SqlParameter("@strTypeName", SqlDbType.VarChar, 50), new SqlParameter("@strType", SqlDbType.VarChar, 50) }; parameters[0].Value = model.strTypeGUID; parameters[1].Value = model.strTypeName; parameters[2].Value = model.strType; object obj = SqlHelper.ExecuteScalar(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(TF.RunSafty.Model.TAB_FileGroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TAB_FileGroup set "); strSql.Append("strTypeGUID=@strTypeGUID,"); strSql.Append("strTypeName=@strTypeName,"); strSql.Append("strType=@strType"); strSql.Append(" where nid=@nid"); SqlParameter[] parameters = { new SqlParameter("@strTypeGUID", SqlDbType.VarChar, 50), new SqlParameter("@strTypeName", SqlDbType.VarChar, 50), new SqlParameter("@strType", SqlDbType.VarChar, 50), new SqlParameter("@nid", SqlDbType.Int, 4) }; parameters[0].Value = model.strTypeGUID; parameters[1].Value = model.strTypeName; parameters[2].Value = model.strType; parameters[3].Value = model.nid; int rows = (int)SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public TF.RunSafty.Model.TAB_FileGroup DataRowToModel(DataRow row) { TF.RunSafty.Model.TAB_FileGroup model = new TF.RunSafty.Model.TAB_FileGroup(); if (row != null) { if (row["nid"] != null && row["nid"].ToString() != "") { model.nid = int.Parse(row["nid"].ToString()); } if (row["strTypeGUID"] != null) { model.strTypeGUID = row["strTypeGUID"].ToString(); } if (row["strTypeName"] != null) { model.strTypeName = row["strTypeName"].ToString(); } if (row["strType"] != null) { model.strType = row["strType"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public TF.RunSafty.Model.TAB_FileGroup GetModel(int nid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 nid,strTypeGUID,strTypeName,strType from TAB_FileGroup "); strSql.Append(" where nid=@nid"); SqlParameter[] parameters = { new SqlParameter("@nid", SqlDbType.Int, 4) }; parameters[0].Value = nid; TF.RunSafty.Model.TAB_FileGroup model = new TF.RunSafty.Model.TAB_FileGroup(); DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }