示例#1
0
 public IDCollectorForm(AccessWriter w, PersonMessageReader reader, IPersonnelReader personnelReader)
 {
     Debug.Assert(w != null, "AccessWriter instance was null in IDCollectorForm constructor");
     InitializeComponent();
     this.Shown          += new EventHandler(windowWasShown);
     this.FormClosed     += new FormClosedEventHandler(windowWasHidden);
     writer               = w;
     pmReader             = reader;
     this.personnelReader = personnelReader;
 }
示例#2
0
        /// <summary>
        /// Initializes the ID card reader:
        /// Fills in the report settings with their default values.
        /// Shows the "Start data collection" UI.
        /// Hides the "Data collection progress" UI.
        /// Sets start & end of report to time filter settings or start/end of time.
        /// Sets up the subprocess structure for idreader2 (./idreader2.exe), and adds hooks.
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">event</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            DestroyAllExcel();
            // Initialize settings
            settings.reportType = ReportType.PERSREP;

            storedSettings = new IniFile();

            DatabaseConnected += (s, conn) => writer = new AccessWriter(conn);
            DatabaseConnected += (s, conn) => pmReader = new PersonMessageReader(conn);
            DatabaseConnected += (s, conn) => personnelReader = new AccessPersonnelReader(conn);
            DatabaseConnected += (s, conn) => cardLogReader = new AccessLogReader(conn);
            DatabaseConnected += (s, conn) => UpdateValidity();

            DatabaseConnected += LoadCompanyList;

            // Load Access DB from the INI file if possible
            if (storedSettings.KeyExists("AccessDatabase") && File.Exists(storedSettings.Read("AccessDatabase")))
            {
                Debug.Print("LOAD: Found stored database! Connecting.");
                openDatabase(storedSettings.Read("AccessDatabase"));
            }

            if (storedSettings.KeyExists("PersrepTemplate") && File.Exists(storedSettings.Read("PersrepTemplate")))
            {
                Debug.Print("LOAD: Found stored PERSREP template file");
                storedPersrepTemplate   = storedSettings.Read("PersrepTemplate");
                settings.reportTemplate = storedPersrepTemplate;
            }

            if (storedSettings.KeyExists("AttendanceTemplate") && File.Exists(storedSettings.Read("AttendanceTemplate")))
            {
                Debug.Print("LOAD: Found stored attendance template file");
                storedAttendanceTemplate = storedSettings.Read("AttendanceTemplate");
            }

            if (storedSettings.KeyExists("RedWhenNoPersonalMessage"))
            {
                Debug.Print("LOAD: Found stored RedWhenNoPersonalMessage");
                bool showRed = storedSettings.Read("RedWhenNoPersonalMessage") == "true";
                this.showRedWhenNoMessageCheckbox.Checked = showRed;
            }

            settings.personnelFileName = null;
            settings.reportFileName    = null;

            // Initialize time filter settings
            if (timeFilterEnabledCheckbox.Checked)
            {
                settings.startOfReport = dataSelectionStartDate.Value;
                settings.endOfReport   = dataSelectionEndDate.Value;
            }
            else
            {
                dataSelectionStartDate.Value = DateTime.Today.Subtract(TimeSpan.FromDays(1));
                dataSelectionEndDate.Value   = DateTime.Today;
            }

            // If we have actually got a logger program, we can allow user to control it
            if (File.Exists("idreader2.exe"))
            {
                Debug.Print("Found idreader2.exe");
                hasIDReaderBackend = true;
            }
            else
            {
                Debug.Print("Missing CWD/idreader2.exe, cannot logger");
                hasIDReaderBackend       = false;
                loggerErrorLabel.Text    = "Viga: puudub vajalik programm, et ID-kaardi andmeid koguda.";
                loggerErrorLabel.Visible = true;
            }

            UpdateValidity();
        }