コード例 #1
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            Employee newEmployee = new Employee()
            {
                FirstName = EmployeeCreateName.Text,
                LastName  = EmployeeCreateSurname.Text,
                username  = EmployeeCreateUsername.Text,
                RoleId    = (int)((ComboboxItem)EmployeeCreateRoles.SelectedItem).Value
            };
            Random randomNumber = new Random();
            var    OTP          = newEmployee.username + randomNumber.Next(1000, 9999);

            newEmployee.Password = OTP;
            db.Employees.Add(newEmployee);
            db.SaveChanges();
        }
コード例 #2
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            if (txtFname.Text == string.Empty || txtLname.Text == string.Empty)
            {
                MessageBox.Show("Please fill the all textboxes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Random rnd    = new Random();
            int    cardNo = rnd.Next(1000, 9999);

            while (_context.Customers.Any(c => c.CardNo == cardNo))
            {
                cardNo = rnd.Next(1000, 9999);
            }
            _context.Customers.Add(new Customer {
                FirstName = txtFname.Text, LastName = txtLname.Text, CardNo = cardNo
            });
            _context.SaveChanges();
            MessageBox.Show("New customer succsessfully added", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            dataGridView1.DataSource = _context.Customers.Select(c => new { c.FirstName, c.LastName, c.CardNo }).ToArray();
            txtLname.Text            = txtFname.Text = "";
            dataGridView1.DataSource = _context.Customers.ToList();
        }