Пример #1
0
 /// <summary>
 /// Carrega os itens do menu conforme perfil logado
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="serverMapPath"></param>
 /// <returns></returns>
 XmlDataSource GetMenuDataSource(string menu, string serverMapPath)
 {
     XmlDataSource objData = new XmlDataSource();
     objData.XPath = "siteMap/siteMapNode";
     switch (menu)
     {
         case "Administrador": //Caso seja o perfil Administrador carrega o perfil setado no xml
             objData.DataFile = serverMapPath + @"\App_Data\Administrador.sitemap";
             break;
         default:
             break;
     }
     objData.DataBind();
     return objData;
 }
Пример #2
0
		public static void datafile (Page p)
		{
			string originalxml = @"<?xml version=""1.0"" encoding=""utf-8""?><bookstore xmlns:bk=""urn:samples""><book genre=""novel"" publicationdate=""1999"" bk:ISBN=""0192100262""><title>Pride and Prejudice</title><author><first-name>Jane</first-name><last-name>Austen</last-name></author><price>24.95</price>""
			</book><book genre=""novel"" publicationdate=""1985"" bk:ISBN=""0771008139""><title>The Handmaid's Tale</title><author><first-name>Margaret</first-name><last-name>Atwood</last-name></author><price>29.95</price></book></bookstore>";

			XmlDataSource ds = new XmlDataSource ();
			p.Form.Controls.Add (ds);
			ds.DataFile = "~/XMLDataSourceTest.xml";
			ds.DataBind ();
			string derivedxml = ((XmlDocument) ds.GetXmlDocument ()).InnerXml;
			HtmlDiff.AssertAreEqual (originalxml, derivedxml, "Loading xml");
		}
Пример #3
0
        protected void HousesRpter_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            LinkButton lnkUpdate = (LinkButton)e.Item.FindControl("lnkUpdate");
            LinkButton lnkCancel = (LinkButton)e.Item.FindControl("lnkCancel");
            LinkButton lnkEdit = (LinkButton)e.Item.FindControl("lnkEdit");
            LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");

            #region Edit
            if (e.CommandName == "edit")
            {

                lnkCancel.Visible = true;
                lnkUpdate.Visible = true;
                lnkEdit.Visible = false;

                int houseId = int.Parse(e.CommandArgument.ToString());
                int doc = GetHomeDocID(houseId);

                object returningValue;
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    using (SqlCommand newcmd = new SqlCommand("SELECT theDoc FROM XMLDoc WHERE id=" + doc, con))
                    {
                        newcmd.CommandType = CommandType.Text;
                        con.Open();
                        returningValue = newcmd.ExecuteScalar();
                        con.Close();
                    }
                }

                HouseDoc.InnerXml = (string)returningValue;

                XmlDataSource homeDatasource = new XmlDataSource();
                homeDatasource.Data = HouseDoc.InnerXml;
                homeDatasource.EnableCaching = false;
                homeDatasource.DataBind();
                AddHomeForm.DataSourceID = null;
                AddHomeForm.DataSource = homeDatasource;

                AddHomeForm.ChangeMode(FormViewMode.Edit);

                AddHomeForm.DataBind();
                AddHomeForm.Visible = true;
            }
            #endregion

            #region Update
            if (e.CommandName == "update")
            {
                lnkCancel.Visible = false;
                lnkUpdate.Visible = false;
                lnkEdit.Visible = true;

                EditHouse edit = (EditHouse)AddHomeForm.FindControl("EditHouse1");
                string HouseName = ((TextBox)edit.FindControl("HouseNameTextBox")).Text;
                string HouseLat = ((TextBox)edit.FindControl("HouseLatTextBox")).Text;
                string HouseLong = ((TextBox)edit.FindControl("HouseLongTextBox")).Text;

                int houseId = int.Parse(e.CommandArgument.ToString());

                House house = new House();
                house.HouseID = houseId;
                house.HouseName = HouseName;
                house.HouseDescription = "House Description";

                int docID = UpdateHouse(house);

                XmlNode name = HouseDoc.SelectSingleNode("home/name");
                name.InnerText = HouseName;
                XmlNode longitude = HouseDoc.SelectSingleNode("home/longitude");
                longitude.InnerText = HouseLong;
                XmlNode latitude = HouseDoc.SelectSingleNode("home/latitude");
                latitude.InnerText = HouseLat;

                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand("UpdateHouseXML", con))
                    {

                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter userId = new SqlParameter("@Original_id", docID);
                        SqlParameter roleId = new SqlParameter("@thedoc", HouseDoc.InnerXml);
                        cmd.Parameters.Add(userId);
                        cmd.Parameters.Add(roleId);

                        con.Open();
                            cmd.ExecuteScalar();
                        con.Close();

                    }
                }
                SqlDataSource1.DataBind();
                HousesRpter.DataBind();
                AddHomeForm.Visible = false;
            }

            #endregion

            #region Cancel
            if (e.CommandName == "cancel")
            {
                lnkCancel.Visible = false;
                lnkUpdate.Visible = false;
                lnkEdit.Visible = true;
                AddHomeForm.Visible = false;
            }
            #endregion

            #region Delete
            if (e.CommandName == "delete")
            {
                int houseId = int.Parse(e.CommandArgument.ToString());

                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand("DeleteHouse", con))
                    {

                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter userId = new SqlParameter("@houseID", houseId);

                        cmd.Parameters.Add(userId);

                        con.Open();
                            cmd.ExecuteScalar();
                        con.Close();

                    }
                }

                SqlDataSource1.DataBind();
                HousesRpter.DataBind();
            }
            #endregion
        }
