public ExpensesForm(MainForm form)
 {
     InitializeComponent();
     mainform = form;
     db = mainform.DataAppCore;
     currentExpense = new Expense();
     //set data grid settings
     ControlFactory.SetDataGridSettings(this.dataGridView1);
 }
        private void Seed()
        {
            //set default data here
            User rootUser = new User() {
                Id = 999,
                IsActive = true,
                Username = "******",
                Password = "******",
                Token = ""
            };

            Company company = new Company()
            {
                Id = 1,
                Name = "NA",
                Description = "NA",
                Email = "NA",
                IsHidden = false,
                Contact = "NA"
            };

            Project project = new Project()
            {
                Id = 1,
                Name = "NA",
                Description = "NA",
                IsHidden = false
            };

            Check check = new Check()
            {
                Id = 1,
                IsHidden = false,
                IssuedOn = DateTime.Now,
                VoucherNumber = "NA",
                Amount = 0,
                CompanyId = 1
            };

            Expense expense = new Expense()
            {
                Id = 1,
                IsHidden = false,
                Date = DateTime.Now,
                Amount = 0,
                ProjectId=1,
                CompanyId = 1,
                CheckId=1,
                ORNUmber = "xxx",
                Description = "NA"
            };

            if (this.UserController.Get(rootUser.Id) == null)
                this.UserController.Add(rootUser);

            if (this.CompanyController.Get(company.Id) == null)
                this.CompanyController.Add(company);

            if (this.ProjectController.Get(project.Id) == null)
                this.ProjectController.Add(project);

            //if (this.ProjectController.Get(project2.Id) == null)
            //    this.ProjectController.Add(project2);

            if (this.CheckController.Get(check.Id) == null)
                this.CheckController.Add(check);

            if (this.ExpenseController.Get(expense.Id) == null)
                this.ExpenseController.Add(expense);
        }
        private void EditSelectedObject()
        {
            if (this.contextMenuStripGridView.Items[0].Selected)
            {
                int selectedRowId = 0;

                foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                {
                    int.TryParse(row.Cells[0].Value.ToString(), out selectedRowId);
                }

                //fetch data
                this.currentExpense = db.ExpenseController.Get(selectedRowId);

                MapObjectToControls();
                tabControl1.SelectedIndex = 1;
            }
        }
        private void SaveDataToDB(bool isUpdate = false)
        {
            try
            {
                if (isUpdate == false)
                    currentExpense = new Expense();

                //map controls to object
                MapControlsToObject();

                //validate
                if (string.IsNullOrEmpty(currentExpense.ORNUmber))
                {
                    MessageBox.Show("Please check empty input fields.");
                    return;
                }

                bool result = false;

                if (isUpdate == false)
                    result = db.ExpenseController.Add(currentExpense);
                else
                    result = db.ExpenseController.Update(currentExpense);

                if (result)
                {
                    if (isUpdate == false)
                        currentExpense = db.ExpenseController.Get(currentExpense.Id);

                    //map
                    MapObjectToControls();
                    TogleUpdateButtons();
                    mainform.WriteStatusBar("Record saved...");
                }
                else
                {
                    mainform.WriteStatusBar("Saving failed...");
                    MessageBox.Show("Saving failed...");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        void ResetDetailsPane()
        {
            textBoxDetailsDescription.Text = "";
            numericUpDownDetailsID.Value = 0;
            textBoxDetailsDescription.Text = "";
            textBoxDetailsORNumber.Text = "";

            currentExpense = new Expense();

            buttonDetailsUpdate.Enabled = false;
            buttonDetailsDelete.Enabled = false;
            buttonDetailsAdd.Enabled = true;
        }
 public ExpenseViewModel(Expense expense)
 {
     this.expense = expense;
 }