/// <summary> /// 增加一条数据 /// </summary> public int Add(Hownet.Model.HadnBackPrice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into HadnBackPrice("); strSql.Append("MaterielID,WorkingID,Price,DateTime,IsUse)"); strSql.Append(" values ("); strSql.Append("@MaterielID,@WorkingID,@Price,@DateTime,@IsUse)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@MaterielID", SqlDbType.Int, 4), new SqlParameter("@WorkingID", SqlDbType.Int, 4), new SqlParameter("@Price", SqlDbType.Decimal, 9), new SqlParameter("@DateTime", SqlDbType.DateTime), new SqlParameter("@IsUse", SqlDbType.TinyInt, 1) }; parameters[0].Value = model.MaterielID; parameters[1].Value = model.WorkingID; parameters[2].Value = model.Price; parameters[3].Value = model.DateTime; parameters[4].Value = model.IsUse; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Hownet.Model.HadnBackPrice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update HadnBackPrice set "); strSql.Append("MaterielID=@MaterielID,"); strSql.Append("WorkingID=@WorkingID,"); strSql.Append("Price=@Price,"); strSql.Append("DateTime=@DateTime,"); strSql.Append("IsUse=@IsUse"); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@MaterielID", SqlDbType.Int, 4), new SqlParameter("@WorkingID", SqlDbType.Int, 4), new SqlParameter("@Price", SqlDbType.Decimal, 9), new SqlParameter("@DateTime", SqlDbType.DateTime), new SqlParameter("@IsUse", SqlDbType.TinyInt, 1) }; parameters[0].Value = model.ID; parameters[1].Value = model.MaterielID; parameters[2].Value = model.WorkingID; parameters[3].Value = model.Price; parameters[4].Value = model.DateTime; parameters[5].Value = model.IsUse; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public Hownet.Model.HadnBackPrice GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,MaterielID,WorkingID,Price,DateTime,IsUse from HadnBackPrice "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Hownet.Model.HadnBackPrice model = new Hownet.Model.HadnBackPrice(); 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()); } if (ds.Tables[0].Rows[0]["MaterielID"].ToString() != "") { model.MaterielID = int.Parse(ds.Tables[0].Rows[0]["MaterielID"].ToString()); } if (ds.Tables[0].Rows[0]["WorkingID"].ToString() != "") { model.WorkingID = int.Parse(ds.Tables[0].Rows[0]["WorkingID"].ToString()); } if (ds.Tables[0].Rows[0]["Price"].ToString() != "") { model.Price = decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString()); } if (ds.Tables[0].Rows[0]["DateTime"].ToString() != "") { model.DateTime = DateTime.Parse(ds.Tables[0].Rows[0]["DateTime"].ToString()); } if (ds.Tables[0].Rows[0]["IsUse"].ToString() != "") { model.IsUse = int.Parse(ds.Tables[0].Rows[0]["IsUse"].ToString()); } return(model); } else { return(null); } }