Can anyone perhaps help me with my problem please?
I want to apply security to my winform application but I am stuck..
This is the code I have that will run when the view job button is clicked and I it doesn't work
private void viewJobBtn_Click(object sender, EventArgs e)
{
//Getting the sql connection and selecting columns in database
SqlConnection conn = new SqlConnection("Data Source=10.0.3.45;Initial Catalog=JobbookDatabase;User ID=sa;Password=123");
conn.Open();
SqlCommand cmdDelete = new SqlCommand("SELECT UserType FROM UserAccounts where Username = '" + displayCurrentUserLbl.Text + "'", conn);
cmdDelete.ExecuteNonQuery();
conn.Close();
//the temporary variables used
string type = "3";
try
{
//if type is right, form will continue
if (userAccessLevelLbl.Text.Equals(type))
{
try
{
//Reading the selected row in the current datagrid and then passing it on to the viewing form
String JobID = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[0].Value.ToString();
String Month = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[1].Value.ToString();
String Date = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[2].Value.ToString();
String Office = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[3].Value.ToString();
String JobCode = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[4].Value.ToString();
bool Pending = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[5].Value;
String AllocatedTo = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[6].Value.ToString();
String JobDescription = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[7].Value.ToString();
String InvoiceNumber = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[8].Value.ToString();
String Client = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[9].Value.ToString();
String ContactDetails = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[10].Value.ToString();
String Amount = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[11].Value.ToString();
String Assistants = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[12].Value.ToString();
bool Surveyd = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[13].Value;
bool PlanCompleted = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[14].Value;
bool PlanGivenToClient = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[15].Value;
bool LetterOfApproval = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[16].Value;
bool Invoiced = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[17].Value;
bool Paid = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[18].Value;
String TypeOfJob = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[19].Value.ToString();
bool FoundationStakeout = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[20].Value;
bool BrickWork = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[21].Value;
bool Application = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[22].Value;
bool Approval = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[23].Value;
bool Appeal = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[24].Value;
bool Endorsements = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[25].Value;
bool SGfeesPaid = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[26].Value;
bool SubmitToSG = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[27].Value;
bool PlansReceived = (bool)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[28].Value;
ViewJob vj = new ViewJob(this, JobID, Month, Date, Office, JobCode, Pending, AllocatedTo, JobDescription, InvoiceNumber, Client, ContactDetails, Amount, Assistants, Surveyd, PlanCompleted, PlanGivenToClient, LetterOfApproval, Invoiced, Paid, TypeOfJob, FoundationStakeout, BrickWork, Application, Approval, Appeal, Endorsements, SGfeesPaid, SubmitToSG, PlansReceived);
vj.Show();
}
catch (Exception ex)
{
MessageBox.Show("Select a job first");
}
}
else
{
MessageBox.Show("Access Denied");
}
}
catch (Exception re)
{
MessageBox.Show("Access Denied" + re);
}
}