private void button2_Click(object sender, EventArgs e) { string loginid = textid.Text; loginid = loginid.Trim(); string password = textpassword.Text; password = password.Trim(); listrole_Click(sender, e); string ip = get_ip_address(); if (listrole.SelectedIndex == 0) { string query = "select roll_no ,password ,name,email,mobile from Student where roll_no ='" + loginid + "' and password='******'"; SqlConnection con = new SqlConnection(connectionstring); // con.Open(); SqlDataAdapter da = new SqlDataAdapter(query, con); DataSet ds = new DataSet(); da.Fill(ds); try { string check_prev_login = "******" + loginid + "' and status = " + 1 + " and ip_address<>'" + ip.Trim() + "'"; SqlDataAdapter da_check = new SqlDataAdapter(check_prev_login, con); DataSet ds_check = new DataSet(); da_check.Fill(ds_check); if (ds_check.Tables[0].Rows.Count > 0) { MessageBox.Show("You Previously Logged in With this IP " + ds_check.Tables[0].Rows[0][2].ToString().Trim()); } } catch (Exception ee) { MessageBox.Show(ee.Message); } if (ds.Tables[0].Rows.Count == 1) { //MessageBox.Show("You have succesfully Logged In"); user_name = ds.Tables[0].Rows[0][2].ToString(); login_id = loginid; role_id = "Student"; //MessageBox.Show("welcome " + ds.Tables[0].Rows[0][2].ToString() + " " + ds.Tables[0].Rows[0][1].ToString() + " " + ds.Tables[0].Rows[0][4].ToString() + " " + ds.Tables[0].Rows[0][3].ToString() + " " + ds.Tables[0].Rows[0][0].ToString() + " " + "Student"); try { Offline_Chat.user_info tem = new user_info(); //tem.Info(ds.Tables[0].Rows[0][2].ToString(), ds.Tables[0].Rows[0][1].ToString(), ds.Tables[0].Rows[0][4].ToString(), ds.Tables[0].Rows[0][3].ToString(), ds.Tables[0].Rows[0][0].ToString(), Form1.role_id.ToString().Trim()); //MessageBox.Show(tem.name); string update_status = "update Student_status set status = " + 1 + " , ip_address='" + ip + "' where roll_no= '" + ds.Tables[0].Rows[0][0].ToString() + "'"; //con.Open(); SqlDataAdapter da_update = new SqlDataAdapter(update_status, con); DataSet ds_update = new DataSet(); da_update.Fill(ds_update); this.Hide(); Home f3 = new Home(); f3.ShowDialog(); } catch (Exception ee) { MessageBox.Show(ee.Message); } } else { MessageBox.Show("Provided Information is wrong, Try Again!!"); } } else if (listrole.SelectedIndex == 1) { string query = "select user_id ,password , name,email_id, mobile_no from Instructor where user_id ='" + loginid + "' and password='******'"; SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlDataAdapter da = new SqlDataAdapter(query, con); DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count == 1) { try { MessageBox.Show("You have succesfully Logged In"); MessageBox.Show("welcome " + ds.Tables[0].Rows[0][1].ToString()); user_name = ds.Tables[0].Rows[0][2].ToString(); login_id = ds.Tables[0].Rows[0][0].ToString(); role_id = "Instructor"; this.Hide(); con.Close(); // Offline_Chat.user_info.Current.Info(ds.Tables[0].Rows[0][2].ToString(), ds.Tables[0].Rows[0][1].ToString(), ds.Tables[0].Rows[0][4].ToString(), ds.Tables[0].Rows[0][3].ToString(), ds.Tables[0].Rows[0][0].ToString(), Form1.role_id.ToString().Trim()); string update_status = "update Instructor_status set status = " + 1 + " , ip_address= '" + ip + "' where user_id= '" + ds.Tables[0].Rows[0][0].ToString() + "'"; //con.Open(); SqlDataAdapter da_update = new SqlDataAdapter(update_status, con); DataSet ds_update = new DataSet(); da_update.Fill(ds_update); Home f3 = new Home(); f3.ShowDialog(); } catch (Exception ee) { // MessageBox.Show(ee.Message); } } else { MessageBox.Show("Provided Information is wrong, Try Again!!"); } } else if (listrole.SelectedIndex == 2) { string query = "select login_id ,password,name from admin_status where Username ='******' and password='******'"; SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlDataAdapter da = new SqlDataAdapter(query, con); DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count == 1) { MessageBox.Show("You have succesfully Logged In"); MessageBox.Show("welcome " + ds.Tables[0].Rows[0][2].ToString()); user_name = ds.Tables[0].Rows[0][2].ToString(); login_id = ds.Tables[0].Rows[0][0].ToString(); this.Hide(); Home f3 = new Home(); f3.ShowDialog(); string update_status = "update admin_status set status =" + 1 + " where login_id= '" + ds.Tables[0].Rows[0][0].ToString() + "',"; con.Open(); SqlDataAdapter da_update = new SqlDataAdapter(update_status, con); DataSet ds_update = new DataSet(); da_update.Fill(ds_update); } else { MessageBox.Show("Provided Information is wrong, Try Again!!"); } } else { MessageBox.Show("You have not selected any role , Please select a role"); } }
private void button1_Click(object sender, EventArgs e) { string db_name = name.Text.Trim(); string db_roll_no = roll_number.Text.Trim(); string db_password = password.Text.Trim(); string db_comfirm_password = comfirm_password.Text.Trim(); Int64 db_mobile = Int64.Parse(mobile_no.Text.Trim()); string db_email = email_id.Text.Trim(); role_Click(sender, e); string ip = get_ip_address(); MessageBox.Show("Your Ip address is" + ip); if (db_name.Length == 0 || db_roll_no.Length == 0 || db_password.Length == 0 || db_comfirm_password.Length == 0 || db_mobile.Equals(0) || db_email.Length == 0) { MessageBox.Show("empty field"); } if (role.SelectedIndex == 0) { //MessageBox.Show("hello"); try { label3.Text = "Roll Number"; string query = "insert into Student values('" + db_name + "','" + db_roll_no + "','" + db_password + "','" + db_comfirm_password + "','" + db_email + "'," + db_mobile + ")"; string update_query = "insert into Student_status values('" + db_name + "','" + db_roll_no + "'," + 1 + ",'" + ip + "')"; SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlDataAdapter da = new SqlDataAdapter(query, con); DataSet ds = new DataSet(); da.Fill(ds); //Offline_Chat.user_info.Current.Info(db_name, db_password, db_mobile.ToString(), db_email, db_roll_no, Form1.role_id.ToString().Trim()); //con.Open(); SqlDataAdapter da_update = new SqlDataAdapter(update_query, con); DataSet ds_update = new DataSet(); da_update.Fill(ds_update); con.Close(); roll_number.Visible = true; label3.Visible = true; Form1.user_name = db_name; Form1.login_id = db_roll_no; MessageBox.Show("Succesfully Register"); Form1.role_id = "Student"; Home f3 = new Home(); f3.ShowDialog(); this.Hide(); } catch (NullReferenceException ex) { MessageBox.Show("Processor Usage" + ex.Message); //MessageBox.Show(ex.Message); } } else if (role.SelectedIndex == 1) { try { //MessageBox.Show(db_roll_no); string query = "insert into Instructor values('" + db_name + "','" + db_password + "','" + db_email + "','" + db_mobile + "','" + db_roll_no + "')"; string update_query = "insert into Instructor_status values('" + db_roll_no + "'," + 1 + ",'" + ip + "')"; SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlDataAdapter da = new SqlDataAdapter(query, con); DataSet ds = new DataSet(); da.Fill(ds); //Offline_Chat.user_info.Current.Info(db_name, db_password, db_mobile.ToString(), db_email, db_roll_no, Form1.role_id.ToString().Trim()); //con.Open(); SqlDataAdapter da_update = new SqlDataAdapter(update_query, con); DataSet ds_update = new DataSet(); da_update.Fill(ds_update); con.Close(); Form1.user_name = db_name; Form1.login_id = db_roll_no; MessageBox.Show("Succesfully Register"); Form1.role_id = "Instructor"; Home f3 = new Home(); f3.ShowDialog(); this.Hide(); } catch (NullReferenceException ex) { //MessageBox.Show("Processor Usage" + ex.Message); //MessageBox.Show(ex.Message); } } else { MessageBox.Show("You have not selected any role , Please select a role"); } }