public void Update(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02) { #region 创建语法 StringBuilder strSql = new StringBuilder(); strSql.Append("update FOUNDERPCB_FRIGHTE_02 set "); strSql.Append("PRO_RKEY=@PRO_RKEY,"); strSql.Append("SORT=@SORT,"); strSql.Append("OPERATION_ENGLISH=@OPERATION_ENGLISH,"); strSql.Append("OPERATION_NAME=@OPERATION_NAME,"); strSql.Append("OPERATION_DESC=@OPERATION_DESC"); strSql.Append(" where RKEY=@RKEY "); SqlParameter[] parameters = { new SqlParameter("@RKEY", SqlDbType.Decimal, 9), new SqlParameter("@PRO_RKEY", SqlDbType.Decimal, 9), new SqlParameter("@SORT", SqlDbType.Int, 4), new SqlParameter("@OPERATION_ENGLISH", SqlDbType.VarChar, 50), new SqlParameter("@OPERATION_NAME", SqlDbType.VarChar, 50), new SqlParameter("@OPERATION_DESC", SqlDbType.VarChar, 100) }; parameters[0].Value = founderpcb_frighte_02.RKEY; parameters[1].Value = founderpcb_frighte_02.PRO_RKEY; parameters[2].Value = founderpcb_frighte_02.SORT; parameters[3].Value = founderpcb_frighte_02.OPERATION_ENGLISH; parameters[4].Value = founderpcb_frighte_02.OPERATION_NAME; parameters[5].Value = founderpcb_frighte_02.OPERATION_DESC; #endregion #region 操作 if (conn.State != ConnectionState.Open) { conn.Open(); } cmd.Connection = conn; cmd.CommandText = strSql.ToString(); cmd.Transaction = trans; 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); } } cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); #endregion }
public int Add(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02) { // Validate input if (founderpcb_frighte_02 == null) { return(0); } return(founderpcb_frighte_02Dal.Add(cmd, conn, trans, founderpcb_frighte_02)); }
/// <summary> /// 向数据库中插入一条新记录。 /// </summary> /// <param name="FOUNDERPCB_FRIGHTE_02">founderpcb_frighte_02对象</param> /// <returns>新插入记录的编号</returns> public int Add(FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02) { // Validate input if (founderpcb_frighte_02 == null) { return(0); } return(founderpcb_frighte_02Dal.Add(founderpcb_frighte_02)); }
public void Update(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02) { // Validate input if (founderpcb_frighte_02 == null) { return; } founderpcb_frighte_02Dal.Update(cmd, conn, trans, founderpcb_frighte_02); }
///<sumary> /// 通过SQL语句获取数据对象 ///</sumary> /// <param name="sqlWhere">sqlWhere参数条件</param> ///<returns>IList<FOUNDERPCB_FRIGHTE_02>数据集合</returns> public IList <FOUNDERPCB_FRIGHTE_02> FindBySql(string sqlWhere) { #region SQL string sql = @"select isNull(rkey,0) as rkey , isNull(pro_rkey,0) as pro_rkey , isNull(sort,0) as sort , isNull(operation_english,'') as operation_english , isNull(operation_name,'') as operation_name , isNull(operation_desc,'') as operation_desc from FOUNDERPCB_FRIGHTE_02 with (nolock)" ; if (sqlWhere.Length > 0) { sql = sql + " where " + sqlWhere; } #endregion IList <FOUNDERPCB_FRIGHTE_02> resultList = new List <FOUNDERPCB_FRIGHTE_02>(); #region 操作 try { using (DataTable tb = dbHelper.GetDataSet(sql)) { foreach (DataRow row in tb.Rows) { FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02 = new FOUNDERPCB_FRIGHTE_02(); founderpcb_frighte_02.RKEY = decimal.Parse(row["RKEY"].ToString()); founderpcb_frighte_02.PRO_RKEY = decimal.Parse(row["PRO_RKEY"].ToString()); founderpcb_frighte_02.SORT = int.Parse(row["SORT"].ToString()); founderpcb_frighte_02.OPERATION_ENGLISH = row["OPERATION_ENGLISH"].ToString(); founderpcb_frighte_02.OPERATION_NAME = row["OPERATION_NAME"].ToString(); founderpcb_frighte_02.OPERATION_DESC = row["OPERATION_DESC"].ToString(); resultList.Add(founderpcb_frighte_02); } } } catch (Exception e) { log.Info("FID=" + this.factoryID.ToString() + ";userAD=" + this.userAD + ";FindBySql function:" + e.Message, e); throw e; } #endregion return(resultList); }
/// <summary> /// 向数据库中插入一条新记录。 /// </summary> /// <param name="FOUNDERPCB_FRIGHTE_02">founderpcb_frighte_02对象</param> /// <returns>新插入记录的编号</returns> public int Add(FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02) { #region 调用SQL存储过程进行添加 string sql = "sp_FOUNDERPCB_FRIGHTE_02_Add"; ///存储过程名 SqlParameter[] parameters = { new SqlParameter("@returnID", SqlDbType.Int), new SqlParameter("@userAD", SqlDbType.VarChar), ///new SqlParameter("@RKEY",SqlDbType.Decimal,9), new SqlParameter("@RKEY", SqlDbType.Float), new SqlParameter("@PRO_RKEY", SqlDbType.Decimal, 9), new SqlParameter("@SORT", SqlDbType.Int, 4), new SqlParameter("@OPERATION_ENGLISH", SqlDbType.VarChar, 50), new SqlParameter("@OPERATION_NAME", SqlDbType.VarChar, 50), new SqlParameter("@OPERATION_DESC", SqlDbType.VarChar, 100) }; parameters[0].Value = 0; parameters[0].Direction = ParameterDirection.InputOutput; parameters[1].Value = this.userAD; parameters[2].Direction = ParameterDirection.InputOutput; parameters[2].Value = founderpcb_frighte_02.RKEY; parameters[3].Value = founderpcb_frighte_02.PRO_RKEY; parameters[4].Value = founderpcb_frighte_02.SORT; parameters[5].Value = founderpcb_frighte_02.OPERATION_ENGLISH; parameters[6].Value = founderpcb_frighte_02.OPERATION_NAME; parameters[7].Value = founderpcb_frighte_02.OPERATION_DESC; #endregion #region 数据库操作 int result = 0; try { dbHelper.ExecuteCommandProc(sql, parameters); result = int.Parse(parameters[0].Value.ToString()); founderpcb_frighte_02.RKEY = decimal.Parse(parameters[2].Value.ToString()); // log.Info("FID="+this.factoryID.ToString()+";userAD="+this.userAD+";FOUNDERPCB_FRIGHTE_02,save successful"); } catch (Exception e) { ///message ID result = 2; log.Error("FID=" + this.factoryID.ToString() + ";userAD=" + this.userAD + ";" + e.Message, e); } #endregion return(result); }
///<sumary> /// 通过主键获取数据对象 ///</sumary> /// <param name="RKEY">rkey</param> ///<returns>FOUNDERPCB_FRIGHTE_02对象</returns> public FOUNDERPCB_FRIGHTE_02 getFOUNDERPCB_FRIGHTE_02ByRKEY(decimal rkey) { #region SQL string sql = @"select top 1 isNull(rkey,0) as rkey , isNull(pro_rkey,0) as pro_rkey , isNull(sort,0) as sort , isNull(operation_english,'') as operation_english , isNull(operation_name,'') as operation_name , isNull(operation_desc,'') as operation_desc from FOUNDERPCB_FRIGHTE_02 with (nolock) where RKEY='{0}'" ; #endregion ///定义返回对象 FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02 = null; #region 数据库操作 try { founderpcb_frighte_02 = new FOUNDERPCB_FRIGHTE_02(); using (DataTable tb = dbHelper.GetDataSet(string.Format(sql, rkey))) { foreach (DataRow row in tb.Rows) { founderpcb_frighte_02.RKEY = decimal.Parse(row["RKEY"].ToString()); founderpcb_frighte_02.PRO_RKEY = decimal.Parse(row["PRO_RKEY"].ToString()); founderpcb_frighte_02.SORT = int.Parse(row["SORT"].ToString()); founderpcb_frighte_02.OPERATION_ENGLISH = row["OPERATION_ENGLISH"].ToString(); founderpcb_frighte_02.OPERATION_NAME = row["OPERATION_NAME"].ToString(); founderpcb_frighte_02.OPERATION_DESC = row["OPERATION_DESC"].ToString(); } } } catch (Exception e) { //Console.WriteLine(e.Message); log.Info("FID=" + this.factoryID.ToString() + ";userAD=" + this.userAD + ";get function:" + e.Message, e); } #endregion return(founderpcb_frighte_02); }
///<sumary> /// 删除 ///</sumary> /// <param name="founderpcb_frighte_02">对象</param> ///<returns>返回INT类型号, 0为操作成功, 非0操作失败.</returns> public int Delete(FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02) { #region 调用SQL存储过程进行删除 string sql = "sp_FOUNDERPCB_FRIGHTE_02_Delete"; //========================= SqlParameter[] parameters = { new SqlParameter("@returnID", SqlDbType.Int), new SqlParameter("@userAD", SqlDbType.VarChar), new SqlParameter("@RKEY", SqlDbType.Decimal, 9) }; parameters[0].Value = 1; parameters[0].Direction = ParameterDirection.InputOutput; parameters[1].Value = this.userAD; parameters[2].Value = founderpcb_frighte_02.RKEY; //========================= #endregion #region 数据库操作 int result = 0; try { dbHelper.ExecuteCommandProc(sql, parameters); result = int.Parse(parameters[0].Value.ToString()); // log.Info("FID="+this.factoryID.ToString()+";userAD="+this.userAD+";FOUNDERPCB_FRIGHTE_02,delete successful"); } catch (Exception e) { result = 2; log.Info("FID=" + this.factoryID.ToString() + ";userAD=" + this.userAD + ";" + e.Message, e); } #endregion return(result); }
public int Add(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, FOUNDERPCB_FRIGHTE_02 founderpcb_frighte_02) { #region 创建SQL语法 StringBuilder strSql = new StringBuilder(); strSql.Append("insert into FOUNDERPCB_FRIGHTE_02("); strSql.Append("PRO_RKEY,SORT,OPERATION_ENGLISH,OPERATION_NAME,OPERATION_DESC"); strSql.Append(" ) values ("); strSql.Append("@PRO_RKEY,@SORT,@OPERATION_ENGLISH,@OPERATION_NAME,@OPERATION_DESC"); strSql.Append(");select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@PRO_RKEY", SqlDbType.Decimal, 9), new SqlParameter("@SORT", SqlDbType.Int, 4), new SqlParameter("@OPERATION_ENGLISH", SqlDbType.VarChar, 50), new SqlParameter("@OPERATION_NAME", SqlDbType.VarChar, 50), new SqlParameter("@OPERATION_DESC", SqlDbType.VarChar, 100) }; parameters[0].Value = founderpcb_frighte_02.PRO_RKEY; parameters[1].Value = founderpcb_frighte_02.SORT; parameters[2].Value = founderpcb_frighte_02.OPERATION_ENGLISH; parameters[3].Value = founderpcb_frighte_02.OPERATION_NAME; parameters[4].Value = founderpcb_frighte_02.OPERATION_DESC; #endregion #region 操作 if (conn.State != ConnectionState.Open) { conn.Open(); } cmd.Connection = conn; cmd.CommandText = strSql.ToString(); cmd.Transaction = trans; 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); } } int indentity = 0; object obj = cmd.ExecuteScalar(); cmd.Parameters.Clear(); if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value))) { indentity = 0; } else { indentity = int.Parse(obj.ToString()); } #endregion return(indentity); }