⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subjectsetting.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 2 页
字号:
			// 
			// tBoxSubjectNameShow
			// 
			this->tBoxSubjectNameShow->Location = System::Drawing::Point(40, 88);
			this->tBoxSubjectNameShow->Name = S"tBoxSubjectNameShow";
			this->tBoxSubjectNameShow->Size = System::Drawing::Size(240, 21);
			this->tBoxSubjectNameShow->TabIndex = 1;
			this->tBoxSubjectNameShow->Text = S"";
			this->tBoxSubjectNameShow->Leave += new System::EventHandler(this, tBoxSubjectNameShow_Leave);
			// 
			// tBoxSubjectCodeShow
			// 
			this->tBoxSubjectCodeShow->Location = System::Drawing::Point(40, 40);
			this->tBoxSubjectCodeShow->Name = S"tBoxSubjectCodeShow";
			this->tBoxSubjectCodeShow->Size = System::Drawing::Size(240, 21);
			this->tBoxSubjectCodeShow->TabIndex = 0;
			this->tBoxSubjectCodeShow->Text = S"";
			this->tBoxSubjectCodeShow->Leave += new System::EventHandler(this, tBoxSubjectCodeShow_Leave);
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->label6);
			this->groupBox1->Controls->Add(this->label5);
			this->groupBox1->Controls->Add(this->label3);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Controls->Add(this->cmbBalance);
			this->groupBox1->Controls->Add(this->cmbSubjectType);
			this->groupBox1->Controls->Add(this->tBoxSubjectHelpCode);
			this->groupBox1->Controls->Add(this->tBoxSubjectNameShow);
			this->groupBox1->Controls->Add(this->tBoxSubjectCodeShow);
			this->groupBox1->Dock = System::Windows::Forms::DockStyle::Right;
			this->groupBox1->Location = System::Drawing::Point(456, 137);
			this->groupBox1->Name = S"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(312, 276);
			this->groupBox1->TabIndex = 4;
			this->groupBox1->TabStop = false;
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->btnSearch);
			this->groupBox2->Controls->Add(this->label9);
			this->groupBox2->Controls->Add(this->label10);
			this->groupBox2->Controls->Add(this->tBoxSubjectName);
			this->groupBox2->Controls->Add(this->tBoxSubjectCode);
			this->groupBox2->Dock = System::Windows::Forms::DockStyle::Top;
			this->groupBox2->Location = System::Drawing::Point(0, 41);
			this->groupBox2->Name = S"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(768, 96);
			this->groupBox2->TabIndex = 5;
			this->groupBox2->TabStop = false;
			// 
			// btnSearch
			// 
			this->btnSearch->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->btnSearch->ImageIndex = 6;
			this->btnSearch->ImageList = this->imageList1;
			this->btnSearch->Location = System::Drawing::Point(24, 40);
			this->btnSearch->Name = S"btnSearch";
			this->btnSearch->Size = System::Drawing::Size(88, 24);
			this->btnSearch->TabIndex = 37;
			this->btnSearch->Text = S"查询";
			this->btnSearch->Click += new System::EventHandler(this, btnSearch_Click);
			// 
			// label9
			// 
			this->label9->Location = System::Drawing::Point(380, 43);
			this->label9->Name = S"label9";
			this->label9->Size = System::Drawing::Size(56, 16);
			this->label9->TabIndex = 33;
			this->label9->Text = S"科目名称";
			// 
			// label10
			// 
			this->label10->Location = System::Drawing::Point(136, 46);
			this->label10->Name = S"label10";
			this->label10->Size = System::Drawing::Size(56, 16);
			this->label10->TabIndex = 32;
			this->label10->Text = S"科目代码";
			// 
			// tBoxSubjectName
			// 
			this->tBoxSubjectName->Location = System::Drawing::Point(440, 40);
			this->tBoxSubjectName->Name = S"tBoxSubjectName";
			this->tBoxSubjectName->Size = System::Drawing::Size(168, 21);
			this->tBoxSubjectName->TabIndex = 28;
			this->tBoxSubjectName->Text = S"";
			// 
			// tBoxSubjectCode
			// 
			this->tBoxSubjectCode->Location = System::Drawing::Point(200, 40);
			this->tBoxSubjectCode->Name = S"tBoxSubjectCode";
			this->tBoxSubjectCode->Size = System::Drawing::Size(168, 21);
			this->tBoxSubjectCode->TabIndex = 27;
			this->tBoxSubjectCode->Text = S"";
			// 
			// imageList1
			// 
			this->imageList1->ImageSize = System::Drawing::Size(16, 16);
			this->imageList1->ImageStream = (__try_cast<System::Windows::Forms::ImageListStreamer *  >(resources->GetObject(S"imageList1.ImageStream")));
			this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
			// 
			// SubjectSetting
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(768, 413);
			this->Controls->Add(this->dgrdSubject);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->toolBar1);
			this->Name = S"SubjectSetting";
			this->Text = S"科目设置";
			this->Load += new System::EventHandler(this, SubjectSetting_Load);
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdSubject))->EndInit();
			this->groupBox1->ResumeLayout(false);
			this->groupBox2->ResumeLayout(false);
			this->ResumeLayout(false);

		}		
private: System::Void SubjectSetting_Load(System::Object *  sender, System::EventArgs *  e)
		 {
			 this->cmSubject = __try_cast<CurrencyManager*>(this->BindingContext->Item[this->ds->Tables->Item[S"科目表"]]);
			 this->dgrdSubject->DataSource = this->ds->Tables->Item[S"科目表"];
			 this->DataGridStateControl();
			 this->DataBidings();
			 this->SetModify(false);
		 }
		 //------------------设置表格样式----------------------
		void DataGridStateControl()
		{
			DataGridTableStyle* ts = new DataGridTableStyle();
			DataGridNoActiveCellColumn* aTextColumn;
			ts->AlternatingBackColor = Color::LightGray;
			ts->MappingName = this->ds->Tables->Item[S"科目表"]->TableName;

			int numCols = this->ds->Tables->Item[S"科目表"]->Columns->Count;
			for(int i = 0;i < numCols;i++)
			{
				aTextColumn = new DataGridNoActiveCellColumn();
				aTextColumn->get_TextBox()->Enabled = false;
				aTextColumn->MappingName = this->ds->Tables->Item[S"科目表"]->Columns->Item[i]->ColumnName;
				aTextColumn->HeaderText = this->ds->Tables->Item[S"科目表"]->Columns->Item[i]->ColumnName;
				aTextColumn->NullText = S"";
				aTextColumn->Format = S"D";
				ts->GridColumnStyles->Add(aTextColumn);
			}
			this->dgrdSubject->TableStyles->Add(ts);
			this->dgrdSubject->Select(0);
		}

		//------------------设置数据绑定----------------------
        void DataBidings()
		{
			this->tBoxSubjectCodeShow->DataBindings->Add("Text",this->ds->Tables->Item[S"科目表"],"科目代码");
			this->tBoxSubjectNameShow->DataBindings->Add("Text",this->ds->Tables->Item[S"科目表"],"科目名称");
			this->tBoxSubjectHelpCode->DataBindings->Add("Text",this->ds->Tables->Item[S"科目表"],"助记码");
			this->cmbSubjectType->DataBindings->Add("Text",this->ds->Tables->Item[S"科目表"],"科目类别");
			this->cmbBalance->DataBindings->Add("Text",this->ds->Tables->Item[S"科目表"],"余额方向");			
		}
		//-----------------设置控件属性-----------------------
		void SetModify(bool isModifiable)
		{
			this->tBoxSubjectCodeShow->ReadOnly = !isModifiable;
			this->tBoxSubjectNameShow->ReadOnly = !isModifiable;
			this->tBoxSubjectHelpCode->ReadOnly = !isModifiable;
			this->cmbSubjectType->Enabled = isModifiable;
			this->cmbBalance->Enabled = isModifiable;
		}		
private: System::Void toolBar1_ButtonClick(System::Object *  sender, System::Windows::Forms::ToolBarButtonClickEventArgs *  e)
		 {
			 if(String::Compare(e->Button->ToolTipText->Trim(),S"首记录") == 0)
			 {
				 this->dgrdSubject->UnSelect(this->cmSubject->Position);
				 this->cmSubject->Position = 0;
				 this->dgrdSubject->Select(this->cmSubject->Position);
				 this->dgrdSubject->CurrentRowIndex = this->cmSubject->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"上一记录") == 0)
			 {
				 if(this->cmSubject->Position > 0)
				 {
					 this->dgrdSubject->UnSelect(this->cmSubject->Position);
					 this->cmSubject->Position--;
					 this->dgrdSubject->Select(this->cmSubject->Position);
					 this->dgrdSubject->CurrentRowIndex = this->cmSubject->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"下一记录") == 0)
			 {
				 if(this->cmSubject->Position < this->cmSubject->Count - 1)
				 {
					 this->dgrdSubject->UnSelect(this->cmSubject->Position);
					 this->cmSubject->Position++;
					 this->dgrdSubject->Select(this->cmSubject->Position);
					 this->dgrdSubject->CurrentRowIndex = this->cmSubject->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"尾记录") == 0)
			 {
				 this->dgrdSubject->UnSelect(this->cmSubject->Position);
				 this->cmSubject->Position = this->cmSubject->Count - 1;
				 this->dgrdSubject->Select(this->cmSubject->Position);
				 this->dgrdSubject->CurrentRowIndex = this->cmSubject->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"新增记录") == 0)
			 {					 
				 this->cmSubject->AddNew();
				 this->cmbSubjectType->SelectedIndex = 0;
				 this->cmbBalance->SelectedIndex = 0;
				 this->SetModify(true);				
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"修改记录") == 0)
			 {					 
				 this->SetModify(true);				
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"删除记录") == 0)
			 {
				 //修改数据库
				 String* tempSQL = String::Format(S"Delete from 科目余额表 where 科目代码 = '{0}'",this->tBoxSubjectCodeShow->Text);
				 this->MyDataBase->SQLOperate(tempSQL);
				 tempSQL = String::Format(S"Delete from 本期汇总帐簿 where 科目代码 = '{0}'",this->tBoxSubjectCodeShow->Text);
				 this->MyDataBase->SQLOperate(tempSQL);
				 tempSQL = String::Format(S"Delete from 本期明细帐簿 where 科目代码 = '{0}'",this->tBoxSubjectCodeShow->Text);
				 this->MyDataBase->SQLOperate(tempSQL);
				 tempSQL = String::Format(S"Delete from 分录表 where 科目代码 = '{0}'",this->tBoxSubjectCodeShow->Text);
				 this->MyDataBase->SQLOperate(tempSQL);
				 tempSQL = String::Format(S"Delete from 分录表历史 where 科目代码 = '{0}'",this->tBoxSubjectCodeShow->Text);
				 this->MyDataBase->SQLOperate(tempSQL);
				 tempSQL = String::Format(S"Delete from 帐簿初始化表 where 科目代码 = '{0}'",this->tBoxSubjectCodeShow->Text);
				 this->MyDataBase->SQLOperate(tempSQL);
				  
				 tempSQL = String::Format(S"Delete from 科目表 where 科目代码 = '{0}' AND 科目名称 = '{1}'",this->tBoxSubjectCodeShow->Text,this->tBoxSubjectNameShow->Text);
				 this->MyDataBase->SQLOperate(tempSQL);
				 //修改数据集
				 this->cmSubject->RemoveAt(this->cmSubject->Position);
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"保存修改") == 0)
			 {
				 //检查新记录
				 if(this->tBoxSubjectCodeShow->Text->Trim() == S"")
				 {
					 MessageBox::Show(S"科目代码不能为空",S"提示");
					 return;
				 }
				 if(this->tBoxSubjectNameShow->Text->Trim() == S"")
				 {
					 MessageBox::Show(S"科目名称不能为空",S"提示");
					 return;
				 }
				 //提交修改
				 this->cmSubject->EndCurrentEdit();
				 //更新数据库
				 SqlCommandBuilder* sqlCmdBld = new SqlCommandBuilder(this->SubjectAdapter);
				 if(this->ds->HasChanges(DataRowState::Modified))
					 this->SubjectAdapter->Update(this->ds->GetChanges(DataRowState::Modified),S"科目表");
				 if(this->ds->HasChanges(DataRowState::Added))
					 this->SubjectAdapter->Update(this->ds->GetChanges(DataRowState::Added),S"科目表");
				 this->ds->AcceptChanges();

				 this->SetModify(false);
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"取消修改") == 0)
			 {
				 this->cmSubject->CancelCurrentEdit();
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"退出") == 0)
			 {
				 if(MessageBox::Show(S"是否保存数据?",S"确认",MessageBoxButtons::OKCancel) == DialogResult::OK)
				 {
					 //提交修改
					 this->cmSubject->EndCurrentEdit();
					 //更新数据库
					 this->MyDataBase->UpdateDataBase(this->SubjectAdapter,this->ds,S"科目表");
				 }
				 this->Close();
			 }
		 }

private: System::Void tBoxSubjectCodeShow_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 //检查新记录
			 if(this->tBoxSubjectCodeShow->Text->Trim() == S"")
			 {
				 MessageBox::Show(S"科目代码不能为空",S"提示");
				 this->tBoxSubjectCodeShow->Focus();
				 return;
			 }
		 }

private: System::Void tBoxSubjectNameShow_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(this->tBoxSubjectNameShow->Text->Trim() == S"")
			 {
				 MessageBox::Show(S"科目名称不能为空",S"提示");
				 this->tBoxSubjectNameShow->Focus();
				 return;
			 }
		 }

private: System::Void btnSearch_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 this->ds->Tables->Item[S"科目表"]->Clear();
			 this->strSQL = String::Format( S"SELECT * FROM  科目表 WHERE 科目代码 like '%{0}%'AND 科目名称 like '%{1}%'",this->tBoxSubjectCode->Text,this->tBoxSubjectName->Text);
			 this->strTableName = S"科目表";
			 this->MyDataBase->SelectDataBase(this->SubjectAdapter,this->ds,this->strSQL,this->strTableName);
		 }

};
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -