Exemple #1
0
 public void SerialSubscribe(SerialPortReceiverClass s)
 {
     s.DataReceived += SerialReception;
 }
Exemple #2
0
 public void SerialReception(SerialPortReceiverClass sender)
 {
     PreviousConnection = ConnectionType.Serial;
     Invoke((MethodInvoker)(ParseCall));
 }
Exemple #3
0
        public FrmMain()
        {
            InitializeComponent();

            string old_database = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CallerID.com\ELPopup\CallDatabase.db3";

            if (File.Exists(old_database))
            {
                DialogResult import_result = Common.MessageBox("Import Old Database?", "Old ELPopup database found. Import those call records into ELPopup 5?", true, DialogResult.Yes, true, DialogResult.No, false, DialogResult.None, "Yes", "No", "", 1);

                if (import_result == DialogResult.Yes)
                {
                    FrmOptions fOptTemp = new FrmOptions(true);
                    fOptTemp.ImportOldDatabase(old_database);
                    if (fOptTemp.Visible)
                    {
                        fOptTemp.Close();
                    }
                    fOptTemp = null;
                }
                else
                {
                    DialogResult not_show_again = Common.MessageBox("Remind Me?", "Remind me later to Import?", true, DialogResult.Yes, true, DialogResult.No, false, DialogResult.None, "Yes", "No", "", 1);

                    if (not_show_again == DialogResult.No)
                    {
                        File.Move(old_database, old_database.Replace(".db3", "-skipped.db3"));
                    }
                }
            }

            lbLines[1]  = lbL1;
            lbLines[2]  = lbL2;
            lbLines[3]  = lbL3;
            lbLines[4]  = lbL4;
            lbLines[5]  = lbL5;
            lbLines[6]  = lbL6;
            lbLines[7]  = lbL7;
            lbLines[8]  = lbL8;
            lbLines[9]  = lbL9;
            lbLines[10] = lbL10;
            lbLines[11] = lbL11;
            lbLines[12] = lbL12;

            tbNumbers[1]  = tbL1Number;
            tbNumbers[2]  = tbL2Number;
            tbNumbers[3]  = tbL3Number;
            tbNumbers[4]  = tbL4Number;
            tbNumbers[5]  = tbL5Number;
            tbNumbers[6]  = tbL6Number;
            tbNumbers[7]  = tbL7Number;
            tbNumbers[8]  = tbL8Number;
            tbNumbers[9]  = tbL9Number;
            tbNumbers[10] = tbL10Number;
            tbNumbers[11] = tbL11Number;
            tbNumbers[12] = tbL12Number;

            tbNames[1]  = tbL1Name;
            tbNames[2]  = tbL2Name;
            tbNames[3]  = tbL3Name;
            tbNames[4]  = tbL4Name;
            tbNames[5]  = tbL5Name;
            tbNames[6]  = tbL6Name;
            tbNames[7]  = tbL7Name;
            tbNames[8]  = tbL8Name;
            tbNames[9]  = tbL9Name;
            tbNames[10] = tbL10Name;
            tbNames[11] = tbL11Name;
            tbNames[12] = tbL12Name;

            switch (Program.AppSettings[(int)Program.AppSetting.MAX_LINE_NUMBER])
            {
            case "-1":
                UnHideLines(Lines.OneThroughFour, true);
                Program.AppSettings[(int)Program.AppSetting.MAX_LINE_NUMBER] = "4";
                Common.SaveSettings();
                break;

            case "4":
                UnHideLines(Lines.OneThroughFour, true);
                break;

            case "8":
                UnHideLines(Lines.FiveThroughEight, true);
                break;

            case "12":
                UnHideLines(Lines.EightThroughTwelve, true);
                break;
            }

            PreviousCall.Line = -1;

            if (bool.Parse(Program.AppSettings[(int)Program.AppSetting.USE_CUSTOM_MAIN_WINDOW_SIZING]))
            {
                Size = new Size(int.Parse(Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_WIDTH]), int.Parse(Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_HEIGHT]));
            }

            if (bool.Parse(Program.AppSettings[(int)Program.AppSetting.USE_CUSTOM_POSITION]))
            {
                if (int.Parse(Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_X]) > Screen.PrimaryScreen.Bounds.Width ||
                    int.Parse(Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_X]) < 0)
                {
                    Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_X] = "0";
                }

                if (int.Parse(Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_Y]) > Screen.PrimaryScreen.Bounds.Height ||
                    int.Parse(Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_Y]) < 0)
                {
                    Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_Y] = "0";
                }

                Location = new Point(int.Parse(Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_X]), int.Parse(Program.AppSettings[(int)Program.AppSetting.MAIN_WINDOW_Y]));
            }
            else
            {
                this.CenterToScreen();
            }

            UdpReceiver       = new UdpReceiverClass();
            _udpReceiveThread = new Thread(UdpReceiver.UdpIdleReceive);

            Program.COM_PORTS.Add("None");
            string[] com_ports       = SerialPort.GetPortNames();
            string   found_port_name = "";

            foreach (string port_name in com_ports)
            {
                PortScan = new SerialPort(port_name, 9600, Parity.None, 8, StopBits.One);
                string found_text = "";

                try
                {
                    PortScan.DataReceived += new SerialDataReceivedEventHandler(PortTest);
                    PortScan.Open();
                    PortScan.Write("@");
                    PortScan.ReadTimeout = 900;
                    Common.WaitFor(1000);
                    if (SerialReadIn == "#")
                    {
                        found_port_name = port_name;
                        found_text      = " (Unit Detected)";
                    }
                    PortScan.Close();
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    found_text = " (Another app using COM Port)";
                }

                Program.COM_PORTS.Add(port_name + found_text);
            }

            if (found_port_name != "" && found_port_name != "None")
            {
                Program.AppSettings[(int)Program.AppSetting.SS_COM_PORT] = found_port_name;
                Common.SaveSettings();
            }

            SerialReceiver = new SerialPortReceiverClass(Program.AppSettings[(int)Program.AppSetting.SS_COM_PORT]);

            sys_tray_icon      = new NotifyIcon();
            sys_tray_icon.Icon = new Icon("phone.ico");

            ContextMenuStrip sys_tray_menu = new ContextMenuStrip();

            sys_tray_icon.DoubleClick += new EventHandler(SysTrayMenuOpen_Clicked);
            sys_tray_icon.Click       += new EventHandler(SysTrayMenuOptions_Single_Click);

            ToolStripMenuItem sys_tray_menu_open = new ToolStripMenuItem();

            sys_tray_menu_open.Text   = "Main Window";
            sys_tray_menu_open.Click += new EventHandler(SysTrayMenuOpen_Clicked);
            sys_tray_menu.Items.Add(sys_tray_menu_open);

            ToolStripMenuItem sys_tray_menu_options = new ToolStripMenuItem();

            sys_tray_menu_options.Text   = "Options";
            sys_tray_menu_options.Click += new EventHandler(SysTrayMenuOptions_Clicked);
            sys_tray_menu.Items.Add(sys_tray_menu_options);

            ToolStripMenuItem sys_tray_menu_user_manual = new ToolStripMenuItem();

            sys_tray_menu_user_manual.Text   = "User Manual";
            sys_tray_menu_user_manual.Click += new EventHandler(SysTrayUserManual_Clicked);
            sys_tray_menu.Items.Add(sys_tray_menu_user_manual);

            ToolStripMenuItem sys_tray_menu_close = new ToolStripMenuItem();

            sys_tray_menu_close.Text   = "Close ELPopup";
            sys_tray_menu_close.Click += new EventHandler(SysTrayMenuClose_Clicked);
            sys_tray_menu.Items.Add(sys_tray_menu_close);

            sys_tray_icon.ContextMenuStrip = sys_tray_menu;
            sys_tray_icon.Text             = "ELPopup 5";

            // Initialize popup controller
            pController = new PopupController();

            // Start listener for UDP traffic
            Subscribe(UdpReceiver);
            _udpReceiveThread.IsBackground = true;
            _udpReceiveThread.Start();

            // Start listener for SERIAL traffic
            SerialSubscribe(SerialReceiver);
            SerialReceiver.OpenCOMPort();

            PopulateCallLog();

            UpdateTitleBar();

            sys_tray_icon.Visible = true;

            dgvCallLog.ClearSelection();

            ndDisplayCount.Value = int.Parse(Program.AppSettings[(int)Program.AppSetting.DISPLAY_RECORD_COUNT]);

            if (bool.Parse(Program.AppSettings[(int)Program.AppSetting.START_MINIMIZED]))
            {
                timerAutoHide.Enabled = true;
                timerAutoHide.Start();
            }
        }