private void UpdateNCFile(object sender, EventArgs e) { if (!_view.Connected) { MessageBox.Show("Please connect Machine!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int retValueInt = 0; if (!string.IsNullOrEmpty(_view.FilePath)) { ProgramTransferSrv srv = new ProgramTransferSrv(_view.IpAddress); string fileName = System.IO.Path.GetFileName(_view.FilePath); //string strDel = srv.DeleteProgram("0", fileName); string str = srv.UploadCNCProgram(0, _view.FilePath, out retValueInt); //var result = srv.GetProgramList(); MessageBox.Show(str, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); GetProgramList(null, null); } else { MessageBox.Show("Please select NC file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public async Task <Boolean> TransferNcFileService() { return(await Task.Factory.StartNew(() => { bool transferCompleted = false; var taskUploadNc = _repoJob.GetReadyToTransferNC(); if (taskUploadNc != null) { bool uploadFlag = false; string resultMessage = string.Empty; string strBasePath = Application.StartupPath + "\\NCFiles\\" + taskUploadNc.JobNumber + "\\" + taskUploadNc.TaskNumber; string strFilePath = strBasePath + "\\" + taskUploadNc.NcFile; string NewFile = ReplaceNCFile(strFilePath, strBasePath); int retValueInt = 0; if (!string.IsNullOrEmpty(NewFile)) { var machine = _repoMachine.GetByCode(taskUploadNc.MachineNoReady); if (machine != null) { ProgramTransferSrv srv = new ProgramTransferSrv(machine.IpAddress); string fileName = Path.GetFileName(NewFile); resultMessage = srv.UploadCNCProgram(0, NewFile, out retValueInt); if (retValueInt == 0)//EW_OK = Upload file Successfully. { uploadFlag = true; } else if (retValueInt == 5) { try { resultMessage = srv.DeleteProgram("0", fileName); resultMessage = srv.UploadCNCProgram(0, NewFile, out retValueInt); } catch { uploadFlag = false; retValueInt = -1; resultMessage = "Data is protected."; } if (retValueInt == 0) { uploadFlag = true; } else { uploadFlag = false; } } else { uploadFlag = false; } } else { uploadFlag = false; resultMessage = "Get Machine Address is null."; } } else { uploadFlag = false; resultMessage = "Cannot replace NC file."; } taskUploadNc.TransferNCFileToMachineFlag = uploadFlag; taskUploadNc.TransferMessage = resultMessage; _repoJob.UpdateTask(taskUploadNc); } return transferCompleted; })); }