예제 #1
0
        private void bgwUpdateDTDrivers_DoWork(object sender, DoWorkEventArgs e)
        {
            var lbValidate  = false;
            var tokenSource = new CancellationTokenSource();

            try
            {
                if (DtSelectedDate < DateTime.Today)
                {
                    DialogResult lcValidationResult = MessageBox.Show("Are you sure you want to update drivers for a date prior the current date?\r\nPlease press YES to continue.", "Action Confirmation Request", MessageBoxButtons.YesNo);
                    if (lcValidationResult == DialogResult.Yes)
                    {
                        lbValidate = true;
                    }
                }
                else
                {
                    DialogResult lcValidationResult = MessageBox.Show("Drivers information will be send to Dispatch Track for " + DtSelectedDate.ToString("MM/dd/yyyy") + ".\r\nPlease press YES to continue.", "Action Confirmation Request", MessageBoxButtons.YesNo);
                    if (lcValidationResult == DialogResult.Yes)
                    {
                        lbValidate = true;
                    }
                }
                if (lbValidate == true)
                {
                    DataAccess dataAccess  = new DataAccess();
                    string     processCode = ProcessCode.DRIVERS.ToString();
                    int        currentProcessId;
                    if (dataAccess.CreateProcess(processCode, out currentProcessId))
                    {
                        var token = tokenSource.Token;
                        RunProcessLogs(token, processCode, currentProcessId);

                        CFDispatchTrackApplicationSettings loAppSettings = new CFDispatchTrackApplicationSettings();
                        string apiHost          = loAppSettings.Get("DispatchTrackAPIHost");
                        string apiPort          = loAppSettings.Get("DispatchTrackAPIPort");
                        string apiImportDrivers = loAppSettings.Get("DispatchTrackUpdateDrivers");
                        string requestDate      = DtSelectedDate.ToString("yyyyMMdd");
                        string url = apiHost + (apiPort.Trim().Length > 0 ? ":" + apiPort : "") + apiImportDrivers + requestDate + "/" + currentProcessId;

                        string reply = NodeAPI.UpdateDriversInformation(url);
                        //MessageBox.Show(reply);
                        MessageBox.Show("Update Drivers process complete.");
                    }
                    else
                    {
                        MessageBox.Show("Error while creating the process.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            Thread.Sleep(1000);
            tokenSource.Cancel();  //this change the value of token.IsCancellationRequested from 'false' to 'true', stopping the while loop in method ProcessLogs
        }
예제 #2
0
        private void bgwImportOrders_DoWork(object sender, DoWorkEventArgs e)
        {
            var lbValidate  = false;
            var tokenSource = new CancellationTokenSource();

            if (DtSelectedDate < DateTime.Today)
            {
                DialogResult lcValidationResult = MessageBox.Show("Are you sure you want to request AS400 orders for a date prior current date?", "Action Confirmation Request", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification);
                if (lcValidationResult == DialogResult.Yes)
                {
                    lbValidate = true;
                }
            }
            else
            {
                lbValidate = true;
            }

            DataAccess dataAccess = new DataAccess();

            try
            {
                bool stopExport;
                if (dataAccess.CheckWaveExportedtoAS400Already(DtSelectedDate, importingWaveDesc) == "BAD")
                {
                    DialogResult lcValidationRes = MessageBox.Show("WARNING - WARNING - WARNING\n\nThe orders for the selected Date and Wave have been exported to the AS400 already.\n\nContinuing the process will add - change - delete data in/from Dispatch Track that is not included in this batch.\n\nAre you sure you want to procedd?\n\nPress 'Yes' to continue if you are sure that is correct, 'No' to cancel export process.", "WARNING - Action Confirmation Request", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification);
                    stopExport = (lcValidationRes != DialogResult.Yes);
                    if (stopExport)
                    {
                        lbValidate = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                lbValidate = false;
            }

            if (lbValidate == true)
            {
                try
                {
                    bool stopExport;
                    if (dataAccess.CheckLockStatus(DtSelectedDate, importingWave))
                    {
                        DialogResult lcValidationRes = MessageBox.Show("Orders for selected wave/date has been exported to Dispatch Track before.\\nPlease make sure routes and time windows are locked in Dispatch Track before exporting again.\\nPress 'Yes' to continue if routes are locked, 'No' to cancel export process and check out routes in Dispatch Track.", "Action Confirmation Request", MessageBoxButtons.YesNo);
                        stopExport = (lcValidationRes != DialogResult.Yes);
                        if (stopExport)
                        {
                            lbValidate = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    lbValidate = false;
                }
            }

            if (lbValidate == true)
            {
                try
                {
                    string processCode = ProcessCode.IMPORT.ToString();
                    int    currentProcessId;
                    if (dataAccess.CreateProcess(processCode, out currentProcessId))
                    {
                        var token = tokenSource.Token;
                        RunProcessLogs(token, processCode, currentProcessId);

                        bgwImportOrders.ReportProgress(20);
                        cmdImportOrders.Enabled = false;
                        Cursor.Current          = Cursors.WaitCursor;

                        CFDispatchTrackApplicationSettings loAppSettings = new CFDispatchTrackApplicationSettings();
                        string apiHost         = loAppSettings.Get("DispatchTrackAPIHost");
                        string apiPort         = loAppSettings.Get("DispatchTrackAPIPort");
                        string apiImportOrders = "";
                        string url             = "";
                        string date            = DtSelectedDate.ToString("yyyyMMdd");
                        string warehouseId     = int.Parse(sessionsValues.First(cdr => cdr["sessionid_pk"].ToString() == importingWave)["cfwh_id"].ToString()).ToString();
                        //string warehouseId = ((int)Enum.Parse(typeof(Warehouse), Warehouse.TAMARAC.ToString())).ToString();
                        apiImportOrders = loAppSettings.Get("DispatchTrackImportOrders");
                        //if (this.chkNoRegularInvoices.Checked == false)
                        //    url = apiHost + ":" + apiPort + apiImportOrders + warehouseId + "/" + date + "/" + importingWave + "/ALL/" + currentProcessId;
                        //else
                        //    url = apiHost + ":" + apiPort + apiImportOrders + warehouseId + "/" + date + "/" + importingWave + "/NRI/" + currentProcessId ;
                        if (chkNoRegularInvoices.Checked)
                        {
                            url = apiHost + (apiPort.Trim().Length > 0 ? ":" + apiPort : "") + apiImportOrders + warehouseId + "/" + date + "/" + importingWave + "/NRI/" + currentProcessId;
                        }
                        else if (chkOnlyTransfers.Checked)
                        {
                            url = apiHost + (apiPort.Trim().Length > 0 ? ":" + apiPort : "") + apiImportOrders + warehouseId + "/" + date + "/" + importingWave + "/TRA/" + currentProcessId;
                        }
                        else
                        {
                            url = apiHost + (apiPort.Trim().Length > 0 ? ":" + apiPort : "") + apiImportOrders + warehouseId + "/" + date + "/" + importingWave + "/ALL/" + currentProcessId;
                        }

                        bgwImportOrders.ReportProgress(25);

                        HttpResponseMessage aSyncResponse;

                        bool res = NodeAPI.UploadOrdersData(url, out aSyncResponse);

                        Cursor.Current = Cursors.Default;
                        Thread.Sleep(1000);
                        if (!res)
                        {
                            tokenSource.Cancel();
                            MessageBox.Show("Unsuccessful call to node.js api. Reason Phrase: " + aSyncResponse.ReasonPhrase);
                        }
                        else
                        {
                            bgwImportOrders.ReportProgress(100);
                            tokenSource.Cancel();
                            MessageBox.Show("Orders successfully imported.");
                        }
                    }
                    else
                    {
                        tokenSource.Cancel();
                        MessageBox.Show("Error while creating the process.");
                    }
                }
                catch (Exception error)
                {
                    //MessageBox.Show(error.ToString());
                    //MessageBox.Show(error.Message.ToString());
                    //MessageBox.Show("No Orders Found to Import");
                    tokenSource.Cancel();
                    MessageBox.Show("No Orders Found to Import", "Import Orders from AS400", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //Text, caption
                }
            }
            //Thread.Sleep(1000);
            //tokenSource.Cancel();  //this change the value of token.IsCancellationRequested from 'false' to 'true', stopping the while loop in method ProcessLogs
            tokenSource.Dispose();
        }