Exemplo n.º 1
0
        public void EPT_BatchImport()
        {
            int size = EntityTest.BATCH_IMPORT_DATA_SIZE;

            var repo = RF.ResolveInstance <InvoiceRepository>();

            using (RF.TransactionScope(repo))
            {
                var list = new InvoiceList();
                for (int i = 0; i < size; i++)
                {
                    var item = new Invoice();
                    list.Add(item);
                }
                repo.CreateImporter().Save(list);

                list.Clear();
                repo.CreateImporter().Save(list);

                Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");

                using (PhantomContext.DontFilterPhantoms())
                {
                    Assert.AreEqual(repo.CountAll(), size, "幽灵状态的实体,可以使用特定 API 查出。");
                    var all2 = repo.GetAll();
                    Assert.AreEqual(all2.Count, size, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                }
            }
        }
        /// <summary>
        /// Retrieves list of Invoice objects from SqlCommand, after database query
        /// number of rows retrieved and returned depends upon the rows field value
        /// </summary>
        /// <param name="cmd">The command object to use for query</param>
        /// <param name="rows">Number of rows to process</param>
        /// <returns>A list of Invoice objects</returns>
        private InvoiceList GetList(SqlCommand cmd, long rows)
        {
            // Select multiple records
            SqlDataReader reader;
            long          result = SelectRecords(cmd, out reader);

            //Invoice list
            InvoiceList list = new InvoiceList();

            using ( reader )
            {
                // Read rows until end of result or number of rows specified is reached
                while (reader.Read() && rows-- != 0)
                {
                    Invoice invoiceObject = new Invoice();
                    FillObject(invoiceObject, reader);

                    list.Add(invoiceObject);
                }

                // Close the reader in order to receive output parameters
                // Output parameters are not available until reader is closed.
                reader.Close();
            }

            return(list);
        }
Exemplo n.º 3
0
        private void NewInvoice()
        {
            if (Validator.ValidateAll().IsValid)
            {
                if (order.Id == 0)
                {
                    order = UnitOfWork.Orders.Add(order);
                }

                var vm = new InvoiceCreationViewModel(new UnitOfWorkFactory());
                vm.Init();
                var windowView = new InvoiceCreationView(vm);

                if (windowView.ShowDialog() ?? false)
                {
                    var    invoiceNumber = vm.InvoiceNumber;
                    var    amount        = double.Parse(vm.Amount);
                    string fileName;
                    try
                    {
                        fileName = FileAccess.CreateDocumentFromTemplate(order.Customer, invoiceNumber, Properties.Settings.Default.InvoiceTemplatePath);
                    }
                    catch (Win32Exception)
                    {
                        MessageBox.Show("Das Dokument konnte nicht erstellt werden. Eventuell haben Sie die Vorlage noch geöffnet.", "Ein Fehler ist aufgetreten");
                        return;
                    }

                    var document = new Document
                    {
                        IssueDate    = DateTime.Now,
                        Name         = invoiceNumber,
                        Tag          = "Rechnung",
                        RelativePath = fileName
                    };

                    document = UnitOfWork.Documents.Add(document);

                    var invoice = new Invoice
                    {
                        Amount        = amount,
                        InvoiceNumber = invoiceNumber,
                        IsPaid        = false,
                        Order         = order,
                        Document      = document
                    };

                    invoice = UnitOfWork.Invoices.Add(invoice);

                    UnitOfWork.Complete();

                    InvoiceList.Add(invoice);

                    if (vm.OpenAfterSave ?? false)
                    {
                        Open(fileName);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void EPT_BatchImport_Aggt()
        {
            if (IsTestDbSQLite())
            {
                return;
            }

            int size = EntityTest.BATCH_IMPORT_DATA_SIZE;

            var repo     = RF.ResolveInstance <InvoiceRepository>();
            var itemRepo = RF.ResolveInstance <InvoiceItemRepository>();

            using (RF.TransactionScope(repo))
            {
                var invoices = new InvoiceList();
                for (int i = 0; i < size; i++)
                {
                    var Invoice = new Invoice
                    {
                        InvoiceItemList =
                        {
                            new InvoiceItem(),
                            new InvoiceItem(),
                        }
                    };
                    invoices.Add(Invoice);
                }

                var importer = repo.CreateImporter();
                importer.Save(invoices);

                Assert.AreEqual(size, repo.CountAll());
                Assert.AreEqual(size * 2, itemRepo.CountAll());

                invoices.Clear();
                importer.Save(invoices);

                Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                Assert.AreEqual(itemRepo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");

                using (PhantomContext.DontFilterPhantoms())
                {
                    Assert.AreEqual(repo.CountAll(), size, "幽灵状态的实体,可以使用特定 API 查出。");
                    var roots = repo.GetAll();
                    Assert.AreEqual(roots.Count, size, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(roots[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");

                    Assert.AreEqual(itemRepo.CountAll(), size * 2, "幽灵状态的实体,可以使用特定 API 查出。");
                    var items = itemRepo.GetAll();
                    Assert.AreEqual(items.Count, size * 2, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(items[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                }
            }
        }
Exemplo n.º 5
0
        private void btnAddInvoice_Click(object sender, EventArgs e)
        {
            Invoice invoice = _car.createInvoice();

            if (openAddEditDialog(invoice))
            {
                _invoiceList.Add(invoice);

                _driverCarList.ReLoad();

                loadInvoice();
            }
        }
Exemplo n.º 6
0
        //Grid view Chart Item Add
        public void ChartItemAdd(InvoiceList invoiceItems, string productID,string Description, string stockQuantity, string saleQuanty, string SaleAmount, string saleRate, TextBlock quantity)
        {
            if (Convert.ToInt32(saleQuanty) <= Convert.ToInt32(stockQuantity))
            {
                IEnumerable<InvoiceItems> invoiceitem = from tempInvoiceItem in invoiceItems where tempInvoiceItem.ProductID.Equals(productID) select tempInvoiceItem;
                if (invoiceitem.Count() > 0)
                    {
                        MessageBoxResult errorCodeMessBoxResult = new MessageBoxResult();
                        errorCodeMessBoxResult = Microsoft.Windows.Controls.MessageBox.Show(Variables.ERROR_MESSAGES[1, 7], Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

                        switch (errorCodeMessBoxResult)
                        {
                            case MessageBoxResult.Yes:
                                invoiceitem.First().Quantity += Convert.ToInt32(saleQuanty);
                                invoiceitem.First().Amount += Convert.ToDouble(SaleAmount);
                                break;
                            case MessageBoxResult.No:
                                invoiceitem.First().Quantity = Convert.ToInt32(saleQuanty);
                                invoiceitem.First().Amount = Convert.ToDouble(SaleAmount);
                                break;
                            case MessageBoxResult.Cancel:
                                return;
                            default:
                                return;
                        }
                    }
                    else
                    {
                        invoiceItems.Add(new InvoiceItems(productID, Description, Convert.ToInt32(saleQuanty), Convert.ToDouble(saleRate), Convert.ToDouble(SaleAmount)));
                    }
                    quantity.Text = Convert.ToString(Convert.ToDouble(stockQuantity) - Convert.ToDouble(saleQuanty));
                    return;
                }
            else
            {
                Microsoft.Windows.Controls.MessageBox.Show(Variables.ERROR_MESSAGES[1, 0], Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Hand);
                return;
            }
        }
Exemplo n.º 7
0
        public void LoadInvoiceList(InvoiceList invoiceList)
        {
            //Build query to get Invoice's and their roti
            StringBuilder sqlQuery = new StringBuilder();

            sqlQuery.Append(String.Format("Select invoiceID, noInvoice, dueDate, invoiced.outletCode, OUTLET.OUTLNAME, subTotal, ppn, total, issuedDate, isPPN, nomorPO, Periode, Pengguna, id_payment, isPayed FROM invoiced INNER JOIN OUTLET ON invoiced.outletCode = OUTLET.OUTLCODE ;"));
            sqlQuery.Append(string.Format("Select rotiID, invoiceID, itemCode, itemQty, itemPrice, discount, subTotal FROM invoiceDetail"));

            //Get a data set from the query
            DataSet dataSet = DataProvider.GetDataSet(sqlQuery.ToString());

            //Create Variables for data set tables
            DataTable invoiceTable = dataSet.Tables[0];
            DataTable detailTable  = dataSet.Tables[1];

            //Create a data relation from invoice (parent table) to detail Invoice
            DataColumn   parentColumn    = invoiceTable.Columns["invoiceID"];
            DataColumn   childColumn     = detailTable.Columns["invoiceID"];
            DataRelation invoiceToDetail = new DataRelation("invoiceToDetail", parentColumn, childColumn, false);

            dataSet.Relations.Add(invoiceToDetail);

            //Load InvoiceList from the data set
            InvoiceItem nextInvoice = null;
            rotiItem    nextRoti    = null;

            foreach (DataRow parentRow in invoiceTable.Rows)
            {
                //Create a new invoice
                bool createDatabaseRecord = false;
                nextInvoice = new InvoiceItem(createDatabaseRecord);

                //Fill in invoice properties
                nextInvoice.InvoiceID  = Convert.ToInt32(parentRow["invoiceID"]);
                nextInvoice.Nomor      = parentRow["noInvoice"].ToString();
                nextInvoice.DueDate    = Convert.ToDateTime(parentRow["dueDate"]);
                nextInvoice.OutletCode = parentRow["outletCode"].ToString();

                //nextInvoice.SubTotal = Convert.ToDecimal(parentRow["subTotal"]);
                nextInvoice.PPN = Convert.ToInt32(parentRow["ppn"]);
                //nextInvoice.Total = Convert.ToDecimal(parentRow["total"]);
                nextInvoice.IssuedData = Convert.ToDateTime(parentRow["issuedDate"]);
                nextInvoice.IsPPN      = Convert.ToBoolean(parentRow["isPPN"]);
                nextInvoice.NomorPO    = parentRow["nomorPO"].ToString();
                nextInvoice.User       = parentRow["pengguna"].ToString();

                //Get Invoice Item
                DataRow[] childRows = parentRow.GetChildRows(invoiceToDetail);

                //Create invoiceItem object foe each of the invoice
                foreach (DataRow childRow in childRows)
                {
                    //Create a new item
                    nextRoti = new rotiItem();

                    //Fill in roti's properties
                    nextRoti.ID        = Convert.ToInt32(childRow["rotiID"]);
                    nextRoti.Invoiceid = Convert.ToInt32(childRow["invoiceID"]);
                    nextRoti.ItemCode  = childRow["itemCode"].ToString();
                    nextRoti.Qty       = Convert.ToInt32(childRow["itemQty"]);
                    nextRoti.Price     = Convert.ToDecimal(childRow["itemPrice"]);
                    nextRoti.Discount  = Convert.ToDouble(childRow["discount"]);
                    //nextRoti.SubTotal = Convert.ToDecimal(childRow["Subtotal"]);

                    //Add roti to invoice
                    if (nextRoti.ItemCode != "0")
                    {
                        nextInvoice.Items.Add(nextRoti);
                    }
                    else
                    {
                        nextRoti.DeleteDatabaseRecord();
                    }
                }

                //Add the invoice to the invoice List
                invoiceList.Add(nextInvoice);
            }

            //Dispose of the dataset
            dataSet.Dispose();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Updates the listbox based on the Invoice Number Combobox selection
 /// </summary>
 /// <param name="sender">Combobox</param>
 /// <param name="e">Args</param>
 private void cb_InvoiceNum_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         // Checks to make sure that the selected index is not the reset value
         ComboBox temp = (ComboBox)sender;
         if (temp.SelectedIndex != -1)
         {
             // Reset other comboboxes
             //cb_InvoiceDate.SelectedIndex = -1;
             //cb_TotalCost.SelectedIndex = -1;
             // Clear items out of Listbox source
             UIInvoices.Clear();
             string invoiceNum = ((ComboBox)sender).SelectedItem.ToString();
             // Add items that match into listbox
             foreach (Invoice item in DAInvoice.ListInvoices())
             {
                 if (item.iInvoiceNumber == invoiceNum)
                 {
                     if (cb_TotalCost.SelectedIndex != -1 && cb_InvoiceDate.SelectedIndex != -1)
                     {
                         if (item.dTotal.ToString("c") == cb_TotalCost.SelectedItem.ToString() && item.sInvoiceDate == (DateTime)cb_InvoiceDate.SelectedItem)
                         {
                             UIInvoices.Add(item);
                         }
                     }
                     else if (cb_TotalCost.SelectedIndex != -1)
                     {
                         if (item.dTotal.ToString("c") == cb_TotalCost.SelectedItem.ToString())
                         {
                             UIInvoices.Add(item);
                         }
                     }
                     else if (cb_InvoiceDate.SelectedIndex != -1)
                     {
                         if (item.sInvoiceDate == (DateTime)cb_InvoiceDate.SelectedItem)
                         {
                             UIInvoices.Add(item);
                         }
                     }
                     else
                     {
                         UIInvoices.Add(item);
                     }
                 }
                 //if (item.iInvoiceNumber == invoiceNum)
                 //{
                 //    UIInvoices.Add(item);
                 //}
             }
             lb_srch_Invoices.Items.Refresh();
         }
     }
     catch (Exception ex)
     {
         Exceptions.Spool(ex);
     }
 }
        /// <summary>
        /// The OnAddInvoice
        /// </summary>
        private async void OnAddInvoice()
        {
            if (SelectedProduct == null)
            {
                return;
            }
            Validator.RemoveAllRules();
            ConfigureValidationRules(); await ValidateAsync();

            if (HasErrors)
            {
                await DialogHost.Show(new FailedView(), "RootDialog");

                return;
            }

            double price = 0.0d;
            string size;
            double unit = 0.0d;

            if (SelectedProduct.Type.Name == "pcs" || SelectedProduct.Type.Name == "pieces" ||
                SelectedProduct.Type.Name == "pc")
            {
                price = Price * Quantity.GetValueOrDefault();
                unit  = Price;
                size  = null;
                SelectedProduct.Stock -= Quantity.GetValueOrDefault();
            }
            else
            {
                unit = (Quantity.GetValueOrDefault() *
                        (Size1.GetValueOrDefault() * Size2.GetValueOrDefault()));
                price = Price * unit;
                SelectedProduct.Stock -= (Quantity.GetValueOrDefault() *
                                          (Size1.GetValueOrDefault() * Size2.GetValueOrDefault()));
                size = $"{Size1} x {Size2}";
            }
            RaisePropertyChanged(() => SelectedProduct);
            RaisePropertyChanged(() => Products);
//            var code = _context.Invoices.Select(c => c.InvoiceCode).OrderByDescending(c => c).FirstOrDefault();
//            int finalNumber = 0;
//            if (code > 0)
//            {
//                finalNumber = code + 1;
//            }
//            else
//            {
//                finalNumber = 1000001;
//            }
            NewInvoice = new Invoice()
            {
                Product     = SelectedProduct,
                Unit        = unit,
                Price       = price,
                Length      = Size1.GetValueOrDefault(),
                Width       = Size2.GetValueOrDefault(),
                Quantity    = Quantity.GetValueOrDefault(),
                Size        = $"{Size1} x {Size2}",
                Description = Description
            };

            InvoiceList.Add(NewInvoice);
            CalculateTotal();
            Total = Total;
            ClearFields();
        }