public frmKaryawan(frmMain i)
 {
     InitializeComponent();
     frm = i;
 }
 public frmEditPengguna(frmMain frm)
 {
     InitializeComponent();
     this.frm = frm;
 }
Beispiel #3
0
        private void loginProcess()
        {
            try {
                frmMain frm   = new frmMain(this);
                bool    login = false;
                string  nama  = "";
                using (SqlConnection myConnection = new SqlConnection()) {
                    string     oString = "SELECT * FROM operator WHERE NIK = @nik";
                    SqlCommand oCmd    = new SqlCommand(oString, myConnection);
                    oCmd.Parameters.Add("@nik", SqlDbType.VarChar).Value = txtNIK.Text;

                    myConnection.ConnectionString = @"Data Source=" + Properties.Settings.Default.Server + "; Initial Catalog=" + Properties.Settings.Default.DBName + "; Integrated Security=True";
                    myConnection.Open();
                    using (SqlDataReader oReader = oCmd.ExecuteReader()) {
                        while (oReader.Read())
                        {
                            if (txtPassword.Text == oReader["pasword"].ToString())
                            {
                                login = true;
                                if (oReader["level"].ToString() == "Admin")
                                {
                                    frm.operatorToolStripMenuItem.Visible = true;
                                    frm.karyawanToolStripMenuItem.Visible = true;
                                }
                                else if (oReader["level"].ToString() == "Operator")
                                {
                                    frm.operatorToolStripMenuItem.Visible = false;
                                    frm.karyawanToolStripMenuItem.Visible = false;
                                }
                                else
                                {
                                    MessageBox.Show(this, "Unknown error expected. Login aborted.");
                                    return;
                                }
                                nama             = oReader["nama"].ToString();
                                frm.username     = oReader["NIK"].ToString();
                                frm.txtUser.Text = oReader["nama"].ToString();
                            }
                            else
                            {
                                login = false;
                            }
                        }

                        myConnection.Close();
                    }
                    if (login == true)
                    {
                        MessageBox.Show(this, "Selamat datang, " + nama + "!", "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        frm.Show();
                        this.txtNIK.Text      = "";
                        this.txtPassword.Text = "";
                        this.Visible          = false;
                    }
                    else
                    {
                        MessageBox.Show(this, "NIK/Password salah!", "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            } catch (Exception e) {
                MessageBox.Show(this, e.ToString());
            }
        }