Ejemplo n.º 1
0
        public static ErrorForm ShowMessage(string message)
        {
            ErrorForm messageform = new ErrorForm(message);

            messageform.Show();
            messageform.Update();

            return(messageform);
        }
Ejemplo n.º 2
0
        static void Main()
        {
            WINDOW_BACKGROUND_COLOR = "255,255,255"; //must be set temporarily so that loading form can be initialized
            WindowBackRed           = 255;
            WindowBackGreen         = 255;
            WindowBackBlue          = 255;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ErrorForm loading = ShowMessage("");

            if (!Directory.Exists("Logs"))
            {
                Directory.CreateDirectory("Logs");
            }

            if (!Directory.Exists("Transactions"))
            {
                Directory.CreateDirectory("Transactions");
            }

            #region Program Initialization
            try
            {
                #region Config file values
                loading.SetLabelText("Loading Config\r\nFile Values...");
                xml                  = new XmlConfig.XmlConfigDoc(CONFIGURATION_FILE_NAME);
                root                 = xml.GetNode("root");
                globals              = root.GetNode("globals");
                portnode             = root.GetNode("ports");
                idscannode           = root.GetNode("idscan");
                emailnode            = root.GetNode("email");
                textnode             = root.GetNode("textmsg");
                rfidnode             = root.GetNode("rfid");
                sqlitenode           = root.GetNode("sqlite");
                biometricnode        = root.GetNode("biometric");
                usersnode            = root.GetNode("users");
                configadminpasswords = root.GetNode("configurableadminpasswords");

                //globals
                KD_DEBUG          = GetBoolValue("UseDebugLog", globals);
                DEV_STATION_SETUP = GetBoolValue("DevSetup", globals);
                PROGRAM_VERSION   = GetStringValue("Version", globals);
                KIOSK_ID          = GetStringValue("KioskID", globals);
                KIOSK_LOCATION    = GetStringValue("KioskLocation", globals);

                EXIT_CODE = GetStringValue("ExitCode", globals);
                RELAY_CONTROL_BOARD_TYPE               = GetStringValue("RelayControlBoardType", globals);
                MAINSCREEN_TITLE1                      = GetStringValue("MainscreenTitle1", globals);
                MAINSCREEN_TITLE2                      = GetStringValue("MainscreenTitle2", globals);
                WINDOW_BACKGROUND_COLOR                = GetStringValue("WindowBackColor", globals);
                SERVICE_MANAGER_NUMBER                 = GetStringValue("serviceManagerPhone", globals);
                REMINDER_INTERVAL                      = GetIntValue("reminderTimer", globals);
                TIMEOUT_INTERVAL                       = GetIntValue("timeOutInterval", globals);
                GLOBAL_ACCESS_TYPE                     = (GlobalAccessType)GetIntValue("globalAccessType", globals);
                PASSWORD_SIZE                          = GetIntValue("passWordSize", globals);
                NUMBER_CREDIT_CARD_DIGITS              = GetIntValue("cardNumberSize", globals);
                VEHICLE_NUMBER_LENGTH                  = GetIntValue("vehicleNumLength", globals);
                GENERIC_DATA_FIELD_LENGTH              = GetIntValue("genericDataFieldLength", globals);
                MILEAGE_DIFFERENCE_ALLOWED             = GetIntValue("mileageDifferenceAllowed", globals);
                NUMBER_RELAYS                          = GetIntValue("numberOfRelays", globals);
                RESERVATION_DATABASE_CONNECTION_STRING = GetStringValue("ReservationDatabaseConnection", globals);
                CUSTOMER_DATA_SERVER                   = GetStringValue("customerdataserver", globals);
                OPEN_DOOR_INTERVAL                     = GetIntValue("openDoorInterval", globals);

                //Window Background Color
                WindowBackRed   = int.Parse(WINDOW_BACKGROUND_COLOR.Split(',')[0]);
                WindowBackGreen = int.Parse(WINDOW_BACKGROUND_COLOR.Split(',')[1]);
                WindowBackBlue  = int.Parse(WINDOW_BACKGROUND_COLOR.Split(',')[2]);

                //ports
                string tempPort = GetStringValue("RCB_port", portnode);
                RCB_PORT  = ValidPortName(tempPort);
                RFID_PORT = GetStringValue("RFID_port", portnode);

                //configurable admin passwords
                CONFIG_ADMIN_PWORD_1 = GetStringValue("adminpassword1", configadminpasswords);
                CONFIG_ADMIN_PWORD_2 = GetStringValue("adminpassword2", configadminpasswords);
                CONFIG_ADMIN_PWORD_3 = GetStringValue("adminpassword3", configadminpasswords);

                //idscan
                IMAGE_SCAN_RESOLUTION = GetIntValue("imagescanresolution", idscannode);
                IMAGE_SCAN_TYPE       = GetStringValue("imagescantype", idscannode);

                //Text Msg
                ENABLE_TEXTMSG = GetBoolValue("textEnable", textnode);
                TEXTTO_ADDRESS = GetStringValue("textToAddress", textnode);

                //Email
                SMTP_SERVER         = GetStringValue("smtpServer", emailnode);
                SMTP_USERNAME       = GetStringValue("smtpUsername", emailnode);
                SMTP_PASSWORD       = GetStringValue("smtpPassword", emailnode);
                SMTP_AUTHENTICATION = GetBoolValue("smtpAuthentication", emailnode);
                FROM_ADDRESS        = GetStringValue("emailFromAddress", emailnode);
                TO_ADDRESS          = GetStringValue("emailToAddress", emailnode);
                ENABLE_EMAIL        = GetBoolValue("emailEnable", emailnode);

                //RFID
                ENABLE_RFID              = GetBoolValue("RFID_Enable", rfidnode);
                RFID_READER_TYPE         = GetStringValue("RFID_Reader", rfidnode);
                RFID_READ_ON_TIME        = GetIntValue("RFID_ReadOnTime", rfidnode);
                RFID_READ_OFF_TIME       = GetIntValue("RFID_ReadOffTime", rfidnode);
                RFID_TOTAL_READ_TIME     = GetIntValue("RFID_TotalReadTime", rfidnode);
                RFID_READ_POWER          = GetIntValue("RFID_ReadPower", rfidnode);
                RFID_INVENTORY_READ_TIME = GetIntValue("RFID_InventoryTime", rfidnode);
                IMPINJ_ANTENNA1_ENABLE   = GetBoolValue("ImpinjAntenna1Enable", rfidnode);
                IMPINJ_ANTENNA1_POWER    = GetIntValue("ImpinjAntenna1Power", rfidnode);
                IMPINJ_ANTENNA2_ENABLE   = GetBoolValue("ImpinjAntenna2Enable", rfidnode);
                IMPINJ_ANTENNA2_POWER    = GetIntValue("ImpinjAntenna2Power", rfidnode);
                IMPINJ_ANTENNA3_ENABLE   = GetBoolValue("ImpinjAntenna3Enable", rfidnode);
                IMPINJ_ANTENNA3_POWER    = GetIntValue("ImpinjAntenna3Power", rfidnode);
                IMPINJ_ANTENNA4_ENABLE   = GetBoolValue("ImpinjAntenna4Enable", rfidnode);
                IMPINJ_ANTENNA4_POWER    = GetIntValue("ImpinjAntenna4Power", rfidnode);

                //SQLite
                ENABLE_SQLITE        = GetBoolValue("EnableSQLiteDatabase", sqlitenode);
                SQLITE_DATABASE_NAME = GetStringValue("SQLiteDatabaseName", sqlitenode);
                SQLITE_MAX_RECORDS   = GetIntValue("MaxSQLiteRecords", sqlitenode);

                //Biometrics
                BIOMETRIC_ENABLE  = GetBoolValue("BiometricEnable", biometricnode);
                BIOMETRIC_TIMEOUT = GetIntValue("BiometricTimeout", biometricnode);
                BIOMETRIC_FALSE_POSITIVE_RATIO = GetIntValue("BiometricFalsePositiveRatio", biometricnode);

                //Users
                USERS_ENABLE = GetBoolValue("Users_Enable", usersnode);
                USERS_ACCESS_RESTRICTIONS_OVERRIDE = GetBoolValue("Users_Access_Restrictions_Override", usersnode);
                USER_ID_LENGTH = GetIntValue("UsersIDLength", usersnode);
                #endregion

                #region Software Initialization
                if (NUMBER_RELAYS > 20)
                {
                    SIXTY_KEY_DISPENSER = true;
                }

                loading.SetLabelText("Loading key data");
                // read in the key location and password file
                passwordMgr = new KeyPasswordManager(PASSWORD_FILE_NAME);

                loading.SetLabelText("Loading email\r\nmanager");
                //create the email manager
                emailMgr = new EmailerManager(SMTP_SERVER, FROM_ADDRESS, TO_ADDRESS, TEXTTO_ADDRESS);

                //create the user manager
                if (USERS_ENABLE)
                {
                    loading.SetLabelText("Loading user data");
                    userMgr = new UserManager("Users.xml");
                }

                //create the SQLcommandClass
                SqlManager = new SQLManager();

                #endregion

                #region Hardware Initialization
                //create Biometric Reader connection
                if (BIOMETRIC_ENABLE)
                {
                    loading.SetLabelText("Loading biometric\r\ndata");
                    biometricMgr = new BiometricDataManager("Fingerprints.xml");
                }
            }
            catch (Exception e)
            {
                string message = LanguageTranslation.CONFIGURATION_FILE_ERROR + "\r\n" + e.Message;
                MessageBox.Show(message);

                Program.logError(message); //try to log error
                Program.programExit();     //exit program - unreliable program due to unknown configuration problem
            }

            try
            {
                //create RFID reader connection
                if (ENABLE_RFID)
                {
                    if (RFID_READER_TYPE.ToUpper() == "IMPINJ")
                    {
                        loading.SetLabelText("Impinj Reader\r\nConnecting");
                        ImpinjRFIDreader = new ImpinjSpeedwayRFID(RFID_PORT);
                    }
                    else
                    {
                        loading.SetLabelText("M6e Micro Reader\r\nConnecting");
                        ThingMagicRFIDreader = new M6eMicroRFID(RFID_PORT, 115200, RFID_READ_ON_TIME, RFID_READ_OFF_TIME, RFID_READ_POWER, RFID_TOTAL_READ_TIME);
                    }
                }
            }
            catch (Exception ex)
            {
                string       message = LanguageTranslation.CONFIGURATION_RFID_ERROR_1 + "\r\n " + ex.Message + "\r\n" + LanguageTranslation.CONFIGURATION_RFID_ERROR_2;
                DialogResult result  = MessageBox.Show(message, "RFID Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                Program.logError(message);  //try to log error
                //if (result == DialogResult.No) //This ability to exit the program was removed 2/2/15 due to my concerns that if the impinj readers did not connect for some
                //{                              //reason during a daily morning reboot, a user could exit the program, access the box opening software and steal keys.
                //    Program.programExit();
                //}
            }
            #endregion

            #endregion

            #region port initialization

            try
            {
                loading.SetLabelText("Initializing Serial\r\nPorts");
                pm = PortManager.GetInstance();
                pm.InitializePorts(RCB_PORT);
            }
            catch (Exception e)
            {
                string message = LanguageTranslation.CONFIGURATION_OPEN_PORT_ERROR + "\r\n" + e.Message;
                MessageBox.Show(message);

                Program.logError(message); //try to log error
                Program.programExit();     //exit program - unreliable program due to unknown configuration problem
            }

            #endregion

            try
            {
                //Set REMINDER_INTERVAL to 0 if there is no need for reminders.
                if (REMINDER_INTERVAL > 0)
                {
                    loading.SetLabelText("Initializing Reminders");
                    System.Timers.Timer ReminderTimer = new System.Timers.Timer(REMINDER_INTERVAL);
                    ReminderTimer.Elapsed += new System.Timers.ElapsedEventHandler(ReminderTimer_Elapsed);
                    ReminderTimer.Start();
                }

                loading.SetLabelText("Initializing Customer\r\nConfiguration");
                if (KIOSK_LOCATION.ToUpper() == "ONTARIO")
                {
                    locationdata = new OntarioLocationData();
                }
                else if (KIOSK_LOCATION.ToUpper() == "NEBRASKA")
                {
                    NebResMgr     = new NebraskaReservationManager("NebraskaReservations.xml");
                    locationdata  = new NebraskaLocationData();
                    InitIDScanner = new SnapShell_Driver_Lic.Snapshell();
                }
                else if (KIOSK_LOCATION.ToUpper() == "OSU")
                {
                    locationdata = new OregonStateULocationData();
                }
                else if (KIOSK_LOCATION.ToUpper() == "MONTANA")
                {
                    locationdata = new MontanaLocationData();
                }
                else if (KIOSK_LOCATION.ToUpper() == "WAWATER")
                {
                    locationdata = new WAWaterLocationData();
                }
                else if (KIOSK_LOCATION.ToUpper() == "HUDSON")
                {
                    locationdata = new HudsonLocationData();
                }
                else if (KIOSK_LOCATION.ToUpper() == "DAIMLER")
                {
                    locationdata = new DaimlerChinaLocationData();
                    LanguageTranslation.language = language.Chinese;
                }
                else if (Program.KIOSK_LOCATION.ToUpper() == "CHEVIN") //if ChevinLocationData is used WaWaterTransactionData will be used with it
                {
                    locationdata = new ChevinLocationData();
                }
                else
                {
                    locationdata = new DefaultLocationData();
                }

                main = new MainForm();
                logEvent("Version: " + PROGRAM_VERSION);
                DeleteOldLogs();
                loading.Dispose();
                blank = new BlankForm();
                Program.blank.Visible = false;
                Program.blank.SendToBack();

                Program.logEvent("Program Started");
                Application.Run(main);
            }
            catch (Exception e)
            {
                string message = LanguageTranslation.CONFIGURATION_APP_ERROR + "\r\n " + e.Message;
                MessageBox.Show(message);

                Program.logError(message); //try to log error
                Program.programExit();     //exit program - unreliable program due to unknown configuration problem
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Displays an error message on a dialog which then closes after displayTimeMs milliseconds
        /// </summary>
        ///
        /// <param name="message"></param>
        /// <param name="displayTimeMs"></param>
        public static void ShowErrorMessage(string message, int displayTimeMs)
        {
            ErrorForm errorForm = new ErrorForm(message, displayTimeMs);

            errorForm.ShowDialog();
        }
        public bool SendEmail(ReportType type)
        {
            if (smtpEmailer == null)
            {
                Program.logError("smtp emailer null");
                return(false);
            }
            if (string.IsNullOrEmpty(report))
            {
                Program.logError("report null or empty");
                return(false);
            }

            string date       = DateTime.Now.Date.ToString();
            string time       = DateTime.Now.TimeOfDay.ToString();
            string serverAddr = smtpServer;       // "mail.authsmtp.com";
            string fromAddr   = emailFromAddress; // "*****@*****.**";
            string toAddr;

            if (type == ReportType.TextMsg || type == ReportType.BackgroundTextMsg)
            {
                toAddr = textToAddress;
            }
            else
            {
                toAddr = emailToAddress;
            }
            string emailSubjectHeader = "SafePak key cabinet";

            string username    = userName; //local constant
            string password    = passWord; //local constant
            bool   UsePassword = Program.SMTP_AUTHENTICATION;
            bool   UseSSL      = false;
            int    tryCount    = 2;

            ErrorForm SendingEmail = null;

            //if ((type == ReportType.TextMsg) || (type == ReportType.Email))
            if (type == ReportType.Email || type == ReportType.BackgroundEmail)
            {
                SendingEmail = Program.ShowMessage(LanguageTranslation.SENDING_EMAIL_RECEIPT);
            }
            else if (type == ReportType.TextMsg || type == ReportType.BackgroundTextMsg)
            {
                SendingEmail = Program.ShowMessage(LanguageTranslation.SENDING_TXTMSG_RECEIPT);
            }
            else if (type == ReportType.TransactionHistory)
            {
                SendingEmail = Program.ShowMessage(LanguageTranslation.SENDING_TRANSACTION_HISTORY);
            }
            try
            {
                smtpEmailer.sendEmail(date,                                            // string date
                                      time,                                            // string time
                                      serverAddr,                                      // string server address
                                      fromAddr,                                        // string from_address,
                                      toAddr,                                          // string to_address
                                      emailSubjectHeader,                              // string email subject
                                      this.report,                                     // string email_body
                                      UsePassword,                                     // bool username_password
                                      UseSSL,                                          // bool SSL
                                      username,                                        // string username,
                                      password,                                        // string password,
                                      tryCount);                                       // int trycount
            }

            catch (EmailSuccessMessage esm)
            {
                if (type == ReportType.TextMsg)
                {
                    Program.ShowErrorMessage(LanguageTranslation.TEXT_SUCCESSFUL, 5000);
                }
                else if (type == ReportType.Email)
                {
                    Program.ShowErrorMessage(LanguageTranslation.EMAIL_SUCCESSFUL, 5000);
                }
                else if (type == ReportType.TransactionHistory)
                {
                    Program.ShowErrorMessage(LanguageTranslation.EMAIL_TRANSACTIONS_SUCCESSFUL, 5000);
                }

                Program.logEvent(type.ToString() + " Success");
                return(true);
            }
            catch (Exception ex)
            {
                //If the sending of the email receipt fails a local copy is stored to be retrieved later.
                Program.logEvent("Receipt Failed. Local Copy Stored");
                Program.logEvent(ex.Message);
                Program.SqlManager.ErrorDatabaseEntry("", "", DateTime.Now.ToString(), Program.KIOSK_ID, 0, "Receipt Failed. Local Copy Stored" + ex.Message, "", 0);
                try { File.AppendAllText("Receipts\\" + DateTime.Today.Month.ToString() + ".log", "FAILED EMAIL" + DateTime.Now.ToString() + " " + this.report.ToString() + "\r\n"); }
                catch (Exception e)
                { File.AppendAllText("Logs\\error.log", e.Message + "\r\n" + DateTime.Now.ToString() + " " + this.report.ToString() + "\r\n"); }

                if (type == ReportType.TextMsg)
                {
                    Program.ShowErrorMessage(LanguageTranslation.TEXT_FAILED, 7000);
                }
                else if (type == ReportType.Email)
                {
                    Program.ShowErrorMessage(LanguageTranslation.EMAIL_FAILED, 7000);
                }
                else if (type == ReportType.TransactionHistory)
                {
                    Program.ShowErrorMessage(LanguageTranslation.EMAIL_TRANSACTIONS_FAILED, 7000);
                }

                return(false);
            }
            finally
            {
                report = "";
                SendingEmail.Dispose();
            }
            return(true);
        }