private void Signin_Load(object sender, EventArgs e) { if (File.Exists("token.txt")) { string token = File.ReadAllText("token.txt"); UserEndPointClient userClient = new UserEndPointClient(); userDto user = userClient.me(token); if (user.type == "admin") { this.Close(); Admin admin = new Admin(); admin.Show(); } else { this.Close(); Dashboard dash = new Dashboard(); dash.Show(); } } else { //this.Hide(); //Signin signIn = new Signin(); //signIn.Show(); //Application.Run(new First()); //Console.WriteLine("File does not exist in the current directory!"); } }
private void changepassword_Click(object sender, EventArgs e) { Boolean vpassword = false; if (string.IsNullOrWhiteSpace(password.Text) | password.Text.Length < 4) { vpassword = false; password.Focus(); errorProvider1.SetError(password, "New Password should contain at least four character."); } else { vpassword = true; errorProvider1.SetError(password, ""); } Boolean vconfirmpassword = false; if (string.IsNullOrWhiteSpace(confirmpassword.Text) | confirmpassword.Text.Length < 4 | !(confirmpassword.Text == password.Text)) { vconfirmpassword = false; confirmpassword.Focus(); errorProvider1.SetError(confirmpassword, "Confirm password should be same with password and not empty."); } else { vconfirmpassword = true; errorProvider1.SetError(confirmpassword, ""); } Boolean voldpassword = false; if (string.IsNullOrWhiteSpace(oldpassword.Text) | oldpassword.Text.Length < 4) { voldpassword = false; oldpassword.Focus(); errorProvider1.SetError(oldpassword, "Old password should contain at least four character."); } else { voldpassword = true; errorProvider1.SetError(oldpassword, ""); } if (vpassword == true & vconfirmpassword == true & voldpassword == true) { string token = File.ReadAllText("token.txt"); UserEndPointClient userClient = new UserEndPointClient(); responseDto res = userClient.changePasswordUser(password.Text, token); if (res.status == true) { MessageBox.Show(res.message + "\n" + "Password changed, Login again", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); File.Delete("token.txt"); this.Close(); Signin s = new Signin(); s.Show(); } else { MessageBox.Show(res.message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void update_Click(object sender, EventArgs e) { string token = File.ReadAllText("token.txt"); UserEndPointClient userend = new UserEndPointClient(); responseDto response = userend.deactivateUser(currentUserNow.id, token); if (response.status == true) { DialogResult rese = MessageBox.Show(response.message, "Success", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); this.Close(); Admin admin = new Admin(); admin.Show(); } else { DialogResult rese = MessageBox.Show(response.message, "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (File.Exists("token.txt")) { string token = File.ReadAllText("token.txt"); UserEndPointClient userClient = new UserEndPointClient(); userDto user = userClient.me(token); if (user.type == "admin") { Application.Run(new Admin()); } else { Application.Run(new Dashboard()); } } else { //this.Hide(); //Signin signIn = new Signin(); //signIn.Show(); Application.Run(new First()); //Console.WriteLine("File does not exist in the current directory!"); } } catch { MessageBox.Show("Unknown error", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Run(new First()); } }
private void Profile_Load(object sender, EventArgs e) { // string token = File.ReadAllText("token.txt"); UserEndPointClient userClient = new UserEndPointClient(); userDto user = userClient.me(token); //userDto user = new userDto(); if (user == null) { } else { currentUserNow = user; username.Text = currentUserNow.username; firstname.Text = currentUserNow.fname; lastname.Text = currentUserNow.lname; phone.Text = currentUserNow.phone; email.Text = currentUserNow.email; company.Text = currentUserNow.company; status.Text = currentUserNow.status.ToString(); } }
private void button1_Click(object sender, EventArgs e) { Boolean vuserNameTB = false; Boolean vpasswordTB = false; if (string.IsNullOrWhiteSpace(userNameTB.Text) | userNameTB.Text.Length < 4) { vuserNameTB = false; userNameTB.Focus(); errorProvider1.SetError(userNameTB, "User name should contain at least four character."); } else { vuserNameTB = true; errorProvider1.SetError(userNameTB, ""); } if (string.IsNullOrWhiteSpace(passwordTB.Text) | passwordTB.Text.Length < 4) { vpasswordTB = false; userNameTB.Focus(); errorProvider1.SetError(passwordTB, "Paswword name should contain at least four character."); } else { vpasswordTB = true; errorProvider1.SetError(passwordTB, ""); } if (vuserNameTB == true & vpasswordTB == true) { UserEndPointClient userEpc = new UserEndPointClient(); authDto authdto = new authDto(); authdto.username = userNameTB.Text; authdto.password = passwordTB.Text; authResponseDto response = userEpc.auth(authdto); Console.WriteLine(response.token); if (response.status == false) { MessageBox.Show(response.message, "Signin error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (response.type == "admin") { File.WriteAllText("token.txt", response.token); this.Hide(); Admin ad = new Admin(); ad.Show(); } else { File.WriteAllText("token.txt", response.token); Console.WriteLine("TOKEN " + File.ReadAllText("token.txt")); this.Hide(); Dashboard userDb = new Dashboard(); userDb.Show(); } } } }
private void save_Click(object sender, EventArgs e) { Boolean vusername = false; if (string.IsNullOrWhiteSpace(username.Text) | username.Text.Length < 4) { vusername = false; username.Focus(); errorProvider1.SetError(username, "User name should contain at least four character."); } else { vusername = true; errorProvider1.SetError(username, ""); } Boolean vpassword = false; if (string.IsNullOrWhiteSpace(username.Text) | username.Text.Length < 4) { vpassword = false; password.Focus(); errorProvider1.SetError(password, "Password should contain at least four character."); } else { vpassword = true; errorProvider1.SetError(password, ""); } Boolean vconfirmpassword = false; if (string.IsNullOrWhiteSpace(confirmpassword.Text) | confirmpassword.Text.Length < 4 | !(confirmpassword.Text == password.Text)) { vconfirmpassword = false; confirmpassword.Focus(); errorProvider1.SetError(confirmpassword, "Confirm password should be same with password and empty."); } else { vconfirmpassword = true; errorProvider1.SetError(confirmpassword, ""); } Boolean vfirstname = false; if (string.IsNullOrWhiteSpace(firstname.Text) | firstname.Text.Length < 3) { vfirstname = false; firstname.Focus(); errorProvider1.SetError(firstname, "First name should contain at least three character."); } else { vfirstname = true; errorProvider1.SetError(firstname, ""); } Boolean vlastname = false; if (string.IsNullOrWhiteSpace(lastname.Text) | lastname.Text.Length < 3) { vlastname = false; lastname.Focus(); errorProvider1.SetError(lastname, "Last name should contain at least three character."); } else { vlastname = true; errorProvider1.SetError(lastname, ""); } Boolean vphone = false; if (string.IsNullOrWhiteSpace(lastname.Text) | lastname.Text.Length < 3) { vphone = false; phone.Focus(); errorProvider1.SetError(phone, "Phone should contain ten number."); } else { vphone = true; errorProvider1.SetError(phone, ""); } Boolean vemail = false; if (string.IsNullOrWhiteSpace(email.Text) | email.Text.Length < 3) { vemail = false; email.Focus(); errorProvider1.SetError(email, "Email should follow email format."); } else { vemail = true; errorProvider1.SetError(email, ""); } Boolean vcompany = false; if (string.IsNullOrWhiteSpace(company.Text) | company.Text.Length < 3) { vcompany = false; company.Focus(); errorProvider1.SetError(company, "Company name should contain atleast two character."); } else { vcompany = true; errorProvider1.SetError(company, ""); } if (vusername == true & vpassword == true & vfirstname == true & vlastname == true & vphone == true & vemail == true & vcompany == true & vconfirmpassword == true) { UserEndPointClient userClient = new UserEndPointClient(); userDto user = new userDto(); user.id = 0; user.username = username.Text; user.password = password.Text; Console.WriteLine("Password <===> " + password.Text); user.fname = firstname.Text; user.lname = lastname.Text; user.phone = phone.Text; user.email = email.Text; user.company = company.Text; user.status = true; user.createdat = new DateTime(); responseDto res = userClient.createUser(user); if (res.status == true) { MessageBox.Show(res.message + "\n" + "You can login now", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); Signin signin = new Signin(); signin.Show(); } else { MessageBox.Show(res.message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Admin_Load(object sender, EventArgs e) { string token = File.ReadAllText("token.txt"); UserEndPointClient userClient = new UserEndPointClient(); paginationDto pag = new paginationDto(); pag.start = 8; pag.max = 30; pag.count = 0; userListResponseDto listUser = userClient.listUser(pag, token); if (listUser.responseDto.status == false) { } else { int x = 10; int y = 5; int delta = 10; int dx = 0 + delta; // Create name label var labelName1 = new Label(); labelName1.AutoSize = true; labelName1.Location = new Point(x + dx, y); labelName1.Font = new Font(labelName1.Font, FontStyle.Bold); labelName1.Text = "Username"; // Create mail label var labelMail1 = new Label(); labelMail1.AutoSize = true; labelMail1.Location = new Point(x + dx + labelName1.Width, y); labelMail1.Font = new Font(labelMail1.Font, FontStyle.Bold); labelMail1.Text = "Type"; // Create phone label var labelPhone1 = new Label(); labelPhone1.AutoSize = true; labelPhone1.Location = new Point(x + dx + labelName1.Width + labelMail1.Width, y); labelPhone1.Font = new Font(labelPhone1.Font, FontStyle.Bold); labelPhone1.Text = "Status"; panel1.Controls.Add(labelName1); panel1.Controls.Add(labelMail1); panel1.Controls.Add(labelPhone1); // Iterate int dy1 = x + labelName1.Height; // + labelMail.Height + labelPhone.Height; int dy2 = x + labelName1.Height; //picture.Height; y += Math.Max(dy1, dy2) + delta; for (int i = 0; i < listUser.paginationDto.count; i++) { userDto user = listUser.userDtoList[i]; dx = 0 + delta; // Create name label var labelName = new Label(); labelName.AutoSize = true; labelName.Location = new Point(x + dx, y); //labelName.Font = new Font(labelName.Font, FontStyle.Bold); labelName.Text = listUser.userDtoList[i].username; // Create mail label var labelMail = new Label(); labelMail.AutoSize = true; labelMail.Location = new Point(x + dx + labelName.Width, y); labelMail.Text = listUser.userDtoList[i].type; // Create phone label var labelPhone = new Label(); labelPhone.AutoSize = true; labelPhone.Location = new Point(x + dx + labelName.Width + labelMail.Width, y); labelPhone.Text = listUser.userDtoList[i].status.ToString(); // var btn = new Button(); btn.Text = "Detail"; btn.Name = "detail"; btn.Location = new Point(x + dx + labelName.Width + labelMail.Width + labelMail.Width, y); btn.Click += (object s, EventArgs ee) => { this.Hide(); currentUser = user; UserDetaile userDetaile = new UserDetaile(); userDetaile.Show(); }; panel1.Controls.Add(labelName); panel1.Controls.Add(labelMail); panel1.Controls.Add(labelPhone); panel1.Controls.Add(btn); // Iterate dy1 = x + labelName.Height; // + labelMail.Height + labelPhone.Height; dy2 = x + labelName.Height; //picture.Height; y += Math.Max(dy1, dy2) + delta; } } }
private void update_Click(object sender, EventArgs e) { Boolean vusername = false; if (string.IsNullOrWhiteSpace(username.Text) | username.Text.Length < 4) { vusername = false; username.Focus(); errorProvider1.SetError(username, "User name should contain at least four character."); } else { vusername = true; errorProvider1.SetError(username, ""); } Boolean vfirstname = false; if (string.IsNullOrWhiteSpace(firstname.Text) | firstname.Text.Length < 3) { vfirstname = false; firstname.Focus(); errorProvider1.SetError(firstname, "First name should contain at least three character."); } else { vfirstname = true; errorProvider1.SetError(firstname, ""); } Boolean vlastname = false; if (string.IsNullOrWhiteSpace(lastname.Text) | lastname.Text.Length < 3) { vlastname = false; lastname.Focus(); errorProvider1.SetError(lastname, "Last name should contain at least three character."); } else { vlastname = true; errorProvider1.SetError(lastname, ""); } Boolean vphone = false; if (string.IsNullOrWhiteSpace(lastname.Text) | lastname.Text.Length < 3) { vphone = false; phone.Focus(); errorProvider1.SetError(phone, "Phone should contain ten number."); } else { vphone = true; errorProvider1.SetError(phone, ""); } Boolean vemail = false; if (string.IsNullOrWhiteSpace(email.Text) | email.Text.Length < 3) { vemail = false; email.Focus(); errorProvider1.SetError(email, "Email should follow email format."); } else { vemail = true; errorProvider1.SetError(email, ""); } Boolean vcompany = false; if (string.IsNullOrWhiteSpace(company.Text) | company.Text.Length < 3) { vcompany = false; company.Focus(); errorProvider1.SetError(company, "Company name should contain atleast two character."); } else { vcompany = true; errorProvider1.SetError(company, ""); } if (vusername == true & vfirstname == true & vlastname == true & vphone == true & vemail == true & vcompany == true) { UserEndPointClient userClient = new UserEndPointClient(); userDto user = new userDto(); user.id = currentUserNow.id; //user.username = username.Text; //user.password = password.Text; user.fname = firstname.Text; user.lname = lastname.Text; user.phone = phone.Text; user.email = email.Text; user.company = company.Text; //user.status = null; user.createdat = currentUserNow.createdat; string token = File.ReadAllText("token.txt"); responseDto res = userClient.updateUser(user, token); if (res.status == true) { MessageBox.Show(res.message, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); Signin signin = new Signin(); signin.Show(); } else { MessageBox.Show(res.message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }