Exemple #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            importData();
            MemoryTable.initializeTabes();
            frmClassRoom = new frmClassRoom();
            frmFloat     = new frmFloat();
            StaticDataPort.openDataPort(5000);       //普通的系统数据交互端口
            LoginManager.StartRFID_UDPServer(5001);  //读卡器传送数据端口
            LoginManager.StartLogin_UDPServer(5002); //登陆端口
            LoginManager.start_broadcasting_config(5000, 5002);

            Application.Run(frmFloat);

            //Application.Run(new frmTest());

            //frmMainFloat frmStart = new frmMainFloat();
            //Application.Run(frmStart);
            //frmCheckInit frmStart = new frmCheckInit();
            //frmCheckStatics frmStart = new frmCheckStatics();
            //Application.Run(frmMain);
            //Application.Run(new Form1());
            //Application.Run(new frmLogin());
            //frmCheck = new frmCheck();
            //frmTest = new frmRTTest();
            //Program.compareString();
        }
        public static void openDataPort()
        {
            try
            {
#if UDP_TRANSE
                initial_udp_server();
                IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
                //The epSender identifies the incoming clients
                EndPoint epSender = (EndPoint)ipeSender;

                //Start receiving data
                serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length,
                                              SocketFlags.None, ref epSender, new AsyncCallback(OnReceive), epSender);
#endif

#if SERIAL_PORT_TRANSE
                if (!StaticDataPort.getStaticSerialPort().IsOpen)
                {
                    StaticDataPort.getStaticSerialPort().Open();
                }
#endif
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message + ",请检查后重启本系统", "信息提示", MessageBoxButtons.OK);
            }
        }
        //关闭串口的时候必须考虑死锁问题
        public static void closeDataPort()
        {
#if SERIAL_PORT_TRANSE
            if (StaticDataPort.getStaticSerialPort().IsOpen)
            {
                StaticDataPort.getStaticSerialPort().Close();
            }
#endif
        }
 public static SerialPort getStaticSerialPort()
 {
     if (StaticDataPort.comport == null)
     {
         StaticDataPort.comport = new SerialPort();
         comport.DataReceived  += StaticDataPort.port_DataReceived;
         StaticDataPort.resetStaticSerialPort();//使用统一配置参数
     }
     return(StaticDataPort.comport);
 }
        /// <summary>
        /// 串口关闭时可能引起线程死锁,因此这里要求首先安全关闭串口
        /// </summary>
        /// <param name="portName"></param>
        /// <param name="baudRate"></param>
        /// <param name="parity"></param>
        /// <param name="dataBits"></param>
        /// <param name="stopBits"></param>
        public static void resetStaticSerialPort(string portName, string baudRate, string parity, string dataBits, string stopBits)
        {
            SerialPort sp         = StaticDataPort.getStaticSerialPort();
            bool       biniOpened = sp.IsOpen;

            if (biniOpened)
            {
                //sp.Close();
                MessageBox.Show("请先关闭串口!");
                return;
            }
            try
            {
                sp.PortName = portName;
                sp.BaudRate = int.Parse(baudRate);
                sp.DataBits = int.Parse(dataBits);
                sp.StopBits = (StopBits)Enum.Parse(typeof(StopBits), stopBits);
                sp.Parity   = (Parity)Enum.Parse(typeof(Parity), parity);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("设置串口时出现异常错误!" + ex.Message);
            }
        }
