Exemplo n.º 1
0
        /// <summary>
        /// ConnectToDatabase.
        /// Si connette ad un database esistente
        /// </summary>
        private bool ConnectToDatabase()
        {
            var connected        = false;
            var connectionString = GetConnectionString();

            try
            {
                myConnection = new SqlProxyConnection(connectionString);
                myConnection.Open();
                connected = (myConnection.State == ConnectionState.Open);
                // @@ try to remove changedatabase
                //if (connected)
                //    myConnection.ChangeDatabase(lI.InitialCatalog);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), GlobalInfo.LoginInfo.InitialCatalog, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            if (SqlProxyDatabaseHelper.SearchTable <EF_Version>(myConnection))
            {
                if (MessageBox.Show(Properties.Resources.Database_WrongType,
                                    Properties.Resources.Attention,
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    connected = false;
                    return(false);
                }
                else
                {
                    RegisterModule RsT = new ERPFramework.ModuleData.RegisterModule();
                    RsT.CreateTable(myConnection, GlobalInfo.UserInfo.userType);
                    AddAdminUser();
                }
            }
            else
            {
                RegisterModule RsT = new ERPFramework.ModuleData.RegisterModule();
                connected = RsT.CreateTable(myConnection, GlobalInfo.UserInfo.userType);
            }

            return(connected);
        }
Exemplo n.º 2
0
        public void AddTable <T>(bool toExport = true)
        {
            System.Diagnostics.Debug.Assert(typeof(T).BaseType == typeof(Table));
            var existVirtual = typeof(T).GetField("IsVirtual");
            var isVirtual    = existVirtual == null
                                ? false
                                : bool.Parse(existVirtual.GetValue(null).ToString());

            var table = new TableDefinition {
                Module = Module(), Table = typeof(T), ToExport = toExport, IsVirtual = isVirtual
            };

            if (!GlobalInfo.Tables.ContainsKey(table.Table.Name))
            {
                GlobalInfo.Tables.Add(table.Table.Name, table);
                AddTableType <T>();
            }

            if (!isVirtual && SqlProxyDatabaseHelper.SearchTable <T>(GlobalInfo.SqlConnection))
            {
                SqlCreateTable.CreateTable <T>();
            }
        }