コード例 #1
0
		private void buttonRegistr_Click(object sender, EventArgs e)
		{


			//if (isUserExist())
			//	return;

			string card_type;
			string access_gum;
			string access_swimming;
			Int32 Price;

			if (card_VIP_check.Checked)
			{
				cardPrice.Text = "22500 рублей";
				card_type = "vip";
				access_gum = "yes";
				access_swimming = "yes";
				Price = 22500;
			}
			else
			{
				cardPrice.Text = "15000 рублей";
				card_type = "normal";
				access_gum = "yes";
				access_swimming = "no";
				Price = 15000;
			}



			DataTable table = new DataTable();

			MySqlDataAdapter adapter = new MySqlDataAdapter();
			MySqlDataAdapter adapter2 = new MySqlDataAdapter();

			DB db = new DB();



			MySqlCommand check = new MySqlCommand("SELECT phone FROM `customer` WHERE customer.phone= @phone ", db.getConnection());
			check.Parameters.Add("@phone", MySqlDbType.VarChar).Value = customerPhoneField.Text;



			//commandUp.Parameters.Add("@phone1", MySqlDbType.VarChar).Value = customerPhoneField.Text;


			adapter.SelectCommand = check;
			adapter.Fill(table);



			db.openConnection();


			if (table.Rows.Count > 0)
			{

		
				MySqlCommand command = new MySqlCommand("INSERT INTO `card`(`phone`, `price`, `card_type`, `validity`, `access_gum`, `access_swimming`) VALUES(@phone , @price ,@card_type ,CURDATE(), @access_gum, @access_swimming); UPDATE `card` SET `validity`= DATE_ADD(`validity`, INTERVAL 1 year) WHERE card.phone=@phone;    ", db.getConnection());
				command.Parameters.Add("@phone", MySqlDbType.VarChar).Value = customerPhoneField.Text;
				command.Parameters.Add("@price", MySqlDbType.Int32).Value = Price;
				command.Parameters.Add("@card_type", MySqlDbType.VarChar).Value = card_type;
				command.Parameters.Add("@access_gum", MySqlDbType.VarChar).Value = access_gum;
				command.Parameters.Add("@access_swimming", MySqlDbType.VarChar).Value = access_swimming;
				adapter2.SelectCommand = command;

				

				if (command.ExecuteNonQuery() == 2)
				{
					
					MessageBox.Show("Карта зарегистрированна");
					curCard();
				}
				else
				{
					
					MessageBox.Show("Что то пошло не так");
				}
			}
			else
			{
				MessageBox.Show("Карта не была привязана, проверьте правильность написания номера");
			}


		



			db.closeConnection();

		


		}