我需要一個int血型類型以等於特定值,具體取決於檢查哪個單選按鈕。如果任何布爾值爲真,它將使血型等於特定值。我只是不知道如何讓bool爲int血型賦值。任何指針?如果bool爲真,則返回int
private void btnAddPatient_Click(object sender, RoutedEventArgs e)////Adds Patients using buttone etc to set properties
{
string name = txtPatientName.Text;
int bloodType,x=1;
DateTime dob;
bool bloodA = rbA.IsChecked.Equals(true);
bool bloodB = rbB.IsChecked.Equals(true);
bool bloodAB = rbAB.IsChecked.Equals(true);
bool blood0 = rb0.IsChecked.Equals(true);
if (dpDOB.SelectedDate == null || txtPatientName.Text == "" || !bloodA || !bloodAB || !bloodB || !blood0)
{
if (txtPatientName.Text == "")
{
MessageBox.Show("Please enter Patient's Name");
}
else if (dpDOB.SelectedDate == null)
{
MessageBox.Show("Please select a date");
}
else if(!bloodA || !bloodAB || !bloodB || !blood0)
{
MessageBox.Show("Please enter patient's blood type");
}
}
else
{
//bloodType How to make this equal to a value depending on what radio button is checked?
dob = dpDOB.SelectedDate.Value;
Patient patient = new Patient(name, bloodType, x, dob);
MainWindow mainWindow = Owner as MainWindow;
patients.Add(patient);
lstPatients.ItemsSource = null;
lstPatients.ItemsSource = patients;
// this.Close();
}
}
難道你不能只用'if if if'來檢查,哪個單選按鈕是真的並且分配正確的值? –
bloodType的int值是在哪裏定義的? – maccettura
是的,我可以。上帝,我在時間愚蠢。 –