Exemple #1
0
        private void toolStripButtonStreetEdit_Click(object sender, EventArgs e)
        {
            if (dataGridViewStreets.SelectedRows.Count > 0)
            {
                int  index = dataGridViewStreets.SelectedRows[0].Index;
                int  street_code;
                bool converted = Int32.TryParse(dataGridViewStreets[0, index].Value.ToString(), out street_code);
                if (converted == false)
                {
                    return;
                }

                Street street = db.Streets.Find(street_code);

                FormStreet formStreet = new FormStreet(db);
                formStreet.textBoxStreetCode.Text     = street.Street_Code.ToString();
                formStreet.textBoxStreetName.Text     = street.Street_Name;
                formStreet.textBoxNameStatus.Text     = street.Street_Name_Status;
                formStreet.textBoxOfficialCode.Text   = street.Street_Official_Code.ToString();
                formStreet.comboBoxCity.SelectedIndex = formStreet.comboBoxCity.FindStringExact(street.City.City_Name);

                formStreet.textBoxStreetCode.Enabled = false;

                DialogResult result = formStreet.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                street.Street_Name        = formStreet.textBoxStreetName.Text;
                street.Street_Name_Status = formStreet.textBoxNameStatus.Text;
                int official_code;
                converted = Int32.TryParse(formStreet.textBoxOfficialCode.Text, out official_code);
                if (converted == false)
                {
                    return;
                }
                street.Street_Official_Code = official_code;
                street.City_Code            = (formStreet.comboBoxCity.SelectedItem as dynamic).Value;
                //
                db.SaveChanges();

                dataGridViewStreets.Refresh(); // обновляем грид

                MessageBox.Show("Object updated");
            }
        }
Exemple #2
0
        private void toolStripButtonStreetAdd_Click(object sender, EventArgs e)
        {
            FormStreet   formStreet = new FormStreet(db);
            DialogResult result     = formStreet.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Street street = new Street();
            int    street_code;
            bool   converted = Int32.TryParse(formStreet.textBoxStreetCode.Text, out street_code);

            if (converted == false)
            {
                return;
            }
            street.Street_Code        = street_code;
            street.Street_Name        = formStreet.textBoxStreetName.Text;
            street.Street_Name_Status = formStreet.textBoxNameStatus.Text;
            int official_code;

            converted = Int32.TryParse(formStreet.textBoxOfficialCode.Text, out official_code);
            if (converted == false)
            {
                return;
            }
            street.Street_Official_Code = official_code;
            street.City_Code            = (formStreet.comboBoxCity.SelectedItem as dynamic).Value;

            db.Streets.Add(street);
            db.SaveChanges();

            MessageBox.Show("New object added");
        }