コード例 #1
0
    protected void deleteRow()
    {
        //הסרת ענף של משחק קיים באמצעות זיהוי האיי דיי שניתן לו על ידי לחיצה עליו מתוך הטבלה
        //שמירה ועדכון לתוך העץ ולגריד ויו
        //במחיקה לא נוגעים באיי די קאונטר כדי שלא ייוצר כפילות
        string GameID    = Session["gameIDSession"].ToString();
        string qustionid = ViewState["quastionIDviewstate"].ToString();

        //לקיחת הקובץ
        XmlDocument myDoc = new XmlDocument();

        myDoc.Load(Server.MapPath("/tree/game.xml"));

        XmlNode node = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[@id=" + qustionid + "]");

        //פקודת המחיקה
        node.ParentNode.RemoveChild(node);


        ViewState["quastionIDviewstate"] = "1";

        int qcount = myDoc.SelectNodes("/RootTree/game[@GameCode=" + GameID + "]//question").Count;

        for (int q = 1; q <= qcount; q++)
        {
            XmlNode thisq = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[" + q + "]");
            thisq.Attributes["id"].InnerText = q.ToString();
        }
        //שמירה
        myDoc.Save(Server.MapPath("/tree/game.xml"));
        GridView1edit.DataBind();
        refreshrow();
    }
コード例 #2
0
    public void newq()
    {
        string      GameID = Session["gameIDSession"].ToString();
        XmlDocument myDoc  = new XmlDocument();

        myDoc.Load(Server.MapPath("/tree/game.xml"));
        int qcount = (myDoc.SelectNodes("/RootTree/game[@GameCode=" + GameID + "]//question").Count) + 1;

        ViewState["quastionIDviewstate"] = qcount;
        cleaneow();
        Table1.DataBind();
        GridView1edit.DataBind();
    }
