Ejemplo n.º 1
0
        private void ValidateLogIn(object sender, RoutedEventArgs e)
        {
            bool loginSuccess = false;

            if ((password.Password != "") && (username.SelectedIndex != -1))
            {
                // Get login connection
                if (loginSuccess == false)
                {
                    SQL.SetUserID(username.Text.ToLower());
                    SQL.SetPassWord(password.Password.ToString());

                    SQL.init();
                    loginSuccess = SQL.open();
                }
                if (loginSuccess == true)
                {
                    if (username.Text == "Admin")
                    {
                        AdminPage newpage = new AdminPage();
                        this.NavigationService.Navigate(newpage);
                    }
                    else if (username.Text == "Buyer")
                    {
                        BuyerPage newpage = new BuyerPage();
                        this.NavigationService.Navigate(newpage);
                    }
                    else if (username.Text == "Planner")
                    {
                        PlannerPage newpage = new PlannerPage();
                        this.NavigationService.Navigate(newpage);
                    }
                }
            }
        }
        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);
            }
        }