Пример #4
0
        protected void ListView1_PreRender(object sender, EventArgs e)
        {
            ListView listview = (ListView)sender;
            ListViewItem item = (ListViewItem)listview.Parent;

            HtmlControl htmlDivControl = (HtmlControl)item.FindControl("CheckBox1");

            HiddenField hidden = (HiddenField)item.FindControl("RoomName");
            string str = "//rooms/room[name/text()='"+hidden.Value+"']/devices/device";
            XmlDataSource src = new XmlDataSource();
            src.Data = HouseDoc.InnerXml;
            src.TransformFile = "~/XML/StateTransform.xslt";
            src.XPath = str;
            src.DataBind();
            src.EnableCaching = false;
            src.ID = "srcDevices";
            listview.DataSource = src;
            listview.DataBind();
        }
Пример #5
0
        private XmlDataSource GetXmlDataSource(DataTable topParents, DataTable childrenAndParents)
        {
            XmlDocument doc = new XmlDocument();

            XmlNode rootNode = doc.CreateElement("root");
            doc.AppendChild(rootNode);

            foreach (DataRow drParent in topParents.Rows)
            {
                XmlNode topParent = doc.CreateElement("person");

                XmlAttribute ID = doc.CreateAttribute("ID");
                ID.Value = drParent["ParentID"].ToString();
                topParent.Attributes.Append(ID);

                XmlAttribute Name = doc.CreateAttribute("name");
                Name.Value = drParent["Name"].ToString();
                topParent.Attributes.Append(Name);

                rootNode.AppendChild(topParent);
            }

            int inc = childrenAndParents.Rows.Count;

            for (int i = 0; i < inc; i++)
            {
                foreach (DataRow drChild in childrenAndParents.Rows)
                {
                    string parentID = drChild["ParentID"].ToString();
                    string childID = drChild["ChildID"].ToString();

                    XmlNodeList nl = doc.GetElementsByTagName("person");

                    foreach (XmlNode node in nl)
                    {
                        if (node.Attributes["ID"].Value == parentID)
                        {
                            XmlNode child = doc.CreateElement("person");

                            XmlAttribute ID = doc.CreateAttribute("ID");
                            ID.Value = childID;
                            child.Attributes.Append(ID);

                            XmlAttribute Name = doc.CreateAttribute("name");
                            Name.Value = "Fake Name " + childID;
                            child.Attributes.Append(Name);

                            node.AppendChild(child);
                        }
                    }
                }

                inc--;
            }

            XmlDataSource xmlDataSource = new XmlDataSource();
            xmlDataSource.ID = "dsTreeView";
            xmlDataSource.Data = doc.OuterXml;
            xmlDataSource.XPath = "root/parent";
            xmlDataSource.DataBind();

            return xmlDataSource;
        }