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

📄 booksubscribe.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 3 页
字号:
			this->tBoxOrderCodeShow->ReadOnly = !isModifiable;
			this->tBoxBookIDShow->ReadOnly = !isModifiable;
			this->tBoxBookName->ReadOnly = !isModifiable;
			this->tBoxOderBy->ReadOnly = !isModifiable;
			this->tBoxOperator->ReadOnly = !isModifiable;
			this->tBoxOrderQuantity->ReadOnly = !isModifiable;
			this->tBoxOrderPrice->ReadOnly = !isModifiable;
			this->tBoxContact->ReadOnly = !isModifiable;	
			

			this->chkIsChecked->Enabled = false;
			
			this->dtpOrderDate->Enabled = isModifiable;			

			this->btnSearch->Enabled = !isModifiable;

			this->dgrdBooks->ReadOnly = !isModifiable;
		}
		//---------------------设置控件的数据邦定--------------------------
		void SetDataBindings()
		{
			this->tBoxOrderCodeShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书征订"],S"征订编号");
			this->tBoxBookIDShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书征订"],S"图书编号");			
			this->tBoxOderBy->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书征订"],S"订购者");
			this->tBoxOperator->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书征订"],S"操作员");
			this->tBoxOrderQuantity->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书征订"],S"订购数量");
			this->tBoxOrderPrice->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书征订"],S"订购单价");
			this->tBoxContact->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书征订"],S"订购者联系方式");			

			this->chkIsChecked->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"图书征订"],S"是否验收");
			
			this->dtpOrderDate->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书征订"],S"订购日期");						
		}
		//-----------------------设置表格各列的属性-----------------------
		void DataGridStateControl()
		{

			DataGridTableStyle* ts = new DataGridTableStyle();			
			ts->MappingName = this->ds->Tables->Item[S"图书征订"]->TableName;
			
			DataGridTextBoxColumn* 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 DataGridTextBoxColumn();
				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 = String::Empty;
				//aTextColumn->Format = S"D";
				ts->GridColumnStyles->Add(aTextColumn);
			}

			this->dgrdBooks->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->dgrdBooks->UnSelect(this->cmBook->Position);
				 this->cmBook->Position = 0;
				 this->dgrdBooks->Select(this->cmBook->Position);
				 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"上一记录") == 0)
			 {
				 if(this->cmBook->Position > 0)
				 {
					 this->dgrdBooks->UnSelect(this->cmBook->Position);
					 this->cmBook->Position--;
					 this->dgrdBooks->Select(this->cmBook->Position);
					 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"下一记录") == 0)
			 {
				 if(this->cmBook->Position < this->cmBook->Count)
				 {
					 this->dgrdBooks->UnSelect(this->cmBook->Position);
					 this->cmBook->Position++;
					 this->dgrdBooks->Select(this->cmBook->Position);
					 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"尾记录") == 0)
			 {
				 this->dgrdBooks->UnSelect(this->cmBook->Position);
				 this->cmBook->Position = this->cmBook->Count + 1;
				 this->dgrdBooks->Select(this->cmBook->Position);
				 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
			 {
				 this->cmBook->SuspendBinding();
				 /*this->dgrdBooks->UnSelect(this->cmBook->Position);
				 DataRow* row = this->ds->Tables->Item[S"图书征订"]->NewRow();
				 row->Item["是否验收"] = __box(false);
				 row->Item["订购日期"] = __box(System::DateTime::Now.Date);
				 this->ds->Tables->Item[S"图书征订"]->Rows->Add(row);
				 */

				 this->cmBook->AddNew();
				 this->cmBook->EndCurrentEdit();
				 this->ds->Tables->Item[S"图书征订"]->Rows->Item[this->cmBook->Position]->Item["是否验收"] = __box(false);
				 this->ds->Tables->Item[S"图书征订"]->Rows->Item[this->cmBook->Position]->Item["订购日期"] = __box(System::DateTime::Now.Date);
				 this->cmBook->ResumeBinding();
				 //this->chkIsChecked->Checked = false;
				 //this->dtpOrderDate->Value = System::DateTime::Now.Date;
				 this->SetModify(true);

				 
				 this->cmBook->Position = this->cmBook->Count - 1;
				 this->dgrdBooks->Select(this->cmBook->Position);
				 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;

				 //设置默认值
				 //设置编号
				 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->tBoxOrderCodeShow->Text = String::Format(S"000000{0}",MaxID.ToString()->Trim());
					 break;
				 case 2:
					 this->tBoxOrderCodeShow->Text = String::Format(S"00000{0}",MaxID.ToString()->Trim());
					 break;
				 case 3:
					 this->tBoxOrderCodeShow->Text = String::Format(S"0000{0}",MaxID.ToString()->Trim());
					 break;
				 case 4:
					 this->tBoxOrderCodeShow->Text = String::Format(S"000{0}",MaxID.ToString()->Trim());
					 break;
				 case 5:
					 this->tBoxOrderCodeShow->Text = String::Format(S"00{0}",MaxID.ToString()->Trim());
					 break;
				 case 6:
					 this->tBoxOrderCodeShow->Text = String::Format(S"0{0}",MaxID.ToString()->Trim());
					 break;
				 }	
				 
			 }
			 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->cmBook->Count > 0)
						 this->cmBook->RemoveAt(this->cmBook->Position);
					 else
						 MessageBox::Show(S"表格已空,无可删除数据",S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
			 {
				 this->cmBook->EndCurrentEdit();
				 this->MyDataBase->UpdateDataBase(this->BookAdapter,this->ds,S"图书征订");
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
			 {
				 try
				 {
					 this->cmBook->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)
		 {
			 String* strBookID = this->tBoxBookID->Text->Trim();
			 String* strOrderCode = this->tBoxOrderCode->Text->Trim();
			 String* Filter = S"";
			 if(String::Compare(strBookID,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (图书编号 LIKE '%{1}%')",Filter,strBookID);
			 }
			 if(String::Compare(strOrderCode,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (征订编号 LIKE '%{1}%')",Filter,strOrderCode);
			 }

			 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} AND 是否验收 = 0",Filter);
				 this->strTableName = S"图书征订";
				 this->MyDataBase->SelectDataBase(this->BookAdapter,this->ds,this->strSQL,this->strTableName);           
			 }
			 else
			 {
				 //查询图书征订
				 this->strSQL = S"Select * from 图书征订";
				 this->strTableName = S"图书征订";
				 this->MyDataBase->SelectDataBase(this->BookAdapter,this->ds,this->strSQL,this->strTableName);            
			 }
		 }

		 

		//-------------检查征订编号---------------
private: System::Void tBoxOrderCodeShow_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 //编号不能为空
			 if(String::Compare(this->tBoxOrderCodeShow->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"编号不能为空",S"提示");
					 this->tBoxOrderCodeShow->Focus();
				 }
		 }
		 //-----------提交图书征订----------------
private: System::Void btnSubmitOrder_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 //调用存储过程
			 String* tempSQL = S"exec sf_图书征订";
			 this->MyDataBase->SQLOperate(tempSQL);
			 //刷新数据集
			 tempSQL = this->BookAdapter->SelectCommand->CommandText;
			 this->ds->Clear();
			 this->MyDataBase->SelectDataBase(this->BookAdapter,this->ds,tempSQL,S"图书征订");
		 }
		 //-----------选择图书----------------
private: System::Void tBoxBookName_DoubleClick(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(this->tBoxBookName->ReadOnly == false)
			 {
				 //当数据表处于编辑状态时才能选择图书
				 SelectBook* newFrm = new SelectBook();
				 if(newFrm->ShowDialog(this) == DialogResult::OK)
				 {
					 this->tBoxBookIDShow->Text = newFrm->strBookID;
					 this->tBoxBookName->Text = newFrm->strBookName;
				 }
			 }
		 }
		 //显示图书名称
private: System::Void tBoxBookIDShow_TextChanged(System::Object *  sender, System::EventArgs *  e)
		 {
			 String* Filter = String::Format(S"编号 = '{0}'",this->tBoxBookIDShow->Text);
			 DataRow* rows[] = this->ds->Tables->Item[S"图书信息"]->Select(Filter);
			 if(rows->Length > 0)
			 {
				 this->tBoxBookName->Text = rows[0]->Item[S"书名"]->ToString();
			 }
			 
		 }



};
}

⌨️ 快捷键说明

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