using System; using System.Data; using System.Text; using System.Data.SqlClient; namespace Mtxfw.DAL { /// /// 数据访问类:freighttemplate_freight /// public partial class freighttemplate_freight : Mtxfw.Utility.Myabstract { public freighttemplate_freight() : base("freighttemplate_freight") { } /// /// 增加一条数据 /// public int Add(Mtxfw.Model.freighttemplate_freight model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into freighttemplate_freight("); strSql.Append("ifallregions,regions,firstweight,firstfreight,contweight,contfreight,fid)"); strSql.Append(" values ("); strSql.Append("@ifallregions,@regions,@firstweight,@firstfreight,@contweight,@contfreight,@fid)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters = { new SqlParameter("@ifallregions", SqlDbType.Int), new SqlParameter("@regions", SqlDbType.NText), new SqlParameter("@firstweight", SqlDbType.Money), new SqlParameter("@firstfreight", SqlDbType.Money), new SqlParameter("@contweight", SqlDbType.Money), new SqlParameter("@contfreight", SqlDbType.Money), new SqlParameter("@fid", SqlDbType.Int)}; parameters[0].Value = model.ifallregions; parameters[1].Value = model.regions; parameters[2].Value = model.firstweight; parameters[3].Value = model.firstfreight; parameters[4].Value = model.contweight; parameters[5].Value = model.contfreight; parameters[6].Value = model.fid; string obj = Mtxfw.Utility.SqlDbHelper_U.GetObject(strSql.ToString(), parameters).ToString(); if (obj == "") { return 0; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public bool Update(Mtxfw.Model.freighttemplate_freight model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update freighttemplate_freight set "); strSql.Append("ifallregions=@ifallregions,"); strSql.Append("regions=@regions,"); strSql.Append("firstweight=@firstweight,"); strSql.Append("firstfreight=@firstfreight,"); strSql.Append("contweight=@contweight,"); strSql.Append("contfreight=@contfreight"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ifallregions", SqlDbType.Int), new SqlParameter("@regions", SqlDbType.NText), new SqlParameter("@firstweight", SqlDbType.Money), new SqlParameter("@firstfreight", SqlDbType.Money), new SqlParameter("@contweight", SqlDbType.Money), new SqlParameter("@contfreight", SqlDbType.Money), new SqlParameter("@ID", SqlDbType.Int)}; parameters[0].Value = model.ifallregions; parameters[1].Value = model.regions; parameters[2].Value = model.firstweight; parameters[3].Value = model.firstfreight; parameters[4].Value = model.contweight; parameters[5].Value = model.contfreight; parameters[6].Value = model.Id; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// fid /// public int Updatefid(int fid) { String sql = "update freighttemplate_freight set fid=@fid where fid=0"; SqlParameter[] para = { new SqlParameter("@fid", SqlDbType.Int, 4) }; para[0].Value = fid; return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(sql, para); } /// /// 删除一条数据 /// public bool Delete(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from freighttemplate_freight "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 得到一个对象实体 /// public Mtxfw.Model.freighttemplate_freight GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from freighttemplate_freight "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; Mtxfw.Model.freighttemplate_freight model = new Mtxfw.Model.freighttemplate_freight(); DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.Id = Convert.ToInt32(ds.Tables[0].Rows[0]["Id"].ToString()); model.ifallregions = Convert.ToInt32(ds.Tables[0].Rows[0]["ifallregions"].ToString()); model.regions = ds.Tables[0].Rows[0]["regions"].ToString(); model.firstweight = Convert.ToDouble(ds.Tables[0].Rows[0]["firstweight"].ToString()); model.firstfreight = Convert.ToDouble(ds.Tables[0].Rows[0]["firstfreight"].ToString()); model.contweight = Convert.ToDouble(ds.Tables[0].Rows[0]["contweight"].ToString()); model.contfreight = Convert.ToDouble(ds.Tables[0].Rows[0]["contfreight"].ToString()); model.fid = Convert.ToInt32(ds.Tables[0].Rows[0]["fid"].ToString()); return model; } else { return null; } } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * "); strSql.Append(" FROM freighttemplate_freight "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } /// /// 获得前几行数据 /// public DataSet GetList(int Top, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append(" * "); strSql.Append(" FROM freighttemplate_freight "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } } }