private void IniciarSesion()
        {
            ControlDB DBControl = new ControlDB(ControlDB.cPath, "dbQA.mdf");

            string[] parameters = { "@id", "@pass" };
            string[] elements   = { TxtUserName.Text, TxtPsw.Text };
            TxtUserName.Clear();
            TxtPsw.Clear();
            List <string> admins = new List <string> {
                "Adm", "Dev"
            };

            if (DBControl.Buscar("select * from [User] where [Username]=@id and [Password]=@pass", parameters, elements))
            {
                string   cat      = DBControl.BuscarElemento("select [Tipo] from [User] where [UserName]=@id and [Password]=@pass", parameters, elements);
                MainPage mainPage = new MainPage(cat);
                this.Hide();
                mainPage.ShowDialog();
                this.Show();
                TxtUserName.Focus();
            }
            else
            {
                MessageBox.Show("Usuario o contraseña inválidos");
                TxtUserName.Focus();
                TxtPsw.Text = "";
            }
        }
 private void MaterialSingleLineTextField1_KeyDown(object sender, KeyEventArgs e)
 {
     if (Keys.Enter == e.KeyCode)
     {
         TxtPsw.Focus();
     }
 }
Exemple #3
0
        private void materialRaisedButton1_Click(object sender, EventArgs e)
        {
            if (TxtPsw.Text != TxtRepeatPsw.Text)
            {
                MessageBox.Show("Contraseña diferente", "Google LLC", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtPsw.Text       = "";
                TxtRepeatPsw.Text = "";
                TxtPsw.Focus();
                return;
            }

            try
            {
                if (TxtPsw.Text == TxtUsername.Text)
                {
                    MessageBox.Show("El usuario y al contraseña no pueden ser iguales");
                    TxtUsername.Clear();
                    TxtPsw.Clear();
                    TxtRepeatPsw.Clear();
                    comboBox1.SelectedIndex = 0;
                    return;
                }
                ControlDB DBControl  = new ControlDB(ControlDB.cPath, "dbQA.mdf");
                string[]  parameters = { "@name", "@Username", "@pass", "cat" };
                string[]  elements   = { TxtName.Name, TxtUsername.Text, TxtPsw.Text, comboBox1.SelectedIndex.ToString() };
                if (DBControl.Buscar("Select * from [User] where Username=@userName", parameters, elements))
                {
                    MessageBox.Show("El usuario ya existe");
                    TxtUsername.Clear();
                    TxtPsw.Clear();

                    return;
                }
                if (DBControl.Insertar("insert into [User] values(@Name,@userName,@pass,@cat)", parameters, elements))
                {
                    //MessageBox.Show("Usuario agregado");
                }
                else
                {
                    MessageBox.Show("El usuario no pudo ser agregado");
                    DBControl.Close();
                    return;
                }
                DBControl.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Por favor, verifique los datos");
            }

            // Despues de Agregar Usuario
            MessageBox.Show("Usuario agregado Correctamente", "Google LLC", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
 private void devAdd()
 {
     try
     {
         if (TxtPsw.Text == TxtUserName.Text)
         {
             MessageBox.Show("El usuario y al contraseña no pueden ser iguales");
             TxtUserName.Clear();
             TxtPsw.Clear();
             return;
         }
         ControlDB DBControl  = new ControlDB(ControlDB.cPath, "dbQA.mdf");
         string[]  parameters = { "@name", "@Username", "@pass", "cat" };
         string[]  elements   = { "No One", TxtUserName.Text, TxtPsw.Text, "Dev" };
         if (DBControl.Buscar("Select * from [User] where Username=@userName", parameters, elements))
         {
             MessageBox.Show("El usuario ya existe");
             TxtUserName.Clear();
             TxtPsw.Clear();
             return;
         }
         if (DBControl.Insertar("insert into [User] values(@Name,@userName,@pass,@cat)", parameters, elements))
         {
             MessageBox.Show("Usuario agregado");
         }
         else
         {
             MessageBox.Show("El usuario no pudo ser agregado");
         }
         DBControl.Close();
     }
     catch (Exception)
     {
         MessageBox.Show("Por favor, verifique los datos");
     }
 }
        private void ButLogin_Click(object sender, EventArgs e)
        {
            if (comboId.Text != "" & TxtPsw.Text != "")
            {
                currentAccountNumber = comboId.Text.Trim(); // 用户编号
                Boolean found = false;
                // Check the password
                if (isFirstLogin)
                {
                    if (DEFAULT_ACCOUNT_PASSWORD.Equals(TxtPsw.Text.Trim()))
                    {
                        found = true;
                        currentAccountName = userAccounts[0].name;
                        // Insert to the database
                        String dStr = "insert into login(ID,code,name,password,permission,status) values ('"
                                      + "1" + "','" + userAccounts[0].number + "','" + userAccounts[0].name + "','"
                                      + DEFAULT_ACCOUNT_PASSWORD + "','" + userAccounts[0].permission.ToString() + "','"
                                      + Utils.Constants.ACCOUNT_STATUS_LOGIN.ToString() + "')";
                        Utils.DatabaseUtils.ExecuteSqlCommand(dStr);
                    }
                }
                else
                {
                    foreach (Data.Account account in userAccounts)
                    {
                        if (account.number.Equals(comboId.Text.Trim()) && account.password.Equals(TxtPsw.Text.Trim()))
                        {
                            found = true;
                            currentAccountName = account.name;
                            String dStr = null;

                            // Find the last login account and update the status in database.
                            foreach (Data.Account account1 in userAccounts)
                            {
                                if (account1.status == Utils.Constants.ACCOUNT_STATUS_LOGIN)
                                {
                                    dStr = "Update login set status='" + Utils.Constants.ACCOUNT_STATUS_LOGOUT.ToString()
                                           + "'" + " where code='" + account1.number + "'";
                                    Utils.DatabaseUtils.ExecuteSqlCommand(dStr);

                                    break;
                                }
                            }

                            // Update the account status in database.
                            dStr = "Update login set status='" + Utils.Constants.ACCOUNT_STATUS_LOGIN.ToString()
                                   + "'" + " where code='" + account.number + "'";
                            Utils.DatabaseUtils.ExecuteSqlCommand(dStr);

                            break;
                        }
                    }
                }

                if (found)
                {
                    // 登录日志
                    string dStr = "insert into operationlog (code,name,operationtime,hardware,details) values ('"
                                  + currentAccountNumber + "','" + currentAccountName + "','" + DateTime.Now.ToString() + "','成品包装系统','系统登录')";
                    Utils.DatabaseUtils.ExecuteSqlCommand(dStr);
                    // TODO: Close this form.
                    this.Hide();
                    // this.Close();

                    frmMain frmMain1 = new frmMain(currentAccountNumber, currentAccountName);
                    frmMain1.ShowDialog();
                }
                else
                {
                    MessageBox.Show("输入的用户名或者密码不正确!");
                    TxtPsw.Focus();
                    return;
                }
            }
            else
            {
                MessageBox.Show("输入不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }