First of all, I'm new in c#, a newbie. Basically I have 2 forms, one is the "main" form, and the second is the "prompt" form.
- The "main" form has a groupbox and a button in it, in which the groupbox is not visible by default (visibility = false).
- When the button in "main" prompt is click, the "prompt" form will show.
- The "prompt" form has a textbox in it, which the user will type his password in it.
- If the user click the button in "prompt" form and inputted the correct password in textbox, the groupbox in "main" form will be visible.
Here is my code in my "main" form:
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;
namespace User_Interface
{
public partial class HomePage : Form
{
public HomePage()
{
InitializeComponent();
}
private void sECRETQUESTIONToolStripMenuItem_Click(object sender, EventArgs e)
{
SecQuestionPrompt aac = new SecQuestionPrompt();
aac.Show();
//this will show my "prompt" form
}
}
}
And this is my code in my "prompt" form:
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.Sql;
using System.Data.SqlClient;
namespace User_Interface
{
public partial class UserPassPrompt : Form
{
public UserPassPrompt()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string emnconnection = "data source = -L-EMN-L-\\SQLExpress; database = buildingmanagement; integrated security = true";
SqlConnection sqlconn = new SqlConnection(emnconnection);
SqlCommand sqlcomm = new SqlCommand("select * from tbl_admin where admin_pass = '" + this.textBox1.Text + "' ;", sqlconn);
SqlDataReader sqlreader;
sqlconn.Open();
sqlreader = sqlcomm.ExecuteReader();
int count = 0;
while (sqlreader.Read())
{
count = count + 1;
}
if (count == 1)
{
//in this part, i don't know how to call or make the groupbox visible...
this.Hide();
HomePage aaa = new HomePage();
}
else
MessageBox.Show("Password");
sqlconn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
to be precise in this part:
//in this part, i don't know how to call or make the groupbox visible...
//Homepage is my "main" form.. and the name of my groupbox is "grpBox_userndpass"
this.Hide();
HomePage aaa = new HomePage();
Sorry for the long post guys... T_T