Exemplo n.º 1
0
        //Calculator IMC
        private void button5_Click(object sender, EventArgs e)
        {
            if (ok == 1)
            {
                string W = metroTextBox4.Text;
                string H = metroTextBox5.Text;

                double IMC = Convert.ToDouble(W) * 10000 / (Convert.ToDouble(H) * Convert.ToDouble(H));
                IMC = Math.Round(IMC, 2);
                metroTextBox1.Text = "IMC :" + Convert.ToString(IMC);

                string result = Util_Func.Result_IMC((float)IMC);
                metroTextBox2.Text = result;
            }
            else
            {
                string errorMessage = "INVALID input data";
                err.SetError(button5, errorMessage);
            }
        }
Exemplo n.º 2
0
        // SAVE BUTTON //
        private void metroButton1_Click(object sender, EventArgs e)
        {
            // Validate First Name
            string FirstName = metroTextBox1.Text;
            string regex     = "^[a-zA-Z -]+$";

            if (Regex.IsMatch(FirstName, regex) && (FirstName.Length > 3) && (FirstName.Length < 20))
            {
                err.Clear();
            }
            else
            {
                string errorMessage = "Maximum size:10.\nMinimum size:3.\nFirst Name must have a valid format.\n" +
                                      "For example 'Name' ";
                err.SetError(metroTextBox1, errorMessage);
                return;
            }

            //Validate Last Name
            regex = "^[a-zA-Z]+$";
            string LastName = metroTextBox2.Text;

            if (Regex.IsMatch(LastName, regex) && (LastName.Length > 3) && (LastName.Length < 10))
            {
                err.Clear();
            }
            else
            {
                string errorMessage = "Maximum size:10.\nMinimum size:3.\nLast Name must have a valid format.\n" +
                                      "For example 'Name' ";
                err.SetError(metroTextBox2, errorMessage);
                return;
            }

            //Validate Email
            if (string.IsNullOrEmpty(metroTextBox7.Text) || metroTextBox7.Text != "-")
            {
                string emailAddress = metroTextBox7.Text;

                if (emailAddress.Length == 0)
                {
                    err.SetError(metroTextBox7, "if you don't have an email address complete with - ");
                    metroTextBox7.Text = "-";
                    return;
                }

                else if (metroTextBox7.Text != "-")
                {
                    regex = "^[^@\\s]+@[^@\\s]+(\\.[^@\\s]+)+$";
                    if (Regex.IsMatch(emailAddress, regex))
                    {
                        err.Clear();
                    }
                    else
                    {
                        string errorMessage = "e-mail address must be valid e-mail address format.\n" +
                                              "For example '*****@*****.**' ";
                        err.SetError(metroTextBox7, errorMessage);
                        return;
                    }
                }
            }


            // Validate Phone number
            string phone = metroTextBox3.Text;

            regex = "^\\(?\\d{4}\\)?[\\s.-]\\d{3}[\\s.-]\\d{3}$";
            if (phone.Length == 0)
            {
                err.SetError(metroTextBox7, "if you don't have a phone number complete with - ");
                metroTextBox3.Text = "-";
            }
            else if (metroTextBox3.Text != "-")
            {
                if (Regex.IsMatch(phone, regex))
                {
                    err.Clear();
                }
                else
                {
                    string errorMessage = "Phone number must have a valid format.\n" +
                                          "For example 'xxxx xxx xxx' \n            'xxxx.xxx.xxx' \n            'xxxx-xxx-xxx' \n";
                    err.SetError(metroTextBox3, errorMessage);
                    return;
                }
            }


            // Validate Weight number
            string weight = metroTextBox4.Text;

            regex = "^(0|([1-9][0-9]*))(\\.[0-9]+)?$";
            if (Regex.IsMatch(weight, regex))
            {
                err.Clear();
            }
            else
            {
                string errorMessage = "The weight must be a number format.\n" +
                                      "For example '80.2' ";
                err.SetError(metroTextBox4, errorMessage);
                return;
            }


            // Validate Height number
            string height = metroTextBox5.Text;

            regex = "^(0|([1-9][0-9]*))(\\.[0-9]+)?$";
            if (Regex.IsMatch(height, regex))
            {
                err.Clear();
            }
            else
            {
                string errorMessage = "The height must be a number format.\n" +
                                      "For example '1.82' ";
                err.SetError(metroTextBox5, errorMessage);
                return;
            }

            // Validate age number
            string age = metroTextBox6.Text;

            if (string.IsNullOrEmpty(metroTextBox6.Text))
            {
                string errorMessage = "The age must be a integer format.\n" +
                                      "For example '22' ";
                err.SetError(metroTextBox6, errorMessage);
                return;
            }
            else
            {
                if (Convert.ToInt32(age) > 0 && Convert.ToInt32(age) < 200)
                {
                    err.Clear();
                }
                else
                {
                    string errorMessage = "The age must be a integer format.\n" +
                                          "For example '22' ";
                    err.SetError(metroTextBox6, errorMessage);
                    return;
                }
            }


            //Valide gender
            if (string.IsNullOrEmpty(metroComboBox1.Text))
            {
                err.SetError(metroComboBox1, "Please Chose Value from Gender  ");
                return;
            }

            //Validate observations Box
            if (string.IsNullOrEmpty(richTextBox1.Text))
            {
                err.SetError(richTextBox1, "if you don't have a observation complete with - ");
                richTextBox1.Text = "-";
                return;
            }
            if (string.IsNullOrEmpty(richTextBox2.Text))
            {
                err.SetError(richTextBox2, "if you don't have a observation complete with - ");
                richTextBox2.Text = "-";
                return;
            }

            // Calcul IMC si gasire rezultat//
            double        w      = Convert.ToDouble(metroTextBox4.Text);
            double        h      = Convert.ToDouble(metroTextBox5.Text);
            string        result = Util_Func.Result_IMC(Util_Func.IMC_Calculator((float)w, (float)h));
            SqlConnection con    = new SqlConnection(Globals.connString);
            SqlCommand    cmd    = new SqlCommand("Select * from Nutritional where Result='" + result + "'", con);

            con.Open();
            SqlDataReader rdr = cmd.ExecuteReader();

            Int32 nID = 1;

            if (rdr.Read())
            {
                nID = rdr.GetInt32(0);
            }
            else
            {
                MessageBox.Show(Convert.ToString("The element from DataBase NUTRITIONAL doesn't exist! "));
            }
            rdr.Close();


            cmd = new SqlCommand("insert into Patients (FirstName,LastName,Gender,Phone,Weight,Height,Age,Email,NId_fk) values (@fname, @lname,@gender,@phone, @weight, @height,@age,@email,@Nutritional_ID)", con);
            cmd.Parameters.Add("@fname", metroTextBox1.Text);
            cmd.Parameters.Add("@lname", metroTextBox2.Text);
            cmd.Parameters.Add("@gender", metroComboBox1.GetItemText(metroComboBox1.SelectedItem));
            cmd.Parameters.Add("@phone", metroTextBox3.Text);
            cmd.Parameters.Add("@weight", Convert.ToDouble(metroTextBox4.Text));
            cmd.Parameters.Add("@height", Convert.ToDouble(metroTextBox5.Text));
            cmd.Parameters.Add("@age", metroTextBox6.Text);
            cmd.Parameters.Add("@email ", metroTextBox7.Text);
            cmd.Parameters.Add("@Nutritional_ID ", nID);
            cmd.ExecuteNonQuery();


            cmd = new SqlCommand("insert into Observations (PId_fk,Nutritional_Obs,Medical_Obs) values ( (select MAX (Id) from Patients), @n_obs,@m_obs)", con);
            cmd.Parameters.Add("@n_obs", richTextBox1.Text);
            cmd.Parameters.Add("@m_obs", richTextBox2.Text);
            cmd.ExecuteNonQuery();


            // ID-ul se cunoaste si se face legatura dintre DISEASES si PATIENTS
            if (diseases.Count == 0)//Asigură că pune - dacă nu este nimic
            {
                cmd = new SqlCommand("insert into Patients_Diseases (PId_fk,DId_fk) values ( (select MAX(Id) from Patients), @DiseasesID)", con);
                cmd.Parameters.Add("@DiseasesID", 1);
                cmd.ExecuteNonQuery();
            }
            else
            {
                foreach (string str in diseases)
                {
                    cmd = new SqlCommand("insert into Patients_Diseases (PId_fk,DId_fk) values ( (select MAX(Id) from Patients),(select Id from Diseases where Disease=@DiseasesID) )", con);
                    cmd.Parameters.Add("@DiseasesID", str);
                    cmd.ExecuteNonQuery();
                }
            }
            con.Close();
            messagebox save = new messagebox();

            this.Close();
            save.ShowDialog(this);
        }