示例#1
0
        //Кнока изменить клиента
        private void Button6_Click(object sender, EventArgs e)
        {
            dataGridView1.Refresh(); // обновляем грид

            if (dataGridView1.SelectedRows.Count > 0)
            {
                using (var db2 = new TablGoogleContext())
                {
                    int  index     = dataGridView1.SelectedRows[0].Index; // Привязка индекса по id строки
                    int  id        = 0;
                    bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);

                    if (converted == false) //проверка
                    {
                        return;
                    }


                    TablGoogle tablGoogle = db2.TablGoogles.Find(id); // ищем по базе ID строки

                    PlayerForm plForm = new PlayerForm();             // создаем форму для редактирования

                    plForm.textBoxDatetime.Visible = true;
                    plForm.labelDateTime.Visible   = true;

                    plForm.textBoxNameClient.Text     = tablGoogle.NameClienta;
                    plForm.textBoxPassClient.Text     = tablGoogle.PassClient;
                    plForm.textBoxTelefonClienta.Text = tablGoogle.TelefonClient;
                    plForm.textBoxNameClient.Text     = tablGoogle.NameClienta;
                    plForm.textBoxDatetime.Text       = tablGoogle.DataTimeAddTable;

                    DialogResult result = plForm.ShowDialog(this); //включаем диалог

                    if (result == DialogResult.Cancel)             //при нажатии отмены, выходим из формы
                    {
                        return;
                    }

                    tablGoogle.NameClienta      = plForm.textBoxNameClient.Text; // присваиваем текст
                    tablGoogle.PassClient       = plForm.textBoxPassClient.Text;
                    tablGoogle.TelefonClient    = plForm.textBoxTelefonClienta.Text;
                    tablGoogle.DataTimeAddTable = DateTime.Now.ToString(); // время создания

                    //player.Age = (int)plForm.numericUpDown1.Value;
                    //player.Name = plForm.textBox1.Text;
                    //player.Position = plForm.comboBox1.SelectedItem.ToString();

                    db2.SaveChanges();
                    //    dataGridView1.Refresh(); // обновляем грид
                    MessageBox.Show("Объект обновлен");
                    // dataGridView1.Refresh(); // обновляем грид
                }
            }
            dataGridView1.Refresh(); // обновляем грид
        }
示例#2
0
        //Кнопка добавить клиента
        private void Button5_Click(object sender, EventArgs e)
        {
            dataGridView1.Refresh();                       // обновляем грид
            PlayerForm   plForm = new PlayerForm();        // Создание новой формы
            DialogResult result = plForm.ShowDialog(this); // включение диалога
            string       arenda = "79520302311 Арендный телефон";

            if (result == DialogResult.Cancel) // если нажата кнопка отмены, то выход из формы
            {
                return;
            }

            using (var db2 = new TablGoogleContext())
            {
                TablGoogle tablGoogle = new TablGoogle();
                tablGoogle.NameClienta      = plForm.textBoxNameClient.Text; // присваиваем текст
                tablGoogle.PassClient       = plForm.textBoxPassClient.Text;
                tablGoogle.TelefonClient    = plForm.textBoxTelefonClienta.Text;
                tablGoogle.DataTimeAddTable = DateTime.Now.ToString(); // время создания

                if (plForm.checkBoxArenda.Checked)
                {
                    tablGoogle.TelefonClient += $"/t/n 79520302311 Арендный телефон";
                    tablGoogle.PassClient    += "1234qwer или 1234Qwer ";
                }
                if (plForm.checkBoxArendaEvolaina.Checked)
                {
                    tablGoogle.TelefonClient += $"\n{arenda}";
                    tablGoogle.PassClient    += "\n1234qwer или 1234Qwer ";
                }


                db2.TablGoogles.Add(tablGoogle); // добавляем в БД новые данные
                db2.SaveChanges();
            }


            MessageBox.Show("Новый объект добавлен");
        }