📄 roominfo.h
字号:
this->label7->Text = S"客房类型";
//
// cmbRoomType
//
this->cmbRoomType->Location = System::Drawing::Point(136, 48);
this->cmbRoomType->Name = S"cmbRoomType";
this->cmbRoomType->Size = System::Drawing::Size(152, 20);
this->cmbRoomType->TabIndex = 7;
//
// RoomInfo
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(760, 389);
this->Controls->Add(this->dgrdRoom);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->toolBar1);
this->Name = S"RoomInfo";
this->Text = S"客房信息设置";
this->groupBox1->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdRoom))->EndInit();
this->groupBox2->ResumeLayout(false);
this->ResumeLayout(false);
}
private:
//----------------设置控件ReadOnly属性------------------------
void SetModify(bool isModifiable)
{
this->tBoxRoomIDShow->ReadOnly = !isModifiable;
this->tBoxCapacity->ReadOnly = !isModifiable;
this->tBoxBedInRoom->ReadOnly = !isModifiable;
this->tBoxStatus->ReadOnly = true;
this->tBoxRoomDiscribe->ReadOnly = !isModifiable;
this->tBoxMemo->ReadOnly = !isModifiable;
this->chkIsCanCombine->Enabled = isModifiable;
this->cmbRoomType->Enabled = isModifiable;
this->cmbFloor->Enabled = isModifiable;
this->btnSearch->Enabled = !isModifiable;
this->dgrdRoom->ReadOnly = !isModifiable;
}
//---------------------设置控件的数据邦定--------------------------
void SetDataBindings()
{
this->tBoxRoomIDShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"客房信息"],S"客房编号");
this->tBoxCapacity->DataBindings->Add(S"Text",this->ds->Tables->Item[S"客房信息"],S"额定人数");
this->tBoxBedInRoom->DataBindings->Add(S"Text",this->ds->Tables->Item[S"客房信息"],S"床数");
this->tBoxStatus->DataBindings->Add(S"Text",this->ds->Tables->Item[S"客房信息"],S"状态");
this->tBoxRoomDiscribe->DataBindings->Add(S"Text",this->ds->Tables->Item[S"客房信息"],S"客房描述");
this->tBoxMemo->DataBindings->Add(S"Text",this->ds->Tables->Item[S"客房信息"],S"备注");
this->chkIsCanCombine->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"客房信息"],S"是否可拼房");
this->cmbRoomType->DataBindings->Add(S"SelectedValue",this->ds->Tables->Item[S"客房信息"],S"类型编号");
this->cmbFloor->DataBindings->Add(S"SelectedValue",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->dgrdRoom->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->dgrdRoom->UnSelect(this->cmRoom->Position);
this->cmRoom->Position = 0;
this->dgrdRoom->Select(this->cmRoom->Position);
this->dgrdRoom->CurrentRowIndex = this->cmRoom->Position;
}
else if(String::Compare(e->Button->ToolTipText,S"上一记录") == 0)
{
if(this->cmRoom->Position > 0)
{
this->dgrdRoom->UnSelect(this->cmRoom->Position);
this->cmRoom->Position--;
this->dgrdRoom->Select(this->cmRoom->Position);
this->dgrdRoom->CurrentRowIndex = this->cmRoom->Position;
}
}
else if(String::Compare(e->Button->ToolTipText,S"下一记录") == 0)
{
if(this->cmRoom->Position < this->cmRoom->Count)
{
this->dgrdRoom->UnSelect(this->cmRoom->Position);
this->cmRoom->Position++;
this->dgrdRoom->Select(this->cmRoom->Position);
this->dgrdRoom->CurrentRowIndex = this->cmRoom->Position;
}
}
else if(String::Compare(e->Button->ToolTipText,S"尾记录") == 0)
{
this->dgrdRoom->UnSelect(this->cmRoom->Position);
this->cmRoom->Position = this->cmRoom->Count;
this->dgrdRoom->Select(this->cmRoom->Position);
this->dgrdRoom->CurrentRowIndex = this->cmRoom->Position;
}
else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
{
this->chkIsCanCombine->DataBindings->Clear();
this->cmbRoomType->DataBindings->Clear();
this->cmbFloor->DataBindings->Clear();
this->cmRoom->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;
this->tBoxRoomIDShow->Text = MaxID.ToString();
//设置类型
this->cmbRoomType->SelectedIndex = 0;
//设置状态
this->tBoxStatus->Text = S"空房";
this->cmRoom->EndCurrentEdit();
int row = this->cmRoom->Count - 1;
this->ds->Tables->Item[S"客房信息"]->Rows->Item[row]->Item[S"是否可拼房"] = __box(false);
this->ds->Tables->Item[S"客房信息"]->Rows->Item[row]->Item[S"类型编号"] = __box(1);
this->ds->Tables->Item[S"客房信息"]->Rows->Item[row]->Item[S"楼层编号"] = __box(1);
this->chkIsCanCombine->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"客房信息"],S"是否可拼房");
this->cmbRoomType->DataBindings->Add(S"SelectedValue",this->ds->Tables->Item[S"客房信息"],S"类型编号");
this->cmbFloor->DataBindings->Add(S"SelectedValue",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->cmRoom->Count > 0)
this->cmRoom->RemoveAt(this->cmRoom->Position);
else
MessageBox::Show(S"表格已空,无可删除数据",S"提示");
}
}
else if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
{
this->cmRoom->EndCurrentEdit();
this->MyDataBase->UpdateDataBase(this->RoomAdapter,this->ds,S"客房信息");
}
else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
{
try
{
this->cmRoom->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* strRoomID = this->tBoxRoomID->Text->Trim();
String* strRoomTypeID = this->tBoxRoomTypeID->Text->Trim();
String* strFloorID = this->tBoxFloorID->Text->Trim();
String* Filter = S"";
if(String::Compare(strRoomID,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (客房编号 LIKE '%{1}%')",Filter,strRoomID);
}
if(String::Compare(strRoomTypeID,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (类型编号 LIKE '%{1}%')",Filter,strRoomTypeID);
}
if(String::Compare(strFloorID,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (楼层编号 LIKE '%{1}%')",Filter,strFloorID);
}
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->RoomAdapter,this->ds,this->strSQL,this->strTableName);
}
else
{
//查询客房信息
this->strSQL = S"Select * from 客房信息";
this->strTableName = S"客房信息";
this->MyDataBase->SelectDataBase(this->RoomAdapter,this->ds,this->strSQL,this->strTableName);
}
}
//额定人数不能为空
private: System::Void tBoxBookIDShow_Leave(System::Object * sender, System::EventArgs * e)
{
if(String::Compare(this->tBoxCapacity->Text,String::Empty) == 0)
{
MessageBox::Show(S"额定人数不能为空",S"提示");
this->tBoxCapacity->Focus();
}
}
//编号不能为空
private: System::Void tBoxRoomIDShow_Leave(System::Object * sender, System::EventArgs * e)
{
if(String::Compare(this->tBoxRoomIDShow->Text,String::Empty) == 0)
{
MessageBox::Show(S"客房编号不能为空",S"提示");
this->tBoxRoomIDShow->Focus();
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -