예제 #1
0
        private void bwPostAudit_DoWork(object sender, DoWorkEventArgs e)
        {
            CommonDatabaseContext dataContext = CreateCommonDatabaseContext();

            ADS.beginTransactionBlock();
            InventoryAuditProcedures.PostAudit(ADS.ActiveAudit, dataContext);

            if (!dataContext.Result)
            {
                ADS.endTransactionBlock(EndTransactionType.ROLLBACK);
            }
            else
            {
                ADS.endTransactionBlock(EndTransactionType.COMMIT);
            }

            e.Result = dataContext;
        }
예제 #2
0
        private void DownloadFiles()
        {
            ProcessingMessage = new ProcessingMessage("Retrieving upload files", 0);
            ProcessingMessage.Show();
            try
            {
                string tmpPath       = Path.Combine(Application.StartupPath, "tmp");
                string trakkerPath   = Path.Combine(tmpPath, "uptrak");
                string trakkerIdPath = Path.Combine(tmpPath, "trakker.id");

                if (!Directory.Exists(tmpPath))
                {
                    Directory.CreateDirectory(tmpPath);
                }

                FtpHelper ftpHelper = new FtpHelper(FtpHost, FtpUser, FtpPassword);
                ftpHelper.DownloadFile("tmp_" + ADS.ActiveAudit.StoreNumber + "/uptrak", trakkerPath, false);
                ftpHelper.DownloadFile("tmp_" + ADS.ActiveAudit.StoreNumber + "/trakker.id", trakkerIdPath, false);

                string[] fileContents = File.ReadAllLines(trakkerIdPath);

                if (fileContents.Length == 0 || string.IsNullOrWhiteSpace(fileContents[0]))
                {
                    ProcessingMessage.Close();
                    throw new ApplicationException("trakker.id file is empty");
                }

                int trakkerId = Utilities.GetIntegerValue(fileContents[0].Substring(fileContents[0].IndexOf('|') + 1), 0);

                ProcessingMessage.Hide();
                ConfirmTrakker confirmTrakker = new ConfirmTrakker(trakkerId);
                if (confirmTrakker.ShowDialog() == DialogResult.Cancel)
                {
                    ProcessingMessage.Close();
                    return;
                }
                ProcessingMessage.Show();

                TrakkerFileReader  trakkerFileReader = new TrakkerFileReader(trakkerPath);
                List <TrakkerItem> uploadedItems     = trakkerFileReader.ReadFile();

                int count = 0;
                if (uploadedItems.Count > 0)
                {
                    ADS.beginTransactionBlock();
                    foreach (TrakkerItem item in uploadedItems)
                    {
                        count++;
                        ProcessingMessage.Message = string.Format("Uploading record {0} of {1}", count, uploadedItems.Count);
                        CommonDatabaseContext dataContext = new CommonDatabaseContext();

                        InventoryAuditProcedures.UploadTrakkerItem(item, ADS.ActiveAudit.AuditId, trakkerId, ADS.ActiveAudit.StoreNumber, dataContext);

                        if (!dataContext.Result)
                        {
                            ADS.endTransactionBlock(EndTransactionType.ROLLBACK);
                            MessageBox.Show(dataContext.ErrorText);
                            return;
                        }
                    }
                    ADS.endTransactionBlock(EndTransactionType.COMMIT);
                }

                ProcessingMessage.Close();
                ChangeStatusMessage2("Records Uploaded from Trakker " + trakkerId);
                ChangeStatusValue2(uploadedItems.Count.ToString());
                Uploaded = true;
            }
            catch (Exception exc)
            {
                ProcessingMessage.Close();
                BasicExceptionHandler.Instance.AddException("Failed to upload trakker files", exc);
                MessageBox.Show(exc.Message);
            }
        }