Beispiel #1
0
 private void frmInvoice_FormClosing(object sender, FormClosingEventArgs e)
 {
     this.Hide();
     frmMainMenu frm = new frmMainMenu();
     frm.lblUser.Text = label6.Text;
     frm.Show();
 }
Beispiel #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text == "")
            {
                MessageBox.Show("Please enter user name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserName.Focus();
                return;
            }
            if (txtPassword.Text == "")
            {
                MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPassword.Focus();
                return;
            }
            try
            {
                if (!Directory.Exists(ConfigurationManager.AppSettings["DatabaseFolder"]))
                {
                    DirectoryInfo di = Directory.CreateDirectory(ConfigurationManager.AppSettings["DatabaseFolder"]);
                    DirectorySecurity ds = di.GetAccessControl();
                    ds.AddAccessRule(new FileSystemAccessRule("Users",FileSystemRights.Delete,AccessControlType.Deny));
                    ds.AddAccessRule(new FileSystemAccessRule("Administrators", FileSystemRights.Delete, AccessControlType.Deny));
                    di.SetAccessControl(ds);
                    di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
                    if (!File.Exists(ConfigurationManager.AppSettings["DatabasePath"]))
                    {
                        File.Copy("SIS_DB.accdb", ConfigurationManager.AppSettings["DatabasePath"]);
                        //OleDbConnection newConnection = default(OleDbConnection);
                        //newConnection = new OleDbConnection(cs);

                        //OleDbCommand newCommand = default(OleDbCommand);
                        //newCommand = new OleDbCommand("INSERT INTO [Registration] ([NameOfUser], [UserName], [User_Password], [ContactNo], [Email], [JoiningDate]) VALUES (\"bala\", \"admin\", \"12345\", NULL, NULL, NULL);", newConnection);
                        //newCommand.Connection.Open();
                        //newCommand.ExecuteNonQuery();
                        //newCommand.Connection.Close();
                        //newCommand = new OleDbCommand("INSERT INTO [Users] ([Username], [User_Password]) VALUES (\"admin\", \"12345\");", newConnection);
                        //newCommand.Connection.Open();
                        //newCommand.ExecuteNonQuery();
                        //newCommand.Connection.Close();
                    }
                }

                OleDbConnection myConnection = default(OleDbConnection);
                myConnection = new OleDbConnection(cs);

                OleDbCommand myCommand = default(OleDbCommand);

                myCommand = new OleDbCommand("SELECT Username,User_password FROM Users WHERE Username = @username AND User_password = @UserPassword", myConnection);
                OleDbParameter uName = new OleDbParameter("@username", OleDbType.VarChar);
                OleDbParameter uPassword = new OleDbParameter("@UserPassword", OleDbType.VarChar);
                uName.Value = txtUserName.Text;
                uPassword.Value = txtPassword.Text;
                myCommand.Parameters.Add(uName);
                myCommand.Parameters.Add(uPassword);

                myCommand.Connection.Open();

                OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

                if (myReader.Read() == true)
                {
                        int i;
                        ProgressBar1.Visible = true;
                        ProgressBar1.Maximum = 5000;
                        ProgressBar1.Minimum = 0;
                        ProgressBar1.Value = 4;
                        ProgressBar1.Step = 1;

                        for (i = 0; i <= 5000; i++)
                        {
                            ProgressBar1.PerformStep();
                        }
                        this.Hide();
                        frmMainMenu frm = new frmMainMenu();
                        frm.Show();
                        frm.lblUser.Text = txtUserName.Text;

                    }

                else
                {
                    MessageBox.Show("Login is Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    txtUserName.Clear();
                    txtPassword.Clear();
                    txtUserName.Focus();

                }
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Dispose();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }