private void bLogin_Click(object sender, EventArgs e) { Login login = new Login(); Role role; if (login.ShowDialog() == DialogResult.OK) { switch (login.Role) { case "m": role = new ManagerRole(); break; case "e": role = new EmployeeRole(); break; case "c": role = new CustomerRole(); break; default: role = Role.Instance; break; } } else { role = Role.Instance; } #if DEBUG var type = role.GetType(); if(type == typeof(ManagerRole)) { MessageBox.Show("Manager"); } else if(type == typeof(EmployeeRole)) { MessageBox.Show("Employee"); } else if(type == typeof(CustomerRole)) { MessageBox.Show("Customer"); } else { MessageBox.Show("Guest"); } #endif }
public Role(string username, string password) : this() { try { using (MySqlDataReader data = DB.Instance.SelectReader(string.Format(loginFormat, username, password))) { if (data != null && data.HasRows) { data.Read(); ID = data.GetUInt16("id"); Name = data.GetString("first_name"); Address = data.GetString("address"); City = data.GetString("city"); Country = data.GetString("country"); PostalCode = data.GetString("postal_code"); Phone = data.GetString("phone"); if (data.GetBoolean("is_mananger")) { Instance = new ManagerRole(this); } else { Instance = new EmployeeRole(this); } } else { Instance = new Role(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }