Beispiel #1
0
 private void btnAddCustomers_Click(object sender, EventArgs e)
 {
     addCustomer = new AddCustomers();
     //Passing form name to identify already opened form to keep using of one form,
     //reference to object and type of form to switch between Add and Edit form view and behavior
     openWindow("AddCustomers", ref addCustomer, "Add");
     //Set customer ID to update customer information in the form
     addCustomer.setID(-1);
 }
Beispiel #2
0
        private void btnEditCustomers_Click(object sender, EventArgs e)
        {
            //Customer id in database
            int id;

            int.TryParse(dgvCustomers.Rows[dgvCustomers.SelectedRows[0].Index].Cells[0].Value.ToString(), out id);
            addCustomer = new AddCustomers();
            openWindow("AddCustomers", ref addCustomer, "Edit");
            addCustomer.setID(id);
        }
Beispiel #3
0
        private void openWindow(string formName, ref AddCustomers form, string type)
        {
            //If form is not exists in application
            if (((Form)Application.OpenForms[formName]) == null)
            {
                form.MdiParent = (Form)Application.OpenForms["WarehouseSystem"];
                if (type == "Add")
                {
                    form.setType("Add");
                }
                else
                {
                    form.setType("Edit");
                }
                form.TabCtrl = warehouse.tabControl1;
                tp           = new TabPage();
                //Add a Tabpage and enables it
                tp.Parent = warehouse.tabControl1;
                tp.Text   = form.Text;
                tp.Show();

                //child Form will now hold a reference value to a tabpage
                form.TabPag = tp;

                //Activate the newly created Tabpage
                warehouse.tabControl1.SelectedTab = tp;
                warehouse.tabControl1.Visible     = true;
                form.Show();
            }
            //If this form already opened
            else
            {
                form = (AddCustomers)Application.OpenForms[formName];
                if (type == "Add")
                {
                    form.setType("Add");
                }
                else
                {
                    form.setType("Edit");
                }
                form.Focus();
                tp.Text = form.Text;
            }
        }