public static bool PurchasersSaveState(Purchaser pucharserobj) { bool transOk = false; int datos; try { var ConectStr = Tools.ConectionNow.BuildConection(pucharserobj.User); Database dbeAuction = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(ConectStr); // Database dbeAuction = DatabaseFactory.CreateDatabase("Auction"); // Crear objeto SP DbCommand spComprador = dbeAuction.GetStoredProcCommand("SP_COMPRADORES"); dbeAuction.AddInParameter(spComprador, "@i_operation", DbType.String, "IU"); dbeAuction.AddInParameter(spComprador, "@i_option", DbType.String, "B"); dbeAuction.AddInParameter(spComprador, "@id_Comprador", DbType.Int32, pucharserobj.IdSegas); dbeAuction.AddInParameter(spComprador, "@IdSubasta", DbType.Int32, pucharserobj.IdSubasta); dbeAuction.AddInParameter(spComprador, "@Estado", DbType.Boolean, pucharserobj.Estado); dbeAuction.AddInParameter(spComprador, "@Cubrimiento", DbType.Boolean, pucharserobj.Cubrimiento); dbeAuction.AddInParameter(spComprador, "@Listas", DbType.Boolean, pucharserobj.Listas); spComprador.CommandTimeout = 900000000; datos = dbeAuction.ExecuteNonQuery(spComprador); transOk = true; } catch (Exception ex) { transOk = false; System.Diagnostics.Trace.WriteLine(string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name)); throw new Exception((string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name))); } return(transOk); }
///-------------------------------------------------------------------------------- /// <summary>This method executes a non query (for database update operations). /// The user is expect to commit or roll back the transaction after one or more of /// these operations.</summary> /// /// <param name="sprocName">Name of the stored procedure.</param> /// <param name="sprocParams">The input stored procedure parameter values.</param> /// /// <returns>The result code of the operation.</returns> ///-------------------------------------------------------------------------------- public int ExecuteNonQuery(string sprocName, NameObjectCollection sprocParams) { DbCommand command = null; int results = DefaultValue.Int; try { // build the command and execute the non query for update operations command = SetupSprocCommand(sprocName, sprocParams); if (command.Connection.State == ConnectionState.Closed) { command.Connection.Open(); } results = _database.ExecuteNonQuery(command, Transaction); // put output/return values into sproc params foreach (DbParameter loopParameter in command.Parameters) { sprocParams[SqlHelper.GetParameterNameFromSqlParameterName(loopParameter.ParameterName)] = loopParameter.Value; } } catch (Exception ex) { bool reThrow = ExceptionHandler.HandleException(ex); if (reThrow) { throw; } } return(results); }
public static bool SavePurchaserUser(Purchaser purchaserobj) { int datos; bool SafeSave; try { var ConectStr = Tools.ConectionNow.BuildConection(purchaserobj.User); Database dbeAuction = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(ConectStr); // Database dbeAuction = DatabaseFactory.CreateDatabase("Auction"); // Crear objeto SP DbCommand spComprador = dbeAuction.GetStoredProcCommand("SP_COMPRADORES"); dbeAuction.AddInParameter(spComprador, "@i_operation", DbType.String, "IU"); dbeAuction.AddInParameter(spComprador, "@i_option", DbType.String, "C"); dbeAuction.AddInParameter(spComprador, "@id_Comprador", DbType.Int32, purchaserobj.IdSegas); dbeAuction.AddInParameter(spComprador, "@Nombre", DbType.String, purchaserobj.Nombre); dbeAuction.AddInParameter(spComprador, "@IdSubasta", DbType.Int32, purchaserobj.IdSubasta); dbeAuction.AddInParameter(spComprador, "@DemandaMaxima", DbType.Int32, purchaserobj.DemandaMaximaTotal); dbeAuction.AddInParameter(spComprador, "@IdOperador", DbType.Int32, purchaserobj.User.CodigoOperador); spComprador.CommandTimeout = 900000000; datos = dbeAuction.ExecuteNonQuery(spComprador); SafeSave = true; } catch (Exception ex) { SafeSave = false; System.Diagnostics.Trace.WriteLine(string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name)); throw new Exception((string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name))); } return(SafeSave); }
public static Seller SellerSave(Seller sellerobj) { int datos; try { var ConectStr = Tools.ConectionNow.BuildConection(sellerobj.User); Database dbeAuction = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(ConectStr); // Database dbeAuction = DatabaseFactory.CreateDatabase("Auction"); // Crear objeto SP // Crear objeto SP DbCommand spVendedor = dbeAuction.GetStoredProcCommand("SP_VENDEDORES"); dbeAuction.AddInParameter(spVendedor, "@i_operation", DbType.String, "IU"); dbeAuction.AddInParameter(spVendedor, "@i_option", DbType.String, "A"); dbeAuction.AddInParameter(spVendedor, "@id_Vendedor", DbType.Int32, sellerobj.IdSegas); dbeAuction.AddInParameter(spVendedor, "@PTDVF", DbType.Decimal, sellerobj.PTDVF); dbeAuction.AddInParameter(spVendedor, "@CIFVF", DbType.Decimal, sellerobj.CIFVF); dbeAuction.AddInParameter(spVendedor, "@IdSubasta", DbType.Int32, sellerobj.IdSubasta); dbeAuction.AddInParameter(spVendedor, "@Nombre", DbType.String, sellerobj.Nombre); dbeAuction.AddInParameter(spVendedor, "@IdOperador", DbType.Int32, sellerobj.User.CodigoOperador); spVendedor.CommandTimeout = 900000000; datos = dbeAuction.ExecuteNonQuery(spVendedor); return(sellerobj); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name)); throw new Exception((string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name))); } }
public static bool CreateToken(Token tokenObj) { bool InsertBDok = false; try { var ConectStr = ConfigurationSettings.AppSettings["ConectionAuction"]; ConectStr = ConectStr.Replace("USER", tokenObj.UserName); //testgas1 ConectStr = ConectStr.Replace("PASS", tokenObj.Password); //test12345 // Database dbeAuction = DatabaseFactory.CreateDatabase(a); Database dbeAuction = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(ConectStr); // Crear objeto SP DbCommand spUsuarios = dbeAuction.GetStoredProcCommand("SP_USUARIOS"); dbeAuction.AddInParameter(spUsuarios, "@i_operation", DbType.String, "IU"); dbeAuction.AddInParameter(spUsuarios, "@i_option", DbType.String, "A"); dbeAuction.AddInParameter(spUsuarios, "@UserId", DbType.String, tokenObj.IdUser); dbeAuction.AddInParameter(spUsuarios, "@UserName", DbType.String, tokenObj.UserName); dbeAuction.AddInParameter(spUsuarios, "@AuthToken", DbType.String, tokenObj.AuthToken); dbeAuction.AddInParameter(spUsuarios, "@Password", DbType.String, tokenObj.Password); dbeAuction.ExecuteNonQuery(spUsuarios); InsertBDok = true; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name)); throw new Exception((string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name))); } return(InsertBDok); }
/// <summary> /// For getting xml from database /// </summary> /// <param name="dom"></param> /// <returns></returns> public static string GetXml(XDocument dom, string ConnectionStr) { try { Database db = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(ConnectionStr); DbParameter parameter; DbCommand cmd; IEnumerable <XElement> elems; IEnumerable <XElement> elem_list; string Procname = GetProcName(dom); cmd = db.GetStoredProcCommand(Procname); SetCommandTimeOut(cmd); string OutParameterName = ""; elems = dom.Descendants(); elem_list = from elem in elems select elem; foreach (XElement element in elem_list) { parameter = cmd.CreateParameter(); if (element.Name.ToString() != "BIC" && element.Name.ToString() != "XsdName" && element.Name.ToString() != "procName" && element.Name.ToString() != "pFILESDATA") { OutParameterName = element.Name.ToString(); parameter.ParameterName = "@" + element.Name.ToString(); if (element.Name.ToString().Trim() == "pERRORXML") { parameter.DbType = DbType.Xml; parameter.Direction = ParameterDirection.Output; } else { parameter.Value = element.Value; parameter.Direction = ParameterDirection.Input; } cmd.Parameters.Add(parameter); } } db.ExecuteNonQuery(cmd); var retval = db.GetParameterValue(cmd, "@pERRORXML"); return(Convert.ToString(retval)); } catch (Exception ex) { throw ex; } }
/// <summary> /// Reads the application connection string from Config database /// </summary> /// <param name="connectionStringID">value of connectionStringID</param> /// <returns>application connection string</returns> private static string GetApplicationConnectionStringFromDB(string connectionStringID) { string configDatabaseConnectionString = null; string applicationConnectionString = null; configDatabaseConnectionString = GetDatabaseConnectionStringFromRegistry(CONFIGSDATABASEKEY); Database database = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(configDatabaseConnectionString); using (DbCommand cmd = database.GetStoredProcCommand(CONFIGURATIONCONNECTIONSTRINGGET)) { database.AddInParameter(cmd, "@connectionStringKey", DbType.AnsiString, connectionStringID); database.AddOutParameter(cmd, "@connectionStringValue", DbType.AnsiString, 8000); database.ExecuteNonQuery(cmd); applicationConnectionString = (string)database.GetParameterValue(cmd, "@connectionStringValue"); } return(applicationConnectionString); }
public static int InsertLogGas(GasLog gasobj) { int datos; DataTable clientes = new DataTable(); try { var ConectStr = Tools.ConectionNow.BuildConection(gasobj.User); Database dbAuction = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(ConectStr); // Database dbeAuction = DatabaseFactory.CreateDatabase("Auction"); // Crear objeto SP DbCommand spInsertarLog = dbAuction.GetStoredProcCommand("SP_GASLOG"); dbAuction.AddInParameter(spInsertarLog, "@i_operation", DbType.String, "I"); dbAuction.AddInParameter(spInsertarLog, "@i_option", DbType.String, "A"); dbAuction.AddInParameter(spInsertarLog, "@Descripcion", DbType.String, gasobj.Descripcion); dbAuction.AddInParameter(spInsertarLog, "@NombreUsuario", DbType.String, gasobj.NombreUsuario); dbAuction.AddInParameter(spInsertarLog, "@IdUsuario", DbType.Int16, gasobj.IdUsuario); dbAuction.AddInParameter(spInsertarLog, "@TipoMovimiento", DbType.String, gasobj.Descripcion); dbAuction.AddInParameter(spInsertarLog, "@IdTipoAccion", DbType.Int16, gasobj.IdTipoAccion); dbAuction.AddInParameter(spInsertarLog, "@Nombre", DbType.String, gasobj.Nombre); dbAuction.AddInParameter(spInsertarLog, "@EstadoTrans", DbType.Boolean, gasobj.EstadoTransaccion); spInsertarLog.CommandTimeout = 900000000; datos = dbAuction.ExecuteNonQuery(spInsertarLog); return(datos); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("AuctionGas ApiWebServices Auditoria: {0} , NameSpace: {1}, Clase: {2}, Metodo: {3} ", ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name)); throw new Exception("Excepcion en la funcion LogGas" + ex.StackTrace); } }