0% found this document useful (0 votes)
34 views

Pragma Once

The document contains C# code for a Windows Forms application with the following key elements: 1. The Form1 class contains code to define the user interface elements like buttons, text boxes, labels and panels. 2. The InitializeComponent method sets up the layout and properties of the UI elements. 3. Additional methods like DviewCreate are used to connect to a database and load data into a dataset for display in the form.

Uploaded by

asdfasdf460
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Pragma Once

The document contains C# code for a Windows Forms application with the following key elements: 1. The Form1 class contains code to define the user interface elements like buttons, text boxes, labels and panels. 2. The InitializeComponent method sets up the layout and properties of the UI elements. 3. Additional methods like DviewCreate are used to connect to a database and load data into a dataset for display in the form.

Uploaded by

asdfasdf460
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

#pragma once

namespace ex1431 { using using using using using using using namespace namespace namespace namespace namespace namespace namespace System; System::ComponentModel; System::Collections; System::Windows::Forms; System::Data; System::Data ::OleDb ; System::Drawing;

/// <summary> /// Form1 /// /// : .resx /// Managed 'Resource File Name' /// /// /// /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: // } protected: /// <summary> /// /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ protected: private: System::Windows::Forms::Button^ private: System::Windows::Forms::Button^ private: System::Windows::Forms::Button^ private: System::Windows::Forms::Button^ private: System::Windows::Forms::Panel^

button1; button2; button3; button4; button5; panel1;

private: private: private: private: private: private:

System::Windows::Forms::DataGridView^ dataGridView1; System::Windows::Forms::Label^ label1; System::Windows::Forms::Label^ label2; System::Windows::Forms::Label^ label3; System::Windows::Forms::Label^ label4; System::Windows::Forms::Label^ label5; textBox2; textBox3; textBox4; panel2; textBox1; textBox5;

private: System::Windows::Forms::TextBox^ private: System::Windows::Forms::TextBox^ private: System::Windows::Forms::TextBox^ private: System::Windows::Forms::Panel^ private: System::Windows::Forms::TextBox^ private: System::Windows::Forms::TextBox^

private: System::ComponentModel::IContainer^ components; private: /// <summary> /// /// </summary>

#pragma region Windows Form Designer generated code /// <summary> /// - /// /// </summary> void InitializeComponent(void) { this->button1 = (gcnew System::Windows::Forms::Button()); this->button2 = (gcnew System::Windows::Forms::Button()); this->button3 = (gcnew System::Windows::Forms::Button()); this->button4 = (gcnew System::Windows::Forms::Button()); this->button5 = (gcnew System::Windows::Forms::Button()); this->panel1 = (gcnew System::Windows::Forms::Panel()); this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView()); 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()); this->label5 = (gcnew System::Windows::Forms::Label()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->textBox3 = (gcnew System::Windows::Forms::TextBox()); this->textBox4 = (gcnew System::Windows::Forms::TextBox());

this->panel2 = (gcnew System::Windows::Forms::Panel()); this->textBox5 = (gcnew System::Windows::Forms::TextBox()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->panel1->SuspendLayout(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->BeginInit(); this->panel2->SuspendLayout(); this->SuspendLayout(); // // button1 // this->button1->Location = System::Drawing::Point(16, 8); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(49, 20); this->button1->TabIndex = 0; this->button1->Text = L""; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // button2 // this->button2->Location = System::Drawing::Point(67, 8); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(49, 20); this->button2->TabIndex = 1; this->button2->Text = L""; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // button3 // this->button3->Location = System::Drawing::Point(118, 8); this->button3->Name = L"button3"; this->button3->Size = System::Drawing::Size(49, 20); this->button3->TabIndex = 2; this->button3->Text = L""; this->button3->UseVisualStyleBackColor = true; this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click); // // button4 // this->button4->Location = System::Drawing::Point(169, 8); this->button4->Name = L"button4"; this->button4->Size = System::Drawing::Size(49, 20); this->button4->TabIndex = 3; this->button4->Text = L""; this->button4->UseVisualStyleBackColor = true; this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click); // // button5 // this->button5->Location = System::Drawing::Point(220, 8); this->button5->Name = L"button5"; this->button5->Size = System::Drawing::Size(49, 20); this->button5->TabIndex = 4;

this->button5->Text = L""; this->button5->UseVisualStyleBackColor = true; this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click); // // panel1 // this->panel1->BackColor = System::Drawing::SystemColors::GradientInactiveCaption; this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D; this->panel1->Controls->Add(this->button5); this->panel1->Controls->Add(this->button4); this->panel1->Controls->Add(this->button3); this->panel1->Controls->Add(this->button2); this->panel1->Controls->Add(this->button1); this->panel1->Dock = System::Windows::Forms::DockStyle::Top; this->panel1->Location = System::Drawing::Point(0, 0); this->panel1->Name = L"panel1"; this->panel1->Size = System::Drawing::Size(292, 39); this->panel1->TabIndex = 5; // // dataGridView1 // this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize; this->dataGridView1->Dock = System::Windows::Forms::DockStyle::Bottom; this->dataGridView1->Location = System::Drawing::Point(0, 64); this->dataGridView1->Name = L"dataGridView1"; this->dataGridView1->RowTemplate->Height = 24; this->dataGridView1->Size = System::Drawing::Size(292, 202); this->dataGridView1->TabIndex = 7; // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(27, 13); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(32, 12); this->label1->TabIndex = 8; this->label1->Text = L":"; // // label2 // this->label2->AutoSize = true; this->label2->Location = System::Drawing::Point(27, 60); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(32, 12); this->label2->TabIndex = 9; this->label2->Text = L":"; // // label3 // this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(139, 18); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(29, 12); this->label3->TabIndex = 10;

this->label3->Text = L""; // // label4 // this->label4->AutoSize = true; this->label4->Location = System::Drawing::Point(190, 18); this->label4->Name = L"label4"; this->label4->Size = System::Drawing::Size(29, 12); this->label4->TabIndex = 11; this->label4->Text = L""; // // label5 // this->label5->AutoSize = true; this->label5->Location = System::Drawing::Point(241, 18); this->label5->Name = L"label5"; this->label5->Size = System::Drawing::Size(29, 12); this->label5->TabIndex = 12; this->label5->Text = L""; // // textBox2 // this->textBox2->Location = System::Drawing::Point(134, 33); this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(35, 22); this->textBox2->TabIndex = 14; // // textBox3 // this->textBox3->Location = System::Drawing::Point(186, 33); this->textBox3->Name = L"textBox3"; this->textBox3->Size = System::Drawing::Size(34, 22); this->textBox3->TabIndex = 15; // // textBox4 // this->textBox4->Location = System::Drawing::Point(237, 33); this->textBox4->Name = L"textBox4"; this->textBox4->Size = System::Drawing::Size(34, 22); this->textBox4->TabIndex = 16; // // panel2 // this->panel2->Controls->Add(this->textBox5); this->panel2->Controls->Add(this->textBox4); this->panel2->Controls->Add(this->textBox3); this->panel2->Controls->Add(this->textBox2); this->panel2->Controls->Add(this->textBox1); this->panel2->Controls->Add(this->label5); this->panel2->Controls->Add(this->label4); this->panel2->Controls->Add(this->label3); this->panel2->Controls->Add(this->label2); this->panel2->Controls->Add(this->label1); this->panel2->Dock = System::Windows::Forms::DockStyle::Top; this->panel2->Location = System::Drawing::Point(0, 39);

this->panel2->Name = L"panel2"; this->panel2->Size = System::Drawing::Size(292, 79); this->panel2->TabIndex = 18; // // textBox5 // this->textBox5->Location = System::Drawing::Point(63, 11); this->textBox5->Name = L"textBox5"; this->textBox5->Size = System::Drawing::Size(64, 22); this->textBox5->TabIndex = 17; // // textBox1 // this->textBox1->Location = System::Drawing::Point(63, 54); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(65, 22); this->textBox1->TabIndex = 13; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 12); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(292, 266); this->Controls->Add(this->panel2); this->Controls->Add(this->dataGridView1); this->Controls->Add(this->panel1); this->Name = L"Form1"; this->Text = L""; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); this->panel1->ResumeLayout(false); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->EndInit(); this->panel2->ResumeLayout(false); this->panel2->PerformLayout(); this->ResumeLayout(false); } #pragma endregion DataView^ DviewCreate(String^ str2) {// String^ str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application::StartupPath + "\\student.mdb"; OleDbConnection^ conn; // conn OleDbDataAdapter^ adapter1; // Adapter DataSet^ DSet1 = gcnew DataSet(); // conn = gcnew OleDbConnection(str1); // conn->Open(); // adapter1 = gcnew OleDbDataAdapter(str2, conn); // Adapter adapter1->Fill(DSet1, ""); // Adapter return( DSet1->Tables[""]->DefaultView); // } private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {// String^ str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application::StartupPath +

"\\student.mdb"; String^ str2 = "Select * from "; OleDbConnection^ conn = gcnew OleDbConnection(str1); OleDbDataAdapter^ myAdapter= gcnew OleDbDataAdapter(str2, conn); DataSet^ DSet1 = gcnew DataSet(); myAdapter->Fill(DSet1, ""); textBox5->DataBindings->Add("Text", DSet1, "."); // textBox1->DataBindings->Add("Text", DSet1, "."); textBox2->DataBindings->Add("Text", DSet1, "."); textBox3->DataBindings->Add("Text", DSet1, "."); textBox4->DataBindings->Add("Text", DSet1, "."); dataGridView1->DataSource = DSet1; dataGridView1->DataMember = ""; } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {// if(textBox5->Text == "" || textBox5->Text->Length!=6 ) // MessageBox::Show("!!"); else { try { String^ str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application::StartupPath + "\\student.mdb"; String^ str2 = "Insert Into (, , , , ) Values(@, @, @, @ , @)"; String^ str3=textBox5->Text; OleDbConnection^ conn; OleDbCommand^ cmd; conn = gcnew OleDbConnection(str1); conn->Open(); cmd = gcnew OleDbCommand(str2, conn); // cmd->Parameters->Add(gcnew OleDbParameter("@", OleDbType::Char)); cmd->Parameters->Add(gcnew OleDbParameter("@", OleDbType::Char)); cmd->Parameters->Add(gcnew OleDbParameter("@", OleDbType::Integer)); cmd->Parameters->Add(gcnew OleDbParameter("@", OleDbType::Integer)); cmd->Parameters->Add(gcnew OleDbParameter("@", OleDbType::Integer)); // cmd->Parameters["@"]->Value = textBox5->Text; cmd->Parameters["@"]->Value = textBox1->Text; cmd->Parameters["@"]->Value =int::Parse(textBox2->Text); cmd->Parameters["@"]->Value =int::Parse(textBox3->Text); cmd->Parameters["@"]->Value =int::Parse(textBox4->Text); cmd->ExecuteNonQuery(); // // conn->Close(); String^ str4 = "Select * FROM WHERE = '" + textBox5->Text->Replace("'", "''") + "'"; DataView^ dv1= DviewCreate(str4); dataGridView1->DataSource =dv1; }

catch(Exception ^err) // { MessageBox::Show("!!" + err->Message); } } } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {// if(textBox5->Text == "" || textBox5->Text->Length!=6) MessageBox::Show("!!"); else { String^ str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application::StartupPath + "\\student.mdb"; String^ str2 = "Delete From Where = '" + textBox5->Text->Replace("'", "''") + "'"; OleDbConnection^ conn; OleDbCommand^ cmd; conn = gcnew OleDbConnection(str1); conn->Open(); cmd = gcnew OleDbCommand(str2, conn); if(!cmd->ExecuteNonQuery()) MessageBox::Show(", !!"); else { conn->Close(); // String^ str3 = "Select * From Order By ASC"; // DataView^ dv1= DviewCreate(str3); dataGridView1->DataSource =dv1; } } } private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {// if(textBox5->Text == "" || textBox5->Text->Length!=6) MessageBox::Show("!!"); else { try { String^ str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application::StartupPath + "\\student.mdb"; String^ str2 = "update Set = '" + textBox1->Text->Replace("'", "''") + "', =" + int::Parse(textBox2->Text) + ", =" + int::Parse(textBox3->Text) + ", =" + int::Parse(textBox4->Text) + " Where = '" + textBox5->Text->Replace("'", "''") + "'"; OleDbConnection^ conn; OleDbCommand^ cmd; conn = gcnew OleDbConnection(str1); conn->Open();

cmd = gcnew OleDbCommand(str2, conn); if(!cmd->ExecuteNonQuery()) MessageBox::Show(", !!"); else { conn->Close(); // String^ str3 = "Select * FROM WHERE = '" + textBox5->Text->Replace("'", "''") + "'"; DataView^ dv1= DviewCreate(str3); dataGridView1->DataSource =dv1; } } catch(Exception ^err) // { MessageBox::Show("!!" + err->Message); } } } private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {// if(textBox5->Text == "" || textBox5->Text->Length!=6) MessageBox::Show("!!"); else { try { String^ str2 = "Select * FROM WHERE = '" + textBox5->Text->Replace("'", "''") + "'"; DataView^ dv1= DviewCreate(str2); dataGridView1->DataSource =dv1; } catch(Exception ^err) // { MessageBox::Show("!!" + err->Message); } } } private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) { if(MessageBox::Show(L" ...",L" !",MessageBoxButtons::YesNo,MessageBoxIcon::Question) == Windows::Forms:: DialogResult ::Yes) Application::Exit(); else MessageBox::Show(" ...", "!"); } }; }

You might also like