示例#1
0
    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)
        { }
    }
示例#2
0
    private void _BindData()
    {
        try
        {
            double percentage = 0.0;

            int classId      = Convert.ToInt32(ddlClass.SelectedValue);
            int CompleteLegs = objStudent.GetCompleteLegCount(classId);

            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.Visible = true;
                divForumBlog.Style.Add("Width", "700px");
                div_NoStagePlan.Visible     = false;
                lblCongratulations1.Visible = false;
                lblCongratulations3.Visible = false;

                if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    lblStage.Text        = "Aktuelle Etappe<br/>";
                    lblCurrentStage.Text = ds.Tables[0].Rows[0]["StartCity"].ToString() +
                                           " => " + ds.Tables[0].Rows[0]["EndCity"].ToString();
                    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 (ds.Tables[0].Rows[0]["lastreachedcity"].ToString() != "")
                    {
                        lblCongratulations2.Text    = ds.Tables[0].Rows[0]["lastreachedcity"].ToString();
                        lblCongratulations1.Visible = true;
                        lblCongratulations3.Visible = true;
                    }

                    double sm2 = double.Parse(ds.Tables[0].Rows[0]["Distance_Covered"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                    double sm3 = double.Parse(ds.Tables[0].Rows[0]["Distance"].ToString(), System.Globalization.CultureInfo.InvariantCulture);

                    lblDistanceCovered.Text = (Math.Round(sm2, 2).ToString() + " km von " +
                                               Math.Round(sm3, 2).ToString() + " km gefahren").Replace(",", ".").ToString();

                    percentage = ((sm2 * 100) / sm3);
                    Remove();
                    //  _BindMap(ds.Tables[0].Rows[0]["StartCity"].ToString(), ds.Tables[0].Rows[0]["EndCity"].ToString(), percentage);
                    _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
                {
                    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 = "Letzte Etappe<br/>" + dtLStage.Rows[0]["StartCity"].ToString() +
                                                   " => " + dtLStage.Rows[0]["EndCity"].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();

                            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 angetrieben").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)
                {
                    h1_ClassForum.InnerHtml = "Klasse Forum - " + ds.Tables[1].Rows[0]["School"].ToString();
                    BindGermanyMap(); // Remove();
                }
                if (ds.Tables[2] != null && ds.Tables[2].Rows.Count > 0)
                {
                    lbtnCityInfo.Visible     = true;
                    lbtnCityInfo.PostBackUrl = "~/Student/CityInfo.aspx?cityid=" + ds.Tables[2].Rows[0]["cityInfoCityId"].ToString() +
                                               "&cityname=" + ds.Tables[2].Rows[0]["cityname"].ToString() + "&parent=class";
                    // Remove();
                }
            }
            else
            {
                BindGermanyMap();
                div_NoStagePlan.Visible = true;
                pnlContent.Visible      = false;
                divForumBlog.Style.Add("Width", "100%");
                divForumBlog.Visible = true;
            }
        }
        catch (Exception ex)
        {
            Helper.Log(ex.Message, "Bind Data");
        }
    }
示例#3
0
    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)
                {
                    pass = 1;
                    Session["result"] = "pass";
                }

                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 = 0;// objStudent.InsertQuizResult(0, userid, classid, cityid, outofscore, passingscore, studentscore, pass);
                    if (res > 0 && pass == 1)
                    {
                        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/Forum.aspx");
            }
        }
        else
        {
            Helper.Log("Null values from php page ", "Invalid values from php page");
            Response.Redirect("~/Student/Forum.aspx");
        }
    }
