protected void btn_Submit_ServerClick(object sender, EventArgs e) { if (!CheckRegistrationData()) { return; } int teamCount = Request.Form.AllKeys.Where(key => key.Contains("input_Name")).ToList().Count; List <teamPeople> teamMembers = new List <teamPeople>(); teamPeople leader = new teamPeople(); //要判斷隊長是誰 int count = (Request.Form.AllKeys.Where(key => key.Contains("input_Name")).ToList()).Count; for (int i = 1; i <= count; i++) { HtmlInputRadioButton btn = Master.FindControl("MainContent").FindControl("radioBtn_" + i) as HtmlInputRadioButton; HtmlInputText nameControl = Master.FindControl("MainContent").FindControl("input_Name" + i) as HtmlInputText; HtmlInputText idControl = Master.FindControl("MainContent").FindControl("input_Id" + i) as HtmlInputText; HtmlInputText BirthdayControl = Master.FindControl("MainContent").FindControl("input_Birthday" + i) as HtmlInputText; if (btn == null) { continue; } if (btn.Checked) { //隊長 leader.Name = nameControl.Value; leader.Id = idControl.Value; leader.Birthday = BirthdayControl.Value; } else { teamPeople member2 = new teamPeople(); member2.Name = nameControl.Value; member2.Id = idControl.Value; member2.Birthday = BirthdayControl.Value; teamMembers.Add(member2); } } string commandString = $"UPDATE BridgeTeam SET Count = {count},Name='{input_TeamName.Value}'"; //隊長 commandString += $", LeaderName = '{leader.Name}', LeaderID = '{leader.Id}', LeaderBirthday = '{leader.Birthday}'"; //隊員 for (int i = 1; i < count; i++) { commandString += $", PlayerName{i} = '{teamMembers[i - 1].Name}', PlayerID{i} = '{teamMembers[i - 1].Id}', " + $"PlayerBirthday{i} = '{teamMembers[i - 1].Birthday}'"; } if (input_SecondTeacher.Value != "") { commandString += $", SecondTeacher = '{input_SecondTeacher.Value}'"; } else { commandString += $", SecondTeacher = NULL"; } commandString += $" WHERE Id = '{Session["UpdateId"]}';"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlDB"].ConnectionString); conn.Open(); SqlCommand command = new SqlCommand(commandString, conn); command.ExecuteNonQuery(); command.Cancel(); conn.Close(); //Update Name of FilmInfo commandString += $"UPDATE FilmInfo SET Name ='{input_TeamName.Value}' WHERE Id='{Session["OrginName"].ToString()}'"; conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlDB"].ConnectionString); conn.Open(); command = new SqlCommand(commandString, conn); command.ExecuteNonQuery(); command.Cancel(); conn.Close(); Session["UpdateId"] = null; if (Session["ManageLogin"] != null && Session["ManageLogin"].ToString() == "Y") { Response.Redirect("~/BridgeModify.aspx"); } else { Response.Redirect("Intro.aspx"); } }
protected void btn_Submit_ServerClick(object sender, EventArgs e) { if (!CheckRegistrationData()) { return; } if (Session["IsFirstSubmit"] == null || Session["IsFirstSubmit"].ToString() == "Y") { Session["IsFirstSubmit"] = "N"; } else { Session["IsFirstSubmit"] = null; Response.Redirect("Intro.aspx"); } int teamCount = Request.Form.AllKeys.Where(key => key.Contains("input_Name")).ToList().Count; List <teamPeople> teamMembers = new List <teamPeople>(); teamPeople leader = new teamPeople(); //要判斷隊長是誰 int count = (Request.Form.AllKeys.Where(key => key.Contains("input_Name")).ToList()).Count; for (int i = 1; i <= count; i++) { HtmlInputRadioButton btn = Master.FindControl("MainContent").FindControl("radioBtn_" + i) as HtmlInputRadioButton; HtmlInputText nameControl = Master.FindControl("MainContent").FindControl("input_Name" + i) as HtmlInputText; HtmlInputText idControl = Master.FindControl("MainContent").FindControl("input_Id" + i) as HtmlInputText; HtmlInputText BirthdayControl = Master.FindControl("MainContent").FindControl("input_Birthday" + i) as HtmlInputText; if (btn == null) { continue; } if (btn.Checked) { //隊長 leader.Name = nameControl.Value; leader.Id = idControl.Value; leader.Birthday = BirthdayControl.Value; } else { teamPeople member2 = new teamPeople(); member2.Name = nameControl.Value; member2.Id = idControl.Value; member2.Birthday = BirthdayControl.Value; teamMembers.Add(member2); } } //判斷有沒有第二位老師 bool hasSecondTeacher = false; if (input_SecondTeacher.Value != "") { hasSecondTeacher = true; } string commandString = $"INSERT INTO BridgeTeam (AccountID ,Name, Count, LeaderName, LeaderID, LeaderBirthday"; for (int i = 1; i < count; i++) { commandString += $", PlayerName{i}, PlayerID{i}, PlayerBirthday{i}"; } if (hasSecondTeacher) { commandString += ", SecondTeacher"; } commandString += $") VALUES('{Session["LoginId"]}', '{input_TeamName.Value}', {teamMembers.Count + 1}"; commandString += $", '{leader.Name}', '{leader.Id}', '{leader.Birthday}'"; foreach (teamPeople peo in teamMembers) { commandString += $", '{peo.Name}', '{peo.Id}', '{peo.Birthday}'"; } if (hasSecondTeacher) { commandString += $", '{input_SecondTeacher.Value}'"; } commandString += ");"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlDB"].ConnectionString); conn.Open(); SqlCommand command = new SqlCommand(commandString, conn); command.ExecuteNonQuery(); command.Cancel(); conn.Close(); Session["IsFirstSubmit"] = null; Response.Redirect("Intro.aspx"); }