コード例 #1
0
        private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Cursor tmpCursor = Cursor.Current;

            try
            {
                if ((e.KeyChar == (char)Keys.Enter) && (txtUserName.Text.Length > 0 && txtPassword.Text.Length > 0))
                {
                    if (txtUserName.Text.Length > 0 && txtPassword.Text.Length > 0)
                    {
                        DataTable dtUser;
                        dtUser = SQLite.GetUser(txtUserName.Text);
                        if (dtUser.Rows.Count == 1)
                        {
                            foreach (DataRow dr in dtUser.Rows)
                            {
                                Common.appSession.sUserIpk = Convert.ToInt32(dr.ItemArray.GetValue(0).ToString());
                                Common.appSession.sUserPass = dr.ItemArray.GetValue(2).ToString();
                            }

                            if (Common.appSession.sUserPass.Equals(txtPassword.Text))
                            {
                                frm_Area frm_Area = new frm_Area();
                                frm_Area.Show();
                            }
                            else
                            {
                                //Wrong password
                                MessageBox.Show("The password is incorrect, please retype and try again.");
                                txtPassword.Text = "";
                                txtPassword.Focus();
                            }
                        }
                        else
                        {
                            //Check for new users
                            SQLite.LoadUsers();
                            dtUser = SQLite.GetUser(Common.appSession.sUser);
                            if (dtUser.Rows.Count == 1)
                            {
                                foreach (DataRow dr in dtUser.Rows)
                                {
                                    Common.appSession.sUserIpk = Convert.ToInt32(dr.ItemArray.GetValue(0).ToString());
                                    Common.appSession.sUserPass = dr.ItemArray.GetValue(2).ToString();
                                }

                                if (Common.appSession.sUserPass.Equals(txtPassword.Text))
                                {
                                    frm_Area frm_Area = new frm_Area();
                                    frm_Area.Show();
                                }
                                else
                                {
                                    MessageBox.Show("The password is incorrect, please retype and try again.");
                                    txtPassword.Text = "";
                                    txtPassword.Focus();
                                }
                            }
                            else
                            {
                                MessageBox.Show("The User was not found");
                            }

                        }
                    }
                    else
                    {
                        MessageBox.Show("Complete the required fields.");
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Network connection failed. New users not loaded or user does not exist.");
            }

            Cursor.Current = Cursors.Default;
            
        }
コード例 #2
0
        private void cmdLogon_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text.Length > 0 && txtPassword.Text.Length > 0)
            {
                if (txtUserName.Text.Length > 0 && txtPassword.Text.Length > 0)
                {
                    DataTable dtUser;
                    dtUser = SQLite.GetUser(txtUserName.Text);
                    if (dtUser.Rows.Count == 1)
                    {
                        foreach (DataRow dr in dtUser.Rows)
                        {
                            Common.appSession.sUserIpk = Convert.ToInt32(dr.ItemArray.GetValue(0).ToString());
                            Common.appSession.sUserPass = dr.ItemArray.GetValue(2).ToString();
                        }

                        if (Common.appSession.sUserPass.Equals(txtPassword.Text))
                        {
                            frm_Area frm_Area = new frm_Area();
                            frm_Area.Show();
                        }
                        else
                        {
                            //Wrong password
                            MessageBox.Show("The password is incorrect, please retype and try again.");
                            txtPassword.Text = "";
                            txtPassword.Focus();
                        }
                    }
                    else
                    {
                        //Check for new users
                        SQLite.LoadUsers();
                        dtUser = SQLite.GetUser(Common.appSession.sUser);
                        if (dtUser.Rows.Count == 1)
                        {
                            foreach (DataRow dr in dtUser.Rows)
                            {
                                Common.appSession.sUserIpk = Convert.ToInt32(dr.ItemArray.GetValue(0).ToString());
                                Common.appSession.sUserPass = dr.ItemArray.GetValue(2).ToString();
                            }

                            if (Common.appSession.sUserPass.Equals(txtPassword.Text))
                            {
                                frm_Area frm_Area = new frm_Area();
                                frm_Area.Show();
                            }
                            else
                            {
                                MessageBox.Show("The password is incorrect, please retype and try again.");
                                txtPassword.Text = "";
                                txtPassword.Focus();
                            }
                        }
                        else
                        {
                            MessageBox.Show("The User was not found");
                        }

                    }
                }
                else
                {
                    MessageBox.Show("Complete the required fields.");
                }
            }
        }