Example #1
0
 private void setAddButton_Click(object sender, EventArgs e)
 {
     if (diseaseText.Text != "")
     {
         if (checkVxojdenie())
         {
             DiseaseEntity diseaseEntity = new DiseaseEntity(DBAPI.getMAXDiseaseID() + 1, diseaseText.Text);
             DBAPI.SaveDisease(diseaseEntity);
             foreach (SymptomsComp s in symptomsComps)
             {
                 if (s.isChecked())
                 {
                     try
                     {
                         DBAPI.SaveMatch(new MatchesEntity(diseaseEntity.Id,
                                                           s.Id, Double.Parse(s.Confidence.Text), Double.Parse(s.Distrust.Text)));
                     }
                     catch (Exception ex)
                     {
                         MessageBox.Show(ex.ToString());
                     }
                 }
             }
             clearDiseaseAdd();
             setDiseaseAdd();
             clearDiseaseList();
             setDiseaseList();
         }
         else
         {
             MessageBox.Show("Так нельзя");
         }
     }
 }
Example #2
0
        private void setDiseaseList()
        {
            var   list   = DBAPI.LoadDiseases();
            int   x      = this.Width - 400;
            int   y      = 50;
            Label naming = new Label();

            naming.Text     = "Список болезней:";
            naming.AutoSize = true;
            naming.Location = new System.Drawing.Point(x, y);
            this.Controls.Add(naming);
            y += 30;

            foreach (DiseaseEntity d in list)
            {
                Label  name   = new Label();
                Button delete = new Button();
                delete.Location = new System.Drawing.Point(x - 30, y);
                delete.AutoSize = true;
                delete.Text     = "X";
                delete.Width    = 20;
                delete.Click   += (object sender, EventArgs e) =>
                {
                    DBAPI.DeleteDisease(d);
                    //this.Controls.Remove(delete);

                    clearDiseaseList();
                    setDiseaseList();
                };

                name.Text     = d.Disease;
                name.AutoSize = true;

                name.Click += (object sender, EventArgs e) =>
                {
                    var           matches = DBAPI.LoadMatchesByDisease(d.Id);
                    StringBuilder s       = new StringBuilder();
                    foreach (MatchesEntity m in matches)
                    {
                        s.Append(DBAPI.getSymptomByID(m.Symptoms_id).Symptom + " [" + m.Confidence_measure + " : " + m.Distrust_measure + "]\n");
                    }
                    MessageBox.Show(s.ToString());
                };
                name.Location = new System.Drawing.Point(x, y);
                y            += 30;
                diseases.Add(name);
                diseaseButtons.Add(delete);
                this.Controls.Add(name);
                this.Controls.Add(delete);
            }
        }
Example #3
0
        private bool checkVxojdenie()
        {
            var diseases = DBAPI.LoadDiseases();

            var comps = symptomsComps.GroupBy(k => k.isChecked()).ToList();

            foreach (DiseaseEntity d in diseases)
            {
                var matchesids = DBAPI.LoadMatchesByDisease(d.Id);
                var sympts     = matchesids.Select(k => k.Symptoms_id).ToList();

                int count = 0;

                foreach (SymptomsComp m in comps[0])
                {
                    foreach (MatchesEntity match in matchesids)
                    {
                        if (m.Id == match.Symptoms_id)
                        {
                            count++;
                        }
                    }
                }

                if (comps[0].Count() == count && comps[0].Count() < matchesids.Count)
                {
                    MessageBox.Show("Содержится");
                    System.Console.WriteLine("Содержится");
                    return(false);
                }
                if (comps[0].Count() == count && comps[0].Count() == matchesids.Count)
                {
                    MessageBox.Show("Существует");
                    System.Console.WriteLine("Существует");
                    return(false);
                }
                if (matchesids.Count == count && comps[0].Count() > matchesids.Count && matchesids != null)
                {
                    MessageBox.Show("Содержит");
                    System.Console.WriteLine("Содержит");
                    return(false);
                }
            }

            return(true);
        }
