Beispiel #1
0
 void New()
 {
     try
     {
         CreateDbForm form = GetCreateDbForm();
         if (form.ShowDialog() == DialogResult.OK)
         {
             if (form.IsDbProvider)
             {
                 using (WaitCursor wr = new WaitCursor(this, Locale.Get("_createDb...")))
                 {
                     ConnectionInfo gisConn = MapCreator.CreateGisDb(form.DbCreationProperties);
                     app.CreateLib(gisConn);
                 }
             }
             else
             {
                 app.CreateLib(new ConnectionInfo(form.DbCreationProperties.dbName, form.FilePath));
             }
         }
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
Beispiel #2
0
 void Export()
 {
     try
     {
         GLib lib = app.Lib;
         if (lib != null)
         {
             CreateDbForm form = GetCreateDbForm();
             if (form.ShowDialog() == DialogResult.OK)
             {
                 using (WaitCursor wc = new WaitCursor(this, Locale.Get("_exportingData...")))
                 {
                     if (form.IsDbProvider)
                     {
                         ConnectionInfo gisConn = MapCreator.CreateGisDb(form.DbCreationProperties);
                         using (Context context = lib.GetContext())
                         {
                             context.TargetConn = gisConn.CreateConnection();
                             context.Filter     = Filter.All;
                             lib.Save(context);
                         }
                         app.UpdateConnectionList(gisConn);
                     }
                     else
                     {
                         Save(form.FilePath);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
Beispiel #3
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);
        }