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

📄 hotelreserve.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 4 页
字号:
			this->tBoxRoomPrice->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"客房价格");
			this->tBoxRealPrice->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"入住价格");
			this->tBoxDiscount->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"折扣");
			this->tBoxDiscountCause->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"折扣原因");
			this->tBoxSettleNumber->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"入住人数");
			this->tBoxAdditionalBedPrice->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"加床价格");
			this->tBoxPreDeal->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"预收款");
			this->tBoxOderStatus->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"单据状态");
			this->tBoxOderShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"预定人");
			this->tBoxOP->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"业务员");
			this->tBoxMemberID->DataBindings->Add(S"Text",this->ds->Tables->Item[S"预定单"],S"会员编号");
			this->tBoxOderCompany->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->chkIsAdditionalBed->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"预定单"],S"是否加床");
			
			this->cmbRoomType->DataBindings->Add(S"SelectedValue",this->ds->Tables->Item[S"预定单"],S"客房类型");

			this->dtpArrival->DataBindings->Add(S"Value",this->ds->Tables->Item[S"预定单"],S"抵店时间");
			this->dtpDeparture->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"";
				ts->GridColumnStyles->Add(aTextColumn);
			}

			this->dgrdOder->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->dgrdOder->UnSelect(this->cmOder->Position);
				 this->cmOder->Position = 0;
				 this->dgrdOder->Select(this->cmOder->Position);
				 this->dgrdOder->CurrentRowIndex = this->cmOder->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"上一记录") == 0)
			 {
				 if(this->cmOder->Position > 0)
				 {
					 this->dgrdOder->UnSelect(this->cmOder->Position);
					 this->cmOder->Position--;
					 this->dgrdOder->Select(this->cmOder->Position);
					 this->dgrdOder->CurrentRowIndex = this->cmOder->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"下一记录") == 0)
			 {
				 if(this->cmOder->Position < this->cmOder->Count)
				 {
					 this->dgrdOder->UnSelect(this->cmOder->Position);
					 this->cmOder->Position++;
					 this->dgrdOder->Select(this->cmOder->Position);
					 this->dgrdOder->CurrentRowIndex = this->cmOder->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"尾记录") == 0)
			 {
				 this->dgrdOder->UnSelect(this->cmOder->Position);
				 this->cmOder->Position = this->cmOder->Count;
				 this->dgrdOder->Select(this->cmOder->Position);
				 this->dgrdOder->CurrentRowIndex = this->cmOder->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
			 {
				 this->chkIsAdditionalBed->DataBindings->Clear();

				 this->dtpArrival->DataBindings->Clear();
				 this->dtpDeparture->DataBindings->Clear();

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


				 //设置默认值
				 //设置编号
				 String* tempSQL ;
				 if(this->ds->Tables->Item[S"预定单"]->Rows->Count == 0)
					 tempSQL = S"Select max(预定单号) 最大编号 from 预定单历史";
				 else
					 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)
				 {
					 String* temp = r->ToString();
					 MaxID = System::Convert::ToInt32(temp->Substring(2,temp->Length - 2)) + 1;
				 }
				 int length = MaxID.ToString()->Length;
				 switch(length)
				 {
				 case 1:
					 this->tBoxOderIDShow->Text = String::Format(S"YD0000000{0}",MaxID.ToString()->Trim());
					 break;
				 case 2:
					 this->tBoxOderIDShow->Text = String::Format(S"YD000000{0}",MaxID.ToString()->Trim());
					 break;
				 case 3:
					 this->tBoxOderIDShow->Text = String::Format(S"YD00000{0}",MaxID.ToString()->Trim());
					 break;
				 case 4:
					 this->tBoxOderIDShow->Text = String::Format(S"YD0000{0}",MaxID.ToString()->Trim());
					 break;
				case 5:
					 this->tBoxOderIDShow->Text = String::Format(S"YD000{0}",MaxID.ToString()->Trim());
					 break;
				 case 6:
					 this->tBoxOderIDShow->Text = String::Format(S"YD00{0}",MaxID.ToString()->Trim());
					 break;
				 case 7:
					 this->tBoxOderIDShow->Text = String::Format(S"YD0{0}",MaxID.ToString()->Trim());
					 break;
				 }
				 //设置类型
				 this->cmbRoomType->SelectedIndex = 0;
				 //设置单据状态
				 this->tBoxOderStatus->Text = S"预订";

				 this->cmOder->EndCurrentEdit();
				 int row = this->cmOder->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->chkIsAdditionalBed->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"预定单"],S"是否加床");

				 this->dtpArrival->DataBindings->Add(S"Value",this->ds->Tables->Item[S"预定单"],S"抵店时间");
				 this->dtpDeparture->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->cmOder->Count > 0)
						 this->cmOder->RemoveAt(this->cmOder->Position);
					 else
						 MessageBox::Show(S"表格已空,无可删除数据",S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
			 {
				 this->cmOder->EndCurrentEdit();
				 this->MyDataBase->UpdateDataBase(this->OderAdapter,this->ds,S"预定单");
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
			 {
				 try
				 {
					 this->cmOder->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* strOderID = this->tBoxOderID->Text->Trim();
			 String* strArrival = this->tBoxArrival->Text->Trim();
			 String* strOder = this->tBoxOder->Text->Trim();
			 String* Filter = S"";
			 if(String::Compare(strOderID,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (预定单号 LIKE '%{1}%')",Filter,strOderID);
			 }
			 if(String::Compare(strArrival,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (抵店时间 = {1})",Filter,strArrival);
			 }
			 if(String::Compare(strOder,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (预定人 LIKE '{1}' OR 预定人 IS NULL)",Filter,strOder);
			 }

			 //this->ds->Tables->Item[S"预定单"]->Clear();

			 this->dtpArrival->DataBindings->Clear();
			 this->dtpDeparture->DataBindings->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->OderAdapter,this->ds,this->strSQL,this->strTableName);           
				 */
				 this->ds->Tables->Item[S"预定单"]->DefaultView->RowFilter = Filter;
				 int n = this->ds->Tables->Item[S"预定单"]->Rows->Count;
			 }
			 else
			 {
				this->ds->Tables->Item[S"预定单"]->DefaultView->RowFilter = S"";
			 }
			 this->dtpArrival->DataBindings->Add(S"Value",this->ds->Tables->Item[S"预定单"],S"抵店时间");
			 this->dtpDeparture->DataBindings->Add(S"Value",this->ds->Tables->Item[S"预定单"],S"离店时间");
		 }
		 //选择客房
private: System::Void btnFindRoom_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 RoomStatus* newFrm = new RoomStatus(true);
			 if(newFrm->ShowDialog(this) == DialogResult::OK)
			 {
				 //只能选择空房
				 if(newFrm->strRoomStatus != S"空房")
				 {
					 MessageBox::Show(S"请选择空的房间");
					 return;
				 }
				 else
				 {
					 this->tBoxRoomID->Text = newFrm->strRoomID;
					 this->cmbRoomType->Text = newFrm->strRoomType;
					 String* Filter = String::Format(S"类型名称 = '{0}'",newFrm->strRoomType);
					 DataRow* rows[] = this->ds->Tables->Item[S"客房类型"]->Select(Filter);
					 if(rows->Length > 0)
					 {
						 this->tBoxRoomPrice->Text = rows[0]->Item[S"价格"]->ToString();
					 }
				 }
			 }
		 }
		 //预定单号不能为空
private: System::Void tBoxOderIDShow_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->tBoxOderIDShow->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"预定单号不能为空",S"提示");
					 this->tBoxOderIDShow->Focus();
				 }
		 }
		 //客房编号不能为空
private: System::Void tBoxRoomID_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->tBoxRoomID->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"客房编号不能为空",S"提示");
					 this->tBoxRoomID->Focus();
				 }				 
		 }
		 //更新客房状态
private: static void UpdateOder(Object* sender, SqlRowUpdatingEventArgs* e)
		{
			if(e->StatementType == StatementType::Delete)
				return;
			String* strRoomID = e->Row->Item[S"客房编号"]->ToString()->Trim();
			String* tempSQL = String::Format(S"Update 客房信息 SET 状态 = '将到' Where 客房编号 = '{0}'",strRoomID);
			SqlConnection* connection = new SqlConnection(S"workstation id=localhost;Integrated Security=SSPI;database=hotelbook");
			connection->Open();
			SqlCommand* SqlCmd = new SqlCommand(tempSQL,connection);			
			SqlCmd->ExecuteNonQuery();
			
		}

};
}

⌨️ 快捷键说明

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