Esempio n. 1
0
        public override bool TestConfig(string[] args)
        {
            RelationalDatabase db = new MsSqlServer();

            try
            {
                string connectionString = "packet size=4096;user id={0};password={1};data source={2};persist security info=True;initial catalog={3}";
                db.Initialize(string.Format(connectionString, args[2], args[3], args[0], args[1]));
                db.Open();
                db.Close();
                return(true);
            }
            catch (Exception error)
            {
                return(false);
            }
            finally
            {
                db.Dispose();
                db = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 监听端口 有数据传输则刷新显示屏以及语音朗诵
        /// </summary>
        /// <param name="port">端口号</param>
        public void SocketListen(int port, RelationalDatabase _DataBase, Fz_Zq zq,
                                 Socket listener, VoiceHelp _voice, ref Socket socket)
        {
            RelationalDatabase db1 = new MsSqlServer();

            db1.Initialize(_DataBase.ConnectionString);
            string rq1 = DateManager.ServerDateTimeByDBType(db1).ToShortDateString() + " 00:00:00";

            db1.Close();
            db1.Dispose();
            RelationalDatabase db2 = new MsSqlServer();

            db2.Initialize(_DataBase.ConnectionString);
            string rq2 = DateManager.ServerDateTimeByDBType(db2).ToShortDateString() + " 23:59:59";

            db2.Close();
            db2.Dispose();
            Hjcs = int.Parse(zq.Zqhjcs);
            string msg = "";

            _voice.InitializeVoiceLib();
            _voice.VoiceSpeak(zq.Zqname, ref msg);
            IPEndPoint address = new IPEndPoint(IPAddress.Any, port);

            while (true)
            {
                try
                {
                    if (new SystemCfg(3103).Config == "1")
                    {
                        UpdateDisplayDelegate callDisplay = new UpdateDisplayDelegate(UpdateDisplay);
                        callDisplay("正在等待呼叫。。。", zq.Zqid, _DataBase);
                    }
                    if (listener != null)
                    {
                        if (listener.LocalEndPoint == null)
                        {
                            listener.Bind(address);
                        }
                    }

                    listener.Listen(0);
                    socket = listener.Accept();
                    Stream netStream = new NetworkStream(socket);

                    StreamReader reader = new StreamReader(netStream);
                    string       result = reader.ReadToEnd();//收到呼叫的信息
                    lock (objLockHelper)
                    {
                        ts_mzys_class.MZHS_FZJL p   = new ts_mzys_class.MZHS_FZJL();
                        System.Xml.XmlDocument  doc = new System.Xml.XmlDocument();
                        bool valid = false;
                        try
                        {
                            doc.LoadXml(result);
                            valid = true;
                        }
                        catch
                        {
                            UpdateDisplayDelegate _callDisplay = new UpdateDisplayDelegate(UpdateDisplay);
                            _callDisplay("无效的呼叫信息!", zq.Zqid, _DataBase);
                        }
                        if (valid)
                        {
                            System.Xml.XmlNodeList nodes = doc.GetElementsByTagName("PATIENT")[0].ChildNodes;
                            /*反射生成病人对象*/
                            foreach (System.Xml.XmlNode node in nodes)
                            {
                                try
                                {
                                    System.Reflection.PropertyInfo pi = p.GetType().GetProperty(node.Name); //定义一个属性对象,并且设置类型(需要反射目的对象的某个属性名称)
                                    object objValue = Convert.ChangeType(node.InnerText, pi.PropertyType);  //通过一个object对象获取属性的值与属性的类型
                                    p.GetType().GetProperty(node.Name).SetValue(p, objValue, null);         //对反射对象进行赋值,第一个参数为反射对象,第二参数为反射对象所需的值与类型信息
                                }
                                catch
                                {
                                    continue;
                                }
                            }
                            lstCalledPatient.Insert(0, p);
                            //将当前呼叫的病人发送到显示窗口
                            if (refreshScreenDisplay != null)
                            {
                                int sort = 0;
                                RelationalDatabase dbTemp = new MsSqlServer();
                                dbTemp.Initialize(_DataBase.ConnectionString);
                                int hour = Convert.ToInt32(dbTemp.GetDataResult("select DATEPART(hh, GETDATE())"));
                                dbTemp.Close();
                                dbTemp.Dispose();
                                if (hour >= 8 && hour <= 12)
                                {
                                    sort = 1;
                                }
                                else if (hour > 12 && hour < 18)
                                {
                                    sort = 2;
                                }
                                RelationalDatabase dbTemp2 = new MsSqlServer();
                                dbTemp2.Initialize(_DataBase.ConnectionString);
                                DataSet ds = MZHS_FZJL.Select_yfzpat(zq.Zqid, rq1, rq2, 0, "", "", sort, dbTemp2);//得到最新的候诊列表
                                dbTemp2.Close();
                                dbTemp2.Dispose();
                                List <MZHS_FZJL> _list = new List <MZHS_FZJL>();
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    _list.Add(MZHS_FZJL.DataRowToFZjl(dr));
                                }
                                refreshScreenDisplay(p, _list);
                            }
                            CallPatient(lstCalledPatient);
                        }
                    }
                }
                catch (Exception ea)
                {
                    writelog("SocketListen方法发生错误:" + ea.Message);
                }
            }
        }