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