Example #1
0
 private void 退出监听程序ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (FrmDialog.ShowDialog(this, "是否确认退出程序?", "提示", true) == DialogResult.OK)
     {
         LogPathTimer.Stop();
         CleaningTimer.Stop();
         TransModuleRefresh.Stop();
         fsw.Flush();
         fsw.Close();
         NotifyIcon.Visible = false;
         System.Environment.Exit(0);
     }
 }
Example #2
0
        private void DM_Load(object sender, EventArgs e)
        {
            Properties.Settings.Default.StartTime = DateTime.Now;
            label7.Text                     = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            this.MaximizeBox                = false;
            this.MinimumSize                = new Size(280, 563);
            this.Size                       = new Size(280, 563);
            this.FormBorderStyle            = FormBorderStyle.FixedSingle;
            splitContainer1.Panel1Collapsed = true;
            if (!System.IO.File.Exists(Application.StartupPath + "/Config.mdb"))
            {
                FrmTips.ShowTipsInfo(this, "检测不到中继数据库,正在生成,请稍候");
                //MessageBox.Show("检测不到数据库,自动生成,请重启程序后使用", "数据传输中继");
                byte[] config = Properties.Resources.Config;
                System.IO.File.WriteAllBytes(Application.StartupPath + "/Config.mdb", config);
                System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
                System.Environment.Exit(0);
            }
            try
            {
                string      path = Application.ExecutablePath;
                RegistryKey rk   = Registry.LocalMachine;
                RegistryKey rk2  = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                string[]    rest = rk2.GetValueNames();
                foreach (string line in rest)
                {
                    if (line == "JcShutdown")
                    {
                        设为开机启动ToolStripMenuItem.Checked = true;
                    }
                }
            }
            catch (Exception ex)
            {
                FrmTips.ShowTipsWarning(this, "请使用管理员模式运行");
                //MessageBox.Show(ex.Message, "请使用管理员模式运行本程序");
            }
            if (Properties.Settings.Default.LogsReserve != "0")
            {
                LogsCleaningTimer.Start();
            }
            CleaningTimer.Start();
            LogPathTimer.Start();
            TransModuleRefresh.Start();
            LogPathTimer_Tick(null, null);
            try
            {
                fsw = new FileStream(logpath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
            }
            catch (Exception ex)
            {
                FrmDialog.ShowDialog(this, "写日志线程异常:" + ex.Message);
            }
            LogPrint("*************************************", 2);
            LogPrint("正在启动LIS系统网口仪器中继程序", 2);
            LogPrint("*************************************", 2);
            try
            {
                MachineName.Text               = Properties.Settings.Default.MachineName;
                MenuMachineName.Text           = "仪器:" + Properties.Settings.Default.MachineName;
                this.Text                      = Properties.Settings.Default.ProgramName;
                this.NotifyIcon.Text           = Properties.Settings.Default.ProgramName;
                this.NotifyIcon.BalloonTipText = Properties.Settings.Default.ProgramName;
                desktopenter                   = Properties.Settings.Default.ShortcutName;
                CleaningTimer.Interval         = int.Parse(Properties.Settings.Default.CleaningTimer);
                TransModuleRefresh.Interval    = int.Parse(Properties.Settings.Default.ApplyTimer);
                lisport            = Properties.Settings.Default.LISport.ToString();
                ConnectWay         = byte.Parse(Properties.Settings.Default.ConnectWay);
                serialportno       = Properties.Settings.Default.SerialPortNo.ToString();
                serialbaudrate     = Properties.Settings.Default.SerialBaudRate;
                serialparitycheck  = Properties.Settings.Default.SerialParityCheck;
                serialdatabit      = Properties.Settings.Default.SerialDataBit;
                serialstopbit      = Properties.Settings.Default.SerialStopBit;
                filenameextension  = Properties.Settings.Default.FileNameExtension;
                filepath           = Properties.Settings.Default.FilePath;
                filewritepath      = Properties.Settings.Default.FileWritePath;
                filewriteextension = Properties.Settings.Default.FileWriteExtension;
                clientport         = Properties.Settings.Default.ClientPort.ToString();
                serverport         = Properties.Settings.Default.ServerPort.ToString();
                timesleep          = int.Parse(Properties.Settings.Default.ClientTimer);
                FileTimer.Interval = int.Parse(Properties.Settings.Default.FileTimer);
                clientip           = IPAddress.Parse(Properties.Settings.Default.ClientIP.Replace(" ", ""));
            }
            catch (Exception ex)
            {
                FrmTips.ShowTipsError(this, "服务启动错误:" + ex.Message);
            }
            LogPrint("LIS连接IP:" + ip.ToString(), 0);
            LogPrint("LIS连接端口:" + lisport, 0);
            ConfigConsole terminal = new ConfigConsole(fsw);

            threadlis = new Thread(WaitLIS);
            threadlis.Start();
            terminal.start();

            ClearMemoryInfo.FlushMemory();

            switch (ConnectWay)
            {
            case 0:
                LogPrint("仪器连接方式:客户端连接", 1);
                LogPrint("仪器连接IP端口:" + ip + ":" + serverport, 1);
                threadmac = new Thread(WaitMac);
                threadmac.Start();
                LogPrint("*************************************", 2);
                break;

            case 1:
                LogPrint("仪器连接方式:服务端监听", 1);
                LogPrint("仪器监听IP端口:" + clientip + ":" + clientport, 1);
                threadmac = new Thread(ConnMac);
                threadmac.Start();
                LogPrint("*************************************", 2);
                break;

            case 2:
                LogPrint("仪器连接方式:串口连接", 1);
                LogPrint("仪器连接串口号:" + serialportno, 1);
                LogPrint("波特率:" + serialbaudrate, 1);
                LogPrint("校验:" + serialparitycheck, 1);
                LogPrint("数据位:" + serialdatabit, 1);
                LogPrint("停止位:" + serialstopbit, 1);
                LogPrint("RTS/CTS:" + Properties.Settings.Default.SerialRTSEnable, 1);
                threadmac = new Thread(SerialPort);
                threadmac.Start();
                LogPrint("*************************************", 2);
                break;

            case 3:
                LogPrint("仪器连接方式:读文件", 1);
                LogPrint("仪器数据目录:" + filepath + "\\*." + filenameextension, 1);
                LogPrint("写入数据目录:" + filewritepath + "\\*." + filewriteextension, 1);
                FileTimer.Start();
                ucWave1.WaveColor = Color.FromArgb(0, 155, 144);

                if (Properties.Settings.Default.FileConnectLIS)
                {
                    LogPrint("链接Cache模式", 1);
                    MACIP.Text = "读文件(链接Cache)模式";
                    Properties.Settings.Default.MacStatus = "读文件(链接Cache)模式";
                    string ret = operat.Login(Properties.Settings.Default.CacheHost, int.Parse(Properties.Settings.Default.CachePort), Properties.Settings.Default.CacheNamespace, Properties.Settings.Default.CacheUserID, Properties.Settings.Default.CachePassword);
                    if (ret == "Login Cache OK")
                    {
                        LogPrint("登录LIS数据库成功", 1);
                    }
                    else
                    {
                        LogPrint("登录LIS数据库失败:" + ret.Split(':')[1], 1);
                        FileTimer.Stop();
                        ucWave1.WaveColor = Color.FromArgb(255, 77, 59);
                    }
                }
                else
                {
                    LogPrint("转网络传输模式", 1);
                    MACIP.Text = "读文件(转网络)模式";
                    Properties.Settings.Default.MacStatus = "读文件(转网络)模式";
                }
                LogPrint("*************************************", 2);
                break;
            }
        }