Example #4
0
        private void setSymptomsAdd()
        {
            int   x      = this.Width / 2;
            int   y      = 50;
            Label naming = new Label();

            naming.Text     = "Добавить симптом:";
            naming.AutoSize = true;
            naming.Location = new System.Drawing.Point(x, y);
            this.Controls.Add(naming);
            y += 30;

            symptomText          = new TextBox();
            symptomText.Location = new System.Drawing.Point(x, y);
            Button addSympbutton = new Button();

            addSympbutton.Location = new System.Drawing.Point(x, y + 20);
            addSympbutton.Text     = "Добавить симптом";
            addSympbutton.Click   += (object sender, EventArgs e) =>
            {
                if (symptomText.Text != "")
                {
                    try
                    {
                        DBAPI.SaveSymptom(new SymptomEntity(DBAPI.getMAXSymptomID() + 1, symptomText.Text));
                        clearDiseaseAdd();
                        setDiseaseAdd();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            };

            Controls.AddRange(new System.Windows.Forms.Control[] { symptomText, addSympbutton });
        }
Example #5
0
        public Form1()
        {
            InitializeComponent();

            var dis = DBAPI.LoadDiseases();
        }
Example #6
0
        private void setTestList()
        {
            int    x = 50, y = 50;
            double dov = 0, nedov = 0;

            Button test = new Button();

            test.Text     = "Узнать";
            test.Location = new System.Drawing.Point(x, y);
            test.Click   += (object sender, EventArgs e) =>
            {
                dov   = 0;
                nedov = 0;
                this.symptoms.Clear();
                this.coefs.Clear();
                foreach (SymptomsComp s in symptomsComps)
                {
                    if (s.isChecked())
                    {
                        this.symptoms.Add(new SymptomEntity(s.Id, s.Checkbox.Text));
                    }
                }
                var diseases = DBAPI.LoadDiseases();
                foreach (DiseaseEntity d in diseases)
                {
                    var matches = DBAPI.LoadMatchesByDisease(d.Id);
                    foreach (MatchesEntity m in matches)
                    {
                        if (this.symptoms.Find(v => v.Id == m.Symptoms_id) != null)
                        {
                            dov   += (m.Confidence_measure * (1 - dov));
                            nedov += (m.Distrust_measure * (1 - nedov));
                        }
                    }
                    this.coefs.Add(d.Disease, (dov - nedov));
                }
                result = new Result(this.coefs);
                //result.Coefs = this.coefs;
                result.Show();
            };
            this.Controls.Add(test);
            y += 40;

            var symptoms = DBAPI.LoadSymptoms();

            foreach (SymptomEntity s in symptoms)
            {
                CheckBox cb = new CheckBox();

                cb.Location = new System.Drawing.Point(x, y);
                //label.Location = new System.Drawing.Point(x + 20, y);
                cb.Text     = s.Symptom;
                cb.AutoSize = true;
                //label.AutoSize = true;

                this.Controls.AddRange(new System.Windows.Forms.Control[] { cb });
                symptomsComps.Add(new SymptomsComp(cb, new TextBox(), new TextBox(), s.Id, new Button()));

                y += 30;
            }
        }
Example #7
0
        private void setDiseaseAdd()
        {
            symptomsComps.Clear();
            int x = 50, y = 90;

            try
            {
                var symptoms = DBAPI.LoadSymptoms();

                foreach (SymptomEntity s in symptoms)
                {
                    CheckBox cb        = new CheckBox();
                    TextBox  conf      = new TextBox();
                    TextBox  distr     = new TextBox();
                    Button   delbutton = new Button();

                    cb.Location = new System.Drawing.Point(x, y);
                    //label.Location = new System.Drawing.Point(x + 20, y);
                    cb.Text     = s.Symptom;
                    cb.AutoSize = true;
                    //label.AutoSize = true;
                    conf.Location  = new System.Drawing.Point(x + 220, y);
                    conf.Width     = 50;
                    distr.Location = new System.Drawing.Point(x + 280, y);
                    distr.Width    = 50;

                    distr.Validating += (object sender, CancelEventArgs e) =>
                    {
                        // if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab)
                        // {
                        double d1 = -1, d2 = -1;
                        double.TryParse(distr.Text, out d1);
                        double.TryParse(conf.Text, out d2);
                        if (d1 > d2 && d1 != -1 && d2 != -1)
                        {
                            MessageBox.Show("Значение должно быть меньше меры доверия");
                        }
                        else
                        {
                            if (d1 <= 0)
                            {
                                MessageBox.Show("Значение должно быть положительным");
                            }
                        }
                        //  }
                    };
                    conf.Validating += (object sender, CancelEventArgs e) =>
                    {
                        double d1 = -1;
                        double.TryParse(conf.Text, out d1);
                        if ((d1 <= 0 || d1 > 1) && d1 != -1)
                        {
                            MessageBox.Show("Значение должно быть в диапазоне от 0 до 1");
                        }
                    };



                    delbutton.Location = new System.Drawing.Point(x + 340, y);
                    delbutton.Text     = "X";
                    delbutton.AutoSize = true;
                    delbutton.Click   += (object sender, EventArgs e) =>
                    {
                        DBAPI.DeleteSymptom(s);
                        clearDiseaseAdd();
                        setDiseaseAdd();
                    };

                    this.Controls.AddRange(new System.Windows.Forms.Control[] { cb, conf, distr, delbutton });
                    symptomsComps.Add(new SymptomsComp(cb, conf, distr, s.Id, delbutton));

                    y += 30;
                }
                addDiseaseButton.Location = new System.Drawing.Point(x, y + 20);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }