📄 roomtype.h
字号:
//
// tBoxPrice
//
this->tBoxPrice->Location = System::Drawing::Point(625, 40);
this->tBoxPrice->Name = S"tBoxPrice";
this->tBoxPrice->Size = System::Drawing::Size(120, 21);
this->tBoxPrice->TabIndex = 6;
this->tBoxPrice->Text = S"";
//
// label4
//
this->label4->Location = System::Drawing::Point(559, 43);
this->label4->Name = S"label4";
this->label4->Size = System::Drawing::Size(56, 11);
this->label4->TabIndex = 5;
this->label4->Text = S"价格";
//
// dgrdRoom
//
this->dgrdRoom->DataMember = S"";
this->dgrdRoom->Dock = System::Windows::Forms::DockStyle::Fill;
this->dgrdRoom->HeaderForeColor = System::Drawing::SystemColors::ControlText;
this->dgrdRoom->Location = System::Drawing::Point(0, 120);
this->dgrdRoom->Name = S"dgrdRoom";
this->dgrdRoom->Size = System::Drawing::Size(760, 125);
this->dgrdRoom->TabIndex = 2;
//
// groupBox2
//
this->groupBox2->Controls->Add(this->tBoxRoomTypeNameShow);
this->groupBox2->Controls->Add(this->label3);
this->groupBox2->Controls->Add(this->tBoxRoomTypeIDShow);
this->groupBox2->Controls->Add(this->label5);
this->groupBox2->Controls->Add(this->tBoxPriceShow);
this->groupBox2->Controls->Add(this->label6);
this->groupBox2->Dock = System::Windows::Forms::DockStyle::Bottom;
this->groupBox2->Location = System::Drawing::Point(0, 245);
this->groupBox2->Name = S"groupBox2";
this->groupBox2->Size = System::Drawing::Size(760, 136);
this->groupBox2->TabIndex = 3;
this->groupBox2->TabStop = false;
//
// tBoxRoomTypeNameShow
//
this->tBoxRoomTypeNameShow->Location = System::Drawing::Point(344, 58);
this->tBoxRoomTypeNameShow->Name = S"tBoxRoomTypeNameShow";
this->tBoxRoomTypeNameShow->Size = System::Drawing::Size(120, 21);
this->tBoxRoomTypeNameShow->TabIndex = 10;
this->tBoxRoomTypeNameShow->Text = S"";
//
// label3
//
this->label3->Location = System::Drawing::Point(280, 62);
this->label3->Name = S"label3";
this->label3->Size = System::Drawing::Size(56, 11);
this->label3->TabIndex = 9;
this->label3->Text = S"类型名称";
//
// tBoxRoomTypeIDShow
//
this->tBoxRoomTypeIDShow->Location = System::Drawing::Point(144, 58);
this->tBoxRoomTypeIDShow->Name = S"tBoxRoomTypeIDShow";
this->tBoxRoomTypeIDShow->Size = System::Drawing::Size(120, 21);
this->tBoxRoomTypeIDShow->TabIndex = 8;
this->tBoxRoomTypeIDShow->Text = S"";
this->tBoxRoomTypeIDShow->Leave += new System::EventHandler(this, tBoxRoomTypeIDShow_Leave);
//
// label5
//
this->label5->Location = System::Drawing::Point(80, 63);
this->label5->Name = S"label5";
this->label5->Size = System::Drawing::Size(56, 11);
this->label5->TabIndex = 7;
this->label5->Text = S"类型编号";
//
// tBoxPriceShow
//
this->tBoxPriceShow->Location = System::Drawing::Point(561, 58);
this->tBoxPriceShow->Name = S"tBoxPriceShow";
this->tBoxPriceShow->Size = System::Drawing::Size(120, 21);
this->tBoxPriceShow->TabIndex = 12;
this->tBoxPriceShow->Text = S"";
//
// label6
//
this->label6->Location = System::Drawing::Point(495, 61);
this->label6->Name = S"label6";
this->label6->Size = System::Drawing::Size(56, 11);
this->label6->TabIndex = 11;
this->label6->Text = S"价格";
//
// RoomType
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(760, 381);
this->Controls->Add(this->dgrdRoom);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->toolBar1);
this->Name = S"RoomType";
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->tBoxRoomTypeIDShow->ReadOnly = !isModifiable;
this->tBoxRoomTypeNameShow->ReadOnly = !isModifiable;
this->tBoxPriceShow->ReadOnly = !isModifiable;
this->btnSearch->Enabled = !isModifiable;
this->dgrdRoom->ReadOnly = !isModifiable;
}
//---------------------设置控件的数据邦定--------------------------
void SetDataBindings()
{
this->tBoxRoomTypeIDShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"客房类型"],S"类型编号");
this->tBoxRoomTypeNameShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"客房类型"],S"类型名称");
this->tBoxPriceShow->DataBindings->Add(S"Text",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->cmRoom->AddNew();
this->SetModify(true);
this->dgrdRoom->UnSelect(this->cmRoom->Position);
this->cmRoom->Position = this->cmRoom->Count;
this->dgrdRoom->Select(this->cmRoom->Position);
this->dgrdRoom->CurrentRowIndex = this->cmRoom->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;
}
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* strRoomTypeID = this->tBoxRoomTypeID->Text->Trim();
String* strRoomTypeName = this->tBoxRoomTypeName->Text->Trim();
String* strPrice = this->tBoxPrice->Text->Trim();
String* Filter = S"";
if(String::Compare(strRoomTypeID,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (类型编号 LIKE '%{1}%')",Filter,strRoomTypeID);
}
if(String::Compare(strRoomTypeName,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (类型名称 LIKE '%{1}%')",Filter,strRoomTypeName);
}
if(String::Compare(strPrice,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (价格 = {1})",Filter,strPrice);
}
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 tBoxRoomTypeIDShow_Leave(System::Object * sender, System::EventArgs * e)
{
if(String::Compare(this->tBoxRoomTypeIDShow->Text,String::Empty) == 0)
{
MessageBox::Show(S"类型编号不能为空",S"提示");
this->tBoxRoomTypeIDShow->Focus();
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -