viewing paste Unknown #15831 | C#

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Entity;
using System.Data.Linq;
 
namespace Nusel.Controllers
{
   public class Authentication 
    {
        public class Connection_action : Connectionstring
        {
            public string Name2;
            public string Matricula;
            public string Lastconn;
            public Controllers.Log_in.Login_actions Login_Action;
            public Controllers.Connectionstring Class_String;
            public MainWindows.Welcome welcome;
            public string Connectionstring;
            public Models.ModelContext context;
 
            public void IsvalidUser(string ID, string Password)
            {
                Connectionstring = Class_String.con;
                if (ID.Length == 0)
                {
                    errormessage.Text = "Enter an ID or Password.";
                    TextBoxID.Focus();
                }
                else if (ID.Length <= 4 || Password.Length <= 4)
                {
                    errormessage.Text = "Invalid ID Or Password.";
                    TextBoxID.Focus();
                }
                else
                {
                    try
                    {
                        using (var db = new Models.ModelContext())
                        {
                            var query = db.Student_LoginModel.Find(ID, Password);
 
                            if (query == null)
                            {
                                var binky = db.Student_LoginModel.Where(u => u.Student_FirstName == ID).FirstOrDefault();
                            }
                            else
                            {
 
                            }
                        }
 
///
///Esto de aqui abajo es lo que trato de simplificar con entity
///
                       // var UsernameQuery = from cust in con.Customers where cust.City == "London" select cust.CompanyName;
                        SqlConnection con = new SqlConnection(Connectionstring);
                        con.Open();
                        SqlCommand cmd = new SqlCommand("Select * from Students where ID='" + ID + "'  and Password_ID='" + Password + "'", con);
                        cmd.CommandType = CommandType.Text;
                        SqlDataAdapter adapter = new SqlDataAdapter();
                        adapter.SelectCommand = cmd;
                        DataSet dataSet = new DataSet();
                        adapter.Fill(dataSet);
                        if (dataSet.Tables[0].Rows.Count > 0)
                        {
                            Name2 = dataSet.Tables[0].Rows[0]["FirstName"].ToString() + " " + dataSet.Tables[0].Rows[0]["LastName"].ToString();
                            Matricula = dataSet.Tables[0].Rows[0]["ID"].ToString();
                            Lastconn = dataSet.Tables[0].Rows[0]["LastLogin"].ToString();
                            welcome.CompleteName.Text = Name2;
                            welcome.LastconnDate.Text = Lastconn;
                            welcome.Matricula.Text = Matricula;
                            Login_Action.Login_action(ID);
                            welcome.Show();
                            Close();
                        }
                        else
                        {
                            errormessage.Text = "Sorry! Please enter existing ID/Password.";
                        }
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                    catch (Exception)
                    {
                        errormessage.Text = "Failed to connect with the server";
                    }
                }
            }
        }
    }
}
Viewed 1046 times, submitted by Dynasty.