private void Disconnect_button_Click(object sender, RoutedEventArgs e) { var callback = new ClientCallback(); var client = new FourRowServiceClient(new InstanceContext(callback)); if (string.IsNullOrEmpty(TbUsername.Text)) { MessageBox.Show("insert valid username to disconnet THIS BUTTON IS FOR DEBUG USAGE ONLY!!"); } else { var userName = TbUsername.Text.Trim(); try { client.ClientDisconnected(userName); } catch (DbException ex) { MessageBox.Show(ex.Message); } catch (FaultException<UserDoesntExistsFault> ex) { MessageBox.Show(ex.Detail.Details); TbPasswrd.Clear(); TbUsername.Clear(); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show(userName + " disconnected successfully"); } }
} /*end of constructor*/ private void Button_Connect_Click(object sender, RoutedEventArgs e) { var callback = new ClientCallback(); var client = new FourRowServiceClient(new InstanceContext(callback)); if (!utils.AllTextboxesFilled(MainGrid)) { MessageBox.Show("Please insert User name and Password"); return; } var userName = TbUsername.Text.Trim(); var pass = TbPasswrd.Password.Trim(); try { client.ClientConnected(userName, utils.HashValue(pass).ToString()); } catch (DbException ex) { MessageBox.Show(ex.Message); } catch (FaultException<UserDoesntExistsFault> ex) { MessageBox.Show(ex.Detail.Details); TbPasswrd.Clear(); TbUsername.Clear(); return; } catch (FaultException<UserAlreadyConnectedFault> ex) { MessageBox.Show(ex.Detail.Details); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } WaitingWindow waitingWindow = null; try { var ww = new WaitingWindow { Username = userName, Client = client, Callback = callback, Title = "Wellcome " + userName }; waitingWindow = ww; } catch (Exception ex) { MessageBox.Show(ex.Message); client.ClientDisconnected(userName); } Close(); waitingWindow?.Show(); }
private void TbUsername_TextChanged(object sender, EventArgs e) { // On change up of the textbox string UsernameValue = TbUsername.Text; // Create a string with the value of the TbUsername value if (UsernameValue == "") { // If the username textbox is empty UsernameValid = 1; // Set the usernamevalid to 1, which disables the user from selecting a difficulty TmrPopUp.Start(); LblPopUp.Visible = true; // Display the popup text LblPopUp.Text = "Please enter a username. Remember no numbers allowed!"; } else { // The username is not empty UsernameValid = 0; // Set the usernamevalid to 0, which enables the user to select a difficulty } for (int i = 0; i < UsernameValue.Length; i++) { if (!char.IsLetter(UsernameValue[i])) { // If the current character is not a letter TbUsername.Clear(); // Remove all characters in the username textbox TbUsername.Focus(); // Focuse the user onto the username textbox to set the user to editing the username UsernameValid = 1; // Set the usernamevalid to 1, which disables the user from selecting a difficulty TmrPopUp.Start(); LblPopUp.Visible = true; // Display the popup text LblPopUp.Text = "Remember no numbers allowed!"; } else { UsernameValid = 0; // Set the usernamevalid to 0, which enables the user to select a difficulty } } }
private void Blogin_Click(object sender, EventArgs e) { if (TbPassword.ForeColor == Color.DimGray || TbUsername.ForeColor == Color.DimGray) { MessageBox.Show("User dan Password harus di isi!!", "PERINGATAN", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { A.SetQueri("SELECT `id_user`, `id_akses`, `username`, `kode_ref` " + "FROM `m_user` WHERE `hapus`='N' AND `username`='" + TbUsername.Text + "' AND `password`=MD5('" + TbPassword.Text + "') LIMIT 1"); bool ada = false; foreach (DataRow baris in A.GetQueri().GetData().Rows) { S.SetUsername(baris["username"].ToString().EncodeToBase64String()); S.SetUseracces(baris["id_akses"].ToString()); S.SetUserid(baris["id_user"].ToString()); S.SetKodeGuru(baris["kode_ref"].ToString()); S.SetKodesiswa(baris["kode_ref"].ToString()); ada = true; } if (ada) { if (S.GetUseracces() == "1" || S.GetUseracces() == "2") { S.SetUsernama(A.SingelData("SELECT `namaguru` FROM `m_guru` WHERE `kode_guru`='" + S.GetKodeGuru() + "';")); } else if (S.GetUseracces() == "3") { S.SetUsernama(A.SingelData("SELECT `namasiswa` FROM `m_siswa` WHERE `kode_siswa`='" + S.GetKodesiswa() + "';")); } TbPassword.Clear(); TbUsername.Clear(); Tbusername_Leave(sender, e); Tbpassword_Leave(sender, e); this.ShowInTaskbar = false; this.Hide(); A.SetLogin(); Properties.Settings.Default.loginsaveusername = CbSaveUsername.Checked; Properties.Settings.Default.username = S.GetUsername(); Properties.Settings.Default.Save(); FMainMenu f = new FMainMenu(); if (f.ShowDialog() == DialogResult.OK) { List <Form> openForms = new List <Form>(); foreach (Form form in Application.OpenForms) { openForms.Add(form); } foreach (Form ff in openForms) { if (ff.Name != "FLogin") { ff.Close(); } } this.Show(); this.ShowInTaskbar = true; if (Properties.Settings.Default.loginsaveusername) { TbUsername.Text = S.GetUsername().DecodeFromBase64String(); TbUsername.ForeColor = Color.Black; } } else { A.SetLogout(); Close(); } } else { MessageBox.Show("Username / Password Salah!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }