Ejemplo n.º 1
0
        private void editCompanyDataButton_Click(object sender, EventArgs e)
        {
            if (companyDataGridView.SelectedRows.Count > 0)
            {
                int  index = companyDataGridView.SelectedRows[0].Index;
                int  id;
                bool converted = int.TryParse(companyDataGridView[0, index].Value.ToString(), out id);
                if (!converted)
                {
                    return;
                }

                var     companies = from t in controller.Elements where t.ID == id select t;
                Company company   = companies.First();

                CompanyForm companyAddForm = new CompanyForm();
                companyAddForm.companyFullNameTextBox.Text  = company.FullName;
                companyAddForm.companyShortNameTextBox.Text = company.ShortName;
                companyAddForm.companyTINTextBox.Text       = company.TIN;

                DialogResult dialogResult = companyAddForm.ShowDialog(this);

                if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }

                company.FullName  = companyAddForm.companyFullNameTextBox.Text;
                company.ShortName = companyAddForm.companyShortNameTextBox.Text;
                company.TIN       = companyAddForm.companyTINTextBox.Text;

                controller.UpdateElement(company);
                companyDataGridView.DataSource = controller.Elements;
            }
        }
Ejemplo n.º 2
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            CompanyForm form = new CompanyForm(-1);

            form.ShowDialog();
            fillGrid();
        }
Ejemplo n.º 3
0
        public override void edit(int id)
        {
            Company company = (from p in db.Company
                               where p.Id == id
                               select p).FirstOrDefault();

            CompanyForm companyViewer = new CompanyForm();

            companyViewer.mainEntity = company;
            companyViewer.controller = this;

            if (companyViewer.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                db.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        private void addCompanyDataButton_Click(object sender, EventArgs e)
        {
            CompanyForm  companyAddForm = new CompanyForm();
            DialogResult dialogResult   = companyAddForm.ShowDialog(this);

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }

            var newCompany = new Company(companyAddForm.companyFullNameTextBox.Text,
                                         companyAddForm.companyShortNameTextBox.Text,
                                         companyAddForm.companyTINTextBox.Text);

            controller.AddElement(newCompany);
            companyDataGridView.DataSource = controller.Elements;
        }
Ejemplo n.º 5
0
        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            DataGridView gv = (DataGridView)sender;

            if (gv.SelectedCells.Count > 0)
            {
                DataGridViewColumn col = gv.Columns[gv.SelectedCells[0].ColumnIndex];

                if (col.DataGridView.SelectedCells.Count > 0 && gv.SelectedCells[0].Selected)
                {
                    DataGridViewRow dr = gv.SelectedCells[0].OwningRow;
                    int             id = -1;
                    id = int.Parse(dr.Cells[CompanyEntity.FIELD_ID].Value.ToString());
                    CompanyForm form = new CompanyForm(id, _readOnly);
                    form.ShowDialog();
                    fillGrid();
                }
            }
        }
Ejemplo n.º 6
0
        public override void add()
        {
            try
            {
                Company     company       = new Company();     // initilize entity
                CompanyForm companyViewer = new CompanyForm(); //
                companyViewer.mainEntity = company;
                companyViewer.controller = this;

                if (companyViewer.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    db.Company.Add(company);
                    db.SaveChanges();
                }
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }