public static string CreatePalletForceInvoice()
        {
            System.Web.SessionState.HttpSessionState currentSession = HttpContext.Current.Session;

            string       retVal       = string.Empty;
            string       userID       = !string.IsNullOrEmpty(currentSession[vs_userID].ToString()) ? currentSession[vs_userID].ToString() : string.Empty;
            int          invoiceID    = -1;
            int?         preInvoiceID = (int?)currentSession[vs_preInvoiceID];
            eInvoiceType?invoiceType  = (eInvoiceType?)currentSession[vs_preInvoiceType];

            if (preInvoiceID.HasValue && preInvoiceID.Value > 0 && invoiceType != null && userID != string.Empty)
            {
                Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice();

                List <int> preInvoiceIDs = new List <int>();
                preInvoiceIDs.Add(preInvoiceID.Value);

                List <Entities.PreInvoice> preInvoices = facPreInvoice.GetPreInvoices(preInvoiceIDs);

                if (preInvoices != null && preInvoices.Count > 0)
                {
                    try
                    {
                        Entities.PreInvoice currentPreInvoice = preInvoices[0];
                        invoiceID = facPreInvoice.CreateInvoice(currentPreInvoice, userID);

                        if (invoiceID > 0)
                        {
                            facPreInvoice.DeletePreInvoice(currentPreInvoice.PreInvoiceID);
                        }
                    }
                    catch (Exception ex)
                    {
                        retVal = RetrieveErrorMessages(ex);
                    }
                }
            }
            else
            {
                retVal = string.Format("{0}|{1}", 1, "There was an error retrieving the preinvoice details. Please reload the page and try again.");
            }

            return(retVal);
        }
        private void ConfigureDisplay()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["pfID"]))
            {
                PreInvoiceID = int.Parse(Request.QueryString["pfID"]);
            }

            if (PreInvoiceID > 0)
            {
                Facade.IPalletForceImportPreInvoice facPFiii = new Facade.PreInvoice();
                Facade.IPreInvoice facPreInvoice             = new Facade.PreInvoice();

                Entities.PalletForceImportedInvoice pfImportedInvoice = facPFiii.GetImportedInvoiceForPreInvoiceID(PreInvoiceID);
                Entities.PreInvoice preInvoice = facPreInvoice.GetPreInvoice(PreInvoiceID);

                preInvoiceDate = pfImportedInvoice.InvoiceDate;
                preInvoiceNo   = pfImportedInvoice.InvoiceNo;
                preInvoiceType = pfImportedInvoice.InvoiceType;

                lblSystemItemTotal.Text = preInvoice.NetAmount.ToString("C", ci);

                UploadedFileExtension = Path.GetExtension(pfImportedInvoice.Filename);
                UploadedFileName      = Path.GetFileName(pfImportedInvoice.Filename);
                UploadedFilePath      = pfImportedInvoice.Filename;

                UploadedFileDetails.Style["display"] = "";
                UploadInvoiceFile.Style["display"]   = "none";
            }

            DisplayFileDetails();

            RebindGrid();
            UserID = ((Entities.CustomPrincipal)Page.User).UserName;

            // Define button visibilty.
            // If the pre-invoice has been created allow removal.
            btnRemove.Visible = btnRemove1.Visible = PreInvoiceID > 0;
            // If the pre-invoice has been created and all items are matched, allow creation.
            btnApprove.Visible = btnApprove1.Visible = PreInvoiceID > 0 && UnMatchedItems == 0;
        }