新增记录时返回自增ID (DAL数据访问类)

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using EXDataControl;
using Utility;

namespace BasicInformation
{
	/// <summary>
	/// 类pdt_MaterialMasterBill。
	/// </summary>
	[Serializable]
	public partial class pdt_MaterialMasterBill
	{
        public pdt_MaterialMasterBill(EXDataControl.EXDataCenter dc)
        {
            DbHelperSQL = dc;
        }

        EXDataControl.EXDataCenter DbHelperSQL;

		#region Model
		private int _autoid;
		private string _materialcode;
		private string _materialname;
		private string _nnemoniccode;
		private string _spellcode;
		private int? _classfication;
		private string _color;
		private decimal? _size=0M;
		private decimal? _weight=0M;
		private bool _isvirtual;
		private int? _processroute;
		private int? _materialplantype;
		private int? _materialstatustype;
		private int? _purchasingleadcycle;
		private int? _preparationcycle;
		private int? _repleasecycle;
		private decimal? _costprice;
		private decimal? _price;
		private DateTime? _begindate;
		private DateTime? _enddate;
		private string _remark;
		private bool _active;
		private string _loginby;
		private DateTime? _logindate;
		private string _updateby;
		private DateTime? _updatedate;
		/// <summary>
		///
		/// </summary>
		public int AutoID
		{
			set{ _autoid=value;}
			get{return _autoid;}
		}
		/// <summary>
		///
		/// </summary>
		public string MaterialCode
		{
			set{ _materialcode=value;}
			get{return _materialcode;}
		}
		/// <summary>
		///
		/// </summary>
		public string MaterialName
		{
			set{ _materialname=value;}
			get{return _materialname;}
		}
		/// <summary>
		///
		/// </summary>
		public string NnemonicCode
		{
			set{ _nnemoniccode=value;}
			get{return _nnemoniccode;}
		}
		/// <summary>
		///
		/// </summary>
		public string SpellCode
		{
			set{ _spellcode=value;}
			get{return _spellcode;}
		}
		/// <summary>
		///
		/// </summary>
		public int? ClassFication
		{
			set{ _classfication=value;}
			get{return _classfication;}
		}
		/// <summary>
		///
		/// </summary>
		public string Color
		{
			set{ _color=value;}
			get{return _color;}
		}
		/// <summary>
		///
		/// </summary>
		public decimal? Size
		{
			set{ _size=value;}
			get{return _size;}
		}
		/// <summary>
		///
		/// </summary>
		public decimal? Weight
		{
			set{ _weight=value;}
			get{return _weight;}
		}
		/// <summary>
		///
		/// </summary>
		public bool IsVirtual
		{
			set{ _isvirtual=value;}
			get{return _isvirtual;}
		}
		/// <summary>
		///
		/// </summary>
		public int? ProcessRoute
		{
			set{ _processroute=value;}
			get{return _processroute;}
		}
		/// <summary>
		///
		/// </summary>
		public int? MaterialPlanType
		{
			set{ _materialplantype=value;}
			get{return _materialplantype;}
		}
		/// <summary>
		///
		/// </summary>
		public int? MaterialStatusType
		{
			set{ _materialstatustype=value;}
			get{return _materialstatustype;}
		}
		/// <summary>
		///
		/// </summary>
		public int? PurchasingLeadCycle
		{
			set{ _purchasingleadcycle=value;}
			get{return _purchasingleadcycle;}
		}
		/// <summary>
		///
		/// </summary>
		public int? PreparationCycle
		{
			set{ _preparationcycle=value;}
			get{return _preparationcycle;}
		}
		/// <summary>
		///
		/// </summary>
		public int? RepleaseCycle
		{
			set{ _repleasecycle=value;}
			get{return _repleasecycle;}
		}
		/// <summary>
		///
		/// </summary>
		public decimal? CostPrice
		{
			set{ _costprice=value;}
			get{return _costprice;}
		}
		/// <summary>
		///
		/// </summary>
		public decimal? Price
		{
			set{ _price=value;}
			get{return _price;}
		}
		/// <summary>
		///
		/// </summary>
		public DateTime? BeginDate
		{
			set{ _begindate=value;}
			get{return _begindate;}
		}
		/// <summary>
		///
		/// </summary>
		public DateTime? EndDate
		{
			set{ _enddate=value;}
			get{return _enddate;}
		}
		/// <summary>
		///
		/// </summary>
		public string Remark
		{
			set{ _remark=value;}
			get{return _remark;}
		}
		/// <summary>
		///
		/// </summary>
		public bool Active
		{
			set{ _active=value;}
			get{return _active;}
		}
		/// <summary>
		///
		/// </summary>
		public string LoginBy
		{
			set{ _loginby=value;}
			get{return _loginby;}
		}
		/// <summary>
		///
		/// </summary>
		public DateTime? LoginDate
		{
			set{ _logindate=value;}
			get{return _logindate;}
		}
		/// <summary>
		///
		/// </summary>
		public string UpdateBy
		{
			set{ _updateby=value;}
			get{return _updateby;}
		}
		/// <summary>
		///
		/// </summary>
		public DateTime? UpdateDate
		{
			set{ _updatedate=value;}
			get{return _updatedate;}
		}
		#endregion Model

		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public pdt_MaterialMasterBill(int AutoID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select AutoID,MaterialCode,MaterialName,NnemonicCode,SpellCode,ClassFication,Color,Size,Weight,IsVirtual,ProcessRoute,MaterialPlanType,MaterialStatusType,PurchasingLeadCycle,PreparationCycle,RepleaseCycle,CostPrice,Price,BeginDate,EndDate,Remark,Active,LoginBy,LoginDate,UpdateBy,UpdateDate ");
			strSql.Append(" FROM [pdt_MaterialMasterBill] ");
			strSql.Append(" where [email protected] ");
			SqlParameter[] parameters = {
					new SqlParameter("@AutoID", SqlDbType.Int,4)};
			parameters[0].Value = AutoID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["AutoID"]!=null && ds.Tables[0].Rows[0]["AutoID"].ToString()!="")
				{
					this.AutoID=int.Parse(ds.Tables[0].Rows[0]["AutoID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialCode"]!=null)
				{
					this.MaterialCode=ds.Tables[0].Rows[0]["MaterialCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MaterialName"]!=null)
				{
					this.MaterialName=ds.Tables[0].Rows[0]["MaterialName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NnemonicCode"]!=null)
				{
					this.NnemonicCode=ds.Tables[0].Rows[0]["NnemonicCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SpellCode"]!=null)
				{
					this.SpellCode=ds.Tables[0].Rows[0]["SpellCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ClassFication"]!=null && ds.Tables[0].Rows[0]["ClassFication"].ToString()!="")
				{
					this.ClassFication=int.Parse(ds.Tables[0].Rows[0]["ClassFication"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Color"]!=null)
				{
					this.Color=ds.Tables[0].Rows[0]["Color"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Size"]!=null && ds.Tables[0].Rows[0]["Size"].ToString()!="")
				{
					this.Size=decimal.Parse(ds.Tables[0].Rows[0]["Size"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Weight"]!=null && ds.Tables[0].Rows[0]["Weight"].ToString()!="")
				{
					this.Weight=decimal.Parse(ds.Tables[0].Rows[0]["Weight"].ToString());
				}
				if(ds.Tables[0].Rows[0]["IsVirtual"]!=null && ds.Tables[0].Rows[0]["IsVirtual"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["IsVirtual"].ToString()=="1")||(ds.Tables[0].Rows[0]["IsVirtual"].ToString().ToLower()=="true"))
					{
						this.IsVirtual=true;
					}
					else
					{
						this.IsVirtual=false;
					}
				}

				if(ds.Tables[0].Rows[0]["ProcessRoute"]!=null && ds.Tables[0].Rows[0]["ProcessRoute"].ToString()!="")
				{
					this.ProcessRoute=int.Parse(ds.Tables[0].Rows[0]["ProcessRoute"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialPlanType"]!=null && ds.Tables[0].Rows[0]["MaterialPlanType"].ToString()!="")
				{
					this.MaterialPlanType=int.Parse(ds.Tables[0].Rows[0]["MaterialPlanType"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialStatusType"]!=null && ds.Tables[0].Rows[0]["MaterialStatusType"].ToString()!="")
				{
					this.MaterialStatusType=int.Parse(ds.Tables[0].Rows[0]["MaterialStatusType"].ToString());
				}
				if(ds.Tables[0].Rows[0]["PurchasingLeadCycle"]!=null && ds.Tables[0].Rows[0]["PurchasingLeadCycle"].ToString()!="")
				{
					this.PurchasingLeadCycle=int.Parse(ds.Tables[0].Rows[0]["PurchasingLeadCycle"].ToString());
				}
				if(ds.Tables[0].Rows[0]["PreparationCycle"]!=null && ds.Tables[0].Rows[0]["PreparationCycle"].ToString()!="")
				{
					this.PreparationCycle=int.Parse(ds.Tables[0].Rows[0]["PreparationCycle"].ToString());
				}
				if(ds.Tables[0].Rows[0]["RepleaseCycle"]!=null && ds.Tables[0].Rows[0]["RepleaseCycle"].ToString()!="")
				{
					this.RepleaseCycle=int.Parse(ds.Tables[0].Rows[0]["RepleaseCycle"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CostPrice"]!=null && ds.Tables[0].Rows[0]["CostPrice"].ToString()!="")
				{
					this.CostPrice=decimal.Parse(ds.Tables[0].Rows[0]["CostPrice"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Price"]!=null && ds.Tables[0].Rows[0]["Price"].ToString()!="")
				{
					this.Price=decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
				}
				if(ds.Tables[0].Rows[0]["BeginDate"]!=null && ds.Tables[0].Rows[0]["BeginDate"].ToString()!="")
				{
					this.BeginDate=DateTime.Parse(ds.Tables[0].Rows[0]["BeginDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["EndDate"]!=null && ds.Tables[0].Rows[0]["EndDate"].ToString()!="")
				{
					this.EndDate=DateTime.Parse(ds.Tables[0].Rows[0]["EndDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Remark"]!=null)
				{
					this.Remark=ds.Tables[0].Rows[0]["Remark"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Active"]!=null && ds.Tables[0].Rows[0]["Active"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["Active"].ToString()=="1")||(ds.Tables[0].Rows[0]["Active"].ToString().ToLower()=="true"))
					{
						this.Active=true;
					}
					else
					{
						this.Active=false;
					}
				}

				if(ds.Tables[0].Rows[0]["LoginBy"]!=null)
				{
					this.LoginBy=ds.Tables[0].Rows[0]["LoginBy"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LoginDate"]!=null && ds.Tables[0].Rows[0]["LoginDate"].ToString()!="")
				{
					this.LoginDate=DateTime.Parse(ds.Tables[0].Rows[0]["LoginDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UpdateBy"]!=null)
				{
					this.UpdateBy=ds.Tables[0].Rows[0]["UpdateBy"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UpdateDate"]!=null && ds.Tables[0].Rows[0]["UpdateDate"].ToString()!="")
				{
					this.UpdateDate=DateTime.Parse(ds.Tables[0].Rows[0]["UpdateDate"].ToString());
				}
			}
		}
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int AutoID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from [pdt_MaterialMasterBill]");
			strSql.Append(" where [email protected] ");

			SqlParameter[] parameters = {
					new SqlParameter("@AutoID", SqlDbType.Int,4)};
			parameters[0].Value = AutoID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into [pdt_MaterialMasterBill] (");
			strSql.Append("MaterialCode,MaterialName,NnemonicCode,SpellCode,ClassFication,Color,Size,Weight,IsVirtual,ProcessRoute,MaterialPlanType,MaterialStatusType,PurchasingLeadCycle,PreparationCycle,RepleaseCycle,CostPrice,Price,BeginDate,EndDate,Remark,Active,LoginBy,LoginDate,UpdateBy,UpdateDate)");
			strSql.Append(" values (");
			strSql.Append("@MaterialCode,@MaterialName,@NnemonicCode,@SpellCode,@ClassFication,@Color,@Size,@Weight,@IsVirtual,@ProcessRoute,@MaterialPlanType,@MaterialStatusType,@PurchasingLeadCycle,@PreparationCycle,@RepleaseCycle,@CostPrice,@Price,@BeginDate,@EndDate,@Remark,@Active,@LoginBy,@LoginDate,@UpdateBy,@UpdateDate)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@MaterialCode", SqlDbType.VarChar,10),
					new SqlParameter("@MaterialName", SqlDbType.NVarChar,255),
					new SqlParameter("@NnemonicCode", SqlDbType.VarChar,128),
					new SqlParameter("@SpellCode", SqlDbType.VarChar,255),
					new SqlParameter("@ClassFication", SqlDbType.Int,4),
					new SqlParameter("@Color", SqlDbType.NVarChar,50),
					new SqlParameter("@Size", SqlDbType.Decimal,9),
					new SqlParameter("@Weight", SqlDbType.Decimal,9),
					new SqlParameter("@IsVirtual", SqlDbType.Bit,1),
					new SqlParameter("@ProcessRoute", SqlDbType.Int,4),
					new SqlParameter("@MaterialPlanType", SqlDbType.Int,4),
					new SqlParameter("@MaterialStatusType", SqlDbType.Int,4),
					new SqlParameter("@PurchasingLeadCycle", SqlDbType.Int,4),
					new SqlParameter("@PreparationCycle", SqlDbType.Int,4),
					new SqlParameter("@RepleaseCycle", SqlDbType.Int,4),
					new SqlParameter("@CostPrice", SqlDbType.Decimal,9),
					new SqlParameter("@Price", SqlDbType.Decimal,9),
					new SqlParameter("@BeginDate", SqlDbType.DateTime),
					new SqlParameter("@EndDate", SqlDbType.DateTime),
					new SqlParameter("@Remark", SqlDbType.NVarChar,255),
					new SqlParameter("@Active", SqlDbType.Bit,1),
					new SqlParameter("@LoginBy", SqlDbType.NVarChar,30),
					new SqlParameter("@LoginDate", SqlDbType.DateTime),
					new SqlParameter("@UpdateBy", SqlDbType.NVarChar,30),
					new SqlParameter("@UpdateDate", SqlDbType.DateTime)};
			parameters[0].Value = PubControl.SqlDBNull(MaterialCode);
			parameters[1].Value = PubControl.SqlDBNull(MaterialName);
			parameters[2].Value = PubControl.SqlDBNull(NnemonicCode);
			parameters[3].Value = PubControl.SqlDBNull(SpellCode);
			parameters[4].Value = PubControl.SqlDBNull(ClassFication);
			parameters[5].Value = PubControl.SqlDBNull(Color);
			parameters[6].Value = PubControl.SqlDBNull(Size);
			parameters[7].Value = PubControl.SqlDBNull(Weight);
			parameters[8].Value = PubControl.SqlDBNull(IsVirtual);
			parameters[9].Value = PubControl.SqlDBNull(ProcessRoute);
			parameters[10].Value = PubControl.SqlDBNull(MaterialPlanType);
			parameters[11].Value = PubControl.SqlDBNull(MaterialStatusType);
			parameters[12].Value = PubControl.SqlDBNull(PurchasingLeadCycle);
			parameters[13].Value = PubControl.SqlDBNull(PreparationCycle);
			parameters[14].Value = PubControl.SqlDBNull(RepleaseCycle);
			parameters[15].Value = PubControl.SqlDBNull(CostPrice);
			parameters[16].Value = PubControl.SqlDBNull(Price);
			parameters[17].Value = PubControl.SqlDBNull(BeginDate);
			parameters[18].Value = PubControl.SqlDBNull(EndDate);
			parameters[19].Value = PubControl.SqlDBNull(Remark);
			parameters[20].Value = PubControl.SqlDBNull(Active);
			parameters[21].Value = PubControl.SqlDBNull(LoginBy);
			parameters[22].Value = PubControl.SqlDBNull(LoginDate);
			parameters[23].Value = PubControl.SqlDBNull(UpdateBy);
            parameters[24].Value = PubControl.SqlDBNull(UpdateDate);

            #region   返回AutoID
            int iIntFlag = 0;
            if (parameters != null)
            {
                SqlConnection conn = new SqlConnection(this.DbHelperSQL.ConnString);
                SqlCommand cmd = new SqlCommand();
                try
                {
                    conn.Open();

                    cmd.Connection = conn;
                    cmd.CommandText = strSql.ToString();
                    cmd.CommandType = CommandType.Text;//cmdType;
                    if (parameters != null)
                    {
                        foreach (SqlParameter parameter in parameters)
                        {
                            if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&

                                (parameter.Value == null))
                            {
                                parameter.Value = DBNull.Value;
                            }

                            cmd.Parameters.Add(parameter);
                        }
                    }
                    object obj = cmd.ExecuteScalar();
                    if (obj != null)
                    {
                        if (Convert.ToInt32(obj) > 0)
                        {
                            iIntFlag = Convert.ToInt32(obj);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    conn.Close();
                    cmd.Dispose();
                }

            }
            #endregion

            return iIntFlag;
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public int Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update [pdt_MaterialMasterBill] set ");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected],");
			strSql.Append("[email protected]ateBy,");
			strSql.Append("[email protected]");
			strSql.Append(" where [email protected] ");
			SqlParameter[] parameters = {
					new SqlParameter("@MaterialCode", SqlDbType.VarChar,10),
					new SqlParameter("@MaterialName", SqlDbType.NVarChar,255),
					new SqlParameter("@NnemonicCode", SqlDbType.VarChar,128),
					new SqlParameter("@SpellCode", SqlDbType.VarChar,255),
					new SqlParameter("@ClassFication", SqlDbType.Int,4),
					new SqlParameter("@Color", SqlDbType.NVarChar,50),
					new SqlParameter("@Size", SqlDbType.Decimal,9),
					new SqlParameter("@Weight", SqlDbType.Decimal,9),
					new SqlParameter("@IsVirtual", SqlDbType.Bit,1),
					new SqlParameter("@ProcessRoute", SqlDbType.Int,4),
					new SqlParameter("@MaterialPlanType", SqlDbType.Int,4),
					new SqlParameter("@MaterialStatusType", SqlDbType.Int,4),
					new SqlParameter("@PurchasingLeadCycle", SqlDbType.Int,4),
					new SqlParameter("@PreparationCycle", SqlDbType.Int,4),
					new SqlParameter("@RepleaseCycle", SqlDbType.Int,4),
					new SqlParameter("@CostPrice", SqlDbType.Decimal,9),
					new SqlParameter("@Price", SqlDbType.Decimal,9),
					new SqlParameter("@BeginDate", SqlDbType.DateTime),
					new SqlParameter("@EndDate", SqlDbType.DateTime),
					new SqlParameter("@Remark", SqlDbType.NVarChar,255),
					new SqlParameter("@Active", SqlDbType.Bit,1),
					new SqlParameter("@LoginBy", SqlDbType.NVarChar,30),
					new SqlParameter("@LoginDate", SqlDbType.DateTime),
					new SqlParameter("@UpdateBy", SqlDbType.NVarChar,30),
					new SqlParameter("@UpdateDate", SqlDbType.DateTime),
					new SqlParameter("@AutoID", SqlDbType.Int,4)};
			parameters[0].Value = PubControl.SqlDBNull(MaterialCode);
			parameters[1].Value = PubControl.SqlDBNull(MaterialName);
			parameters[2].Value = PubControl.SqlDBNull(NnemonicCode);
			parameters[3].Value = PubControl.SqlDBNull(SpellCode);
			parameters[4].Value = PubControl.SqlDBNull(ClassFication);
			parameters[5].Value = PubControl.SqlDBNull(Color);
			parameters[6].Value = PubControl.SqlDBNull(Size);
			parameters[7].Value = PubControl.SqlDBNull(Weight);
			parameters[8].Value = PubControl.SqlDBNull(IsVirtual);
			parameters[9].Value = PubControl.SqlDBNull(ProcessRoute);
			parameters[10].Value = PubControl.SqlDBNull(MaterialPlanType);
			parameters[11].Value = PubControl.SqlDBNull(MaterialStatusType);
			parameters[12].Value = PubControl.SqlDBNull(PurchasingLeadCycle);
			parameters[13].Value = PubControl.SqlDBNull(PreparationCycle);
			parameters[14].Value = PubControl.SqlDBNull(RepleaseCycle);
			parameters[15].Value = PubControl.SqlDBNull(CostPrice);
			parameters[16].Value = PubControl.SqlDBNull(Price);
			parameters[17].Value = PubControl.SqlDBNull(BeginDate);
			parameters[18].Value = PubControl.SqlDBNull(EndDate);
			parameters[19].Value = PubControl.SqlDBNull(Remark);
			parameters[20].Value = PubControl.SqlDBNull(Active);
			parameters[21].Value = PubControl.SqlDBNull(LoginBy);
			parameters[22].Value = PubControl.SqlDBNull(LoginDate);
			parameters[23].Value = PubControl.SqlDBNull(UpdateBy);
			parameters[24].Value = PubControl.SqlDBNull(UpdateDate);
            parameters[25].Value = PubControl.SqlDBNull(AutoID);

            //int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
            //if (rows > 0)
            //{
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return rows;
            }
            else
            {
                return 0;
            }
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int AutoID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from [pdt_MaterialMasterBill] ");
			strSql.Append(" where [email protected] ");
			SqlParameter[] parameters = {
					new SqlParameter("@AutoID", SqlDbType.Int,4)};
			parameters[0].Value = AutoID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(int AutoID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select AutoID,MaterialCode,MaterialName,NnemonicCode,SpellCode,ClassFication,Color,Size,Weight,IsVirtual,ProcessRoute,MaterialPlanType,MaterialStatusType,PurchasingLeadCycle,PreparationCycle,RepleaseCycle,CostPrice,Price,BeginDate,EndDate,Remark,Active,LoginBy,LoginDate,UpdateBy,UpdateDate ");
			strSql.Append(" FROM [pdt_MaterialMasterBill] ");
			strSql.Append(" where [email protected] ");
			SqlParameter[] parameters = {
					new SqlParameter("@AutoID", SqlDbType.Int,4)};
			parameters[0].Value = AutoID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["AutoID"]!=null && ds.Tables[0].Rows[0]["AutoID"].ToString()!="")
				{
					this.AutoID=int.Parse(ds.Tables[0].Rows[0]["AutoID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialCode"]!=null )
				{
					this.MaterialCode=ds.Tables[0].Rows[0]["MaterialCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MaterialName"]!=null )
				{
					this.MaterialName=ds.Tables[0].Rows[0]["MaterialName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NnemonicCode"]!=null )
				{
					this.NnemonicCode=ds.Tables[0].Rows[0]["NnemonicCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SpellCode"]!=null )
				{
					this.SpellCode=ds.Tables[0].Rows[0]["SpellCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ClassFication"]!=null && ds.Tables[0].Rows[0]["ClassFication"].ToString()!="")
				{
					this.ClassFication=int.Parse(ds.Tables[0].Rows[0]["ClassFication"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Color"]!=null )
				{
					this.Color=ds.Tables[0].Rows[0]["Color"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Size"]!=null && ds.Tables[0].Rows[0]["Size"].ToString()!="")
				{
					this.Size=decimal.Parse(ds.Tables[0].Rows[0]["Size"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Weight"]!=null && ds.Tables[0].Rows[0]["Weight"].ToString()!="")
				{
					this.Weight=decimal.Parse(ds.Tables[0].Rows[0]["Weight"].ToString());
				}
				if(ds.Tables[0].Rows[0]["IsVirtual"]!=null && ds.Tables[0].Rows[0]["IsVirtual"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["IsVirtual"].ToString()=="1")||(ds.Tables[0].Rows[0]["IsVirtual"].ToString().ToLower()=="true"))
					{
						this.IsVirtual=true;
					}
					else
					{
						this.IsVirtual=false;
					}
				}
				if(ds.Tables[0].Rows[0]["ProcessRoute"]!=null && ds.Tables[0].Rows[0]["ProcessRoute"].ToString()!="")
				{
					this.ProcessRoute=int.Parse(ds.Tables[0].Rows[0]["ProcessRoute"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialPlanType"]!=null && ds.Tables[0].Rows[0]["MaterialPlanType"].ToString()!="")
				{
					this.MaterialPlanType=int.Parse(ds.Tables[0].Rows[0]["MaterialPlanType"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialStatusType"]!=null && ds.Tables[0].Rows[0]["MaterialStatusType"].ToString()!="")
				{
					this.MaterialStatusType=int.Parse(ds.Tables[0].Rows[0]["MaterialStatusType"].ToString());
				}
				if(ds.Tables[0].Rows[0]["PurchasingLeadCycle"]!=null && ds.Tables[0].Rows[0]["PurchasingLeadCycle"].ToString()!="")
				{
					this.PurchasingLeadCycle=int.Parse(ds.Tables[0].Rows[0]["PurchasingLeadCycle"].ToString());
				}
				if(ds.Tables[0].Rows[0]["PreparationCycle"]!=null && ds.Tables[0].Rows[0]["PreparationCycle"].ToString()!="")
				{
					this.PreparationCycle=int.Parse(ds.Tables[0].Rows[0]["PreparationCycle"].ToString());
				}
				if(ds.Tables[0].Rows[0]["RepleaseCycle"]!=null && ds.Tables[0].Rows[0]["RepleaseCycle"].ToString()!="")
				{
					this.RepleaseCycle=int.Parse(ds.Tables[0].Rows[0]["RepleaseCycle"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CostPrice"]!=null && ds.Tables[0].Rows[0]["CostPrice"].ToString()!="")
				{
					this.CostPrice=decimal.Parse(ds.Tables[0].Rows[0]["CostPrice"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Price"]!=null && ds.Tables[0].Rows[0]["Price"].ToString()!="")
				{
					this.Price=decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
				}
				if(ds.Tables[0].Rows[0]["BeginDate"]!=null && ds.Tables[0].Rows[0]["BeginDate"].ToString()!="")
				{
					this.BeginDate=DateTime.Parse(ds.Tables[0].Rows[0]["BeginDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["EndDate"]!=null && ds.Tables[0].Rows[0]["EndDate"].ToString()!="")
				{
					this.EndDate=DateTime.Parse(ds.Tables[0].Rows[0]["EndDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Remark"]!=null )
				{
					this.Remark=ds.Tables[0].Rows[0]["Remark"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Active"]!=null && ds.Tables[0].Rows[0]["Active"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["Active"].ToString()=="1")||(ds.Tables[0].Rows[0]["Active"].ToString().ToLower()=="true"))
					{
						this.Active=true;
					}
					else
					{
						this.Active=false;
					}
				}
				if(ds.Tables[0].Rows[0]["LoginBy"]!=null )
				{
					this.LoginBy=ds.Tables[0].Rows[0]["LoginBy"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LoginDate"]!=null && ds.Tables[0].Rows[0]["LoginDate"].ToString()!="")
				{
					this.LoginDate=DateTime.Parse(ds.Tables[0].Rows[0]["LoginDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UpdateBy"]!=null )
				{
					this.UpdateBy=ds.Tables[0].Rows[0]["UpdateBy"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UpdateDate"]!=null && ds.Tables[0].Rows[0]["UpdateDate"].ToString()!="")
				{
					this.UpdateDate=DateTime.Parse(ds.Tables[0].Rows[0]["UpdateDate"].ToString());
				}
			}
		}

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel2(string MaterialCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AutoID,MaterialCode,MaterialName,NnemonicCode,SpellCode,ClassFication,Color,Size,Weight,IsVirtual,ProcessRoute,MaterialPlanType,MaterialStatusType,PurchasingLeadCycle,PreparationCycle,RepleaseCycle,CostPrice,Price,BeginDate,EndDate,Remark,Active,LoginBy,LoginDate,UpdateBy,UpdateDate ");
            strSql.Append(" FROM [pdt_MaterialMasterBill] ");
            strSql.Append(" where [email protected] ");
            SqlParameter[] parameters = {
					new SqlParameter("@MaterialCode", SqlDbType.VarChar,-1)};
            parameters[0].Value = MaterialCode;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["AutoID"] != null && ds.Tables[0].Rows[0]["AutoID"].ToString() != "")
                {
                    this.AutoID = int.Parse(ds.Tables[0].Rows[0]["AutoID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MaterialCode"] != null)
                {
                    this.MaterialCode = ds.Tables[0].Rows[0]["MaterialCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MaterialName"] != null)
                {
                    this.MaterialName = ds.Tables[0].Rows[0]["MaterialName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NnemonicCode"] != null)
                {
                    this.NnemonicCode = ds.Tables[0].Rows[0]["NnemonicCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SpellCode"] != null)
                {
                    this.SpellCode = ds.Tables[0].Rows[0]["SpellCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ClassFication"] != null && ds.Tables[0].Rows[0]["ClassFication"].ToString() != "")
                {
                    this.ClassFication = int.Parse(ds.Tables[0].Rows[0]["ClassFication"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Color"] != null)
                {
                    this.Color = ds.Tables[0].Rows[0]["Color"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Size"] != null && ds.Tables[0].Rows[0]["Size"].ToString() != "")
                {
                    this.Size = decimal.Parse(ds.Tables[0].Rows[0]["Size"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Weight"] != null && ds.Tables[0].Rows[0]["Weight"].ToString() != "")
                {
                    this.Weight = decimal.Parse(ds.Tables[0].Rows[0]["Weight"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsVirtual"] != null && ds.Tables[0].Rows[0]["IsVirtual"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsVirtual"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsVirtual"].ToString().ToLower() == "true"))
                    {
                        this.IsVirtual = true;
                    }
                    else
                    {
                        this.IsVirtual = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["ProcessRoute"] != null && ds.Tables[0].Rows[0]["ProcessRoute"].ToString() != "")
                {
                    this.ProcessRoute = int.Parse(ds.Tables[0].Rows[0]["ProcessRoute"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MaterialPlanType"] != null && ds.Tables[0].Rows[0]["MaterialPlanType"].ToString() != "")
                {
                    this.MaterialPlanType = int.Parse(ds.Tables[0].Rows[0]["MaterialPlanType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MaterialStatusType"] != null && ds.Tables[0].Rows[0]["MaterialStatusType"].ToString() != "")
                {
                    this.MaterialStatusType = int.Parse(ds.Tables[0].Rows[0]["MaterialStatusType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PurchasingLeadCycle"] != null && ds.Tables[0].Rows[0]["PurchasingLeadCycle"].ToString() != "")
                {
                    this.PurchasingLeadCycle = int.Parse(ds.Tables[0].Rows[0]["PurchasingLeadCycle"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PreparationCycle"] != null && ds.Tables[0].Rows[0]["PreparationCycle"].ToString() != "")
                {
                    this.PreparationCycle = int.Parse(ds.Tables[0].Rows[0]["PreparationCycle"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RepleaseCycle"] != null && ds.Tables[0].Rows[0]["RepleaseCycle"].ToString() != "")
                {
                    this.RepleaseCycle = int.Parse(ds.Tables[0].Rows[0]["RepleaseCycle"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CostPrice"] != null && ds.Tables[0].Rows[0]["CostPrice"].ToString() != "")
                {
                    this.CostPrice = decimal.Parse(ds.Tables[0].Rows[0]["CostPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Price"] != null && ds.Tables[0].Rows[0]["Price"].ToString() != "")
                {
                    this.Price = decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BeginDate"] != null && ds.Tables[0].Rows[0]["BeginDate"].ToString() != "")
                {
                    this.BeginDate = DateTime.Parse(ds.Tables[0].Rows[0]["BeginDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["EndDate"] != null && ds.Tables[0].Rows[0]["EndDate"].ToString() != "")
                {
                    this.EndDate = DateTime.Parse(ds.Tables[0].Rows[0]["EndDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Remark"] != null)
                {
                    this.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Active"] != null && ds.Tables[0].Rows[0]["Active"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Active"].ToString() == "1") || (ds.Tables[0].Rows[0]["Active"].ToString().ToLower() == "true"))
                    {
                        this.Active = true;
                    }
                    else
                    {
                        this.Active = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["LoginBy"] != null)
                {
                    this.LoginBy = ds.Tables[0].Rows[0]["LoginBy"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoginDate"] != null && ds.Tables[0].Rows[0]["LoginDate"].ToString() != "")
                {
                    this.LoginDate = DateTime.Parse(ds.Tables[0].Rows[0]["LoginDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateBy"] != null)
                {
                    this.UpdateBy = ds.Tables[0].Rows[0]["UpdateBy"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UpdateDate"] != null && ds.Tables[0].Rows[0]["UpdateDate"].ToString() != "")
                {
                    this.UpdateDate = DateTime.Parse(ds.Tables[0].Rows[0]["UpdateDate"].ToString());
                }
            }
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM [pdt_MaterialMasterBill] ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

  

时间: 2024-10-03 13:20:43

新增记录时返回自增ID (DAL数据访问类)的相关文章

mybatis添加记录时返回主键id

参考:https://www.cnblogs.com/nuccch/p/7687281.html 场景 有些时候我们在添加记录成功后希望能直接获取到该记录的主键id值,而不需要再执行一次查询操作.在使用mybatis作为ORM组件时,可以很方便地达到这个目的.鉴于mybatis目前已经支持xml配置和注解2种方式,所以分别给予详细介绍. 数据表设计: drop table if exists `test`; create table `test` ( `id` bigint(20) NOT NU

Entity Framework添加记录时获取自增ID值

var m = new 你的Model(); db.你的Model.add(m); db.SaveChange(); Response.Write(m.Id); //执行.SaveChange()保存后就直接可以取得id值了. 保存前没有id值. Entity Framework在将数据插入数据库时,如果主键字段是自增标识列,会将该自增值返回给实体对象对应的属性. 比如下面添加博客随笔至数据库的示例代码: var blogPost = new BlogPost() { Author = "博客园

mysql插入数据后返回自增ID的方法

mysql插入数据后返回自增ID的方法 mysql和oracle插入的时候有一个很大的区别是,oracle支持序列做id,mysql本身有一个列可以做自增长字段,mysql在插入一条数据后,如何能获得到这个自增id的值呢? 方法一:是使用last_insert_id mysql> SELECT LAST_INSERT_ID(); 产生的ID 每次连接后保存在服务器中.这意味着函数向一个给定客户端返回的值是该客户端产生对影响AUTO_INCREMENT列的最新语句第一个 AUTO_INCREMEN

select @@identity得到上一次插入记录时自动产生的ID

select @@identity的用法 2008-10-25 11:25:39|  分类: JSP Dev|举报|字号 订阅 用select @@identity得到上一次插入记录时自动产生的ID 如果你使用存储过程的话,将非常简单,代码如下:SET @[email protected]@IDENTITY 说明: 在一条 INSERT.SELECT INTO 或大容量复制语句完成后,@@IDENTITY 中包含此语句产生的最后的标识值.若此语句没有影响任何有标识列的表,则 @@IDENTITY

Postgresql插入数据返回自增id

Postgresql插入数据返回自增id 一.设置自增id 新建字段  并且将字段属性设置为serial 二.插入返回 insert语句增加return 例如:insert into point(pointtype,pointx,pointy,pointval)values(1,2,3,4) RETURNING id;

OpenCV访问Mat对象中数据时发生异常---Mat中的数据访问

7.1和7.1.1由于越狱不成熟,半完美越狱后电脑上无法访问系统越狱目录,如var usr 等等. 今天有些意外地发现,可以在电脑上使用手机的越狱目录我手机 i4 7.1.1 联通 半完美越狱,没装Afc2Add,也没装Appsync 附上  --->我的半完美越狱过程 好了,下面直接正题 一.前提,必须安装ifile! 打开ifile,并转到 /var/mobile/media 目录下,然后点击右上角的 [ 编辑 ]如图: 二.点左下角的 + 号创建,如图: 三.点 [ 类型],选择[符号链接

加载的DAL数据访问层的类型

using System; using System.Collections; using System.Reflection; using CSFrameworkV4_5.Core; using CSFrameworkV4_5.Core.CodeGenerator; using CSFrameworkV4_5.Server.DataAccess.DAL_Base; namespace CSFrameworkV4_5.Server.DataAccess { /// <summary> ///

MySql 更新时返回主键id

最近做项目,遇到一个逻辑,就是在修改单条记录时需要返回该记录的id. 先说一下我的使用环境,springMVC+MyBatis,于是上度娘查了一下,将结果记录一下,仅供日后参考和大家们共同探讨 具体逻辑就是在多个条件下,包括一个嵌套查询,对一条记录进行更新,并返回该记录的主键id,在这个查询语句里面用到一个变量update_id在执行更新语句的时候将本记录的id重新赋值为自身的id,同时将自身的id赋值给updatge_id这个变量,最后返回这个变量,就是这个更新最后的目的. SET @upda

使用mybatis注解@Options实现添加记录时返回主键值

官网:http://www.mybatis.org/mybatis-3/index.html 在使用mybatis作为ORM框架时,我通常更喜欢使用注解而非xml配置文件的方式.业务场景:添加记录之后需要返回自己自增长的主键字段值.通常,我们会将DAO层写成如下代码(以添加员工Staff为例): public interface StaffDAO { @InsertProvider(type=StaffProvider.class, method="buildSinleStaff")