Questions

Mdi application development ... is this the right way ?

Tags:
+
0 Votes
Locked

Mdi application development ... is this the right way ?

navdeepz
Hi,
I am making this new project for a friend. Its an ERP windows app. using C# .

Now i am using menu bar in a MDI form (main form) and every menu option opens a specific child form. the problem is i want it to look more like SDI i.e. every time i click on some other option, the currently active child form closes (not hides or minimizes). So for that i am coding my MDI form .. to always check if a child form is active .. and close it (if it is active) and then open the new child form that was asked for. Hence making it more like SDI .

Well i thinks it not really the correct way to go about it because handling 2-3 forms is fine but handling around 22 forms is kinda hard and the number of forms just seem to add up ... please help !

thanks
Navdeep
  • +
    0 Votes
    cmiller5400

    In the MDI parent form, there should be a collection (MDIChildren) that houses all the children. You just need to check that collection and close the children from there.

    +
    0 Votes
    navdeepz

    This is what my coding looks like right now ..


    namespace HSN
    {
    public partial class HSN_main : Form
    {
    public static int edf=0,eaf =0,caf = 0,pf =0,vsf=0,veaf = 0,vedf=0,ndf=0,eef =0,eedf =0,def = 0;
    public static int npf = 0,npo = 0,epd=0,vpd=0,epo=0,df=0,cpo=0,rf=0,vpo=0;
    public static int nlf = 0,raf=0;

    public static int auth;

    newpart_form f1 ;
    newpoorder_form f2 ;
    editpart_form f3;
    viewpart_form f4;
    login_form lf;
    dispatch_form f5;
    cancel_po_form f6;
    reinstate_form f7;
    editpo_form f8;
    view_po_Form f9;

    emp_detail_form f10;
    emp_atd_form f11;
    calculate_att_form f12;
    pay_form f13;
    View_empsal_form f14;
    view_emp_att_form f15;
    view_emp_detail_form f16;
    new_designation_form f17;
    edit_emp_form f18;
    edit_Desg_form f19;
    delete_emp_form f20;

    new_login_form f21;
    retrieve_form f22;


    public static void setauth(int n)
    {
    auth = n;
    }

    public HSN_main()
    {
    InitializeComponent();
    }


    // to show login form while while loading main HSN
    private void HSN_main_Load(object sender, EventArgs e)
    {
    lf = new login_form();
    lf.ShowDialog();

    }

    private void partDetailToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    npf = 1;
    f1 = new newpart_form();
    f1.MdiParent = this;
    f1.Show();
    }

    private void pOOrderToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    npo = 1;
    f2 = new newpoorder_form();
    f2.MdiParent = this;
    f2.Show();
    }

    // when ever a form is clicked the other form that is open is to be closed
    public void closeform()
    {
    if (npf == 1)
    {
    f1.Close();
    }
    if (npo == 1)
    {
    f2.Close();
    }
    if (epd == 1)
    {
    f3.Close();
    }
    if (vpd == 1)
    {
    f4.Close();
    }
    if (df == 1)
    {
    f5.Close();
    }
    if (cpo == 1)
    {
    f6.Close();
    }
    if (rf == 1)
    {
    f7.Close();
    }
    if (epo == 1)
    {
    f8.Close();
    }
    if (vpo == 1)
    {
    f9.Close();
    }
    if (edf == 1)
    {
    f10.Close();
    }
    if (eaf == 1)
    {
    f11.Close();
    }
    if (caf == 1)
    {
    f12.Close();
    }
    if (pf == 1)
    {
    f13.Close();
    }
    if (vsf == 1)
    {
    f14.Close();
    }
    if (veaf == 1)
    {
    f15.Close();
    }
    if (vedf == 1)
    {
    f16.Close();
    }
    if (ndf == 1)
    {
    f17.Close();
    }
    if (eef == 1)
    {
    f18.Close();
    }
    if (eedf == 1)
    {
    f19.Close();
    }
    if (def == 1)
    {
    f20.Close();
    }
    if (nlf == 1)
    {
    f21.Close();
    }
    if (raf == 1)
    {
    f22.Close();
    }
    }

    private void partDetailToolStripMenuItem1_Click(object sender, EventArgs e)
    {
    closeform();
    epd = 1;
    f3 = new editpart_form ();
    f3.MdiParent = this;
    f3.Show();
    }

    private void partDetailsToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    vpd = 1;
    f4 = new viewpart_form();
    f4.MdiParent = this;
    f4.Show();
    }

    // --- setting up rights for authority

    private void setauth()
    {
    switch (auth)
    {
    case 0:
    {
    menuStrip1.Enabled = true;
    dmiToolStripMenuItem.Enabled = true;

    break;
    }
    case 1:
    {
    menuStrip1.Enabled = true;
    dmiToolStripMenuItem.Enabled = false;
    break;
    }
    case 2:
    {
    menuStrip1.Enabled = true;
    dmiToolStripMenuItem.Enabled = false;
    salaryMgmtToolStripMenuItem.Enabled = false;
    partDetailToolStripMenuItem1.Enabled = false;
    pOOrderToolStripMenuItem1.Enabled = false;
    cancelPOToolStripMenuItem.Enabled = false;
    reinToolStripMenuItem.Enabled = false;
    break;
    }
    default:
    {
    menuStrip1.Enabled = false;
    break;
    }
    }
    }


    private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    auth = 0;
    setauth();
    lf = new login_form();
    lf.ShowDialog();
    }


    private void dmiToolStripMenuItem_MouseEnter(object sender, EventArgs e)
    {
    setauth();
    }

    private void startToolStripMenuItem_MouseEnter(object sender, EventArgs e)
    {
    setauth();
    }

    private void dispatchToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    df = 1;
    f5 = new dispatch_form();
    f5.MdiParent = this;
    f5.Show();
    }

    private void cancelPOToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    cpo = 1;
    f6 = new cancel_po_form();
    f6.MdiParent = this;
    f6.Show();
    }

    private void reinToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    rf = 1;
    f7 = new reinstate_form();
    f7.MdiParent = this;
    f7.Show();
    }

    private void pOOrderToolStripMenuItem1_Click(object sender, EventArgs e)
    {
    closeform();
    epo = 1;
    f8 = new editpo_form();
    f8.MdiParent = this;
    f8.Show();
    }

    private void pOOrderToolStripMenuItem2_Click(object sender, EventArgs e)
    {
    closeform();
    vpo = 1;
    f9 = new view_po_Form();
    f9.MdiParent = this;
    f9.Show();
    }

    private void employeeToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    edf = 1;
    f10 = new emp_detail_form();
    f10.MdiParent = this;
    f10.Show();
    }

    private void attendanceToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    eaf = 1;
    f11 = new emp_atd_form();
    f11.MdiParent = this;
    f11.Show();
    }

    private void salaryToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    caf = 1;
    f12 = new calculate_att_form();
    f12.MdiParent = this;
    f12.Show();

    }

    private void paySalaryToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    pf = 1;
    f13 = new pay_form();
    f13.MdiParent = this;
    f13.Show();
    }

    private void employeeSalaryToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    vsf = 1;
    f14 = new View_empsal_form();
    f14.MdiParent = this;
    f14.Show();
    }

    private void employeeAttendanceToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    veaf = 1;
    f15 = new view_emp_att_form();
    f15.MdiParent = this;
    f15.Show();
    }

    private void employeeDetailsToolStripMenuItem1_Click(object sender, EventArgs e)
    {
    closeform();
    vedf = 1;
    f16 = new view_emp_detail_form();
    f16.MdiParent = this;
    f16.Show();
    }

    private void designationToolStripMenuItem1_Click(object sender, EventArgs e)
    {
    closeform();
    ndf= 1;
    f17 = new new_designation_form();
    f17.MdiParent = this;
    f17.Show();
    }

    private void employeeDetailsToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    eef = 1;
    f18 = new edit_emp_form();
    f18.MdiParent = this;
    f18.Show();
    }

    private void designationToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    eedf = 1;
    f19 = new edit_Desg_form();
    f19.MdiParent = this;
    f19.Show();
    }

    private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    def = 1;
    f20 = new delete_emp_form();
    f20.MdiParent = this;
    f20.Show();
    }

    private void newLoginToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    nlf = 1;
    f21 = new new_login_form();
    f21.MdiParent = this;
    f21.Show();
    }

    private void retrievePasswordToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    raf=1;
    f22 = new retrieve_form();
    f22.MdiParent = this;
    f22.Show();
    }
    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
    Application.Exit();
    }

    }
    }

    +
    0 Votes
    navdeepz

    So basically i use those static int to basically know if the form is currently open or not .. if its open the closeform() checks for the open forms .. and closes it .. before a new form opens.

  • +
    0 Votes
    cmiller5400

    In the MDI parent form, there should be a collection (MDIChildren) that houses all the children. You just need to check that collection and close the children from there.

    +
    0 Votes
    navdeepz

    This is what my coding looks like right now ..


    namespace HSN
    {
    public partial class HSN_main : Form
    {
    public static int edf=0,eaf =0,caf = 0,pf =0,vsf=0,veaf = 0,vedf=0,ndf=0,eef =0,eedf =0,def = 0;
    public static int npf = 0,npo = 0,epd=0,vpd=0,epo=0,df=0,cpo=0,rf=0,vpo=0;
    public static int nlf = 0,raf=0;

    public static int auth;

    newpart_form f1 ;
    newpoorder_form f2 ;
    editpart_form f3;
    viewpart_form f4;
    login_form lf;
    dispatch_form f5;
    cancel_po_form f6;
    reinstate_form f7;
    editpo_form f8;
    view_po_Form f9;

    emp_detail_form f10;
    emp_atd_form f11;
    calculate_att_form f12;
    pay_form f13;
    View_empsal_form f14;
    view_emp_att_form f15;
    view_emp_detail_form f16;
    new_designation_form f17;
    edit_emp_form f18;
    edit_Desg_form f19;
    delete_emp_form f20;

    new_login_form f21;
    retrieve_form f22;


    public static void setauth(int n)
    {
    auth = n;
    }

    public HSN_main()
    {
    InitializeComponent();
    }


    // to show login form while while loading main HSN
    private void HSN_main_Load(object sender, EventArgs e)
    {
    lf = new login_form();
    lf.ShowDialog();

    }

    private void partDetailToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    npf = 1;
    f1 = new newpart_form();
    f1.MdiParent = this;
    f1.Show();
    }

    private void pOOrderToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    npo = 1;
    f2 = new newpoorder_form();
    f2.MdiParent = this;
    f2.Show();
    }

    // when ever a form is clicked the other form that is open is to be closed
    public void closeform()
    {
    if (npf == 1)
    {
    f1.Close();
    }
    if (npo == 1)
    {
    f2.Close();
    }
    if (epd == 1)
    {
    f3.Close();
    }
    if (vpd == 1)
    {
    f4.Close();
    }
    if (df == 1)
    {
    f5.Close();
    }
    if (cpo == 1)
    {
    f6.Close();
    }
    if (rf == 1)
    {
    f7.Close();
    }
    if (epo == 1)
    {
    f8.Close();
    }
    if (vpo == 1)
    {
    f9.Close();
    }
    if (edf == 1)
    {
    f10.Close();
    }
    if (eaf == 1)
    {
    f11.Close();
    }
    if (caf == 1)
    {
    f12.Close();
    }
    if (pf == 1)
    {
    f13.Close();
    }
    if (vsf == 1)
    {
    f14.Close();
    }
    if (veaf == 1)
    {
    f15.Close();
    }
    if (vedf == 1)
    {
    f16.Close();
    }
    if (ndf == 1)
    {
    f17.Close();
    }
    if (eef == 1)
    {
    f18.Close();
    }
    if (eedf == 1)
    {
    f19.Close();
    }
    if (def == 1)
    {
    f20.Close();
    }
    if (nlf == 1)
    {
    f21.Close();
    }
    if (raf == 1)
    {
    f22.Close();
    }
    }

    private void partDetailToolStripMenuItem1_Click(object sender, EventArgs e)
    {
    closeform();
    epd = 1;
    f3 = new editpart_form ();
    f3.MdiParent = this;
    f3.Show();
    }

    private void partDetailsToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    vpd = 1;
    f4 = new viewpart_form();
    f4.MdiParent = this;
    f4.Show();
    }

    // --- setting up rights for authority

    private void setauth()
    {
    switch (auth)
    {
    case 0:
    {
    menuStrip1.Enabled = true;
    dmiToolStripMenuItem.Enabled = true;

    break;
    }
    case 1:
    {
    menuStrip1.Enabled = true;
    dmiToolStripMenuItem.Enabled = false;
    break;
    }
    case 2:
    {
    menuStrip1.Enabled = true;
    dmiToolStripMenuItem.Enabled = false;
    salaryMgmtToolStripMenuItem.Enabled = false;
    partDetailToolStripMenuItem1.Enabled = false;
    pOOrderToolStripMenuItem1.Enabled = false;
    cancelPOToolStripMenuItem.Enabled = false;
    reinToolStripMenuItem.Enabled = false;
    break;
    }
    default:
    {
    menuStrip1.Enabled = false;
    break;
    }
    }
    }


    private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    auth = 0;
    setauth();
    lf = new login_form();
    lf.ShowDialog();
    }


    private void dmiToolStripMenuItem_MouseEnter(object sender, EventArgs e)
    {
    setauth();
    }

    private void startToolStripMenuItem_MouseEnter(object sender, EventArgs e)
    {
    setauth();
    }

    private void dispatchToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    df = 1;
    f5 = new dispatch_form();
    f5.MdiParent = this;
    f5.Show();
    }

    private void cancelPOToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    cpo = 1;
    f6 = new cancel_po_form();
    f6.MdiParent = this;
    f6.Show();
    }

    private void reinToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    rf = 1;
    f7 = new reinstate_form();
    f7.MdiParent = this;
    f7.Show();
    }

    private void pOOrderToolStripMenuItem1_Click(object sender, EventArgs e)
    {
    closeform();
    epo = 1;
    f8 = new editpo_form();
    f8.MdiParent = this;
    f8.Show();
    }

    private void pOOrderToolStripMenuItem2_Click(object sender, EventArgs e)
    {
    closeform();
    vpo = 1;
    f9 = new view_po_Form();
    f9.MdiParent = this;
    f9.Show();
    }

    private void employeeToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    edf = 1;
    f10 = new emp_detail_form();
    f10.MdiParent = this;
    f10.Show();
    }

    private void attendanceToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    eaf = 1;
    f11 = new emp_atd_form();
    f11.MdiParent = this;
    f11.Show();
    }

    private void salaryToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    caf = 1;
    f12 = new calculate_att_form();
    f12.MdiParent = this;
    f12.Show();

    }

    private void paySalaryToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    pf = 1;
    f13 = new pay_form();
    f13.MdiParent = this;
    f13.Show();
    }

    private void employeeSalaryToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    vsf = 1;
    f14 = new View_empsal_form();
    f14.MdiParent = this;
    f14.Show();
    }

    private void employeeAttendanceToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    veaf = 1;
    f15 = new view_emp_att_form();
    f15.MdiParent = this;
    f15.Show();
    }

    private void employeeDetailsToolStripMenuItem1_Click(object sender, EventArgs e)
    {
    closeform();
    vedf = 1;
    f16 = new view_emp_detail_form();
    f16.MdiParent = this;
    f16.Show();
    }

    private void designationToolStripMenuItem1_Click(object sender, EventArgs e)
    {
    closeform();
    ndf= 1;
    f17 = new new_designation_form();
    f17.MdiParent = this;
    f17.Show();
    }

    private void employeeDetailsToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    eef = 1;
    f18 = new edit_emp_form();
    f18.MdiParent = this;
    f18.Show();
    }

    private void designationToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    eedf = 1;
    f19 = new edit_Desg_form();
    f19.MdiParent = this;
    f19.Show();
    }

    private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    def = 1;
    f20 = new delete_emp_form();
    f20.MdiParent = this;
    f20.Show();
    }

    private void newLoginToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    nlf = 1;
    f21 = new new_login_form();
    f21.MdiParent = this;
    f21.Show();
    }

    private void retrievePasswordToolStripMenuItem_Click(object sender, EventArgs e)
    {
    closeform();
    raf=1;
    f22 = new retrieve_form();
    f22.MdiParent = this;
    f22.Show();
    }
    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
    Application.Exit();
    }

    }
    }

    +
    0 Votes
    navdeepz

    So basically i use those static int to basically know if the form is currently open or not .. if its open the closeform() checks for the open forms .. and closes it .. before a new form opens.