Esempio n. 1
0
        private void button7_Click(object sender, EventArgs e)
        {
            var form = new PhoneForm();
            {
                var getReq         = "SELECT *FROM Nazarov_Provider";
                var contactAdapter = new SqlDataAdapter(getReq, address_and_else);
                var dict           = new Dictionary <int, string>();
                var providerTbl    = new DataTable();
                contactAdapter.Fill(providerTbl);

                foreach (DataRow row in providerTbl.Rows)
                {
                    dict.Add((int)row["Id"], row["name"].ToString());
                }
                form.ProviderData = dict;
            }

            var res = form.ShowDialog();

            if (res == DialogResult.OK)
            {
                var phone       = form.Phone.Text;
                var type        = form.type.Text;
                var provider_id = form.ProviderID;
                var connection  = new SqlConnection(address_and_else);
                connection.Open();
                var request = "INSERT INTO Nazarov_Contact (phone, type, povider_id) VALUES ('" + phone + "', '" + type + "', '" + provider_id.ToString() + "')";
                var command = new SqlCommand(request, connection);
                command.ExecuteNonQuery(); //выполняет комманду не требуя что-то взамен и ничего не возвращающий
                connection.Close();
                UpdateAll();
            }
        }
Esempio n. 2
0
        private void button9_Click(object sender, EventArgs e)
        {
            var rov = dgrv_phone.SelectedRows.Count > 0 ? dgrv_phone.SelectedRows[0] : null;

            if (rov == null)
            {
                MessageBox.Show("Строчку выбери", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var form = new PhoneForm();

            form.Phone.Text = rov.Cells["phone"].Value.ToString();
            form.type.Text  = rov.Cells["type"].Value.ToString();
            int index = 0;
            var prid  = rov.Cells["povider_id"].Value.ToString();
            {
                var getReq         = "SELECT *FROM Nazarov_Provider";
                var contactAdapter = new SqlDataAdapter(getReq, address_and_else);
                var dict           = new Dictionary <int, string>();
                var providerTbl    = new DataTable();
                contactAdapter.Fill(providerTbl);

                foreach (DataRow row in providerTbl.Rows)
                {
                    dict.Add((int)row["Id"], row["name"].ToString());
                    if ((int)row["Id"] == int.Parse(prid))
                    {
                        index = dict.Count - 1;
                    }
                }
                form.ProviderData            = dict;
                form.comboBox1.SelectedIndex = index;
            }

            var res = form.ShowDialog();

            if (res == DialogResult.OK)
            {
                var phone       = form.Phone.Text;
                var type        = form.type.Text;
                var provider_id = form.ProviderID;
                var id          = rov.Cells["Id"].Value.ToString();
                var connection  = new SqlConnection(address_and_else);
                connection.Open();
                var request = "UPDATE Nazarov_Contact SET phone ='" + phone + "', type ='" + type + "', povider_id ='" + provider_id.ToString() + "' WHERE Id=" + id + ";";
                var command = new SqlCommand(request, connection);
                command.ExecuteNonQuery(); //выполняет комманду не требуя что-то взамен и ничего не возвращающий
                connection.Close();
                UpdateAll();
            }
        }