Ejemplo n.º 1
0
        private void changeButton_Click(object sender, EventArgs e)
        {
            AddMedicineUse form = new AddMedicineUse();

            string myQuery = "SELECT Название FROM Лекарства WHERE Код = " + Convert.ToInt32(dataGridView1.CurrentRow.Cells[2].Value);
            string s1      = GetStringValue(myQuery);

            form.SetBoxes(Convert.ToString(dataGridView1.CurrentRow.Cells[1].Value),
                          s1,
                          Convert.ToString(dataGridView1.CurrentRow.Cells[3].Value));

            form.ShowDialog();
            string s2 = form.GetUsage();
            string s3 = form.GetMedicine();

            myQuery = "SELECT Код FROM Лекарства WHERE [Название] = '" + s3 + "'";
            s3      = GetStringValue(myQuery);
            string s4 = form.GetPeriod();

            dataGridView1.CurrentRow.Cells[1].Value = s2;
            dataGridView1.CurrentRow.Cells[2].Value = s3;
            dataGridView1.CurrentRow.Cells[3].Value = s4;

            BindingSource bs = new BindingSource(ds, "НазначениеЛекарств");

            dataGridView1.DataSource = bs;
            UpdateGrid();
        }
Ejemplo n.º 2
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            AddMedicineUse form = new AddMedicineUse();

            form.ShowDialog();
            string medicine = form.GetMedicine();
            string usage    = form.GetUsage();
            string period   = form.GetPeriod();

            LoadGrid();

            oleDbConnection1.Open();
            string          myQuery   = "SELECT Код FROM Лекарства WHERE [Название] = '" + medicine + "'";
            OleDbCommand    myCommand = new OleDbCommand(myQuery, oleDbConnection1);
            OleDbDataReader myReader;

            myReader = myCommand.ExecuteReader();
            myReader.Close();
            try
            {
                medicine = myCommand.ExecuteScalar().ToString();
            }
            catch (Exception)
            {
            }
            oleDbConnection1.Close();

            if (medicine != "" && usage != "" && period != "")
            {
                try
                {
                    oleDbConnection1.Open();

                    oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO [НазначениеЛекарств] (idНазначения, idЛекарств, Период) VALUES ('" + medicine + "', '" + usage + "', '" + period + "')";

                    oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
                }
                catch (Exception)
                {
                };
            }
            oleDbConnection1.Close();
            UpdateGrid();
        }