退出软件断开与板子连接
This commit is contained in:
		
							parent
							
								
									5d04921387
								
							
						
					
					
						commit
						386a663026
					
				| 
						 | 
					@ -3,7 +3,7 @@
 | 
				
			||||||
  <connectionStrings>
 | 
					  <connectionStrings>
 | 
				
			||||||
	<!-- 数据库连接字符串 -->
 | 
						<!-- 数据库连接字符串 -->
 | 
				
			||||||
	<!--<add name="database" connectionString="server=127.0.0.1;database=wpf_dm_program;userid=root;password=qq1223" />-->
 | 
						<!--<add name="database" connectionString="server=127.0.0.1;database=wpf_dm_program;userid=root;password=qq1223" />-->
 | 
				
			||||||
	<add name="database" connectionString="server=127.0.0.1;port=3306;database=xiangtan_mazuike_xx;userid=root;password=root" />
 | 
						<add name="database" connectionString="server=127.0.0.1;port=3306;database=xiangtan_mazuike;userid=root;password=root" />
 | 
				
			||||||
  </connectionStrings>
 | 
					  </connectionStrings>
 | 
				
			||||||
	<!--<runtime>
 | 
						<!--<runtime>
 | 
				
			||||||
		--><!--配置之后,Appdomain.CurrentDomain.UnhandledException 事件的 IsTerminating 就变成了 false 啦!也就是说,程序并不会因为这次的异常而崩溃退出。--><!--
 | 
							--><!--配置之后,Appdomain.CurrentDomain.UnhandledException 事件的 IsTerminating 就变成了 false 啦!也就是说,程序并不会因为这次的异常而崩溃退出。--><!--
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@
 | 
				
			||||||
		<!-- 按处方还药或者按取药记录还药 1:处方(ReturnDrugWindow2)2:药品(ReturnDrugWindow)-->
 | 
							<!-- 按处方还药或者按取药记录还药 1:处方(ReturnDrugWindow2)2:药品(ReturnDrugWindow)-->
 | 
				
			||||||
		<add key="returnDrugMode" value="2" />
 | 
							<add key="returnDrugMode" value="2" />
 | 
				
			||||||
		<!-- 自动退出时间,单位秒,为0时不自动退出 -->
 | 
							<!-- 自动退出时间,单位秒,为0时不自动退出 -->
 | 
				
			||||||
		<add key="autoExit" value="5"/>
 | 
							<add key="autoExit" value="0"/>
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		<!-- 无操作退出录像时间,单位秒,为0时不退出录像 -->
 | 
							<!-- 无操作退出录像时间,单位秒,为0时不退出录像 -->
 | 
				
			||||||
		<add key="stopRecord" value="180"/>
 | 
							<add key="stopRecord" value="180"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ using DM_Weight.util;
 | 
				
			||||||
using DM_Weight.ViewModels;
 | 
					using DM_Weight.ViewModels;
 | 
				
			||||||
using log4net;
 | 
					using log4net;
 | 
				
			||||||
using Mina.Core.Future;
 | 
					using Mina.Core.Future;
 | 
				
			||||||
 | 
					using Mina.Core.Session;
 | 
				
			||||||
using Mina.Filter.Codec;
 | 
					using Mina.Filter.Codec;
 | 
				
			||||||
using Mina.Filter.Logging;
 | 
					using Mina.Filter.Logging;
 | 
				
			||||||
using Mina.Transport.Socket;
 | 
					using Mina.Transport.Socket;
 | 
				
			||||||
| 
						 | 
					@ -25,18 +26,18 @@ namespace DM_Weight.Port
 | 
				
			||||||
        private readonly ILog logger = LogManager.GetLogger(typeof(SocketHelper));
 | 
					        private readonly ILog logger = LogManager.GetLogger(typeof(SocketHelper));
 | 
				
			||||||
        AsyncSocketConnector acceptor = new AsyncSocketConnector();
 | 
					        AsyncSocketConnector acceptor = new AsyncSocketConnector();
 | 
				
			||||||
        IConnectFuture iConnectFuture;
 | 
					        IConnectFuture iConnectFuture;
 | 
				
			||||||
        public bool OpenStatus=false;
 | 
					        public bool OpenStatus = false;
 | 
				
			||||||
        public bool ConnectedStatus = false;
 | 
					        public bool ConnectedStatus = false;
 | 
				
			||||||
        //多线程退出标识
 | 
					        //多线程退出标识
 | 
				
			||||||
        public bool IsMultiThread = false;
 | 
					        public bool IsMultiThread = false;
 | 
				
			||||||
        string ip = ConfigurationManager.AppSettings["modbusIp"].ToString();
 | 
					        string ip = ConfigurationManager.AppSettings["modbusIp"].ToString();
 | 
				
			||||||
        int port =Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
 | 
					        int port = Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
 | 
				
			||||||
        IEventAggregator _eventAggregator;
 | 
					        IEventAggregator _eventAggregator;
 | 
				
			||||||
        FingerprintUtil _fingerprintUtil;
 | 
					        FingerprintUtil _fingerprintUtil;
 | 
				
			||||||
        public DateTime dateTime { get; set; } = DateTime.Now;
 | 
					        public DateTime dateTime { get; set; } = DateTime.Now;
 | 
				
			||||||
        public SocketHelper(IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil)
 | 
					        public SocketHelper(IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _fingerprintUtil= fingerprintUtil;
 | 
					            _fingerprintUtil = fingerprintUtil;
 | 
				
			||||||
            _eventAggregator = eventAggregator;
 | 
					            _eventAggregator = eventAggregator;
 | 
				
			||||||
            acceptor.ExceptionCaught += (o, e) =>
 | 
					            acceptor.ExceptionCaught += (o, e) =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
| 
						 | 
					@ -60,17 +61,21 @@ namespace DM_Weight.Port
 | 
				
			||||||
                logger.Info("MessageReceived>>>>>>>>>>>>>>>>" + OpenStatus);
 | 
					                logger.Info("MessageReceived>>>>>>>>>>>>>>>>" + OpenStatus);
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            acceptor.SessionClosed += new EventHandler<IoSessionEventArgs>(SessionCloseMethod);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            acceptor.SessionClosed += (o, e) =>
 | 
					            //acceptor.SessionClosed += (o, e) =>
 | 
				
			||||||
            {
 | 
					            //{
 | 
				
			||||||
                logger.Info("SessionClosed");
 | 
					            //    logger.Info($"SessionClosed;ExitFlag:{ExitFlag}");
 | 
				
			||||||
                //Task.Delay(50).Wait();
 | 
					            //    //Task.Delay(50).Wait();
 | 
				
			||||||
                SocketConnect(); 
 | 
					            //    if (!ExitFlag)
 | 
				
			||||||
                Task.Factory.StartNew(() =>
 | 
					            //    {
 | 
				
			||||||
                {
 | 
					            //        SocketConnect();
 | 
				
			||||||
                    _fingerprintUtil.FingerDisconnect();
 | 
					            //        Task.Factory.StartNew(() =>
 | 
				
			||||||
                });
 | 
					            //        {
 | 
				
			||||||
            };
 | 
					            //            _fingerprintUtil.FingerDisconnect();
 | 
				
			||||||
 | 
					            //        });
 | 
				
			||||||
 | 
					            //    }
 | 
				
			||||||
 | 
					            //};
 | 
				
			||||||
            this.SocketConnect();
 | 
					            this.SocketConnect();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        int i = 0;
 | 
					        int i = 0;
 | 
				
			||||||
| 
						 | 
					@ -84,7 +89,6 @@ namespace DM_Weight.Port
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (i <= 3)
 | 
					                if (i <= 3)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Thread.Sleep(1950);
 | 
					 | 
				
			||||||
                    //没连上会再连两次
 | 
					                    //没连上会再连两次
 | 
				
			||||||
                    SocketConnect();
 | 
					                    SocketConnect();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					@ -107,9 +111,24 @@ namespace DM_Weight.Port
 | 
				
			||||||
            ConnectedStatus = iConnectFuture.Connected;
 | 
					            ConnectedStatus = iConnectFuture.Connected;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void SessionCloseMethod(System.Object o, IoSessionEventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            logger.Info($"SessionClosed");
 | 
				
			||||||
 | 
					            SocketConnect();
 | 
				
			||||||
 | 
					            Task.Factory.StartNew(() =>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _fingerprintUtil.FingerDisconnect();
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        public void SocketDisConnect()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            acceptor.SessionClosed -=new EventHandler<IoSessionEventArgs>(SessionCloseMethod);
 | 
				
			||||||
 | 
					            iConnectFuture.Session.CloseNow();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void SendMessage(MyBaseMessage baseMessage)
 | 
					        public void SendMessage(MyBaseMessage baseMessage)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if(!ConnectedStatus)
 | 
					            if (!ConnectedStatus)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                SocketConnect();
 | 
					                SocketConnect();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -503,7 +503,7 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                                    && cs.Quantity >= oi._OrderDetail.Quantity).First();
 | 
					                                                    && cs.Quantity >= oi._OrderDetail.Quantity).First();
 | 
				
			||||||
                            if (cs == null)
 | 
					                            if (cs == null)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo},{oi._OrderDetail.SetEffDate};";
 | 
					                                empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo};";
 | 
				
			||||||
                                continue;
 | 
					                                continue;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;
 | 
					                            cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -377,6 +377,7 @@ _exitCommand ??= new DelegateCommand(Exit);
 | 
				
			||||||
        void Exit()
 | 
					        void Exit()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            //_chkFunction.HIKLoginOut();
 | 
					            //_chkFunction.HIKLoginOut();
 | 
				
			||||||
 | 
					            _socketHelper.SocketDisConnect();
 | 
				
			||||||
            Process.GetCurrentProcess().Kill();
 | 
					            Process.GetCurrentProcess().Kill();
 | 
				
			||||||
            Environment.Exit(0);
 | 
					            Environment.Exit(0);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue