Exemplo n.º 1
0
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            XmlDocument  xdoc = XmlDataSource2.GetXmlDocument();
            XmlNodeList  list = xdoc.GetElementsByTagName("User");
            XmlElement   feed;
            XmlElement   game  = null;
            XmlAttribute name  = null;
            XmlAttribute score = null;
            XmlElement   game1;

            if (Idplayer == "")
            {
                feed       = xdoc.CreateElement("User");
                name       = xdoc.CreateAttribute("id");
                name.Value = HttpContext.Current.User.Identity.Name.ToString();
                feed.Attributes.Append(name);

                game  = xdoc.CreateElement("Rating");
                name  = xdoc.CreateAttribute("idJogo");
                score = xdoc.CreateAttribute("Rating");

                name.Value = Request.QueryString["id"];
                TextBox textBox = sender as TextBox;
                score.Value = textBox.Text;
                game.Attributes.Append(name);
                game.Attributes.Append(score);
                feed.AppendChild(game);
            }
            else
            {
                feed = xdoc.SelectSingleNode("Ratings/User[@id='" + Idplayer + "']") as XmlElement;
                if (gameReviewed == false)
                {
                    game  = xdoc.CreateElement("Rating");
                    name  = xdoc.CreateAttribute("idJogo");
                    score = xdoc.CreateAttribute("Rating");

                    name.Value = Request.QueryString["id"];
                    TextBox textBox = sender as TextBox;
                    score.Value = textBox.Text;
                    game.Attributes.Append(name);
                    game.Attributes.Append(score);
                    feed.AppendChild(game);
                }
                else
                {
                    game1 = xdoc.SelectSingleNode("Ratings/User[@id='" + Idplayer + "']/Rating[@idJogo='" + Request.QueryString["id"] + "']") as XmlElement;
                    TextBox textBox = sender as TextBox;
                    game1.Attributes[1].Value = textBox.Text;
                    game1.Attributes[0].Value = Request.QueryString["id"];
                    feed.AppendChild(game1);
                }
            }



            xdoc.DocumentElement.AppendChild(feed);

            XmlDataSource2.Save();
        }
    protected void deleteApprove_Click(object sender, EventArgs e)
    {
        fileId = Session["fileId"].ToString();
        XmlNode node = myFiles.SelectSingleNode("/files//file[@id='" + fileId + "']");

        node.ParentNode.RemoveChild(node);
        myFiles.Save(Server.MapPath("myTrees/TempFiles.xml"));
        XmlDataSource2.Save();
        Repeater1.DataBind();
        disableDiv2.Visible  = false;
        deleteFalert.Visible = false;
    }
Exemplo n.º 3
0
        protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            //verificar se os campos estao todos preenchidos
            DateTime datavelha = DateTime.Now;
            string   script    = "<script language=\"javascript\">\n" + "alert (\"Preencha todos os campos\");\n" + "</script>";

            if (e.Values["nif"].ToString().Length == 0 || e.Values["fname"].ToString().Length == 0 || e.Values["lname"].ToString().Length == 0 || e.Values["pdate"].ToString().Length == 0)
            {
                ClientScript.RegisterStartupScript(script.GetType(), "Error", script);
                e.Cancel = true;
            }
            else
            {
                //verificar se o nif foi corretamente preenchido
                UInt32 n;
                if (UInt32.TryParse(e.Values["nif"].ToString(), out n) && e.Values["nif"].ToString().Length == 9)
                {
                    //verificar se a data e valida
                    DateTime d;
                    if (DateTime.TryParse(e.Values["pdate"].ToString(), out d))
                    {
                        XmlDocument xdoc = XmlDataSource2.GetXmlDocument();
                        //verificar se a propriedade selecionada ja possui dono
                        XmlElement propSelecionada = xdoc.SelectSingleNode("properties/property[@id='" + DropDownList1.SelectedValue + "']") as XmlElement;
                        XmlElement dono            = propSelecionada.SelectSingleNode("owner") as XmlElement;
                        if (dono == null)
                        {
                            dono = xdoc.CreateElement("owner");

                            XmlAttribute nif   = xdoc.CreateAttribute("nif");
                            XmlAttribute fname = xdoc.CreateAttribute("fname");
                            XmlAttribute lname = xdoc.CreateAttribute("lname");
                            XmlAttribute pdate = xdoc.CreateAttribute("pdate");

                            nif.Value   = e.Values["nif"].ToString();
                            fname.Value = e.Values["fname"].ToString();
                            lname.Value = e.Values["lname"].ToString();
                            pdate.Value = e.Values["pdate"].ToString();

                            dono.Attributes.Append(nif);
                            dono.Attributes.Append(fname);
                            dono.Attributes.Append(lname);
                            dono.Attributes.Append(pdate);

                            propSelecionada.AppendChild(dono);

                            XmlDataSource2.Save();
                            e.Cancel = true;

                            script = "<script language=\"javascript\">\n" + "alert (\"Criação de dono bem sucedida!\");\n" + "</script>";
                            ClientScript.RegisterStartupScript(script.GetType(), "Success", script);

                            Response.Redirect("Owners.aspx");
                        }
                        else
                        {
                            datavelha = Convert.ToDateTime(dono.GetAttribute("pdate").ToString());


                            if (datavelha < d)
                            {
                                dono.RemoveAllAttributes();
                                XmlAttribute nif   = xdoc.CreateAttribute("nif");
                                XmlAttribute fname = xdoc.CreateAttribute("fname");
                                XmlAttribute lname = xdoc.CreateAttribute("lname");
                                XmlAttribute pdate = xdoc.CreateAttribute("pdate");

                                nif.Value   = e.Values["nif"].ToString();
                                fname.Value = e.Values["fname"].ToString();
                                lname.Value = e.Values["lname"].ToString();
                                pdate.Value = e.Values["pdate"].ToString();

                                dono.Attributes.Append(nif);
                                dono.Attributes.Append(fname);
                                dono.Attributes.Append(lname);
                                dono.Attributes.Append(pdate);

                                propSelecionada.AppendChild(dono);
                                XmlDataSource2.Save();
                                e.Cancel = true;

                                script = "<script language=\"javascript\">\n" + "alert (\"Alteração de dono bem sucedida!\");\n" + "</script>";
                                ClientScript.RegisterStartupScript(script.GetType(), "Success", script);

                                Response.Redirect("propriedades.aspx");
                            }
                            else
                            {
                                script = "<script language=\"javascript\">\n" + "alert (\"a data de compra nao pode ser mais antiga que a do dono anterior\");\n" + "</script>";
                                ClientScript.RegisterStartupScript(script.GetType(), "Error", script);
                                e.Cancel = true;
                            }
                        }
                    }
                    else
                    {
                        script = "<script language=\"javascript\">\n" + "alert (\"a data não é válida\");\n" + "</script>";
                        ClientScript.RegisterStartupScript(script.GetType(), "Error", script);
                        e.Cancel = true;
                    }
                }
                else
                {
                    script = "<script language=\"javascript\">\n" + "alert (\"O nif nao foi bem preenchido\");\n" + "</script>";
                    ClientScript.RegisterStartupScript(script.GetType(), "Error", script);
                    e.Cancel = true;
                }
            }
        }
Exemplo n.º 4
0
    protected void uploadApprove_Click(object sender, EventArgs e)
    {
        XmlNode filesCounterNode = myFiles.SelectSingleNode("/files/filesCounter");
        int     newFileId        = Convert.ToInt16(filesCounterNode.InnerXml);

        newFileId++;
        filesCounterNode.InnerXml = newFileId.ToString();

        if (((RadioButtonList)FindControl("RadioButtonList1")).SelectedValue == "URL")
        {
            string urlTitleLabel = urlTitle.Text;
            string urlLinkLabel  = urlLink.Text;

            XmlElement NewLessonURLNode = myFiles.CreateElement("file");
            NewLessonURLNode.SetAttribute("id", filesCounterNode.InnerXml.ToString());

            XmlElement NewLessonURLNameNode = myFiles.CreateElement("fileName");
            NewLessonURLNameNode.InnerText = urlTitleLabel;
            NewLessonURLNode.AppendChild(NewLessonURLNameNode);

            XmlElement NewLessonURLFormatNode = myFiles.CreateElement("fileFormat");
            NewLessonURLFormatNode.InnerText = "url";
            NewLessonURLNode.AppendChild(NewLessonURLFormatNode);

            XmlElement NewLessonURLLinkNode = myFiles.CreateElement("fileLink");
            NewLessonURLLinkNode.InnerText = urlLinkLabel;
            NewLessonURLNode.AppendChild(NewLessonURLLinkNode);



            XmlNode LessonNode = myFiles.SelectSingleNode("/files");
            LessonNode.AppendChild(NewLessonURLNode);

            urlTitle.Text = "";
            urlLink.Text  = "";
            myFiles.Save(Server.MapPath("myTrees/TempFiles.xml"));
            XmlDataSource2.Save();
            Repeater1.DataBind();
        }
        else
        {
            string fileName      = FileUpload1.PostedFile.FileName;
            string endOfFileName = fileName.Substring(fileName.LastIndexOf("."));
            string myTime        = DateTime.Now.ToString("dd_MM_yy-HH_mm_ss");
            string newFileName   = fileName + "_" + myTime;
            FileUpload1.PostedFile.SaveAs(Server.MapPath("UploadedFiles") + "//" + newFileName);

            XmlElement NewLessonFileNode = myFiles.CreateElement("file");
            NewLessonFileNode.SetAttribute("id", filesCounterNode.InnerXml.ToString());

            XmlElement NewLessonFileNameNode = myFiles.CreateElement("fileName");
            NewLessonFileNameNode.InnerText = newFileName;
            NewLessonFileNode.AppendChild(NewLessonFileNameNode);

            XmlElement NewLessonFileFormatNode = myFiles.CreateElement("fileFormat");
            NewLessonFileFormatNode.InnerText = endOfFileName;
            NewLessonFileNode.AppendChild(NewLessonFileFormatNode);

            XmlNode LessonNode = myFiles.SelectSingleNode("/files");
            LessonNode.AppendChild(NewLessonFileNode);

            myFiles.Save(Server.MapPath("myTrees/TempFiles.xml"));
            XmlDataSource2.Save();
            Repeater1.DataBind();
        }
    }
