Пример #1
0
        private void InitializeInterface()
        {
            Company company = CompanyInfo.GetCompanyInfo();

            tbBillText.Text          = BillInfo.GetBillInfo().billText.Trim();
            tbCompanyAdress.Text     = company.adress.Trim();
            tbCompanyCity.Text       = company.city.Trim();
            tbCompanyName.Text       = company.name.Trim();
            tbCompanyPhone.Text      = company.phone.Trim();
            tbCompanyPostalCode.Text = company.postalCode.ToString();
            tbCompanyWebSite.Text    = company.web.Trim();
        }
Пример #2
0
        private void CreateXmlBillFromDatabaseSource(string orderId)
        {
            // Načtení dat z DB
            LinqToSqlDataContext db = DatabaseSetup.Database;
            int orderIdInt          = Convert.ToInt32(orderId);
            // Získat vybraný Order
            Order selectedOrder = (from o in db.Orders
                                   where o.id == orderIdInt
                                   select o).Single();
            // Získat výrobky
            IEnumerable <OrderItem> shoppingCartItemsFromDb =
                (from shopItm in db.OrderItems
                 where shopItm.orderId == orderIdInt
                 select shopItm);

            // Dovýpočet některých hodnot

            /*  decimal? totalPriceOfTransaction = 0;
             * foreach(OrderItem item in shoppingCartItemsFromDb)
             * {
             *    if (item.priceForUnit) totalPriceOfTransaction += item.price * item.quantity;
             *    if (!item.priceForUnit) totalPriceOfTransaction += item.price * item.unitQuantity;
             * }
             *
             * decimal? change = selectedOrder.paid - totalPriceOfTransaction;
             */

            // VAT pro produkty
            IEnumerable <OrderItemsVat> listOfVat = from vat in db.OrderItemsVats
                                                    where vat.orderId == orderIdInt
                                                    select vat;



            #region hardcoded účtenka
            if (!Directory.Exists(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill")))
            {
                Directory.CreateDirectory(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill"));
            }
            using (XmlWriter xmlWriter = XmlWriter.Create(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill", orderIdInt.ToString() + ".xml")))
            {
                xmlWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"../CashRegister/Bill.xslt\"?>");
                xmlWriter.WriteStartElement("bill");


                foreach (OrderItem item in shoppingCartItemsFromDb)
                {
                    xmlWriter.WriteStartElement("product");
                    xmlWriter.WriteElementString("name", item.name.Trim());
                    xmlWriter.WriteElementString("quantity", item.quantity.ToString());
                    xmlWriter.WriteElementString("unit", item.unit.Trim());

                    if (!item.priceForUnit)
                    {
                        xmlWriter.WriteElementString("unitQuantity", item.unitQuantity.ToString());
                    }

                    xmlWriter.WriteElementString("expirationDate", ((DateTime)item.expirationDate).ToString("dd.MM.yyyy"));
                    xmlWriter.WriteElementString("code", item.code.ToString());
                    xmlWriter.WriteElementString("totalPrice", item.totalPrice.ToString());
                    xmlWriter.WriteElementString("priceForUnit", item.priceForUnit.ToString());
                    xmlWriter.WriteElementString("priceForSingleUnit", item.price.ToString());
                    xmlWriter.WriteElementString("vatType", item.vatId.ToString());
                    xmlWriter.WriteEndElement();
                }

                xmlWriter.WriteElementString("totalShoppingCartPrice", selectedOrder.totalShoppingCartPrice.ToString());
                xmlWriter.WriteElementString("paid", selectedOrder.paid.ToString());
                xmlWriter.WriteElementString("change", (selectedOrder.change).ToString());
                xmlWriter.WriteElementString("staff", selectedOrder.staff.Trim());
                xmlWriter.WriteElementString("time", ((DateTime)selectedOrder.timeOfTransaction).ToShortDateString() + " " + ((DateTime)selectedOrder.timeOfTransaction).ToShortTimeString());


                //DPH se počítá dohromady pro všechny výrobky dané kategorie (A,B,C,D)

                /* List<VAT> listOfVat = GetVat();
                 * decimal? vatSum = GetVatSum(listOfVat);
                 * decimal? vatSumSingle = GetVatSumSingle(listOfVat);*/
                xmlWriter.WriteElementString("vatSum", string.Format("{0:0.00}", selectedOrder.vatSum));
                xmlWriter.WriteElementString("vatSumSingle", string.Format("{0:0.00}", selectedOrder.vatSumSingle));
                foreach (OrderItemsVat singleVat in listOfVat)
                {
                    xmlWriter.WriteStartElement(singleVat.vatId.ToString());
                    xmlWriter.WriteAttributeString("percentage", singleVat.percentageLabel.Trim());
                    xmlWriter.WriteAttributeString("totalPrice", string.Format("{0:0.00}", singleVat.vatValueProducts));
                    xmlWriter.WriteString(string.Format("{0:0.00}", singleVat.vatValue));
                    xmlWriter.WriteEndElement();
                }

                //Informace do hlavičky

                xmlWriter.WriteElementString("companyName", selectedOrder.companyName.Trim()); // Name je vždy vyplněné

                //Další nepovinné údaje, pokud chybí, tak se to do XML nebude přidávat
                if (!string.IsNullOrEmpty(selectedOrder.companyAdress))
                {
                    xmlWriter.WriteElementString("companyAdress", selectedOrder.companyAdress.Trim());
                }

                if (!string.IsNullOrEmpty(selectedOrder.companyCity))
                {
                    xmlWriter.WriteElementString("companyCity", selectedOrder.companyCity.Trim());
                }

                if (selectedOrder.companyPostalCode != null)
                {
                    xmlWriter.WriteElementString("companyPostalCode", selectedOrder.companyPostalCode.ToString().Trim());
                }

                if (!string.IsNullOrEmpty(selectedOrder.companyPhone))
                {
                    xmlWriter.WriteElementString("companyPhone", selectedOrder.companyPhone.Trim());
                }

                if (!string.IsNullOrEmpty(selectedOrder.companyWeb))
                {
                    xmlWriter.WriteElementString("companyWeb", selectedOrder.companyWeb.Trim());
                }

                Bill billInfo = BillInfo.GetBillInfo();
                if (!string.IsNullOrEmpty(billInfo.billText))
                {
                    xmlWriter.WriteElementString("billText", billInfo.billText.Trim());
                }

                xmlWriter.WriteEndElement();
            }
            #endregion
        }