示例#4
0
    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(ddlSchool.SelectedValue) > 0 && Convert.ToInt32(ddlClass.SelectedValue) > 0)
        {
            BCCityAdmin cityContent   = new BCCityAdmin();
            DateTime    cityStartDate = new DateTime();
            string      FileName      = fu_UploadGpx.PostedFile.FileName;
            string      NewFile       = "";
            string      NewFileName   = "";
            string      FilePath      = Server.MapPath("../GPXFiles/" + ddlSchool.SelectedValue.ToString() + "/" + ddlClass.SelectedValue.ToString() + "/0/").ToString();
            string      extension     = System.IO.Path.GetExtension(FileName).ToLower();

            if ((extension == ".gpx") | (extension == ".GPX"))
            {
                if (IsFileUploaded(FilePath + FileName))
                {
                    string popupScript = "alert('File already uploaded!');";
                    ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                }
                else
                {
                    #region Save file on server for evaluation

                    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(FilePath);
                    if (!(dir.Exists))
                    {
                        System.IO.Directory.CreateDirectory(FilePath);
                    }
                    fu_UploadGpx.SaveAs(FilePath + FileName.Replace(".gpx", ".xml"));

                    DataTable dt = cityContent.GetCityContent(0, Convert.ToInt32(ddlSchool.SelectedValue));

                    try
                    {
                        string TimeStamp = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() +
                                           DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".xml";

                        NewFileName = Session["UserRoleId"].ToString() + "_" + Session["UserId"].ToString() + "_" + TimeStamp + "";
                        File.Move(FilePath + FileName.Replace(".gpx", ".xml"), FilePath + NewFileName); // Try to move
                        NewFile = FilePath + NewFileName;
                    }
                    catch (IOException ex)
                    {
                        NewFile     = FilePath + FileName;
                        NewFileName = FileName;
                    }

                    #endregion

                    DataTable dtNew = new DataTable();
                    dtNew = LoadGPXWaypoints(NewFile);
                    DateTime DateOfFile = DateTime.MinValue;
                    try
                    {
                        if (dt != null && dt.Rows.Count > 0 && dtNew != null && dtNew.Rows.Count > 0)
                        {
                            cityStartDate = Convert.ToDateTime(dt.Rows[0]["CityStartDate"]);
                            DateOfFile    = Convert.ToDateTime(dtNew.Rows[0]["time"]);
                        }
                        if (cityStartDate != new DateTime() &&
                            DateOfFile <= cityStartDate)
                        {
                            File.Delete(NewFile);
                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileNotForPriorDate") + "');";
                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                            return;
                        }
                        if (DateOfFile < DateTime.Parse(ConfigurationManager.AppSettings["BatchStartDate"]))
                        {
                            File.Delete(NewFile);
                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileNotForCurrentBatch") + "');";
                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileNoHaveTimeStamp") + "');";
                        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                        return;
                    }
                    int trackCount = dtNew.Rows.Count;

                    //DataTable dtNewRows = CheckPreviousGPXTrackPoints(Convert.ToInt32(Session["UserId"]),
                    //    Convert.ToInt32(ddlSchool.SelectedValue),
                    //    Convert.ToInt32(ddlClass.SelectedValue.ToString()), dtNew);

                    DataTable dtNewRows = CheckPreviousGPXTrackPointsNew
                                              (Convert.ToInt32(Session["UserId"]),
                                              Convert.ToInt32(ddlSchool.SelectedValue),
                                              Convert.ToInt32(ddlClass.SelectedValue.ToString()), dtNew);

                    if (dtNewRows != null &&
                        dtNewRows.Rows.Count > 0)
                    {
                        double distance     = CalculateTotalDistance(dtNewRows);
                        double time         = CalculateTotalTime(dtNewRows);
                        double timeAvg      = CalculateAvgTime(dtNewRows);
                        double highestSpeed = 0;
                        #region Calculate Average Speed
                        if (timeAvg > 0)
                        {
                            time = timeAvg;
                        }

                        double avgSpeed = 0.0;
                        if (time > 0)
                        {
                            avgSpeed = distance / time;
                        }
                        #endregion

                        if (avgSpeed == 0)
                        {
                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgAvgSpeedIsLow") + "');";
                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                            File.Delete(NewFile);
                        }
                        else
                        {
                            highestSpeed = GetHighestSpeedInGPX(dtNewRows);

                            string avgMsg = IsAvgSpeedExceed(avgSpeed, out avgSpeedLimit);
                            //if (!string.IsNullOrEmpty(avgMsg))
                            //{
                            //    ClientScript.RegisterStartupScript(Page.GetType(), "script", avgMsg, true);
                            //    return;
                            //}
                            string highMsg = IsHighSpeedExceed(highestSpeed, out highSpeedLimit);
                            //if (!string.IsNullOrEmpty(highMsg))
                            //{
                            //    ClientScript.RegisterStartupScript(Page.GetType(), "script", highMsg, true);
                            //    return;
                            //}

                            #region Check ongoing stage information

                            int     stagePlanId   = 0;
                            double  stageDistance = 0;
                            double  distCovered   = 0;
                            DataSet _dtStage      = objStudent.GetCurrentStageInfo(Convert.ToInt32(Session["UserId"]), Convert.ToInt32(Session["UserRoleId"]), Convert.ToInt32(ddlClass.SelectedValue));
                            if (_dtStage.Tables[0].Rows.Count > 0)
                            {
                                stagePlanId   = Convert.ToInt32(_dtStage.Tables[0].Rows[0]["StagePlanId"]);
                                stageDistance = Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance"]);
                                distCovered   = double.Parse(_dtStage.Tables[0].Rows[0]["Distance_Covered"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                                //Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance_Covered"]);
                            }
                            else
                            {
                                string popupScript = "alert('No active stage plan!');";
                                ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                                return;
                            }
                            #endregion

                            if (avgSpeed > avgSpeedLimit)
                            {
                                string popupScript = "alert('Speed Limit Crossed!');";//Speed Limit Crossed!
                                ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                            }
                            else
                            {
                                //Save data in Student Uploads
                                #region Save data in Student Uploads
                                if (stagePlanId != 0)
                                {
                                    int res = objStudent.StudentsUpload(0, 0, stagePlanId, stageDistance, distCovered, (NewFile), NewFileName, DateTime.Now, distance, time, Convert.ToInt32(ddlClass.SelectedValue), 1, trackCount);
                                    if (res > 0)
                                    {
                                        string popupScript = "alert('File uploaded successfully!');";
                                        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                                    }
                                    else
                                    {
                                        string popupScript = "alert('" + (string)GetLocalResourceObject("MsgUploadException") + "');";
                                        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                                        File.Delete(NewFile);
                                    }
                                    grd_Uploads.DataBind();
                                }
                                else
                                {
                                    string popupScript = "alert('No active stage plan!');";
                                    ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                                }
                                #endregion
                            }
                        }
                    }
                    else
                    {
                        string popupScript = "alert('File already uploaded!');";//File already uploaded!
                        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                    }
                }
            }
            else
            {
                string popupScript = "alert('" + (string)GetLocalResourceObject("MsgSelectGPX") + "');";//Select GPX file!
                ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
            }
        }

        else
        {
            string popupScript = "alert('Please select School and Class!');";
            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
        }
    }
示例#5
0
    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");
        }
    }
示例#6
0
        static void Main(string[] args)
        {
            try
            {
                // variable declaration
                BCStudent objStudent    = new BCStudent();
                int       studentId     = 0;
                int       UserRoleId    = 5;
                int       stagePlanId   = 0;
                double    stageDistance = 0;
                double    distCovered   = 0;
                Int32     UserId        = 0;
                DataTable studInfo      = null;

                string UserName = string.Empty;
                Int32  schoolId = 0;
                Int32  classId  = 0;
                Int32  cityId   = 0;
                // end variable declaration



                // Get student info
                StringBuilder sqlString = new StringBuilder();

                sqlString.Append("select * from LoginDtls where LoginName='");
                sqlString.Append(args[0]);
                sqlString.Append("' and cast(Password as varbinary(20))=cast('");
                sqlString.Append(args[1]);
                sqlString.Append("' as varbinary(50)) and IsActive=1");

                var login = DataAccessLayer.ReturnDataTable(sqlString.ToString());

                if (login != null)
                {
                    UserRoleId = Convert.ToInt32(login.Rows[0]["RoleId"]);
                    UserId     = Convert.ToInt32(login.Rows[0]["LoginId"]);
                    UserName   = Convert.ToString(login.Rows[0]["LoginName"]);

                    if (UserRoleId == 5)
                    {
                        sqlString = new StringBuilder();
                        sqlString.Append("Select * FROM StudentMaster Where LoginId = ");
                        sqlString.Append(UserId);

                        var student = DataAccessLayer.ReturnDataTable(sqlString.ToString());
                        if (student != null && student.Rows.Count > 0)
                        {
                            schoolId  = Convert.ToInt32(student.Rows[0]["SchoolId"]);
                            classId   = Convert.ToInt32(student.Rows[0]["ClassId"]);
                            cityId    = Convert.ToInt32(student.Rows[0]["CityId"]);
                            studentId = Convert.ToInt32(student.Rows[0]["StudentId"]);
                        }
                    }

                    studInfo = objStudent.GetMyProfileInfo(studentId);
                    schoolId = Convert.ToInt32(studInfo.Rows[0]["SchoolId"]);
                    classId  = Convert.ToInt32(studInfo.Rows[0]["ClassId"]);



                    DataSet _dtStage = objStudent.GetCurrentStageInfo((studentId > 0 ? studentId : UserId),
                                                                      UserRoleId, classId);
                    if (_dtStage.Tables[0].Rows.Count > 0)
                    {
                        stagePlanId   = Convert.ToInt32(_dtStage.Tables[0].Rows[0]["StagePlanId"]);
                        stageDistance = Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance"]);
                        distCovered   = double.Parse(_dtStage.Tables[0].Rows[0]["Distance_Covered"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                        //Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance_Covered"]);
                    }

                    int res = objStudent.StudentsDeleteLastUpload(
                        UserRoleId, UserId,
                        0, studentId,
                        stagePlanId, stageDistance, distCovered, classId, 1);
                }
                else
                {
                    Console.WriteLine("Incorrect Username or Password");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("No last file found or internal server error occured, following are details : \n\n" + ex.Message);
            }
        }
示例#7
0
    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        try
        {
            BCCityAdmin cityContent   = new BCCityAdmin();
            DateTime    cityStartDate = new DateTime();
            DataTable   _dtTrkpts     = new DataTable();
            string      FileName      = fu_UploadGpx.PostedFile.FileName;
            string      NewFile       = "";
            string      NewFileName   = "";
            DataTable   studInfo      = objStudent.GetMyProfileInfo(Convert.ToInt32(Session["UserId"]));

            string FilePath  = Server.MapPath("../GPXFiles/" + studInfo.Rows[0]["SchoolId"].ToString() + "/" + studInfo.Rows[0]["ClassId"].ToString() + "/" + Session["UserId"].ToString() + "/").ToString();
            string extension = System.IO.Path.GetExtension(FileName).ToLower();

            if ((extension == ".gpx") | (extension == ".GPX"))
            {
                if (IsFileUploaded(FilePath + FileName))
                {
                    string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileAlredyUploaded") + "');";//File already uploaded!
                    ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                }
                else
                {
                    #region Save file on server for evaluation

                    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(FilePath);
                    if (!(dir.Exists))
                    {
                        System.IO.Directory.CreateDirectory(FilePath);
                    }
                    fu_UploadGpx.SaveAs(FilePath + FileName.Replace(".gpx", ".xml"));
                    DataTable dt = cityContent.GetCityContent(Convert.ToInt32(studInfo.Rows[0]["CityId"]), 0);

                    try
                    {
                        string TimeStamp = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() +
                                           DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "";

                        NewFileName = Session["UserRoleId"].ToString() + "_" + Session["UserId"].ToString() + "_" + TimeStamp + ".xml";
                        File.Move(FilePath + FileName.Replace(".gpx", ".xml"), FilePath + NewFileName); // Try to move
                        NewFile = FilePath + NewFileName;
                    }
                    catch (IOException ex)
                    {
                        NewFile     = FilePath + FileName;
                        NewFileName = FileName;
                    }

                    #endregion

                    DataTable dtNew = new DataTable();
                    dtNew = LoadGPXWaypoints(NewFile);
                    DateTime DateOfFile = DateTime.MinValue;
                    try
                    {
                        if (dt != null && dt.Rows.Count > 0 && dtNew != null && dtNew.Rows.Count > 0)
                        {
                            cityStartDate = Convert.ToDateTime(dt.Rows[0]["CityStartDate"]);
                            DateOfFile    = Convert.ToDateTime(dtNew.Rows[0]["time"]);
                        }

                        if (cityStartDate != new DateTime() &&
                            DateOfFile <= cityStartDate)
                        {
                            File.Delete(NewFile);
                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileNotForPriorDate") + "');";
                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                            return;
                        }

                        if (DateOfFile < DateTime.Parse(ConfigurationManager.AppSettings["BatchStartDate"]))
                        {
                            File.Delete(NewFile);
                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileNotForCurrentBatch") + "');";
                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileNoHaveTimeStamp") + "');";
                        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                        return;
                    }

                    _dtTrkpts = dtNew;
                    int    trackCount   = (dtNew.Rows.Count / 5) + 1;
                    double highestSpeed = 0;

                    DataTable dtNewRows = CheckPreviousGPXTrackPointsNew
                                              (Convert.ToInt32(Session["UserId"]),
                                              Convert.ToInt32(studInfo.Rows[0]["SchoolId"].ToString()),
                                              Convert.ToInt32(studInfo.Rows[0]["ClassId"].ToString()), dtNew);

                    if (dtNewRows != null &&
                        dtNewRows.Rows.Count > 0)
                    {
                        double distance = CalculateTotalDistance(dtNewRows);
                        double time     = CalculateTotalTime(dtNewRows);
                        double timeAvg  = CalculateAvgTime(dtNewRows);

                        #region Calculate Average Speed

                        if (timeAvg > 0)
                        {
                            time = timeAvg;
                        }

                        double avgSpeed = 0.0;
                        if (time > 0)
                        {
                            avgSpeed = distance / time;
                        }

                        #endregion

                        int speedLimit = 15;

                        if (ConfigurationManager.AppSettings["SpeedLimit"].ToString() != "")
                        {
                            speedLimit = Convert.ToInt32(ConfigurationManager.AppSettings["SpeedLimit"]);
                        }

                        // bool IsFileCopied = checkGPXWayPoints(dtNew);


                        if (avgSpeed == 0)
                        {
                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgAvgSpeedIsLow") + "');";
                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                            File.Delete(NewFile);
                        }
                        else
                        {
                            highestSpeed = GetHighestSpeedInGPX(dtNewRows);


                            string avgMsg = IsAvgSpeedExceed(avgSpeed, out avgSpeedLimit);
                            //if (!string.IsNullOrEmpty(avgMsg))
                            //{
                            //    ClientScript.RegisterStartupScript(Page.GetType(), "script", avgMsg, true);
                            //    return;
                            //}
                            string highMsg = IsHighSpeedExceed(highestSpeed, out highSpeedLimit);
                            //if (!string.IsNullOrEmpty(highMsg))
                            //{
                            //    ClientScript.RegisterStartupScript(Page.GetType(), "script", highMsg, true);
                            //    return;
                            //}

                            #region Check ongoing stage information

                            int     stagePlanId   = 0;
                            double  stageDistance = 0;
                            double  distCovered   = 0;
                            DataSet _dtStage      = objStudent.GetCurrentStageInfo(Convert.ToInt32(Session["UserId"]), Convert.ToInt32(Session["UserRoleId"]), Convert.ToInt32(studInfo.Rows[0]["ClassId"]));
                            if (_dtStage.Tables[0].Rows.Count > 0)
                            {
                                stagePlanId   = Convert.ToInt32(_dtStage.Tables[0].Rows[0]["StagePlanId"]);
                                stageDistance = Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance"]);
                                distCovered   = double.Parse(_dtStage.Tables[0].Rows[0]["Distance_Covered"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                                //Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance_Covered"]);
                            }
                            else
                            {
                                string popupScript = "alert('No active stage plan!');";
                                ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                            }
                            #endregion
                            bool isApproved = true;
                            if (avgSpeed <= avgSpeedLimit && highestSpeed <= highSpeedLimit)
                            {
                                isApproved = true;
                            }
                            if (highestSpeed >= 40 &&
                                highestSpeed <= highSpeedLimit)
                            {
                                isApproved = false;
                            }
                            if (isApproved)
                            {
                                //Save data in Student Uploads

                                #region Save data in Student Uploads

                                // Check for similar track points


                                int res = objStudent.StudentsUpload(0, Convert.ToInt32(Session["UserId"]), stagePlanId, stageDistance, distCovered, (NewFile), NewFileName, DateTime.Now, distance, time, Convert.ToInt32(studInfo.Rows[0]["ClassId"]), 1, trackCount);
                                if (res > 0)
                                {
                                    _SaveTrackPoints(_dtTrkpts, res);

                                    string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileUploaded") + "');";//File uploaded successfully!
                                    ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                                }
                                else
                                {
                                    string popupScript = "alert('" + (string)GetLocalResourceObject("MsgUploadException") + "');";//File already uploaded!
                                    ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                                    File.Delete(NewFile);
                                }
                                grd_Uploads.DataBind();

                                #endregion
                            }
                            else // Upload file out of speed limit. No change in stage distance.
                            {
                                #region Save data in Student Uploads
                                int res = objStudent.StudentsUploadExtraSpeed(0, Convert.ToInt32(Session["UserId"]), stagePlanId, stageDistance, distCovered, (NewFile), NewFileName, DateTime.Now, distance, time, Convert.ToInt32(studInfo.Rows[0]["ClassId"]), 0, trackCount);
                                if (res > 0)
                                {
                                    _SaveTrackPoints(_dtTrkpts, res);
                                    #region Send email to Class Admin & City Admin for speed limit

                                    if (avgSpeed > avgSpeedLimit || highestSpeed > highSpeedLimit)
                                    {
                                        try
                                        {
                                            string ClassAdminEmail = studInfo.Rows[0]["ClassAdminEmail"].ToString();
                                            string CityAdminEmail  = studInfo.Rows[0]["CityAdminEmail"].ToString();

                                            StringBuilder sb = new StringBuilder();
                                            sb.Append("<p>Dear " + studInfo.Rows[0]["ClassAdminName"].ToString() + ",</p>");
                                            sb.Append("<p><b>" + Session["UserName"].ToString() + " (Student in " + studInfo.Rows[0]["School"].ToString() + ", " + studInfo.Rows[0]["Class"].ToString() + ")</b> have uploaded a GPX file (" + NewFileName + ") with speed <b>" + avgSpeed.ToString() + " Kmph and heighest speed being " + highestSpeed + "</b>.</p>");
                                            sb.Append("<p>Kindly approve or reject file manually.</p>");
                                            Helper.sendMailMoreThanAvgSpeed("BikeTour - Speed Limit Crossed!", ClassAdminEmail, sb.ToString());

                                            StringBuilder sb2 = new StringBuilder();
                                            sb2.Append("<p>Dear " + studInfo.Rows[0]["CityAdminName"].ToString() + ",</p>");
                                            sb.Append("<p><b>" + Session["UserName"].ToString() + " (Student in " + studInfo.Rows[0]["School"].ToString() + ", " + studInfo.Rows[0]["Class"].ToString() + ")</b> have uploaded a GPX file (" + NewFileName + ") with speed <b>" + avgSpeed.ToString() + "Kmph and heighest speed being " + highestSpeed + "</b>.</p>");
                                            sb.Append("<p>Kindly approve or reject file manually.</p>");
                                            Helper.sendMailMoreThanAvgSpeed("BikeTour - Speed Limit Crossed!", ClassAdminEmail, sb2.ToString());
                                        }
                                        catch (Exception ex)
                                        {
                                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgUploadException") + "');";//File already uploaded!
                                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                                        }
                                    }

                                    #endregion

                                    string popupScripts = "alert('" + (string)GetLocalResourceObject("MsgFileUploaded") + "');";//File uploaded successfully!
                                    ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScripts, true);
                                }
                                else
                                {
                                    string popupScript = "alert('" + (string)GetLocalResourceObject("MsgUploadException") + "');";//File already uploaded!
                                    ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                                    File.Delete(NewFile);
                                }
                                grd_Uploads.DataBind();

                                #endregion
                            }
                        }
                    }
                    else
                    {
                        string popupScript = "alert('" + (string)GetLocalResourceObject("MsgFileAlredyUploaded") + "');";//File already uploaded!
                        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                    }
                }
            }
            else
            {
                string popupScript = "alert('" + (string)GetLocalResourceObject("MsgSelectGPX") + "');";//Select GPX file!
                ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
            }
        }
        catch (Exception)
        {
            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgUploadException") + "');";//Select GPX file!
            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
        }
    }
示例#8
0
        protected void Upload(UploadFile PostedFile,
                              UploadResponseMessage response, string filePath)
        {
            string FileName = string.Empty;

            try
            {
                BCCityAdmin cityContent   = new BCCityAdmin();
                DateTime    cityStartDate = new DateTime();
                DataTable   _dtTrkpts     = new DataTable();
                DataTable   studInfo      = null;
                FileName = PostedFile.FileName;
                string NewFile     = "";
                string NewFileName = "";
                string FilePath    = string.Empty;


                studInfo = objStudent.GetMyProfileInfo(studentId);
                schoolId = Convert.ToInt32(studInfo.Rows[0]["SchoolId"]);
                classId  = Convert.ToInt32(studInfo.Rows[0]["ClassId"]);

                FilePath = filePath + schoolId + @"\" +
                           classId + @"\" + studentId.ToString() + @"\".ToString();


                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(FilePath);
                if (!(dir.Exists))
                {
                    System.IO.Directory.CreateDirectory(FilePath);
                }
                //string extension = System.IO.Path.GetExtension(FileName).ToLower();
                string[] extention = FileName.Split('.');
                if (extention != null && extention.Count() > 0)
                {
                    FileName = extention[0];
                }

                //if ((extension == ".gpx") | (extension == ".GPX"))
                //{
                if (IsFileUploaded(FilePath + FileName + ".xml"))
                {
                    ErrorLogManager.WriteLog(response, FileName, "008", "File already uploaded!");
                }
                else
                {
                    #region Save file on server for evaluation

                    File.WriteAllBytes(FilePath + FileName + ".xml", PostedFile.FileData);
                    DataTable dt = cityContent.GetCityContent(Convert.ToInt32(studInfo.Rows[0]["CityId"]), 0);

                    try
                    {
                        string TimeStamp = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() +
                                           DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "";

                        NewFileName = UserRoleId.ToString() + "_" + UserId.ToString() + "_" + TimeStamp + ".xml";
                        File.Move(FilePath + FileName + ".xml", FilePath + NewFileName); // Try to move
                        NewFile = FilePath + NewFileName;
                    }
                    catch (IOException ex)
                    {
                        NewFile     = FilePath + FileName;
                        NewFileName = FileName;
                    }

                    //File.WriteAllBytes(FilePath + FileName + ".xml", PostedFile.FileData);
                    ////fu_UploadGpx.SaveAs(FilePath + FileName.Replace(".gpx", ".xml"));
                    //DataTable dt = cityContent.GetCityContent(cityId, 0);
                    //XElement root = null;
                    //DateTime DateOfFile = new DateTime();
                    //try
                    //{
                    //    root = XElement.Load(FilePath + FileName + ".xml");
                    //    DateOfFile = DateTime.Parse(root.Elements().Skip(1).Take(1).Elements().Take(1).ToList()[0].Value);
                    //}
                    //catch (Exception ex)
                    //{
                    //    ErrorLogManager.WriteLog(response,FileName, "009", "Uploaded File does not have Time Information, Please check the file and re-upload");
                    //    return;
                    //}
                    //if (dt != null && dt.Rows.Count > 0)
                    //{
                    //    cityStartDate = (dt.Rows[0]["CityStartDate"] != DBNull.Value ? Convert.ToDateTime(dt.Rows[0]["CityStartDate"]) : new DateTime());

                    //    if (cityStartDate != new DateTime() &&
                    //        DateOfFile != new DateTime() &&
                    //        DateOfFile.Date <= cityStartDate.Date)
                    //    {
                    //        ErrorLogManager.WriteLog(response,FileName, "010", "File can not be uploaded prior to Batch Start Date.");
                    //        return;
                    //    }
                    //}
                    //try
                    //{
                    //    string TimeStamp = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() +
                    //    DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "";

                    //    NewFileName = UserRoleId.ToString() + "_" + UserId.ToString() + "_" + TimeStamp + ".xml";
                    //    File.Move(FilePath + FileName + ".xml", FilePath + NewFileName); // Try to move
                    //    NewFile = FilePath + NewFileName;
                    //}
                    //catch (IOException ex)
                    //{
                    //    NewFile = FilePath + FileName + ".xml";
                    //    NewFileName = FileName;
                    //}

                    #endregion

                    DataTable dtNew = new DataTable();
                    dtNew = LoadGPXWaypoints(NewFile);
                    DateTime DateOfFile = DateTime.MinValue;;
                    if (dt != null && dt.Rows.Count > 0 && dtNew != null && dtNew.Rows.Count > 0)
                    {
                        cityStartDate = Convert.ToDateTime(dt.Rows[0]["CityStartDate"]);
                        DateOfFile    = Convert.ToDateTime(dtNew.Rows[0]["time"]);
                    }

                    if ((cityStartDate != new DateTime() &&
                         DateOfFile <= cityStartDate) ||
                        (DateOfFile < DateTime.Parse(ConfigurationManager.AppSettings["BatchStartDate"])))
                    {
                        ErrorLogManager.WriteLog(response, FileName, "010", "File can not be uploaded prior to Batch Start Date.");
                        return;
                    }

                    _dtTrkpts = dtNew;
                    int    trackCount   = dtNew.Rows.Count; //(dtNew.Rows.Count / 5) + 1;
                    double highestSpeed = 0;

                    DataTable dtNewRows = CheckPreviousGPXTrackPointsNew(UserId,
                                                                         schoolId,
                                                                         classId, dtNew);

                    if (dtNewRows != null &&
                        dtNewRows.Rows.Count > 0)
                    {
                        double distance = CalculateTotalDistance(dtNewRows);
                        double time     = CalculateTotalTime(dtNewRows);
                        double timeAvg  = CalculateAvgTime(dtNewRows);

                        #region Calculate Average Speed

                        if (timeAvg > 0)
                        {
                            time = timeAvg;
                        }

                        double avgSpeed = 0.0;
                        if (time > 0)
                        {
                            avgSpeed = distance / time;
                        }

                        #endregion

                        int speedLimit = 15;

                        if (ConfigurationManager.AppSettings["SpeedLimit"].ToString() != "")
                        {
                            speedLimit = Convert.ToInt32(ConfigurationManager.AppSettings["SpeedLimit"]);
                        }

                        if (avgSpeed == 0)
                        {
                            ErrorLogManager.WriteLog(response, FileName, "011", "Invalid file!");
                            File.Delete(NewFile);
                        }
                        else
                        {
                            highestSpeed = GetHighestSpeedInGPX(dtNewRows);

                            #region Check ongoing stage information

                            int     stagePlanId   = 0;
                            double  stageDistance = 0;
                            double  distCovered   = 0;
                            DataSet _dtStage      = objStudent.GetCurrentStageInfo((studentId > 0 ? studentId : UserId),
                                                                                   UserRoleId, classId);
                            if (_dtStage.Tables[0].Rows.Count > 0)
                            {
                                stagePlanId   = Convert.ToInt32(_dtStage.Tables[0].Rows[0]["StagePlanId"]);
                                stageDistance = Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance"]);
                                distCovered   = double.Parse(_dtStage.Tables[0].Rows[0]["Distance_Covered"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                                //Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance_Covered"]);
                            }

                            #endregion
                            //if (avgSpeed > speedLimit)
                            //{
                            //    ErrorLogManager.WriteLog(response, FileName, "016", "Speed Limit Crossed!");
                            //}
                            //else
                            if (avgSpeed <= speedLimit && highestSpeed <= speedLimit)
                            {
                                //Save data in Student Uploads

                                #region Save data in Student Uploads

                                // Check for similar track points


                                int res = objStudent.StudentsUpload(
                                    UserRoleId, UserId,
                                    0, studentId,
                                    stagePlanId, stageDistance, distCovered, (NewFile), NewFileName,
                                    DateTime.Now, distance, time, classId, 1, trackCount);
                                if (res > 0)
                                {
                                    _SaveTrackPoints(_dtTrkpts, res);
                                    ErrorLogManager.WriteLog(response, FileName, "012", "File uploaded successfully!", false);
                                }
                                else
                                {
                                    ErrorLogManager.WriteLog(response, FileName, "008", "File already uploaded!");
                                    File.Delete(NewFile);
                                }

                                #endregion
                            }
                            else // Upload file out of speed limit. No change in stage distance.
                            {
                                #region Save data in Student Uploads
                                int res = objStudent.StudentsUploadExtraSpeed(
                                    UserRoleId, UserId,
                                    0,
                                    studentId, stagePlanId,
                                    stageDistance, distCovered, (NewFile), NewFileName,
                                    DateTime.Now, distance, time, classId, 0, trackCount);
                                if (res > 0)
                                {
                                    _SaveTrackPoints(_dtTrkpts, res);
                                    #region Send email to Class Admin & City Admin for speed limit

                                    if (avgSpeed > speedLimit || highestSpeed > speedLimit)
                                    {
                                        try
                                        {
                                            string ClassAdminEmail = studInfo.Rows[0]["ClassAdminEmail"].ToString();
                                            string CityAdminEmail  = studInfo.Rows[0]["CityAdminEmail"].ToString();

                                            StringBuilder sb = new StringBuilder();
                                            sb.Append("<p>Dear " + studInfo.Rows[0]["ClassAdminName"].ToString() + ",</p>");
                                            sb.Append("<p><b>" + UserName + " (Student in " + studInfo.Rows[0]["School"].ToString() + ", " + studInfo.Rows[0]["Class"].ToString() + ")</b> have uploaded a GPX file (" + NewFileName + ") with speed <b>" + avgSpeed.ToString() + " Kmph and heighest speed being " + highestSpeed + "</b>.</p>");
                                            sb.Append("<p>Kindly approve or reject file manually.</p>");
                                            Helper.sendMailMoreThanAvgSpeed("BikeTour - Speed Limit Crossed!", ClassAdminEmail, sb.ToString());

                                            StringBuilder sb2 = new StringBuilder();
                                            sb2.Append("<p>Dear " + studInfo.Rows[0]["CityAdminName"].ToString() + ",</p>");
                                            sb.Append("<p><b>" + UserName + " (Student in " + studInfo.Rows[0]["School"].ToString() + ", " + studInfo.Rows[0]["Class"].ToString() + ")</b> have uploaded a GPX file (" + NewFileName + ") with speed <b>" + avgSpeed.ToString() + "Kmph and heighest speed being " + highestSpeed + "</b>.</p>");
                                            sb.Append("<p>Kindly approve or reject file manually.</p>");
                                            Helper.sendMailMoreThanAvgSpeed("BikeTour - Speed Limit Crossed!", ClassAdminEmail, sb2.ToString());
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                    }

                                    #endregion
                                    ErrorLogManager.WriteLog(response, FileName, "012", "File uploaded successfully!", false);
                                }
                                else
                                {
                                    ErrorLogManager.WriteLog(response, FileName, "008", "File already uploaded!");
                                    File.Delete(NewFile);
                                }

                                #endregion
                            }
                        }
                    }
                    else
                    {
                        ErrorLogManager.WriteLog(response, FileName, "008", "File already uploaded!");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogManager.WriteLog(response, FileName, "013", "Select GPX file!" + ex.Message);
            }
        }