public TaskManager(UserInfo userInfo, Config config, AppCache appCache)
 {
     this.userInfo  = userInfo;
     this.config    = config;
     this.depConfig = config.departmentConfig;
     this.appCache  = appCache;
 }
示例#2
0
        bool InitInstance()
        {
            if (App.instance == null)
            {
                Log.LogSystem.LogSystemFlags = LogSystemFlags.UseIp | LogSystemFlags.UseUserId;
                Log.LogSystem.AddLogHandlers(new MessageFormLogInformer());
            }
            using (WaitCursor wc = new WaitCursor())
            {
                if (App.instance != null)
                {
                    throw new HospitalDepartmentException("Приложение уже инициализировано.");
                }
                Locale.StringSet.Load();
                instance     = this;
                assemblyInfo = new AssemblyInfo();
                appCache     = new AppCache();
                userInfo     = new UserInfo();

                // App config
                appConfig = AppConfig.Load();

                // DB
                if (appConfig.dataProvider.Trim().Length == 0 || appConfig.connStr.Trim().Length == 0 || appConfig.debugMode == 2)
                {
                    CreateDbForm form = new CreateDbForm("Data", "HospitalDepartment");
                    form.DataProviders.Add(SqlServerProvider.name);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        connectionFactory = form.DbCreationProperties.CreateDb();

                        // create database
                        UpdateScripts.UpdateDb(connectionFactory, null, "HospitalDepartment.Resources.CreationScripts.sql");
                        appConfig.dataProvider = connectionFactory.ProviderFactory.Name;
                        appConfig.connStr      = connectionFactory.ConnectionString;
                        appConfig.Save();

                        // import tables
                        ImportTable.ImportData(connectionFactory, PathUtils.BaseDirectory + "Import");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    connectionFactory = new ConnectionFactory(appConfig.dataProvider, appConfig.connStr);
                }


                // Hospital department config
                config = Config.Load();
                ConfigUpdate.CheckUpdate(config, true);

                // Connection test
                using (GmConnection conn = App.CreateConnection())
                {
                    conn.DbConnection.Open();
                }
                Log.LogSystem.AddLogHandlers(new SqlLog(connectionFactory));
                Log.LogSystem.OnLogMessage += new EventHandler <LogMessageEventArgs>(LogHandler_OnLogMessage);
                Log.Info("AppStart", "Запуск программы.");

                // update database
                UpdateScripts.UpdateDb(connectionFactory, null, "HospitalDepartment.Resources.UpdateScripts.sql");

                // load icon
                Assembly assembly = Assembly.GetExecutingAssembly();
                using (Stream stream = assembly.GetManifestResourceStream(App.DepartmentConfig.iconName))
                {
                    icon = new Icon(stream);
                }
            }
            // Login
            if (App.DebugMode > 0 && System.Diagnostics.Debugger.IsAttached)            // autologin
            {
                Login("1", "1");
            }
            else
            {
                LoginForm form = new LoginForm(false);
                form.ShowDialog();
            }

            if (UserId == 0 || Role == null)
            {
                return(false);
            }

            Log.Info("Пользователь вошел в систему", "UserId={0} RoleId={1}", UserId, Role.Id);

            // App cache
            using (WaitCursor wc = new WaitCursor())
            {
                using (GmConnection conn = App.CreateConnection())
                {
                    appCache.Update(conn, this.Role.watchingGroupId);
                }
            }

            // Check watching
            if (userInfo.HasWatching)
            {
                if (userInfo.Watching.Id == 0)
                {
                    WatchingForm watchingForm = new WatchingForm(this);
                    if (watchingForm.ShowDialog() != DialogResult.OK)
                    {
                        return(false);
                    }
                }
                if (userInfo.Watching.Id == 0)
                {
                    return(false);
                }
            }

            taskManager = new TaskManager(userInfo, config, appCache);
            return(true);
        }