Exemple #1
0
        private void btnDoctorForm_Click(object sender, EventArgs e)
        {
            EndPoint epRemote = new IPEndPoint(IPAddress.Parse("192.168.0.117"),
                                               Convert.ToInt32("8000"));


            SqlConnection conn = new SqlConnection();// ("Data Source = (LocalDB)\\MSSQLLocalDB;AttachDbFilename=" + "D:\\C#\\PoliHack6\\PoliHackV4\\DatabaseApp.mdf;" + "Integrated Security = True");

            conn.ConnectionString = PoliHackV4.Properties.Resources.ConnectionStringLogin;
            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("There was an error" + ex.ToString());
            }
            SqlDataReader rd   = null;
            SqlCommand    cmd  = new SqlCommand("SELECT IP FROM Login where Username = @Username", conn);
            SqlCommand    cmd2 = new SqlCommand("SELECT * FROM Login", conn);

            cmd.Parameters.AddWithValue("Username", name);

            rd = cmd2.ExecuteReader();
            Trace.WriteLine("Asta e numele" + name);
            string ip = null;

            while (rd.Read())
            {
                if (rd["Username"].ToString() == name)
                {
                    ip = rd["IP"].ToString();
                }
            }
            //string ip = "111";
            Trace.WriteLine(ip);
            try
            {
                EndPoint epLocal = new IPEndPoint(IPAddress.Parse(ip),
                                                  Convert.ToInt32("8000"));

                //EndPoint epLocal = new IPEndPoint(IPAddress.Parse("192.168.0.140"),
                //Convert.ToInt32("8000"));
                TreatmentForm formTreat = new TreatmentForm(epLocal, epRemote, cntTreatmentForm);
                cntTreatmentForm++;
                //formTreat.Parent = this;
                formTreat.Show();
                //this.Hide();
                //while(formTreat.Visible == true)
                // {
                //    this.Visible = false;
                //}
                this.Visible = true;
            }
            catch
            {
                Trace.WriteLine("This is the ip!!!!" + ip);
                this.Close();
            }
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string numeFinal = null;
            string ipAdress  = null;

            using (SqlConnection conn = new SqlConnection())
            {
                try
                {
                    //conn.ConnectionString = "Data Source = (LocalDB)\\MSSQLLocalDB;AttachDbFilename=" + "C:\\Users\\Horatiu\\Desktop\\PoliHack5\\PoliHackV4\\DatabaseApp.mdf;" + "Integrated Security = True";
                    //conn.ConnectionString = "Data Source = (LocalDB)\\MSSQLLocalDB;AttachDbFilename=" + "D:\\C#\\PoliHack6\\PoliHackV4\\DatabaseApp.mdf;" + "Integrated Security = True";
                    conn.ConnectionString = PoliHackV4.Properties.Resources.ConnectionStringLogin;
                }
                catch (Exception exception1)
                {
                    Debug.WriteLine(exception1.ToString());
                    MessageBox.Show("There was an error at connection LoginForm!" + exception1.ToString());

                    return;
                }
                try
                {
                    conn.Open();
                }
                catch (Exception exception1)
                {
                    Debug.WriteLine(exception1.ToString());
                    MessageBox.Show("There was an error at connection LoginForm!" + exception1.ToString());

                    return;
                }
                SqlCommand    command2           = new SqlCommand("SELECT * FROM Login", conn);
                SqlCommand    command3           = new SqlCommand("Select * FROM Pacients", conn);
                SqlDataReader dataReader         = null;
                SqlDataReader dataReaderPacients = null;
                string        s = null;
                if (comboBox2.SelectedItem.ToString() != "")
                {
                    s = comboBox2.SelectedItem.ToString();
                }
                else
                {
                    MessageBox.Show("Te rog selecteaza un pacient");
                    return;
                }

                string[] numePrenume = s.Split(' ');

                //dataReaderPacients = command3.ExecuteReader();
                try
                {
                    dataReaderPacients = command3.ExecuteReader();
                }
                catch (SqlException oError)
                {
                    Debug.WriteLine(oError.ToString());
                    MessageBox.Show(oError.ToString());
                }
                while (dataReaderPacients.Read())
                {
                    if (dataReaderPacients["Nume"].ToString() == numePrenume[0])
                    {
                        numeFinal = dataReaderPacients["Username"].ToString();
                        break;
                    }
                }
                dataReaderPacients.Close();
                try
                {
                    dataReader = command2.ExecuteReader();
                }
                catch (SqlException oError)
                {
                    Debug.WriteLine(oError.ToString());
                    MessageBox.Show(oError.ToString());
                }
                while (dataReader.Read())
                {
                    if (numeFinal == dataReader["Username"].ToString())
                    {
                        ipAdress = dataReader["IP"].ToString();
                        break;
                    }
                }
                dataReader.Close();
                Debug.WriteLine(ipAdress);
            }
            try
            {
                EndPoint epRemote = new IPEndPoint(IPAddress.Parse(ipAdress),
                                                   Convert.ToInt32("8000"));
                EndPoint epLocal = new IPEndPoint(IPAddress.Parse("192.168.0.117"),
                                                  Convert.ToInt32("8000"));
                TreatmentForm formTreat = new TreatmentForm(epLocal, epRemote, cntTreat);

                cntTreat++;
                formTreat.Show();
                comboBox1.Items.Clear();
                string baseDir = System.AppDomain.CurrentDomain.BaseDirectory;

                /*
                 * var s = System.IO.Path.Combine(baseDir, @"\\Conversatii");
                 */
                var      s     = baseDir + "Conversatii";
                string[] files = System.IO.Directory.GetFiles(s);

                comboBox1.Items.AddRange(files);
                //comboBox1.SelectedItem = 1;
                this.Visible = true;
            }
            catch (Exception e6)
            {
                MessageBox.Show(e6.Message);
            }
        }