コード例 #1
0
        private void ConfirmInvoice_Click(object sender, RoutedEventArgs e)
        {
            if (BuyerClass.SelectedForInvoice != null && BuyerClass.SelectedForInvoice.Count > 0)
            {
                FC_Invoice invTemp = PlannerClass.GenerateInvoice(BuyerClass.SelectedForInvoice[0]);
                PlannerClass.InsertInvoice(invTemp, BuyerClass.SelectedForInvoice[0]);
                PlannerClass.UpdateContratState(BuyerClass.SelectedForInvoice[0], 4);

                BuyerClass.SelectedForInvoice.Remove(BuyerClass.SelectedForInvoice[0]);

                foreach (FC_LocalContract c in BuyerClass.SelectedForInvoice)
                {
                    PlannerClass.AddContractToInvoices(invTemp, c);
                    PlannerClass.UpdateContratState(c, 4);
                }


                InvoiceForFileSystem fsIn = new InvoiceForFileSystem(invTemp);


                try
                {
                    string invoiceDir = Directory.GetCurrentDirectory() + "\\Invoices";

                    FileInfo fi = new FileInfo(invoiceDir);
                    if (fi.Exists == false)
                    {
                        Directory.CreateDirectory(invoiceDir);
                    }

                    string filePath = "\\invoice_" + fsIn.FC_InvoiceID + ".txt";

                    /// Open the filestream to append to the file.
                    FileStream   fileStream = new FileStream(invoiceDir + filePath, FileMode.Create, FileAccess.Write);
                    StreamWriter fileWriter = new StreamWriter(fileStream);

                    /// Add each log entry from the working list to the file as a BSV
                    fileWriter.WriteLine(fsIn.ToString());
                    fileWriter.Flush();

                    /// Close the file
                    fileWriter.Close(); fileStream.Close();
                }
                /// If an exception is thrown here, catch it
                catch (Exception ex)
                {
                    TMSLogger.LogIt("|" + "/InvoiceSelection.xaml.cs" + "|" + "InvoiceSelection" + "|" + "ConfirmInvoice_Click" + "|" + ex.GetType().ToString() + "|" + ex.Message + "|");
                }
                BuyerPage newpage = new BuyerPage();
                this.NavigationService.Navigate(newpage);
            }
        }