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

📄 cinstore.h

📁 MFC程序开发参考大全 【明日科技】宋坤 刘锐宁 李伟明 【丛 书 名】 软件工程师典藏 【出 版 社】 人民邮电出版社 本书详细介绍了MFC框架中所有常用类及控件的应用
💻 H
📖 第 1 页 / 共 3 页
字号:
			Operator->Text = CLogin::CurUser;
		 }


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 BookPrice_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();
		 }

}

private: System::Void BookName_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {

			 
			 if (e->KeyValue==45) //insert键
			 {
				 if (! BookInfoIsNull())
				 {
					 Decimal  price,num,rabate,summoney;
					 try
					 {
						 price = Convert::ToDecimal(BookPrice->Text->Trim());
						 num =Convert::ToDecimal(BookNum->Text->Trim());
						 rabate = Convert::ToDecimal(BookRebate->Text->Trim());
					 }
					 catch(...)
					 {
						 MessageBox::Show("数字格式不正确.");
						 return;
					 
					 }
					 BookList->RowCount+=1;
					 
					 BookList->Rows[CurInsertedRow]->Cells[0]->Value = BookName->Text->Trim();
					 BookList->Rows[CurInsertedRow]->Cells[1]->Value = Author->Text->Trim();
					 BookList->Rows[CurInsertedRow]->Cells[2]->Value = BookPrice->Text->Trim();
					 BookList->Rows[CurInsertedRow]->Cells[3]->Value = BookNum->Text->Trim();
					 BookList->Rows[CurInsertedRow]->Cells[4]->Value = BookRebate->Text->Trim();

					 summoney = price*num*rabate;
					 BookList->Rows[CurInsertedRow]->Cells[5]->Value = summoney;


					 TotalNum->Text = Convert::ToString( GroupNum());
					 TotalMoney->Text = Convert::ToString(GroupMoney());

					 ClearText();
					 BookName->Focus();

					 CurInsertedRow +=1;
					 
				 }
				 return;
			 }

			 if (e->KeyValue==27) //esc键,清空编辑框文本
			 {
				 ClearText();
				 BookName->Focus();
				 return;
			 }

			 if (((Control^)sender)->Handle==BookName->Handle)
			 {
				 if (e->Control && AuList->Visible)
					 AuList->Focus();
				 if (e->KeyValue==13)
				 {	
					 String ^ sql = String::Format("select * from BookInfo where Bookname ='{0}'",BookName->Text->Trim());

					 SqlDataAdapter^ dataAdapter = gcnew SqlDataAdapter(sql,DataManage.Connection);

					 DataSet ^ dataset = gcnew DataSet();
					 dataAdapter->Fill(dataset);

					 if (dataset->Tables[0]->Rows->Count>0)
					 {
						 BookName->Text = dataset->Tables[0]->Rows[0]->ItemArray[dataset->Tables[0]->Columns->IndexOf("bookName")]->ToString();
						 Author->Text = dataset->Tables[0]->Rows[0]->ItemArray[dataset->Tables[0]->Columns->IndexOf("bookAuthor")]->ToString();
						 BookPrice->Text = dataset->Tables[0]->Rows[0]->ItemArray[dataset->Tables[0]->Columns->IndexOf("BookPrice")]->ToString();
						 BookPrice->Focus();
					 }
				 }
			 }
			 else if (e->KeyValue==13)
			 {
				 Control^ temp =  GetNextControl(ActiveControl,true);
				 if (temp->GetType()->Name=="TextBox")
					temp->Focus();
			 
			 }

		 }

private: System::Void BookName_Enter(System::Object^  sender, System::EventArgs^  e) {

			 AuList->Hide();

		 }
private: System::Void BookName_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {

		 }
private: System::Void Author_TextChanged(System::Object^  sender, System::EventArgs^  e) {

			 if (Author->Text->Trim() !="")
			 {
				 BookName->ReadOnly = true;
			 }
			 else
				 BookName->ReadOnly = false;
		 }
		 //用户在表格中按Delete键将删除当前行
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 button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (BookList->RowCount>1) //表格中有数据
			 {
				 SqlTransaction^ sqltrans;
				try
				{
					sqltrans = 	DataManage.Connection->BeginTransaction();

					DataManage.Command->Transaction = sqltrans;
					
					String^ sql = String::Format("Execute AddInStoreID @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^ InStoreID = Convert::ToString(param1->Value);
					DataManage.DataReader->Close();

					for (int i = 0; i<BookList->RowCount-1; i++)
					{

						sql = String::Format("insert into InStoreDetail values ( '{0}','{1}',{2},{3},{4},{5})",
							InStoreID,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));

						DataManage.Command->CommandText = sql;
						DataManage.DataReader = DataManage.Command->ExecuteReader();
						
						if (DataManage.DataReader->HasRows)
						{
							DataManage.DataReader->Close();
							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();
						}
						else
						{
							
							DataManage.DataReader->Close();
							sql = String::Format("insert into BookStorage values ('{0}','{1}',{2})",
								Convert::ToString(BookList->Rows[i]->Cells[0]->Value),"mrkj",
								Convert::ToDecimal(BookList->Rows[i]->Cells[3]->Value));
							
							DataManage.Command->CommandText = sql;
							DataManage.Command->ExecuteNonQuery();
						}
						
					}
					sqltrans->Commit();
					ButtonCancel_Click(sender,e);
					MessageBox::Show("操作成功,单号为:"+ InStoreID);

				}
				catch(DbException^ exp)
				{			
					sqltrans->Rollback();
					MessageBox::Show("操作失败,错误信息为"+ exp->Message);
								
				}	 
			 }
		 }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			 Close();
		 }
};
}

⌨️ 快捷键说明

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