Example #1
0
        public int ExecuteSqlInsertImg(string strSQL, byte[] fs)
        {
            int num;

            using (AseConnection connection = new AseConnection(this.connectionString))
            {
                AseCommand   command = new AseCommand(strSQL, connection);
                AseParameter p       = new AseParameter("@fs", AseDbType.Image)
                {
                    Value = fs
                };
                command.Parameters.Add(p);
                try
                {
                    connection.Open();
                    num = command.ExecuteNonQuery();
                }
                catch (Exception exception1)
                {
                    throw new Exception(exception1.Message);
                }
                finally
                {
                    command.Dispose();
                    connection.Close();
                }
            }
            return(num);
        }
Example #2
0
 public void ExecuteSqlTran(Hashtable SQLStringList)
 {
     using (AseConnection connection = new AseConnection(this.connectionString))
     {
         connection.Open();
         using (AseTransaction transaction = connection.BeginTransaction())
         {
             AseCommand cmd = new AseCommand();
             try
             {
                 foreach (DictionaryEntry entry in SQLStringList)
                 {
                     string         cmdText  = entry.Key.ToString();
                     AseParameter[] cmdParms = (AseParameter[])entry.Value;
                     this.PrepareCommand(cmd, connection, transaction, cmdText, cmdParms);
                     cmd.ExecuteNonQuery();
                     cmd.Parameters.Clear();
                     transaction.Commit();
                 }
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
Example #3
0
        public int ExecuteSql(string SQLString, params AseParameter[] cmdParms)
        {
            int num;

            using (AseConnection connection = new AseConnection(this.connectionString))
            {
                AseCommand cmd = new AseCommand();
                try
                {
                    this.PrepareCommand(cmd, connection, null, SQLString, cmdParms);
                    cmd.Parameters.Clear();
                    num = cmd.ExecuteNonQuery();
                }
                catch (Exception exception1)
                {
                    throw new Exception(exception1.Message);
                }
                finally
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
            }
            return(num);
        }
Example #4
0
        public int ExecuteSql(string SQLString)
        {
            int num;

            using (AseConnection connection = new AseConnection(this.connectionString))
            {
                AseCommand command = new AseCommand(SQLString, connection);
                try
                {
                    connection.Open();
                    num = command.ExecuteNonQuery();
                }
                catch (Exception exception1)
                {
                    connection.Close();
                    throw new Exception(exception1.Message);
                }
                finally
                {
                    if (command != null)
                    {
                        command.Dispose();
                    }
                }
            }
            return(num);
        }
        /// <summary>
        /// 执行非查询SQL语句
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>受影响的记录数</returns>
        public override int ExecuteNoQuery(string sql, KdtParameterCollection parameters)
        {
            try
            {
                int effected = 0;

                // 执行SQL命令
                using (AseCommand cmd = new AseCommand(ReplaceSqlText(sql, parameters), _sybaseCn))
                {
                    InitCommand(cmd); // 初始化

                    // 赋值参数
                    var hasConvertParams = ConvertToSqlParameter(parameters);
                    foreach (var item in hasConvertParams)
                    {
                        cmd.Parameters.Add(item.Value);
                    }

                    effected = cmd.ExecuteNonQuery();

                    cmd.Cancel();
                    cmd.Dispose();
                }

                return(effected);
            }
            catch (Exception ex)
            {
                KdtLoger.Instance.Error(ex);
                throw new DataException(string.Format("执行非查询SQL语句错误,原因为:{0}", ex.Message));
            }
        }
Example #6
0
        public int ExecuteSql(string SQLString, string content)
        {
            int num;

            using (AseConnection connection = new AseConnection(this.connectionString))
            {
                AseCommand   command = new AseCommand(SQLString, connection);
                AseParameter p       = new AseParameter("@content", OracleType.NVarChar)
                {
                    Value = content
                };
                command.Parameters.Add(p);
                try
                {
                    connection.Open();
                    num = command.ExecuteNonQuery();
                }
                catch (Exception exception1)
                {
                    throw new Exception(exception1.Message);
                }
                finally
                {
                    command.Dispose();
                    connection.Close();
                }
            }
            return(num);
        }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="query"></param>
 /// <param name="commandType"></param>
 /// <param name="closeConnection"></param>
 /// <returns></returns>
 public int ExecuteNonQuery(string query, CommandType commandType = CommandType.Text, bool closeConnection = true)
 {
     comm.CommandText = query.ToString();
     comm.CommandType = commandType;
     try
     {
         if (_conn.State != ConnectionState.Open)
         {
             _conn.Open();
         }
         return(comm.ExecuteNonQuery());
     }
     catch (Exception ex)
     {
         throw;
     }
     finally
     {
         comm = new AseCommand();
         if (closeConnection)
         {
             comm.Dispose();
             if (_conn.State != ConnectionState.Closed)
             {
                 _conn.Close();
             }
         }
     }
 }
        /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ///  <summary> GET: Student/Delete/5 </summary>
        /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        public int DeleteClaims(List <string> claimIdList)
        {
            int claimsDeleted = 0;

            SybaseConnString = HomeController.SybaseConnString;

            using (var conn = new AseConnection(SybaseConnString))
            {
                conn.Open();

                foreach (var claimId in claimIdList)
                {
                    try
                    {
                        AseCommand cmd = new AseCommand("SP_XC_CLAIM_REJECTION_DELETE", conn);

                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add(new AseParameter("@TABLE_NAME", TableName));
                        cmd.Parameters.Add(new AseParameter("@CLCL_ID", claimId));

                        claimsDeleted += cmd.ExecuteNonQuery();
                    }

                    catch (Exception e)
                    {
                        System.Console.WriteLine("**ERROR INSERTING CLAIMS** : {0}", e.ToString());
                        throw e;
                    }
                }
            }
            return(claimsDeleted);
        }
        private void ExecutarQuerySemRetorno(string query, string strConn, List <AseParameter> parameters = null)
        {
            _log.TraceMethodStart();

            _log.Trace($"Query gerada: {query}");

            AseConnection connection = new AseConnection(strConn);
            AseCommand    cmd        = new AseCommand(query, connection);

            if (parameters != null)
            {
                cmd.Parameters.AddRange(parameters.ToArray());
            }

            try
            {
                connection.Open();
                cmd.ExecuteNonQuery();
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            _log.TraceMethodEnd();
        }
Example #10
0
        private void GetComaprisonReport()
        {
            using (AseConnection oCon = new AseConnection(sybConnectionString))
            {
                using (AseCommand oCom = new AseCommand("portia_load_dtc_comparison", oCon) { CommandType = CommandType.StoredProcedure })
                {
                    AseParameter oParam1 = new AseParameter("@trade_dt", AseDbType.DateTime);
                    oParam1.Value = new DateTime(2014, 03, 26);
                    oCom.Parameters.Add(oParam1);

                    oCon.Open();

                    try
                    {
                        oCom.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {

                    }

                }


            }
        }
Example #11
0
 public int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
 {
     using (AseConnection connection = new AseConnection(this.connectionString))
     {
         connection.Open();
         AseCommand command = this.BuildIntCommand(connection, storedProcName, parameters);
         rowsAffected = command.ExecuteNonQuery();
         return((int)command.Parameters["ReturnValue"].Value);
     }
 }
Example #12
0
        public int CargarData(DTO.clsCargaDatos ParametrosIngreso, out DTO.clsResultado resultado)
        {
            string strConexion = ConfigurationManager.ConnectionStrings["BDD_ANDALUCIA"].ConnectionString;

            resultado = new DTO.clsResultado();

            try
            {
                using (AseConnection con = new AseConnection(strConexion))
                {
                    con.Open();
                    using (AseCommand cmd = new AseCommand("anda_reporte..sp_cc_carga_datos_diario", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        if (ParametrosIngreso.Finmes != null)
                        {
                            cmd.Parameters.Add(new AseParameter("@i_fin_mes", AseDbType.Char, ParametrosIngreso.Finmes.Length, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Default, ParametrosIngreso.Finmes));
                        }

                        if (ParametrosIngreso.Fechadesde != null)
                        {
                            cmd.Parameters.Add(new AseParameter("@i_fecha_desde", AseDbType.DateTime, -1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Default, ParametrosIngreso.Fechadesde));
                        }
                        if (ParametrosIngreso.FechaHasta != null)
                        {
                            cmd.Parameters.Add(new AseParameter("@i_fecha_hasta", AseDbType.DateTime, -1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Default, ParametrosIngreso.FechaHasta));
                        }

                        cmd.Parameters.Add(new AseParameter("@O_RETVAL", AseDbType.Integer, 0, ParameterDirection.Output, false, 0, 0, "", DataRowVersion.Default, 0));
                        cmd.Parameters.Add(new AseParameter("@O_RETMSG", AseDbType.NVarChar, 128, ParameterDirection.Output, false, 0, 0, "", DataRowVersion.Default, ""));


                        cmd.ExecuteNonQuery();
                        resultado.Resultado = Convert.ToInt32(cmd.Parameters["@O_RETVAL"].Value);
                        resultado.Mensaje   = cmd.Parameters["@O_RETMSG"].Value.ToString();
                    }
                    con.Close();
                }
            }
            catch (Exception error)
            {
                string strSource = ConfigurationManager.AppSettings["NombreLog"];
                using (EventLog eventLog = new System.Diagnostics.EventLog("Application", Environment.MachineName, strSource))
                {
                    eventLog.WriteEntry("Error en DAL CuentaEliminar... " + " Descripción=  " + error.Message + " Stack: " + error.StackTrace, EventLogEntryType.Error, 0);
                }
                resultado.Resultado = -10;
                resultado.Mensaje   = error.Message;
            }
            return(resultado.Resultado);
        }
        /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ///  <summary> GET: Student/Delete/5 </summary>
        /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        public ClaimsSubmission GetAllClaims(ClaimsSubmission claimSub, string tableName)
        {
            ClaimDataAccessLayer.TableName = tableName;

            using (var conn = new AseConnection(HomeController.SybaseConnString))
            {
                int rowsRead = 0;

                try
                {
                    conn.Open();

                    AseCommand cmd = new AseCommand("SP_XC_CLAIM_REJECTION_READ", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new AseParameter("@TABLE_NAME", TableName));

                    rowsRead = cmd.ExecuteNonQuery();

                    if (rowsRead > 0)
                    {
                        AseDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            string claimid          = reader["CLCL_ID"].ToString();
                            string createdByUser    = reader["CREATED_BY_USER"].ToString();
                            string createdByService = reader["CREATED_BY_SERVICE"].ToString();
                            string createdDate      = reader["CREATED_DATE"].ToString();
                            string prprNpi          = reader["PRPR_NPI"].ToString();

                            Claim newClaim = new Claim()
                            {
                                ClaimId          = claimid,
                                CreatedByUser    = createdByUser,
                                CreatedByService = createdByService,
                                CreatedDate      = createdDate,
                                PrprNpi          = prprNpi
                            };

                            claimSub.ClaimList.Add(newClaim);
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("**ERROR READING CLAIMS** : {0}", e.ToString());
                }

                return(claimSub);
            }
        }
Example #14
0
        /// <summary>
        /// Eliminación de CorreoAplicacion por ID
        /// </summary>
        /// <param name="CorreoAplicacion">Información de CorreoAplicacion a ser eliminado</param>
        /// <param name="resultado">Obtiene el código y el mensaje de resultado</param>
        /// <returns>Retorna el código de error de la transacción. Si retorna 0 es OK</returns>
        public int CorreoAplicacionEliminar(DTO.clsCorreoAplicacion CorreoAplicacion, out DTO.clsResultado resultado)
        {
            string strConexion = ConfigurationManager.ConnectionStrings["CADENA"].ConnectionString;

            resultado = new DTO.clsResultado();

            try
            {
                using (AseConnection con = new AseConnection(strConexion))
                {
                    con.Open();
                    using (AseCommand cmd = new AseCommand("Correo_Aplicacion_DEL", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        if (CorreoAplicacion.Codigo != null)
                        {
                            cmd.Parameters.Add(new AseParameter("@I_Codigo", AseDbType.Integer, -1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Default, CorreoAplicacion.Codigo));
                        }


                        cmd.Parameters.Add(new AseParameter("@I_Version", AseDbType.DateTime, -1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Default, CorreoAplicacion.Version));

                        cmd.Parameters.Add(new AseParameter("@O_RETVAL", AseDbType.Integer, 0, ParameterDirection.Output, false, 0, 0, "", DataRowVersion.Default, 0));
                        cmd.Parameters.Add(new AseParameter("@O_RETMSG", AseDbType.NVarChar, 128, ParameterDirection.Output, false, 0, 0, "", DataRowVersion.Default, ""));


                        cmd.ExecuteNonQuery();
                        resultado.Resultado = Convert.ToInt32(cmd.Parameters["@O_RETVAL"].Value);
                        resultado.Mensaje   = cmd.Parameters["@O_RETMSG"].Value.ToString();
                    }
                    con.Close();
                }
            }
            catch (Exception error)
            {
                string strSource = ConfigurationManager.AppSettings["NombreLog"];
                using (EventLog eventLog = new System.Diagnostics.EventLog("Application", Environment.MachineName, strSource))
                {
                    eventLog.WriteEntry("Error en DAL CorreoAplicacionEliminar... " + " Descripción=  " + error.Message + " Stack: " + error.StackTrace, EventLogEntryType.Error, 0);
                }
                resultado.Resultado = -10;
                resultado.Mensaje   = ConfigurationManager.AppSettings["ErrorInternoMensaje"];
            }
            return(resultado.Resultado);
        }
        private void GetComparison(DateTime tradeDate)
        {
            using (AseConnection oCon = new AseConnection("Data Source=mcmqavip;port=4105;Database=MCM;Uid=idsi;Pwd=3idsi3;"))
            {
                using (AseCommand oCom = new AseCommand("portia_load_dtc_comparison", oCon) { CommandType = CommandType.StoredProcedure })
                {
                    AseParameter oParam = new AseParameter("@trade_dt", AseDbType.DateTime) { Value = tradeDate };
                    oCom.Parameters.Add(oParam);
                    oCon.Open();
                    try
                    {
                        oCom.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }
Example #16
0
 public int InsertDataUsingStoredProcedure(string storedProcedureName, DatabaseEnum dbName, List<AseParameter> parameters)
 {
     var connFactory = new ConnectionFactory();
     int _errorCode = 0;
     string connectionString = connFactory.GetConnectionString(dbName);
     using (conn = connFactory.GetAseConnectionString(connectionString))
     {
         try
         {
             conn.Open();
             if (conn.State == ConnectionState.Open)
             {
                 using (cmd = conn.CreateCommand())
                 {
                     cmd.CommandType = CommandType.StoredProcedure;
                     cmd.CommandText = storedProcedureName;
                     if (parameters != null )
                     {
                         foreach (AseParameter param in parameters)
                         {
                             cmd.Parameters.Add(param);
                         }
                     }
                    _errorCode = cmd.ExecuteNonQuery();
                 }
             }
         }
         catch (AseException ex)
         {
             _logger.ErrorFormat("Error Inserting Data into Database {0}", ex);
             throw;
         }
         finally
         {
             conn.Close();
         }
     }
     return _errorCode;
 }
Example #17
0
        public override int ExecuteNoQuery(string cmdText, DBHelperParmCollection parameters)
        {
            int        effectNum;
            AseCommand _AseCommand = (AseCommand)CreateCommand(cmdText, CommandType.Text);

            _AseCommand.Parameters.Clear();
            if (parameters != null)
            {
                foreach (DBHelperParm para in parameters)
                {
                    _AseCommand.Parameters.Add(new AseParameter(para.Key, EncodingHelper.Default2DB(para.Value, _DBEncodeing)));
                }
            }
            try
            {
                effectNum = _AseCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            _AseCommand.Parameters.Clear();
            return(effectNum);
        }
        /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ///  <summary>   </summary>
        /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        public int AddAndEnrichClaims(ClaimsSubmission req, string tableName, string httpContextUser)
        {
            int claimsInserted = 0;

            TableName = tableName;
            req.SetClaims(); // Build claim list from string input
            SybaseConnString = HomeController.SybaseConnString;

            using (var conn = new AseConnection(SybaseConnString))
            {
                AseTransaction trans = conn.BeginTransaction(); // START LOCKING TABLE HERE!!!

                try
                {
                    conn.Open();
                    AseCommand cmd;

                    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    // INSERT NEW CLAIM DELETIONS TO STAGING TABLES
                    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    foreach (var claim in req.ClaimList)
                    {
                        try
                        {
                            cmd             = new AseCommand("SP_XC_CLAIM_REJECTION_INSERT", conn);
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.Add(new AseParameter("@TABLE_NAME", TableName));
                            cmd.Parameters.Add(new AseParameter("@CLCL_ID", claim.ClaimId));
                            cmd.Parameters.Add(new AseParameter("@CREATED_BY_USER", httpContextUser));

                            if (cmd.ExecuteNonQuery() > 0)
                            {
                                claimsInserted++;
                            }

                            else
                            {
                                req.InvalidClaimList.Add(claim.ClaimId);
                            }
                        }
                        catch (Exception e)
                        {
                            if (e.ToString().ToUpper().Contains("DUPLICATE KEY ROW"))
                            {
                                req.DupClaimList.Add(claim.ClaimId);
                            }

                            System.Console.WriteLine("**ERROR INSERTING CLAIMS** : {0}", e.ToString());
                        }
                    }

                    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    // NOW ENRICH THE NEWLY INSERTED CLAIM DELETIONS
                    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    if (TableName.ToUpper().Contains("NPI"))
                    {
                        cmd             = new AseCommand("SP_XC_CLAIM_REJECTION_ENRICH_NPI", conn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.ExecuteNonQuery();
                    }

                    else if (TableName.ToUpper().Contains("NAME"))
                    {
                        cmd             = new AseCommand("SP_XC_CLAIM_REJECTION_ENRICH_NAME", conn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.ExecuteNonQuery();
                    }

                    else if (TableName.ToUpper().Contains("TIN"))
                    {
                        cmd             = new AseCommand("SP_XC_CLAIM_REJECTION_ENRICH_TIN", conn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.ExecuteNonQuery();
                    }

                    trans.Commit(); // COMMIT THE TRANSACTION
                }

                catch (Exception e)
                {
                    Console.WriteLine("*****************************************");
                    Console.WriteLine("INSERT ERROR!! --ROLLBACK TRANSACTION--");
                    Console.WriteLine("*****************************************");
                    Console.WriteLine(e.ToString());

                    trans.Rollback(); // **** Abort transaction ****
                    throw e;
                }
            }

            return(claimsInserted);
        }
        private void UpdateSybaseData(DataTable dtPortia)
        {
            using (AseConnection oCon = new AseConnection("Data Source=mcmqavip;port=4105;Database=MCM;Uid=idsi;Pwd=3idsi3;"))
            {
                using (AseCommand oCom = new AseCommand(Constants.InsertPortiaToSybase, oCon) { CommandType = CommandType.StoredProcedure, CommandTimeout = 5000 })
                {

                    oCon.Open();
                    foreach (DataRow row in dtPortia.Rows)
                    {
                        oCom.Parameters.Add(new AseParameter("@id", Convert.ToInt32(row["id"])));
                        oCom.Parameters.Add(new AseParameter("@tran_#", Convert.ToInt32(row["tran_#"])));
                        oCom.Parameters.Add(new AseParameter("@portfolio_nm", row["portfolio"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@portfolio", row["portfolio_code"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@security_nm", row["security"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@cusip", row["cusip"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@lot_#", Convert.ToInt32(row["lot_#"])));
                        oCom.Parameters.Add(new AseParameter("@tran_type_id", Convert.ToInt32(row["tran_type_id"])));
                        oCom.Parameters.Add(new AseParameter("@tran_type", row["tran_type"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@trade_date", Convert.ToDateTime(row["trade_date"])));
                        oCom.Parameters.Add(new AseParameter("@settle_date", Convert.ToDateTime(row["settle_date"])));
                        oCom.Parameters.Add(new AseParameter("@maturity_date", Convert.ToDateTime(row["maturity_date"])));
                        oCom.Parameters.Add(new AseParameter("@issue_date", Convert.ToDateTime(row["issue_date"])));
                        oCom.Parameters.Add(new AseParameter("@coupon_rate", Convert.ToDouble(row["coupon_rate"])));
                        oCom.Parameters.Add(new AseParameter("@broker", row["broker"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@broker_number", row["broker_number"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@quantity", Convert.ToDouble(row["quantity"])));
                        oCom.Parameters.Add(new AseParameter("@face_value", Convert.ToDouble(row["face_value"])));
                        oCom.Parameters.Add(new AseParameter("@price", Convert.ToDouble(row["price"])));
                        oCom.Parameters.Add(new AseParameter("@commission", Convert.ToDouble(row["commission"])));
                        oCom.Parameters.Add(new AseParameter("@sec_fee", Convert.ToDouble(row["sec_fee"])));
                        oCom.Parameters.Add(new AseParameter("@total_amount", Convert.ToDouble(row["total_amount"])));
                        oCom.Parameters.Add(new AseParameter("@entry_status", row["entry_status"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@post_date", Convert.ToDateTime(row["post_date"])));
                        oCom.Parameters.Add(new AseParameter("@settlement_country", row["settlement_country"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@currency_id", row["currency_id"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@price_symbol", row["price_symbol"].ToString()));
                        oCom.Parameters.Add(new AseParameter("@interest", Convert.ToDouble(row["interest"])));
                        oCom.Parameters.Add(new AseParameter("@principal_amount", Convert.ToDouble(row["principal_amount"])));
                        oCom.Parameters.Add(new AseParameter("@sec_type", row["sec_type"].ToString()));

                        try
                        {
                            oCom.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {

                        }

                    }
                }
            }
        }
Example #20
0
        /// <summary>
        /// 更新DataTable的方式插入数据
        /// </summary>
        /// <param name="_dt">DataTable</param>
        /// <returns>插入记录条数</returns>
        public override int DataTableInsert(DataTable _dt)
        {
            bool flag     = false;
            int  _nResult = 0;

            if (_dt == null)
            {
                return(_nResult);
            }
            string            _sCmdText = string.Format("select * from {0} where 1=2", _dt.TableName);
            AseCommand        _Command  = (AseCommand)CreateCommand(_sCmdText, CommandType.Text);
            AseDataAdapter    _adapter  = new AseDataAdapter(_Command);
            AseDataAdapter    _adapter1 = new AseDataAdapter(_Command);
            AseCommandBuilder _builder  = new AseCommandBuilder(_adapter1);

            _adapter.InsertCommand = _builder.GetInsertCommand();

            if (_adapter.InsertCommand.Parameters.Count < _dt.Columns.Count)
            {
                flag = true;//因为表中有自增字段,所以CommandBuild生成的InserttCommand的参数中少了自增字段
                foreach (DataColumn _dc in _dt.Columns)
                {
                    if (!_adapter.InsertCommand.Parameters.Contains(_dc.ColumnName))
                    {
                        _adapter.InsertCommand.CommandText =
                            _adapter.InsertCommand.CommandText.Insert(_adapter.InsertCommand.CommandText.IndexOf(") VALUES"), ',' + _dc.ColumnName);

                        _adapter.InsertCommand.CommandText =
                            _adapter.InsertCommand.CommandText.Insert(_adapter.InsertCommand.CommandText.Length - 1, ",@" + _dc.ColumnName);

                        _adapter.InsertCommand.Parameters.Add("@" + _dc.ColumnName, AseDbType.Decimal, _dc.MaxLength, _dc.ColumnName);

                        if (_adapter.InsertCommand.Parameters.Count >= _dt.Columns.Count)
                        {
                            break;
                        }
                    }
                }
            }

            if (flag)
            {
                this.ExecuteNoQuery(string.Format("SET IDENTITY_INSERT {0} on", _dt.TableName));
            }

            this.BeginTransaction();
            try
            {
                _Command.CommandText = "delete from " + _dt.TableName;
                _Command.ExecuteNonQuery();
                _adapter.InsertCommand.Transaction = _Command.Transaction;
                _nResult = _adapter.Update(_dt);
                this.CommitTransaction();
            }
            catch (Exception ex)
            {
                this.RollbackTransaction();
                throw ex;
            }
            finally
            {
                if (flag)
                {
                    this.ExecuteNoQuery(string.Format("SET IDENTITY_INSERT {0} OFF", _dt.TableName));
                }
            }
            return(_nResult);
        }
    private void GetComaprisonReport(DateTime tradeDate)
    {
        string strCon = ConfigurationSettings.AppSettings["ConnectionSybaseMCM_STAGE"];
        using (AseConnection oCon = new AseConnection(strCon))
        {
            using (AseCommand oCom = new AseCommand("portia_load_dtc_comparison", oCon) { CommandType = CommandType.StoredProcedure })
            {
                AseParameter oParam1 = new AseParameter("@trade_dt", AseDbType.DateTime);
                oParam1.Value = tradeDate;
                oCom.Parameters.Add(oParam1);

                oCon.Open();

                try
                {
                    oCom.ExecuteNonQuery();
                }
                catch (Exception ex)
                {

                }
            }
        }
        dtCompare = GetCompareRecords();
        ExportDataTableTOExcel(dtCompare,tradeDate);

    }
    private void UpdateSybase(System.Data.DataTable dtPortiaa)
    {
        string strCon = ConfigurationSettings.AppSettings["ConnectionSybaseMCM_STAGE"];
        using (AseConnection oCon = new AseConnection(strCon))
        {

            using (AseCommand oCom = new AseCommand("insert_mcm_dtc_recon", oCon) { CommandType = CommandType.StoredProcedure, CommandTimeout = 5000 })
            {

                oCon.Open();

                foreach (DataRow row in dtPortiaa.Rows)
                {
                    //oCom.Parameters.Add(new AseParameter("@id", Convert.ToInt32(row["id"])));
                    //oCom.Parameters.Add(new AseParameter("@tran_#", Convert.ToInt32(row["tran_#"])));
                    ////oCom.Parameters.Add(new AseParameter("@trade_list_id",row["trade_list_id"]));
                    //oCom.Parameters.Add(new AseParameter("@portfolio_nm", row["portfolio"].ToString()));
                    oCom.Parameters.Add(new AseParameter("@portfolio", row["portfolio_code"].ToString()));
                    oCom.Parameters.Add(new AseParameter("@cusip", row["cusip"].ToString()));
                    //oCom.Parameters.Add(new AseParameter("@lot_#", Convert.ToInt32(row["lot_#"])));
                    //oCom.Parameters.Add(new AseParameter("@tran_type_id", Convert.ToInt32(row["tran_type_id"])));
                    oCom.Parameters.Add(new AseParameter("@tran_type", row["tran_type"].ToString()));
                    oCom.Parameters.Add(new AseParameter("@trade_date", Convert.ToDateTime(row["trade_date"])));
                    oCom.Parameters.Add(new AseParameter("@settle_date", Convert.ToDateTime(row["settle_date"])));
                    oCom.Parameters.Add(new AseParameter("@price", Convert.ToDouble(row["price"])));
                    oCom.Parameters.Add(new AseParameter("@sec_type", row["sec_type"].ToString()));
                    oCom.Parameters.Add(new AseParameter("@security_nm", row["security"].ToString()));
                    //oCom.Parameters.Add(new AseParameter("@maturity_date", Convert.ToDateTime(row["maturity_date"])));
                    //oCom.Parameters.Add(new AseParameter("@issue_date", Convert.ToDateTime(row["issue_date"])));
                    //oCom.Parameters.Add(new AseParameter("@coupon_rate", Convert.ToDouble(row["coupon_rate"])));
                    oCom.Parameters.Add(new AseParameter("@broker", row["broker"].ToString()));
                    oCom.Parameters.Add(new AseParameter("@broker_number", row["broker_number"].ToString()));
                    oCom.Parameters.Add(new AseParameter("@face_value", Convert.ToDouble(row["face_value"])));
                    oCom.Parameters.Add(new AseParameter("@quantity", Convert.ToDouble(row["quantity"])));
                    //oCom.Parameters.Add(new AseParameter("@commission", Convert.ToDouble(row["commission"])));
                    //oCom.Parameters.Add(new AseParameter("@sec_fee", Convert.ToDouble(row["sec_fee"])));
                    oCom.Parameters.Add(new AseParameter("@total_amount", Convert.ToDouble(row["total_amount"])));
                    oCom.Parameters.Add(new AseParameter("@entry_status", row["entry_status"].ToString()));
                    //oCom.Parameters.Add(new AseParameter("@raw_id",row["raw_id"]));
                    //oCom.Parameters.Add(new AseParameter("@post_date", Convert.ToDateTime(row["post_date"])));
                    //oCom.Parameters.Add(new AseParameter("@settlement_country", row["settlement_country"].ToString()));
                    //oCom.Parameters.Add(new AseParameter("@currency_id", row["currency_id"].ToString()));
                    //oCom.Parameters.Add(new AseParameter("@price_symbol", row["price_symbol"].ToString()));
                    oCom.Parameters.Add(new AseParameter("@interest", Convert.ToDouble(row["interest"])));
                    oCom.Parameters.Add(new AseParameter("@principal_amount", Convert.ToDouble(row["principal_amount"])));

                    try
                    {
                        oCom.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {

                    }

                }
            }
        }
    }
 private void DeleteExistingRecords()
 {
     string strCon = ConfigurationSettings.AppSettings["ConnectionSybaseMCM_STAGE"];
     using (AseConnection oCon = new AseConnection(strCon))
     {
         using (AseCommand oCom = new AseCommand("Delete from MCM_DTC_MTF", oCon) { CommandType = CommandType.Text })
         {
             oCon.Open();
             oCom.ExecuteNonQuery();
         }
         using (AseCommand oCom = new AseCommand("Delete from Confirms_DifferenceTable", oCon) { CommandType = CommandType.Text })
         {
             oCon.Open();
             oCom.ExecuteNonQuery();
         }
     }
 }
        private object AddAccount(object param)
        {
            string dtcAccount = ((Tuple<string, string>)param).Item1;
            string portiaAccount = ((Tuple<string, string>)param).Item2;
            if (!string.IsNullOrEmpty(dtcAccount) && !string.IsNullOrEmpty(portiaAccount))
            {
                using (AseConnection con = new AseConnection(model.Constants.SybaseConnection))
                {
                    using (AseCommand com = new AseCommand(model.Constants.InsertAccount, con) { CommandType = CommandType.Text })
                    {
                        AseParameter oParam = new AseParameter("@dtcAccountNumber", AseDbType.VarChar);
                        oParam.Value = dtcAccount;
                        com.Parameters.Add(oParam);

                        AseParameter oParam1 = new AseParameter("@portiaAccountNumber", AseDbType.VarChar);
                        oParam1.Value = portiaAccount;
                        com.Parameters.Add(oParam1);

                        con.Open();
                        try
                        {
                            com.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }
            }
            //DtcAccountNum = string.Empty;
            //PortiaAccountNum = string.Empty;
            return null;
        }
        private object AddBroker(object param)
        {
            string portiaName = ((Tuple<string, string,string>)param).Item1;
            string dtcName = ((Tuple<string, string, string>)param).Item2;
            string execBrokerId = ((Tuple<string, string, string>)param).Item3;
            if (!string.IsNullOrEmpty(dtcName) && !string.IsNullOrEmpty(portiaName))
            {
                using (AseConnection con = new AseConnection(model.Constants.SybaseConnection))
                {
                    using (AseCommand com = new AseCommand(model.Constants.InsertBroker, con) { CommandType = CommandType.Text })
                    {
                        AseParameter oParam = new AseParameter("@portiaBrokerName", AseDbType.VarChar);
                        oParam.Value = portiaName;
                        com.Parameters.Add(oParam);

                        AseParameter oParam1 = new AseParameter("@dtcBrokerName", AseDbType.VarChar);
                        oParam1.Value = dtcName;
                        com.Parameters.Add(oParam1);

                        AseParameter oParam2 = new AseParameter("@executingBrokerId", AseDbType.VarChar);
                        oParam2.Value = execBrokerId;
                        com.Parameters.Add(oParam2);

                        con.Open();
                        try
                        {
                            com.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }
            }
            DtcBrokerName = string.Empty;
            PortiaBrokerName = string.Empty;
            ExecBrokerId = string.Empty;
            return null;
        }
Example #26
0
        static int Main(string[] args)
        {
            int
                Result = -1,
                tmpInt;

            decimal
                tmpDecimal;

            object
                tmpObject;

            StreamWriter
                fstr_out = null;

            string
                tmpString,
                OutputFileName = "log.log";

                        #if WITH_TRACE
            string
                TraceFileName = "trace.log";
                        #endif

            AseConnection
                conn = null;

            AseCommand
                cmd = null;

            AseTransaction
                Transaction = null;

            AseDataReader
                reader = null;

            AseParameter
                Parameter = null;

            AseDataAdapter
                da = null;

            DataTable
                tmpDataTable = null;

            try
            {
                try
                {
                    fstr_out           = new StreamWriter(OutputFileName, false, System.Text.Encoding.GetEncoding(1251));
                    fstr_out.AutoFlush = true;

                                        #if WITH_REFLECTION
                    Assembly[]
                    asms = AppDomain.CurrentDomain.GetAssemblies();

                    Assembly
                        asm = null;

                    foreach (Assembly a in asms)
                    {
                        if (a.FullName.ToLower().IndexOf("sybase.data.aseclient") > -1)
                        {
                            asm = a;
                        }

                        fstr_out.WriteLine("Assembly.CodeBase: " + a.CodeBase);
                        fstr_out.WriteLine("Assembly.EscapedCodeBase: " + a.EscapedCodeBase);
                        fstr_out.WriteLine("Assembly.FullName: " + a.FullName);
                        fstr_out.WriteLine("Assembly.GlobalAssemblyCache: " + a.GlobalAssemblyCache.ToString().ToLower());
                        fstr_out.WriteLine("Assembly.ImageRuntimeVersion: " + a.ImageRuntimeVersion);
                        fstr_out.WriteLine("Assembly.Location: " + a.Location);
                        fstr_out.WriteLine();
                    }

                    if (asm != null)
                    {
                        Type[]
                        alltypes = asm.GetTypes();

                        for (tmpInt = 0; tmpInt < alltypes.Length; ++tmpInt)
                        {
                            fstr_out.WriteLine("Обнаружено: " + alltypes[tmpInt].Name);
                            if (alltypes[tmpInt].Name.CompareTo("AseConnection") == 0)
                            {
                                Type
                                    t = alltypes[tmpInt];

                                FieldInfo[]
                                fi = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

                                fstr_out.WriteLine("Анализ Field, определенных в " + t.Name);
                                foreach (FieldInfo f in fi)
                                {
                                    fstr_out.Write("   " + f.Name);
                                    fstr_out.WriteLine();
                                }
                                fstr_out.WriteLine();

                                PropertyInfo[]
                                //pi_=t.GetProperties(BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Static); // AseConnection.Language
                                pi_ = t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

                                fstr_out.WriteLine("Анализ Property, определенных в " + t.Name);
                                foreach (PropertyInfo p_ in pi_)
                                {
                                    fstr_out.Write("   " + p_.Name);
                                    fstr_out.WriteLine();
                                }
                                fstr_out.WriteLine();

                                fstr_out.WriteLine("Поддерживаемые методы:");

                                ParameterInfo[]
                                pi;

                                MethodInfo[]
                                mi;

                                //mi=t.GetMethods();
                                mi = t.GetMethods(BindingFlags.DeclaredOnly
                                                  | BindingFlags.Instance
                                                  | BindingFlags.Public);

                                foreach (MethodInfo m in mi)
                                {
                                    fstr_out.Write("   " + m.ReturnType.Name + " " + m.Name + "(");
                                    pi = m.GetParameters();

                                    for (int i = 0; i < pi.Length; ++i)
                                    {
                                        fstr_out.Write(pi[i].ParameterType.Name + " " + pi[i].Name);
                                        if (i + 1 < pi.Length)
                                        {
                                            fstr_out.Write(", ");
                                        }
                                    }
                                    fstr_out.WriteLine(")");
                                }
                                fstr_out.WriteLine();
                            }
                        }
                        fstr_out.WriteLine();
                    }
                                        #endif

                                        #if WITH_TRACE
                    _strmWriter           = new StreamWriter(TraceFileName, false, System.Text.Encoding.GetEncoding(1251));
                    _strmWriter.AutoFlush = true;
                                        #endif

                    if ((tmpString = ConfigurationSettings.AppSettings["connectionString"]) == null ||
                        tmpString == string.Empty)
                    {
                        fstr_out.WriteLine("ConfigurationSettings.AppSettings[\"connectionString\"] is empty!!!");
                        return(Result);
                    }

                    conn              = new AseConnection(tmpString);
                    conn.InfoMessage += new AseInfoMessageEventHandler(conn_InfoMessage);
                    conn.StateChange += new System.Data.StateChangeEventHandler(conn_StateChange);
                                        #if WITH_TRACE
                    conn.TraceEnter += new TraceEnterEventHandler(conn_TraceEnter);
                    conn.TraceExit  += new TraceExitEventHandler(conn_TraceExit);
                                        #endif
                    conn.Open();

                    fstr_out.WriteLine("AseConnection.ConnectionString: " + conn.ConnectionString);
                    fstr_out.WriteLine("AseConnection.ConnectionTimeout: " + conn.ConnectionTimeout);
                    fstr_out.WriteLine("AseConnection.Database: " + conn.Database);
                    fstr_out.WriteLine("AseConnection.NamedParameters: " + conn.NamedParameters.ToString().ToLower());
                    fstr_out.WriteLine("AseConnection.State: " + conn.State);
                    fstr_out.WriteLine("AseConnection.DriverVersion: " + AseConnection.DriverVersion);
                    //fstr_out.WriteLine("AseConnection.Language: "+AseConnection.Language);
                    fstr_out.WriteLine();

                    cmd             = conn.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "select @@spid";

                    if ((tmpObject = cmd.ExecuteScalar()) != null)
                    {
                        tmpString = Convert.ToString(tmpObject);
                    }

                                        #if TEST_CHARSET
                    cmd.CommandText = "select cast(val as date) from T4 where GroupId=4 and Id=1";
                    if (da == null)
                    {
                        da = new AseDataAdapter(cmd);
                    }
                    else
                    {
                        da.SelectCommand = cmd;
                    }

                    if (tmpDataTable == null)
                    {
                        tmpDataTable = new DataTable();
                    }
                    else
                    {
                        tmpDataTable.Reset();
                    }

                    da.Fill(tmpDataTable);
                                        #endif

                                        #if TEST_EXECUTE_NON_QUERY
                    if (cmd == null)
                    {
                        cmd = conn.CreateCommand();
                    }
                    cmd.NamedParameters = false;
                    cmd.CommandType     = CommandType.Text;
                    cmd.Parameters.Clear();
                    cmd.CommandText = "update Victim set Val = ? where Id = ?";
                    cmd.Parameters.Add("Val", AseDbType.Integer);
                    cmd.Parameters.Add("Id", AseDbType.Integer);
                    for (int Id = 1; Id <= 5; Id += 2)
                    {
                        cmd.Parameters["Val"].Value = Id;
                        cmd.Parameters["Id"].Value  = Id;
                        tmpInt = cmd.ExecuteNonQuery();
                    }
                    cmd.NamedParameters = true;
                                        #endif

                                        #if TEST_BLOB
                    if (cmd == null)
                    {
                        cmd = conn.CreateCommand();
                    }

                    cmd.CommandType = CommandType.Text;

                    FileStream
                        fs;

                    byte[]
                    Blob;

                                                #if TEST_BLOB_SAVE
                    tmpString       = "@FImage";
                    cmd.CommandText = "update TestTypes set FImage = " + tmpString;
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(tmpString, AseDbType.Image);
                    fs   = new FileStream("welcome.bmp", FileMode.Open, FileAccess.Read);
                    Blob = new byte[fs.Length];
                    fs.Read(Blob, 0, Blob.Length);
                    cmd.Parameters[tmpString].Value = Blob;
                    tmpInt = cmd.ExecuteNonQuery();
                                                #endif

                    cmd.Parameters.Clear();
                    cmd.CommandText = "select * from TestTypes";
                    reader          = cmd.ExecuteReader();

                    do
                    {
                        if (reader.HasRows)
                        {
                            for (int i = 0; i < reader.FieldCount; ++i)
                            {
                                fstr_out.WriteLine(reader.GetName(i) + " GetDataTypeName(): \"" + reader.GetDataTypeName(i) + "\" GetFieldType(): \"" + reader.GetFieldType(i) + "\"");
                            }

                            tmpInt = reader.GetOrdinal("FImage");

                            while (reader.Read())
                            {
                                tmpString = "FromBlob.bmp";
                                if (File.Exists(tmpString))
                                {
                                    File.Delete(tmpString);
                                }

                                Blob = (byte[])reader["FImage"];
                                fs   = new FileStream(tmpString, FileMode.Create);
                                fs.Write(Blob, 0, Blob.Length);
                                fs.Close();

                                tmpString = "FromBlob_1.bmp";
                                if (File.Exists(tmpString))
                                {
                                    File.Delete(tmpString);
                                }

                                Blob = new byte[reader.GetBytes(tmpInt, 0, null, 0, int.MaxValue)];
                                reader.GetBytes(tmpInt, 0, Blob, 0, Blob.Length);
                                fs = new FileStream(tmpString, FileMode.Create);
                                fs.Write(Blob, 0, Blob.Length);
                                fs.Close();
                            }
                        }
                    }while(reader.NextResult());
                    reader.Close();
                                        #endif

                                        #if TEST_SMTH
                    if (cmd == null)
                    {
                        cmd = conn.CreateCommand();
                    }

                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "select * from TestDate order by FDate";
                    cmd.Parameters.Clear();

                    if (da == null)
                    {
                        da = new AseDataAdapter(cmd);
                    }
                    else
                    {
                        da.SelectCommand = cmd;
                    }

                    if (tmpDataTable != null)
                    {
                        tmpDataTable.Reset();
                    }
                    else
                    {
                        tmpDataTable = new DataTable();
                    }

                    da.Fill(tmpDataTable);

                    tmpString = "";
                    for (int i = 0; i < tmpDataTable.Rows.Count; ++i)
                    {
                        if (tmpString != string.Empty)
                        {
                            tmpString += " ";
                        }
                        tmpString += Convert.ToDateTime(tmpDataTable.Rows[i]["FDate"]).ToString("yyyy-MM-dd");
                    }

                    cmd.NamedParameters = false;
                    cmd.CommandText     = "update TestTypes set FDatetime = ?";
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add("FDate", AseDbType.DateTime).Value = DateTime.Now;
                    tmpInt = cmd.ExecuteNonQuery();

                    cmd.NamedParameters = true;
                    cmd.CommandText     = "update TestTypes set FDatetime = @FDatetime";
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add("@FDatetime", AseDbType.DateTime).Value = DateTime.Now;
                    tmpInt = cmd.ExecuteNonQuery();
                                        #endif

                                        #if TEST_DATA_ADAPTER_FILL_SCHEMA
                    if (cmd == null)
                    {
                        cmd = conn.CreateCommand();
                    }

                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "select * from Staff";

                    if (da == null)
                    {
                        da = new AseDataAdapter(cmd);
                    }
                    else
                    {
                        da.SelectCommand = cmd;
                    }

                    if (tmpDataTable != null)
                    {
                        tmpDataTable.Reset();
                    }
                    else
                    {
                        tmpDataTable = new DataTable();
                    }

                    da.FillSchema(tmpDataTable, SchemaType.Source);
                                        #endif

                                        #if TEST_STORED_PROCEDURES
                    if (cmd == null)
                    {
                        cmd = conn.CreateCommand();
                    }

                    object[]
                    tmpObjects = new object[] { 5, 6 };

                    cmd.CommandType     = CommandType.StoredProcedure;
                    cmd.NamedParameters = false;
                    cmd.CommandType     = CommandType.StoredProcedure;
                    cmd.CommandText     = "mathtutor";
                    for (int i = 0; i < tmpObjects.Length; ++i)
                    {
                        Parameter = new AseParameter();
                        Parameter.ParameterName = "Param" + i;
                        switch (Type.GetTypeCode(tmpObjects[i].GetType()))
                        {
                        case System.TypeCode.Int32:
                        {
                            Parameter.DbType = DbType.Int32;
                            break;
                        }
                        }
                        Parameter.Value = tmpObjects[i];
                        cmd.Parameters.Add(Parameter);
                    }
                    Parameter = new AseParameter();
                    Parameter.ParameterName = "Param3";
                    Parameter.DbType        = DbType.Int32;
                    Parameter.Direction     = ParameterDirection.Output;
                    cmd.Parameters.Add(Parameter);
                    cmd.ExecuteNonQuery();
                    tmpInt = !Convert.IsDBNull(cmd.Parameters["Param3"].Value) ? Convert.ToInt32(cmd.Parameters["Param3"].Value) : Int32.MinValue;

                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "sp_TestTypes_Decimal_10_6";
                    AseCommandBuilder.DeriveParameters(cmd);
                    cmd.Parameters["@FDecimal_10_6"].Value = 123.45m;
                    cmd.ExecuteNonQuery();
                    tmpDecimal = !Convert.IsDBNull(cmd.Parameters["@FDecimal_10_6_out"].Value) ? Convert.ToDecimal(cmd.Parameters["@FDecimal_10_6_out"].Value) : decimal.MinValue;

                    cmd.Parameters.Clear();
                    cmd.CommandType     = CommandType.Text;
                    cmd.CommandText     = "{? = call sp_TestTypes_Decimal_10_6(? ,?)}";
                    cmd.NamedParameters = false;

                    Parameter           = new AseParameter("@RETURN_VALUE", AseDbType.Integer);
                    Parameter.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(Parameter);

                    Parameter = new AseParameter("@FDecimal_10_6", AseDbType.Decimal);                          //AseDbType.Numeric
                    //Parameter=new AseParameter();
                    //Parameter.ParameterName="@FDecimal_10_6";
                    //Parameter.DbType=DbType.Decimal;
                    //Parameter.AseDbType=AseDbType.Decimal; //AseDbType.Numeric
                    Parameter.Direction = ParameterDirection.Input;
                    //Parameter.Precision=10;
                    //Parameter.Scale=6;
                    Parameter.Value = 123.45m;
                    cmd.Parameters.Add(Parameter);

                    Parameter           = new AseParameter("@FDecimal_10_6_out", AseDbType.Decimal);                 //AseDbType.Numeric
                    Parameter.Direction = ParameterDirection.Output;
                    Parameter.Precision = 10;
                    Parameter.Scale     = 6;
                    cmd.Parameters.Add(Parameter);

                    cmd.ExecuteNonQuery();
                    tmpDecimal = !Convert.IsDBNull(cmd.Parameters["@FDecimal_10_6_out"].Value) ? Convert.ToDecimal(cmd.Parameters["@FDecimal_10_6_out"].Value) : decimal.MinValue;

                    tmpDecimal = 2;

                    if (cmd == null)
                    {
                        cmd = conn.CreateCommand();
                    }

                    cmd.Parameters.Clear();
                    cmd.CommandType     = CommandType.Text;
                    cmd.CommandText     = "{call UpdateTestTypes(?)}";
                    cmd.NamedParameters = false;

                    Parameter           = new AseParameter("@rate", AseDbType.Decimal);
                    Parameter.Direction = ParameterDirection.Input;
                    Parameter.Value     = tmpDecimal;
                    cmd.Parameters.Add(Parameter);

                    /*
                     * if(cmd==null)
                     *      cmd=conn.CreateCommand();
                     *
                     * cmd.CommandType=CommandType.StoredProcedure;
                     * cmd.CommandText="UpdateTestTypes";
                     * AseCommandBuilder.DeriveParameters(cmd);
                     * cmd.Parameters["@Decimal_18_4"].Value=tmpDecimal;
                     */

                    tmpInt = cmd.ExecuteNonQuery();

                    cmd.CommandType = CommandType.StoredProcedure;
                    for (int size = 255; size <= 258; ++size)
                    {
                        cmd.CommandText = "sp_ReturnAndOutputVarChar" + size;
                        AseCommandBuilder.DeriveParameters(cmd);
                        cmd.ExecuteNonQuery();
                        tmpString = !Convert.IsDBNull(cmd.Parameters["@OutParam"].Value) ? Convert.ToString(cmd.Parameters["@OutParam"].Value) : "NULL";
                    }

                    conn.ChangeDatabase("master");
                    cmd.CommandText = "testdb..sp_ReturnAndOutput";
                    AseCommandBuilder.DeriveParameters(cmd);
                    conn.ChangeDatabase("testdb");
                                        #endif

                    Transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted);

                    if (cmd == null)
                    {
                        cmd = conn.CreateCommand();
                    }
                    cmd.Transaction = Transaction;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "sp_Staff_Save";
                    //cmd.CommandText="sp_TestTypes";
                    fstr_out.WriteLine("AseCommandBuilder.DeriveParameters(\"" + cmd.CommandText + "\")");
                    AseCommandBuilder.DeriveParameters(cmd);
                    foreach (AseParameter parameter in cmd.Parameters)
                    {
                        fstr_out.WriteLine("\tParameterIndex: " + parameter.ParameterIndex + Environment.NewLine +
                                           "\tParameterName: " + parameter.ParameterName + Environment.NewLine +
                                           "\tDirection: " + parameter.Direction + Environment.NewLine +
                                           "\tDbType: " + parameter.DbType + Environment.NewLine +
                                           "\tAseDbType: " + parameter.AseDbType + Environment.NewLine +
                                           "\tSize: " + parameter.Size + Environment.NewLine +
                                           "\tPrecision: " + parameter.Precision + Environment.NewLine +
                                           "\tScale: " + parameter.Scale + Environment.NewLine +
                                           "\tIsNullable: " + parameter.IsNullable.ToString().ToLower() + Environment.NewLine +
                                           "\tSourceColumn: " + parameter.SourceColumn + Environment.NewLine +
                                           "\tSourceVersion: " + parameter.SourceVersion + Environment.NewLine);
                    }
                    fstr_out.WriteLine();

                    conn.ChangeDatabase("veksel");
                    cmd.CommandText = "sp_CONTRACT_SAVE";
                    fstr_out.WriteLine("AseCommandBuilder.DeriveParameters(\"" + cmd.CommandText + "\")");
                    AseCommandBuilder.DeriveParameters(cmd);
                    foreach (AseParameter parameter in cmd.Parameters)
                    {
                        fstr_out.WriteLine("\tParameterIndex: " + parameter.ParameterIndex + Environment.NewLine +
                                           "\tParameterName: " + parameter.ParameterName + Environment.NewLine +
                                           "\tDirection: " + parameter.Direction + Environment.NewLine +
                                           "\tDbType: " + parameter.DbType + Environment.NewLine +
                                           "\tAseDbType: " + parameter.AseDbType + Environment.NewLine +
                                           "\tSize: " + parameter.Size + Environment.NewLine +
                                           "\tPrecision: " + parameter.Precision + Environment.NewLine +
                                           "\tScale: " + parameter.Scale + Environment.NewLine +
                                           "\tIsNullable: " + parameter.IsNullable.ToString().ToLower() + Environment.NewLine +
                                           "\tSourceColumn: " + parameter.SourceColumn + Environment.NewLine +
                                           "\tSourceVersion: " + parameter.SourceVersion + Environment.NewLine);
                    }
                    fstr_out.WriteLine();

                    Transaction.Rollback();
                    Transaction = null;

                    Result = 0;
                }
                catch (AseException eException)
                {
                    Console.WriteLine(eException.GetType().FullName + Environment.NewLine +
                                      "Errors:" + Environment.NewLine + ErrorsToString(eException.Errors) + Environment.NewLine +
                                      "Message: " + eException.Message + Environment.NewLine +
                                      "Source: " + eException.Source + Environment.NewLine +
                                      "StackTrace:" + Environment.NewLine + eException.StackTrace + Environment.NewLine +
                                      "TargetSite: " + eException.TargetSite + Environment.NewLine);
                }
                catch (Exception eException)
                {
                    Console.WriteLine(eException.GetType().FullName + Environment.NewLine +
                                      "Message: " + eException.Message + Environment.NewLine +
                                      "Source: " + eException.Source + Environment.NewLine +
                                      "StackTrace:" + Environment.NewLine + eException.StackTrace + Environment.NewLine +
                                      "TargetSite: " + eException.TargetSite + Environment.NewLine +
                                      "InnerException:" + Environment.NewLine + eException.InnerException.GetType().FullName + Environment.NewLine +
                                      "InnerException.Message: " + eException.InnerException.Message + Environment.NewLine +
                                      "InnerException.Source: " + eException.InnerException.Source + Environment.NewLine +
                                      "InnerException.StackTrace:" + Environment.NewLine + eException.InnerException.StackTrace + Environment.NewLine +
                                      "InnerException.TargetSite: " + eException.InnerException.TargetSite);
                }
            }
            finally
            {
                if (Transaction != null)
                {
                    try
                    {
                        Transaction.Rollback();
                    }
                    catch
                    {
                        ;
                    }
                }

                if (reader != null && !reader.IsClosed)
                {
                    reader.Close();
                }

                if (cmd != null)
                {
                    cmd.Dispose();
                }

                if (conn != null && conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }

                if (fstr_out != null)
                {
                    fstr_out.Close();
                }

                                #if WITH_TRACE
                if (_strmWriter != null)
                {
                    _strmWriter.Close();
                }
                                #endif
            }

            return(Result);
        }
Example #27
0
        public void UpdateSybase(BlockingCollection<List<AseParameter>> taskQueue)
        {
            using (AseConnection oCon = new AseConnection(sybConnectionString))
            {
                using (AseCommand oCom = new AseCommand("insert_mcm_dtc_recon", oCon) { CommandType = CommandType.StoredProcedure, CommandTimeout = 5000 })
                {
                    oCon.Open();

                    using (Task uploadSybase = Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            while (true)
                            {

                                oCom.Parameters.AddRange(taskQueue.Take());
                                oCom.ExecuteNonQuery();
                            }
                        }
                        catch (InvalidOperationException ex)
                        {
                            Environment.Exit(0);
                        }

                    }))
                        Console.ReadLine();

                }

            }

        }