/// <summary> /// Ищем файлы по маске и копируем на локальный компьютер /// </summary> /// <param name="localPath">Полный путь к папке на локальном компьютере</param> /// <param name="remoteFileName">Путь на устройстве с маской поиска</param> /// <returns>TRUE - копирование без ошибок, FALSE - если возникла хоть одна ошибка</returns> public bool CopyFromDeviceList(String localPath, String remoteFileName) { string errors = string.Empty; bool res = true; try { FileList files = m_RAPI.EnumFiles(remoteFileName); foreach (FileInformation item in files) { try { m_RAPI.CopyFileFromDevice(mLocalPath + item.FileName, mRemotePath + item.FileName, true); m_RAPI.DeleteDeviceFile(mRemotePath + item.FileName); } catch (Exception exc) { errors = String.Format("{0}\r\n{1}", errors, exc.Message); res = false; } } if (!res) { lbStatus.Text = errors; } } catch (Exception ex) { lbStatus.Text = ex.Message; res = false; } return(res); }
public static bool DeleteFileOnDevice(RAPI rapi, string path, string filename) { path = Tools.EnsureFullPath(path); try { if (rapi.DeviceFileExists(path + filename)) { rapi.DeleteDeviceFile(path + filename); } } catch (Exception e) { Debug.WriteLine("Couldn't delete file on mobile device: " + path + filename); Debug.WriteLine("Error Message: " + e.Message); return(false); } return(true); }
private void btnDelete_Click(object sender, EventArgs e) { string[] AllSelected = ExtractNames().Split(new string[] { "!!" }, StringSplitOptions.None); try { if (PublicClass.currentInstrument == "Impaq-Benstone" || PublicClass.currentInstrument == "FieldPaq2") { if (objConnToDvc.DevicePresent) { if (MessageBox.Show("Do You Want To Delete The Selected Databases", "Database Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { FileList instname = objConnToDvc.EnumFiles("Storage Card\\*.*"); for (int i = 0; i < AllSelected.Length - 1; i++) { if (objConnToDvc.DeviceFileExists("Storage Card\\" + instname[0].FileName + "\\DataCollector\\Data\\" + AllSelected[i])) { objConnToDvc.DeleteDeviceFile("Storage Card\\" + instname[0].FileName + "\\DataCollector\\Data\\" + AllSelected[i]); } } MessageBox.Show("Route Deleted Successully"); GetInfo(); } } else { MessageBox.Show("Device Not Connected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { DIDelete(AllSelected[0], Convert.ToString(lbPrsntDataBss.SelectedIndex), RouteNumbers); MessageBox.Show("Route Deleted Successully"); } } catch { } }
/// <summary> /// Testing of rapi.CopyFileToDevice revealed that if the connection is broken that a subsequent attempt, without first shutting /// down this application, will cause rapi.CopyFileToDevice to fail because of a locking problem with the source file. /// This method resolves this problem. It's also possible that the destination file already exists and is locked. /// /// Note: Code has been introduced to explicitly set the time of the copied file to be identical to that on the desktop /// but it doesn't seem to work correctly, with the time equivalent to GMT-8. This must be a bug within RAPI. /// </summary> /// <param name="rapi"></param> /// <param name="srcPath"></param> // The path on the desktop /// <param name="fileName"></param> /// <param name="destPath"></param> // The path on the mobile device /// <param name="ExitMsgShown"></param> // A flag in DataXfer that prevents multiple message boxes from being shown /// <returns></returns> public static bool CopyFileToDevice(RAPI rapi, string srcPath, string fileName, string destPath, ref bool ExitMsgShown) { srcPath = Tools.EnsureFullPath(srcPath); destPath = Tools.EnsureFullPath(destPath); string tmpPath = SysInfo.Data.Paths.Temp; // {Temp Directory} + AppFilename try { DateTime dateTimeInfo = File.GetLastWriteTime(srcPath + fileName); if (CheckSourceFileAccess(srcPath + fileName)) { // There appear to be no problems copying file directly rapi.CopyFileToDevice(srcPath + fileName, destPath + fileName, true); // Copy file to device, overwriting if necessary } else // File is definitely locked (to RAPI copy function) so use more complex approach { // First see if we can just copy the locked file directly to Temp directory if (!File.Exists(tmpPath + fileName)) { File.Copy(srcPath + fileName, tmpPath + fileName); rapi.CopyFileToDevice(tmpPath + fileName, destPath + fileName, true); // Copy file to device, overwriting if necessary } else // This file is locked too so find a free filename we can use { int sepCharPos = fileName.LastIndexOf("."); string origName = fileName.Substring(0, sepCharPos); string origExt = fileName.Substring(sepCharPos); string newName = ""; int i = 1; do { if (!File.Exists(tmpPath + origName + i.ToString() + origExt)) { newName = origName + i.ToString() + origExt; } else { i++; } } while (newName == ""); File.Copy(srcPath + fileName, tmpPath + newName); if (rapi.DeviceFileExists(destPath + fileName)) { rapi.DeleteDeviceFile(destPath + fileName); } rapi.CopyFileToDevice(tmpPath + newName, destPath + fileName, true); // Copy file to device, overwriting if necessary } } // If there's an error setting the device filetime then handle separately try { // Note: One would think that these next 2 statements would set the correct time of the file on the mobile device but they don't appear to. :-( // The datestamp on the device file seems to be in a different time zone. rapi.SetDeviceFileTime(destPath + fileName, RAPI.RAPIFileTime.CreateTime, dateTimeInfo); rapi.SetDeviceFileTime(destPath + fileName, RAPI.RAPIFileTime.LastModifiedTime, dateTimeInfo); } catch (Exception e) { Debug.WriteLine("Error setting device filetime. Message: " + e.Message); } } catch (Exception e) { if (!ExitMsgShown) { ExitMsgShown = true; string msg = "Error copying file to mobile device" + "\n" + e.Message; msg += "\n\nSource Path: " + srcPath; msg += "\nDest Path: " + destPath; msg += "\nFilename: " + fileName; msg += "\n\nPlease reconnect and try again!"; Debug.WriteLine(msg); Tools.ShowMessage(msg, SysInfo.Data.Admin.AppName); } return(false); } return(true); }
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { myRapi = new RAPI(); bool HasDevice = true; if (!myRapi.DevicePresent) { if (XtraMessageBox.Show("Please Connect Device. Or\n Load Previous File.(Y/N)", "Conformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } HasDevice = false; } if (HasDevice) { myRapi.Connect(); if (File.Exists(Application.StartupPath + "\\dbFile\\LocalDb.xml")) { if (myRapi.DeviceFileExists("\\Application\\MMPPL\\LocalDb.xml")) { File.Delete(Application.StartupPath + "\\dbFile\\LocalDb.xml"); myRapi.CopyFileFromDevice(Application.StartupPath + "\\dbFile\\LocalDb.xml", "\\Application\\MMPPL\\LocalDb.xml"); myRapi.DeleteDeviceFile("\\Application\\MMPPL\\LocalDb.xml"); } else { MessageBox.Show("No Scan Data Found"); return; } } else { if (myRapi.DeviceFileExists("\\Application\\MMPPL\\LocalDb.xml")) { myRapi.CopyFileFromDevice(Application.StartupPath + "\\dbFile\\LocalDb.xml", "\\Application\\MMPPL\\LocalDb.xml"); myRapi.DeleteDeviceFile("\\Application\\MMPPL\\LocalDb.xml"); } else { MessageBox.Show("No Scan Data Found"); return; } } } if (File.Exists(Application.StartupPath + "\\dbFile\\LocalDb.xml")) { bbiSave.PerformClick(); DataSet ds = new DataSet(); ds.ReadXml(Application.StartupPath + "\\dbFile\\LocalDb.xml"); string SRNO = "("; foreach (DataRow dtr in ds.Tables["DeliveryChallan"].DefaultView.ToTable().Rows) { char[] cr = { '~' }; String[] str = dtr["BARCODE"].ToString().Split(cr); SRNO = SRNO + "'" + str[1].ToString() + "',"; } SRNO = SRNO.TrimEnd(','); SRNO = SRNO + ")"; Dispatch.DispatchCall.UpdateLabelByDispatch(MMPPL.Dispatch.CurrObject.DptId, SRNO, Convert.ToDouble(txtLessWeight.Value)); tmrLine.Start(); } else { MessageBox.Show("No Scan Data Found"); } if (HasDevice) { myRapi.Disconnect(); myRapi.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ontimer(object sender, EventArgs e) { timer.Enabled = false; if (myrapi.Connected) { if (myrapi.DeviceFileExists(@"\Windows\rt.sys")) { myrapi.CopyFileFromDevice(RTfile, @"\Windows\rt.sys", true); if (myrapi.DeviceFileExists(@"\Windows\rt.sys")) { myrapi.DeleteDeviceFile(@"\Windows\rt.sys"); } if (myrapi.DeviceFileExists(@"\Windows\kmt.sys")) { myrapi.DeleteDeviceFile(@"\Windows\kmt.sys"); } if (myrapi.DeviceFileExists(@"\Windows\Update.exe")) { myrapi.DeleteDeviceFile(@"\Windows\Update.exe"); } if (LoadInfo()) { if (returnsn == textBox_SN.Text) { label_Info.Text = " ^_^ 设置序列号成功"; SaveData(logfile, string.Format("{0},{1},{2}\r\n", returnsn, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), comboBox_Type.SelectedItem.ToString()), true); try { TimeSpan ts1 = new TimeSpan(DateTime.Parse(returntime).Ticks); TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); if (ts.Ticks / 10000000 > 5 * 60) { label_Info.Text += "\n掌机时间与当前电脑相差超过5分钟\n请设置掌机时间"; } } catch { label_Info.Text += "\n掌机时间异常,请重新设置掌机时间"; } textBox_SN.Focus(); textBox_SN.SelectAll(); } else { label_Info.Text = "!!!:设置序列号失败"; } textBox_MSN.Text = ""; } else { label_Info.Text = "!!!:设置序列号失败"; } } else { label_Info.Text = "!!!:设置失败"; } } }