Example #1
0
        public static void sendData(this client cs)//chek input >> connect >> send prescription to server >> db
        {
            int cnt = 0;

            try
            {
                connectToServer("127.0.0.1", 8001);
            }
            catch (Exception) { }

            MedSchd med = new MedSchd();

            med.ClientId     = cs.text_id.Text;
            med.PharmacistId = cs.Pharmacist_number_txt.Text;
            med.MedId        = cs.comboMed.SelectedItem.ToString();
            if (cs.MorningText.Text == "")
            {
                med.AmountMorning = 0;
            }
            else
            {
                med.AmountMorning = Int32.Parse(cs.MorningText.Text);
            }
            if (cs.NoonText.Text == "")
            {
                med.AmountNoon = 0;
            }
            else
            {
                med.AmountNoon = Int32.Parse(cs.NoonText.Text);
            }
            if (cs.NightText.Text == "")
            {
                med.AmountNight = 0;
            }
            else
            {
                med.AmountNight = Int32.Parse(cs.NightText.Text);
            }
            med.StartTime = DateTime.Now;
            med.DaysLong  = Int32.Parse(cs.NumOfDays_txt.Text);

            string medSchd_json = JsonConvert.SerializeObject(med);

            MedSchd med2 = JsonConvert.DeserializeObject <MedSchd>(medSchd_json);

            while (cnt < 2)
            {
                if (cnt == 0)
                {
                    writer.Write("prescription");
                    cnt++;
                }
                else
                {
                    writer.Write(medSchd_json);
                    cnt++;
                }
            }
        }
Example #2
0
        public void clientHandler(object clientConection)//פתיחת סטרים וקבלת מידע מהלקוח.. הצגת הודעה על העברה מוצלחת או בעיה בהעברה
        {
            NewClient newC   = new NewClient();
            string    str    = "";
            int       cnt    = 0;
            TcpClient client = clientConection as TcpClient;

            if (client == null)
            {
                throw new Exception("A non valid connection");
            }
            NetworkStream stream = client.GetStream();
            BinaryReader  reader = new BinaryReader(stream);
            BinaryWriter  writer = new BinaryWriter(stream);

            writer.Write("Starting Loop");
            while (client.Connected)
            {
                str = reader.ReadString();

                if (str == "EXIT")
                {
                    client.Close();
                }
                else if (str == "prescription")
                {
                    medSchd_json = reader.ReadString();
                    medSchd      = JsonConvert.DeserializeObject <MedSchd>(medSchd_json);
                    initConnection();
                    cnt++;
                }
                else if (str == "clientId")
                {
                    try
                    {
                        string         id               = reader.ReadString();
                        bool           found            = false;
                        DataSet        ds_old_Client_id = new DataSet();
                        SqlDataAdapter da_old_Client_id = new SqlDataAdapter("SELECT * FROM Client", connection);
                        da_old_Client_id.Fill(ds_old_Client_id, "Client");
                        DataRow[] arr_client = ds_old_Client_id.Tables["Client"].Select("IdNumber =" + id);

                        foreach (DataRow dr in arr_client)
                        {
                            found             = true;
                            newC.ClientId    += dr["IdNumber"];
                            newC.FirstName   += dr["FirstName"];
                            newC.LastName    += dr["LastName"];
                            newC.PhoneNumber += dr["PhoneNumber"];
                        }
                        if (!found)
                        {
                            newC.ClientId    = null;
                            newC.FirstName   = null;
                            newC.LastName    = null;
                            newC.PhoneNumber = null;
                            string client_json = JsonConvert.SerializeObject(newC);
                            writer.Write(client_json);
                        }
                        else
                        {
                            string client_json = JsonConvert.SerializeObject(newC);
                            writer.Write(client_json);
                        }
                        cnt++;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }

                else if (str == "PharmacistId")
                {
                    try
                    {
                        string         str_p         = reader.ReadString();
                        string         str_PN        = "";
                        bool           found         = false;
                        DataSet        ds_pharmacist = new DataSet();
                        SqlDataAdapter da_pharmacist = new SqlDataAdapter("SELECT * FROM pharmacist", connection);
                        da_pharmacist.Fill(ds_pharmacist, "pharmacist");
                        DataRow[] arr_p = ds_pharmacist.Tables["pharmacist"].Select("IdNumber =" + str_p);

                        foreach (DataRow dr in arr_p)
                        {
                            found   = true;
                            str_PN += dr["FirstName"];
                        }
                        if (!found)
                        {
                            str_PN = "";
                            writer.Write(str_PN);
                        }
                        else
                        {
                            writer.Write(str_PN);
                        }
                        cnt++;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
                else if (str == "MedCombo")
                {
                    DataSet        ds_medCombo = new DataSet();
                    SqlDataAdapter da_medCombo = new SqlDataAdapter("SELECT BrandName FROM medicines", connection);
                    da_medCombo.Fill(ds_medCombo, "medicines");
                    DataRow[] arr_p = ds_medCombo.Tables["medicines"].Select();

                    var medList = ds_medCombo.Tables["medicines"]
                                  .AsEnumerable()
                                  .Select(medicine => new
                    {
                        BrnadName = medicine.Field <string>("BrandName")
                    });

                    string med_str = "";

                    foreach (var med in medList)
                    {
                        med_str += med.BrnadName.Trim() + ",";
                    }

                    writer.Write(med_str);
                }
            }
        }
Example #3
0
        public static void sendData(this client cs)//בדיקת תקינות ושליחת מידע
        {
            int cnt = 0;

            connectToServer("127.0.0.1", 8001);

            MedSchd med = new MedSchd();

            med.ClientId     = cs.text_id.Text;
            med.PharmacistId = Int32.Parse(cs.Pharmacist_number_txt.Text);
            med.MedId        = cs.comboMed.SelectedItem.ToString();
            if (cs.MorningText.Text == "")
            {
                med.AmountMorning = 0;
            }
            else
            {
                med.AmountMorning = Int32.Parse(cs.MorningText.Text);
            }
            if (cs.NoonText.Text == "")
            {
                med.AmountNoon = 0;
            }
            else
            {
                med.AmountNoon = Int32.Parse(cs.NoonText.Text);
            }
            if (cs.NightText.Text == "")
            {
                med.AmountNight = 0;
            }
            else
            {
                med.AmountNight = Int32.Parse(cs.NightText.Text);
            }
            med.StartTime = DateTime.Now;
            med.DaysLong  = Int32.Parse(cs.NumOfDays_txt.Text);

            string medSchd_json = JsonConvert.SerializeObject(med);

            MedSchd med2 = JsonConvert.DeserializeObject <MedSchd>(medSchd_json);

            while (cnt < 2)
            {
                if (cnt == 0)
                {
                    writer.Write("prescription");
                    cnt++;
                }
                else
                {
                    writer.Write(medSchd_json);
                    cnt++;
                }
            }

            //איפוס משתנים לאחר שליחה
            cs.text_id.Text           = "";
            cs.text_fName.Text        = "";
            cs.text_lName.Text        = "";
            cs.paneldays.Visible      = true;
            cs.MorningText.Text       = "";
            cs.NoonText.Text          = "";
            cs.NightText.Text         = "";
            cs.comboMed.SelectedIndex = -1;
            cs.NumOfDays_txt.Text     = "";
            cs.PhoneNumberText.Text   = "";
        }