Beispiel #1
0
        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";
            }
        }
Beispiel #2
0
        //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";
            }
        }