繁体   English   中英

我将如何减少 lblTotalCredits、lblNumberCourses、lblCurrentGPA 中的计数。 另外,我将如何计算GPA?

[英]How would I decrease the count in the lblTotalCredits, lblNumberCourses, lblCurrentGPA. Also, how would I calculate GPA?

这是我到目前为止所拥有的以及包含的评论,以向大家传达我的思考过程。

protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnContinue_Click(object sender, EventArgs e)
{
    //takes input from user and stores it appropriately
    lblFirstName.Text = txtFirstName.Text;
    lblLastName.Text = txtLastName.Text;
    lblMajor.Text = ddlMajors.SelectedValue;
    //makes second panel visible and hides original panel
    pnlCourseInfo.Visible = true;
    pnlStudent.Visible = false;
    lblTotalCredits.Text = "0";
    lblNumberCourses.Text = "Unknown";
    lblCurrentGPA.Text = "0.0";
}

protected void lbAddCourse_Click(object sender, EventArgs e)
{
    //make add course panel visible
    pnlCourseAdd.Visible = true;
}

protected void rblAddedCourses_SelectedIndexChanged(object sender, EventArgs e)
{
    //make remove button visible
    btnRemoveSelected.Visible = true;
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
    //make RadioButtonList visible
    rblAddedCourses.Visible = true;



    //create variables for summary items
    int intCourseCount = 0;
    int intTotalCredits = 0;
    decimal decCurrentGPA = 0m;


    //store course entered as variable
    string strNewCourse = txtCoursePrefix.Text.ToUpper() + " " + txtCourseNumber.Text + " " + "(" + ddlGradeEarned.SelectedItem + ")";

    //loop thru to make sure duplicate course is not added
    bool blnDuplicateCourse = false;

    foreach (ListItem liCourses in rblAddedCourses.Items)
    {
        //if the current courses matches the new course, set flag to true
        if (liCourses.Text == strNewCourse)
        {
            blnDuplicateCourse = true;
        }
    }
    //only add course if it is a new course
    if (blnDuplicateCourse == true)
    {
        lblError.Text = "This course already exists! Please enter a new course.";
    }
    else
    {
        //new course not in the list, clear error message and add to RadioButtonList
        lblError.Text = "";
        rblAddedCourses.Items.Add(strNewCourse);
    }


    //create increments for number of courses and total credits
    foreach (ListItem liCourse in rblAddedCourses.Items)
    {
        intCourseCount += 1;
        intTotalCredits += 3;
    }



    //calculate GPA
    if (ddlGradeEarned.SelectedValue == "A")
    {

    }
    //assign value to summary labels
    if (intCourseCount >= 1)
    {
        lblNumberCourses.Text = intCourseCount.ToString();
    }

    if (decCurrentGPA >= 1)
    {
        lblCurrentGPA.Text = decCurrentGPA.ToString();
    }

    if (intTotalCredits > 0)
    {
        lblTotalCredits.Text = intTotalCredits.ToString();
    }
}


protected void btnRemoveSelected_Click(object sender, EventArgs e)
{
    //remove selected course
    rblAddedCourses.Items.RemoveAt(rblAddedCourses.SelectedIndex);

    //hide button until another selection is made
    btnRemoveSelected.Visible = false;

    int intCourseCount = 0;
    int intTotalCredits = 0;
    decimal decCurrentGPA = 0m;

    foreach (ListItem liCourse in rblAddedCourses.Items)
    {
        intCourseCount -= 1;
        intTotalCredits -= 3;
    }
    
    if (intCourseCount >= 1)
    {
        lblNumberCourses.Text = intCourseCount.ToString();
    }

    if (decCurrentGPA >= 1)
    {
        lblCurrentGPA.Text = decCurrentGPA.ToString();
    }

    if (intTotalCredits > 0)
    {
        lblTotalCredits.Text = intTotalCredits.ToString();
    }
}

protected void btnCancel_Click(object sender, EventArgs e)
{
    //hide add course panel and clear contents
    txtCourseNumber.Text = "";
    txtCoursePrefix.Text = "";
    ddlGradeEarned.SelectedIndex = 0;
    pnlCourseAdd.Visible = false;
}

protected void lbStartOver_Click(object sender, EventArgs e)
{
    //hide panel for course information and clear all contents
    txtFirstName.Text = "";
    txtLastName.Text = "";
    ddlMajors.SelectedIndex = 0;
    ddlGradeEarned.SelectedIndex = 0;
    txtCourseNumber.Text = "";
    txtCoursePrefix.Text = "";
    pnlCourseInfo.Visible = false;
    pnlStudent.Visible = true;
    lblCurrentGPA.Text = "0.0";
    lblNumberCourses.Text = "Unknown";
    lblTotalCredits.Text = "0";
}

}

我正在尝试构建代码,以便在我从列表中删除项目时减少计数,就像在添加项目时增加计数一样。 我还需要一些帮助来设置和计算 GPA

我会创建一个名为 lblTotalCreditsInt 之类的新变量,然后将 lblTotalCredits.text 设置为 lblTotalCreditsInt.ToString()。 与其他值相同的事情。 GPA 是这样计算的https://gpacalculator.net/how-to-calculate-gpa/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM