Ejemplo n.º 1
0
        private void doTheBill()
        {
            BillHeader header = new BillHeader(Bills.Count, actualUser, table);

            ActualBill.Header = header;

            for (int i = 1; i <= Products.Count; i++)
            {
                BillLine line = new BillLine(Products.Get(i).ActualProduct,
                                             Products.Get(i).Amount);
                ActualBill.AddLine(line);
            }
        }
Ejemplo n.º 2
0
        public string Load()
        {
            Bills = new List <Bill>();

            if (!(File.Exists(PATH)))
            {
                return("Creating the bills file");
            }
            else
            {
                try
                {
                    StreamReader input = new StreamReader(PATH);

                    string line = "";
                    do
                    {
                        line = input.ReadLine();
                        if (line != null)
                        {
                            Bill bill = new Bill();

                            string[] parts = line.Split('|');
                            //Bill lines
                            string[] billLines = parts[0].Split('$');
                            for (int i = 0; i < billLines.Length; i++)
                            {
                                string[] billLineParts =
                                    billLines[i].Split('=');
                                //Product
                                string[] productsParts =
                                    billLineParts[0].Split('·');
                                Product product = new Product();

                                product.Description = productsParts[0];
                                product.Price       =
                                    Convert.ToDouble(productsParts[1]);
                                product.ImagePath = productsParts[2];
                                product.Stock     =
                                    Convert.ToInt32(productsParts[3]);
                                product.MinimunStock =
                                    Convert.ToInt32(productsParts[4]);
                                product.Code =
                                    Convert.ToInt32(productsParts[5]);
                                product.Category = productsParts[6];
                                product.BuyPrice =
                                    Convert.ToDouble(productsParts[7]);

                                //amount
                                int amount =
                                    Convert.ToInt32(billLineParts[1]);

                                BillLine billLine =
                                    new BillLine(product, amount);
                                bill.AddLine(billLine);
                            }

                            //Header
                            string[] headerParts = parts[1].Split('=');

                            //Other things
                            string[] otherParts = headerParts[0].Split('·');
                            int      table      = Convert.ToInt32(otherParts[0]);
                            int      number     = Convert.ToInt32(otherParts[1]);
                            string   date       = otherParts[2];

                            //User
                            string[] userParts = headerParts[1].Split('·');

                            User employee = new User();

                            employee.Name      = userParts[0];
                            employee.Code      = Convert.ToInt32(userParts[1]);
                            employee.ImagePath = userParts[2];
                            employee.Pass      = userParts[3];

                            BillHeader billHeader =
                                new BillHeader(number, employee, table);
                            billHeader.Date = Convert.ToDateTime(date);

                            //Total
                            bill.Total      = Convert.ToDouble(parts[2]);
                            bill.SubTotal   = Convert.ToDouble(parts[3]);
                            bill.MoneyGiven = Convert.ToDouble(parts[4]);
                            bill.Change     = Convert.ToDouble(parts[5]);

                            bill.Header = billHeader;

                            this.Add(bill);
                        }
                    } while (line != null);

                    input.Close();
                }
                catch (Exception e)
                {
                    return("Error loading the bills file: "
                           + e.Message);
                }
            }
            return("");
        }