//Show searched records public void OnPostSearch() { String Search_User = Request.Form["Search_User"]; String Exception = ""; String Current_User = HttpContext.Session.GetString("User_Name"); int OFFSET = 50; Boolean CheckConnection = MyOwnMySQLConnectionClass.LoadConnection(ref Exception); MySqlCommand MySQLQuery = new MySqlCommand(); MySqlDataReader UserReader; UserList = new List <String> { }; if (Search_User != null || Search_User.CompareTo("") != 0) { HttpContext.Session.SetString("Search_User", Search_User); HttpContext.Session.SetString("OFFSET", OFFSET.ToString()); SessionSearchUser = Search_User; MySQLQuery = new MySqlCommand(); MySQLQuery.Parameters.Clear(); MySQLQuery.CommandText = "SELECT `User_Name` FROM `User` WHERE `User_Name`!='@Current_User' AND `User_Name` LIKE '%@Search_User%' LIMIT 50"; MySQLQuery.Parameters.Add("@Search_User", MySqlDbType.Text).Value = Search_User; MySQLQuery.Parameters.Add("@Current_User", MySqlDbType.Text).Value = Current_User; MySQLQuery.Connection = MyOwnMySQLConnectionClass.MyMySQLConnection; MySQLQuery.Prepare(); UserReader = MySQLQuery.ExecuteReader(); while (UserReader.Read()) { UserList.Add(UserReader.GetValue(0).ToString()); } MyOwnMySQLConnectionClass.MyMySQLConnection.Close(); } }
bool FindAdmin(string NameToFind) { bool UserFind = false; MySqlCommand UserCommand; MySqlDataReader UserReader; Connection.Open(); if (Connection != null) { UserCommand = Connection.CreateCommand(); UserCommand.CommandText = "Select login from admin where login ='******'"; UserReader = UserCommand.ExecuteReader(); if (UserReader.Read()) { if (UserReader["login"].ToString() == NameToFind) { UserFind = true; } } UserReader.Close(); Connection.Close(); } else { //connexion non réussie Response.Redirect("default.aspx"); } return(UserFind); }
public ActionResult LoginExec(AccountLoginViewModel accountLogin) { if (ModelState.IsValid) { string filePath = Server.MapPath(@"/App_Data/Utenti.txt"); var reader = new UserReader(); IList <Account> listaAccount = reader.Read(filePath); Account verificaEmail = listaAccount.FirstOrDefault(e => e.Email == accountLogin.Email); if (verificaEmail == null) { ModelState.AddModelError("Email", "Email non presente"); return(View("Login")); } Account verificaAccount = listaAccount.FirstOrDefault(e => e.Email == accountLogin.Email && e.Password == accountLogin.Password); if (verificaAccount == null) { ModelState.AddModelError("", "Credenziali Errate"); return(View("Login")); } Session["user"] = verificaAccount; Session["logged"] = true; return(RedirectToAction("Index", "Home")); } return(View("Login")); }
//Show previous records public void OnPostPrevious() { String User = HttpContext.Session.GetString("Search_User"); String OFFSETString = HttpContext.Session.GetString("OFFSET"); String Exception = ""; String Current_User = HttpContext.Session.GetString("User_Name"); Boolean CheckConnection = MyOwnMySQLConnectionClass.LoadConnection(ref Exception); MySqlCommand MySQLQuery = new MySqlCommand(); MySqlDataReader UserReader; UserList = new List <String> { }; int OFFSET = 0; SessionSearchUser = User; if (User != null && OFFSETString != null) { OFFSET = int.Parse(OFFSETString); if (OFFSET != 0) { OFFSET -= 50; } MySQLQuery.CommandText = "SELECT `User_Name` FROM `User` WHERE `User_Name`!='@Current_User' AND `User_Name` LIKE '%@Search_User%' LIMIT 50 OFFSET " + OFFSET.ToString(); MySQLQuery.Parameters.Add("@Search_User", MySqlDbType.Text).Value = User; MySQLQuery.Parameters.Add("@Current_User", MySqlDbType.Text).Value = Current_User; MySQLQuery.Connection = MyOwnMySQLConnectionClass.MyMySQLConnection; MySQLQuery.Prepare(); UserReader = MySQLQuery.ExecuteReader(); while (UserReader.Read()) { UserList.Add(UserReader.GetValue(0).ToString()); } MyOwnMySQLConnectionClass.MyMySQLConnection.Close(); HttpContext.Session.SetString("OFFSET", OFFSET.ToString()); } else if (User == null && OFFSETString != null) { OFFSET = int.Parse(OFFSETString); if (OFFSET != 0) { OFFSET -= 50; } MySQLQuery.CommandText = "SELECT `User_Name` FROM `User` WHERE `User_Name`!='@Current_User' LIMIT 50 OFFSET " + OFFSET.ToString(); MySQLQuery.Parameters.Add("@Current_User", MySqlDbType.Text).Value = Current_User; MySQLQuery.Connection = MyOwnMySQLConnectionClass.MyMySQLConnection; MySQLQuery.Prepare(); UserReader = MySQLQuery.ExecuteReader(); while (UserReader.Read()) { UserList.Add(UserReader.GetValue(0).ToString()); } MyOwnMySQLConnectionClass.MyMySQLConnection.Close(); HttpContext.Session.SetString("OFFSET", OFFSET.ToString()); } }
public ActionResult Edit(int Id) { if (Session["loggedAdmin"] == null) { return(RedirectToAction("Index", "Home")); } string filePath = Server.MapPath(@"/App_Data/Utenti.txt"); var reader = new UserReader(); IList <Account> listaAccount = reader.Read(filePath); AccountViewModel account = listaAccount.Where(e => e.Id == Id).Select(acc => new AccountViewModel() { Id = acc.Id, Nome = acc.Nome, Cognome = acc.Cognome, Email = acc.Email, TipoAccount = (acc.Tipo == Account.tipo.Normal) ? "Normal" : "Premium" }).First(); return(View(account)); }
public ActionResult Index() { if (Session["loggedAdmin"] == null) { return(RedirectToAction("Index", "Home")); } string filePath = Server.MapPath(@"/App_Data/Utenti.txt"); var reader = new UserReader(); IList <Account> listaAccount = reader.Read(filePath); IList <AccountViewModel> listaAccountViewModel = listaAccount.Select(account => new AccountViewModel() { Id = account.Id, Nome = account.Nome, Cognome = account.Cognome, Email = account.Email, TipoAccount = (Account.tipo.Normal == account.Tipo)?"Normale":"Premium" }).ToList(); return(View(listaAccountViewModel)); }
private void LoginBtn_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=PHONEANDMORE;Integrated Security=True"); conn.Open(); SqlCommand SelectUsername = new SqlCommand("select Type from Creds where UserName = '******'and Password ='******'", conn); SqlDataReader UserReader; UserReader = SelectUsername.ExecuteReader(); if (UserReader.Read() == true) { if (UserReader[0].ToString() == "admin" || UserReader[0].ToString() == "user") { MainMenu ah = new MainMenu(); ah.get(UserTextBox.Text); ah.ShowDialog(); this.Close(); } } else { if (UserTextBox.Text == "Elbeld" && PassTextBox.Text == "stG65gr5") { MainMenu ah = new MainMenu(); ah.get(UserTextBox.Text); ah.ShowDialog(); this.Close(); } else { MessageBox.Show(" incorrect Username or Password, Please check your entries correctly ", "\t\t Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); UserTextBox.Clear(); PassTextBox.Clear(); UserTextBox.Focus(); conn.Close(); UserReader.Close(); } } conn.Close(); }
public ActionResult Edit(int Id, string tipo) { if (Session["loggedAdmin"] == null) { return(RedirectToAction("Index", "Home")); } string filePath = Server.MapPath(@"/App_Data/Utenti.txt"); var reader = new UserReader(); var writer = new UserWriter(); IList <Account> listaAccount = reader.Read(filePath); var daAggiornare = listaAccount.First(e => e.Id == Id); daAggiornare.Tipo = (tipo == "Normal") ? Account.tipo.Normal : Account.tipo.Premium; writer.Reset(filePath); foreach (var account in listaAccount) { int Tipo = (account.Tipo == Account.tipo.Normal) ? 1 : 2; string linea = $"{account.Id},{account.Nome},{account.Cognome},{account.Email},{account.Password},{Tipo}"; writer.Append(filePath, linea); } return(RedirectToAction("Index", "Account")); }
public ActionResult Index() { if (Session["loggedAdmin"] == null) { return(RedirectToAction("Index", "Home")); } var reservationReader = new ReservationReader(); string filepathPrenotazioni = Server.MapPath("~/App_Data/Prenotazioni.txt"); IList <Reservation> listaPrenotazioni = reservationReader.Read(filepathPrenotazioni); string filepathAccount = Server.MapPath("~/App_Data/Utenti.txt"); var accountReader = new UserReader(); IList <Account> listaAccount = accountReader.Read(filepathAccount); string filepathConfermato = Server.MapPath("~/App_Data/Confermato.txt"); var confirmedReader = new ReservationConfirmedReader(); IList <ReservationConfirmed> prenotazioniConfermate = confirmedReader.Read(filepathConfermato); IList <ReservationViewModel> listaPrenotazioneViewModel = listaPrenotazioni.Where(k => k.Confermata == false) .Select(pre => new ReservationViewModel() { Id = pre.Id, Data = pre.Data, NomeProdotto = pre.NomeProdotto, Cliente = $"{listaAccount.First(e => e.Id == pre.IdAccount).Nome} {listaAccount.First(e => e.Id == pre.IdAccount).Cognome}", Prezzo = pre.Prezzo, Confermata = pre.Confermata }).ToList(); IList <ReservationConfirmedViewModel> prenotazioniConfermateViewModel = prenotazioniConfermate.Where(e => e.Evasa == false) .Select(pre => new ReservationConfirmedViewModel() { Id = pre.Id, Data = pre.Data, IdReservation = pre.IdReservation, Cliente = $"{listaAccount.First(e => e.Id == pre.IdAccount).Nome} {listaAccount.First(e => e.Id == pre.IdAccount).Cognome}", NomeProdotto = pre.NomeProdotto, Prezzo = pre.Prezzo, DataConferma = pre.DataConferma }).ToList(); IList <ReservationConfirmedViewModel> prenotazioniEvaseViewModel = prenotazioniConfermate.Where(e => e.Evasa == true) .Select(pre => new ReservationConfirmedViewModel() { Id = pre.Id, IdReservation = pre.IdReservation, Data = pre.Data, Cliente = $"{listaAccount.First(e => e.Id == pre.IdAccount).Nome} {listaAccount.First(e => e.Id == pre.IdAccount).Cognome}", NomeProdotto = pre.NomeProdotto, Prezzo = pre.Prezzo, Evasa = pre.Evasa, DataEvasione = pre.DataEvasione }).ToList(); var reservationResume = new ReservationResumeViewModel(); reservationResume.listaPrenotazioniAttive = listaPrenotazioneViewModel; reservationResume.listaPrenotazioniConfermate = prenotazioniConfermateViewModel; reservationResume.listaPrenotazioniEvase = prenotazioniEvaseViewModel; return(View(reservationResume)); }