public List <UserInfo> loginUser(string email, string password) { // kode get data from sql server.. Koneksi kon = new Koneksi(); SqlConnection sqlcon = kon.getConnection(); List <UserInfo> objList = new List <UserInfo>(); using (sqlcon) { sqlcon.Open(); string sql = "select * from tb_customer where email = @email and password = @password "; SqlCommand sqlcom = new SqlCommand(sql, sqlcon); using (sqlcom) { sqlcom.Parameters.AddWithValue("@email", email); sqlcom.Parameters.AddWithValue("@password", password); SqlDataReader dr = sqlcom.ExecuteReader(); if (dr.Read()) { UserInfo obj = new UserInfo(); obj.IDUser = dr.GetString(1); obj.NameUser = dr.GetString(2); //Convert Date Time to String. DateTime dt = Convert.ToDateTime(dr.GetDateTime(3)); obj.BirthdateUser = dt.ToString("dd-MM-yyyy"); obj.AddressUser = dr.GetString(4); obj.PhoneNumberUser = dr.GetString(5); obj.Card_typeUser = dr.GetString(6); obj.Card_numberUser = dr.GetString(7); obj.EmailUser = dr.GetString(8); obj.PasswordUser = dr.GetString(9); objList.Add(obj); } } sqlcon.Close(); } return(objList); }
public string insertData(ReservationInfo data) { Koneksi kon = new Koneksi(); SqlConnection sqlcon = kon.getConnection(); string msg = string.Empty; using (sqlcon) { sqlcon.Open(); string sql = "insert into tb_reservation (id_room,id_customer,info) values (@idroom,@idcustomer,@info);"; SqlCommand sqlcom = new SqlCommand(sql, sqlcon); using (sqlcom) { sqlcom.Parameters.AddWithValue("@idroom", data.IDRoomReservation); sqlcom.Parameters.AddWithValue("@idcustomer", data.IDCustomerReservation); sqlcom.Parameters.AddWithValue("@info", data.InfoReservation); int res = sqlcom.ExecuteNonQuery(); msg = (res != 0 ? "Data has been saved." : "Oops, something went wrong."); } sqlcon.Close(); } return(msg); }
public List <UserInfo> getUserFromName(string nama) { // kode get data from sql server.. Koneksi kon = new Koneksi(); SqlConnection sqlcon = kon.getConnection(); List <UserInfo> objList = new List <UserInfo>(); using (sqlcon) { sqlcon.Open(); string sql = "select * from tb_customer where name like @nama "; SqlCommand sqlcom = new SqlCommand(sql, sqlcon); using (sqlcom) { sqlcom.Parameters.AddWithValue("@nama", '%' + nama + '%'); SqlDataReader dr = sqlcom.ExecuteReader(); while (dr.Read()) { UserInfo obj = new UserInfo(); obj.IDUser = dr.GetString(1); obj.NameUser = dr.GetString(2); //Convert Date Time to String. DateTime dt = Convert.ToDateTime(dr.GetDateTime(3)); obj.BirthdateUser = dt.ToString("dd-MM-yyyy"); obj.AddressUser = dr.GetString(4); obj.PhoneNumberUser = dr.GetString(5); obj.Card_typeUser = dr.GetString(6); obj.Card_numberUser = dr.GetString(7); objList.Add(obj); } } sqlcon.Close(); } return(objList); }