Exemplo n.º 1
0
        public static bool Init()
        {
            SetVersion();

            // Splash screen
            fSplash = new frmSplash();
            fSplash.SetAppName(" v " + SYS.App.version);
            fSplash.Show();
            fSplash.ShowMsg("Initializing the application...");
            fSplash.TopMost = true;
            // Database connection string from setting.ini
            try
            {
                fSplash.ShowMsg("Loading settings...");
                LoadSettings();

                fSplash.ShowMsg("Connecting to the database ...");
                SqlFacade.OpenConnection(); // Database connection: open/test

                fSplash.ShowMsg("Ensuring database setup ...");
                SqlFacade.EnsureDBSetup();  // Create tables if not exist
            }
            catch (Exception ex)
            {
                fSplash.ShowError(ex.Message);
                fSplash.Visible = false;
                fSplash.ShowDialog();
                ErrorLogFacade.LogToFile(ex);
                return(false);
            }

            //Session
            session.Username          = "******"; //todo: logged in user (to be removed)
            session.Branch_Code       = "000";
            session.Machine_Name      = Environment.MachineName;
            session.Machine_User_Name = Environment.UserName;
            session.Version           = version;

            LabelFacade.LoadSystemLabel();
            MessageFacade.LoadSystemMessage();

            // Log
            ErrorLogFacade.logFile.FileName = Path.Combine(Application.StartupPath, "Error.log");
            AccessLog.FileName = Path.Combine(Application.StartupPath, "Access.log");
            AccessLog.Write(DateTime.Now.ToString("yyy-MM-dd ddd hh:mm:ss tt") + " Application started. Process Id: " + ProcessID + ", Machine: " + session.Machine_Name + ", machine's username: "******", version: " + session.Version);
            session.Id = SessionFacade.Save(session);
            SessionLogFacade.Log(Type.Priority_Information, "Application", Type.Log_Launch, "Application started");

            return(true);
        }