Article by: Vijayeta.t of SONATA SOFTWARE LIMITED
This article explains how to fetch data from a database and use that data to create a PresentationML document. Each slide in the presentation consists of a heading and a subtitle, and the data for these textboxes is retrieved from a table in database.
The attached sample application provides the user with a GUI, wherein the user has the option to choose the slide contents.
The user can select the database using the textbox provided, which displays the connection string.
The dropdown listbox contains all the topics for which the slides can be generated. On selection of a particular topic, the slide headings for that topic, and a brief data about the particular slide heading is displayed in the list view.
Among the slide headings displayed, user can select the titles required for the presentation document.
The presentation document is then generated, where slides would hold the selected headings and corresponding subtitles.
Initially the combo box drops down displaying the slides available. When a topic is selected,at the backend all the records corresponding the topic are fetched from the database, i.e. the table containing the Slide Titles and a brief description about the Title, and are mapped to the Listview.
string selectstatement = "select Title,Description from mainTable " ;
SqlDataAdapter myAdpt = new SqlDataAdapter(selectstatement, conn);
DataSet ds=new DataSet ();
myAdpt.Fill(ds, "mainTable");
table = ds.Tables["mainTable"];
// Clear the ListView control
listView1.Items.Clear();
for (int i = 0; i < table.Rows.Count; i++)
{
DataRow drow = table.Rows[i];
listView1.GridLines = true;
ListViewItem lvi = new ListViewItem(drow["Title"].ToString());
lvi.SubItems .Add (drow ["Description"].ToString ());
listView1.Items.Add(lvi);
}
On selection of the required titles, all the rows from the table containing the Titles and Subtitles are fetched and a comparison is done between the rows fetched and the items selected in the Listview, hence the slides are generated for the selected titles.
string selectstatement = "select Title,SubTitle from " + tableName;
DataSet ds = new DataSet();
myAdpt.Fill(ds, tableName);
table = ds.Tables[tableName];
for (int i = 0; i <table.Rows.Count; i++)
for (int j = 0; j <listView1.SelectedItems.Count; j++)
if (listView1.SelectedItems[j].ToString().Remove(0, 15).TrimEnd('}') == (drow[0].ToString()))
Heading.Add ( drow[0].ToString());
SubTitle.Add ( drow[1].ToString());
n+=1;
num +=1;
The files such as SlideX.xml that holds the contents of slides and presentation.xml that describes the relationship Id of each of the slides, are created programatically.
Additional xml files in the Presentation document are the standard files such as SlideLayouts, SlideMaster, NotesMaster and Themes. Since these files are not created programatically,they are added along with the .exe file, which are then read and packaged to form the presentation package. These files could also be created programatically as part of package.
The Application code and table structure required for the application to run is attached.