Пример #1
0
        internal void Save(UCProduct ucProduct)
        {
            if (!UserControlHelpers.EmptyFieldValidation(ucProduct.TxtName) | !UserControlHelpers.EmptyFieldValidation(ucProduct.TxtPrice) | !UserControlHelpers.EmptyFieldValidation(ucProduct.TxtVAT) | !UserControlHelpers.EmptyFieldValidationCB(ucProduct.CbType) | !UserControlHelpers.EmptyFieldValidationCB(ucProduct.CbCurrency))
            {
                MessageBox.Show("Sva polja su obavezna!");
                return;
            }
            if (!UserControlHelpers.CheckDoubleType(ucProduct.TxtPrice) | !UserControlHelpers.CheckDoubleType(ucProduct.TxtVAT))
            {
                MessageBox.Show("Pogrešan unos!");
                return;
            }

            try
            {
                Product p = new Product();
                p.Name            = ucProduct.TxtName.Text;
                p.PriceWithoutVAT = Math.Ceiling(Double.Parse(ucProduct.TxtPrice.Text));
                p.VAT             = Math.Ceiling(Double.Parse(ucProduct.TxtVAT.Text));
                p.Currency        = (Currency)ucProduct.CbCurrency.SelectedItem;
                p.Type            = (ProductType)ucProduct.CbType.SelectedItem;

                Communication.Communication.Instance.SaveProduct(p);
                MessageBox.Show("Sistem je zapamtio proizvod!");
                ucProduct.Visible = false;
            }
            catch (Exception)
            {
                MessageBox.Show("Sistem ne može da zapamti proizvod!");
            }
        }
Пример #2
0
        internal void SaveInvoice(UCInvoice uCInvoice)
        {
            if (uCInvoice.CbPayment.SelectedItem.Equals(PaymentType.Kartica) || uCInvoice.CbPayment.SelectedItem.Equals(PaymentType.Kombinovano))
            {
                if (!UserControlHelpers.EmptyFieldValidationCB(uCInvoice.CbCardType) | !UserControlHelpers.EmptyFieldValidation(uCInvoice.TxtCardNumber))
                {
                    MessageBox.Show("Neophodno je uneti 'tip kartice' i broj kartice'");
                    return;
                }
                if (!UserControlHelpers.CheckLongIntType(uCInvoice.TxtCardNumber))
                {
                    MessageBox.Show("Broj kartice nije ispravano unet.");
                    return;
                }
            }

            double totalToPay = int.Parse(uCInvoice.TxtTotalToPay.Text);
            double card;
            double cache;

            if (uCInvoice.CbPayment.SelectedItem.Equals(PaymentType.Kombinovano))
            {
                if (string.IsNullOrEmpty(uCInvoice.TxtCache.Text) | string.IsNullOrEmpty(uCInvoice.TxtCard.Text))
                {
                    MessageBox.Show("Neophodno je popuniti polja: 'Iznos koji se plaća gotovinom', 'Iznos koji se plaća karticom'");
                    return;
                }

                if (!UserControlHelpers.CheckDoubleType(uCInvoice.TxtCache) | !UserControlHelpers.CheckDoubleType(uCInvoice.TxtCard))
                {
                    MessageBox.Show("Neispravan unos iznosa za plaćanje. Unete vrednosti moraju biti brojevi.");
                    return;
                }

                cache = double.Parse(uCInvoice.TxtCache.Text);
                card  = double.Parse(uCInvoice.TxtCard.Text);

                if ((card + cache) != totalToPay)
                {
                    MessageBox.Show($"Neispravan unos iznosa za plaćanje. Ukupan iznos za plaćanje iznosi {totalToPay}.");
                    return;
                }
            }

            Cache cache1 = null;
            Card  card1  = null;

            DateTime dateTime = DateTime.Now;

            uCInvoice.TxtDate.Text = dateTime.ToString("dd/MM/yyyy HH:mm:ss");

            Table table = new Table
            {
                TableNumber = int.Parse(uCInvoice.TxtTable.Text)
            };

            try
            {
                if (uCInvoice.CbPayment.SelectedItem.Equals(PaymentType.Gotovina))
                {
                    cache = totalToPay;

                    cache1 = new Cache
                    {
                        OrderId      = order.OrderId,
                        TotalInCache = cache
                    };
                }

                if (uCInvoice.CbPayment.SelectedItem.Equals(PaymentType.Kartica))
                {
                    card = totalToPay;

                    card1 = new Card
                    {
                        OrderId     = order.OrderId,
                        CardType    = (CardType)uCInvoice.CbCardType.SelectedItem,
                        CardNumber  = long.Parse(uCInvoice.TxtCardNumber.Text),
                        TotalByCard = card
                    };
                }

                if (uCInvoice.CbPayment.SelectedItem.Equals(PaymentType.Kombinovano))
                {
                    card  = double.Parse(uCInvoice.TxtCard.Text);
                    cache = double.Parse(uCInvoice.TxtCache.Text);

                    card1 = new Card
                    {
                        OrderId     = order.OrderId,
                        CardType    = (CardType)uCInvoice.CbCardType.SelectedItem,
                        CardNumber  = long.Parse(uCInvoice.TxtCardNumber.Text),
                        TotalByCard = card
                    };

                    cache1 = new Cache
                    {
                        OrderId      = order.OrderId,
                        TotalInCache = cache
                    };
                }

                Payment payment = new Payment
                {
                    OrderId     = order.OrderId,
                    Total       = totalToPay,
                    Currency    = currency,
                    PaymentType = (PaymentType)uCInvoice.CbPayment.SelectedItem,
                    Cache       = cache1,
                    Card        = card1
                };

                Invoice invoice = new Invoice
                {
                    DateTime        = dateTime,
                    User            = MainCoordinator.Instance.User,
                    Table           = table,
                    Currency        = currency,
                    TotalWithoutVAT = double.Parse(uCInvoice.TxtTotal.Text),
                    TotalWithVAT    = double.Parse(uCInvoice.TxtTotalVAT.Text),
                    TotalToPay      = double.Parse(uCInvoice.TxtTotalToPay.Text),
                    InvoiceItems    = invoiceItems,
                    OrderId         = order.OrderId,
                    Payment         = payment
                };

                Communication.Communication.Instance.SaveInvoice(invoice);

                order.State = "Placeno";
                Communication.Communication.Instance.UpdateOrder(order);

                MessageBox.Show("Sistem je zapamtio račun!");
                uCInvoice.Visible = false;
            }
            catch (Exception)
            {
                MessageBox.Show("Sistem ne može da zapamti račun!");
            }
        }