static public string SprawdzDane(string id_pacjent) { String dane = string.Empty; Laczenie.Initialize(); Laczenie.Open(); string query = "select imie, nazwisko from [dbo].[pacjent] where id_pacjent =" + id_pacjent; List <int> nieakt_kod_userzy = new List <int>(); using (SqlCommand command = Laczenie.SqlCommand(query)) { SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { dane = reader.GetString(1) + " " + reader.GetString(0); } reader.Close(); } if (!String.IsNullOrEmpty(dane)) { return(dane); } else { return(""); } }
static public string SprawdzAkronim(string id_programu) { String akronim = string.Empty; Laczenie.Initialize(); Laczenie.Open(); string query = "select akronim from [dbo].[projekt] where id_projektu =" + id_programu; List <int> nieakt_kod_userzy = new List <int>(); using (SqlCommand command = Laczenie.SqlCommand(query)) { SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { akronim = reader.GetString(0); } reader.Close(); } if (!String.IsNullOrEmpty(akronim)) { return(akronim.Replace(" ", "")); } else { return(""); } }
static public int ZwrocRoleUser(string id_uzytk) { Laczenie.Open(); string query = "select id_uprawnienia from [dbo].[UZYTK] where id_uzytk=" + id_uzytk; int id_uprawnienia = -1; using (SqlCommand command = Laczenie.SqlCommand(query)) { SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { id_uprawnienia = reader.GetInt32(0); } reader.Close(); } return(id_uprawnienia); }
static public int ZwrocIdUser(string login) { Laczenie.Open(); string query = "select id_uzytk from [dbo].[UZYTK] where login='******'"; int id_uzytk = -1; using (SqlCommand command = Laczenie.SqlCommand(query)) { SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { id_uzytk = reader.GetInt32(0); } reader.Close(); } return(id_uzytk); }
static void Main(string[] args) { string godz; TimeSpan godzina; godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.Write($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "***ClientApp v.1.0***\n"); start: Console.Write($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "***Enter Server IP: "); string ip = Console.ReadLine(); // Pobiera IP serwera od klienta TcpClient client = new TcpClient(); try { client.Connect(IPAddress.Parse(ip), 8888); // Próbuje połączyć się z serwerem o podanym IP na porcie 8888 } catch (SocketException se) { godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.WriteLine($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "I can't connect with server... Closing app..."); Console.ReadKey(); goto start; } NetworkStream ns = client.GetStream(); // Tworzy strumień połączenia z serwerem godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; godz = Convert.ToString($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds}"); string message = "Operacja-)Hi(|Status-)Ask(|Identyfikator-)(|Data-)(|Time-)" + godz + "(|"; ns.Write(Encoding.ASCII.GetBytes(message), 0, message.Length); // Prosi serwer o ID sesji ns.Flush(); string[] msgs = new string[4]; msgs = Odbierz(ns); // Odbiera odpowiedź od serwera // Polaczenie zaakceptowane przez serwer if (msgs[0] == "Hi" && msgs[1] == "Ok") { godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.WriteLine($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "***Host connected to server!***\n"); int sesja = Convert.ToInt32(msgs[2]); godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.WriteLine($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "Your sesion id: " + msgs[2]); while (true) { here2: Laczenie pytaj = new Laczenie(ns, sesja); // Klasa odpowiedzialna pobieranie id sesji do połączenia od użytkownika Thread oThread = new Thread(new ThreadStart(pytaj.Run)); oThread.Start(); // Start wątku powyższej klasy msgs = Odbierz(ns); // Pobieranie odpowiedzi od drugiego klienta lub pytania o połączenie oThread.Abort(); // Koniec wątku klasy Laczenie // Pytanie o połączenie od drugiego klienta if (msgs[0] == "Chat" && msgs[1] == "Ask") { while (true) { Console.WriteLine("Client " + msgs[2] + " want to chat with you. Enter [1] to connect or [2] to reject: "); string input = Console.ReadLine(); if (input == "1") // Jeżeli użytkownik się zgodzi { Console.WriteLine("Connected with Client. Say something: "); godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; godz = Convert.ToString($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds}"); message = "Operacja-)Chat(|Status-)Ok(|Identyfikator-)" + sesja + "(|Data-)" + msgs[2] + "(|Time-)" + godz + "(|"; ns.Write(Encoding.ASCII.GetBytes(message), 0, message.Length); // Wysłanie odpowiedzi drugiemu klientowi ns.Flush(); bool conn = true; while (Polaczenie(ns, sesja, Convert.ToInt32(msgs[2]), ref conn)) // Pętla czatu { } break; } else if (input == "2") // Jeżeli użytkownik odmówi { godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; godz = Convert.ToString($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds}"); message = "Operacja-)Chat(|Status-)No(|Identyfikator-)" + sesja + "(|Data-)" + msgs[2] + "(|Time-)" + godz + "(|"; ns.Write(Encoding.ASCII.GetBytes(message), 0, message.Length); // Wysyłamy odpowiedź do drugiego użytkownika ns.Flush(); break; } else if (input == "") { } else { Console.WriteLine("Wrong input!"); } } } // Drugi klient zaakceptował zaproszenie else if (msgs[0] == "Chat" && msgs[1] == "Ok") { Console.WriteLine("Client connected! Say something: "); int sesja2 = pytaj.sesja2; bool connect = true; while (Polaczenie(ns, sesja, sesja2, ref connect)) { } // Pętla czatu goto here2; } // Drugi klient odrzucił zaproszenie else if (msgs[1] == "No") { godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.WriteLine($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "Client don't want to chat with you..."); } // Brak klienta z takim ID else if (msgs[1] == "Noclient") { godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.WriteLine($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "No client with this ID..."); } else { godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.WriteLine($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "Ups something wrong, try again..."); } } } // Serwer odmówił połączenia else if (msgs[0] == "Hi" && msgs[1] == "No") { godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.WriteLine($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "***Host can't connect with server!***"); client.Close(); Console.ReadKey(); return; } else { godzina = DateTime.UtcNow.ToLocalTime().TimeOfDay; Console.WriteLine($"{godzina.Hours}:{godzina.Minutes}:{godzina.Seconds} " + "Problems with connection, you will be disconnected..."); client.Close(); Console.ReadKey(); return; } }