Top Banner

of 29

MS Press - NET Compact Framework Templates

Apr 03, 2018

Download

Documents

ricardoar_ve
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/29/2019 MS Press - NET Compact Framework Templates

    1/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 1/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    How to use the

    .Net Compact Framework templates

    IntroductionIf you are writing applications for Windows CE, you may know that Microsoft provides a SQLServer version for that specific OS:

    SQL Server CE 2.0 (http://www.microsoft.com/sql/CE/default.asp)

    Microsoft is also releasing the Smart Device Extensions (currently in beta) which is a packagecontaining:

    Microsoft .NET Compact Framework Extensions to Visual Studio .NET

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnroad/html/road10242001.asp

    If you need to write a database aware application, you need to use both.

    Once you have created a database on your PPC, you need to write ADO .NET code to accessyour various tables. Specifically, you are going to use the System.Data.SqlServerCenamespace in order to achieve that. You can also access a SQL Server database on a remoteserver using the System.Data.SqlClient namespace.

    This group of templates will generate that code for you. Furthermore, it will also generateDataGrids, ListViews, ListBoxes and ComboBoxes controls that are directly mapped to yourspecific SQL queries.

    Since OlyMars needs a SQL Server 2000 database to run on, here is how to set up yourconfiguration to use efficiently this group of templates.

    You need to create the exact same database, both on your PC and your PPC. One easy way todo this is to create first your database on your PC (SQL Server 2000 database) then setup areplication mechanism so that the PPC version of the database will be created automatically foryou.

    You can also create the SqlCe database by running your own SQL Code.

    We are going to use a database sample in this document in order to illustrate how the providedtemplates work.

  • 7/29/2019 MS Press - NET Compact Framework Templates

    2/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 2/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Databases installation

    SQL Server 2000 database

    The name of the PC database will be DB_PC. The database schema for DB_PC is:

    Create the DB_PC database on your SQL Server machine. You will find next the sql script torun in order to create those tables in the database:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    3/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 3/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Use DB_PCGO

    CREATE TABLE [dbo].[tblCategory] ([Cat_GuidID] uniqueidentifier ROWGUIDCOL NOT NULL ,[Cat_StrName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL

    ) ON [PRIMARY]GO

    ALTER TABLE [dbo].[tblCategory] WITH NOCHECK ADDCONSTRAINT [PK_tblCategory] PRIMARY KEY CLUSTERED ([Cat_GuidID]) ON [PRIMARY],CONSTRAINT [DF_tblCategory_Cat_GuidID] DEFAULT (newid()) FOR [Cat_GuidID],CONSTRAINT [IX_tblCategory] UNIQUE NONCLUSTERED ([Cat_StrName]) ON [PRIMARY]

    GO

    CREATE TABLE [dbo].[tblProduct] ([Pro_GuidID] uniqueidentifier ROWGUIDCOL NOT NULL ,[Pro_StrName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,[Pro_CurPrice] [money] NOT NULL ,[Pro_GuidCategoryID] [uniqueidentifier] NOT NULL

    ) ON [PRIMARY]GO

    ALTER TABLE [dbo].[tblProduct] WITH NOCHECK ADDCONSTRAINT [PK_tblProduct] PRIMARY KEY CLUSTERED ([Pro_GuidID]) ON [PRIMARY],CONSTRAINT [DF_tblProduct_Pro_GuidID] DEFAULT (newid()) FOR [Pro_GuidID],CONSTRAINT [IX_tblProduct] UNIQUE NONCLUSTERED ([Pro_StrName],[Pro_GuidCategoryID]) ON

    [PRIMARY]

    ALTER TABLE [dbo].[tblProduct] ADDCONSTRAINT [FK_tblProduct_tblCategory] FOREIGN KEY ([Pro_GuidCategoryID])REFERENCES [dbo].[tblCategory] ([Cat_GuidID])

    GO

    SQL Server CE database

    Add the following code in DB_PPC.sql file on your disk:

    Create Table tblCategory(Cat_GuidID uniqueidentifier Not Null, Cat_StrName nvarchar(255) Not Null);

    Alter Table tblCategory AddConstraint PK_tblCategory Primary Key (Cat_GuidID),Constraint IX_tblCategory unique (Cat_StrName);

    Create Table tblProduct (Pro_GuidID uniqueidentifier Not Null, Pro_StrName nvarchar(255) Not Null,Pro_CurPrice money Not Null, Pro_GuidCategoryID uniqueidentifier Not Null);

    Alter Table tblProduct AddConstraint PK_tblProduct Primary Key (Pro_GuidID),Constraint IX_tblProduct unique (Pro_StrName, Pro_GuidCategoryID),Constraint FK_tblProduct_tblCategory Foreign Key (Pro_GuidCategoryID)

    References tblCategory (Cat_GuidID)

    Add the following code in a new file named: Install.cs

  • 7/29/2019 MS Press - NET Compact Framework Templates

    4/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 4/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    using System;using System.IO;using System.Data;using System.Data.SqlServerCe;using System.Windows.Forms;using System.Reflection;

    public class MainClass : Form {

    public static void Main() {

    Application.Run(new MainClass());}

    private Button cmdCreateDatabase = null;

    public MainClass() {

    this.cmdCreateDatabase = new System.Windows.Forms.Button();

    this.cmdCreateDatabase.Location = new System.Drawing.Point(8, 8);this.cmdCreateDatabase.Size = new System.Drawing.Size(224, 40);this.cmdCreateDatabase.Text = "Create database";this.cmdCreateDatabase.Click += new System.EventHandler(this.cmdCreateDatabase_Click);this.Controls.Add(this.cmdCreateDatabase);

    this.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular);this.MaximizeBox = false;this.MinimizeBox = false;this.Text = "Database creator";

    }

    private void cmdCreateDatabase_Click(object sender, System.EventArgs e) {

    SqlCeConnection sqlCeConnection = null;

    try {

    Cursor.Current = Cursors.WaitCursor;

    string originalPath =.Assembly.GetExecutingAssembly().GetName().CodeBase;originalPath = Path.GetDirectoryName(originalPath);

    string sdfFilePath = Path.Combine(originalPath, "DB_PPC.sdf");string sqlFilePath = Path.Combine(originalPath, "DB_PPC.sql");string connectionString = String.Format("Data Source={0}", sdfFilePath);

    if (File.Exists(sdfFilePath)) {

    File.Delete(sdfFilePath);

    }

    SqlCeEngine sqlCeEngine = null;sqlCeEngine = new SqlCeEngine(connectionString);sqlCeEngine.CreateDatabase();sqlCeEngine.Dispose();

    TextReader textReader = File.OpenText(sqlFilePath);string[] sqlScripts = textReader.ReadToEnd().Split(';');textReader.Close();

    sqlCeConnection = new SqlCeConnection(connectionString);sqlCeConnection.Open();

    SqlCeCommand sqlCeCommand = sqlCeConnection.CreateCommand();sqlCeCommand.CommandType = CommandType.Text;

    foreach (string sqlScript in sqlScripts) {

    if (sqlScript.Trim().Length != 0) {

    try {

    sqlCeCommand.CommandText = sqlScript;sqlCeCommand.ExecuteNonQuery();

    }catch (SqlCeException sqlCeException) {

    MessageBox.Show((String.Format("Error while executing SQL scripts:\r\n\r\n{0}",sqlCeException.Message)));

    return;}

    }}sqlCeCommand.Dispose();

  • 7/29/2019 MS Press - NET Compact Framework Templates

    5/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 5/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    MessageBox.Show("Database successfully created!");}catch (Exception exception) {

    MessageBox.Show(String.Format("Exception:\r\n\r\n{0}", exception.Message));}finally {

    if (sqlCeConnection != null && sqlCeConnection.State == ConnectionState.Open) {

    sqlCeConnection.Close();}

    Cursor.Current = Cursors.Default;}

    }}

    Add the following code in a new file named: Build.bat

    "%OLYMARS_FXBIN1.1%\csc" /noconfig /nostdlib/r:"%OLYMARS_CFXBIN1.0%\mscorlib.dll","%OLYMARS_CFXBIN1.0%\System.dll","%OLYMARS_CFXBIN1.0%\System.Drawing.dll","%OLYMARS_CFXBIN1.0%\System.Data.dll","%OLYMARS_CFXBIN1.0%\System.Data.SqlServerCe.dll","%OLYMARS_CFXBIN1.0%\System.Windows.Forms.dll" /t:winexe /main:MainClass *.cs

    pause

    Run the Build.bat command batch.

    On the PocketPC, create a new Folder \DB and copy both the Install.exe and DB_PPC.sqlfiles in this folder. From the PocketPC, run the Install.exe program and click on the CreateDatabase button. A new SDF file has been created in \DB.

    How to reuse the .NET Compact Framework templatesOnce you have created the database, lets create a new stored procedure calledspI_xInsertNewCategory:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    6/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 6/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Create Procedure [spI_xInsertNewCategory](@Cat_GuidID uniqueidentifier,@Cat_StrName varchar(255))

    As

    Insert Into tblCategory (Cat_GuidID, Cat_StrName) Values (@Cat_GuidID, @Cat_StrName)

    Return(0)

    GO

    Now, we can run OlyMars on this stored procedure.

    First, run OlyMars and connect to your DB_PCDB_PCDB_PCDB_PC database. Then, import the DotNetCompact Framework template from the file

    \\\\AddOnsAddOnsAddOnsAddOns\\\\DotNet Compact Framework.xmlDotNet Compact Framework.xmlDotNet Compact Framework.xmlDotNet Compact Framework.xml.

    Once this new group is imported, launch the Database Extended PropertiesExplorer:

    Create a new extended property on the spInsertNewCategoryspInsertNewCategoryspInsertNewCategoryspInsertNewCategory stored procedure:

    Name: Olymars/WindowsCE_EnabledOlymars/WindowsCE_EnabledOlymars/WindowsCE_EnabledOlymars/WindowsCE_EnabledValue = TrueTrueTrueTrue

    We have just indicated to the templates that we need to be able to call thisstored procedure directly on the DB_PPC database on our PPC. Lets run thegeneration now:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    7/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 7/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Once the generation done, lets go back to the Database Extended PropertiesExplorer:

    As we can notice, the templates have created others needed extended properties.Since the SQL Server CE Edition does not support things like triggers, storedprocedures or functions, we need to write our SQL code directly in our code.

  • 7/29/2019 MS Press - NET Compact Framework Templates

    8/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 8/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    This is why an Olymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQuery extended property was created. Bydefault the whole original stored procedure SQL code was paste in there. We arenow going to edit this query to be SQL Server CE Edition compliant. Update theOlymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQuery extended property this way:

    Name: Olymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQueryOlymars/WindowsCE_SqlQueryValue: Insert Into tblCategory (Cat_GuidID, Cat_StrName) Values (?, ?)Insert Into tblCategory (Cat_GuidID, Cat_StrName) Values (?, ?)Insert Into tblCategory (Cat_GuidID, Cat_StrName) Values (?, ?)Insert Into tblCategory (Cat_GuidID, Cat_StrName) Values (?, ?)

    Notice that we have replaced our parameter by a question mark (?).We are now ready to generate all the code again since we have updated theSqlQuery property.

    If we browse the output directory we can notice that a CE directory wascreated and that we have a build file ready to use.

    Before running this batch, be aware that it uses some specific environmentvariables to locate C# compiler and the .NET Compact Framework runtime:

    Name = OLYMARS_FXBIN1.1OLYMARS_FXBIN1.1OLYMARS_FXBIN1.1OLYMARS_FXBIN1.1Value = C:C:C:C:\\\\WINNTWINNTWINNTWINNT\\\\Microsoft.NETMicrosoft.NETMicrosoft.NETMicrosoft.NET\\\\FrameworkFrameworkFrameworkFramework\\\\v1.1.4322v1.1.4322v1.1.4322v1.1.4322

    Name = OLYMARS_FXSDK1.1OLYMARS_FXSDK1.1OLYMARS_FXSDK1.1OLYMARS_FXSDK1.1Value = C:C:C:C:\\\\Program FilesProgram FilesProgram FilesProgram Files\\\\MicroMicroMicroMicrosoft Visual Studio .NET 2003soft Visual Studio .NET 2003soft Visual Studio .NET 2003soft Visual Studio .NET 2003\\\\SDKSDKSDKSDK\\\\v1.1v1.1v1.1v1.1\\\\BinBinBinBin

    Name = OLYMARS_CFXBIN1.0OLYMARS_CFXBIN1.0OLYMARS_CFXBIN1.0OLYMARS_CFXBIN1.0Value = C::::\\\\Program FilesProgram FilesProgram FilesProgram Files\\\\Microsoft Visual Studio .NETMicrosoft Visual Studio .NETMicrosoft Visual Studio .NETMicrosoft Visual Studio .NET2003200320032003\\\\CompactFrameworkSDKCompactFrameworkSDKCompactFrameworkSDKCompactFrameworkSDK\\\\v1.0.5000v1.0.5000v1.0.5000v1.0.5000\\\\Windows CEWindows CEWindows CEWindows CE

    For you convenience, you will find a reg file on the root of the OlyMarsbinaries that creates all the necessary environment variables (with defaultvalues) for you:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    9/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 9/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Once your environment variables are correctly set up, run the batch file andignore the errors for now:

    You have now access to an assembly built specifically for the .NET CompactFramework:

    \\\\DB_PCDB_PCDB_PCDB_PC\\\\CECECECE\\\\BinBinBinBin\\\\DB_PC.Ce.dllDB_PC.Ce.dllDB_PC.Ce.dllDB_PC.Ce.dll

    In order to call our Stored Procedure directly from the PPC, we now havetwo useful classes:

    DB_PC.Ce.DataClasses.Parameters.spInsertNewCategory

    DB_PC.Ce.DataClasses.StoredProcedures.spInsertNewCategory

    If you are used to the classical OlyMars templates (DotNet Framework Dataclasses), you now know how to call those classes right? If not, here is anexample:

    Create a new C# SDE Windows Application project named PPC_ClientPPC_ClientPPC_ClientPPC_Client.

  • 7/29/2019 MS Press - NET Compact Framework Templates

    10/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 10/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Update the Output File Folder property of the project to \\\\DBDBDBDB.

    Add the following references:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    11/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 11/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    If you get this message, you can ignore it:

    Add a new TexBox (textBox1textBox1textBox1textBox1) and a new Button (button1button1button1button1) on Form1.

  • 7/29/2019 MS Press - NET Compact Framework Templates

    12/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 12/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Add the following using statements:

    using System.Reflection;using System.IO;using System.Data.SqlTypes;using DB_PC.Ce.SqlCe.DataClasses;using DB_PC.Ce.Windows;using Params = DB_PC.Ce.SqlCe.DataClasses.Parameters;using SPs = DB_PC.Ce.SqlCe.DataClasses.StoredProcedures;

    Double-Click on the button and add the following code:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    13/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 13/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    private void button1_Click(object sender, System.EventArgs e) {

    string currentPath = Assembly.GetExecutingAssembly().GetName().CodeBase;currentPath = Path.GetDirectoryName(currentPath);

    string connectionstring = Information.BuildConnectionString(Path.Combine(currentPath, "DB_PPC.sdf"));

    Params.spI_xInsertNewCategory param = null;Param = new Params.spI_xInsertNewCategory();

    param.SetUpConnection(connectionstring);

    param.Param_Cat_GuidID = new SqlGuid("{BD51E6FC-9293-4FC0-9BE9-13D1E0519922}");param.Param_Cat_StrName = textBox1.Text;

    SPs.spI_xInsertNewCategory sp = null;using (sp = new SPs.spI_xInsertNewCategory(true)) {

    try {

    sp.Execute(ref param);MessageBox.Show("Category successfully created");

    }catch(System.Data.SqlServerCe.SqlCeException sqlCeException) {

    MessageBox.Show(sqlCeException.Message);}catch (System.Exception Exception) {

    MessageBox.Show(Exception.Message);}

    }param.Dispose();

    }

    Deploy and run the application on your PPC.

  • 7/29/2019 MS Press - NET Compact Framework Templates

    14/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 14/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    If you click again on the button you will have the following error:

    This is because the Cat_StrNameCat_StrNameCat_StrNameCat_StrName was declared as a unique key.

    Lets verify if the new record is actually in the database:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    15/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 15/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    OK, thats cool our record is there.

    Lets go back now to our DB_PCDB_PCDB_PCDB_PC database and lets add a new stored procedurespspspspU_xU_xU_xU_xUpdateCategoryUpdateCategoryUpdateCategoryUpdateCategory:

    Create Procedure spU_xUpdateCategory(@Cat_GuidID uniqueidentifier,@Cat_StrName varchar(255))

    As

    Update tblcategory Set Cat_StrName = @Cat_StrNameWhere Cat_GuidID = @Cat_GuidID

    Return(0)

    From OlyMars, refresh the database. As for the previous stored procedure, add anew extended property Olymars/WindowsCE_EnaOlymars/WindowsCE_EnaOlymars/WindowsCE_EnaOlymars/WindowsCE_Enabledbledbledbled and set it to TrueTrueTrueTrue. Lets nowrun again a generation on the whole thing:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    16/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 16/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    You now should see those extended properties for our stored procedure:

    Update the Olymars/WindowsCE_SqlQuery extended property this way:

    Update tblcategory Set Cat_StrName = ? Where Cat_GuidID = ?

  • 7/29/2019 MS Press - NET Compact Framework Templates

    17/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 17/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    As you can notice, we are going to have some problems with the parametersbecause @Cat_GuidID is supposed to be the FIRST parameter and @Cat_StrName thesecond one. But when we have replaced the parameters by our question mark(?), the order is exactly reversed. The first ? is intended for@Cat_StrName and the second one is intended for @Cat_GuidID.

    This is where the Olymars/WindowsCE_ParametersMappingOlymars/WindowsCE_ParametersMappingOlymars/WindowsCE_ParametersMappingOlymars/WindowsCE_ParametersMapping extended property comesinto the picture. We are going to reflect that situation by updating those

    extended properties this way:

    Now we have indicated that @Cat_GuidID actually maps to the second?(Mapping=1) and that @Cat_StrName maps to the first one (Mapping=0).

    Lets go ahead and regenerate the whole stuff (Close your Visual Studio .NETsolution before that). Once the assembly recompiled using the batch file, letsgo back to Visual Studio .NET project and lets rebuild the project to updatethe assembly reference. Lets add two TextBoxes (textBox2) and a button(button2):

    Double-click on button2 and paste this code:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    18/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 18/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    private void button3_Click(object sender, System.EventArgs e) {

    string currentPath = Assembly.GetExecutingAssembly().GetName().CodeBase;currentPath = Path.GetDirectoryName(currentPath);

    string connectionstring = Information.BuildConnectionString(Path.Combine(currentPath, "DB_PPC.sdf"));

    Params.spU_xUpdateCategory param = null;param=new Params.spU_xUpdateCategory();

    param.SetUpConnection(connectionstring);

    param.Param_Cat_GuidID = new SqlGuid("{BD51E6FC-9293-4FC0-9BE9-13D1E0519922}");param.Param_Cat_StrName = textBox2.Text;

    SPs.spU_xUpdateCategory sp = null;using (sp = new SPs.spU_xUpdateCategory(true)) {

    try {

    sp.Execute(ref param);MessageBox.Show("Category successfully updated");

    }catch(System.Data.SqlServerCe.SqlCeException sqlCeException) {

    MessageBox.Show(sqlCeException.Message);}catch (System.Exception Exception) {

    MessageBox.Show(Exception.Message);}

    }param.Dispose();

    }

    Lets go ahead and deploy the new application again:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    19/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 19/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Lets create another stored procedure spspspspS_xS_xS_xS_xGetAllCategoriesGetAllCategoriesGetAllCategoriesGetAllCategories

    CREATE PROCEDURE spS_xGetAllCategories

    As

    Select * From tblCategory

    return(@@RowCount)

    From OlyMars, refresh the database. As for the previous stored procedure, add anew extended property Olymars/WindowsCE_EnabledOlymars/WindowsCE_EnabledOlymars/WindowsCE_EnabledOlymars/WindowsCE_Enabled and set it to TrueTrueTrueTrue. Lets now

    run again a generation on the whole thing. Lets update the SqlQuery extendedproperty like this:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    20/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 20/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Lets run again the generation and recompile the assembly again.

  • 7/29/2019 MS Press - NET Compact Framework Templates

    21/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 21/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Since there is at least one stored procedure that returns some data, you nowhave access to visual controls. In order to successfully use them, you need tocustomize Visual Studio .NET toolbox.

    Click on the Browse button and pick up the following assembly:C:C:C:C:\\\\Program FilesProgram FilesProgram FilesProgram Files\\\\Microsoft Visual Studio .NETMicrosoft Visual Studio .NETMicrosoft Visual Studio .NETMicrosoft Visual Studio .NET2003200320032003\\\\CompactFrameworkSDKCompactFrameworkSDKCompactFrameworkSDKCompactFrameworkSDK\\\\v1.0.5000v1.0.5000v1.0.5000v1.0.5000\\\\Windows CEWindows CEWindows CEWindows CE\\\\DesignerDesignerDesignerDesigner\\\\Design.Design.Design.Design.DB_PCDB_PCDB_PCDB_PC.Ce.dll.Ce.dll.Ce.dll.Ce.dll

  • 7/29/2019 MS Press - NET Compact Framework Templates

    22/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 22/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Then

    And finally your toolbox looks like this:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    23/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 23/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    In Visual Studio .NET, add a WinListBoxCustom_spS_xGetAllCategories (listBox1)and a Button (button3):

    Double-Click on the button4. Add the following code:

    private void button4_Click(object sender, System.EventArgs e) {

    string currentPath = Assembly.GetExecutingAssembly().GetName().CodeBase;currentPath = Path.GetDirectoryName(currentPath);

    string connectionstring = Information.BuildConnectionString(Path.Combine(currentPath, "DB_PPC.sdf"));

    winListBoxCustom_spS_xGetAllCategories1.Initialize(connectionstring, "Cat_GuidID", "Cat_StrName", FillMethod.SqlCeDataReader);

    winListBoxCustom_spS_xGetAllCategories1.RefreshData();}

    Lets deploy and run again:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    24/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 24/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    *******************************NEEDS UPDATE STARTING FROM HERE*******************************

    Lets create this last stored procedure spGetspGetspGetspGetSomeSomeSomeSomeCategoriesCategoriesCategoriesCategories:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    25/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 25/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    From OlyMars, refresh the database. As for the previous stored procedure, add anew extended property Olymars/WindowsCE_EnabledOlymars/WindowsCE_EnabledOlymars/WindowsCE_EnabledOlymars/WindowsCE_Enabled and set it to TrueTrueTrueTrue. Lets nowrun again a generation on the whole thing. Lets update the SqlQuery extended

    property like this:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    26/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 26/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    Lets run again the generation and recompile the assembly again. In VisualStudio .NET, add a new Form (form2), add a ListView (listView1, View=Details)and a Button (button1):

    Double-Click the button1. From now on and because of a bug in SDE, we are goingto close the Form2 design windows. In the source code, we are going to replacethe two instances of System.Windows.Forms.ListView byDB_PC.Ce.Windows.ListViews.WinListViewCustom_spGetSomeCategories:

  • 7/29/2019 MS Press - NET Compact Framework Templates

    27/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 27/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    And

    Add the following code:

    Update the project to start on form2 instead of Form1.

    Finally add the button1 click event handler:

    privatevoid button1_Click(object sender, System.EventArgs e)

    {

    string connectionstring;

    connectionstring=DB_PC.Ce.DataClasses.Information.BuildConnectionString(@"\M

    y Documents\DB_PPC.sdf");

    DB_PC.Ce.Windows.ListViewParameters ListViewParameters;

    DB_PC.Ce.Windows.ListViewParameter ListViewParameter;

    ListViewParameter = new

    DB_PC.Ce.Windows.ListViewParameter("Cat_StrName","Name");

    ListViewParameters = new

    DB_PC.Ce.Windows.ListViewParameters("Cat_GuidID",ListViewParameter);

    ListViewParameter = new

    DB_PC.Ce.Windows.ListViewParameter("Cat_GuidID","Guid");

    ListViewParameters.AddSubItem(ListViewParameter);

    try

    {

    listView1.Initialize(connectionstring,ListViewParameters,"A","T");

    listView1.RefreshData();

    }

    catch (DB_PC.Ce.DataClasses.CustomException ee)

    {

  • 7/29/2019 MS Press - NET Compact Framework Templates

    28/29

    Version : 15 dc. 02 .NET Compact Framework templates

    SQL Server Centric .NET Code Generator (OlyMars) 28/29http://www.microsoft.fr/OlyMars/WebUpdate.xml

    MessageBox.Show(ee.Parameter.SqlCeException.Message);

    }

    }

    Compile and deploy your project:

    Add this code:

    this.listView1.SelectedIndexChanged += new

    System.EventHandler(this.listView1.SelectedIndexChanged);

  • 7/29/2019 MS Press - NET Compact Framework Templates

    29/29

    Version : 15 dc. 02 .NET Compact Framework templates

    Compile and deploy:

    Erreur de compile : The modifier 'private' is not valid for this item pour la ligne private

    void listView1.SelectedIndexChanged (object sender, System.EventArgs e) ????