示例#1
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     validateAll();
     if(isValid == 0)
     {
         SQLStatement con = new SQLStatement(SLS.Static.Server, SLS.Static.Database);
         String sql = "SELECT UserID, [password]  FROM [USER] where username COLLATE Latin1_General_CS_AS = @username";
         Dictionary<String, Object> parameters = new Dictionary<string, object>();
         parameters.Add("@username", txtUser.Text);
         SqlDataReader reader = con.executeReader(sql, parameters);
         if (reader.HasRows)
         {
             reader.Read();
             if(txtPass.Text == Convert.ToString(reader.GetString(1)))
             {
                 MessageBox.Show("Login success.", "Logged In", MessageBoxButtons.OK);
                 this.Hide();
                 SLS.Static.UserID = Convert.ToInt32(reader.GetInt32(0));
                 var Menu = new MainMenu();
                 Menu.Closed += (s, args) => this.Close();
                 Menu.Show();
             }
             else
             {
                 e2.Visible = true;
                 MessageBox.Show("The password you entered is incorrect.", "Not Logged In", MessageBoxButtons.OK);
             }
         }
         else
         {
             e1.Visible = true;
             e2.Visible = true;
             MessageBox.Show("The username you entered does not belong to any account.", "Not Logged In", MessageBoxButtons.OK);
         }
     }
     else
     {
         MessageBox.Show("The username or password is incorrect.", "Not Logged In", MessageBoxButtons.OK);
     }
 }
示例#2
0
        private void getInfos()
        {
            try
            {
                SQLStatement con = new SQLStatement(SLS.Static.Server, SLS.Static.Database);
                String sql = "SELECT [USER].fName, [USER].mName, [USER].lName, COMPANY.companyName, COMPANY.street, COMPANY.brgy, COMPANY.city, COMPANY.mobileNoCountryCode, COMPANY.mobileNo, COMPANY.teleNoCountryCode, COMPANY.teleNo FROM [USER], COMPANY where [USER].UserID = @UserID";
                Dictionary<String, Object> parameters = new Dictionary<string, object>();
                parameters.Add("@UserID", SLS.Static.UserID);
                SqlDataReader reader = con.executeReader(sql, parameters);
                while (reader.Read())
                {
                    try
                    {
                        user = string.Concat(user, reader.GetString(0));
                    }
                    catch(Exception)
                    {

                    }
                    try
                    {
                        user = string.Concat(user, ' ');
                        user = string.Concat(user, reader.GetString(1));
                    }
                    catch (Exception)
                    {

                    }
                    try
                    {
                        user = string.Concat(user, ' ');
                        user = string.Concat(user, reader.GetString(2));
                    }
                    catch (Exception)
                    {

                    }
                    lblUser.Text = user;
                    try
                    {
                        compName = string.Concat(compName, reader.GetString(3));
                    }
                    catch (Exception)
                    {

                    }
                    lblCompName.Text = compName;
                    try
                    {
                        compAddress = string.Concat(compAddress, reader.GetString(4));
                    }
                    catch (Exception)
                    {

                    }
                    try
                    {
                        compAddress = string.Concat(compAddress, ", ");
                        compAddress = string.Concat(compAddress, reader.GetString(5));
                    }
                    catch (Exception)
                    {

                    }
                    try
                    {
                        compAddress = string.Concat(compAddress, ", ");
                        compAddress = string.Concat(compAddress, reader.GetString(6));
                    }
                    catch (Exception)
                    {

                    }
                    lblCompAddress.Text = compAddress;
                    try
                    {
                        compContact = string.Concat(compContact, reader.GetString(7));
                    }
                    catch (Exception)
                    {

                    }
                    try
                    {
                        compContact = string.Concat(compContact, reader.GetString(8));
                    }
                    catch (Exception)
                    {

                    }
                    try
                    {
                        compContact = string.Concat(compContact, " / ");
                        compContact = string.Concat(compContact, reader.GetString(9));
                    }
                    catch (Exception)
                    {

                    }
                    try
                    {
                        compContact = string.Concat(compContact, reader.GetString(10));
                    }
                    catch (Exception)
                    {

                    }
                    lblCompContact.Text = compContact;
                    //lblUser.Text = reader.GetString(0) + " " + reader.GetString(1) + " " + reader.GetString(2);
                    //lblCompName.Text = reader.GetString(3);
                    //lblCompAddress.Text = reader.GetString(4) + ", " + reader.GetString(5) + ", " + reader.GetString(6);
                    //lblCompContact.Text = reader.GetString(7) + " / " + reader.GetString(8);

                }
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot load program details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }