Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi my name is vishal for 10 days i have been breaking my head on how to show each group box along with it's controls inside based on value of integer variable in form in c# windows forms with sql server 2008?

i have 5 group boxes
1) group box1 name:GrpStep3,text:Step 4,enabled:true and visible:true(contains 2buttons,2pictureboxes,1label and 1StrokeScribe control).

GrpStep3 is put on or embed on GrpStep2
2)group box2 name:GrpStep2,text:Step 3,enabled:true,visible:true(contains 1textbox,1button and 1StrokeScribe control).

GrpStep2 is put on or embed on both group boxes GrpDEntry and GrpBarCode
3)group box3 name:GrpDEntry,enabled:true and visible:true(contains 2radiobuttons)

4)group box4 name:GrpBarCode,enabled:true,visible:true
GrpBarCode is put on or embed on GrpStep1(contains 1label and 1textbox control)

5)group box5 name:GrpStep1,enabled:true and visible:true(contains 8labels,2comboboxes,3textboxes and 3datetimepickers)

button1 name:btnNext,text:Next,enabled:true and visible:true
button2 name:btnCancel,text:Cancel,enabled:true and visible:true

Both these 2 buttons are outside group boxes but inside form named:frmDialyzer
Given below is my code in c# with sql server 2008;
C#
private void frmDialyzer_Load(object sender, EventArgs e)
        {
            dtExpDate.MinDate = dtMFRDate.Value;
            dStepIndex = 0;
            GrpStep1.Visible = true;
            GrpStep2.Visible = false;
            GrpStep3.Visible = false;
            dtStartDate.MinDate =dtStartDate.Value; 
        }
frmDialyzer code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DRRS_CSharp
{
    public partial class frmDialyzer : Form
    {
        int dStepIndex;
        int pUserID;
        public frmDialyzer()
        {
            InitializeComponent();          
        }
private void btnNext_Click(object sender, EventArgs e)
        {
            if (GrpDEntry.Visible == true)
            {
                GrpStep1.Text = "Step 2";
                if (radioButton1.Checked == false)
                {
                    GrpBarCode.Visible = false;
                }
                else
                {
                    if (dStepIndex == 0)
                    {
                        string dFieldName = "";
                        Boolean vEmptyB = false;
                        if (cboManufacturer.Text == "")
                        {
                            vEmptyB = true;
                            dFieldName = "Please select a Manufacturer";
                        }
                        else if (cboequipmentType.Text == "")
                        {
                            vEmptyB = true;
                            dFieldName = "Please select size of the dialyzer";
                        }
                        // else if(txtMFRRefNo.Text.ToString().Trim()=="")
                        //{
                        // vEmptyB=true;
                        //dFieldName="Please enter Reference number of the dialyzer";
                        // }
                        else if (txtMFRLotNo.Text.ToString().Trim() == "")
                        {
                            vEmptyB = true;
                            dFieldName = "Please enter Lot No of the dialyzer";
                        }
                        else if (txtPVol.Text.ToString().Trim() == "")
                        {
                            vEmptyB = true;
                            dFieldName = "Please enter packed volume of the dialyzer";
                        }
                        if (vEmptyB == true)
                        {
                            MessageBox.Show(dFieldName + "should not be empty");
                            return;
                        }
                        string dDID;
                        SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }
                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection = conn;
                        cmd.CommandType = CommandType.Text;
                        DataTable dt = new DataTable();
                        int autoGenId = -1;
                        cmd = new SqlCommand("Select max(agn) from dialyser;Select @autoGenId = SCOPE_IDENTITY();", conn);
                        cmd.Parameters.Add("@autoGenId", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.ExecuteNonQuery();
                        autoGenId = Convert.ToInt32(cmd.Parameters["@autoGenId"].Value);
                        if (autoGenId == 0)
                        {
                            dDID = "1";
                        }
                        else
                        {
                            dDID = autoGenId.ToString() + 1;
                        }
                        txtDID.Text = string.Format(00000+txtDID.Text) + dDID;
                        conn.Close();
                        GrpStep1.Visible = false;
                        GrpStep2.Visible = true;
                        GrpStep3.Visible = false;
                        btnNext.Enabled =false;
                        button1.Enabled = false;
                        txtDID.Focus();
                        dStepIndex = 2;
                    }
                    
                        if (dStepIndex == 2)
                    {
                        GrpStep1.Visible = false;
                        GrpStep2.Visible = true;
                        GrpStep3.Visible = false;
                        btnNext.Visible = true;
                        dStepIndex = 3;
                    }
             
                       else if (dStepIndex == 3)
                     {
                         GrpStep1.Visible = false;
                         GrpStep2.Visible = false;
                         GrpStep3.Visible = true;
                         btnNext.Visible = false;
                         btnCancel.Visible = true;
                         btnSearch.Enabled = true;
                         btnSearch.Visible = true;
                         btnAssign.Visible = true;
                         btnAssign.Enabled = true;
                     }
                }
            }
        }

The code above executes till i GrpStep1. But after reaching GrpStep1 and when i press or click btnNext control nothing happens or no process happens


I know that each group box along with it's datas are shown based on value of integer variable name:int dStepIndex in form name:frmDialyzer
When my form loads dStepIndex value is set to 0

I know that i have to do some modifications in my btnNext Click event code in c# but i dont know how to do it!

To be honest with you all. What is wish to accomplish in c# code in btnNext Click event is given below:

1.Form loads for first time i get GrpDEntry and when i check or click radiobutton2(text:Manual) and click btnNext i go to GrpStep1.
2.in GrpStep1 after entering and selecting some datas when i click btnNext i want to go to GrpStep2.
3.In GrpStep2 after entering some datas in that group box when i click btnNext i want to go to GrpStep3.

That's all i want
Tell me what modifications should i need to make in my btnNext click event in c# code? Tell me please?
Can anyone help me please!? Any help or guidance in solving this problem would be greatly appreciated!
Posted
Updated 24-Apr-14 19:20pm
v4
Comments
[no name] 23-Apr-14 7:42am    
Do you really expect people to decipher this?
ZurdoDev 23-Apr-14 7:43am    
This is incredibly hard to read and follow. Please click improve question and remove all irrelevant code and simplify it down to a specific problem so we can help.
Sunasara Imdadhusen 27-May-14 7:47am    
Do not post your entire code over here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900