private void _BindData() { try { double percentage = 0.0; DataTable dsStud = objStudent.GetStudentInfo(Convert.ToInt32(Session["UserId"])); int classId = Convert.ToInt32(dsStud.Rows[0]["ClassId"].ToString()); int CompleteLegs = objStudent.GetCompleteLegCount(classId); DataTable dsPrevStage = objStudent.GetLastCompleteLeg(classId); int showOld = 0; DataSet ds = objStudent.GetCurrentStageInfo(Convert.ToInt32(Session["UserId"].ToString()), Convert.ToInt32(Session["UserRoleId"].ToString()), classId); if ((ds != null && ds.Tables[0].Rows.Count > 0) || (CompleteLegs > 0)) { divForumBlog.Style.Add("Width", "700px"); DataTable dtm = new DataTable(); dtm = objStudent.GetVisitedCity(classId.ToString()); if (dtm.Rows.Count > 0) { ddlcity.DataSource = dtm; ddlcity.DataTextField = "CityName"; ddlcity.DataValueField = "CityId"; ddlcity.DataBind(); ddlcity.Items.Insert(0, new ListItem(" Stadt", "0")); } else { ddlcity.Items.Add(new ListItem(" Stadt", "0")); } if (dtm.Rows.Count > 0) { ddlcity.SelectedValue = dtm.Rows[dtm.Rows.Count - 1]["CityId"].ToString(); } lblCongratulations1.Visible = false; lblCongratulations3.Visible = false; if ((ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)) { //lblCurrentStage.Text = (string)GetLocalResourceObject("CurrentStage") + "<br/>" + ds.Tables[0].Rows[0]["StartCity"].ToString() + // " => " + ds.Tables[0].Rows[0]["EndCity"].ToString(); hdn_StartCity.Value = ds.Tables[0].Rows[0]["StartCityId"].ToString(); hdn_EndCity.Value = ds.Tables[0].Rows[0]["EndCityId"].ToString(); // QuizTest(Convert.ToInt32(hdn_StartCity.Value)); string FromCity = "../CityImages/" + ds.Tables[0].Rows[0]["FromCityimage"].ToString(); string ToCity = "../CityImages/" + ds.Tables[0].Rows[0]["ToCityimage"].ToString(); if (ds.Tables[0].Rows[0]["FromCityimage"].ToString() != "") { imgFromCity.ImageUrl = FromCity; } else { imgFromCity.ImageUrl = "../CityImages/noImageBig.png"; } imgFromCity.ToolTip = ds.Tables[0].Rows[0]["StartCity"].ToString(); if (ds.Tables[0].Rows[0]["ToCityimage"].ToString() != "") { imgToCity.ImageUrl = ToCity; } else { imgToCity.ImageUrl = "../CityImages/noImageBig.png"; } imgToCity.ToolTip = ds.Tables[0].Rows[0]["EndCity"].ToString(); if (hdn_StartCity.Value.ToString() != "0" || CompleteLegs == 0) { // QuizTest(Convert.ToInt32(hdn_StartCity.Value)); Session["StartCity"] = hdn_StartCity.Value.ToString(); Session["CurrentClass"] = classId.ToString(); DataTable dt = objStudent.GetQuizResult(classId, Convert.ToInt32(hdn_StartCity.Value)); dt.DefaultView.RowFilter = " IsPassed =1"; int isPassed = dt.DefaultView.Count; dt.DefaultView.RowFilter = string.Empty; if ((isPassed == 1 || dt.Rows.Count > 5) || CompleteLegs == 0) { if (objStudent.GetNextStageFiles(classId) == 0 && CompleteLegs != 0) { lbl_TestResult.Text = (string)GetLocalResourceObject("PassedTest") + "<br/>" + (string)GetLocalResourceObject("ContinueToNextStage") + "<br/>"; lbl_TestResult.Visible = true; div_Congrats.Visible = false; } } else { #region Change : Show Old Leg till Quiz passed try { showOld = 1; if (dsPrevStage.Rows.Count > 0) { lblCurrentStage.Text = (string)GetLocalResourceObject("CurrentStage") + "<br/>" + dsPrevStage.Rows[0]["StartCity"].ToString() + " => " + dsPrevStage.Rows[0]["EndCity"].ToString(); hdn_StartCity.Value = dsPrevStage.Rows[0]["FromCityId"].ToString(); hdn_EndCity.Value = dsPrevStage.Rows[0]["ToCityId"].ToString(); FromCity = "../CityImages/" + dsPrevStage.Rows[0]["FromCityimage"].ToString(); ToCity = "../CityImages/" + dsPrevStage.Rows[0]["ToCityimage"].ToString(); if (dsPrevStage.Rows[0]["FromCityimage"].ToString() != "") { imgFromCity.ImageUrl = FromCity; } else { imgFromCity.ImageUrl = "../CityImages/noImageBig.png"; } imgFromCity.ToolTip = dsPrevStage.Rows[0]["StartCity"].ToString(); if (dsPrevStage.Rows[0]["ToCityimage"].ToString() != "") { imgToCity.ImageUrl = ToCity; } else { imgToCity.ImageUrl = "../CityImages/noImageBig.png"; } imgToCity.ToolTip = dsPrevStage.Rows[0]["EndCity"].ToString(); } } catch { showOld = 0; } #endregion div_NextStage.Visible = true; div_RightCol.Visible = false; } } else { div_QuizTest.Visible = false; } if (ds.Tables[0].Rows[0]["lastreachedcity"].ToString() != "") { lblCongratulations2.Text = ds.Tables[0].Rows[0]["lastreachedcity"].ToString(); lblCongratulations1.Visible = true; lblCongratulations3.Visible = true; //lblFromCityName.Text = ds.Tables[0].Rows[0]["lastreachedcity"].ToString(); } else { //lblFromCityName.Text = ds.Tables[0].Rows[0]["StartCity"].ToString(); } try { double sm2 = 0; double sm3 = 0; if (showOld == 0) { sm2 = double.Parse(ds.Tables[0].Rows[0]["Distance_Covered"].ToString().Replace(@",", "."), System.Globalization.CultureInfo.InvariantCulture); sm3 = double.Parse(ds.Tables[0].Rows[0]["Distance"].ToString(), System.Globalization.CultureInfo.InvariantCulture); percentage = ((sm2 * 100) / Convert.ToDouble(ds.Tables[0].Rows[0]["Distance"])); } else { sm2 = double.Parse(dsPrevStage.Rows[0]["Distance_Covered"].ToString().Replace(@",", "."), System.Globalization.CultureInfo.InvariantCulture); sm3 = double.Parse(dsPrevStage.Rows[0]["Distance"].ToString(), System.Globalization.CultureInfo.InvariantCulture); percentage = ((sm2 * 100) / Convert.ToDouble(dsPrevStage.Rows[0]["Distance"])); } lblDistanceCovered.Text = (Math.Round(sm2, 2).ToString() + " km " + (string)GetLocalResourceObject("From") + " " + Math.Round(sm3, 2).ToString() + " km " + (string)GetLocalResourceObject("driven") + "").Replace(",", ".").ToString(); } catch (Exception ex) { } //Remove(); //if (showOld == 0) //{ // _BindMap(ds.Tables[0].Rows[0]["StartCity"].ToString(), ds.Tables[0].Rows[0]["EndCity"].ToString(), percentage, Convert.ToDouble(ds.Tables[0].Rows[0]["FromCityLat"].ToString()), Convert.ToDouble(ds.Tables[0].Rows[0]["FromCityLong"].ToString()), Convert.ToDouble(ds.Tables[0].Rows[0]["ToCityLat"].ToString()), Convert.ToDouble(ds.Tables[0].Rows[0]["ToCityLong"].ToString())); //} //else //{ // _BindMap(dsPrevStage.Rows[0]["StartCity"].ToString(), dsPrevStage.Rows[0]["EndCity"].ToString(), percentage, Convert.ToDouble(dsPrevStage.Rows[0]["FromCityLat"].ToString()), Convert.ToDouble(dsPrevStage.Rows[0]["FromCityLong"].ToString()), Convert.ToDouble(dsPrevStage.Rows[0]["ToCityLat"].ToString()), Convert.ToDouble(dsPrevStage.Rows[0]["ToCityLong"].ToString())); //} } else { if (CompleteLegs > 0) { DataTable dtLStage = objStudent.GetLastCompleteStageInfo(Convert.ToInt32(Session["UserId"].ToString()), Convert.ToInt32(Session["UserRoleId"].ToString()), classId); if (dtLStage.Rows.Count > 0) { // lblCurrentStage.Text = (string)GetLocalResourceObject("LastStage") + "<br/>" + dtLStage.Rows[0]["StartCity"].ToString() + //" => " + dtLStage.Rows[0]["EndCity"].ToString(); hdn_StartCity.Value = dtLStage.Rows[0]["StartCityId"].ToString(); hdn_EndCity.Value = dtLStage.Rows[0]["EndCityId"].ToString(); string FromCity = "../CityImages/" + dtLStage.Rows[0]["FromCityimage"].ToString(); string ToCity = "../CityImages/" + dtLStage.Rows[0]["ToCityimage"].ToString(); if (dtLStage.Rows[0]["FromCityimage"].ToString() != "") { imgFromCity.ImageUrl = FromCity; } else { imgFromCity.ImageUrl = "../CityImages/noImageBig.png"; } imgFromCity.ToolTip = dtLStage.Rows[0]["FromCityimage"].ToString(); if (dtLStage.Rows[0]["ToCityimage"].ToString() != "") { imgToCity.ImageUrl = ToCity; } else { imgToCity.ImageUrl = "../CityImages/noImageBig.png"; } imgToCity.ToolTip = dtLStage.Rows[0]["ToCityimage"].ToString(); div_QuizTest.Visible = false; //lblFromCityName.Text = dtLStage.Rows[0]["StartCity"].ToString(); try { double sm2 = double.Parse(dtLStage.Rows[0]["Distance_Covered"].ToString().Replace(@",", "."), System.Globalization.CultureInfo.InvariantCulture); double sm3 = double.Parse(dtLStage.Rows[0]["Distance"].ToString(), System.Globalization.CultureInfo.InvariantCulture); percentage = ((sm2 * 100) / Convert.ToDouble(dtLStage.Rows[0]["Distance"])); lblDistanceCovered.Text = (Math.Round(sm2, 2).ToString() + " km von " + Math.Round(sm3, 2).ToString() + " km " + (string)GetLocalResourceObject("driven") + "").Replace(",", ".").ToString(); } catch (Exception ex) { } //Remove(); //_BindMap(dtLStage.Rows[0]["StartCity"].ToString(), dtLStage.Rows[0]["EndCity"].ToString(), percentage, Convert.ToDouble(dtLStage.Rows[0]["FromCityLat"].ToString()), Convert.ToDouble(dtLStage.Rows[0]["FromCityLong"].ToString()), Convert.ToDouble(dtLStage.Rows[0]["ToCityLat"].ToString()), Convert.ToDouble(dtLStage.Rows[0]["ToCityLong"].ToString())); } } } if (ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0) { ltlClassForum.Text += " - " + ds.Tables[1].Rows[0]["School"].ToString(); //h1_ClassForum.InnerHtml += " - " + ds.Tables[1].Rows[0]["School"].ToString(); // BindGermanyMap(); } if (ds.Tables[2] != null && ds.Tables[2].Rows.Count > 0) { div_RightCol.Visible = true; lbtnCityInfo.Visible = true; div_QuizTest.Visible = true; lbtnCityInfo.PostBackUrl = "~/Student/CityInfo.aspx?cityid=" + ds.Tables[2].Rows[0]["cityInfoCityId"].ToString() + "&cityname=" + ds.Tables[2].Rows[0]["cityname"].ToString() + "&parent=student"; } } else { // BindGermanyMap(); div_NoStagePlan.Visible = true; div_Content.Visible = false; divForumBlog.Style.Add("Width", "100%"); } } catch (Exception ex) { } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["pscore"] != null && Request.QueryString["pointsawarded"] != null && Request.QueryString["totalScore"] != null) { int userid = 0; int pass = 0; int cityid = 0; int classid = 0; if (Session["StartCity"] != null) { cityid = Convert.ToInt32(Session["StartCity"]); } if (Session["CurrentClass"] != null) { classid = Convert.ToInt32(Session["CurrentClass"]); } DataSet ds = objStudent.GetCurrentStageInfo(Convert.ToInt32(Session["UserId"].ToString()), Convert.ToInt32(Session["UserRoleId"].ToString()), 0); if (ds != null && ds.Tables.Count > 0) { if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { cityid = Convert.ToInt32(ds.Tables[0].Rows[0]["StartCityId"].ToString()); classid = Convert.ToInt32(ds.Tables[0].Rows[0]["ClassId"].ToString()); } } try { double passingscore = Convert.ToDouble(Request.QueryString["pscore"]); double outofscore = Convert.ToDouble(Request.QueryString["totalScore"]); double studentscore = Convert.ToDouble(Request.QueryString["pointsawarded"]); if (studentscore >= passingscore) { Session["result"] = "pass"; pass = 1; } else { Session["result"] = "fail"; } if (Session["UserId"] != null) { userid = Convert.ToInt32(Session["UserId"]); } try { StreamWriter tw = new StreamWriter(Server.MapPath("TestQuiz/result.txt"), true); tw.WriteLine(" Passing: " + passingscore.ToString()); tw.WriteLine(" Outof: " + outofscore.ToString()); tw.WriteLine(" Score: " + studentscore.ToString()); tw.WriteLine(" User: "******" City: " + cityid.ToString()); tw.Close(); } catch { } if (userid != 0) { int res = objStudent.InsertQuizResult(0, userid, classid, cityid, outofscore, passingscore, studentscore, pass); DataTable dt = objStudent.GetQuizResult(classid, cityid); dt.DefaultView.RowFilter = " IsPassed =1"; int isPassed = dt.DefaultView.Count; dt.DefaultView.RowFilter = string.Empty; if (res > 0 && (isPassed == 1 || dt.Rows.Count > 5)) { //Deleteting appeared test files from respective folder try { string directoryPath = Server.MapPath("QuizTests/HtmlQuiz1").ToString(); string[] filePaths = Directory.GetFiles(directoryPath); foreach (string filePath in filePaths) { File.Delete(filePath); } string[] dirPaths = Directory.GetDirectories(directoryPath); if (dirPaths != null) { foreach (string dirPath in dirPaths) { filePaths = Directory.GetFiles(dirPath); foreach (string filePath in filePaths) { File.Delete(filePath); } Directory.Delete(dirPath); } } } catch (Exception ex) { } int NextLegId = 0; double RemainingDist = 0; DataTable dtLastComplete = objStudent.GetLastCompleteLeg(classid); DataTable dtNextLeg = objStudent.GetNextStageLeg(classid); if (dtLastComplete.Rows.Count > 0) { int LastLegId = Convert.ToInt32(dtLastComplete.Rows[0]["StagePlanId"]); double ExtraDistance = Convert.ToDouble(dtLastComplete.Rows[0]["Distance_Extra"]); if (dtNextLeg.Rows.Count > 0) { NextLegId = Convert.ToInt32(dtNextLeg.Rows[0]["StagePlanId"]); double DistanceToCover = Convert.ToDouble(dtNextLeg.Rows[0]["Distance"]); if (ExtraDistance > DistanceToCover) { RemainingDist = ExtraDistance - DistanceToCover; ExtraDistance = DistanceToCover; } int result = objStudent.StartNextLeg(ExtraDistance, RemainingDist, NextLegId); if (result > 0) { int result2 = objStudent.ClearExtraLegDistance(LastLegId); } } } } } //Response.Redirect("~/Student/StudentForm.aspx"); } catch (Exception ex) { Helper.Log(ex.Message.ToString(), "Error in Saving test result"); // Response.Redirect("~/Student/HtmlForum.aspx"); } } else { Helper.Log("Null values from php page ", "Invalid values from php page"); // Response.Redirect("~/Student/HtmlForum.aspx"); } }