不知道为什么这个单选按钮会抛出错误?

问题描述

我目前正在制作一个健身课程预订系统,我正在做一些学习,所以请不要打扰我。

我已经完成了大部分代码,但是我的第二个单选按钮出现了这个奇怪的问题,用于选择您想要的课程。

我已设置我的代码,因此如果您输入的会员 ID 已注册到您选择的健身课程,则会出现一个消息框。对于我的 RadioButton1 (rbCardioClass) 和 RadioButton2 (rbPilatesClass),错误消息框效果很好,并且可以正常工作。但是我的 RadioButton2 (rbSpinClass) 每次都会使错误消息框出现,即使 MemberID 没有关联到“Spin Class”。

我尝试了 if 语句的不同用法、不同的单选按钮等,但似乎无法按照我想要的方式工作。

如果我转到我的 servicesErrorCheck(string[] description) 方法并且只将 temp 变量设置为 true,所有单选按钮都正确地保存到数据库表中,但是我会丢失我的错误,这让我觉得可能与我设置消息框的方式有关。

这里是原型表单的截图,仅供参考。 FitnessClassBooking Form

这是应用运行时表格的屏幕截图App Running Fitness Form

这是使用没有关联的“Spin”类的 MemberID 抛出的错误 App Running Error

这是我有问题的代码 -

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.sqlClient;
using System.Configuration;

namespace Membership_Formv2
{
public partial class fitnessClassBooking : Form
{
    public fitnessClassBooking()
    {
        InitializeComponent();
    }

    private void bMainMenu_Click(object sender,EventArgs e)
    {
        new MainMenu().Show();
        this.Hide();
    }

    private void fitnessinformationBindingNavigatorSaveItem_Click(object sender,EventArgs e)
    {
        this.Validate();
        this.fitnessinformationBindingSource.EndEdit();
        this.tableAdapterManager.Updateall(this.databaseDataSet);

    }

    private void fitnessClassBooking_Load(object sender,EventArgs e)
    {
        // Todo: This line of code loads data into the 'databaseDataSet.Members' table. You can move,or remove it,as needed.
        this.membersTableAdapter.Fill(this.databaseDataSet.Members);
        // Todo: This line of code loads data into the 'databaseDataSet.fitnessinformation' table. You can move,as needed.
        this.fitnessinformationTableAdapter.Fill(this.databaseDataSet.fitnessinformation);



    }

    private void fitnessinformationDataGridView_CellContentClick(object sender,DataGridViewCellEventArgs e)
    {

    }

    private string descriptionfit()
    {

        string className = "";

       

        if (rbCardioClass.Checked == true)
        {
            className = "Cardio";
        }
        else if (rbSpinClass.Checked == true)
        {
            className = "Spin";
        }
        else if (rbPilatesClass.Checked == true)
        {
            className = "Pilates";
        }

        return className;

    }

    private string classDescription()
    {
        string serviceSeletionString = "Class";

        if (rbCardioClass.Checked == true)
        {
            serviceSeletionString = rbCardioClass.Text;
            this.Refresh();
        }
        else if (rbSpinClass.Checked == true)
        {
            serviceSeletionString = rbSpinClass.Text;
            this.Refresh();
        }
        else if (rbPilatesClass.Checked == true)
        {
            serviceSeletionString = rbPilatesClass.Text;
            this.Refresh();
        }

        return serviceSeletionString;
    }

    private bool errorCheckingID()
    {
        bool statusDB = true;
        //Getting row info from MembersTa table
        DatabaseDataSet.MembersRow newEntry = databaseDataSet.Members.FindByMemberID(Int32.Parse(textBox3.Text));

        //Getting information from BookingTa table
        if (newEntry == null)
        {
            statusDB = false;
            return (statusDB);
        }
        return (statusDB);
    }


    public bool servicesErrorCheck(string[] description)
    {
        bool temp = true;
        string serviceSeletionString = "";

        if (rbCardioClass.Checked == true)
        {
            serviceSeletionString = rbCardioClass.Text;
            this.Refresh();
        }
        else if (rbSpinClass.Checked == true)
        {
            serviceSeletionString = rbSpinClass.Text;
            this.Refresh();
        }
        else if (rbPilatesClass.Checked == true)
        {
            serviceSeletionString = rbPilatesClass.Text;
            this.Refresh();
        }


        for (int t = 0; t < description.Length; t++)
        {
            if (serviceSeletionString.Contains(description[t].Trim()))
            {
                temp = false;
                break;
            }
        }
        return (temp);
    }

    private string originalaccesdb()
    {
        string a = "";

        DatabaseDataSet.fitnessinformationRow newRow = databaseDataSet.fitnessinformation.NewfitnessinformationRow();

        newRow.fitness_Booking_ID = databaseDataSet.fitnessinformation.Count + 1;
        newRow.Description = descriptionfit();
        newRow.MemberID = Int32.Parse(textBox3.Text);
        databaseDataSet.fitnessinformation.AddfitnessinformationRow(newRow);

        return a;
    }

    private string[] accessDB()
    {
        int t = 0;
        int temp;
        string[] servicesList = { "n","n","n" };  //This variable will store the data

        //Same code too extract table information
        foreach (DaTarow r in databaseDataSet.fitnessinformation.Rows)
        {
            temp = Int32.Parse(r["MemberID"].ToString());

            if (temp == Int32.Parse(textBox3.Text))
            {
                //Store inside the array all the services/description against the ID.
                //Note that this array will remain "" for all the elements inside the array
                //if no descritopn/services (i.e.,record) is found against the input ID
                servicesList[t] = r["Description"].ToString();
                t = t + 1;
            }
        }
        return (servicesList);
    }


    private void button1_Click(object sender,EventArgs e)
    {

        

        string text = textBox1.Text;
        textBox1.Text = "";
        int a = Int32.Parse(textBox2.Text);
        DatabaseDataSet.MembersRow newID = databaseDataSet.Members.FindByMemberID(Int32.Parse(textBox2.Text));

        string booking = "";
        int temp;

        foreach (DaTarow r in databaseDataSet.fitnessinformation.Rows)
        {
            temp = Int32.Parse(r["MemberID"].ToString());

            if (temp == Int32.Parse(textBox2.Text))
            {
                booking = r["Description"].ToString() + "," + booking;
            }
        }

        textBox1.Text = "Member ID is: " + (newID.MemberID).ToString() + Environment.NewLine +
                        "First Name is: " + (newID.First_Name).ToString() + Environment.NewLine +
                        "Last Name is: " + (newID.Last_Name).ToString() + Environment.NewLine +
                        "Bookings: " + booking;

        
    }

    public void button2_Click(object sender,EventArgs e)
    {
        

        bool status1,status2;
        string[] description;

        //Error control at the outer level for valid ID
        status1 = errorCheckingID();

        //Proceed only if ID is valid or status1 is true
        if (status1)
        {
            //Retrieve information from the other database. Ideally you want this method to return
            //an array containing registered services. This would be an array of strings.
            description = accessDB();

            //Services error checking
            status2 = servicesErrorCheck(description);

            //Now this is the code that would call the method to save data ito database
            //when status2 and 2 are true
            if (status2)
            {

                //Code for saving into database. 
                DatabaseDataSet.fitnessinformationRow newRow = databaseDataSet.fitnessinformation.NewfitnessinformationRow();

                newRow.fitness_Booking_ID = databaseDataSet.fitnessinformation.Count + 1;
                newRow.Description = classDescription();
                newRow.MemberID = Int32.Parse(textBox3.Text);
                databaseDataSet.fitnessinformation.AddfitnessinformationRow(newRow);
            }
            else
            {
                //Show error that this service is not available
                MessageBox.Show("This Class is already assigned to that Member ID");
            }
        }
        else
        {
            //Error message invalid ID
            MessageBox.Show("Invalid ID");
        }
    }

    private void radioButton1_Click(object sender,EventArgs e)
    {

    }

    private void radioButton4_Click(object sender,EventArgs e)
    {

    }

    private void radioButton3_Click(object sender,EventArgs e)
    {

        }
    }
}

我真的不知道为什么会发生这种情况,所以我非常感谢您的帮助。

解决方法

您正在检查 From Coq Require Import Init.Prelude Unicode.Utf8. From mathcomp Require Import all_ssreflect. Fixpoint remove_one (v:nat) (l:list nat) : list nat:= match l with | nil => nil | cons h t => if v == h then t else cons h (remove_one v t) end. Fixpoint count (v:nat) (l:list nat) : nat := match l with | nil => 0 | cons h t => (if h == v then 1 else 0) + (count v t) end. Fixpoint leb (n m:nat) : bool := match n,m with | O,_ => true | S _,O => false | S n',S m' => leb n' m' end. Lemma leb1 (n : nat) : leb n (S n). Proof. by elim: n. Qed. Theorem remove_decr_count: forall (l : list nat),leb (count 0 (remove_one 0 l)) (count 0 l). Proof. elim=> [|h t IH] //=. - have [] := boolP (h == 0) => eqh0. by rewrite eq_sym eqh0 leb1. - by rewrite eq_sym ifN //= ifN. Qed. 中的每个字符串,如下所示:

descriptions

考虑到至少一个字符串只是 serviceSeletionString.Contains(description[t].Trim()) 它将始终匹配 n
我不知道为什么你总是返回一个带有 Spin 的空白数组。我个人只会使用 nList<string> 数据库中的每个项目。但这是一个单独的观点。

要么将其更改为 Add(不明白为什么需要 serviceSeletionString == description[t]),或者只是将整个 Trim() 循环替换为 foreach