Building Data-Centric Smart Client Applications Rajiv Sodhi Microsoft India
Agenda Introduction To Smart Clients Performing Connected Operations Performing Client-Side Operations Creating an Offline Application
Smart clients are easily deployed and managed client applications that provide an adaptive and interactive experience by leveraging local resources and intelligently connecting to distributed data sources. Web Services & Offline/Online support Device Adaptability Tough to Deploy Heavy Footprint DLL Hell Network Dependency Poor User Experience Rich UI Complex To Develop Rich User Experience Developer Productivity Responsive Broad Reach Easy Change Management Ease of Deployment
Microsoft Smart Client Platforms Mobile Field Smart Client Front-end to Enterprise LOB Systems Web site Smart Client Experiences Office System 2003Windows Mobile Windows Forms Version 1.1 Version 2.0 CurrentGeneration NextGeneration Version 1.0 Version 1.1 “Whidbey” Integrating Office XML with Enterprise Data E-Government Smart Client Front-end to Enterprise LOB Systems Web site Smart Client Experiences Mobile Field Web site Smart Client Experiences
Mobile Field Smart Client Front-end to Enterprise LOB Systems Web site Smart Client Experiences Windows Forms Version 1.1 Version 2.0 CurrentGeneration NextGeneration “Whidbey” Radically simplified application deployment ClickOnce deployment, update, rollback Visually Appealing UI New Data Controls Office Look and Feel Developer productivity Simplify working with data Fewer lines of code Few clicks.NET Framework distribution 120 million deployments Preinstalled on 60% of new machines and growing Included on SP2 CD Consumer 55% installed by end of ’04 75% installed by end of ’05 Enterprise 50% installed by end of ’04 68% installed by end of ‘05 Office System 2003Windows Mobile Version 1.0 Version 2.0 Integrating Office XML with Enterprise Data E-Government Smart Client Front-end to Enterprise LOB Systems Web site Smart Client Experiences Mobile Field Web site Smart Client Experiences Microsoft Smart Client Platforms
Office System 2003 Version 1.0 Version 2.0 Integrating Office XML with Enterprise Data E-Government Smart Client Front-end to Enterprise LOB Systems Web site Smart Client Experiences Connect live business data to your documents & access them off-line Increase velocity and accuracy of decision making Increase worker productivity Reduce error caused by data re-entry & copy/paste Leverage existing Office experience of end users Reach 400+ million practiced Office users Eliminate training and ramp up time on new applications Reduce new application burn-in errors Leverage rich and robust Office functionality High developer productivity = reduced time to develop Greatly improved maintainability & deployment options Optimize use of PC & central resources Mobile Field Smart Client Front-end to Enterprise LOB Systems Web site Smart Client Experiences Windows Forms Version 1.1 Version 2.0 CurrentGeneration NextGeneration “Whidbey” Windows Mobile Mobile Field Web site Smart Client Experiences Microsoft Smart Client Platforms
Office System 2003 Version 1.0 Version 2.0 Integrating Office XML with Enterprise Data E-Government Smart Client Front-end to Enterprise LOB Systems Web site Smart Client Experiences Mobile Field Smart Client Front-end to Enterprise LOB Systems Web site Smart Client Experiences Windows Forms Version 1.1 Version 2.0 CurrentGeneration NextGeneration “Whidbey” Windows Mobile Mobile Field Instant access to data anywhere, anytime Form factor and instant-on more appropriate for most field work Access existing Web services in SOAs Leverage.NET development skills and code on devices with.NET Compact Framework Web site Smart Client Experiences Microsoft Smart Client Platforms
Agenda Introduction To Smart Clients Performing Connected Operations Performing Client-Side Operations Creating an Offline Application
Performing Connected Operations Connection Class Represents a connection to a database SqlConnection, OracleConnection, etc. Requires a connection string Ex: “server=(local);database=Northwind;integrated security=true” Common methods Open Creates a connection to the database Close Closes the connection to the database BeginTransaction Starts a transaction and returns a Transaction object
Performing Connected Operations Command Executes SQL statements in the database CommandText DML, DDL, and DCL Contains a collection of parameters Common methods ExecuteReader Executes a Select statement and returns a DataReader ExecuteNonQuery Executes SQL statement, except Select Returns number of rows affected ExecuteScalar Executes a Select statement and returns a single value
Performing Connected Operations DataReader Server-Side, forward-only, read-only cursor Contains a collection of columns Ex: dr[“CustomerID”].ToString(); Common methods Read Advances to the next row Returns True if row exists Close Closes the DataReader and releases rowset GetX Returns a specific data type for the column value GetString, GetInt32, GetDateTime, etc.
Performing Connected Operations Populating an SqlDataReader using System.Data.SqlClient … SqlCommand cmd = new SqlCommand("SELECT * FROM Customers,cn); cn.Open(); SqlDataReader dr = cmd.ExecuteReader( CommandBehavior.CloseConnection); if(dr.Read()) { txtCustomerID.Text = dr["CustomerID"].ToString(); txtCompanyName.Text = dr["CompanyName"].ToString(); txtContactName.Text = dr["ContactName"].ToString(); } dr.Close();
Performing Connected Operations Executing an SqlCommand using System.Data.SqlClient … SqlConnection cn = new SqlConnection(“server=localhost;database=Northwind;integrated security=yes”); SqlCommand cmdDeleteProduct = new SqlCommand("DELETE FROM Products WHERE ProductID cmdDeleteProduct.Parameters.Add(new System.Data.SqlDbType.Int, 4)); = ProductID; cn.Open(); cmdDeleteProduct.ExecuteNonQuery(); cn.Close();
Performing Database Operations Directly
Agenda Introduction To Smart Clients Performing Connected Operations Performing Client-Side Operations Creating an Offline Application
Performing Client-Side Operations DataSet Set of DataTables and DataRelations Tightly integrated with XML Population Add DataTables Load XML Common Methods WriteXML/ReadXML WriteXMLSchema/ReadXMLSchema HasChanges GetChanges, AcceptChanges and RejectChanges Merge
Performing Client-Side Operations DataAdapter Bridge between a database and a DataTable Represents a set of Command objects SelectCommand, InsertCommand, UpdateCommand and DeleteCommand Common methods Fill Executes SelectCommand and populates DataTable Update Executes appropriate Command for each changed row Open and close connection if necessary
Performing Client-Side Operations Populating a DataSet using System.Data; using System.Data.SqlClient; … SqlConnection cn = new SqlConnection(“server=localhost;database=Northwind;inte grated security=yes”); daOrderDetails = new SqlDataAdapter("SELECT OrderID, ProductID, UnitPrice, Quantity, Discount FROM [Order Details]",cn); daOrderDetails.MissingSchemaAction = MissingSchemaAction.AddWithKey; DataSet dsNorthwind = new DataSet(); daOrderDetails.Fill(dsNorthwind, “Order Details”);
Performing Client-Side Operations Updating the Database DataRow tracks changes RowState property Row version GetChanges DataSet/DataTable Returns DataSet/DataTable of changed rows
Performing Client-Side Operations Updating the Database DataAdapter.Update Updates the database Executes appropriate command DataSet.Merge Merges contents into DataSet DataSet, DataTable or DataRow Matches data on primary key AcceptChanges Sets original value equal to current value Sets RowState property to DataRowState.Unchanged
Performing Client-Side Operations Updating the Database … DataTable dtChanges; dtChanges = ds.Tables["Employees"].GetChanges(DataRowState.Added); if(dtChanges != null) { daEmployees.Update(dtChanges); ds.Merge(dtChanges); } dtChanges = ds.Tables[“Orders"].GetChanges(DataRowState.Added); if(dtChanges != null) { daOrders.Update(dtChanges); ds.Merge(dtChanges); } … ds.AcceptChanges();
Performing Client- Side Database Operations
Agenda Introduction To Smart Clients Performing Connected Operations Performing Client-Side Operations Creating an Offline Application
Creating an Offline Application Persisting a DataSet Populate DataSet DataAdapter.Fill WriteXml Can write data, schema, and changes Output determined by XmlWriteMode Use instead of DataAdapter.Update XmlWriteMode.DiffGram XML format Original and values of DataSet
Creating an Offline Application DiffGram Current Value … ALFKI T00:00: : T00:00: : T00:00: : …
Creating an Offline Application DiffGram Original Value … ALFKI T00:00: : T00:00: :
Creating an Offline Application Restoring a DataSet ReadXml Can read data, schema, and changes Input determined by XmlReadMode Use instead of DataAdapter.Fill XmlReadMode.DiffGram Reads DiffGram Adds current and original values to DataSet Update the database DataAdapter.Update
Creating an Offline Application
© 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY. Content created by 3 Leaf Solutions