/// <summary> /// 增加一条数据 /// </summary> public int Add(Hownet.Model.BAS_Region model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BAS_Region("); strSql.Append("CnName,EnName,IsValid,IsEnd)"); strSql.Append(" values ("); strSql.Append("@CnName,@EnName,@IsValid,@IsEnd)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CnName", SqlDbType.VarChar, 50), new SqlParameter("@EnName", SqlDbType.VarChar, 50), new SqlParameter("@IsValid", SqlDbType.Bit, 1), new SqlParameter("@IsEnd", SqlDbType.Int, 4) }; parameters[0].Value = model.CnName; parameters[1].Value = model.EnName; parameters[2].Value = model.IsValid; parameters[3].Value = model.IsEnd; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hownet.Model.BAS_Region model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BAS_Region set "); strSql.Append("CnName=@CnName,"); strSql.Append("EnName=@EnName,"); strSql.Append("IsValid=@IsValid,"); strSql.Append("IsEnd=@IsEnd"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@CnName", SqlDbType.VarChar, 50), new SqlParameter("@EnName", SqlDbType.VarChar, 50), new SqlParameter("@IsValid", SqlDbType.Bit, 1), new SqlParameter("@IsEnd", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.CnName; parameters[1].Value = model.EnName; parameters[2].Value = model.IsValid; parameters[3].Value = model.IsEnd; parameters[4].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Hownet.Model.BAS_Region GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CnName,EnName,IsValid,ID,IsEnd from BAS_Region "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Hownet.Model.BAS_Region model = new Hownet.Model.BAS_Region(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.CnName = ds.Tables[0].Rows[0]["CnName"].ToString(); model.EnName = ds.Tables[0].Rows[0]["EnName"].ToString(); if (ds.Tables[0].Rows[0]["IsValid"] != null && ds.Tables[0].Rows[0]["IsValid"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsValid"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsValid"].ToString().ToLower() == "true")) { model.IsValid = true; } else { model.IsValid = false; } } if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["IsEnd"] != null && ds.Tables[0].Rows[0]["IsEnd"].ToString() != "") { model.IsEnd = int.Parse(ds.Tables[0].Rows[0]["IsEnd"].ToString()); } model.A = 1; return(model); } else { return(null); } }