Example #1
0
        public Dictionary <string, bankData> loadBanks()
        {
            Dictionary <string, bankData> bankMap = new Dictionary <string, bankData>();

            if (!File.Exists(data_dir + banks_file))
            {
                File.CreateText(data_dir + banks_file);
            }


            System.IO.StreamReader br = new System.IO.StreamReader(data_dir + banks_file, System.Text.Encoding.GetEncoding(1255));
            try
            {
                string line = br.ReadLine();
                line = br.ReadLine();                 //skip template line

                while (line != null)
                {
                    string[] arr = line.Split('#');
                    if (arr.Length != 5)
                    {
                        line = br.ReadLine();
                        continue;
                    }

                    string   bankName = arr[0];
                    bankData bankData = new bankData(arr[0], arr[1], arr[2], arr[3], arr[4]);

                    if (bankMap.ContainsKey(arr[0]))
                    {
                        line = br.ReadLine();
                        continue;
                    }

                    bankMap.Add(bankName, bankData);
                    line = br.ReadLine();
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                br.Close();
            }


            return(bankMap);
        }
Example #2
0
        void credit()
        {
            Dictionary <string, double?> result_map = new Dictionary <string, double?>();
            Dictionary <string, int?>    shops      = new Dictionary <string, int?>();

            textBox2.Text = "";

            if (string.IsNullOrEmpty(creditCardPath))
            {
                Microsoft.VisualBasic.Interaction.MsgBox("Please choose credit card file");
                return;
            }

            Excel.Application excel      = new Excel.Application();
            Excel.Workbook    wb         = excel.Workbooks.Open(creditCardPath);
            Excel.Worksheet   excelSheet = wb.ActiveSheet;

            try
            {
                double sum   = 0;
                double money = 0;
                string date;
                int    row = 0, first_col = 0, second_col = 0, date_col = -1;
                String shop_name = "";

                if (string.IsNullOrEmpty(bankChosen))
                {
                    Microsoft.VisualBasic.Interaction.MsgBox("Please choose bank");
                    return;
                }

                //excel = new Excel.Application();
                //            wb = excel.Workbooks.Open(creditCardPath);
                //            excelSheet = wb.ActiveSheet;

                bankData bankDataChosen = banks_hash[bankChosen];
                row        = bankDataChosen.startRow;
                first_col  = bankDataChosen.shop;
                second_col = bankDataChosen.money;
                date_col   = bankDataChosen.date;

                shop_name = excelSheet.Cells[row, first_col].Value.ToString();
                string moneyTextValue = excelSheet.Cells[row, second_col].Value.ToString();
                string moneyText      = Regex.Replace(moneyTextValue, @"[^0-9*.-]+", "");
                money = double.Parse(moneyText, CultureInfo.InvariantCulture);
                //money = excelSheet.Cells[row, second_col].Value;
                date = excelSheet.Cells[row, date_col].Value.ToString();
                //date = date.Substring(0, date.IndexOf(" ") + 1);

                while (!String.IsNullOrEmpty(shop_name))
                {
                    if (shop_category_hash.ContainsKey(shop_name))
                    {
                        if (shops.ContainsKey(shop_name))
                        {
                            shops[shop_name] = shops[shop_name] + 1;
                        }
                        else
                        {
                            shops[shop_name] = 1;
                        }
                        string cat = shop_category_hash[shop_name];
                        add_shop_to_result(result_map, cat, money);

                        // add to sum
                        sum += money;
                    }
                    else
                    {
                        NewCategoryForm categoryForm = new NewCategoryForm(sortedCategories, shop_name, money, date);
                        categoryForm.StartPosition = FormStartPosition.CenterParent;
                        categoryForm.ShowDialog();
                        string cat = categoryForm.result;

                        //string cat = Microsoft.VisualBasic.Interaction.InputBox("Enter new category for " + shop_name + "\nSum: " + money + "\nDate: " + date, "New category", "Enter category here", 450, 300).ToString();
                        if (!String.IsNullOrEmpty(cat) && !cat.Equals("Enter category here") && !categoryForm.ignoreRecord)
                        {
                            try
                            {
                                using (StreamWriter sw = new StreamWriter(data_dir + shops_file, true, System.Text.Encoding.GetEncoding(1255), 512))
                                {
                                    sw.WriteLine(shop_name + "#" + cat);
                                    shop_category_hash[shop_name] = cat;
                                    add_shop_to_result(result_map, cat, money);

                                    if (categoryForm.isNew)
                                    {
                                        sortedCategories.Add(cat);
                                        sortedCategories.Sort();
                                    }

                                    // add to sum
                                    sum += money;
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }

                    // prepare next record
                    row++;
                    shop_name = excelSheet.Cells[row, first_col].Value;

                    //finished
                    if (String.IsNullOrEmpty(shop_name))
                    {
                        break;
                    }

                    date = excelSheet.Cells[row, date_col].Value.ToString();

                    if (excelSheet.Cells[row, second_col].Value != null && !excelSheet.Cells[row, second_col].Value.Equals(""))
                    {
                        moneyText = Regex.Replace(excelSheet.Cells[row, second_col].Value.ToString(), @"[^0-9*.-]+", "");
                        money     = double.Parse(moneyText, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        money = 0;
                    }
                }

                print_result(result_map);
                print_attention(shops);
                textBox2.Text += "Total amount: " + sum;
                //closeAllFiles(excel, wb, excelSheet);
                string user = Console.ReadLine();

                saveToExolidit(result_map, exolidit_hash);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (Exception ex)
            {
                String msg = "";
                if (!String.IsNullOrEmpty(bankSuspected))
                {
                    msg = String.Format("Credit card is suspected to be of type [{0}] or invalid", bankSuspected);
                }
                else
                {
                    msg = "Credit card file is unknown or invalid";
                }

                Microsoft.VisualBasic.Interaction.MsgBox(msg, Microsoft.VisualBasic.MsgBoxStyle.OkOnly, "Credit card");
            }

            closeAllFiles(excel, wb, excelSheet);
        }