📄 coutstore.h
字号:
this->dataGridViewTextBoxColumn1->Name = L"dataGridViewTextBoxColumn1";
this->dataGridViewTextBoxColumn1->ReadOnly = true;
this->dataGridViewTextBoxColumn1->Width = 200;
//
// dataGridViewTextBoxColumn2
//
this->dataGridViewTextBoxColumn2->HeaderText = L"条形码";
this->dataGridViewTextBoxColumn2->Name = L"dataGridViewTextBoxColumn2";
this->dataGridViewTextBoxColumn2->ReadOnly = true;
//
// dataGridViewTextBoxColumn3
//
this->dataGridViewTextBoxColumn3->HeaderText = L"作者";
this->dataGridViewTextBoxColumn3->Name = L"dataGridViewTextBoxColumn3";
this->dataGridViewTextBoxColumn3->ReadOnly = true;
this->dataGridViewTextBoxColumn3->Width = 70;
//
// dataGridViewTextBoxColumn4
//
this->dataGridViewTextBoxColumn4->HeaderText = L"出版社";
this->dataGridViewTextBoxColumn4->Name = L"dataGridViewTextBoxColumn4";
this->dataGridViewTextBoxColumn4->ReadOnly = true;
this->dataGridViewTextBoxColumn4->Width = 80;
//
// dataGridViewTextBoxColumn5
//
this->dataGridViewTextBoxColumn5->HeaderText = L"价格";
this->dataGridViewTextBoxColumn5->Name = L"dataGridViewTextBoxColumn5";
this->dataGridViewTextBoxColumn5->ReadOnly = true;
this->dataGridViewTextBoxColumn5->Width = 60;
//
// COutStore
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(689, 496);
this->Controls->Add(this->AuList);
this->Controls->Add(this->ButtonCancel);
this->Controls->Add(this->button1);
this->Controls->Add(this->TotalMoney);
this->Controls->Add(this->TotalNum);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->button3);
this->Controls->Add(this->BookList);
this->Controls->Add(this->Operator);
this->Controls->Add(this->dateTime1);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->MaximizeBox = false;
this->Name = L"COutStore";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"图书出库管理";
this->Enter += gcnew System::EventHandler(this, &COutStore::BookName_Enter);
this->Load += gcnew System::EventHandler(this, &COutStore::COutStore_Load);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->BookList))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->AuList))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void COutStore_Load(System::Object^ sender, System::EventArgs^ e) {
DataManage.ConStr ="Data Source=.;Initial Catalog=BookManage;User ID=sa";
DataManage.ConnectDataBase();
Operator->Text = CLogin::CurUser;
}
private: System::Void AuList_Leave(System::Object^ sender, System::EventArgs^ e) {
AuList->Hide();
}
private: System::Void AuList_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if (e->KeyValue==13)
{
int r = AuList->SelectedRows[0]->Index;
Author->Text = Convert::ToString(AuList->SelectedRows[0]->Cells[2]->Value);
BookName->Text = Convert::ToString( AuList->Rows[r]->Cells[0]->Value);
BookPrice->Text= Convert::ToString(AuList->SelectedRows[0]->Cells[4]->Value);
BookPrice->Focus();
AuList->Hide();
}
}
private: System::Void AuList_CellDoubleClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
int r = AuList->SelectedRows[0]->Index;
Author->Text = Convert::ToString(AuList->SelectedRows[0]->Cells[2]->Value);
BookName->Text = Convert::ToString( AuList->Rows[r]->Cells[0]->Value);
BookPrice->Text= Convert::ToString(AuList->SelectedRows[0]->Cells[4]->Value);
BookPrice->Focus();
AuList->Hide();
}
private: System::Void Author_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
if (e->KeyChar<8||e->KeyChar>8 && e->KeyChar<46 || e->KeyChar>46 && e->KeyChar<48 || e->KeyChar>57 )
e->KeyChar = 0;
}
private: System::Void BookNum_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
if (e->KeyChar<8||e->KeyChar>8 && e->KeyChar<48 || e->KeyChar>57 )
e->KeyChar = 0;
}
private: System::Void BookName_TextChanged(System::Object^ sender, System::EventArgs^ e) {
String^ str = Convert::ToString(BookName->Text->Trim());
if (str != "")
{
String ^ sql = String::Format("select * from BookInfo where Bookname like '{0}%' or Barcode like '{0}%' ",str);
SqlDataAdapter^ dataAdapter = gcnew SqlDataAdapter(sql,DataManage.Connection);
DataSet ^ dataset = gcnew DataSet();
dataAdapter->Fill(dataset);
if (dataset->Tables[0]->Rows->Count>0)
{
AuList->RowCount = dataset->Tables[0]->Rows->Count;
for(int i = 0; i<dataset->Tables[0]->Rows->Count; i++)
{
AuList->Rows[i]->Cells[0]->Value = dataset->Tables[0]->Rows[i]->ItemArray[dataset->Tables[0]->Columns->IndexOf("bookName")]->ToString();
AuList->Rows[i]->Cells[1]->Value = dataset->Tables[0]->Rows[i]->ItemArray[dataset->Tables[0]->Columns->IndexOf("barcode")]->ToString();
AuList->Rows[i]->Cells[2]->Value = dataset->Tables[0]->Rows[i]->ItemArray[dataset->Tables[0]->Columns->IndexOf("bookAuthor")]->ToString();
AuList->Rows[i]->Cells[3]->Value = dataset->Tables[0]->Rows[i]->ItemArray[dataset->Tables[0]->Columns->IndexOf("BookConcern")]->ToString();
AuList->Rows[i]->Cells[4]->Value = dataset->Tables[0]->Rows[i]->ItemArray[dataset->Tables[0]->Columns->IndexOf("BookPrice")]->ToString();
}
AuList->Rows[0]->Cells[0]->Selected =true; //选中第一行
AuList->Show();
}
else
{
AuList->Hide();
}
}
else
{
AuList->Hide();
}
}
c
private: System::Void BookName_Enter(System::Object^ sender, System::EventArgs^ e) {
AuList->Hide();
}
private: System::Void Author_TextChanged(System::Object^ sender, System::EventArgs^ e) {
if (Author->Text->Trim() !="")
{
BookName->ReadOnly = true;
}
else
BookName->ReadOnly = false;
}
private: System::Void BookList_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if (e->KeyCode==Keys::Delete) //delete键
{
int row = BookList->SelectedCells[0]->RowIndex;
if (row != -1 && row != BookList->RowCount-1)
{
String ^ str =Convert::ToString( BookList->Rows[row]->Cells[0]->Value);
if (MessageBox::Show("确实要删除图书名称为"+str+"的信息吗?","提示",MessageBoxButtons::YesNo)==::DialogResult::Yes)
{
CurInsertedRow -=1;
}
else
e->Handled = true;
}
}
}
private: System::Void BookList_RowsRemoved(System::Object^ sender, System::Windows::Forms::DataGridViewRowsRemovedEventArgs^ e) {
TotalNum->Text = Convert::ToString( GroupNum());
TotalMoney->Text = Convert::ToString(GroupMoney());
}
private: System::Void ButtonCancel_Click(System::Object^ sender, System::EventArgs^ e)
{
ClearText();
CurInsertedRow = 0;
ClearGridData();
TotalNum->Text = "0";
TotalMoney->Text = "0";
BookName->Focus();
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
if (BookList->RowCount>1) //表格中有数据
{
String ^ str = "";
if (!BookInfoIsExist(str))
{
MessageBox::Show(str+ "图书在仓库中不存在!");
return;
}
SqlTransaction^ sqltrans;
try
{
sqltrans = DataManage.Connection->BeginTransaction();
DataManage.Command->Transaction = sqltrans;
String^ sql = String::Format("Execute AddOutStoreID @p1 output,@p2,@p3,@p4,@p5");
DataManage.Command->CommandText = sql;
SqlParameter^ param1 = DataManage.Command->CreateParameter();
param1->ParameterName = "p1";
param1->Size = 50;
param1->Value = "temp";
param1->Direction = ParameterDirection::InputOutput;
SqlParameter^ param2 = DataManage.Command->CreateParameter();
param2->ParameterName = "p2";
param2->Value = Operator->Text;
SqlParameter^ param3 = DataManage.Command->CreateParameter();
param3->ParameterName = "p3";
param3->Value = Convert::ToDecimal(TotalNum->Text);
SqlParameter^ param4 = DataManage.Command->CreateParameter();
param4->ParameterName = "p4";
param4->Value = Convert::ToDecimal(TotalMoney->Text);
SqlParameter^ param5 = DataManage.Command->CreateParameter();
param5->ParameterName = "p5";
param5->Value = dateTime1->Value;
DataManage.Command->Parameters->Clear();
DataManage.Command->Parameters->Add(param1);
DataManage.Command->Parameters->Add(param2);
DataManage.Command->Parameters->Add(param3);
DataManage.Command->Parameters->Add(param4);
DataManage.Command->Parameters->Add(param5);
DataManage.DataReader = DataManage.Command->ExecuteReader();
//获取单号
String^ OutStoreID = Convert::ToString(param1->Value);
DataManage.DataReader->Close();
for (int i = 0; i<BookList->RowCount-1; i++)
{
sql = String::Format("insert into OutStoreDetail values ( '{0}','{1}',{2},{3},{4},{5})",
OutStoreID,Convert::ToString(BookList->Rows[i]->Cells[0]->Value),Convert::ToDecimal(BookList->Rows[i]->Cells[3]->Value),
Convert::ToDecimal(BookList->Rows[i]->Cells[4]->Value),Convert::ToDecimal(BookList->Rows[i]->Cells[2]->Value),
Convert::ToDecimal(BookList->Rows[i]->Cells[5]->Value));
DataManage.Command->CommandText = sql;
DataManage.Command->ExecuteNonQuery();
sql = String::Format("select * from BookStorage where BookName = '{0}'",Convert::ToString(BookList->Rows[i]->Cells[0]->Value));
sql = String::Format("update BookStorage set BookNum=BookNum- {0} where BookName= '{1}'",
Convert::ToDecimal(BookList->Rows[i]->Cells[3]->Value),Convert::ToString(BookList->Rows[i]->Cells[0]->Value));
DataManage.Command->CommandText = sql;
DataManage.Command->ExecuteNonQuery();
}
sqltrans->Commit();
ButtonCancel_Click(sender,e);
MessageBox::Show("操作成功,单号为:"+ OutStoreID);
}
catch(DbException^ exp)
{
sqltrans->Rollback();
MessageBox::Show("操作失败,错误信息为"+ exp->Message);
}
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -