Author: wyoung
Date: Thu Mar 29 19:13:54 2007
New Revision: 1481
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1481&view=rev
Log:
First working version of Windows Forms example
Modified:
trunk/examples/vstudio/wforms/MainForm.h
trunk/examples/vstudio/wforms/MainForm.resX
trunk/examples/vstudio/wforms/wforms.vcproj
Modified: trunk/examples/vstudio/wforms/MainForm.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/wforms/MainForm.h?rev=1481&r1=1480&r2=1481&view=diff
==============================================================================
--- trunk/examples/vstudio/wforms/MainForm.h (original)
+++ trunk/examples/vstudio/wforms/MainForm.h Thu Mar 29 19:13:54 2007
@@ -1,4 +1,32 @@
+/***********************************************************************
+ MainForm.cpp - Defines the dialog box behavior for the MySQL++ C++/CLI
+ Windows Forms example.
+
+ Copyright (c) 2007 by Educational Technology Resources, Inc. Others
+ may also hold copyrights on code in this file. See the CREDITS file in
+ the top directory of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
#pragma once
+
+#include <mysql++.h>
namespace wforms {
@@ -25,17 +53,86 @@
}
}
- private: System::Windows::Forms::TextBox^ textBox1;
- private: System::Windows::Forms::TextBox^ textBox2;
- private: System::Windows::Forms::TextBox^ textBox3;
- private: System::Windows::Forms::ListBox^ listBox1;
- private: System::Windows::Forms::Button^ ConnectButton;
- private: System::Windows::Forms::Button^ CloseButton;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Label^ label2;
- private: System::Windows::Forms::Label^ label3;
- private: System::Windows::Forms::Label^ label4;
- private: System::ComponentModel::Container ^components;
+ private:
+ System::Void CloseButton_Click(Object^ sender, EventArgs^ e)
+ {
+ Application::Exit();
+ }
+
+ Void ConnectButton_Click(Object^ sender, EventArgs^ e)
+ {
+ // Clear out the results list, in case this isn't the
first time
+ // we've come in here.
+ resultsList_->Items->Clear();
+
+ // Translate the Unicode text we get from the UI into
the UTF-8 form
+ // that MySQL wants.
+ const int kInputBufSize = 100;
+ char acServerAddress[kInputBufSize];
+ char acUserName[kInputBufSize];
+ char acPassword[kInputBufSize];
+ ToUTF8(acServerAddress, kInputBufSize,
serverAddress_->Text);
+ ToUTF8(acUserName, kInputBufSize, userName_->Text);
+ ToUTF8(acPassword, kInputBufSize, password_->Text);
+
+ // Connect to the sample database.
+ mysqlpp::Connection con(false);
+ if (!con.connect("mysql_cpp_data", acServerAddress,
acUserName,
+ acPassword)) {
+ AddMessage("Failed to connect to server:");
+ AddMessage(gcnew String(con.error()));
+ return;
+ }
+
+ // Retrieve a subset of the sample stock table set up
by resetdb
+ mysqlpp::Query query = con.query();
+ query << "select item from stock";
+ mysqlpp::Result res = query.store();
+
+ if (res) {
+ // Display the result set
+ mysqlpp::Row row;
+ for (mysqlpp::Row::size_type i = 0; row =
res.at(i); ++i) {
+ AddMessage(ToUCS2(row.at(0)));
+ }
+
+ // Retreive was successful, so save user inputs
now
+ //SaveInputs(sServerAddress, sUserName);
+ }
+ else {
+ // Retreive failed
+ AddMessage("Failed to get item list:");
+ AddMessage(ToUCS2(query.error().c_str()));
+ }
+ }
+
+ Void ToUTF8(char* pcOut, int nOutLen, String^ sIn)
+ {
+ array<Byte>^ bytes =
System::Text::Encoding::UTF8->GetBytes(sIn);
+ nOutLen = Math::Min(nOutLen - 1, bytes->Length);
+ System::Runtime::InteropServices::Marshal::Copy(bytes,
0,
+ IntPtr(pcOut), nOutLen);
+ pcOut[nOutLen] = '\0';
+ }
+
+ String^ ToUCS2(const char* utf8)
+ {
+ return gcnew String(utf8, 0, strlen(utf8),
+ System::Text::Encoding::UTF8);
+ }
+
+ Void AddMessage(String^ msg)
+ {
+ resultsList_->Items->Insert(0, msg);
+ }
+
+ private: System::Windows::Forms::TextBox^ serverAddress_;
+ private: System::Windows::Forms::TextBox^ password_;
+ private: System::Windows::Forms::TextBox^ userName_;
+ private: System::Windows::Forms::ListBox^ resultsList_;
+ private: System::Windows::Forms::Button^ connectButton_;
+ private: System::Windows::Forms::Button^ closeButton_;
+ private: System::ComponentModel::Container^ components;
#pragma region Windows Form Designer generated code
/// <summary>
@@ -44,127 +141,132 @@
/// </summary>
void InitializeComponent(void)
{
- this->textBox1 = (gcnew
System::Windows::Forms::TextBox());
- this->textBox2 = (gcnew
System::Windows::Forms::TextBox());
- this->textBox3 = (gcnew
System::Windows::Forms::TextBox());
- this->listBox1 = (gcnew
System::Windows::Forms::ListBox());
- this->ConnectButton = (gcnew
System::Windows::Forms::Button());
- this->CloseButton = (gcnew
System::Windows::Forms::Button());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->label3 = (gcnew System::Windows::Forms::Label());
- this->label4 = (gcnew System::Windows::Forms::Label());
+ System::Windows::Forms::Label^ label1;
+ System::Windows::Forms::Label^ label2;
+ System::Windows::Forms::Label^ label3;
+ System::Windows::Forms::Label^ label4;
+ this->serverAddress_ = (gcnew
System::Windows::Forms::TextBox());
+ this->password_ = (gcnew
System::Windows::Forms::TextBox());
+ this->userName_ = (gcnew
System::Windows::Forms::TextBox());
+ this->resultsList_ = (gcnew
System::Windows::Forms::ListBox());
+ this->connectButton_ = (gcnew
System::Windows::Forms::Button());
+ this->closeButton_ = (gcnew
System::Windows::Forms::Button());
+ label1 = (gcnew System::Windows::Forms::Label());
+ label2 = (gcnew System::Windows::Forms::Label());
+ label3 = (gcnew System::Windows::Forms::Label());
+ label4 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
- // textBox1
- //
- this->textBox1->Location = System::Drawing::Point(70,
9);
- this->textBox1->Name = L"textBox1";
- this->textBox1->Size = System::Drawing::Size(139, 20);
- this->textBox1->TabIndex = 0;
- //
- // textBox2
- //
- this->textBox2->Location = System::Drawing::Point(70,
61);
- this->textBox2->Name = L"textBox2";
- this->textBox2->Size = System::Drawing::Size(139, 20);
- this->textBox2->TabIndex = 2;
- //
- // textBox3
- //
- this->textBox3->Location = System::Drawing::Point(70,
35);
- this->textBox3->Name = L"textBox3";
- this->textBox3->Size = System::Drawing::Size(139, 20);
- this->textBox3->TabIndex = 1;
- //
- // listBox1
- //
- this->listBox1->Enabled = false;
- this->listBox1->FormattingEnabled = true;
- this->listBox1->Location = System::Drawing::Point(70,
88);
- this->listBox1->Name = L"listBox1";
- this->listBox1->Size = System::Drawing::Size(139, 95);
- this->listBox1->TabIndex = 3;
- this->listBox1->TabStop = false;
- //
- // ConnectButton
- //
- this->ConnectButton->Location =
System::Drawing::Point(224, 9);
- this->ConnectButton->Name = L"ConnectButton";
- this->ConnectButton->Size = System::Drawing::Size(75,
23);
- this->ConnectButton->TabIndex = 3;
- this->ConnectButton->Text = L"Connect!";
- this->ConnectButton->UseVisualStyleBackColor = true;
- //
- // CloseButton
- //
- this->CloseButton->DialogResult =
System::Windows::Forms::DialogResult::Cancel;
- this->CloseButton->Location =
System::Drawing::Point(224, 38);
- this->CloseButton->Name = L"CloseButton";
- this->CloseButton->Size = System::Drawing::Size(75, 23);
- this->CloseButton->TabIndex = 4;
- this->CloseButton->Text = L"Close";
- this->CloseButton->UseVisualStyleBackColor = true;
- this->CloseButton->Click += gcnew
System::EventHandler(this, &MainForm::CloseButton_Click);
- //
// label1
//
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(29, 13);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(41, 13);
- this->label1->TabIndex = 6;
- this->label1->Text = L"Server:";
- this->label1->TextAlign =
System::Drawing::ContentAlignment::TopRight;
+ label1->AutoSize = true;
+ label1->Location = System::Drawing::Point(29, 13);
+ label1->Name = L"label1";
+ label1->Size = System::Drawing::Size(41, 13);
+ label1->TabIndex = 6;
+ label1->Text = L"Server:";
+ label1->TextAlign =
System::Drawing::ContentAlignment::TopRight;
//
// label2
//
- this->label2->AutoSize = true;
- this->label2->Location = System::Drawing::Point(9, 39);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(61, 13);
- this->label2->TabIndex = 7;
- this->label2->Text = L"User name:";
- this->label2->TextAlign =
System::Drawing::ContentAlignment::TopRight;
+ label2->AutoSize = true;
+ label2->Location = System::Drawing::Point(9, 39);
+ label2->Name = L"label2";
+ label2->Size = System::Drawing::Size(61, 13);
+ label2->TabIndex = 7;
+ label2->Text = L"User name:";
+ label2->TextAlign =
System::Drawing::ContentAlignment::TopRight;
//
// label3
//
- this->label3->AutoSize = true;
- this->label3->Location = System::Drawing::Point(14, 65);
- this->label3->Name = L"label3";
- this->label3->Size = System::Drawing::Size(56, 13);
- this->label3->TabIndex = 8;
- this->label3->Text = L"Password:";
- this->label3->TextAlign =
System::Drawing::ContentAlignment::TopRight;
+ label3->AutoSize = true;
+ label3->Location = System::Drawing::Point(14, 65);
+ label3->Name = L"label3";
+ label3->Size = System::Drawing::Size(56, 13);
+ label3->TabIndex = 8;
+ label3->Text = L"Password:";
+ label3->TextAlign =
System::Drawing::ContentAlignment::TopRight;
//
// label4
//
- this->label4->AutoSize = true;
- this->label4->Location = System::Drawing::Point(25, 92);
- this->label4->Name = L"label4";
- this->label4->Size = System::Drawing::Size(45, 13);
- this->label4->TabIndex = 9;
- this->label4->Text = L"Results:";
- this->label4->TextAlign =
System::Drawing::ContentAlignment::TopRight;
+ label4->AutoSize = true;
+ label4->Location = System::Drawing::Point(25, 92);
+ label4->Name = L"label4";
+ label4->Size = System::Drawing::Size(45, 13);
+ label4->TabIndex = 9;
+ label4->Text = L"Results:";
+ label4->TextAlign =
System::Drawing::ContentAlignment::TopRight;
+ //
+ // serverAddress_
+ //
+ this->serverAddress_->Location =
System::Drawing::Point(70, 9);
+ this->serverAddress_->Name = L"serverAddress_";
+ this->serverAddress_->Size = System::Drawing::Size(139,
20);
+ this->serverAddress_->TabIndex = 0;
+ //
+ // password_
+ //
+ this->password_->Location = System::Drawing::Point(70,
61);
+ this->password_->Name = L"password_";
+ this->password_->Size = System::Drawing::Size(139, 20);
+ this->password_->TabIndex = 2;
+ //
+ // userName_
+ //
+ this->userName_->Location = System::Drawing::Point(70,
35);
+ this->userName_->Name = L"userName_";
+ this->userName_->Size = System::Drawing::Size(139, 20);
+ this->userName_->TabIndex = 1;
+ //
+ // resultsList_
+ //
+ this->resultsList_->Enabled = false;
+ this->resultsList_->FormattingEnabled = true;
+ this->resultsList_->Location =
System::Drawing::Point(70, 88);
+ this->resultsList_->Name = L"resultsList_";
+ this->resultsList_->Size = System::Drawing::Size(228,
95);
+ this->resultsList_->TabIndex = 3;
+ this->resultsList_->TabStop = false;
+ //
+ // connectButton_
+ //
+ this->connectButton_->Location =
System::Drawing::Point(224, 9);
+ this->connectButton_->Name = L"connectButton_";
+ this->connectButton_->Size = System::Drawing::Size(75,
23);
+ this->connectButton_->TabIndex = 3;
+ this->connectButton_->Text = L"Connect!";
+ this->connectButton_->UseVisualStyleBackColor = true;
+ this->connectButton_->Click += gcnew
System::EventHandler(this, &MainForm::ConnectButton_Click);
+ //
+ // closeButton_
+ //
+ this->closeButton_->DialogResult =
System::Windows::Forms::DialogResult::Cancel;
+ this->closeButton_->Location =
System::Drawing::Point(224, 38);
+ this->closeButton_->Name = L"closeButton_";
+ this->closeButton_->Size = System::Drawing::Size(75,
23);
+ this->closeButton_->TabIndex = 4;
+ this->closeButton_->Text = L"Close";
+ this->closeButton_->UseVisualStyleBackColor = true;
+ this->closeButton_->Click += gcnew
System::EventHandler(this, &MainForm::CloseButton_Click);
//
// MainForm
//
- this->AcceptButton = this->ConnectButton;
+ this->AcceptButton = this->connectButton_;
this->AutoScaleDimensions = System::Drawing::SizeF(6,
13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
- this->CancelButton = this->CloseButton;
+ this->CancelButton = this->closeButton_;
this->ClientSize = System::Drawing::Size(310, 192);
this->ControlBox = false;
- this->Controls->Add(this->label4);
- this->Controls->Add(this->label3);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->CloseButton);
- this->Controls->Add(this->ConnectButton);
- this->Controls->Add(this->listBox1);
- this->Controls->Add(this->textBox3);
- this->Controls->Add(this->textBox2);
- this->Controls->Add(this->textBox1);
+ this->Controls->Add(label4);
+ this->Controls->Add(label3);
+ this->Controls->Add(label2);
+ this->Controls->Add(label1);
+ this->Controls->Add(this->closeButton_);
+ this->Controls->Add(this->connectButton_);
+ this->Controls->Add(this->resultsList_);
+ this->Controls->Add(this->userName_);
+ this->Controls->Add(this->password_);
+ this->Controls->Add(this->serverAddress_);
this->FormBorderStyle =
System::Windows::Forms::FormBorderStyle::FixedDialog;
this->MaximizeBox = false;
this->MinimizeBox = false;
@@ -176,11 +278,5 @@
}
#pragma endregion
-
-
- private: System::Void CloseButton_Click(System::Object^ sender,
System::EventArgs^ e)
- {
- Application::Exit();
- }
};
}
Modified: trunk/examples/vstudio/wforms/MainForm.resX
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/wforms/MainForm.resX?rev=1481&r1=1480&r2=1481&view=diff
==============================================================================
--- trunk/examples/vstudio/wforms/MainForm.resX (original)
+++ trunk/examples/vstudio/wforms/MainForm.resX Thu Mar 29 19:13:54 2007
@@ -117,4 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
+ <metadata name="label1.GenerateMember" type="System.Boolean, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>False</value>
+ </metadata>
+ <metadata name="label2.GenerateMember" type="System.Boolean, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>False</value>
+ </metadata>
+ <metadata name="label3.GenerateMember" type="System.Boolean, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>False</value>
+ </metadata>
+ <metadata name="label4.GenerateMember" type="System.Boolean, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>False</value>
+ </metadata>
</root>
Modified: trunk/examples/vstudio/wforms/wforms.vcproj
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/wforms/wforms.vcproj?rev=1481&r1=1480&r2=1481&view=diff
==============================================================================
--- trunk/examples/vstudio/wforms/wforms.vcproj (original)
+++ trunk/examples/vstudio/wforms/wforms.vcproj Thu Mar 29 19:13:54 2007
@@ -21,7 +21,7 @@
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
- ManagedExtensions="2"
+ ManagedExtensions="1"
>
<Tool
Name="VCPreBuildEventTool"
@@ -41,6 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\lib,
C:\Program Files\MySQL\MySQL Server 5.0\include"
PreprocessorDefinitions="WIN32;_DEBUG"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
@@ -58,8 +59,9 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="$(NoInherit)"
+ AdditionalDependencies="mysqlpp.lib
libmysql.lib"
LinkIncremental="2"
+
AdditionalLibraryDirectories="..\..\..\Debug,C:\Program Files\MySQL\MySQL
Server 5.0\lib\debug"
GenerateDebugInformation="true"
AssemblyDebug="1"
SubSystem="2"
@@ -97,7 +99,7 @@
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
- ManagedExtensions="2"
+ ManagedExtensions="1"
WholeProgramOptimization="1"
>
<Tool
@@ -117,6 +119,7 @@
/>
<Tool
Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="..\..\..\lib,
C:\Program Files\MySQL\MySQL Server 5.0\include"
PreprocessorDefinitions="WIN32;NDEBUG"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
@@ -134,8 +137,9 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="$(NoInherit)"
+ AdditionalDependencies="mysqlpp.lib
libmysql.lib"
LinkIncremental="1"
+
AdditionalLibraryDirectories="..\..\..\Release,C:\Program Files\MySQL\MySQL
Server 5.0\lib\opt"
GenerateDebugInformation="true"
SubSystem="2"
EntryPointSymbol="main"
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits