/// <summary> /// Create a new Employee object. /// </summary> /// <param name="employeeId">Initial value of the EmployeeId property.</param> /// <param name="username">Initial value of the Username property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="role">Initial value of the Role property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="birthDate">Initial value of the BirthDate property.</param> /// <param name="address">Initial value of the Address property.</param> /// <param name="email">Initial value of the Email property.</param> /// <param name="phone">Initial value of the Phone property.</param> public static Employee CreateEmployee(global::System.String employeeId, global::System.String username, global::System.String password, global::System.String role, global::System.String name, global::System.DateTime birthDate, global::System.String address, global::System.String email, global::System.String phone) { Employee employee = new Employee(); employee.EmployeeId = employeeId; employee.Username = username; employee.Password = password; employee.Role = role; employee.Name = name; employee.BirthDate = birthDate; employee.Address = address; employee.Email = email; employee.Phone = phone; return employee; }
private void pbSubmit_Click(object sender, EventArgs e) { //saat picturebox submit di klik, validasi input sesuai soal if (txUser.Text.Equals("")) { lbError.Text = "Please fill username"; } else if (txPass.Text.Equals("")) { lbError.Text = "Please fill password"; } else { //apabila input valid, cek apakah input cocok dengan database var temp = from x in ent.Employees where x.Username.Equals(txUser.Text) select x; if (temp.Any()) { var temp2 = from x in ent.Employees where x.Username.Equals(txUser.Text) && x.Password.Equals(txPass.Text) select x; if (temp2.Any()) { //apabila cocok, maka tampilkan menu strip, groupbox login tersembunyi userLogin = (from x in ent.Employees where x.Username.Equals(txUser.Text) && x.Password.Equals(txPass.Text) select x).First(); toolStripStatusLabel1.Text = "Welcome " + userLogin.Name+", take your time.. :D"; if (userLogin.Role.Equals("Employee")) { creditCardToolStripMenuItem.Enabled = false; employeeToolStripMenuItem.Enabled = false; } else { creditCardToolStripMenuItem.Enabled = true; employeeToolStripMenuItem.Enabled = true; } menuStrip1.Visible = true; statusStrip1.Visible = true; gbLogin.Visible = false; lbError.Visible = false; pbLogo.Location = new Point((this.Width / 2) - 165, (this.Height / 2) - 165); } else { lbError.Text = "Wrong password"; } } else { lbError.Text = "Wrong username"; } } }
/// <summary> /// Deprecated Method for adding a new object to the Employees EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToEmployees(Employee employee) { base.AddObject("Employees", employee); }
private void btnSave_Click(object sender, EventArgs e) { //validasi semua input sesuai soal if (txUser.Text.Equals("")) { MessageBox.Show("Please fill username"); } else if (txUser.Text.Length < 5) { MessageBox.Show("Username length should be at least 5 characters"); } else if (cmbRole.SelectedIndex < 0) { MessageBox.Show("Please select role"); } else if (txName.Text.Equals("")) { MessageBox.Show("Please fill the name"); } else if (txName.Text.Length < 5) { MessageBox.Show("Name length should be at least 5 characters"); } else if (cmbDD.SelectedIndex < 0 || cmbMM.SelectedIndex < 0 || cmbYYYY.SelectedIndex < 0) { MessageBox.Show("Please select date, month, and year of birth date"); } else if (!checkDate()) { MessageBox.Show("Wrong birth date format"); } else if (txAddress.Text.Equals("")) { MessageBox.Show("Please fill the address"); } else if (txEmail.Text.Equals("")) { MessageBox.Show("Please fill the email"); } else if (!checkEmail()) { MessageBox.Show("Wrong email format"); } else if (!checkPhone()) { MessageBox.Show("Please fill phone with number"); } else { //jika input valid, cek apakah user klik button insert/update if (operation.Equals("insert")) { //jika user klik insert maka lakukan insert ke database string role = cmbRole.SelectedItem.ToString(); DateTime dtm = new DateTime( cmbYYYY.SelectedIndex + 1960, cmbMM.SelectedIndex + 1, cmbDD.SelectedIndex + 1); Employee obj = new Employee(); obj.EmployeeId = txId.Text; obj.Address = txAddress.Text; obj.Email = txEmail.Text; obj.Phone = txPhone.Text; obj.Username = txUser.Text; obj.Name = txName.Text; obj.Role = role; obj.BirthDate = dtm; obj.Password = txId.Text; ent.AddToEmployees( obj ); ent.SaveChanges(); } else if (operation.Equals("update")) { //jika user klik update maka lakukan update ke database string role = cmbRole.SelectedItem.ToString(); DateTime dtm = new DateTime( cmbYYYY.SelectedIndex + 1960, cmbMM.SelectedIndex + 1, cmbDD.SelectedIndex + 1); Employee obj = (from x in ent.Employees where x.EmployeeId.Equals(txId.Text)select x).First(); obj.Address = txAddress.Text; obj.Email = txEmail.Text; obj.Phone = txPhone.Text; obj.Username = txUser.Text; obj.Name = txName.Text; obj.Role = role; obj.BirthDate = dtm; ent.SaveChanges(); } //kembali ke state awal refreshTable(); curr = 0; showData(); operation = ""; enableManipulate(false); } }