using System; using System.Data; using System.Text; using System.Data.SqlClient; using ZWL.DBUtility;//请先添加引用 namespace ZWL.BLL { /// /// 类ERPProduct。 /// public class ERPProduct { public ERPProduct() { } #region Model private int _id; private string _productname; private string _productserils; private string _gongyingshang; private string _producttype; private string _xinghao; private string _danwei; private string _chengben; private string _chushou; private decimal? _rukusum; private decimal? _chukusum; private decimal? _nowkucun; private decimal? _kucunbaojing; private string _cunchuweizhi; private string _chanpinmiaoshu; private string _backinfo; /// /// 规格尺寸 /// private string _ProductSize; public string ProductSize { get { return _ProductSize; } set { _ProductSize = value; } } /// /// 性能 /// private string _Performance; public string Performance { get { return _Performance; } set { _Performance = value; } } /// /// 镀层 /// private string _Coating; public string Coating { get { return _Coating; } set { _Coating = value; } } /// /// 表面处理 /// private string _SurfaceTreatment; public string SurfaceTreatment { get { return _SurfaceTreatment; } set { _SurfaceTreatment = value; } } /// /// 充磁方向 /// private string _MagnetizingDirection; public string MagnetizingDirection { get { return _MagnetizingDirection; } set { _MagnetizingDirection = value; } } /// /// 公差 /// private string _Tolerance; public string Tolerance { get { return _Tolerance; } set { _Tolerance = value; } } /// /// 是否含税 /// private int _IsContainingTax; public int IsContainingTax { get { return _IsContainingTax; } set { _IsContainingTax = value; } } /// /// /// public int ID { set { _id = value; } get { return _id; } } /// /// 产品名称 /// public string ProductName { set { _productname = value; } get { return _productname; } } /// /// 产品编码 /// public string ProductSerils { set { _productserils = value; } get { return _productserils; } } /// /// 产品供应商 /// public string GongYingShang { set { _gongyingshang = value; } get { return _gongyingshang; } } /// /// 产品类别 /// public string ProductType { set { _producttype = value; } get { return _producttype; } } /// /// 产品型号 /// public string XingHao { set { _xinghao = value; } get { return _xinghao; } } /// /// 计量单位 /// public string DanWei { set { _danwei = value; } get { return _danwei; } } /// /// 成本价 /// public string ChengBen { set { _chengben = value; } get { return _chengben; } } /// /// 出售价 /// public string ChuShou { set { _chushou = value; } get { return _chushou; } } /// /// 入库总量 /// public decimal? RuKuSum { set { _rukusum = value; } get { return _rukusum; } } /// /// 出库总量 /// public decimal? ChuKuSum { set { _chukusum = value; } get { return _chukusum; } } /// /// 当前库存 /// public decimal? NowKuCun { set { _nowkucun = value; } get { return _nowkucun; } } /// /// 库存报警量 /// public decimal? KuCunBaoJing { set { _kucunbaojing = value; } get { return _kucunbaojing; } } /// /// 存储位置 /// public string CunChuWeiZhi { set { _cunchuweizhi = value; } get { return _cunchuweizhi; } } /// /// 产品描述 /// public string ChanPinMiaoShu { set { _chanpinmiaoshu = value; } get { return _chanpinmiaoshu; } } /// /// 备注信息 /// public string BackInfo { set { _backinfo = value; } get { return _backinfo; } } #endregion Model #region 成员方法 /// /// 得到一个对象实体 /// public ERPProduct(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID,ProductName,ProductSerils,GongYingShang,ProductType,XingHao,DanWei,ChengBen,ChuShou,RuKuSum,ChuKuSum,NowKuCun,KuCunBaoJing,CunChuWeiZhi,ChanPinMiaoShu,BackInfo, "); strSql.Append(" ProductSize, Performance, Coating, SurfaceTreatment, MagnetizingDirection, Tolerance, IsContainingTax "); strSql.Append(" FROM ERPProduct "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = ID; DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"].ToString() != "") { ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } ProductName = ds.Tables[0].Rows[0]["ProductName"].ToString(); ProductSerils = ds.Tables[0].Rows[0]["ProductSerils"].ToString(); GongYingShang = ds.Tables[0].Rows[0]["GongYingShang"].ToString(); ProductType = ds.Tables[0].Rows[0]["ProductType"].ToString(); XingHao = ds.Tables[0].Rows[0]["XingHao"].ToString(); DanWei = ds.Tables[0].Rows[0]["DanWei"].ToString(); ChengBen = ds.Tables[0].Rows[0]["ChengBen"].ToString(); ChuShou = ds.Tables[0].Rows[0]["ChuShou"].ToString(); if (ds.Tables[0].Rows[0]["RuKuSum"].ToString() != "") { RuKuSum = decimal.Parse(ds.Tables[0].Rows[0]["RuKuSum"].ToString()); } if (ds.Tables[0].Rows[0]["ChuKuSum"].ToString() != "") { ChuKuSum = decimal.Parse(ds.Tables[0].Rows[0]["ChuKuSum"].ToString()); } if (ds.Tables[0].Rows[0]["NowKuCun"].ToString() != "") { NowKuCun = decimal.Parse(ds.Tables[0].Rows[0]["NowKuCun"].ToString()); } if (ds.Tables[0].Rows[0]["KuCunBaoJing"].ToString() != "") { KuCunBaoJing = decimal.Parse(ds.Tables[0].Rows[0]["KuCunBaoJing"].ToString()); } CunChuWeiZhi = ds.Tables[0].Rows[0]["CunChuWeiZhi"].ToString(); ChanPinMiaoShu = ds.Tables[0].Rows[0]["ChanPinMiaoShu"].ToString(); BackInfo = ds.Tables[0].Rows[0]["BackInfo"].ToString(); ProductSize = ds.Tables[0].Rows[0]["ProductSize"].ToString(); Performance = ds.Tables[0].Rows[0]["Performance"].ToString(); Coating = ds.Tables[0].Rows[0]["Coating"].ToString(); SurfaceTreatment = ds.Tables[0].Rows[0]["SurfaceTreatment"].ToString(); MagnetizingDirection = ds.Tables[0].Rows[0]["MagnetizingDirection"].ToString(); Tolerance = ds.Tables[0].Rows[0]["Tolerance"].ToString(); IsContainingTax = Int32.Parse(ds.Tables[0].Rows[0]["IsContainingTax"].ToString()); } } /// /// 得到最大ID /// public int GetMaxId() { return DbHelperSQL.GetMaxID("ID", "ERPProduct"); } /// /// 是否存在该记录 /// public bool Exists(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from ERPProduct"); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = ID; return DbHelperSQL.Exists(strSql.ToString(), parameters); } /// /// 增加一条数据 /// public int Add() { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ERPProduct("); strSql.Append("ProductName,ProductSerils,GongYingShang,ProductType,XingHao,DanWei,ChengBen,ChuShou,RuKuSum,ChuKuSum,NowKuCun,KuCunBaoJing,CunChuWeiZhi,ChanPinMiaoShu,BackInfo,ProductSize, Performance, Coating, SurfaceTreatment, MagnetizingDirection, Tolerance, IsContainingTax)"); strSql.Append(" values ("); strSql.Append("@ProductName,@ProductSerils,@GongYingShang,@ProductType,@XingHao,@DanWei,@ChengBen,@ChuShou,@RuKuSum,@ChuKuSum,@NowKuCun,@KuCunBaoJing,@CunChuWeiZhi,@ChanPinMiaoShu,@BackInfo,@ProductSize, @Performance, @Coating, @SurfaceTreatment, @MagnetizingDirection, @Tolerance, @IsContainingTax)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ProductName", SqlDbType.VarChar,50), new SqlParameter("@ProductSerils", SqlDbType.VarChar,50), new SqlParameter("@GongYingShang", SqlDbType.VarChar,50), new SqlParameter("@ProductType", SqlDbType.VarChar,50), new SqlParameter("@XingHao", SqlDbType.VarChar,50), new SqlParameter("@DanWei", SqlDbType.VarChar,50), new SqlParameter("@ChengBen", SqlDbType.VarChar,50), new SqlParameter("@ChuShou", SqlDbType.VarChar,50), new SqlParameter("@RuKuSum", SqlDbType.Decimal,9), new SqlParameter("@ChuKuSum", SqlDbType.Decimal,9), new SqlParameter("@NowKuCun", SqlDbType.Decimal,9), new SqlParameter("@KuCunBaoJing", SqlDbType.Decimal,9), new SqlParameter("@CunChuWeiZhi", SqlDbType.VarChar,50), new SqlParameter("@ChanPinMiaoShu", SqlDbType.VarChar,5000), new SqlParameter("@BackInfo", SqlDbType.VarChar,5000), new SqlParameter("@ProductSize", SqlDbType.VarChar,50), new SqlParameter("@Performance", SqlDbType.VarChar,50), new SqlParameter("@Coating", SqlDbType.VarChar,50), new SqlParameter("@SurfaceTreatment", SqlDbType.VarChar,50), new SqlParameter("@MagnetizingDirection", SqlDbType.VarChar,50), new SqlParameter("@Tolerance", SqlDbType.VarChar,50), new SqlParameter("@IsContainingTax", SqlDbType.Int,4)}; parameters[0].Value = ProductName; parameters[1].Value = ProductSerils; parameters[2].Value = GongYingShang; parameters[3].Value = ProductType; parameters[4].Value = XingHao; parameters[5].Value = DanWei; parameters[6].Value = ChengBen; parameters[7].Value = ChuShou; parameters[8].Value = RuKuSum; parameters[9].Value = ChuKuSum; parameters[10].Value = NowKuCun; parameters[11].Value = KuCunBaoJing; parameters[12].Value = CunChuWeiZhi; parameters[13].Value = ChanPinMiaoShu; parameters[14].Value = BackInfo; parameters[15].Value = ProductSize; parameters[16].Value = Performance; parameters[17].Value = Coating; parameters[18].Value = SurfaceTreatment; parameters[19].Value = MagnetizingDirection; parameters[20].Value = Tolerance; parameters[21].Value = IsContainingTax; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return 1; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public void Update() { StringBuilder strSql = new StringBuilder(); strSql.Append("update ERPProduct set "); strSql.Append("ProductName=@ProductName,"); strSql.Append("ProductSerils=@ProductSerils,"); strSql.Append("GongYingShang=@GongYingShang,"); strSql.Append("ProductType=@ProductType,"); strSql.Append("XingHao=@XingHao,"); strSql.Append("DanWei=@DanWei,"); strSql.Append("ChengBen=@ChengBen,"); strSql.Append("ChuShou=@ChuShou,"); strSql.Append("RuKuSum=@RuKuSum,"); strSql.Append("ChuKuSum=@ChuKuSum,"); strSql.Append("NowKuCun=@NowKuCun,"); strSql.Append("KuCunBaoJing=@KuCunBaoJing,"); strSql.Append("CunChuWeiZhi=@CunChuWeiZhi,"); strSql.Append("ChanPinMiaoShu=@ChanPinMiaoShu,"); strSql.Append("BackInfo=@BackInfo,"); strSql.Append("ProductSize=@ProductSize,"); strSql.Append("Performance=@Performance,"); strSql.Append("Coating=@Coating,"); strSql.Append("SurfaceTreatment=@SurfaceTreatment,"); strSql.Append("MagnetizingDirection=@MagnetizingDirection,"); strSql.Append("Tolerance=@Tolerance,"); strSql.Append("IsContainingTax=@IsContainingTax "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4), new SqlParameter("@ProductName", SqlDbType.VarChar,50), new SqlParameter("@ProductSerils", SqlDbType.VarChar,50), new SqlParameter("@GongYingShang", SqlDbType.VarChar,50), new SqlParameter("@ProductType", SqlDbType.VarChar,50), new SqlParameter("@XingHao", SqlDbType.VarChar,50), new SqlParameter("@DanWei", SqlDbType.VarChar,50), new SqlParameter("@ChengBen", SqlDbType.VarChar,50), new SqlParameter("@ChuShou", SqlDbType.VarChar,50), new SqlParameter("@RuKuSum", SqlDbType.Decimal,9), new SqlParameter("@ChuKuSum", SqlDbType.Decimal,9), new SqlParameter("@NowKuCun", SqlDbType.Decimal,9), new SqlParameter("@KuCunBaoJing", SqlDbType.Decimal,9), new SqlParameter("@CunChuWeiZhi", SqlDbType.VarChar,50), new SqlParameter("@ChanPinMiaoShu", SqlDbType.VarChar,5000), new SqlParameter("@BackInfo", SqlDbType.VarChar,5000), new SqlParameter("@ProductSize", SqlDbType.VarChar,50), new SqlParameter("@Performance", SqlDbType.VarChar,50), new SqlParameter("@Coating", SqlDbType.VarChar,50), new SqlParameter("@SurfaceTreatment", SqlDbType.VarChar,50), new SqlParameter("@MagnetizingDirection", SqlDbType.VarChar,50), new SqlParameter("@Tolerance", SqlDbType.VarChar,50), new SqlParameter("@IsContainingTax", SqlDbType.Int,4)}; parameters[0].Value = ID; parameters[1].Value = ProductName; parameters[2].Value = ProductSerils; parameters[3].Value = GongYingShang; parameters[4].Value = ProductType; parameters[5].Value = XingHao; parameters[6].Value = DanWei; parameters[7].Value = ChengBen; parameters[8].Value = ChuShou; parameters[9].Value = RuKuSum; parameters[10].Value = ChuKuSum; parameters[11].Value = NowKuCun; parameters[12].Value = KuCunBaoJing; parameters[13].Value = CunChuWeiZhi; parameters[14].Value = ChanPinMiaoShu; parameters[15].Value = BackInfo; parameters[16].Value = ProductSize; parameters[17].Value = Performance; parameters[18].Value = Coating; parameters[19].Value = SurfaceTreatment; parameters[20].Value = MagnetizingDirection; parameters[21].Value = Tolerance; parameters[22].Value = IsContainingTax; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); } /// /// 删除一条数据 /// public void Delete(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from ERPProduct "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = ID; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); } /// /// 得到一个对象实体 /// public void GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,ProductName,ProductSerils,GongYingShang,ProductType,XingHao,DanWei,ChengBen,ChuShou,RuKuSum,ChuKuSum,NowKuCun,KuCunBaoJing,CunChuWeiZhi,ChanPinMiaoShu,BackInfo,ProductSize, Performance, Coating, SurfaceTreatment, MagnetizingDirection, Tolerance, IsContainingTax "); strSql.Append(" FROM ERPProduct "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = ID; DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"].ToString() != "") { ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } ProductName = ds.Tables[0].Rows[0]["ProductName"].ToString(); ProductSerils = ds.Tables[0].Rows[0]["ProductSerils"].ToString(); GongYingShang = ds.Tables[0].Rows[0]["GongYingShang"].ToString(); ProductType = ds.Tables[0].Rows[0]["ProductType"].ToString(); XingHao = ds.Tables[0].Rows[0]["XingHao"].ToString(); DanWei = ds.Tables[0].Rows[0]["DanWei"].ToString(); ChengBen = ds.Tables[0].Rows[0]["ChengBen"].ToString(); ChuShou = ds.Tables[0].Rows[0]["ChuShou"].ToString(); if (ds.Tables[0].Rows[0]["RuKuSum"].ToString() != "") { RuKuSum = decimal.Parse(ds.Tables[0].Rows[0]["RuKuSum"].ToString()); } if (ds.Tables[0].Rows[0]["ChuKuSum"].ToString() != "") { ChuKuSum = decimal.Parse(ds.Tables[0].Rows[0]["ChuKuSum"].ToString()); } if (ds.Tables[0].Rows[0]["NowKuCun"].ToString() != "") { NowKuCun = decimal.Parse(ds.Tables[0].Rows[0]["NowKuCun"].ToString()); } if (ds.Tables[0].Rows[0]["KuCunBaoJing"].ToString() != "") { KuCunBaoJing = decimal.Parse(ds.Tables[0].Rows[0]["KuCunBaoJing"].ToString()); } CunChuWeiZhi = ds.Tables[0].Rows[0]["CunChuWeiZhi"].ToString(); ChanPinMiaoShu = ds.Tables[0].Rows[0]["ChanPinMiaoShu"].ToString(); BackInfo = ds.Tables[0].Rows[0]["BackInfo"].ToString(); ProductSize = ds.Tables[0].Rows[0]["ProductSize"].ToString(); Performance = ds.Tables[0].Rows[0]["Performance"].ToString(); Coating = ds.Tables[0].Rows[0]["Coating"].ToString(); SurfaceTreatment = ds.Tables[0].Rows[0]["SurfaceTreatment"].ToString(); MagnetizingDirection = ds.Tables[0].Rows[0]["MagnetizingDirection"].ToString(); Tolerance = ds.Tables[0].Rows[0]["Tolerance"].ToString(); IsContainingTax = Int32.Parse(ds.Tables[0].Rows[0]["IsContainingTax"].ToString()); } } public void GetModelByName(string pProductName) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,ProductName,ProductSerils,GongYingShang,ProductType,XingHao,DanWei,ChengBen,ChuShou,RuKuSum,ChuKuSum,NowKuCun,KuCunBaoJing,CunChuWeiZhi,ChanPinMiaoShu,BackInfo,ProductSize, Performance, Coating, SurfaceTreatment, MagnetizingDirection, Tolerance, IsContainingTax "); strSql.Append(" FROM ERPProduct "); strSql.Append(" where ProductName=@ProductName "); SqlParameter[] parameters = { new SqlParameter("@ProductName", SqlDbType.VarChar,50)}; parameters[0].Value = pProductName; DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"].ToString() != "") { ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } ProductName = ds.Tables[0].Rows[0]["ProductName"].ToString(); ProductSerils = ds.Tables[0].Rows[0]["ProductSerils"].ToString(); GongYingShang = ds.Tables[0].Rows[0]["GongYingShang"].ToString(); ProductType = ds.Tables[0].Rows[0]["ProductType"].ToString(); XingHao = ds.Tables[0].Rows[0]["XingHao"].ToString(); DanWei = ds.Tables[0].Rows[0]["DanWei"].ToString(); ChengBen = ds.Tables[0].Rows[0]["ChengBen"].ToString(); ChuShou = ds.Tables[0].Rows[0]["ChuShou"].ToString(); if (ds.Tables[0].Rows[0]["RuKuSum"].ToString() != "") { RuKuSum = decimal.Parse(ds.Tables[0].Rows[0]["RuKuSum"].ToString()); } if (ds.Tables[0].Rows[0]["ChuKuSum"].ToString() != "") { ChuKuSum = decimal.Parse(ds.Tables[0].Rows[0]["ChuKuSum"].ToString()); } if (ds.Tables[0].Rows[0]["NowKuCun"].ToString() != "") { NowKuCun = decimal.Parse(ds.Tables[0].Rows[0]["NowKuCun"].ToString()); } if (ds.Tables[0].Rows[0]["KuCunBaoJing"].ToString() != "") { KuCunBaoJing = decimal.Parse(ds.Tables[0].Rows[0]["KuCunBaoJing"].ToString()); } CunChuWeiZhi = ds.Tables[0].Rows[0]["CunChuWeiZhi"].ToString(); ChanPinMiaoShu = ds.Tables[0].Rows[0]["ChanPinMiaoShu"].ToString(); BackInfo = ds.Tables[0].Rows[0]["BackInfo"].ToString(); ProductSize = ds.Tables[0].Rows[0]["ProductSize"].ToString(); Performance = ds.Tables[0].Rows[0]["Performance"].ToString(); Coating = ds.Tables[0].Rows[0]["Coating"].ToString(); SurfaceTreatment = ds.Tables[0].Rows[0]["SurfaceTreatment"].ToString(); MagnetizingDirection = ds.Tables[0].Rows[0]["MagnetizingDirection"].ToString(); Tolerance = ds.Tables[0].Rows[0]["Tolerance"].ToString(); IsContainingTax = Int32.Parse(ds.Tables[0].Rows[0]["IsContainingTax"].ToString()); } } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * "); strSql.Append(" FROM ERPProduct "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return DbHelperSQL.Query(strSql.ToString()); } #endregion 成员方法 } }