Example #1
0
        private void ButtonPick_Click(object sender, EventArgs e)
        {
            string        cont = dataGridView1.CurrentRow.Cells[4].Value.ToString();
            SqlConnection conn = new SqlConnection(myconnstrng);


            orders.taxi_name    = FormLogin.username;
            orders.taxi_contact = FormLogin.contact;
            orders.taxi_number  = LoginDAL.car_number;
            orders._class       = LoginDAL.car_class;

            orders.user_name     = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            orders.user_lastname = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            orders.from          = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            orders.to            = dataGridView1.CurrentRow.Cells[3].Value.ToString();
            orders.user_contact  = dataGridView1.CurrentRow.Cells[4].Value.ToString();
            orders.distance      = dataGridView1.CurrentRow.Cells[5].Value.ToString();
            orders.cost          = dataGridView1.CurrentRow.Cells[6].Value.ToString();

            bool success = ordersdal.AddOrder(orders);

            if (success)
            {
                MessageBox.Show("Success");

                //click.Invoke();
            }
            else
            {
                MessageBox.Show("Error");
            }
            try
            {
                string     sql = "UPDATE Users SET status = 0  WHERE contact = @contact";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@contact", cont);
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    MessageBox.Show("status change");
                }
                else
                {
                    MessageBox.Show("status no change");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            click.Invoke();
        }