/// <summary> /// 增加一条数据 /// </summary> public int Add(university.Model.CCOM.Agency model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Agency("); strSql.Append("Agency_name,Agency_father,Agency_type,Agency_status"); strSql.Append(") values ("); strSql.Append("@Agency_name,@Agency_father,@Agency_type,@Agency_status"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Agency_name", SqlDbType.VarChar, 128), new SqlParameter("@Agency_father", SqlDbType.Int, 4), new SqlParameter("@Agency_type", SqlDbType.Int, 4), new SqlParameter("@Agency_status", SqlDbType.Bit, 1) }; parameters[0].Value = model.Agency_name; parameters[1].Value = model.Agency_father; parameters[2].Value = model.Agency_type; parameters[3].Value = model.Agency_status; object obj = DBSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public university.Model.CCOM.Agency GetModel(int Agency_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select Agency_id, Agency_name, Agency_father, Agency_type, Agency_status "); strSql.Append(" from Agency "); strSql.Append(" where Agency_id=@Agency_id"); SqlParameter[] parameters = { new SqlParameter("@Agency_id", SqlDbType.Int, 4) }; parameters[0].Value = Agency_id; university.Model.CCOM.Agency model = new university.Model.CCOM.Agency(); DataSet ds = DBSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Agency_id"].ToString() != "") { model.Agency_id = int.Parse(ds.Tables[0].Rows[0]["Agency_id"].ToString()); } model.Agency_name = ds.Tables[0].Rows[0]["Agency_name"].ToString(); if (ds.Tables[0].Rows[0]["Agency_father"].ToString() != "") { model.Agency_father = int.Parse(ds.Tables[0].Rows[0]["Agency_father"].ToString()); } if (ds.Tables[0].Rows[0]["Agency_type"].ToString() != "") { model.Agency_type = int.Parse(ds.Tables[0].Rows[0]["Agency_type"].ToString()); } if (ds.Tables[0].Rows[0]["Agency_status"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Agency_status"].ToString() == "1") || (ds.Tables[0].Rows[0]["Agency_status"].ToString().ToLower() == "true")) { model.Agency_status = true; } else { model.Agency_status = false; } } return(model); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public university.Model.CCOM.Agency GetModel(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select Agency_id, Agency_name, Agency_father, Agency_type, Agency_status "); strSql.Append(" from Agency "); strSql.Append(" where " + strWhere); university.Model.CCOM.Agency model = new university.Model.CCOM.Agency(); DataSet ds = DBSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Agency_id"].ToString() != "") { model.Agency_id = int.Parse(ds.Tables[0].Rows[0]["Agency_id"].ToString()); } model.Agency_name = ds.Tables[0].Rows[0]["Agency_name"].ToString(); if (ds.Tables[0].Rows[0]["Agency_father"].ToString() != "") { model.Agency_father = int.Parse(ds.Tables[0].Rows[0]["Agency_father"].ToString()); } if (ds.Tables[0].Rows[0]["Agency_type"].ToString() != "") { model.Agency_type = int.Parse(ds.Tables[0].Rows[0]["Agency_type"].ToString()); } if (ds.Tables[0].Rows[0]["Agency_status"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Agency_status"].ToString() == "1") || (ds.Tables[0].Rows[0]["Agency_status"].ToString().ToLower() == "true")) { model.Agency_status = true; } else { model.Agency_status = false; } } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(university.Model.CCOM.Agency model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Agency set "); strSql.Append(" Agency_name = @Agency_name , "); strSql.Append(" Agency_father = @Agency_father , "); strSql.Append(" Agency_type = @Agency_type , "); strSql.Append(" Agency_status = @Agency_status "); strSql.Append(" where Agency_id=@Agency_id "); SqlParameter[] parameters = { new SqlParameter("@Agency_id", SqlDbType.Int, 4), new SqlParameter("@Agency_name", SqlDbType.VarChar, 128), new SqlParameter("@Agency_father", SqlDbType.Int, 4), new SqlParameter("@Agency_type", SqlDbType.Int, 4), new SqlParameter("@Agency_status", SqlDbType.Bit, 1) }; parameters[0].Value = model.Agency_id; parameters[1].Value = model.Agency_name; parameters[2].Value = model.Agency_father; parameters[3].Value = model.Agency_type; parameters[4].Value = model.Agency_status; int rows = DBSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }