Exemplo n.º 1
0
 public CompaniesForm(MainForm form)
 {
     InitializeComponent();
     mainform = form;
     db = mainform.DataAppCore;
     currentModel = new Company();
     //set data grid settings
     ControlFactory.SetDataGridSettings(this.dataGridViewMainSearchResult);
 }
        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);
        }
Exemplo n.º 3
0
 public CompanyViewModel(Company company)
 {
     this.company = company;
 }
Exemplo n.º 4
0
        private void EditSelectedObject()
        {
            //update
            if (this.contextMenuStripGridView.Items[0].Selected)
            {
                int selectedRowId = 0;

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

                //fetch data
                this.currentModel = db.CompanyController.Get(selectedRowId);

                MapObjectToControls();
                tabControlMain.SelectedIndex = 1;
            }

            //add
            if(this.contextMenuStripGridView.Items[1].Selected)
            {
                ResetDetailsPane();
                tabControlMain.SelectedIndex = 1;
            }
        }
Exemplo n.º 5
0
        private void SaveDataToDB(bool isUpdate = false)
        {
            try
            {
                if (isUpdate == false)
                    currentModel = new Company();

                //map controls to object
                MapControlsToObject();

                //validate
                if (string.IsNullOrEmpty(currentModel.Name) || string.IsNullOrEmpty(currentModel.Description))
                {
                    MessageBox.Show("Please check empty input fields.");
                    return;
                }

                bool result = false;

                if (isUpdate == false)
                    result = db.CompanyController.Add(currentModel);
                else
                    result = db.CompanyController.Update(currentModel);

                if (result)
                {
                    if (isUpdate == false)
                        currentModel = db.CompanyController.Get(currentModel.Id);

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

                throw;
            }
        }
Exemplo n.º 6
0
        void ResetDetailsPane()
        {
            textBoxDetailsDescription.Text = "";
            numericUpDownDetailsID.Value = 0;
            textBoxDetailsDescription.Text = "";
            textBoxDetailsName.Text = "";
            textBoxDetailsContact.Text = "";
            textBoxDetailsEmail.Text = "";

            currentModel = new Company();

            buttonDetailsUpdate.Visible = false;
            buttonDetailsDelete.Visible = false;

            buttonDetailsUpdate.Enabled = false;
            buttonDetailsDelete.Enabled = false;
            buttonDetailsAdd.Enabled = true;
        }