private void btnSave_Click(object sender, EventArgs e) { Donar d = new Donar(); /*txtBirthDate.Text, * txtFirstName.Text, * txtLastName.Text, * txtAddress.Text, * txtCity.Text, * Int32.Parse(txtPostCode.Text), * txtPhoneNo.Text, * cboBloodGroup.SelectedItem.ToString(), * cboGender.SelectedItem.ToString() * ); */ d.FirstName = txtFirstName.Text; d.LastName = txtLastName.Text; d.BirthDate = txtBirthDate.Text; d.PhoneNo = txtPhoneNo.Text; d.Address = txtAddress.Text; d.PostCode = Int32.Parse(txtPostCode.Text); d.City = txtCity.Text; d.BloodGroup = cboBloodGroup.SelectedItem.ToString(); d.Gender = cboGender.SelectedItem.ToString(); Boolean answer = db.InsertDonarToDB(d); if (answer == true) { MessageBox.Show("New donar is registered."); txtFirstName.ResetText(); txtLastName.ResetText(); txtBirthDate.ResetText(); txtPhoneNo.ResetText(); txtAddress.ResetText(); txtPostCode.ResetText(); txtCity.ResetText(); cboBloodGroup.ResetText(); cboGender.ResetText(); } else { MessageBox.Show("Invalid Input."); } }
public bool InsertDonarToDB(Donar newDonar) { myCommand = new SqlCommand(); myCommand.Connection = myConnection; myCommand.CommandType = CommandType.StoredProcedure; myCommand.CommandText = "spRegNewDonar"; SqlParameter workparameter1 = new SqlParameter(); SqlParameter workparameter2 = new SqlParameter(); SqlParameter workparameter3 = new SqlParameter(); SqlParameter workparameter4 = new SqlParameter(); SqlParameter workparameter5 = new SqlParameter(); SqlParameter workparameter6 = new SqlParameter(); SqlParameter workparameter7 = new SqlParameter(); SqlParameter workparameter8 = new SqlParameter(); SqlParameter workparameter9 = new SqlParameter(); SqlParameter workparameter10 = new SqlParameter(); workparameter1 = myCommand.Parameters.Add("@FirstName", SqlDbType.VarChar); workparameter1.Value = newDonar.FirstName; workparameter2 = myCommand.Parameters.Add("@LastName", SqlDbType.VarChar); workparameter2.Value = newDonar.LastName; workparameter3 = myCommand.Parameters.Add("@BirthDate", SqlDbType.VarChar); workparameter3.Value = newDonar.BirthDate; workparameter4 = myCommand.Parameters.Add("@PhoneNo", SqlDbType.VarChar); workparameter4.Value = newDonar.PhoneNo; workparameter5 = myCommand.Parameters.Add("@Address", SqlDbType.VarChar); workparameter5.Value = newDonar.Address; workparameter6 = myCommand.Parameters.Add("@PostCode", SqlDbType.Int); workparameter6.Value = newDonar.PostCode; workparameter7 = myCommand.Parameters.Add("@City", SqlDbType.VarChar); workparameter7.Value = newDonar.City; workparameter8 = myCommand.Parameters.Add("@BloodGroup", SqlDbType.VarChar); workparameter8.Value = newDonar.BloodGroup; workparameter9 = myCommand.Parameters.Add("@Gender", SqlDbType.VarChar); workparameter9.Value = newDonar.Gender; workparameter10 = myCommand.Parameters.Add("@AntalRader", SqlDbType.Int); workparameter10.Direction = ParameterDirection.Output; myConnection.Open(); myCommand.ExecuteNonQuery(); int svar = Convert.ToInt32(workparameter10.SqlValue.ToString()); myConnection.Close(); if (svar == 1) { return(true); } else { return(false); } }