1 / 22

Aplikacje sieciowe

Aplikacje sieciowe. Warstwy aplikacji sieciowych. Architektura warstwowa. Warstwa prezentacji. Warstwa logiki (aplikacji). Warstwa danych. Warstwa prezentacji. Strona aspx Arkusze stylów css Kontrolki wizualne. Warstwa logiki (aplikacji). Własne obiekty Obiekty z bibliotek .NET

kobe
Download Presentation

Aplikacje sieciowe

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Aplikacje sieciowe Warstwy aplikacji sieciowych

  2. Architektura warstwowa Warstwa prezentacji Warstwa logiki (aplikacji) Warstwa danych

  3. Warstwa prezentacji • Strona aspx • Arkusze stylów css • Kontrolki wizualne

  4. Warstwa logiki (aplikacji) • Własne obiekty • Obiekty z bibliotek .NET • Obiekty komunikacji ze źródłem danych publicpartialclassKontakt : System.Web.UI.Page { protectedvoid Page_Load(object sender, EventArgs e) { } protectedvoid SendMailBtn_Click(object sender, EventArgs e) { MailMessage mail = newMailMessage( MailFromInp.Text,ConfigurationManager.AppSettings["contactPersonMailAdress"] , MailSubjectInp.Text, MailBodyInp.Text ); SmtpClient smpt = newSmtpClient(); smpt.Send(mail); } }

  5. Warstwa danych

  6. Źródła danych • Bazy danychAccess, MS Sql, inne • Pliki XML- formaty typu SiteMap- inne formaty XML • Obiekty (tablice, kolekcje itp..) • Pliki tekstowe i inne

  7. Podstawowe obiekty Bazodanowe • SqlCommand • SqlConnection • ConnectionString

  8. Warstwowy schemat pracy ze źródłem danych <TeacherList> <teachername="Paweł Fałat" certificates="MCP, MCAD"/> <teachername="Kornel Warwas" certificates="MCP, MCAD"/> <teachername="Szymon Tegler" certificates="MCP, MCAD"/> <teachername="Andrzej Polański" certificates="MCP, MCAD"/> <teachername="Tomasz Gancarczyk" certificates="MCP, MCSE"/> </TeacherList>

  9. Obiekty typu DataSource

  10. Tworzenie Menu: Źródło dokument typu SiteMap <siteMapxmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNodeurl="Default.aspx" title="Home" description=""> <siteMapNodeurl="~/ConferenceCommity.aspx" title="Conference Commity" description="" /> <siteMapNodeurl="~/ScientificCommity.aspx" title="Scientific Commity" description="" /> <siteMapNodeurl="~/Null3.aspx" title="Comunicates" description="" > <siteMapNodeurl="~/Null3a.aspx" title="Comunicate nr 1" description="" /> <siteMapNodeurl="~/Null3b.aspx" title="Comunicate nr 2" description="" /> <siteMapNodeurl="~/Null3c.aspx" title="Comunicate nr 2" description="" /> </siteMapNode> ... </siteMap>

  11. Źródło danych: dokument XML <TeacherList> <teachername="Paweł Fałat" certificates="MCP, MCAD"/> <teachername="Kornel Warwas" certificates="MCP, MCAD"/> <teachername="Szymon Tegler" certificates="MCP, MCAD"/> <teachername="Andrzej Polański" certificates="MCP, MCAD"/> <teachername="Tomasz Gancarczyk" certificates="MCP, MCSE"/> </TeacherList>

  12. SqlDataSource

  13. SqlDataSource: funkcje operujące na danych • Select() • Update() • Insert() • Delete() Wykorzystują przygotowane obiekty typu SqlCommand połączone z kolekcjami parametrów zapytania: • SelectQuery • InsertQuery • UpdateQuery • DeleteQuery

  14. SqlCommand

  15. SqlCommand przykład kodu using System.Data; using System.Data.SqlClient; publicstaticString GetUserNameForReview(String ReviewID) { SqlConnection connection = newSqlConnection(ConfigurationManager.ConnectionStrings["ConfernceDBConnectionString"].ConnectionString); SqlCommand getUserNameCommand = newSqlCommand(); getUserNameCommand.CommandType = CommandType.Text;//CommandType.StoredProcedure// TableDirect getUserNameCommand.Parameters.Add("@ReviewID", SqlDbType.NVarChar); getUserNameCommand.Connection = connection; getUserNameCommand.Parameters["@ReviewID"].Value = ReviewID; getUserNameCommand.CommandText = "SELECT aspnet_Users.UserName" + " FROM Review INNER JOIN aspnet_Users" + " ON Review.ReviewerID = aspnet_Users.UserId" + " WHERE (Review.ReviewID = @ReviewID)"; connection.Open(); //getUserNameCommand.ExecuteXmlReader(); ExecuteReader(); ExecuteNonQuery() ; string UserName = getUserNameCommand.ExecuteScalar().ToString(); connection.Close(); if (UserName == null) return"NullUser"; return UserName; }

  16. DataSet • Może odzwierciedlić strukturę bazy danych z tabelami i związkami między nimi. Umożliwia wykorzystanie i modyfikację tej struktury • Typed DataSetNa podstawie definicji tabel tworzy się plik xsd zawierający strukturę obiektów. Na podstawie tego pliku generowana jest klasa(y) wykorzystywane w trakcie tworzenia programu- Wsparcie dla Intelisense- Sprawdzanie składni w trakcie kompilacji • Untyped DatasetDo dynamicznego ładowania nie zdefiniowanej wstępnie struktury tabel

  17. DataSet Designer

  18. DataSet Plik xsd <?xmlversion="1.0" encoding="utf-8"?> <xs:schemaid="UserListDataSet" targetNamespace="http://tempuri.org/UserListDataSet.xsd" xmlns:mstns="http://tempuri.org/UserListDataSet.xsd" xmlns="http://tempuri.org/UserListDataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:annotation> <xs:appinfosource="urn:schemas-microsoft-com:xml-msdatasource"> <DataSourceDefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource"> <Connections> <ConnectionAppSettingsObjectName="Web.config" AppSettingsPropertyName="ConfernceDBConnectionString" ConnectionStringObject="" IsAppSettingsProperty="true" Modifier="Assembly" Name="ConfernceDBConnectionString (Web.config)" ParameterPrefix="@" PropertyReference="AppConfig.System.Configuration.ConfigurationManager.0.ConnectionStrings.ConfernceDBConnectionString.ConnectionString" Provider="System.Data.SqlClient" /> </Connections> <Tables> <TableAdapterBaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="aspnet_UsersTableAdapter" GeneratorDataComponentClassName="aspnet_UsersTableAdapter" Name="aspnet_Users" UserDataComponentName="aspnet_UsersTableAdapter"> <MainSource> <DbSourceConnectionRef="ConfernceDBConnectionString (Web.config)" DbObjectName="dbo.aspnet_Users" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="true" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="false" UserGetMethodName="GetData" UserSourceName="Fill"> <DeleteCommand> <DbCommandCommandType="Text" ModifiedByUser="false"> <CommandText>DELETE FROM [dbo].[aspnet_Users] WHERE (([ApplicationId] = @Original_ApplicationId) AND ([LoweredUserName] = @Original_LoweredUserName))</CommandText> <Parameters> <ParameterAllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Guid" Direction="Input" ParameterName="@Original_ApplicationId" Precision="0" ProviderType="UniqueIdentifier" Scale="0" Size="0" SourceColumn="ApplicationId" SourceColumnNullMapping="false" SourceVersion="Original" /> <ParameterAllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Original_LoweredUserName" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="LoweredUserName" SourceColumnNullMapping="false" SourceVersion="Original" /> </Parameters> </DbCommand> </DeleteCommand> .....

  19. DataSet Przykład kodu (źródło: msdn) // Assumes a valid SqlConnection object named connection. SqlDataAdapter customerAdapter = new SqlDataAdapter( "SELECT CustomerID, CompanyName, Phone FROM Customers", connection); SqlDataAdapter orderAdapter = new SqlDataAdapter( "SELECT OrderID, CustomerID, EmployeeID, OrderAdapter FROM Orders", connection); // Populate a strongly typed DataSet. connection.Open(); CustomerDataSet customers = new CustomerDataSet(); customerAdapter.Fill(customers, "Customers"); orderAdapter.Fill(customers, "Orders"); connection.Close(); // Add a strongly typed event. customers.Customers.CustomerChanged += new CustomerDataSet.CustomerChangeEventHandler(OnCustomerChanged); // Add a strongly typed DataRow. CustomerDataSet.Customer newCustomer = customers.Customers.NewCustomeromer(); newCustomer.CustomerID = "NEW01"; newCustomer.CompanyName = "My New Company"; customers.Customers.AddCustomer(newCustomer);

  20. LINQ Language-Integrated Query static void Main() { // The Three Parts of a LINQ Query: // 1. Data source. int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; // 2. Query creation. // numQuery is an IEnumerable<int> var numQuery = from num in numbers where (num % 2) == 0 select num; // 3. Query execution. foreach (int num in numQuery) { Console.Write("{0,1} ", num); } } Źródło MSDN

  21. LINQ to SQL • // Northwnd inherits from System.Data.Linq.DataContext. • Northwnd nw = new Northwnd(@"northwnd.mdf"); • var companyNameQuery = • from cust in nw.Customers • where cust.City == "London" • select cust.CompanyName; • foreach (var customer in companyNameQuery) • { • Console.WriteLine(customer); • } Źródło MSDN

  22. LINQ to XML XElement srcTree = new XElement("Root", new XElement("Element1", 1), new XElement("Element2", 2), new XElement("Element3", 3), new XElement("Element4", 4), new XElement("Element5", 5) ); XElement xmlTree = new XElement("Root", new XElement("Child1", 1), new XElement("Child2", 2), new XElement("Child3", 3), new XElement("Child4", 4), new XElement("Child5", 5) ); xmlTree.Add(new XElement("NewChild", "new content")); xmlTree.Add( from el in srcTree.Elements() where (int)el > 3 select el ); <Root> <Child1>1</Child1> <Child2>2</Child2> <Child3>3</Child3> <Child4>4</Child4> <Child5>5</Child5> <NewChild>new content</NewChild> <Element4>4</Element4> <Element5>5</Element5> </Root> Źródło MSDN

More Related