private void setUsbInfoToScreen(string diskName, bool isShow)
        {
            string currentDriverName = diskName;
            int    pos = -1;

            //根据盘符获得磁盘信息,并且将此对象放入队列待用
            MDUsb usbDiskObject = new MDUsb();

            if (isShow)//插入U盘
            {
                if (getDiskInfo(currentDriverName, usbDiskObject))
                {
                    usbDiskDic.Add(currentDriverName, usbDiskObject);//将插入U盘对象放入容器
                    writeMsg(usbDiskObject.getDiskInfoStrirng());
                    writeMsg(diskName + " 盘 成功载入");
                }
                else
                {
                    writeMsg(diskName + " 盘 内容读取失败!");
                    return;
                }


                //  获得当前U盘对应的屏幕位置
                pos = MDUsbPos.getUsbPos(currentDriverName);
            }
            else//U盘拔出
            {
                if (usbDiskDic.ContainsKey(currentDriverName))
                {
                    usbDiskObject = usbDiskDic[currentDriverName];//取出对应的元素
                    //  获得当前U盘对应的屏幕位置
                    pos = MDUsbPos.getUsbPos(currentDriverName);
                    MDUsbPos.setDisconnect(currentDriverName);//拔出时清空数据
                    usbDiskDic.Remove(currentDriverName);
                }

                if (pos < 0)
                {
                    return;
                }

                writeMsg(diskName + " 盘已经拔出");
            }


            //修改屏幕上的lable信息-------------------------------------------------------



            //根据Name获得对应的控件对象
            string sID    = "label_id_" + pos.ToString();;
            string sCount = "label_count_" + pos.ToString();
            string sPic   = "pictureBox" + pos.ToString();

            System.Reflection.FieldInfo label1 = this.GetType().GetField(sID);    //反射
            System.Reflection.FieldInfo label2 = this.GetType().GetField(sCount); //反射
            System.Reflection.FieldInfo pic1   = this.GetType().GetField(sPic);   //反射

            Label      lableID    = (Label)label1.GetValue(this);
            Label      lableCount = (Label)label2.GetValue(this);
            PictureBox pic        = (PictureBox)pic1.GetValue(this);


            if (isShow)
            {
                //计算当前U盘的文件个数,并且将文件列表放入当前usb对象的队列
                int count = usbDiskObject.calcFileCountAndAdd(m_FilePrefixString, m_FileExtString);



                lableCount.Text    = "0 / " + count.ToString();// 0 / 999
                lableCount.Visible = true;
                lableCount.Refresh();


                //  获得当前U盘的设备ID

                //lableID.Text = usbDiskObject.getDeviceID();// 设备ID: 99999
                //lableID.Text = "编号: " + usbDiskObject.getPoliceID();// 警员编号ID: 99999
                lableID.Text = "编号 " + usbDiskObject.getDeviceID();// 设备编号ID: A000022
                string id1 = usbDiskObject.getPoliceID();
                string id2 = usbDiskObject.getDataTime();
                lableID.Visible = true;
                lableID.Refresh();


                //设置设备颜色为蓝色
                pic.BackgroundImage = MDWorkStation.Properties.Resources.b3;

                if (usbDiskObject.getFileCount() <= 0)//如果usb中没有文件,则设置成绿色
                {
                    pic.BackgroundImage = MDWorkStation.Properties.Resources.b1;
                }
                pic.Refresh();
            }
            else
            {
                lableCount.Visible  = lableID.Visible = false;
                pic.BackgroundImage = MDWorkStation.Properties.Resources.b2;//灰色
                pic.Refresh();
            }

            //修改屏幕上的lable信息 end-------------------------------------------------------

            return;

            /*
             *
             * if (bFirstRun)//只运行一次
             *  StartIdle();
             *
             * return;
             *
             *
             * if (bFirstRun)
             * {
             *
             *
             *  worker.DoWork += new DoWorkEventHandler(worker_DoWork);
             *  worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
             *  worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
             *
             *  bFirstRun = false;
             *
             *  return;
             *
             * }
             *
             * return;
             * */
        }
Exemple #2
0
        private void setUsbInfoToScreen(string diskName, bool isShow)
        {
            string currentDriverName = diskName;
            int pos = -1;

            //根据盘符获得磁盘信息,并且将此对象放入队列待用
            MDUsb usbDiskObject = new MDUsb();
            if (isShow)//插入U盘
            {
                if (getDiskInfo(currentDriverName, usbDiskObject))
                {

                    usbDiskDic.Add(currentDriverName, usbDiskObject);//将插入U盘对象放入容器
                    writeMsg(usbDiskObject.getDiskInfoStrirng());
                    writeMsg(diskName + " 盘 成功载入");
                }
                else
                {
                    writeMsg(diskName + " 盘 内容读取失败!");
                    return;
                }


                //  获得当前U盘对应的屏幕位置
                pos = MDUsbPos.getUsbPos(currentDriverName);

            }
            else//U盘拔出
            {
                if( usbDiskDic.ContainsKey(currentDriverName) )
                {
                    usbDiskObject = usbDiskDic[currentDriverName];//取出对应的元素
                    //  获得当前U盘对应的屏幕位置
                    pos = MDUsbPos.getUsbPos(currentDriverName);
                    MDUsbPos.setDisconnect(currentDriverName);//拔出时清空数据                    
                    usbDiskDic.Remove(currentDriverName);
                    
                }

                if (pos < 0)
                    return;

                writeMsg(diskName + " 盘已经拔出");

            }


            //修改屏幕上的lable信息-------------------------------------------------------

            

            //根据Name获得对应的控件对象
            string sID = "label_id_" + pos.ToString(); ;
            string sCount = "label_count_" + pos.ToString();
            string sPic = "pictureBox" + pos.ToString();
            System.Reflection.FieldInfo label1 = this.GetType().GetField(sID);//反射
            System.Reflection.FieldInfo label2 = this.GetType().GetField(sCount);//反射
            System.Reflection.FieldInfo pic1 = this.GetType().GetField(sPic);//反射

            Label lableID = (Label)label1.GetValue(this);
            Label lableCount = (Label)label2.GetValue(this);
            PictureBox pic = (PictureBox)pic1.GetValue(this);


            if (isShow)
            {



                //计算当前U盘的文件个数,并且将文件列表放入当前usb对象的队列
                int count = usbDiskObject.calcFileCountAndAdd(m_FilePrefixString, m_FileExtString);


                
                lableCount.Text = "0 / " + count.ToString();// 0 / 999
                lableCount.Visible = true;
                lableCount.Refresh();


                //  获得当前U盘的设备ID
                
                //lableID.Text = usbDiskObject.getDeviceID();// 设备ID: 99999
                //lableID.Text = "编号: " + usbDiskObject.getPoliceID();// 警员编号ID: 99999
                lableID.Text = "编号 " + usbDiskObject.getDeviceID();// 设备编号ID: A000022
                string id1 = usbDiskObject.getPoliceID();
                string id2 = usbDiskObject.getDataTime();
                lableID.Visible = true;
                lableID.Refresh();


                //设置设备颜色为蓝色
                pic.BackgroundImage = MDWorkStation.Properties.Resources.b3;

                if (usbDiskObject.getFileCount() <= 0)//如果usb中没有文件,则设置成绿色
                {
                    pic.BackgroundImage = MDWorkStation.Properties.Resources.b1;
                }
                pic.Refresh();
            }
            else
            {
                lableCount.Visible = lableID.Visible = false;
                pic.BackgroundImage = MDWorkStation.Properties.Resources.b2;//灰色
                pic.Refresh();

            }

            //修改屏幕上的lable信息 end-------------------------------------------------------

            return;

            /*

            if (bFirstRun)//只运行一次
                StartIdle();

            return;


            if (bFirstRun)
            {


                worker.DoWork += new DoWorkEventHandler(worker_DoWork);
                worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
                worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

                bFirstRun = false;

                return;

            }

            return;
             * */

            
        }