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; * */ }
private void allOfWork() { while (threadRunFlag) { Thread.Sleep(1000); string sDir = ""; if (!Directory.Exists(m_DataPathStr))//如果设定的目录不存在,就使用当前程序工作路径进行保存 { sDir = System.Environment.CurrentDirectory + "\\Data\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyyMM") + "\\" + DateTime.Today.Date.ToString("yyyyMMdd"); } else { sDir = m_DataPathStr + "\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyyMM") + "\\" + DateTime.Today.Date.ToString("yyyyMMdd"); } //writeMsg(sDir); if (!Directory.Exists(sDir)) //如果文件夹不存在 { Directory.CreateDirectory(sDir); //创建文件夹,\Data\2012\201211\20121101 } try { if (usbDiskDic.Count >= 0) { foreach (MDUsb usbItem in usbDiskDic.Values) //遍历整个usb队列 { if (MDUsbPos.isComplate(usbItem.driverName) || !threadRunFlag) //如果数据已经拷贝完成,就不要再查看了 { continue; } int uploadSuccessFileNum = 1; //从当前U盘获取一个文件 foreach (string usbFileName in usbItem.getFileList()) { LogManager.WriteLog(usbItem.driverName + " 盘 开始数据拷贝: "); //string f1 = FFMpegUtility.getMediaInfo(@"h:\99999920121203091619.mp4");//获取文件信息 //得到文件大小,并且判断当前拷贝磁盘是否够用 FileInfo fileInfo = new FileInfo(usbFileName); //不够用,提示清理文件 if (fileInfo.Length > getDiskFreeSpace(System.Environment.CurrentDirectory.Substring(0, 2))) { writeMsg("错误,磁盘空间不足,停止拷贝!"); Thread.Sleep(1000 * 60 * 10);//停止10分钟 //timer_usbDiskCopy.Enabled = true; break; } //够用,拷贝 string localFileName = sDir + usbFileName.Substring(usbFileName.LastIndexOf("\\")); writeMsg("正在拷贝数据: (" + uploadSuccessFileNum.ToString() + ")" + usbFileName); File.Copy(usbFileName, localFileName, true); //删除USB源文件 writeMsg("正在删除数据: " + usbFileName); File.Delete(usbFileName); if (m_UploadFlag)//如果要上传到服务器,就不能删除本地文件 { FtpList.Add(localFileName); } //else//不应在此删除数据,应该在上传到服务器完成后删除 //{ // writeMsg("正在删除数据: " + localFileName); // File.Delete(localFileName); //} //根据Name获得对应的控件对象,修改屏幕显示进度内容 int pos = MDUsbPos.getUsbPos(usbItem.driverName); string sCount = "label_count_" + pos.ToString(); System.Reflection.FieldInfo label2 = this.GetType().GetField(sCount);//反射 Label lableCount = (Label)label2.GetValue(this); lableCount.Text = uploadSuccessFileNum.ToString() + " / " + usbItem.getFileList().Length; lableCount.Refresh(); if (uploadSuccessFileNum >= usbItem.getFileList().Length) { string sPic = "pictureBox" + pos.ToString(); System.Reflection.FieldInfo pic1 = this.GetType().GetField(sPic); //反射 PictureBox pic = (PictureBox)pic1.GetValue(this); pic.BackgroundImage = MDWorkStation.Properties.Resources.b1; //绿色,代表已经上传完成 writeMsg(usbItem.driverName + " 盘 数据拷贝完成"); writeMsg(usbItem.getPoliceID() + " 编号 数据拷贝完成"); MDUsbPos.setComplated(usbItem.driverName);//数据完成了,所以不应该再使用它 break; } uploadSuccessFileNum++; //调用不成功,提示错误,结束 } } } } catch (Exception ex) { LogManager.WriteLog(ex.Message); continue; } } }