コード例 #3
0
    protected void Button3_Click(object sender, EventArgs e)
    {
        string      GameID    = Session["gameIDSession"].ToString();
        string      qustionid = ViewState["quastionIDviewstate"].ToString();
        XmlDocument myDoc     = new XmlDocument();

        myDoc.Load(Server.MapPath("/tree/game.xml"));

        if (Convert.ToInt32(qustionid) > myDoc.SelectNodes("/RootTree/game[@GameCode=" + GameID + "]//question").Count)
        {
            XmlElement myNewaquestionNode = myDoc.CreateElement("question");
            myNewaquestionNode.SetAttribute("id", qustionid);

            XmlElement myNewaquestionTextNode = myDoc.CreateElement("questionText");
            myNewaquestionNode.AppendChild(myNewaquestionTextNode);

            XmlElement myNewimgNode = myDoc.CreateElement("img");
            myNewaquestionNode.AppendChild(myNewimgNode);

            XmlElement myNewanswerNode = myDoc.CreateElement("answers");
            myNewaquestionNode.AppendChild(myNewanswerNode);

            XmlNode myqthis = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]/questions");
            XmlNode Firstq  = myDoc.SelectNodes("/RootTree/game[@GameCode=" + GameID + "]/questions/question").Item(0);
            myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]/questions").InsertBefore(myNewaquestionNode, Firstq);
        }

        XmlNode titleq = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[@id=" + qustionid + "]/questionText");

        titleq.InnerXml = Server.UrlEncode(((TextBox)FindControl("mainqtb")).Text);

        XmlNode titlimg = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[@id=" + qustionid + "]/img");

        if ((((FileUpload)FindControl("FileUpload1")).PostedFile.ContentType.Contains("image")) || (((ImageButton)FindControl("ImageforUpload1")).ImageUrl.Contains("thisuplod") && (((HiddenField)FindControl("hdnfldVariable1")).Value != "false")))
        {
            if (((FileUpload)FindControl("FileUpload1")).PostedFile.ContentType.Contains("image"))
            {
                string fileType = ((FileUpload)FindControl("FileUpload1")).PostedFile.ContentType;

                if (fileType.Contains("image")) //בדיקה האם הקובץ שהוכנס הוא תמונה
                {
                    // הנתיב המלא של הקובץ עם שמו האמיתי של הקובץ
                    string fileName = ((FileUpload)FindControl("FileUpload1")).PostedFile.FileName;
                    // הסיומת של הקובץ
                    string endOfFileName = fileName.Substring(fileName.LastIndexOf("."));
                    //לקיחת הזמן האמיתי למניעת כפילות בתמונות
                    string myTime  = DateTime.Now.ToString("dd_MM_yy-HH_mm_ss");
                    string mynamee = "thisuplod";
                    // חיבור השם החדש עם הסיומת של הקובץ
                    string imageNewName = mynamee + myTime + 1 + endOfFileName;
                    //שמירה של הקובץ לספרייה בשם החדש שלו
                    // Bitmap המרת הקובץ שיתקבל למשתנה מסוג
                    System.Drawing.Bitmap bmpPostedImage = new System.Drawing.Bitmap(((FileUpload)FindControl("FileUpload1")).PostedFile.InputStream);


                    //קריאה לפונקציה המקטינה את התמונה
                    //אנו שולחים לה את התמונה שלנו בגירסאת הביטמאפ ואת האורך והרוחב שאנו רוצים לתמונה החדשה
                    System.Drawing.Image objImage = FixedSize(bmpPostedImage, 150, 150);

                    //שמירה של הקובץ לספרייה בשם החדש שלו
                    objImage.Save(Server.MapPath(imagesLibPath) + imageNewName);

                    //הצגה של הקובץ החדש מהספרייה
                    ((ImageButton)FindControl("ImageforUpload1")).ImageUrl = imagesLibPath + imageNewName;

                    //XmlNode pic = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[@id=" + qustionid + "]//answer[" + optionnum + "]");
                    titlimg.InnerXml = "/uploadedFiles" + "/" + imageNewName;
                }
            }

            if (((ImageButton)FindControl("ImageforUpload1")).ImageUrl.Contains("thisuplod"))
            {
                if (((HiddenField)FindControl("hdnfldVariable1")).Value != "false")
                {
                    titlimg.InnerXml = ((ImageButton)FindControl("ImageforUpload1")).ImageUrl;
                }
            }
        }
        else
        {
            titlimg.InnerXml = "";
        }



        XmlNode myqqthis = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[@id=" + qustionid + "]");
        XmlNode node     = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[@id=" + qustionid + "]/answers");

        node.ParentNode.RemoveChild(node);
        XmlElement myNewanswersNode = myDoc.CreateElement("answers");

        myqqthis.AppendChild(myNewanswersNode);

        int optionnum = 1;

        for (int l = 1; l <= 7; l++)
        {
            string d  = Convert.ToString(l);
            string dd = Convert.ToString(l + 1);
            if ((((TextBox)FindControl("ATextBox" + d)).Text != "") || (((FileUpload)FindControl("FileUpload" + dd)).PostedFile.ContentType.Contains("image")) || (((ImageButton)FindControl("ImageforUpload" + dd)).ImageUrl.Contains("thisuplod") && (((HiddenField)FindControl("hdnfldVariable" + dd)).Value != "false")))
            {
                XmlElement myNewanswerNode = myDoc.CreateElement("answer");
                myNewanswerNode.SetAttribute("feedback", Convert.ToString(((CheckBox)FindControl("ACheckBox" + d)).Checked));
                myNewanswerNode.SetAttribute("AnsType", "text");


                if (((TextBox)FindControl("ATextBox" + d)).Text != "")
                {
                    myNewanswerNode.InnerXml = Server.UrlEncode(((TextBox)FindControl("ATextBox" + d)).Text);
                    myNewanswerNode.Attributes["AnsType"].InnerText = "text";
                }

                if (((FileUpload)FindControl("FileUpload" + dd)).PostedFile.ContentType.Contains("image"))
                {
                    string fileType = ((FileUpload)FindControl("FileUpload" + dd)).PostedFile.ContentType;

                    if (fileType.Contains("image")) //בדיקה האם הקובץ שהוכנס הוא תמונה
                    {
                        // הנתיב המלא של הקובץ עם שמו האמיתי של הקובץ
                        string fileName = ((FileUpload)FindControl("FileUpload" + dd)).PostedFile.FileName;
                        // הסיומת של הקובץ
                        string endOfFileName = fileName.Substring(fileName.LastIndexOf("."));
                        //לקיחת הזמן האמיתי למניעת כפילות בתמונות
                        string myTime  = DateTime.Now.ToString("dd_MM_yy-HH_mm_ss");
                        string mynamee = "thisuplod";
                        // חיבור השם החדש עם הסיומת של הקובץ
                        string imageNewName = mynamee + myTime + dd + endOfFileName;

                        // Bitmap המרת הקובץ שיתקבל למשתנה מסוג
                        System.Drawing.Bitmap bmpPostedImage = new System.Drawing.Bitmap(((FileUpload)FindControl("FileUpload" + dd)).PostedFile.InputStream);


                        //קריאה לפונקציה המקטינה את התמונה
                        //אנו שולחים לה את התמונה שלנו בגירסאת הביטמאפ ואת האורך והרוחב שאנו רוצים לתמונה החדשה
                        System.Drawing.Image objImage = FixedSize(bmpPostedImage, 230, 230);

                        //שמירה של הקובץ לספרייה בשם החדש שלו
                        objImage.Save(Server.MapPath(imagesLibPath) + imageNewName);

                        //הצגה של הקובץ החדש מהספרייה
                        ((ImageButton)FindControl("ImageforUpload" + dd)).ImageUrl = imagesLibPath + imageNewName;

                        //XmlNode pic = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[@id=" + qustionid + "]//answer[" + optionnum + "]");
                        myNewanswerNode.InnerXml = "/uploadedFiles" + "/" + imageNewName;
                        myNewanswerNode.Attributes["AnsType"].InnerText = "picture";
                        ((TextBox)FindControl("ATextBox" + d)).Enabled  = false;
                    }
                }

                if (((ImageButton)FindControl("ImageforUpload" + dd)).ImageUrl.Contains("thisuplod"))
                {
                    if (((HiddenField)FindControl("hdnfldVariable" + dd)).Value != "false")
                    {
                        myNewanswerNode.InnerXml = ((ImageButton)FindControl("ImageforUpload" + dd)).ImageUrl;
                        myNewanswerNode.Attributes["AnsType"].InnerText = "picture";
                        ((TextBox)FindControl("ATextBox" + d)).Enabled  = false;
                    }
                }


                XmlNode myqthis = myDoc.SelectSingleNode("/RootTree/game[@GameCode=" + GameID + "]//question[@id=" + qustionid + "]/answers");
                myqthis.AppendChild(myNewanswerNode);
                optionnum++;
            }
        }

        myDoc.Save(Server.MapPath("/tree/game.xml"));
        cleaneow();
        GridView1edit.DataBind();
        Table1.DataBind();
        refreshrow();
        newq();
    }