示例#1
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txt_UserName.Text.Length > 0 && txt_Password.Text.Length > 0)
                {
                    user = udao.GetUserDetails(txt_UserName.Text, txt_Password.Text);

                    if (user.ID > 0)
                    {
                        if (udao.SetUserLogIn(user) > 0)
                        {
                            user.IsLoggedIn = true;
                            BarcodeDetailsForm bdf = new BarcodeDetailsForm(user, this);
                            this.Hide();
                            bdf.Show();
                        }
                        else
                        {
                            MessageBox.Show("Multiple user log ins are not allowed", "Login error:");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Unable to log in using provided credentials", "Login error:");
                    }
                }
                else
                {
                    MessageBox.Show("User name and password is required", "Login");
                }
            }
            catch (SqlException se)
            {
                MessageBox.Show("Can not login due to unexpected sql exception" + se.Message, "Sql Exception:");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can not login due to unexpected exception" + ex.Message, "Exception:");
            }
        }
 private void btn_close_Click(object sender, EventArgs e)
 {
     bcdf.Show();
     this.Dispose();
 }