Exemple #6
0
        public frmMainFloat()
        {
            InitializeComponent();
            Screen[] screens = System.Windows.Forms.Screen.AllScreens;
            for (int i = 0; i < screens.Length; i++)
            {
                Screen sc = screens[i];
                if (sc.Primary == true)
                {
                    Rectangle rect = sc.WorkingArea;
                    this.Left = (int)(rect.Width * 0.7);
                    this.Top  = (int)(rect.Height * 0.1);
                }
            }

            Color c = Color.FromArgb(77, 175, 237);

            this.BackColor = c;

            this.menuItemClose        = new System.Windows.Forms.MenuItem();
            this.menuItemClose.Index  = 0;
            this.menuItemClose.Text   = "退出(&X)";
            this.menuItemClose.Click += new EventHandler(menuItemClose_Click);

            menuItemAbout        = new System.Windows.Forms.MenuItem();
            menuItemAbout.Index  = 1;
            menuItemAbout.Text   = "关于(&A)";
            menuItemAbout.Click += new EventHandler(menuItemAbout_Click);

            menuItemSerialConfig        = new System.Windows.Forms.MenuItem();
            menuItemSerialConfig.Index  = 2;
            menuItemSerialConfig.Text   = "串口设置(&C)";
            menuItemSerialConfig.Click += new EventHandler(menuItemSerialConfig_Click);

            menuItemEquipmentConfig        = new System.Windows.Forms.MenuItem();
            menuItemEquipmentConfig.Index  = 3;
            menuItemEquipmentConfig.Text   = "教室设置(&E)";
            menuItemEquipmentConfig.Click += new EventHandler(menuItemEquipmentConfig_Click);

            menuItemQuestionMng        = new System.Windows.Forms.MenuItem();
            menuItemQuestionMng.Index  = 4;
            menuItemQuestionMng.Text   = "题目管理(&Q)";
            menuItemQuestionMng.Click += new EventHandler(menuItemQuestionMng_Click);

            menuItemAnalysis        = new System.Windows.Forms.MenuItem();
            menuItemAnalysis.Index  = 5;
            menuItemAnalysis.Text   = "统计分析(&S)";
            menuItemAnalysis.Click += new EventHandler(menuItemAnalysis_Click);

            menuItemStudentMng        = new System.Windows.Forms.MenuItem();
            menuItemStudentMng.Index  = 6;
            menuItemStudentMng.Text   = "学生管理(&T)";
            menuItemStudentMng.Click += new EventHandler(menuItemStudentMng_Click);



            this.notifyContextMenu = new System.Windows.Forms.ContextMenu();
            this.notifyContextMenu.MenuItems.Add(menuItemStudentMng);
            this.notifyContextMenu.MenuItems.Add(menuItemAnalysis);
            this.notifyContextMenu.MenuItems.Add(menuItemQuestionMng);
            this.notifyContextMenu.MenuItems.Add(menuItemEquipmentConfig);
            this.notifyContextMenu.MenuItems.Add(menuItemSerialConfig);
            this.notifyContextMenu.MenuItems.Add(menuItemAbout);
            this.notifyContextMenu.MenuItems.Add(menuItemClose);


            this.components = new System.ComponentModel.Container();

            // Create the NotifyIcon.
            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

            // The Icon property sets the icon that will appear
            // in the systray for this application.
            notifyIcon1.Icon = new Icon("5.ico");

            // The ContextMenu property sets the menu that will
            // appear when the systray icon is right clicked.
            notifyIcon1.ContextMenu = this.notifyContextMenu;

            // The Text property sets the text that will be displayed,
            // in a tooltip, when the mouse hovers over the systray icon.
            notifyIcon1.Text    = "智能教学互动系统";
            notifyIcon1.Visible = true;

            notifyIcon1.BalloonTipTitle = "智能教学互动系统已经启动";
            notifyIcon1.BalloonTipText  = "更多功能请点击...";
            notifyIcon1.ShowBalloonTip(15);


            //int size = this.pbFloatPie.Width - 2;
            //this.notifyIconChart1 = new System.Windows.Forms.NotifyIconChart(size);

            //this.notifyIconChart1.BackgroundColor = System.Drawing.Color.Transparent;
            //this.notifyIconChart1.ChartType = System.Windows.Forms.NotifyIconChart.ChartTypeEnum.pie;
            //this.notifyIconChart1.Color1 = System.Drawing.Color.Red;
            //this.notifyIconChart1.Color2 = System.Drawing.Color.Green;
            //this.notifyIconChart1.FrameColor = System.Drawing.Color.Transparent;
            //this.notifyIconChart1.NotifyIconObject = null;
            //this.notifyIconChart1.Value1 = 0;
            //this.notifyIconChart1.Value2 = 1;

            //Bitmap bmp = this.notifyIconChart1.GetChartBitmap();
            //this.pbFloatPie.Image = bmp;

            this.MouseDown += new MouseEventHandler(Form1_MouseDown);
            this.MouseMove += new MouseEventHandler(Form1_MouseMove);
            this.MouseUp   += new MouseEventHandler(Form1_MouseUp);

            this.FormClosing += new FormClosingEventHandler(frmMainFloat_FormClosing);
            StaticDataPort.openDataPort();
        }
 void Form1_Shown(object sender, EventArgs e)
 {
     StaticDataPort.openDataPort();
 }