Vishal anand

Vishal anand

  • NA
  • 3
  • 2.7k

how to show each group box along based on value of variable

Apr 25 2014 1:37 AM
Hi my name is vishal for past 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:
 
  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;
}
 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
{
string dStepIndex;
int pUserID;
public frmDialyzer()
{
InitializeComponent();
private void btnNext_Click(object sender, EventArgs e)
{
if (GrpDEntry.Visible == true)
{
GrpDEntry.Visible = false;
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;
dStepIndex = "2";
btnNext.Enabled = false;
button1.Enabled = false;
txtDID.Focus();
if (dStepIndex == "2")
{
GrpStep1.Visible = false;
GrpStep2.Visible = false;
GrpStep3.Visible = true;
dStepIndex = "3";
btnNext.Visible = false;
}
}
}
}
 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 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!