Esempio n. 1
0
        void InfoSyncThread()
        {
            bool UpdateBaseRes = false;
            bool UpdateUserRes = false;
            bool UploadRes     = false;

            //设置各个访问页面
            LoginURL             = "http://" + SysConfig.Setting.serverIP + "/login";
            KnowledgeDownloadURL = "http://" + SysConfig.Setting.serverIP + "/database/download";
            UserInfoDownloadURL  = "http://" + SysConfig.Setting.serverIP + "/firemen/download";
            LogUploadURL         = "http://" + SysConfig.Setting.serverIP + "/event/record";

            //先登录服务器
            int LoginRes = HttpHelper.LoginServer(LoginURL, SysConfig.Setting.accessAccount, SysConfig.Setting.accessPassword);

            if (LoginRes == 2)                  //若登录服务器成功
            {
                //写入网络登录Web记录到日志文件中
                worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.Login, "1"));

                #region  载知识库和设备库
                try
                {
                    if (UpdateBaseResStartFlag)                                 //若开启了 下载知识库和设备库 功能
                    {
                        //1. 先下载知识库和设备库 压缩包
                        if (HttpHelper.DownloadFile(KnowledgeDownloadURL, @"./res/tmp/KnowledgeFile.zip"))                              //若下载成功
                        {
                            //2. 写入网络下载文件记录到日志文件中
                            worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.NetDownloadFile, "KnowledgeFile.zip"));

                            //3. 解压压缩包
                            ZipHelper.UnZip(@"./res/tmp/KnowledgeFile.zip", @"./res/tmp");

                            /*  处理救援知识库  */
                            //4. 删除原有的目录
                            if (Directory.Exists(@"./res/KnowledgeBase/SrcFiles/同步库"))
                            {
                                Directory.Delete(@"./res/KnowledgeBase/SrcFiles/同步库", true);
                            }
                            if (Directory.Exists(@"./res/KnowledgeBase/HtmlFiles/同步库"))
                            {
                                Directory.Delete(@"./res/KnowledgeBase/HtmlFiles/同步库", true);
                            }

                            if (Directory.Exists(@"./res/tmp/KnowledgeFile/救援知识库"))                                     //若下载下来的文件中存在知识库
                            {
                                //5. 移动目录
                                Directory.Move(@"./res/tmp/KnowledgeFile/救援知识库", @"./res/KnowledgeBase/SrcFiles/同步库");
                                //6. 重新加载知识库
                                lock (m_SyncContext) { m_SyncContext.Send(LoadKnowledgeBase, null); }
                            }
                            else
                            {
                                //5. 重新创建目录
                                Directory.CreateDirectory(@"./res/KnowledgeBase/SrcFiles/同步库");
                                //6. 重新加载知识库
                                lock (m_SyncContext) { m_SyncContext.Send(LoadKnowledgeBase, null); }
                            }

                            /*  处理设备器械库  */
                            //4. 删除原有的目录
                            if (Directory.Exists(@"./res/DeviceBase/SrcFiles/同步库"))
                            {
                                Directory.Delete(@"./res/DeviceBase/SrcFiles/同步库", true);
                            }
                            if (Directory.Exists(@"./res/DeviceBase/HtmlFiles/同步库"))
                            {
                                Directory.Delete(@"./res/DeviceBase/HtmlFiles/同步库", true);
                            }

                            if (Directory.Exists(@"./res/tmp/KnowledgeFile/设备器械库"))                                     //若下载下来的文件中存在设备库
                            {
                                //5. 移动目录
                                Directory.Move(@"./res/tmp/KnowledgeFile/设备器械库", @"./res/DeviceBase/SrcFiles/同步库");
                                //6. 重新加载设备库
                                lock (m_SyncContext) { m_SyncContext.Send(LoadDeviceBase, null); }
                            }
                            else
                            {
                                //5. 重新创建目录
                                Directory.CreateDirectory(@"./res/DeviceBase/SrcFiles/同步库");
                                //6. 重新加载设备库
                                lock (m_SyncContext) { m_SyncContext.Send(LoadDeviceBase, null); }
                            }


                            //7. 删除缓存文件
                            File.Delete(@"./res/tmp/KnowledgeFile.zip");
                            Directory.Delete(@"./res/tmp/KnowledgeFile", true);

                            UpdateBaseRes = true;
                        }
                        else
                        {
                            UpdateBaseRes = false;
                            //写入网络下载文件失败记录到日志文件中
                            worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.NetDownloadFileFail, "KnowledgeFile.zip,下载失败"));
                            m_SyncContext.Send(MessageBoxShow, new MessageBoxInfo("知识库下载失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error));
                            //MessageBox.Show("知识库下载失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        UpdateBaseRes = true;
                    }
                }
                catch (Exception ex)
                {
                    UpdateBaseRes = false;
                    Console.WriteLine(ex.Message);
                    log.Info(AppUtil.getExceptionInfo(ex));
                }
                #endregion

                #region  载用户Excel和头像
                try
                {
                    if (UpdateUserResStartFlag)                                         //若开启了 下载用户Excel和头像 功能
                    {
                        //1. 先下载知识库和设备库 压缩包
                        if (HttpHelper.DownloadFile(UserInfoDownloadURL, @"./res/tmp/UserTable.zip"))                           //若下载成功
                        {
                            //2. 写入网络下载文件记录到日志文件中
                            worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.NetDownloadFile, "UserTable.zip"));

                            //3. 删除原有的目录
                            if (Directory.Exists(@"./res/UserTable"))
                            {
                                Directory.Delete(@"./res/UserTable", true);
                            }

                            //4. 解压压缩包
                            ZipHelper.UnZip(@"./res/tmp/UserTable.zip", @"./res/tmp");

                            //5. 移动文件
                            Directory.Move(@"./res/tmp/UserInfo", @"./res/UserTable");


                            //6. 删除缓存文件
                            File.Delete(@"./res/tmp/UserTable.zip");                                                            //删除压缩包

                            //7. 重新加载用户信息表
                            lock (m_SyncContext) { m_SyncContext.Send(ReImportUserFromDefaultFile, null); }

                            UpdateUserRes = true;
                        }
                        else
                        {
                            UpdateUserRes = false;
                            //写入网络下载文件失败记录到日志文件中
                            worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.NetDownloadFileFail, "UserTable.zip,下载失败"));
                            m_SyncContext.Send(MessageBoxShow, new MessageBoxInfo("用户信息下载失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error));
                            //MessageBox.Show("用户信息下载失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        UpdateUserRes = true;
                    }
                }
                catch (Exception ex)
                {
                    UpdateUserRes = false;
                    Console.WriteLine(ex.Message);
                    log.Info(AppUtil.getExceptionInfo(ex));
                }
                #endregion

                #region   日志部分
                if (UploadResStartFlag)
                {
                    GetLatestLogName();                                 //获取最新日志名

                    // 开始上传
                    if (UploadLogFiles() && UploadPlayLogFiles())                               //上传日志文件
                    {
                        UploadRes = true;
                    }
                    else
                    {
                        UploadRes = false;
                        m_SyncContext.Send(MessageBoxShow, new MessageBoxInfo("日志上传失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error));
                        //MessageBox.Show("日志上传失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    UploadRes = true;
                }
                #endregion
            }
            else if (LoginRes == 1)             //若登录服务器失败
            {
                //写入网络登录记录到日志文件中
                worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.Login, "2"));
                m_SyncContext.Send(MessageBoxShow, new MessageBoxInfo("登录服务器失败, 账号或密码错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error));
                //MessageBox.Show("登录服务器失败, 账号或密码错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else                //若登录服务器失败
            {
                //写入网络登录记录到日志文件中
                worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.Login, "2"));
                m_SyncContext.Send(MessageBoxShow, new MessageBoxInfo("登录服务器失败, 网络错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error));
                //MessageBox.Show("登录服务器失败, 网络错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            #region 更新信息同步结果显示
            //更新信息同步结果显示
            if (UpdateBaseRes && UpdateUserRes && UploadRes)
            {
                InfoSyncResDisplay("成 功");
            }
            else
            {
                InfoSyncResDisplay("失 败");
            }
            #endregion

            isInfoSyncing = false;                              //信息同步线程结束了
        }
Esempio n. 2
0
        //上传回放日志文件的函数
        private bool UploadPlayLogFiles()
        {
            try
            {
                //解析最新文件的时间
                DateTime LatestTime         = DateTime.ParseExact(LatestPlayLogName.Split('+')[2].Replace(".csv", ""), "yyyyMMdd-HHmmss", CultureInfo.CurrentCulture); //最新文件的时间
                DateTime LatestTimeLevelOne = new DateTime(LatestTime.Year, LatestTime.Month, 1);                                                                      //最新文件一级目录的时间  年-月
                DateTime LatestTimeLevelTwo = new DateTime(LatestTime.Year, LatestTime.Month, LatestTime.Day);                                                         //最新文件二级目录的时间  年-月-日

                if (Directory.Exists(".\\res\\WorkLogPlay"))
                {
                    /*------ 处理一级目录 ------*/
                    string[] AllLevelOneDirs = Directory.GetDirectories(".\\res\\WorkLogPlay"); //获取所有一级目录 -- 年月
                    if (AllLevelOneDirs != null)                                                //若一级目录不为空
                    {
                        foreach (string LevelOneDir in AllLevelOneDirs)                         //遍历还没上传的一级目录
                        {
                            DateTime LevelOneDir_Date = DateTime.ParseExact(Path.GetFileName(LevelOneDir), "yyyy-MM", CultureInfo.CurrentCulture);
                            if (DateTime.Compare(LatestTimeLevelOne, LevelOneDir_Date) <= 0)                                    //若最新文件比较早, 则需要上传
                            {
                                /*------ 处理二级目录 ------*/
                                string[] AllLevelTwoDirs = Directory.GetDirectories(LevelOneDir); //获取所有二级目录 -- 年-月-日
                                if (AllLevelTwoDirs != null)                                      //若二级目录不为空
                                {
                                    foreach (string LevelTwoDir in AllLevelTwoDirs)               //遍历还没上传的二级目录
                                    {
                                        DateTime LevelTwoDir_Date = DateTime.ParseExact(LevelOneDir_Date.Year.ToString() + "-" + Path.GetFileName(LevelTwoDir), "yyyy-MM-dd", CultureInfo.CurrentCulture);
                                        if (DateTime.Compare(LatestTimeLevelTwo, LevelTwoDir_Date) <= 0)                                                //若最新文件比较早, 则需要上传
                                        {
                                            /*------ 处理二级目录下所有的Log文件 ------*/
                                            string[] LogFilesPath = Directory.GetFiles(LevelTwoDir);                                                    //获取所有Log文件
                                            if (LogFilesPath != null)
                                            {
                                                foreach (string filePath in LogFilesPath)
                                                {
                                                    string aa = Path.GetFileName(filePath).Replace("Log", "").Replace(".csv", "");
                                                    //解析文件时间
                                                    DateTime LogFileDate = DateTime.ParseExact(Path.GetFileName(filePath).Split('+')[2].Replace(".csv", ""), "yyyyMMdd-HHmmss", CultureInfo.CurrentCulture);
                                                    if (DateTime.Compare(LatestTime, LogFileDate) < 0)                                                          //当前Log文件为未上传的
                                                    {
                                                        if (filePath != worklogplay.filePath)                                                                   //不上传正在写入的文件
                                                        {
                                                            //上传该文件
                                                            Console.WriteLine("上传文件:" + filePath);

                                                            if (HttpHelper.UploadFile(LogUploadURL, filePath))                                                                          //若上传成功, 则更新最新文件名
                                                            {
                                                                SetLatestLogName(1, Path.GetFileNameWithoutExtension(filePath));
                                                                //写入工作日志
                                                                worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.NetUploadFile, Path.GetFileName(filePath)));
                                                            }
                                                            else                                                                                                                                //否则重传一次
                                                            {
                                                                if (HttpHelper.UploadFile(LogUploadURL, filePath))                                                                              //若重传上传成功, 则更新最新文件名
                                                                {
                                                                    SetLatestLogName(1, Path.GetFileNameWithoutExtension(filePath));
                                                                    //写入工作日志
                                                                    worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.NetUploadFile, Path.GetFileName(filePath)));
                                                                }
                                                                else
                                                                {
                                                                    //写入工作日志
                                                                    worklog.LogQueue_Enqueue(LogCommand.getNetRecord(NetRecordType.NetUploadFileFail, Path.GetFileName(filePath) + ",上传失败"));
                                                                    return(false);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                log.Info(AppUtil.getExceptionInfo(ex));
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
 //返回按钮响应事件
 void btnInfoSyncReturn_Click(object sender, EventArgs e)
 {
     PanelSwitch(CurPanel.EpanelSysSetting);
     //写入按钮点击记录
     worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.InfoSyncPanel, (int)BtnOfInfoSyncPanel.InfoSyncReturn, null));
 }
Esempio n. 4
0
        /*
         * 根据接收的byte数组更新终端的实时信息, array1[]为16字节的参数(此函数在主线程中执行)
         * 返回true表示更新成功, 否则更新失败(未找到匹配的终端)
         * 与主线程同步执行
         */
        void UpdateTerInfoByBytes(object array)
        {
            if (!isPlayBackMode)                //若不是回放模式
            {
                byte[] array1 = (byte[])array;
                if (AppUtil.bytesToInt(array1, 1, 3) == SysConfig.Setting.groupNumber)                          //若组号匹配
                {
                    int index = 255;
                    for (int i = 0; i < users.Count; i++)
                    {
                        if (users[i].BasicInfo.terminalNO == (byte)array1[4])
                        {
                            index = i;
                            break;
                        }
                    }

                    if (index != 255)                                   //若找到了匹配的终端
                    {
                        //改变标志
                        users[index].isChanged  = true;
                        users[index].isRecvPack = true;
                        //压力, 单位为MPa
                        users[index].TerminalInfo.Pressure = User.GetPressDoubleByBytes(array1, 5);
                        //电压, 单位为V
                        users[index].TerminalInfo.Voltage = User.GetVoltageDoubleByBytes(array1, 7);
                        //温度
                        users[index].TerminalInfo.Temperature = array1[9];// User.GetTemeratureIntByByte(array1[9]);
                        //开机时间
                        users[index].TerminalInfo.PowerONTime = User.GetTimeIntByBytes(array1, 10);
                        //状态
                        users[index].TerminalInfo.TerminalStatus = array1[15];

                        //计算剩余时间
                        double A        = 0;                           //由30s下降值计算出来的时间
                        double B        = 0;                           //由气压值计算出来的时间
                        bool   isAvalid = false;                       //计算的A值是否有效标志: 若30s内无下降, 则计算出来的置为A无效
                        if (users[index].TerminalInfo.Pressure <= 2.0) //若当前气压小于2, 则计算的结果肯定是负数, 则将A和B都置0, 剩余时间当做0
                        {
                            A = 0;
                            B = 0;
                        }
                        else                                                                                                                    //若当前气压大于2, 则需要计算A 和 B, 取小的那一个
                        {
                            //计算A  ----  由30s下降值计算出来的时间
                            if (users[index].TerminalInfo.PressDropDownIn30s > 0)                               //若30s内气压值是下降的, 则可以计算A
                            {
                                isAvalid = true;
                                A        = (users[index].TerminalInfo.Pressure - 2) / (users[index].TerminalInfo.PressDropDownIn30s * 2);                               //由30s下降值计算出来的时间
                            }
                            else
                            {
                                A        = 0;
                                isAvalid = false;
                            }

                            //计算B  ----  由气压值计算出来的时间
                            if (users[index].BasicInfo.terminalCapSpec == "6.8")                                        //6.8L的气瓶
                            {
                                B = (users[index].TerminalInfo.Pressure - 2) * 6.8 * 10 / 50;
                            }
                            else if (users[index].BasicInfo.terminalCapSpec == "9")                                     //9L的气瓶
                            {
                                B = (users[index].TerminalInfo.Pressure - 2) * 9 * 10 / 50;
                            }
                        }
                        //更新剩余时间, 取A、B中小的一方
                        if (A < B)
                        {
                            if (isAvalid)                               //若A有效, 则取A, 否则取B
                            {
                                users[index].TerminalInfo.RemainTime = (int)A;
                            }
                            else
                            {
                                users[index].TerminalInfo.RemainTime = (int)B;
                            }
                        }
                        else
                        {
                            users[index].TerminalInfo.RemainTime = (int)B;
                        }

                        //若用户状态不是撤出中, 则更改用户状态
                        if (users[index].UStatus != USERSTATUS.RetreatingStatus)
                        {
                            if (users[index].TerminalInfo.Pressure > 10)                                                        //安全状态
                            {
                                users[index].UStatus = USERSTATUS.SafeStatus;
                            }
                            else if (users[index].TerminalInfo.Pressure > 6)                                                    //轻度危险
                            {
                                users[index].UStatus = USERSTATUS.MildDangerousStatus;
                            }
                            else
                            {
                                users[index].UStatus = USERSTATUS.DangerousStatus;                                              //危险状态
                            }
                        }
                        else                                    //否则更新气压
                        {
                            users[index].UStatus = USERSTATUS.RetreatingStatus;
                        }

                        //若当前详情窗口显示的是本用户, 则更新详情窗口的显示
                        if (users[index] == detailsForm.CurUser)
                        {
                            detailsForm.UpdateDetailForm();
                        }

                        //判断是否报警
                        //若终端不是关机、不存在状态, 则需要设置其报警状态
                        if (users[index].UStatus != USERSTATUS.NoExistStatus && users[index].UStatus != USERSTATUS.PowerOffStatus)
                        {
                            try
                            {
                                users[index].AlarmFlagForLost = false;
                                bool IsUserExceedTh = false;    //用户是否超出阈值标识

                                //1. 分析用户是否超阈值, 存储在标志IsUserExceedTh中
                                if (SysConfig.Setting.alarmThreshold == 0)                                         //若设定阈值为气瓶容量的50%
                                {
                                    double terminalCapSpec = double.Parse(users[index].BasicInfo.terminalCapSpec); //获取气瓶容量
                                    if (users[index].TerminalInfo.Pressure < (terminalCapSpec / 2.0))              //若小于气瓶容量的50%--超出阈值
                                    {
                                        IsUserExceedTh = true;                                                     //用户超阈值
                                    }
                                    else
                                    {
                                        IsUserExceedTh = false;                                         //没有超出阈值
                                    }
                                }
                                else if (SysConfig.Setting.alarmThreshold == 1)    //若设定阈值为10MPa
                                {
                                    if (users[index].TerminalInfo.Pressure < 10.0) //若小于10MPa--超出阈值
                                    {
                                        IsUserExceedTh = true;                     //用户超阈值
                                    }
                                    else                                           //没有超出阈值
                                    {
                                        IsUserExceedTh = false;                    //没有超出阈值
                                    }
                                }
                                else if (SysConfig.Setting.alarmThreshold == 2)   //若设定阈值为6MPa
                                {
                                    if (users[index].TerminalInfo.Pressure < 6.0) //若小于6MPa--超出阈值
                                    {
                                        IsUserExceedTh = true;                    //用户超阈值
                                    }
                                    else                                          //没有超出阈值
                                    {
                                        IsUserExceedTh = false;                   //没有超出阈值
                                    }
                                }

                                //2. 更新当前用户的"超阈值报警标志"
                                if (IsUserExceedTh)                                             //若用户超阈值
                                {
                                    if (users[index].IsExceedThreshold == false)                //若上一次没有超过阈值, 但本次超出阈值, 则开启"超阈值报警"
                                    {
                                        users[index].AlarmFlagForExceedTh = true;
                                    }
                                    else                                                                                                                        //若上一次超过阈值, 且本次继续超出阈值, 则不去处理
                                    {
                                    }
                                }
                                else                                                                    //若用户没有超阈值
                                {
                                    if (users[index].IsExceedThreshold == true)                         //若上一次超过阈值, 但本次没有超出阈值, 则停止"超阈值报警"
                                    {
                                        users[index].AlarmFlagForExceedTh = false;
                                    }
                                    else                                                                                                                        //若上一次没有超过阈值, 且本次继续没有超出阈值, 则不去处理
                                    {
                                    }
                                }

                                //3. 更新用户超阈值标志
                                users[index].IsExceedThreshold = IsUserExceedTh;
                            }
                            catch (Exception ex) { Console.WriteLine(ex.Message); }
                        }

                        //写入用户状态记录到日志文件中
                        worklog.LogQueue_Enqueue(LogCommand.getUserStatusRecord(users[index]));
                        //写入用户状态记录到回放日志文件中
                        //worklogplay.LogPlayQueue_Enqueue(LogPlayCommand.getUserStatusRecord(users[index]));
                        //若开启了实时上传 且 服务器已连接, 则上传到服务器
                        if (isRealTimeUploading && netcom.isConnected && isAuthPass && isInternetAvailiable)                            //若网络连接正常 且 验证通过 且 服务器在线
                        {
                            //netcom.NetSendQueue_Enqueue(NetCommand.NetUploadUserPacket(users[index]));
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        //确认临时编组按钮点击事件
        void btnTempGroupOK_Click(object sender, EventArgs e)
        {
            //先判断用户输入的格式对不对
            //检查原组号是否是数字
            if (RegexUtil.RegexCheckNumber(richTextTempOldGrpNO.Text))
            {
                //检查原组号是否超出范围
                if (int.Parse(richTextTempOldGrpNO.Text) < 0xFFFFFF)
                {
                    //检查新组号是否是数字
                    if (RegexUtil.RegexCheckNumber(richTextTempNewGrpNO.Text))
                    {
                        //检查新组号是否超出范围
                        if (int.Parse(richTextTempNewGrpNO.Text) < 0xFFFFFF)
                        {
                            //检查原用户号是否是数字
                            if (RegexUtil.RegexCheckNumber(richTextTempOldDevNO.Text))
                            {
                                //检查原用户号是否超出范围
                                if (int.Parse(richTextTempOldDevNO.Text) < 33)
                                {
                                    //检查新用户号是否是数字
                                    if (RegexUtil.RegexCheckNumber(richTextTempNewDevNO.Text))
                                    {
                                        //检查新用户号是否超出范围
                                        if (int.Parse(richTextTempNewDevNO.Text) < 33)
                                        {
                                            //全部检查完毕没有问题
                                            richTextTempGroupStatus.Text = "";                                                          //状态栏清空
                                            TempGrpOldSerialNO           = (int.Parse(richTextTempOldGrpNO.Text) << 8) | (int.Parse(richTextTempOldDevNO.Text));
                                            TempGrpNewSerialNO           = (int.Parse(richTextTempNewGrpNO.Text) << 8) | (int.Parse(richTextTempNewDevNO.Text));

                                            //发送临时组队命令
                                            SerialSendMsg sendMsg = ProtocolCommand.BuildTeamCmdMsg(AppUtil.IntToBytes(TempGrpOldSerialNO),
                                                                                                    AppUtil.IntToBytes(TempGrpNewSerialNO),
                                                                                                    SysConfig.getSerialNOBytes());
                                            serialCom.SendQueue_Enqueue(sendMsg);                                               //发送出去
                                            //写入按钮点击记录
                                            worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.TempGrpPanel, (int)BtnOfTempGrpPanel.StartTempGrp, TempGrpOldSerialNO.ToString("X8") + " " + TempGrpNewSerialNO.ToString("X8")));
                                        }
                                        else
                                        {
                                            MessageBox.Show("新用户号必须小于33");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("新用户号必须为数字形式");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("原用户号必须小于33");
                                }
                            }
                            else
                            {
                                MessageBox.Show("原用户号必须为数字形式");
                            }
                        }
                        else
                        {
                            MessageBox.Show("新组号必须小于16777215");
                        }
                    }
                    else
                    {
                        MessageBox.Show("新组号必须为数字形式");
                    }
                }
                else
                {
                    MessageBox.Show("原组号必须小于16777215");
                }
            }
            else
            {
                MessageBox.Show("原组号必须为数字形式");
            }
        }
Esempio n. 6
0
        //添加按钮点击事件
        void btnDeviceBaseAdd_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode = treeViewDeviceBase.SelectedNode;
            TreeNode ParentNode   = null;
            string   savePath     = null;

            if (selectedNode != null)                           //选中了节点
            {
                string path = ((string[])selectedNode.Tag)[0];  //源文件全路径
                // 若选中的节点在同步库中, 则将其改为本地库
                if (path.Contains("\\res\\DeviceBase\\SrcFiles\\同步库"))
                {
                    foreach (TreeNode node in rootNodeDeviceBase.Nodes)
                    {
                        if (node.Text == "本地库")
                        {
                            ParentNode = node;
                        }
                    }
                    savePath = ((string[])rootNodeDeviceBase.Tag)[0] + "\\本地库";
                }
                else
                {
                    if (Directory.Exists(path))
                    {
                        savePath = path; ParentNode = selectedNode;
                    }                                                                                                                                           //如果选中的是目录, 则保存路径就是当前目录
                    else
                    {
                        savePath = ((string[])selectedNode.Parent.Tag)[0]; ParentNode = selectedNode.Parent;
                    }                                                                                                                   //如果选中的是文件, 则保存路径就是当前文件的目录
                }
            }
            else                                                                //如果没有选中, 则保存路径就是本地库目录
            {
                foreach (TreeNode node in rootNodeDeviceBase.Nodes)
                {
                    if (node.Text == "本地库")
                    {
                        ParentNode = node;
                    }
                }
                savePath = ((string[])rootNodeDeviceBase.Tag)[0] + "\\本地库";
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "Word|*.docx|Word|*.doc";
            openFileDialog.FilterIndex      = 0;
            openFileDialog.RestoreDirectory = true;                                     //保存对话框是否记忆上次打开的目录
            openFileDialog.Title            = "添加文件";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (AppUtil.CopyFileTo(openFileDialog.FileName, savePath))                      //若拷贝文件成功
                {
                    string   filePath    = savePath + "\\" + Path.GetFileName(openFileDialog.FileName);
                    TreeNode subFileNode = new TreeNode(Path.GetFileNameWithoutExtension(filePath));
                    subFileNode.Tag                = GetTagPath(Path.GetFullPath(filePath));
                    subFileNode.ImageIndex         = 1;
                    subFileNode.SelectedImageIndex = 1;
                    ParentNode.Nodes.Add(subFileNode);
                    //写入按钮点击记录到日志文件中
                    worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.DeviceBasePanel, (int)BtnOfDeviceBasePanel.AddBtn, openFileDialog.FileName));
                }
            }
        }
Esempio n. 7
0
        /*
         * 改变用户状态, terminalNO为终端号
         * 与主线程同步执行
         */
        public void ChangeUserState(object statusPara1)
        {
            UserStatusPara statusPara = (UserStatusPara)statusPara1;
            int            index      = 255;

            if (!isPlayBackMode)                //若不是回放模式
            {
                for (int i = 0; i < users.Count; i++)
                {
                    if (users[i].BasicInfo.terminalNO == (int)(statusPara.teriminalNO))
                    {
                        index = i;
                        break;
                    }
                }
                if (index != 255)                               //找到匹配的终端
                {
                    users[index].UStatus = statusPara.status;
                    //改变标志
                    users[index].isChanged = true;

                    //若当前详情窗口显示的是本用户, 则更新详情窗口的显示
                    if (users[index] == detailsForm.CurUser)
                    {
                        detailsForm.Update();
                    }

                    //判断用户是否需要报警
                    if (users[index].UStatus == USERSTATUS.LoseContactStatus)                                   //失去联系需要报警
                    {
                        users[index].AlarmFlagForLost = true;
                        users[index].isRecvPack       = false;
                    }
                    else if (users[index].UStatus == USERSTATUS.RetreatFailStatus)                      //撤出失败需要报警
                    {
                        users[index].AlarmFlagForRetreat = true;
                        users[index].isRecvPack          = false;
                    }
                    else if (users[index].UStatus == USERSTATUS.PowerOffStatus)                                 //撤出失败需要清除报警标志和超出阈值标志
                    {
                        users[index].IsExceedThreshold    = false;
                        users[index].AlarmFlagForExceedTh = false;
                        users[index].AlarmFlagForLost     = false;
                        users[index].AlarmFlagForRetreat  = false;
                        users[index].isRecvPack           = true;
                    }
                    else                                                                                                                                        //否则将失去联系与撤出失败报警标志清除
                    {
                        users[index].AlarmFlagForLost    = false;
                        users[index].AlarmFlagForRetreat = false;
                        users[index].isRecvPack          = true;
                    }

                    //写入用户状态记录到日志文件中
                    worklog.LogQueue_Enqueue(LogCommand.getUserStatusRecord(users[index]));
                    //写入用户状态记录到回放日志文件中
                    //worklogplay.LogPlayQueue_Enqueue(LogPlayCommand.getUserStatusRecord(users[index]));
                    //上传到服务器
                    if (isRealTimeUploading && netcom.isConnected && isAuthPass && isInternetAvailiable)                        //若网络连接正常 且 验证通过 且 服务器在线
                    {
                        //netcom.NetSendQueue_Enqueue(NetCommand.NetUploadUserPacket(users[index]));
                    }
                }
            }
        }
Esempio n. 8
0
 //返回按钮点击事件
 void btnDeviceBaseReturn_Click(object sender, EventArgs e)
 {
     PanelSwitch(CurPanel.EpanelContentMain);
     //写入按钮点击记录到日志文件中
     worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.DeviceBasePanel, (int)BtnOfDeviceBasePanel.DeviceBaseReturn, null));
 }
Esempio n. 9
0
 //用户列表 按钮
 void btnSysSetCheckUser_Click(object sender, EventArgs e)
 {
     PanelSwitch(CurPanel.EpanelCheckUser);
     //写入按钮点击记录
     worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.SysSettingPanel, (int)BtnOfSysSettingPanel.CheckUser, null));
 }
Esempio n. 10
0
        //导入用户 按钮
        void btnSysSetImport_Click(object sender, EventArgs e)
        {
            List <UserBasicInfo> userList = null;
            int            SuccessCnt     = 0;                                  //导入成功的文件数目
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "Excel,JPG,PNG|*.xlsx;*.xls;*.jpg;*.jpeg;*.png";
            openFileDialog.FilterIndex      = 0;
            openFileDialog.RestoreDirectory = true;                                     //保存对话框是否记忆上次打开的目录
            openFileDialog.Multiselect      = true;
            openFileDialog.InitialDirectory = Application.StartupPath + @"\res\UserTable";
            openFileDialog.Title            = "导入用户配置文件";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog.FileNames != null)
                {
                    string[] filesPath = openFileDialog.FileNames;
                    foreach (string filePath in filesPath)
                    {
                        if (Path.GetExtension(filePath).Contains("xlsx") || Path.GetExtension(filePath).Contains("xls")) //若是excel文件
                        {
                            userList = userRW.ReadUserInfoFile(openFileDialog.FileName);                                 //读取导入文件中的用户
                            if (userList != null)
                            {
                                //删除当前所有用户
                                for (int i = users.Count - 1; i >= 0; i--)
                                {
                                    RemoveUserAt(i);
                                }
                                if (userList.Count > 0)
                                {
                                    foreach (UserBasicInfo userInfo in userList)
                                    {
                                        AddUser(userInfo);
                                    }
                                }
                                //更新默认用户文件
                                userRW.SaveUserInfoFile(userRW.DefaultUserFileName, users);

                                //写入按钮点击记录
                                worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.SysSettingPanel, (int)BtnOfSysSettingPanel.ImportUsers, openFileDialog.FileName));
                                //写入用户全部更新记录
                                worklog.LogQueue_Enqueue(LogCommand.getUserUpdateRecord(1, users, null));
                                SuccessCnt++;
                            }
                        }
                        else                                                       //若是图像文件
                        {
                            if (AppUtil.CopyFileTo(filePath, ".\\res\\UserTable")) // 直接将其拷贝到用户目录下
                            {
                                SuccessCnt++;
                            }
                        }
                    }
                    if (SuccessCnt == 0)
                    {
                        MessageBox.Show("导入失败");
                    }
                    else if (SuccessCnt < filesPath.Length)
                    {
                        MessageBox.Show("部分导入成功");
                    }
                    else
                    {
                        MessageBox.Show("导入成功");
                    }
                }
            }
        }
Esempio n. 11
0
 //修改组号
 void btnSysSetGrpNOOK_Click(object sender, EventArgs e)
 {
     if (richTextSysSetGrpNO.Enabled == true)
     {
         //验证组号格式是否正确(即是否是小于16777215的纯数字)
         if (RegexUtil.RegexCheckNumber(richTextSysSetGrpNO.Text))
         {
             int GrpNO = int.Parse(richTextSysSetGrpNO.Text);
             if ((GrpNO > 0) && (GrpNO < 16777215))
             {
                 richTextSysSetGrpNO.Text      = GrpNO.ToString("D8");
                 richTextSysSetGrpNO.Enabled   = false;
                 SysConfig.Setting.groupNumber = GrpNO;
                 labelGrpNumber.Text           = "组号:" + SysConfig.Setting.groupNumber.ToString("D8");
                 SysConfig.SaveSystemSetting(SysConfig.Setting);
                 //写入组号修改记录
                 worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.SysSettingPanel, (int)BtnOfSysSettingPanel.ChangeGrpNO, richTextSysSetGrpNO.Text));
                 isSerialShouldOpen = true;
             }
             else
             {
                 MessageBox.Show("请输入小于16777215的组号");
             }
         }
         else
         {
             MessageBox.Show("请输入正确的组号格式");
         }
         //验证信道格式是否正确(即是否是小于30的纯数字)
         if (RegexUtil.RegexCheckNumber(richTextSysSetChannal.Text))
         {
             int Channal = int.Parse(richTextSysSetChannal.Text);
             if ((Channal > 0) && (Channal < 30) && (Channal < 23 || Channal > 25))
             {
                 richTextSysSetChannal.Text    = Channal.ToString("D8");
                 richTextSysSetChannal.Enabled = false;
                 SysConfig.Setting.channal     = Channal;
                 labelChannel.Text             = "信道:" + SysConfig.Setting.channal.ToString("D2");
                 SysConfig.SaveSystemSetting(SysConfig.Setting);
                 //写入组号修改记录
                 //worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.SysSettingPanel, (int)BtnOfSysSettingPanel.ChangeGrpNO, richTextSysSetGrpNO.Text));
                 isSerialShouldOpen = true;
                 //串口通信配置
                 //string comName = AppUtil.FindComByKeyStr(ComKeyStr);		//查找包含关键字的COM号
                 if (SysConfig.Setting.serialCom != null)
                 {
                     if (serialCom.ComOpen(SysConfig.Setting.serialCom, SerialBaudLUT[SysConfig.Setting.serialBaud]))//若打开串口成功
                     {
                         //写入串口连接记录到日志文件中
                         worklog.LogQueue_Enqueue(LogCommand.getSerialRecord(SerialRecordType.Connect, null));
                         serialCom.SendQueue_Enqueue(ProtocolCommand.SwitchChannelMsg((byte)(SysConfig.Setting.channal)));  //切换信道
                     }
                 }
                 else
                 {
                     MessageBox.Show("打开串口失败!");
                 }
             }
             else
             {
                 MessageBox.Show("请输入小于30的信道号 并且不为 23 24 25");
             }
         }
         else
         {
             MessageBox.Show("请输入正确的组号格式");
         }
     }
 }
Esempio n. 12
0
 //确认改号按钮点击事件
 void btnUserChangeNOOK_Click(object sender, EventArgs e)
 {
     //先判断用户输入的格式对不对
     //检查原组号是否是数字
     if (RegexUtil.RegexCheckNumber(richTextOldGrpNO.Text))
     {
         //检查原组号是否超出范围
         if (int.Parse(richTextOldGrpNO.Text) < 0xFFFFFF)
         {
             //检查新组号是否是数字
             if (RegexUtil.RegexCheckNumber(richTextNewGrpNO.Text))
             {
                 //检查新组号是否超出范围
                 if (int.Parse(richTextNewGrpNO.Text) < 0xFFFFFF)
                 {
                     //检查原用户号是否是数字
                     if (RegexUtil.RegexCheckNumber(richTextOldDevNO.Text))
                     {
                         //检查原用户号是否超出范围
                         if (int.Parse(richTextOldDevNO.Text) < 33)
                         {
                             //检查新用户号是否是数字
                             if (RegexUtil.RegexCheckNumber(richTextNewDevNO.Text))
                             {
                                 //检查新用户号是否超出范围
                                 if (int.Parse(richTextNewDevNO.Text) < 33)
                                 {
                                     //检查信道号是否是数字
                                     if (RegexUtil.RegexCheckNumber(richTextNewChannal.Text))
                                     {
                                         ChangeNONewChannal = int.Parse(richTextNewChannal.Text);
                                         //检查信道号是否超出范围
                                         if (ChangeNONewChannal < 31 && (ChangeNONewChannal < 23 || ChangeNONewChannal > 25))
                                         {
                                             //全部检查完毕没有问题
                                             richTextUserChangeNOStatus.Text = "";       //状态栏清空
                                             ChangeNOOldSerialNO             = (int.Parse(richTextOldGrpNO.Text) << 8) | (int.Parse(richTextOldDevNO.Text));
                                             ChangeNONewSerialNO             = (int.Parse(richTextNewGrpNO.Text) << 8) | (int.Parse(richTextNewDevNO.Text));
                                             ChangeNONewSerialNO_forChannal  = ChangeNONewSerialNO;                                                //发送临时组队命令
                                             SerialSendMsg sendMsg = ProtocolCommand.ParaSetup1CmdMsg(AppUtil.IntToBytes(ChangeNOOldSerialNO), AppUtil.IntToBytes(ChangeNONewSerialNO));
                                             //发送切换信道命令
                                             serialCom.SendQueue_Enqueue(sendMsg);                  //发送出去
                                             ChangeNONewChannal = int.Parse(richTextNewChannal.Text);
                                             Thread th = new Thread(new ThreadStart(ThreadSwitch)); //创建线程
                                             th.Start();                                            //启动线程
                                             //写入按钮点击记录
                                             worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.UserChangeNOPanel, (int)BtnOfUserChangeNOPanel.StartChangeNO, ChangeNOOldSerialNO.ToString("X8") + " " + ChangeNONewSerialNO.ToString("X8")));
                                         }
                                         else
                                         {
                                             MessageBox.Show("信道必须小于30,切不能为23 24 25");
                                         }
                                     }
                                     else
                                     {
                                         MessageBox.Show("信道必须是数字");
                                     }
                                 }
                                 else
                                 {
                                     MessageBox.Show("新用户号必须小于33");
                                 }
                             }
                             else
                             {
                                 MessageBox.Show("新用户号必须为数字形式");
                             }
                         }
                         else
                         {
                             MessageBox.Show("原用户号必须小于33");
                         }
                     }
                     else
                     {
                         MessageBox.Show("原用户号必须为数字形式");
                     }
                 }
                 else
                 {
                     MessageBox.Show("新组号必须小于16777215");
                 }
             }
             else
             {
                 MessageBox.Show("新组号必须为数字形式");
             }
         }
         else
         {
             MessageBox.Show("原组号必须小于16777215");
         }
     }
     else
     {
         MessageBox.Show("原组号必须为数字形式");
     }
 }