public static DbProviderFactory GetInstance(string dbConnectionName)
        {
            if (_instance != null && _currentDbName == dbConnectionName)
                return _instance;

            var connectionStrings = GetDbConnection(dbConnectionName);
            _instance = new DbProviderFactory(connectionStrings);
            _currentDbName = dbConnectionName;
            return _instance;
        }
Beispiel #2
0
        public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
        {
            MigrationsHelper.Run(connectionString, true);

            var factory = new DbProviderFactory
                              {
                                  IsProfiled = profiled
                              };

            var db = new Database(connectionString, factory, Database.DBType.SqlServerCE)
                         {
                             KeepConnectionAlive = true,
                             ForceDateTimesToUtc = false,
                         };

            return db;
        }
 public CountryTableDataService()
 {
     _connectionString = ConfigurationManager.ConnectionStrings["mainAppConnectionString"].ConnectionString;
     _providerFactory  = DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings["mainAppConnectionString"].ProviderName);
 }
Beispiel #4
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term(m_sMODULE + ".LBL_LIST_FORM_TITLE"));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            this.Visible = (SplendidCRM.Security.GetUserAccess(m_sMODULE, "list") >= 0);
            if (!this.Visible)
            {
                return;
            }

            try
            {
                if (this.IsMobile && grdMain.Columns.Count > 0)
                {
                    grdMain.Columns[0].Visible = false;
                }
                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    string sSQL;
                    sSQL = "select *              " + ControlChars.CrLf
                           + "  from vwQUOTES_List  " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        // 11/24/2006 Paul.  Use new Security.Filter() function to apply Team and ACL security rules.
                        Security.Filter(cmd, m_sMODULE, "list");
                        ctlSearchView.SqlSearchClause(cmd);

                        if (bDebug)
                        {
                            RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
                        }

                        using (DbDataAdapter da = dbf.CreateDataAdapter())
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            using (DataTable dt = new DataTable())
                            {
                                da.Fill(dt);
                                vwMain             = dt.DefaultView;
                                grdMain.DataSource = vwMain;
                                if (!IsPostBack)
                                {
                                    // 12/14/2007 Paul.  Only set the default sort if it is not already set.  It may have been set by SearchView.
                                    if (String.IsNullOrEmpty(grdMain.SortColumn))
                                    {
                                        grdMain.SortColumn = "NAME";
                                        grdMain.SortOrder  = "asc";
                                    }
                                    grdMain.ApplySort();
                                    grdMain.DataBind();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                lblError.Text = ex.Message;
            }
            if (!IsPostBack)
            {
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
            }
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InstrumentedDbProviderFactory"/> class.
 /// A proxy provider factory
 /// </summary>
 /// <param name="factory">The provider factory to wrap.</param>
 /// <param name="instrumentationHandler"></param>
 /// <remarks>
 /// </remarks>
 public InstrumentedDbProviderFactory(DbProviderFactory factory, IInstrumentationHandler instrumentationHandler)
 {
     this._factory = factory;
     this._instrumentationHandler = instrumentationHandler;
 }
Beispiel #6
0
        public void TestMigration()
        {
            //arrange

            DbProviderFactory factory = null;

            try
            {
                factory = DbProviderFactories.GetFactory(ProviderName);
            }
            catch (ArgumentException)
            {
                Assert.Inconclusive("Unable to find System.Data.SqlServerCe.4.0 Data Provider. It may not be installed.");
            }
            if (!File.Exists(FilePath))
            {
                Assert.Inconclusive("SqlServerCe4 test requires database file " + FilePath);
            }

            const string connectionString = "Data Source=\"" + FilePath + "\"";

            ProviderChecker.Check(ProviderName, connectionString);


            var tableName = MigrationCommon.FindFreeTableName(ProviderName, connectionString);
            var migration = new DdlGeneratorFactory(SqlType.SqlServerCe).MigrationGenerator();

            var table            = MigrationCommon.CreateTestTable(tableName);
            var newColumn        = MigrationCommon.CreateNewColumn();
            var unqiueConstraint = MigrationCommon.CreateUniqueConstraint(newColumn);
            var fk    = MigrationCommon.CreateForeignKey(table);
            var index = MigrationCommon.CreateUniqueIndex(newColumn, tableName);

            var createTable         = migration.AddTable(table);
            var addColumn           = migration.AddColumn(table, newColumn);
            var addUniqueConstraint = migration.AddConstraint(table, unqiueConstraint);
            var addForeignKey       = migration.AddConstraint(table, fk);
            var addUniqueIndex      = migration.AddIndex(table, index);

            var dropUniqueIndex      = migration.DropIndex(table, index);
            var dropForeignKey       = migration.DropConstraint(table, fk);
            var dropUniqueConstraint = migration.DropConstraint(table, unqiueConstraint);
            var dropColumn           = migration.DropColumn(table, newColumn);
            var dropTable            = migration.DropTable(table);


            using (new TransactionScope())
            {
                using (var con = factory.CreateConnection())
                {
                    con.ConnectionString = connectionString;
                    using (var cmd = con.CreateCommand())
                    {
                        con.Open();

                        Execute(cmd, createTable);

                        Execute(cmd, addColumn);

                        Execute(cmd, addUniqueConstraint);

                        Execute(cmd, addForeignKey);


                        Execute(cmd, dropForeignKey);

                        Execute(cmd, dropUniqueConstraint);

                        Execute(cmd, addUniqueIndex);

                        Execute(cmd, dropUniqueIndex);

                        Execute(cmd, dropColumn);

                        Execute(cmd, dropTable);
                    }
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                this.ValidateEditViewFields(m_sMODULE + ".EditAddress");
                this.ValidateEditViewFields(m_sMODULE + ".EditDescription");
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "LEADS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwLEADS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                // 04/24/2006 Paul.  Upgrade to SugarCRM 4.2 Schema.
                                // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                                // 12/29/2007 Paul.  TEAM_ID is now in the stored procedure.
                                SqlProcs.spLEADS_Update
                                    (ref gID
                                    , new DynamicControl(this, rowCurrent, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, rowCurrent, "SALUTATION").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "FIRST_NAME").Text
                                    , new DynamicControl(this, rowCurrent, "LAST_NAME").Text
                                    , new DynamicControl(this, rowCurrent, "TITLE").Text
                                    , new DynamicControl(this, rowCurrent, "REFERED_BY").Text
                                    , new DynamicControl(this, rowCurrent, "LEAD_SOURCE").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "LEAD_SOURCE_DESCRIPTION").Text
                                    , new DynamicControl(this, rowCurrent, "STATUS").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "STATUS_DESCRIPTION").Text
                                    , new DynamicControl(this, rowCurrent, "DEPARTMENT").Text
                                    , Guid.Empty                                      // 06/24/2005. REPORTS_TO_ID is not used in version 3.0.
                                    , new DynamicControl(this, rowCurrent, "DO_NOT_CALL").Checked
                                    , new DynamicControl(this, rowCurrent, "PHONE_HOME").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_MOBILE").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_WORK").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_OTHER").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_FAX").Text
                                    , new DynamicControl(this, rowCurrent, "EMAIL1").Text
                                    , new DynamicControl(this, rowCurrent, "EMAIL2").Text
                                    , new DynamicControl(this, rowCurrent, "EMAIL_OPT_OUT").Checked
                                    , new DynamicControl(this, rowCurrent, "INVALID_EMAIL").Checked
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_STREET").Text
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_CITY").Text
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_STATE").Text
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_POSTALCODE").Text
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_COUNTRY").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_STREET").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_CITY").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_STATE").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_POSTALCODE").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_COUNTRY").Text
                                    , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text
                                    , new DynamicControl(this, rowCurrent, "ACCOUNT_NAME").Text
                                    , new DynamicControl(this, rowCurrent, "CAMPAIGN_ID").ID
                                    , new DynamicControl(this, rowCurrent, "TEAM_ID").ID
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            gID = Sql.ToGuid(Request["ID"]);
            Guid gOPPORTUNITY_ID = Sql.ToGuid(txtOPPORTUNITY_ID.Value);

            if (!Sql.IsEmptyGuid(gOPPORTUNITY_ID))
            {
                try
                {
                    SqlProcs.spACCOUNTS_OPPORTUNITIES_Update(gID, gOPPORTUNITY_ID);
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
                catch (Exception ex)
                {
                    SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                    lblError.Text = ex.Message;
                }
            }

            DbProviderFactory dbf = DbProviderFactories.GetFactory();

            using (IDbConnection con = dbf.CreateConnection())
            {
                string sSQL;
                sSQL = "select *                       " + ControlChars.CrLf
                       + "  from vwACCOUNTS_OPPORTUNITIES" + ControlChars.CrLf
                       + " where ACCOUNT_ID = @ACCOUNT_ID" + ControlChars.CrLf
                       + " order by DATE_CLOSED desc     " + ControlChars.CrLf;
                using (IDbCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = sSQL;
                    Sql.AddParameter(cmd, "@ACCOUNT_ID", gID);
#if DEBUG
                    Page.RegisterClientScriptBlock("vwACCOUNTS_OPPORTUNITIES", Sql.ClientScriptBlock(cmd));
#endif
                    try
                    {
                        using (DbDataAdapter da = dbf.CreateDataAdapter())
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            using (DataTable dt = new DataTable())
                            {
                                da.Fill(dt);
                                vwMain             = dt.DefaultView;
                                grdMain.DataSource = vwMain;
                                // 09/05/2005 Paul. LinkButton controls will not fire an event unless the the grid is bound.
                                //if ( !IsPostBack )
                                {
                                    grdMain.DataBind();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                        lblError.Text = ex.Message;
                    }
                }
            }
            if (!IsPostBack)
            {
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
            }
        }
        public Page()
        {
            providerFactory = Utils.DB.CreateDBProviderFactory();
            cn = Utils.DB.CreateConnection();

            cmd = providerFactory.CreateCommand();
            cmd.Connection = cn;
        }
Beispiel #10
0
 /// <summary>
 /// Contrutor Init com parametros
 /// </summary>
 /// <param name="providerName"></param>
 /// <param name="connString"></param>
 public static void Init(string providerName, string connString)
 {
     providerFactory = DbProviderFactories.GetFactory(providerName);
     connStr         = connString;
     initialized     = true;
 }
 public UserStore(IConfiguration connStr, DbProviderFactory factory)
 {
     _connectionString = connStr.GetConnectionString("DefaultConnection");
     _factory          = factory;
 }
Beispiel #12
0
        public TestDbProvider()
        {
            IDbProvider provider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");

            dbMetadata = provider.DbMetadata;
        }
Beispiel #13
0
 /// <summary>
 /// 初始化数据库类
 /// </summary>
 /// <param name="connectionString">数据库连接字符串</param>
 /// <param name="dbProvider">数据库提供者</param>
 internal SqlServerDatabase(DbProviderFactory dbProvider, String connectionString)
     : base(dbProvider, connectionString)
 {
 }
Beispiel #14
0
 public EdmMetadataRepository(InternalContext usersContext, string connectionString, DbProviderFactory providerFactory)
     : base(usersContext, connectionString, providerFactory)
 {
     _existingTransaction = usersContext.TryGetCurrentStoreTransaction();
 }
Beispiel #15
0
 public EnviromentConnectionFactory(string envDatabaseName, string providerInvariantName)
 {
     _envVarKey         = "NEventStore.{0}".FormatWith(envDatabaseName);
     _dbProviderFactory = DbProviderFactories.GetFactory(providerInvariantName);
 }
Beispiel #16
0
 public Database(string connectionString, DbProviderFactory factory)
 {
     this.ConnectionString = connectionString;
     this.Factory          = factory;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OracleServerExecuter"/> class.
 /// </summary>
 /// <param name="provider">驱动</param>
 /// <param name="connectionString">连接字符串.</param>
 public OracleServerExecuter(DbProviderFactory provider, string connectionString)
     : base(provider, connectionString)
 {
 }
Beispiel #18
0
 public UmbracoDatabase(string connectionString, DbProviderFactory provider) : base(connectionString, provider)
 {
 }
        public void Actualizar(Perfil persona)
        {
            DbProviderFactory factory = DbProviderFactories.GetFactory(Settings.Default.proveedor);
            DbConnection      conn    = null;
            DbCommand         comm    = null;

            try
            {
                conn = factory.CreateConnection();
                conn.ConnectionString = Settings.Default.connection;
                comm = factory.CreateCommand();

                DbParameter param0  = factory.CreateParameter();
                DbParameter param1  = factory.CreateParameter();
                DbParameter param2  = factory.CreateParameter();
                DbParameter param3  = factory.CreateParameter();
                DbParameter param4  = factory.CreateParameter();
                DbParameter param5  = factory.CreateParameter();
                DbParameter param6  = factory.CreateParameter();
                DbParameter param7  = factory.CreateParameter();
                DbParameter param8  = factory.CreateParameter();
                DbParameter param9  = factory.CreateParameter();
                DbParameter param10 = factory.CreateParameter();
                DbParameter param11 = factory.CreateParameter();
                DbParameter param12 = factory.CreateParameter();
                DbParameter param13 = factory.CreateParameter();
                DbParameter param14 = factory.CreateParameter();
                DbParameter param15 = factory.CreateParameter();
                DbParameter param16 = factory.CreateParameter();


                param0.ParameterName = "@ID";
                param0.DbType        = DbType.Int32;
                param0.Value         = persona._ID;

                param1.ParameterName = "@Nombre";
                param1.DbType        = DbType.String;
                param1.Value         = persona._Nombre;

                param2.ParameterName = "@Cedula";
                param2.DbType        = DbType.Int32;
                param2.Value         = persona._Cedula;

                param3.ParameterName = "@ProfesionPrinc";
                param3.DbType        = DbType.String;
                param3.Value         = persona._ProfesionPrinc;

                param4.ParameterName = "@CantidadTitulos";
                param4.DbType        = DbType.Int32;
                param4.Value         = persona._CantidadTitulos;

                param5.ParameterName = "@ConocimientoAdic";
                param5.DbType        = DbType.String;
                param5.Value         = persona._ConocimientosAdic;

                param6.ParameterName = "@Telefono";
                param6.DbType        = DbType.Int32;
                param6.Value         = persona._Telefono;

                param7.ParameterName = "@Mail";
                param7.DbType        = DbType.String;
                param7.Value         = persona._Mail;

                param8.ParameterName = "@Fecha_Nacimiento";
                param8.DbType        = DbType.Date;
                param8.Value         = persona._Fecha_Nacimiento;

                param9.ParameterName = "@Residencia";
                param9.DbType        = DbType.String;
                param9.Value         = persona._Residencia;

                param10.ParameterName = "@Universidad";
                param10.DbType        = DbType.String;
                param10.Value         = persona._Universidad;

                param11.ParameterName = "@AnoGraduacion";
                param11.DbType        = DbType.Date;
                param11.Value         = persona._AnoGraduacion;

                param12.ParameterName = "@AnoExperiencia";
                param12.DbType        = DbType.Int32;
                param12.Value         = persona._AnoExperiencia;

                param13.ParameterName = "@CantidadEmpleos";
                param13.DbType        = DbType.Int32;
                param13.Value         = persona._CantidadEmpleos;

                param14.ParameterName = "@CantidadDespidos";
                param14.DbType        = DbType.Int32;
                param14.Value         = persona._CantidadDespidos;

                param15.ParameterName = "@Idiomas";
                param15.DbType        = DbType.String;
                param15.Value         = persona._Idiomas;

                param16.ParameterName = "@Pasaporte";
                param16.DbType        = DbType.String;
                param16.Value         = persona._Pasaporte;


                //Abrir Conx
                comm.Connection = conn;
                conn.Open();

                //Ejecutar SP y pasar parametros
                comm.CommandType = CommandType.StoredProcedure;
                comm.CommandText = "ActualizarPerfil";
                comm.Parameters.Add(param0);
                comm.Parameters.Add(param1);
                comm.Parameters.Add(param2);
                comm.Parameters.Add(param3);
                comm.Parameters.Add(param4);
                comm.Parameters.Add(param5);
                comm.Parameters.Add(param6);
                comm.Parameters.Add(param7);
                comm.Parameters.Add(param8);
                comm.Parameters.Add(param9);
                comm.Parameters.Add(param10);
                comm.Parameters.Add(param11);
                comm.Parameters.Add(param12);
                comm.Parameters.Add(param13);
                comm.Parameters.Add(param14);
                comm.Parameters.Add(param15);
                comm.Parameters.Add(param16);



                comm.ExecuteNonQuery();
            }
            catch (Exception ee)
            {
                throw;
            }
            finally
            {
                comm.Dispose();
                conn.Dispose();
            }
        }
        /// <summary>
        /// 创建一个数据提供程序实例
        /// </summary>
        /// <param name="connectionStringName"></param>
        /// <returns></returns>
        public static Database Create(string connectionStringName)
        {
            CheckUtil.ArgumentNotNullOrEmpty(connectionStringName, "connectionStringName");

            ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[connectionStringName];

            if (css == null)
            {
                throw new Exception(string.Format(Resources.Data.ConnectionStringNameNotFound, connectionStringName));
            }

            string            connectionString = css.ConnectionString;
            string            providerName     = css.ProviderName;
            Database          db = new SqlServerDatabase(connectionString);
            DbProviderFactory providerFactory = null;

            if (string.IsNullOrEmpty(providerName))
            {
                return(db);
            }

            providerFactory = DbProviderFactories.GetFactory(css.ProviderName);
            if (providerFactory == null)
            {
                throw new Exception(string.Format(Resources.Data.DataProviderNotFound, css.ProviderName));
            }

            switch (providerName)
            {
            //case "System.Data.SqlClient":
            //    break;
            case "System.Data.Odbc":
                db = new OdbcDatabase(connectionString);
                break;

            case "System.Data.OleDb":
                db = new OleDbDatabase(connectionString);
                break;

            case "System.Data.OracleClient":
                db = new OracleDatabase(connectionString);
                break;

            case "System.Data.SQLite":
                db = new SQLiteDatabase(connectionString, providerFactory);
                break;

            case "MySql.Data.MySqlClient":
                db = new MySqlDatabase(connectionString, providerFactory);
                break;

            case "IBM.Data.DB2":
                db = new DB2Database(connectionString, providerFactory);
                break;

            case "FirebirdSql.Data.FirebirdClient":
                db = new FirebirdDatabase(connectionString, providerFactory);
                break;

            default:
                break;
            }

            return(db);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term(".moduleList." + m_sMODULE));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            this.Visible = (SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!this.Visible)
            {
                return;
            }

            try
            {
                gID = Sql.ToGuid(Request["ID"]);
                if (!IsPostBack)
                {
                    Guid gDuplicateID = Sql.ToGuid(Request["DuplicateID"]);
                    if (!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwLEADS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                // 11/24/2006 Paul.  Use new Security.Filter() function to apply Team and ACL security rules.
                                Security.Filter(cmd, m_sMODULE, "edit");
                                if (!Sql.IsEmptyGuid(gDuplicateID))
                                {
                                    Sql.AppendParameter(cmd, gDuplicateID, "ID", false);
                                    gID = Guid.Empty;
                                }
                                else
                                {
                                    Sql.AppendParameter(cmd, gID, "ID", false);
                                }
                                con.Open();

                                if (bDebug)
                                {
                                    RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
                                }

                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        ctlModuleHeader.Title = Sql.ToString(rdr["SALUTATION"]) + " " + Sql.ToString(rdr["FIRST_NAME"]) + " " + Sql.ToString(rdr["LAST_NAME"]);
                                        SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                                        Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title);
                                        ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;

                                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, rdr);
                                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, rdr);
                                        this.AppendEditViewFields(m_sMODULE + ".EditDescription", tblDescription, rdr);
                                    }
                                    else
                                    {
                                        // 11/25/2006 Paul.  If item is not visible, then don't allow save
                                        ctlEditButtons.DisableAll();
                                        ctlEditButtons.ErrorText = L10n.Term("ACL.LBL_NO_ACCESS");
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditDescription", tblDescription, null);
                    }
                }
                else
                {
                    // 12/02/2005 Paul.  When validation fails, the header title does not retain its value.  Update manually.
                    ctlModuleHeader.Title = Sql.ToString(ViewState["ctlModuleHeader.Title"]);
                    SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                ctlEditButtons.ErrorText = ex.Message;
            }
        }
        private void flightDoneButton_Click(object sender, RoutedEventArgs e)
        {
            factory    = DbProviderFactories.GetFactory("System.Data.OracleClient");
            connection = factory.CreateConnection();

            connection.ConnectionString = "Data Source=localhost;Persist Security Info=True;User ID=system;Password=0326;Unicode=True";
            connection.Open();

            DbCommand command = factory.CreateCommand();

            command.CommandText = strQuery;   //make the query
            command.Connection  = connection; //connect the command

            switch (usersChoice)
            {
            case "add":
                id           = Int32.Parse(flight_id.Text);
                take_off     = takeOffDatePicker.Text;
                airplaneId   = Int32.Parse(airplane_id.Text);
                flightLineId = Int32.Parse(flight_line_id.Text);

                // create insert functions to tacbels credit_card and passanger
                strQuery = "insert into SYSTEM.FLIGHT(FLIGHTID, TAKE_OFF_DATE, AIRPLANEID, FLIGHT_LINE_ID) values (" + id + ",to_date('" + take_off + " " + rand.Next(10, 23) + ":" + rand.Next(10, 59) + ":" + rand.Next(10, 59) + "', 'dd-mm-yyyy hh24:mi:ss')," + airplaneId + "," + flightLineId + ")";

                command.CommandText = strQuery;

                break;

            case "update":
                id           = Int32.Parse(flight_id.Text);
                take_off     = takeOffDatePicker.Text;
                airplaneId   = Int32.Parse(airplane_id.Text);
                flightLineId = Int32.Parse(flight_line_id.Text);

                // create update functions to a row in ticket table
                strQuery = "update SYSTEM.FLIGHT SET TAKE_OFF_DATE = to_date('" + take_off + " " + rand.Next(10, 23) + ":" + rand.Next(10, 59) + ":" + rand.Next(10, 59) + "', 'dd-mm-yyyy hh24:mi:ss'), AIRPLANEID = " + airplaneId + ", FLIGHT_LINE_ID = " + flightLineId + " where FLIGHTID = " + id;

                command.CommandText = strQuery;

                break;

            case "delete":
                id = Int32.Parse(flight_id.Text);

                // create delete query from tickets
                strQuery = "delete from SYSTEM.FLIGHT where FLIGHTID = " + id;

                command.CommandText = strQuery;

                break;

            default:
                break;
            }

            try
            {
                int check = command.ExecuteNonQuery();
                if (check == 1)
                {
                    MessageBox.Show("FLIGHT " + usersChoice + "ed successfully! \n ");
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: " + ex.Message);
            }

            connection.Close();
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                Guid gID = Sql.ToGuid(Request["ID"]);
                // 11/28/2005 Paul.  We must always populate the table, otherwise it will disappear during event processing.
                //if ( !IsPostBack )
                {
                    if (!Sql.IsEmptyGuid(gID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *              " + ControlChars.CrLf
                                   + "  from vwTHREADS_POSTS" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;

                                // 11/27/2006 Paul.  Make sure to filter relationship data based on team access rights.
                                Security.Filter(cmd, m_sMODULE, "list");
                                cmd.CommandText += "   and THREAD_ID = @THREAD_ID" + ControlChars.CrLf;
                                cmd.CommandText += " order by DATE_ENTERED asc   " + ControlChars.CrLf;
                                Sql.AddParameter(cmd, "@THREAD_ID", gID);

                                if (bDebug)
                                {
                                    RegisterClientScriptBlock("vwTHREADS_POSTS", Sql.ClientScriptBlock(cmd));
                                }

                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    using (DataTable dt = new DataTable())
                                    {
                                        da.Fill(dt);

                                        foreach (DataRow rdr in dt.Rows)
                                        {
                                            PostView ctlPost = LoadControl("PostView.ascx") as PostView;
                                            plcPosts.Controls.Add(ctlPost);

                                            ctlPost.POST_ID       = Sql.ToGuid(rdr["ID"]);
                                            ctlPost.TITLE         = Sql.ToString(rdr["TITLE"]);
                                            ctlPost.CREATED_BY    = Sql.ToString(rdr["CREATED_BY"]);
                                            ctlPost.DATE_ENTERED  = Sql.ToString(rdr["DATE_ENTERED"]);
                                            ctlPost.MODIFIED_BY   = Sql.ToString(rdr["MODIFIED_BY"]);
                                            ctlPost.DATE_MODIFIED = Sql.ToString(rdr["DATE_MODIFIED"]);
                                            ctlPost.DESCRIPTION   = Sql.ToString(rdr["DESCRIPTION_HTML"]);
                                            if (Sql.ToDateTime(rdr["DATE_ENTERED"]) != Sql.ToDateTime(rdr["DATE_MODIFIED"]))
                                            {
                                                ctlPost.Modified = true;
                                            }

                                            Guid gCREATED_BY_ID = Sql.ToGuid(rdr["CREATED_BY_ID"]);
                                            ctlPost.ShowEdit   = Security.IS_ADMIN || gCREATED_BY_ID == Security.USER_ID;
                                            ctlPost.ShowDelete = Security.IS_ADMIN || gCREATED_BY_ID == Security.USER_ID;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                string sCATEGORY = new DynamicControl(this, "CATEGORY").Text;
                if (Page.IsValid && !Sql.IsEmptyString(sCATEGORY))
                {
                    DbProviderFactory dbf = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *            " + ControlChars.CrLf
                                   + "  from vwFORUMS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                // 12/29/2007 Paul.  TEAM_ID is now in the stored procedure.
                                SqlProcs.spFORUMS_Update
                                    (ref gID
                                    , new DynamicControl(this, "TITLE").Text
                                    , new DynamicControl(this, "CATEGORY").Text
                                    , new DynamicControl(this, "DESCRIPTION").Text
                                    , new DynamicControl(this, "TEAM_ID").ID
                                    , trn
                                    );
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
Beispiel #25
0
 public ConnectionBuilder(DbProviderFactory providerFactory)
 {
     this.dbFactory = providerFactory;
 }
Beispiel #26
0
 /// <summary>
 /// Funkcja stworzona tylko po to by nie można było tworzyć nowych SzpifDatabase'ów
 /// </summary>
 private SzpifDatabase()
 {
     provider   = "System.Data.SqlClient";
     factory    = DbProviderFactories.GetFactory(provider);
     connection = factory.CreateConnection();
 }
Beispiel #27
0
 /// <summary>
 /// Allow to re-initialize the provider factory.
 /// </summary>
 /// <param name="tail">The tail.</param>
 public void InitProfiledDbProviderFactory(DbProviderFactory tail) => this._factory = tail;
 public VehicleRepository()
 {
     _connectionString  = DBHelper.GetConnectionString();
     _dbProviderName    = DBHelper.GetConnectionProvider();
     _dbProviderFactory = DbProviderFactories.GetFactory(_dbProviderName);
 }
Beispiel #29
0
 protected void Page_Command(object sender, CommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "Search")
         {
             // 10/13/2005 Paul.  Make sure to clear the page index prior to applying search.
             grdMain.CurrentPageIndex = 0;
             grdMain.ApplySort();
             grdMain.DataBind();
         }
         // 12/14/2007 Paul.  We need to capture the sort event from the SearchView.
         else if (e.CommandName == "SortGrid")
         {
             grdMain.SetSortFields(e.CommandArgument as string[]);
         }
         else if (e.CommandName == "MassUpdate")
         {
             string[] arrID = Request.Form.GetValues("chkMain");
             if (arrID != null)
             {
                 // 10/26/2007 Paul.  Use a stack to run the update in blocks of under 200 IDs.
                 //string sIDs = Utils.ValidateIDs(arrID);
                 System.Collections.Stack stk = Utils.FilterByACL_Stack(m_sMODULE, "edit", arrID, "QUOTES");
                 if (stk.Count > 0)
                 {
                     DbProviderFactory dbf = DbProviderFactories.GetFactory();
                     using (IDbConnection con = dbf.CreateConnection())
                     {
                         con.Open();
                         using (IDbTransaction trn = con.BeginTransaction())
                         {
                             try
                             {
                                 while (stk.Count > 0)
                                 {
                                     string sIDs = Utils.BuildMassIDs(stk);
                                     // 07/09/2006 Paul.  The date conversion was moved out of the MassUpdate control.
                                     // 09/11/2007 Paul.  Mass update of teams is now available.
                                     SqlProcs.spQUOTES_MassUpdate(sIDs, ctlMassUpdate.ASSIGNED_USER_ID, ctlMassUpdate.PAYMENT_TERMS, ctlMassUpdate.QUOTE_STAGE, T10n.ToServerTime(ctlMassUpdate.ORIGINAL_PO_DATE), T10n.ToServerTime(ctlMassUpdate.DATE_QUOTE_EXPECTED_CLOSED), ctlMassUpdate.BILLING_ACCOUNT_ID, ctlMassUpdate.BILLING_CONTACT_ID, ctlMassUpdate.SHIPPING_ACCOUNT_ID, ctlMassUpdate.SHIPPING_CONTACT_ID, ctlMassUpdate.TEAM_ID, trn);
                                 }
                                 trn.Commit();
                             }
                             catch (Exception ex)
                             {
                                 trn.Rollback();
                                 throw(new Exception(ex.Message, ex.InnerException));
                             }
                         }
                     }
                     Response.Redirect("default.aspx");
                 }
             }
         }
         else if (e.CommandName == "MassDelete")
         {
             string[] arrID = Request.Form.GetValues("chkMain");
             if (arrID != null)
             {
                 // 10/26/2007 Paul.  Use a stack to run the update in blocks of under 200 IDs.
                 //string sIDs = Utils.ValidateIDs(arrID);
                 System.Collections.Stack stk = Utils.FilterByACL_Stack(m_sMODULE, "delete", arrID, "QUOTES");
                 if (stk.Count > 0)
                 {
                     DbProviderFactory dbf = DbProviderFactories.GetFactory();
                     using (IDbConnection con = dbf.CreateConnection())
                     {
                         con.Open();
                         using (IDbTransaction trn = con.BeginTransaction())
                         {
                             try
                             {
                                 while (stk.Count > 0)
                                 {
                                     string sIDs = Utils.BuildMassIDs(stk);
                                     SqlProcs.spQUOTES_MassDelete(sIDs, trn);
                                 }
                                 trn.Commit();
                             }
                             catch (Exception ex)
                             {
                                 trn.Rollback();
                                 throw(new Exception(ex.Message, ex.InnerException));
                             }
                         }
                     }
                     Response.Redirect("default.aspx");
                 }
             }
         }
         else if (e.CommandName == "Export")
         {
             // 11/03/2006 Paul.  Apply ACL rules to Export.
             int nACLACCESS = SplendidCRM.Security.GetUserAccess(m_sMODULE, "export");
             if (nACLACCESS >= 0)
             {
                 if (nACLACCESS == ACL_ACCESS.OWNER)
                 {
                     vwMain.RowFilter = "ASSIGNED_USER_ID = '" + Security.USER_ID.ToString() + "'";
                 }
                 string[] arrID = Request.Form.GetValues("chkMain");
                 SplendidExport.Export(vwMain, m_sMODULE, ctlExportHeader.ExportFormat, ctlExportHeader.ExportRange, grdMain.CurrentPageIndex, grdMain.PageSize, arrID);
             }
         }
     }
     catch (Exception ex)
     {
         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
         lblError.Text = ex.Message;
     }
 }
Beispiel #30
0
 //-------------------------------------------------------------------------------
 public QuestRepository()
 {
     _connectionString = constr.ConnectionString;
     _factory          = DbProviderFactories.GetFactory(constr.ProviderName);
 }
 public static IDbProviderFactory AsIDbProviderFactory(this DbProviderFactory dbProviderFactory)
 {
     return(new DbProviderFactoryAdapter(dbProviderFactory));
 }
Beispiel #32
0
 /// <summary>
 /// 初始化 <see cref="Database"/> 类的新实例
 /// </summary>
 /// <param name="providerFactory">数据源提供者</param>
 /// <param name="connectionString">数据库连接字符串</param>
 public Database(DbProviderFactory providerFactory, string connectionString)
 {
     _connString        = connectionString;
     _dbProviderFactory = providerFactory;
 }
Beispiel #33
0
            public DynamicModel(string connectionStringName, string tableName = "",
                string primaryKeyField = "", string descriptorField = "")
            {
                TableName = tableName == "" ? this.GetType().Name : tableName;
                PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;
                DescriptorField = descriptorField;
                var _providerName = "System.Data.SqlClient";

                if (ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName != null)
                    _providerName = ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName;

                _factory = DbProviderFactories.GetFactory(_providerName);
                ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
            }
Beispiel #34
0
 public RawDb(IRandom random, DbProviderFactory dbProviderFactory, IOptions <AppSettings> appSettings)
 {
     _random            = random;
     _dbProviderFactory = dbProviderFactory;
     _connectionString  = appSettings.Value.ConnectionString;
 }
Beispiel #35
0
 protected DbFactoryBase(DbProviderFactory factory)
 {
     this.factory = factory;
 }
            /// <summary>
            /// Determines the correct provider to use and sets up the connection and command
            /// objects for use in other methods
            /// </summary>
            /// <param name="connectString">The full connection string to the database</param>
            /// <param name="providerlist">The enum value of providers from dbutilities.Providers</param>
            public void CreateDBObjects(string connectString, Providers providerList)
            {
                //CreateDBObjects(connectString, providerList, null);
                switch (providerList)
                {
                    case Providers.SqlServer:
                        _factory = SqlClientFactory.Instance;
                        break;
                    case Providers.Oracle:
                        _factory = OracleClientFactory.Instance;
                        break;
                    case Providers.OleDB:
                        _factory = OleDbFactory.Instance;
                        break;
                    case Providers.ODBC:
                        _factory = OdbcFactory.Instance;
                        break;
                }

                _connection = _factory.CreateConnection();
                _command = _factory.CreateCommand();

                _connection.ConnectionString = connectString;
                _command.Connection = connection;
            }