예제 #1
0
 public Editor(HandleFormAdd handleForm)
 {
     InitializeComponent();
     FormLoad();
     hf         = handleForm;
     hf.Enabled = false;
 }
예제 #2
0
        private void AddBtnClick(object sender, EventArgs e)
        {
            string query = null;
            int    ID    = 1;

            using (OleDbCommand command = new OleDbCommand("SELECT MAX([Код]) FROM телефоны ", connection))
            {
                OleDbDataReader reader = command.ExecuteReader();
                reader.Read();
                ID += int.Parse(reader[0].ToString());
                reader.Close();
            }

            using (hf = new HandleFormAdd(this))
            {
                hf.ShowDialog();
                if (hf.DialogResult == DialogResult.OK)
                {
                    hf.Close();
                    if (phone_numb == "")
                    {
                        query = $"INSERT INTO [телефоны] VALUES ('{ID}', '{name}', NULL, '{int.Parse(mob_phone_numb)}', {birthday}, '{email}', '{peop_type}', '{adress}', '{remark}'); ";
                    }
                    else if (mob_phone_numb == "")
                    {
                        query = $"INSERT INTO [телефоны] VALUES ('{ID}', '{name}', '{int.Parse(phone_numb)}', NULL, {birthday}, '{email}', '{peop_type}', '{adress}', '{remark}'); ";
                    }
                    else
                    {
                        query = $"INSERT INTO [телефоны] VALUES ('{ID}', '{name}', '{int.Parse(phone_numb)}', '{int.Parse(mob_phone_numb)}', {birthday}, '{email}', '{peop_type}', '{adress}', '{remark}'); ";
                    }
                    try
                    {
                        using (OleDbCommand command = new OleDbCommand(query, connection))
                        {
                            int i = command.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            DataGridLoad();
        }