public ProjExpensesTabHandler(ComboBox combo, DataGrid table)
        {
            ProjectCombo             = combo;
            ProjectCombo.ItemsSource = ExpenseDBProvider.Instance().getProjects();

            ProjectExpenseTable             = table;
            ProjectExpenseTable.ItemsSource = ExpenseDBProvider.Instance().getProjExpenses();
        }
Beispiel #2
0
        public static ExpenseDBProvider Instance()
        {
            if (s_DBProvider == null)
            {
                s_DBProvider = new ExpenseDBProvider();
            }

            return(s_DBProvider);
        }
Beispiel #3
0
        public void Delete()
        {
            List <Project> projects = new List <Project>();

            foreach (var item in ProjectTable.SelectedItems)
            {
                projects.Add(item as Project);
            }
            ExpenseDBProvider.Instance().RemoveRange(projects);
            ExpenseDBProvider.Instance().Save();
        }
        public void Save(int projectId, string usage)
        {
            foreach (ProjectExpenseView item in ProjectExpenseTable.SelectedItems)
            {
                ProjectExpense projectExpense = ExpenseDBProvider.Instance().GetProjExpense(item.ID);

                projectExpense.ProjectID = projectId;
                projectExpense.Usage     = usage;
            }
            ExpenseDBProvider.Instance().Save();
            Refresh();
        }
Beispiel #5
0
        public override bool Import()
        {
            string line = streamReader.ReadLine();

            while (line != null)
            {
                if (line.StartsWith("----"))
                {
                    // We are now at table header
                    line = streamReader.ReadLine();
                    line = streamReader.ReadLine();
                    break;
                }
                line = streamReader.ReadLine();
            }

            List <Expense> expenses = new List <Expense>();

            while (line != null)
            {
                string[] fields      = line.Split(',');
                Expense  transaction = new Expense();

                if (fields[(int)CSVFormat.InOut].Equals("收入"))
                {
                    line = streamReader.ReadLine();
                    continue;
                }

                transaction.TimeStamp = DateTime.Parse(fields[(int)CSVFormat.Time]);
                transaction.Product   = string.Format("{0} - {1}", fields[(int)CSVFormat.Seller], fields[(int)CSVFormat.Product]);
                transaction.Price     = float.Parse(fields[(int)CSVFormat.Price].Replace("¥", ""));
                transaction.Source    = source;

                expenses.Add(transaction);
                line = streamReader.ReadLine();
            }

            if (expenses.Count == 0)
            {
                return(false);
            }

            ExpenseDBProvider.Instance().AddRange(expenses);
            ExpenseDBProvider.Instance().Save();
            return(true);
        }
Beispiel #6
0
        public Result Export(string filename)
        {
            try
            {
                Application excel = new Application();
                excel.Visible = false;

                Workbooks workbooks = excel.Workbooks;
                Workbook  workbook  = workbooks.Add(XlWBATemplate.xlWBATWorksheet);

                Worksheet worksheet = (Worksheet)workbook.Worksheets[1];

                initHeader(worksheet);

                int rowIndex = 2;
                int colIndex = 1;
                List <ProjectExpenseView> data = ExpenseDBProvider.Instance().getProjExpenses();
                foreach (ProjectExpenseView projectExpense in data)
                {
                    worksheet.Cells[rowIndex, colIndex++] = rowIndex - 1;
                    worksheet.Cells[rowIndex, colIndex++] = projectExpense.ProjectName;
                    worksheet.Cells[rowIndex, colIndex++] = projectExpense.Product;
                    worksheet.Cells[rowIndex, colIndex++] = projectExpense.Usage;
                    worksheet.Cells[rowIndex, colIndex++] = projectExpense.Price;
                    worksheet.Cells[rowIndex, colIndex++] = projectExpense.TimeStamp;
                    rowIndex++;
                    colIndex = 1;
                }

                worksheet.Columns.AutoFit();

                workbook.SaveAs(filename);

                workbook.Close(true, Type.Missing, Type.Missing);
                excel.Quit();

                return(Result.Success);
            }
            catch
            {
                return(Result.Fail);
            }
        }
Beispiel #7
0
        public override bool Import()
        {
            string line = streamReader.ReadLine();

            while (line != null)
            {
                // We are now at table header
                if (!line.StartsWith("#"))
                {
                    line = streamReader.ReadLine();
                    break;
                }
                line = streamReader.ReadLine();
            }

            List <Expense> expenses = new List <Expense>();

            while (line != null && !line.StartsWith("#"))
            {
                string[] fields      = line.Split(',');
                Expense  transaction = new Expense();

                transaction.TimeStamp = DateTime.Parse(fields[(int)CSVFormat.Time]);
                transaction.Product   = fields[(int)CSVFormat.Product];
                transaction.Price     = float.Parse(fields[(int)CSVFormat.Price]);
                transaction.Source    = source;

                expenses.Add(transaction);
                line = streamReader.ReadLine();
            }

            if (expenses.Count == 0)
            {
                return(false);
            }

            ExpenseDBProvider.Instance().AddRange(expenses);
            ExpenseDBProvider.Instance().Save();
            return(true);
        }
Beispiel #8
0
        public void Save()
        {
            List <ProjectExpense> projectExpenses = new List <ProjectExpense>();

            foreach (ExpenseView expense in ExpenseTable.ItemsSource)
            {
                if (expense.Dirty)
                {
                    ProjectExpense projectExpense = ExpenseDBProvider.Instance().GetProjExpenseByExpense(expense.ID);

                    if (projectExpense == null && expense.IsBusiness)
                    {
                        ExpenseDBProvider.Instance().Add(expense.ToProjectExpense());
                    }
                    else if (projectExpense != null && !expense.IsBusiness)
                    {
                        ExpenseDBProvider.Instance().Remove(projectExpense);
                    }
                }
            }
            ExpenseDBProvider.Instance().Save();
        }
Beispiel #9
0
        public Result Save(string name, string description)
        {
            if (ExpenseDBProvider.Instance().findProject(name))
            {
                return(Result.AlreadyExist);
            }

            Project project = new Project();

            project.ProjectName        = name;
            project.ProjectDescription = description;

            try
            {
                ExpenseDBProvider.Instance().Add(project);
                ExpenseDBProvider.Instance().Save();
                return(Result.Success);
            }
            catch
            {
                return(Result.Fail);
            }
        }
Beispiel #10
0
 public override void Refresh()
 {
     ProjectTable.ItemsSource = ExpenseDBProvider.Instance().getProjects();
 }
Beispiel #11
0
 public ProjectTabHandler(DataGrid tab)
 {
     ProjectTable             = tab;
     ProjectTable.ItemsSource = ExpenseDBProvider.Instance().getProjects();
 }
Beispiel #12
0
 public bool CanExport()
 {
     return(ExpenseDBProvider.Instance().getProjExpenses().Count > 0);
 }
Beispiel #13
0
 public void Reset()
 {
     ExpenseDBProvider.Instance().Reset();
 }
Beispiel #14
0
 public override void Refresh()
 {
     ExpenseTable.ItemsSource = ExpenseDBProvider.Instance().getExpenses();
 }
Beispiel #15
0
 public ExpensesTabHandler(DataGrid tab)
 {
     ExpenseTable             = tab;
     ExpenseTable.ItemsSource = ExpenseDBProvider.Instance().getExpenses();
 }