示例#1
0
文件: Form1.cs 项目: emskypl/KNN_CBR
        private void deleteButton_Click(object sender, EventArgs e)
        {
            int IDtab;

            Int32.TryParse(textBoxID.Text.ToString(), out IDtab);
            Irises dane = new Irises()
            {
                ID = IDtab
            };

            if (!IDtab.Equals(0))
            {
                try
                {
                    using (var dataContext = new BazaDanychStruktura())
                    {
                        dataContext.Entry(dane).State = EntityState.Deleted;

                        dataContext.SaveChanges();
                    }
                    logBox.Text += DateTime.Now.ToString("HH:mm:ss ") + "Usunięto z bazy wpis o ID " + textBoxID.Text.ToString() + ". \n";
                }
                catch (Exception) { logBox.Text += DateTime.Now.ToString("HH:mm:ss ") + "BŁĄD: Identyfikator " + IDtab.ToString() + " nie istnieje w bazie \n"; }
            }
            else
            {
                logBox.Text += DateTime.Now.ToString("HH:mm:ss ") + "BŁĄD: Podaj identyfikator.  \n";
            }
        }
示例#2
0
文件: Form1.cs 项目: emskypl/KNN_CBR
        //TODO:
        //
        //
        private void modifyButton_Click(object sender, EventArgs e)
        {
            if (!textBoxID.Text.Equals(""))
            {
                int IDtab = Int32.Parse(textBoxID.Text.ToString());

                Irises dane = new Irises()
                {
                    ID             = IDtab,
                    sepal_length   = sepalLength,
                    sepal_width    = sepalWidth,
                    petal_length   = petalLength,
                    petal_width    = petalWidth,
                    classification = textBoxClassification.Text.ToString()
                };
                try {
                    if (!textBoxClassification.Text.Equals(""))
                    {
                        using (var dataContext = new BazaDanychStruktura())
                        {
                            /*
                             * var x = dataContext.Irises.First<Irises>();
                             * var y = dataContext.Irises.ElementAt<Irises>(2);
                             *
                             * y.ID = IDtab;
                             * y.petal_length = petalLength;
                             * y.petal_width = petalWidth;
                             * y.sepal_length = sepalLength;
                             * y.sepal_width = sepalWidth;
                             *
                             * x.sepal_length = sepalLength;
                             * x.sepal_width = sepalWidth;
                             * x.petal_length = petalLength;
                             * x.petal_width = petalWidth;
                             * x.classification = textBoxClassification.Text.ToString();
                             */
                            dataContext.Entry(dane).State = EntityState.Modified;
                            dataContext.SaveChanges();
                        }
                        logBox.Text += DateTime.Now.ToString("HH:mm:ss ") + "Zmodyfikowano w bazie wpis o ID " + textBoxID.Text.ToString() + ". \n";
                    }
                    else
                    {
                        logBox.Text += DateTime.Now.ToString("HH:mm:ss ") + "BŁĄD: Przed modyfikacja, zdiagnozuj." + ". \n";
                    }
                }
                catch (Exception) { MessageBox.Show("BŁĄD: Nie ma takiego rekordu."); }
            }
            else
            {
                logBox.Text += DateTime.Now.ToString("HH:mm:ss ") + "BŁĄD: Uprasza się uprzejmię o wpisanie Identyfikatora Irisa. \n";
            }
        }
示例#3
0
文件: Form1.cs 项目: emskypl/KNN_CBR
        private void saveButton_Click(object sender, EventArgs e)
        {
            using (var dataContext = new BazaDanychStruktura())
            {
                ControlTextBox();

                if (!textBoxClassification.Text.Equals(""))
                {
                    dataContext.Irises.Add(new Irises()
                    {
                        sepal_length = Double.Parse(textBoxSepalLength.Text.ToString()), sepal_width = Double.Parse(textBoxSepalWidth.Text.ToString()), petal_length = Double.Parse(textBoxPetalLength.Text.ToString()), petal_width = Double.Parse(textBoxPetalWidth.Text.ToString()), classification = textBoxClassification.Text.ToString()
                    });
                    dataContext.SaveChanges();
                    logBox.Text += DateTime.Now.ToString("HH:mm:ss ") + "Dodano wpis do bazy danych. \n";
                }
                else
                {
                    logBox.Text += DateTime.Now.ToString("HH:mm:ss ") + "Nie określono klasyfikatora. \n";
                }
            }
        }