Foods.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:6k
- //------------------------------------------------------------------------------
- // 创建标识: Copyright (C) 2009 Socansoft.com 版权所有
- // 创建描述: SocanCode代码生成器 V4.3.3.5 自动创建于 2009-12-23 17:01:32
- //
- // 功能描述:
- //
- // 修改标识:
- // 修改描述:
- //------------------------------------------------------------------------------
- using System;
- using System.Data;
- using System.Data.Common;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- namespace SqlServerDAL
- {
- /// <summary>
- /// 数据访问类 Foods
- /// </summary>
- public class Foods : DALHelper
- {
- /// <summary>
- /// 增加一条数据
- /// </summary>
- public int Add(Model.Foods model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("INSERT INTO Foods(");
- strSql.Append("YCLBMC,CM,YCDW,YCDWDH,JG,BZ)");
- strSql.Append(" VALUES (");
- strSql.Append("@in_YCLBMC,@in_CM,@in_YCDW,@in_YCDWDH,@in_JG,@in_BZ)");
DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_YCLBMC", DbType.AnsiString, model.YCLBMC),
- DataBaseOAHelper.CreateInDbParameter("@in_CM", DbType.AnsiString, model.CM),
- DataBaseOAHelper.CreateInDbParameter("@in_YCDW", DbType.AnsiString, model.YCDW),
- DataBaseOAHelper.CreateInDbParameter("@in_YCDWDH", DbType.AnsiString, model.YCDWDH),
- DataBaseOAHelper.CreateInDbParameter("@in_JG", DbType.Currency, model.JG),
- DataBaseOAHelper.CreateInDbParameter("@in_BZ", DbType.String, model.BZ)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 更新一条数据
- /// </summary>
- public int Update(Model.Foods model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("UPDATE Foods SET ");
- strSql.Append("YCLBMC=@in_YCLBMC,");
- strSql.Append("CM=@in_CM,");
- strSql.Append("YCDW=@in_YCDW,");
- strSql.Append("YCDWDH=@in_YCDWDH,");
- strSql.Append("JG=@in_JG,");
- strSql.Append("BZ=@in_BZ");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_YCLBMC", DbType.AnsiString, model.YCLBMC),
- DataBaseOAHelper.CreateInDbParameter("@in_CM", DbType.AnsiString, model.CM),
- DataBaseOAHelper.CreateInDbParameter("@in_YCDW", DbType.AnsiString, model.YCDW),
- DataBaseOAHelper.CreateInDbParameter("@in_YCDWDH", DbType.AnsiString, model.YCDWDH),
- DataBaseOAHelper.CreateInDbParameter("@in_JG", DbType.Currency, model.JG),
- DataBaseOAHelper.CreateInDbParameter("@in_BZ", DbType.String, model.BZ),
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, model.ID)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 删除一条数据
- /// </summary>
- public int Delete(int ID)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("DELETE FROM Foods ");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 是否存在该记录
- /// </summary>
- public bool Exists(int ID)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT COUNT(1) FROM Foods");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
- object obj = DataBaseOAHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), cmdParms);
- return DataBaseOAHelper.GetInt(obj) > 0;
- }
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- public Model.Foods GetModel(int ID)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT * FROM Foods ");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
- Model.Foods model = null;
- using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), cmdParms))
- {
- while (dr.Read())
- {
- model = GetModel(dr);
- }
- return model;
- }
- }
- /// <summary>
- /// 获取泛型数据列表
- /// </summary>
- public List<Model.Foods> GetList()
- {
- StringBuilder strSql = new StringBuilder("SELECT * FROM Foods");
- using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null))
- {
- List<Model.Foods> lst = GetList(dr);
- return lst;
- }
- }
- /// <summary>
- /// 得到数据条数
- /// </summary>
- public int GetCount(string condition)
- {
- return DataBaseOAHelper.GetCount("Foods", condition);
- }
- /// <summary>
- /// 分页获取泛型数据列表
- /// </summary>
- public List<Model.Foods> GetPageList(int pageSize, int pageIndex, string fldSort, bool fldDir, string condition)
- {
- using (DbDataReader dr = DataBaseOAHelper.GetPageList("Foods", pageSize, pageIndex, fldSort, fldDir, condition))
- {
- List<Model.Foods> lst = GetList(dr);
- return lst;
- }
- }
- #region -------- 私有方法,通常情况下无需修改 --------
- /// <summary>
- /// 由一行数据得到一个实体
- /// </summary>
- private Model.Foods GetModel(DbDataReader dr)
- {
- Model.Foods model = new Model.Foods();
- model.ID = DataBaseOAHelper.GetInt(dr["ID"]);
- model.YCLBMC = DataBaseOAHelper.GetString(dr["YCLBMC"]);
- model.CM = DataBaseOAHelper.GetString(dr["CM"]);
- model.YCDW = DataBaseOAHelper.GetString(dr["YCDW"]);
- model.YCDWDH = DataBaseOAHelper.GetString(dr["YCDWDH"]);
- model.JG = DataBaseOAHelper.GetDecimal(dr["JG"]);
- model.BZ = DataBaseOAHelper.GetString(dr["BZ"]);
- return model;
- }
- /// <summary>
- /// 由DbDataReader得到泛型数据列表
- /// </summary>
- private List<Model.Foods> GetList(DbDataReader dr)
- {
- List<Model.Foods> lst = new List<Model.Foods>();
- while (dr.Read())
- {
- lst.Add(GetModel(dr));
- }
- return lst;
- }
- #endregion
- }
- }