コード例 #1
0
        private void EditButton_Click(object sender, EventArgs e)
        {
            ReservationForm form = new ReservationForm(workers, rooms, clients);

            form.Text         = "Изменить бронь";
            form.button1.Text = "Применить";

            form.Tag = dataGridView.SelectedRows[0].Cells[0].Value.ToString();
            form.worker.SelectedItem = dataGridView.SelectedRows[0].Cells[4].Value.ToString();
            form.room.SelectedItem   = dataGridView.SelectedRows[0].Cells[5].Value.ToString();
            form.client.SelectedItem = dataGridView.SelectedRows[0].Cells[6].Value.ToString();
            form.enterDate.Value     = DateTime.Parse(dataGridView.SelectedRows[0].Cells[7].Value.ToString());
            form.exitDate.Value      = DateTime.Parse(dataGridView.SelectedRows[0].Cells[8].Value.ToString());
            form.price.Value         = decimal.Parse(dataGridView.SelectedRows[0].Cells[9].Value.ToString());

            if (form.ShowDialog() == DialogResult.OK)
            {
                using (var sql = new SqlConnection(Program.sql.ConnectionString))
                {
                    sql.Open();
                    var com = sql.CreateCommand();
                    com.CommandText = String.Format("update Бронь set [Id сотрудника]='{0}',[Id номера]='{1}'," +
                                                    "[Id клиента]='{2}',[Дата въезда]='{3}',[Дата выезда]='{4}',Стоимость='{5}' where Id={6}",
                                                    workers[form.worker.SelectedItem.ToString()], rooms[form.room.SelectedItem.ToString()],
                                                    clients[form.client.SelectedItem.ToString()], form.enterDate.Value.ToString("yyyy-MM-dd"),
                                                    form.exitDate.Value.ToString("yyyy-MM-dd"), form.price.Value.ToString().Replace(',', '.'), form.Tag);
                    com.ExecuteNonQuery();
                    sql.Close();
                }
                RefreshDB();
            }
        }
コード例 #2
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            ReservationForm form = new ReservationForm(workers, rooms, clients);

            form.Text         = "Добавить бронь";
            form.button1.Text = "Добавить";
            if (form.ShowDialog() == DialogResult.OK)
            {
                using (var sql = new SqlConnection(Program.sql.ConnectionString))
                {
                    sql.Open();
                    var com = sql.CreateCommand();
                    com.CommandText = String.Format("insert into Бронь values('{0}','{1}','{2}','{3}','{4}','{5}')",
                                                    workers[form.worker.SelectedItem.ToString()], rooms[form.room.SelectedItem.ToString()],
                                                    clients[form.client.SelectedItem.ToString()], form.enterDate.Value.ToString("yyyy-MM-dd"),
                                                    form.exitDate.Value.ToString("yyyy-MM-dd"), form.price.Value.ToString().Replace(',', '.'));
                    com.ExecuteNonQuery();
                    sql.Close();
                }
                RefreshDB();
            }
        }