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

📄 readerinfo.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 3 页
字号:
			this->label7->Size = System::Drawing::Size(56, 11);
			this->label7->TabIndex = 3;
			this->label7->Text = S"编号";
			// 
			// label29
			// 
			this->label29->Location = System::Drawing::Point(496, 32);
			this->label29->Name = S"label29";
			this->label29->Size = System::Drawing::Size(56, 11);
			this->label29->TabIndex = 8;
			this->label29->Text = S"类型";
			// 
			// cmbReaderClass
			// 
			this->cmbReaderClass->Location = System::Drawing::Point(496, 48);
			this->cmbReaderClass->Name = S"cmbReaderClass";
			this->cmbReaderClass->Size = System::Drawing::Size(104, 20);
			this->cmbReaderClass->TabIndex = 7;
			// 
			// label30
			// 
			this->label30->Location = System::Drawing::Point(496, 88);
			this->label30->Name = S"label30";
			this->label30->Size = System::Drawing::Size(80, 11);
			this->label30->TabIndex = 16;
			this->label30->Text = S"期刊借阅次数";
			// 
			// tBoxMagazineBorrowTimes
			// 
			this->tBoxMagazineBorrowTimes->Location = System::Drawing::Point(496, 104);
			this->tBoxMagazineBorrowTimes->Name = S"tBoxMagazineBorrowTimes";
			this->tBoxMagazineBorrowTimes->Size = System::Drawing::Size(104, 21);
			this->tBoxMagazineBorrowTimes->TabIndex = 12;
			this->tBoxMagazineBorrowTimes->Text = S"";
			// 
			// ReaderInfo
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(760, 469);
			this->Controls->Add(this->dgrdReaders);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->toolBar1);
			this->Name = S"ReaderInfo";
			this->Text = S"读者档案管理";
			this->groupBox1->ResumeLayout(false);
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdReaders))->EndInit();
			this->groupBox2->ResumeLayout(false);
			this->ResumeLayout(false);

		}		
	private:
		//----------------设置控件ReadOnly属性------------------------
		void SetModify(bool isModifiable)
		{
			this->tBoxBarCodeShow->ReadOnly = !isModifiable;
			this->tBoxReaderIDShow->ReadOnly = !isModifiable;
			this->tBoxReaderNameShow->ReadOnly = !isModifiable;
			this->tBoxContactation->ReadOnly = !isModifiable;
			this->tBoxCertificateNumber->ReadOnly = !isModifiable;
			this->tBoxBookBorrowTimes->ReadOnly = !isModifiable;
			this->tBoxMagazineBorrowTimes->ReadOnly = !isModifiable;
			this->tBoxOperator->ReadOnly = !isModifiable;
			this->tBoxMemo->ReadOnly = !isModifiable;

			this->chkIsReportToLost->Enabled = isModifiable;
			
			this->cmbSex->Enabled = isModifiable;
			this->cmbReaderClass->Enabled = isModifiable;
			this->cmbValidCertificate->Enabled = isModifiable;

			this->dtpBirthday->Enabled = isModifiable;
			this->dtpRegisterDate->Enabled = isModifiable;
			this->dtpValidate->Enabled = isModifiable;

			this->btnSearch->Enabled = !isModifiable;

			//this->dgrdReaders->ReadOnly = !isModifiable;
		}
		//---------------------设置控件的数据邦定--------------------------
		void SetDataBindings()
		{
			this->tBoxBarCodeShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"条形码");
			this->tBoxReaderIDShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"编号");
			this->tBoxReaderNameShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"姓名");
			this->tBoxContactation->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"联系方式");
			this->tBoxCertificateNumber->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"证件号码");
			this->tBoxBookBorrowTimes->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"图书借阅次数");
			this->tBoxMagazineBorrowTimes->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"期刊借阅次数");
			this->tBoxOperator->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"操作员");
			this->tBoxMemo->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"备注");

			this->chkIsReportToLost->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"读者信息"],S"是否挂失");
			
			this->cmbSex->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"性别");
			this->cmbReaderClass->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"类型");
			this->cmbValidCertificate->DataBindings->Add(S"Text",this->ds->Tables->Item[S"读者信息"],S"有效证件");

			this->dtpBirthday->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"出生日期");
			this->dtpRegisterDate->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"登记日期");
			this->dtpValidate->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"有限期至");
			
		}
		//-----------------------设置表格各列的属性-----------------------
		void DataGridStateControl()
		{

			DataGridTableStyle* ts = new DataGridTableStyle();			
			ts->MappingName = this->ds->Tables->Item[S"读者信息"]->TableName;
			
			DataGridNoActiveCellColumn* aTextColumn;
			ts->AllowSorting = false;
			ts->AlternatingBackColor = Color::LightGray;

			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->dgrdReaders->TableStyles->Add(ts);
  		 }
		//-----------------------工具栏按钮-----------------------
	private:System::Void toolBar1_ButtonClick(System::Object *  sender, System::Windows::Forms::ToolBarButtonClickEventArgs *  e)
		 {
			 //设置控件属性
			 this->SetModify(false);

			 if(String::Compare(e->Button->ToolTipText,S"首记录") == 0)
			 {
				 this->dgrdReaders->UnSelect(this->cmReader->Position);
				 this->cmReader->Position = 0;
				 this->dgrdReaders->Select(this->cmReader->Position);
				 this->dgrdReaders->CurrentRowIndex = this->cmReader->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"上一记录") == 0)
			 {
				 if(this->cmReader->Position > 0)
				 {
					 this->dgrdReaders->UnSelect(this->cmReader->Position);
					 this->cmReader->Position--;
					 this->dgrdReaders->Select(this->cmReader->Position);
					 this->dgrdReaders->CurrentRowIndex = this->cmReader->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"下一记录") == 0)
			 {
				 if(this->cmReader->Position < this->cmReader->Count)
				 {
					 this->dgrdReaders->UnSelect(this->cmReader->Position);
					 this->cmReader->Position++;
					 this->dgrdReaders->Select(this->cmReader->Position);
					 this->dgrdReaders->CurrentRowIndex = this->cmReader->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"尾记录") == 0)
			 {
				 this->dgrdReaders->UnSelect(this->cmReader->Position);
				 this->cmReader->Position = this->cmReader->Count;
				 this->dgrdReaders->Select(this->cmReader->Position);
				 this->dgrdReaders->CurrentRowIndex = this->cmReader->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
			 {
				 this->chkIsReportToLost->DataBindings->Clear();

				 this->dtpBirthday->DataBindings->Clear();
				 this->dtpRegisterDate->DataBindings->Clear();
				 this->dtpValidate->DataBindings->Clear();

				 this->cmReader->AddNew();
				 this->SetModify(true);

				 //设置默认值
				 //设置编号
				 String* tempSQL = S"Select max(编号) 最大编号 from 读者信息";
				 SqlCommand* sqlCmd = new SqlCommand(tempSQL,this->MyDataBase->myConnection);
				 int MaxID = 1;
				 Object* r = sqlCmd->ExecuteScalar();
				 if(r != System::DBNull::Value)
					 MaxID = System::Convert::ToInt32(r) + 1;
				 int length = MaxID.ToString()->Length;
				 switch(length)
				 {
				 case 1:
					 this->tBoxReaderIDShow->Text = String::Format(S"000{0}",MaxID.ToString()->Trim());
					 break;
				 case 2:
					 this->tBoxReaderIDShow->Text = String::Format(S"00{0}",MaxID.ToString()->Trim());
					 break;
				 case 3:
					 this->tBoxReaderIDShow->Text = String::Format(S"0{0}",MaxID.ToString()->Trim());
					 break;
				 case 4:
					 this->tBoxReaderIDShow->Text = String::Format(S"{0}",MaxID.ToString()->Trim());
					 break;
				 }
				 //设置类型
				 this->cmbReaderClass->SelectedIndex = 0;
				 this->cmReader->EndCurrentEdit();
				 
				 int row = this->cmReader->Count - 1;
				 this->ds->Tables->Item[S"读者信息"]->Rows->Item[row]->Item[S"是否挂失"] = __box(false);
				 this->ds->Tables->Item[S"读者信息"]->Rows->Item[row]->Item[S"出生日期"] = System::DateTime::Now.Date.ToString();
				 this->ds->Tables->Item[S"读者信息"]->Rows->Item[row]->Item[S"登记日期"] = System::DateTime::Now.Date.ToString();
				 this->ds->Tables->Item[S"读者信息"]->Rows->Item[row]->Item[S"有限期至"] = System::DateTime::Now.Date.ToString();

				 this->chkIsReportToLost->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"读者信息"],S"是否挂失");

				 this->dtpBirthday->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"出生日期");
				 this->dtpRegisterDate->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"登记日期");
				 this->dtpValidate->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"有限期至");
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"修改") == 0)
			 {
				 this->SetModify(true);
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"删除") == 0)
			 {
				 System::Windows::Forms::DialogResult r = MessageBox::Show(S"确定删除?",S"删除数据",MessageBoxButtons::OKCancel);
				 if(r == DialogResult::OK)
				 {
					 if(this->cmReader->Count > 0)
						 this->cmReader->RemoveAt(this->cmReader->Position);
					 else
						 MessageBox::Show(S"表格已空,无可删除数据",S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
			 {
				 this->cmReader->EndCurrentEdit();
				 this->MyDataBase->UpdateDataBase(this->ReaderAdapter,this->ds,S"读者信息");
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
			 {
				 try
				 {
					 this->cmReader->CancelCurrentEdit();
				 }
				 catch(Exception* e)
				 {
					 MessageBox::Show(e->Message,S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"退出") == 0)
			 {
				 this->Close();
			 }
		 }
		 //按条件查询
private: System::Void btnSearch_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 this->chkIsReportToLost->DataBindings->Clear();

			 this->dtpBirthday->DataBindings->Clear();
			 this->dtpRegisterDate->DataBindings->Clear();
			 this->dtpValidate->DataBindings->Clear();

			 String* strReaderID = this->tBoxReaderID->Text->Trim();
			 String* strReaderName = this->tBoxReaderName->Text->Trim();
			 String* strBarCode = this->tBoxBarCode->Text->Trim();
			 String* Filter = S"";
			 if(String::Compare(strReaderID,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (编号 LIKE '%{1}%')",Filter,strReaderID);
			 }
			 if(String::Compare(strReaderName,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (姓名 LIKE '%{1}%')",Filter,strReaderName);
			 }
			 if(String::Compare(strBarCode,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (条形码 LIKE '%{1}%')",Filter,strBarCode);
			 }

			 this->ds->Tables->Item[S"读者信息"]->Clear();

			 if(String::Compare(Filter,String::Empty) != 0)
			 {
				 Filter = Filter->Substring(5,Filter->Length - 5);
				 
				 //查询读者信息				 
				 this->strSQL = String::Format(S"Select * from 读者信息 where {0}",Filter);
				 this->strTableName = S"读者信息";
				 this->MyDataBase->SelectDataBase(this->ReaderAdapter,this->ds,this->strSQL,this->strTableName);    				
			 }
			 else
			 {
				 //查询读者信息
				 this->strSQL = S"Select * from 读者信息";
				 this->strTableName = S"读者信息";
				 this->MyDataBase->SelectDataBase(this->ReaderAdapter,this->ds,this->strSQL,this->strTableName);            
			 }
			 this->chkIsReportToLost->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"读者信息"],S"是否挂失");

			 this->dtpBirthday->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"出生日期");
			 this->dtpRegisterDate->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"登记日期");
			 this->dtpValidate->DataBindings->Add(S"Value",this->ds->Tables->Item[S"读者信息"],S"有限期至");
		 }

		 //读者编号不能为空
private: System::Void tBoxReaderIDShow_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->tBoxReaderIDShow->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"编号不能为空",S"提示");
					 this->tBoxReaderIDShow->Focus();
				 }
		 }

};
}

⌨️ 快捷键说明

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