Exemplo n.º 1
0
        private void getAllTransactions(TransactionType transactionType)
        {
            DataTable dtTempTable           = new DataTable();
            DataTable dtMonthlyTransactions = new DataTable();

            if (!File.Exists(Application.StartupPath + "\\data\\logs"))
            {
                Directory.CreateDirectory(Application.StartupPath + "\\data\\logs");
            }

            foreach (string name in Directory.GetFiles(Application.StartupPath + "\\data\\logs"))
            {
                if (name.Contains("\\Transactions_"))
                {
                    DataTable dtTransactions = xmlData.Select("*", "datecreated asc", "logs\\Transactions_" + name.Substring(name.LastIndexOf("_") + 1).ToLower().Replace(".xml", ""), "InventoryItems");

                    if (dtMonthlyTransactions.Columns.Count == 0)
                    {
                        dtMonthlyTransactions = dtTransactions.Clone();
                    }

                    if (dtTransactions != null)
                    {
                        Voodoo.Objects.InventoryItem currentTransactions = new Voodoo.Objects.InventoryItem();

                        switch (transactionType)
                        {
                        case TransactionType.Cash:
                        case TransactionType.Credit:
                            currentTransactions.Price = getTotal(dtTransactions, transactionType);
                            break;

                        default:
                            currentTransactions.Price = getTotal(dtTransactions);
                            break;
                        }

                        currentTransactions.Name = name.Replace(Application.StartupPath + "\\data\\logs\\Transactions_", "");

                        DataRow drNew = dtMonthlyTransactions.NewRow();

                        Type type       = currentTransactions.GetType();
                        var  properties = type.GetProperties();

                        foreach (PropertyInfo property in properties)
                        {
                            drNew[property.Name] = property.GetValue(currentTransactions, null).ToString();
                        }

                        drNew["DateCreated"] = DateTime.Now;

                        dtMonthlyTransactions.Rows.Add(drNew);
                    }
                }
            }

            dgvReport.DataSource = dtMonthlyTransactions;
        }