📄 bookinfo.h
字号:
this->tBoxBarCodeShow->Text = S"";
//
// label5
//
this->label5->Location = System::Drawing::Point(16, 32);
this->label5->Name = S"label5";
this->label5->Size = System::Drawing::Size(56, 11);
this->label5->TabIndex = 1;
this->label5->Text = S"条形码";
//
// tBoxBookNameShow
//
this->tBoxBookNameShow->Location = System::Drawing::Point(256, 48);
this->tBoxBookNameShow->Name = S"tBoxBookNameShow";
this->tBoxBookNameShow->Size = System::Drawing::Size(232, 21);
this->tBoxBookNameShow->TabIndex = 6;
this->tBoxBookNameShow->Text = S"";
//
// label6
//
this->label6->Location = System::Drawing::Point(256, 32);
this->label6->Name = S"label6";
this->label6->Size = System::Drawing::Size(56, 11);
this->label6->TabIndex = 5;
this->label6->Text = S"书名";
//
// label7
//
this->label7->Location = System::Drawing::Point(136, 32);
this->label7->Name = S"label7";
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"类型";
//
// cmbBookClass
//
this->cmbBookClass->Location = System::Drawing::Point(496, 48);
this->cmbBookClass->Name = S"cmbBookClass";
this->cmbBookClass->Size = System::Drawing::Size(104, 20);
this->cmbBookClass->TabIndex = 7;
//
// BookInfo
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(760, 469);
this->Controls->Add(this->dgrdBooks);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->toolBar1);
this->Name = S"BookInfo";
this->Text = S"图书档案管理";
this->groupBox1->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdBooks))->EndInit();
this->groupBox2->ResumeLayout(false);
this->ResumeLayout(false);
}
private:
//----------------设置控件ReadOnly属性------------------------
void SetModify(bool isModifiable)
{
this->tBoxBarCodeShow->ReadOnly = !isModifiable;
this->tBoxBookIDShow->ReadOnly = !isModifiable;
this->tBoxBookNameShow->ReadOnly = !isModifiable;
this->tBoxWritter->ReadOnly = !isModifiable;
this->tBoxTranslator->ReadOnly = !isModifiable;
this->tBoxISBN->ReadOnly = !isModifiable;
this->tBoxPrice->ReadOnly = !isModifiable;
this->tBoxPage->ReadOnly = !isModifiable;
this->tBoxOperator->ReadOnly = !isModifiable;
this->tBoxMemo->ReadOnly = !isModifiable;
this->chkIsUnregister->Enabled = isModifiable;
this->cmbBookClass->Enabled = isModifiable;
this->cmbPublisher->Enabled = isModifiable;
this->cmbShell->Enabled = isModifiable;
this->btnSearch->Enabled = !isModifiable;
this->dgrdBooks->ReadOnly = !isModifiable;
}
//---------------------设置控件的数据邦定--------------------------
void SetDataBindings()
{
this->tBoxBarCodeShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"条形码");
this->tBoxBookIDShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"编号");
this->tBoxBookNameShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"书名");
this->tBoxWritter->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"作者");
this->tBoxTranslator->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"译者");
this->tBoxISBN->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"ISBN");
this->tBoxPrice->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"价格");
this->tBoxPage->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->chkIsUnregister->DataBindings->Add(S"Checked",this->ds->Tables->Item[S"图书信息"],S"是否注销");
this->cmbBookClass->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"类型");
this->cmbPublisher->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书信息"],S"出版社");
this->cmbShell->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"";
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;
this->dgrdBooks->Select(this->cmBook->Position);
this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
}
else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
{
this->chkIsUnregister->DataBindings->Clear();
this->cmBook->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->tBoxBookIDShow->Text = String::Format(S"000{0}",MaxID.ToString()->Trim());
break;
case 2:
this->tBoxBookIDShow->Text = String::Format(S"00{0}",MaxID.ToString()->Trim());
break;
case 3:
this->tBoxBookIDShow->Text = String::Format(S"0{0}",MaxID.ToString()->Trim());
break;
case 4:
this->tBoxBookIDShow->Text = String::Format(S"{0}",MaxID.ToString()->Trim());
break;
}
//设置类型
this->cmbBookClass->SelectedIndex = 0;
this->cmBook->EndCurrentEdit();
int row = this->cmBook->Count - 1;
this->ds->Tables->Item[S"图书信息"]->Rows->Item[row]->Item[S"是否注销"] = __box(false);
this->chkIsUnregister->DataBindings->Add(S"Checked",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->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* strBookName = this->tBoxBookName->Text->Trim();
String* strBarCode = this->tBoxBarCode->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(strBookName,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (书名 LIKE '%{1}%')",Filter,strBookName);
}
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->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 tBoxBookIDShow_Leave(System::Object * sender, System::EventArgs * e)
{
if(String::Compare(this->tBoxBookIDShow->Text,String::Empty) == 0)
{
MessageBox::Show(S"编号不能为空",S"提示");
this->tBoxBookIDShow->Focus();
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -