private void DeleteProg(object sender, EventArgs e)
        {
            if (!_view.Connected)
            {
                MessageBox.Show("Please connect Machine!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DataGridView grd = sender as DataGridView;

            if (grd.SelectedRows.Count > 0)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure to delete program", "Please confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    foreach (DataGridViewRow item in grd.SelectedRows)
                    {
                        try
                        {
                            ProgramListDet     line   = (ProgramListDet)item.DataBoundItem;
                            ProgramTransferSrv srv    = new ProgramTransferSrv(_view.IpAddress);
                            string             strDel = srv.DeleteProgram("0", line.ProgNo);
                            MessageBox.Show(strDel, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            GetProgramList(null, null);
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }
        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;
            }));
        }