示例#1
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            // You can always use the variable types that
            // you are familair with. (string, int, etc...)
            var username = tbUsername.Text;
            var password = tbPassword.Text;

            //Declaring an object of the database model
            var ctx = new vtdi_gate_log_dbEntities1();
            //Declare a variable to store the result of the query.
            //The code below checks the Users table in the database and returns
            // true or false for the condition in the lambda expression.
            var user = ctx.Users.Any(q => q.Username == username &&
                                     q.Password == password);

            //Check if a true value was returned from the user check and
            //grant access. If false, then contrinue to restrict.
            if (user)
            {
                MessageBox.Show($"Welcome {username}");
                //Declaring a an object of Type Form1, which isthe parent of the login form
                var parent = (Form1)this.MdiParent;
                //Change the property in Form1 to true.
                parent.isLoggedIn = true;
                this.Close();
            }
            else
            {
                MessageBox.Show("Invalid Credentials");
            }
        }
        private void GateLogForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'vtdi_gate_log_dbDataSet.VehicleTypes' table. You can move, or remove it, as needed.
            this.vehicleTypesTableAdapter.Fill(this.vtdi_gate_log_dbDataSet.VehicleTypes);
            // TODO: This line of code loads data into the 'vtdi_gate_log_dbDataSet.ItemsToDeclare' table. You can move, or remove it, as needed.
            this.itemsToDeclareTableAdapter.Fill(this.vtdi_gate_log_dbDataSet.ItemsToDeclare);
            // TODO: This line of code loads data into the 'vtdi_gate_log_dbDataSet.PurposeOfVisit' table. You can move, or remove it, as needed.
            this.purposeOfVisitTableAdapter.Fill(this.vtdi_gate_log_dbDataSet.PurposeOfVisit);

            //Initializing the object of ctx for database access.
            ctx = new vtdi_gate_log_dbEntities1();
        }
示例#3
0
        private void UserManagement_Load(object sender, EventArgs e)
        {
            try
            {
                _dbContext = new vtdi_gate_log_dbEntities1();

                //Populate the Gender Dropdown
                //Get The Genders from the database
                var genders = _dbContext.Genders.ToList();
                //Set the datasource of the combobox to the records
                //being retrieved from the database
                cbGenders.DataSource = genders;
                //Set the data member and value member to the values
                //that correspond with the columns coming back from
                //our data source.
                cbGenders.DisplayMember = "name";
                cbGenders.ValueMember   = "id";

                //Populate The Grid View
                RefreshGridView();

                //Manually set the text you want for the column headers. You may want more user and reader friendly
                //headers than what you database column names may afford you.
                gvUsers.Columns["FirstName"].HeaderText = "First Name";
                gvUsers.Columns["LastName"].HeaderText  = "Last Name";
                gvUsers.Columns["Name"].HeaderText      = "Gender";
                gvUsers.Columns["Email"].HeaderText     = "Email Address";
                gvUsers.Columns["Username"].HeaderText  = "Username";

                //Hide columns that you do not want to display for users
                gvUsers.Columns[0].Visible = false;
                //Set the first row as selected by default
                gvUsers.Rows[0].Selected = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }