Пример #1
0
 public Main(myInfo infoFromLogin)
 {
     InitializeComponent();
     userInfo = infoFromLogin;
     //example of use
     lblMessage.Text = userInfo.loginMessage;
 }
Пример #2
0
        public Main( myInfo infoFromLogin)
        {
            InitializeComponent();
            userInfo = infoFromLogin; 
            lblCreateBy.Text = userInfo.loginMessage;
            

        }
Пример #3
0
        private void Btn_login_Click(object sender, EventArgs e)
        {
            SqlConnection myConnection = new SqlConnection();

            myConnection.ConnectionString = ConnectionString;


            try
            {
                //open the connection
                myConnection.Open();
                //Perform the command
                SqlCommand myCommand = new SqlCommand();
                myCommand.CommandText = String.Format(
                    "SELECT * FROM Login WHERE UserId= '{0}' AND Password= '******'",
                    txtusername.Text.Trim().Replace("\"", ",").Replace(";", ""),
                    txtpassword.Text.Trim().Replace("\"", ",").Replace(";", ""));

                myCommand.Connection = myConnection;

                SqlDataReader myDataReader = myCommand.ExecuteReader();
                if (myDataReader.Read())
                {
                    //MessageBox.Show("Logged in!");

                    myInfo infoFromLogin = new myInfo();
                    infoFromLogin.loginMessage = "Welcome!! You are " + txtusername.Text;

                    //pass it on
                    Main newForm = new Main(infoFromLogin);
                    newForm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Not Found!");
                }


                //perform the command
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            finally
            {
                //always close

                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Close();
                }
            }
        }
Пример #4
0
        private void Btn_login_Click(object sender, EventArgs e)
        {
            //SqlConnection myConnection = new SqlConnection();
            //myConnection.ConnectionString = ConnectionString;


            //try
            //{

            //    myConnection.Open();
            //    SqlCommand myCommand = new SqlCommand();
            //    myCommand.CommandText = String.Format(
            //       "SELECT * FROM Login WHERE UserId= '{0}' AND Password= '******'",
            //       txtusername.Text.Trim().Replace("\"", ",").Replace(";", ""),
            //       txtpassword.Text.Trim().Replace("\"", ",").Replace(";", ""));

            //    myCommand.Connection = myConnection;

            //    SqlDataReader myDataReader = myCommand.ExecuteReader();
            //    if (myDataReader.Read())
            //    {
            //        //MessageBox.Show("Logged in!");

            myInfo infoFromLogin = new myInfo();

            infoFromLogin.loginMessage = "admin";


            Main newForm = new Main(infoFromLogin);

            newForm.Show();
            this.Hide();

            //            }
            //            else
            //            {
            //                MessageBox.Show("Invalid User and password");

            //            }



            //        }
            //        catch (Exception ex)
            //        {

            //            MessageBox.Show(ex.Message);
            //        }


            //        finally
            //        {
            //

            //            if (myConnection.State == ConnectionState.Open)
            //            {
            //                myConnection.Close();

            //            }

            //        }
        }