Esempio n. 1
0
        public static void write(Month month, string filename)
        {
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
            xmlWriterSettings.NewLineOnAttributes = true;
            xmlWriterSettings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(filename, xmlWriterSettings))
            //using (XmlWriter writer = XmlWriter.Create(new StreamWriter(filename, false, Encoding.UTF8)))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("Expenses");

                foreach (Transaction e in month.getTransactions())
                {
                    writer.WriteStartElement("Expense");

                    //writer.WriteElementString("Main Category", e.category.primary.ToString());
                    //writer.WriteElementString("Second Category", e.category.secondary);
                    writer.WriteElementString("Date", e.date.ToShortDateString());
                    writer.WriteElementString("FirstName", e.businessName);
                    writer.WriteElementString("TransactionPrice", e.transactionPrice.ToString());
                    writer.WriteElementString("BillingPrice", e.billingPrice.ToString());
                    writer.WriteElementString("ReceiptId", e.receiptId.ToString());
                    writer.WriteElementString("Details", e.details.ToString());
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
Esempio n. 2
0
        public static void loadTransactions()
        {
            if (!File.Exists(dataFolder + dataTransactionsFilename))
                return;

            StreamReader sr = new StreamReader(dataFolder + dataTransactionsFilename, Encoding.GetEncoding("ISO-8859-8"));
            using (XmlReader reader = XmlReader.Create(sr))
            {
                Month month = null;
                DateTime date = new DateTime();
                Transaction e = null;

                while (reader.Read())
                {
                    // Get element name and switch on it.
                    switch (reader.Name)
                    {
                        case "Month":
                            if (reader.IsStartElement())
                            {
                                month = new Month();
                                reader.ReadToFollowing("Date");
                                if (reader.Read())
                                    date = stringDateToDateTime(reader.Value.Trim());
                            }
                            else
                            {
                                month.sortTransactions();
                                Database.months.Add(date, month);
                            }
                            break;
                        case "Transaction":
                            if (reader.IsStartElement())
                            {
                                XmlReader inner = reader.ReadSubtree();

                                e = new Transaction();
                                while (inner.Read())
                                {
                                    if (inner.IsStartElement())
                                    {
                                        switch (inner.Name)
                                        {
                                            case "HashCode":
                                                if (inner.Read())
                                                    e.hashCode = Convert.ToInt32(inner.Value.Trim());
                                                break;
                                            case "Date":
                                                if (inner.Read())
                                                    e.date = stringDateToDateTime(inner.Value.Trim());
                                                break;
                                            case "BusinessName":
                                                if (inner.Read())
                                                    e.businessName = inner.Value.Trim();
                                                break;
                                            case "TransactionPrice":
                                                if (inner.Read())
                                                    e.transactionPrice = Double.Parse(inner.Value.Trim());
                                                break;
                                            case "BillingPrice":
                                                if (inner.Read())
                                                    e.billingPrice = Double.Parse(inner.Value.Trim());
                                                break;
                                            //case "PaymentID":
                                            //    if (inner.Read())
                                            //        e.creditCardNumber = inner.Value.Trim();
                                            //    break;
                                            case "PrimaryCategory":
                                                string primary = null;
                                                string secondary = null;
                                                if (inner.Read())
                                                    primary = inner.Value.Trim();
                                                if (reader.ReadToFollowing("SecondaryCategory"))
                                                    if (inner.Read())
                                                    {
                                                        secondary = inner.Value.Trim();
                                                        e.category = Database.getCategory(primary, secondary);
                                                    }
                                                break;
                                            case "PaymentInfo":
                                                string paymentId = null;
                                                string paymentTypeString = null;
                                                string startDateString = null;
                                                string endDateString = null;

                                                while (inner.Read())
                                                {
                                                    if (inner.IsStartElement())
                                                    {
                                                        switch (inner.Name)
                                                        {
                                                            case "Id":
                                                                if (inner.Read())
                                                                    paymentId = inner.Value.Trim();
                                                                break;
                                                            case "Name":
                                                                if (inner.Read())
                                                                    paymentTypeString = inner.Value.Trim();
                                                                break;
                                                            case "StartDate":
                                                                if (inner.Read())
                                                                    startDateString = inner.Value.Trim();
                                                                break;
                                                            case "EndDate":
                                                                if (inner.Read())
                                                                    endDateString = inner.Value.Trim();
                                                                break;
                                                        }
                                                    }
                                                    if (inner.Name.Equals("PaymentInfo"))
                                                    {
                                                        DateTime startDate = stringDateToDateTime(startDateString);
                                                        DateTime endDate = stringDateToDateTime(endDateString);
                                                        PaymentType paymentType = PaymentInfo.parsePaymentTypeString(paymentTypeString);
                                                        e.paymentInfo = month.getPaymentInfo(paymentId,paymentType,startDate,endDate);
                                                        break;
                                                    }
                                                }
                                                break;
                                            case "ReceiptID":
                                                if (inner.Read())
                                                    e.receiptId = Convert.ToInt32(inner.Value.Trim());
                                                break;
                                            case "Type":
                                                if (inner.Read())
                                                    e.setType(inner.Value.Trim());
                                                break;
                                            case "Details":
                                                if (inner.Read())
                                                    e.details = inner.Value.Trim();
                                                break;
                                            case "Filter":
                                                e.filter = true;
                                                break;
                                            case "Comment":
                                                if (inner.Read())
                                                    e.comment = inner.Value.Trim();
                                                break;
                                        }
                                    }
                                }
                            }
                            reader.Skip();

                            if (e.paymentInfo == null)
                                Console.Write(e.businessName + "\n");

                            month.addTransaction(e);
                            break;

                    }

                }
            }
            sr.Close();
            sr.Dispose();
        }
Esempio n. 3
0
        public static Month getMonth(DateTime date)
        {
            DateTime monthDate = new DateTime(date.Year,date.Month,1);
            Month month;

            if (!months.TryGetValue(monthDate, out month))
            {
                month = new Month();
                months.Add(monthDate, month);
            }

            return month;
        }