Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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());
            }
        }