[英]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.