Exemplo n.º 5
0
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string totalQuest = "";
        string theId      = "";
        string rowNum     = "";
        string buttonId   = "";
        string myTextBox  = "";

        // תחילה אנו מבררים מהו ה -אי די- של הפריט בעץ ה אקס אם אל
        if (e.CommandSource.GetType() == typeof(ImageButton))
        {
            ImageButton i = (ImageButton)e.CommandSource;
            theId      = i.Attributes["theItemId"];
            buttonId   = i.ID;
            myTextBox  = i.Attributes["myTB"];
            rowNum     = buttonId.Substring(buttonId.Length - 1);
            totalQuest = i.Attributes["theItemTotalQuest"];
            Session["gameIDSession"] = i.Attributes["theItemId"];
        }
        else
        {
            if (e.CommandSource.GetType() == typeof(Button))
            {
                Button i = (Button)e.CommandSource;
                theId      = i.Attributes["theItemId"];
                totalQuest = i.Attributes["theItemTotalQuest"];
                Session["gameIDSession"] = i.Attributes["theItemId"];
            }
            Session["CorrectAnswer"] = "0";
        }
        // אנו מושכים את האי די של הפריט באמצעות מאפיין לא שמור במערכת שהוספנו באופן ידני לכפתור-תמונה
        if (totalQuest == "0")
        {
            Session["editQuestNum"] = "0";
        }
        else
        {
            Session["editQuestNum"] = "1";
        }

        // עלינו לברר איזו פקודה צריכה להתבצע - הפקודה רשומה בכל כפתור
        switch (e.CommandName)
        {
        //אם נלחץ על כפתור מחיקה יקרא לפונקציה של מחיקה
        case "deleteRow":
            deleteRow();
            break;

        case "editName":
            if (Session["edit"] != null && Session["edit"].ToString() == "true")
            {
                Session["edit"] = "false";
                XmlNode GameNameNode = xmlRealDoc.SelectSingleNode("/tree/game[@code=" + theId + "]/gameName");
                Session["gameIDSession"] = "";
                foreach (GridViewRow row in GridView1.Rows)
                {
                    string counter = ((Label)row.FindControl("gameIDLbl")).Text;
                    if (counter == theId)
                    {
                        xmlRealDoc.SelectSingleNode("/tree/game[@code='" + theId + "']/gameName").InnerText = Server.UrlEncode(((TextBox)row.FindControl("gameNameEditTextBox")).Text);
                    }
                }
                XmlDataSource1.Save();
                GridView1.DataBind();
            }
            else
            {
                Session["edit"] = "true";
                GridView1.DataBind();
            }
            break;

        case "editTime":
            Button  time       = (Button)e.CommandSource;
            string  y          = time.ID;
            string  x          = y.Substring(y.Length - 2);
            string  gameTimeId = time.Attributes["theItemId"].ToString();
            XmlNode node       = xmlRealDoc.SelectSingleNode("/tree/game[@code='" + gameTimeId + "']");
            node.Attributes["timePerQes"].Value = x;
            XmlDataSource1.Save();
            Session["gameIDSession"] = "";
            GridView1.DataBind();
            break;

        //אם נלחץ על כפתור עריכה (העפרון) נעבור לדף עריכה
        case "editRow":
            Session["saved"] = false;
            XmlNode    FakeGameXml = xmlFakeDoc.SelectSingleNode("tree");
            XmlElement myNewGame   = xmlFakeDoc.CreateElement("game");
            //  myNewGame.SetAttribute("published", "false");
            // myNewGame.SetAttribute("timePerQes", "30");
            myNewGame.SetAttribute("totalQes", totalQuest);
            myNewGame.SetAttribute("code", theId);
            FakeGameXml.AppendChild(myNewGame);
            myNewGame.InnerXml = xmlRealDoc.SelectSingleNode("/tree/game[@code=" + theId + "]").InnerXml;
            XmlDataSource2.Save();
            Response.Redirect("EditGame.aspx");
            break;
        }
    }