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

📄 warrentinput.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 3 页
字号:
			DataGridTableStyle* ts = new DataGridTableStyle();
			DataGridTextBoxColumn* aTextColumn;
			ts->AlternatingBackColor = Color::LightGray;
			ts->MappingName = this->ds->Tables->Item[S"凭证明细表"]->TableName;

			aTextColumn = new DataGridTextBoxColumn();
			aTextColumn->get_TextBox()->Enabled = false;
			aTextColumn->MappingName = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"科目代码"]->ColumnName;
			aTextColumn->HeaderText = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"科目代码"]->ColumnName;
			aTextColumn->NullText = S"";
			aTextColumn->Format = S"D";
			ts->GridColumnStyles->Add(aTextColumn);

			aTextColumn = new DataGridTextBoxColumn();
			aTextColumn->get_TextBox()->Enabled = false;
			aTextColumn->MappingName = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"科目名称"]->ColumnName;
			aTextColumn->HeaderText = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"科目名称"]->ColumnName;
			aTextColumn->NullText = S"";
			aTextColumn->Format = S"D";
			ts->GridColumnStyles->Add(aTextColumn);

			aTextColumn = new DataGridTextBoxColumn();	
			aTextColumn->get_TextBox()->add_TextChanged(new System::EventHandler(this,Total_TextChanged));
			aTextColumn->MappingName = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"借方"]->ColumnName;
			aTextColumn->HeaderText = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"借方"]->ColumnName;
			aTextColumn->NullText = S"";
			aTextColumn->Format = S"D";
			ts->GridColumnStyles->Add(aTextColumn);

			aTextColumn = new DataGridTextBoxColumn();
			aTextColumn->get_TextBox()->add_TextChanged(new System::EventHandler(this,Total_TextChanged));
			aTextColumn->MappingName = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"贷方"]->ColumnName;
			aTextColumn->HeaderText = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"贷方"]->ColumnName;
			aTextColumn->NullText = S"";
			aTextColumn->Format = S"D";
			ts->GridColumnStyles->Add(aTextColumn);


			aTextColumn = new DataGridTextBoxColumn();			
			aTextColumn->MappingName = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"摘要"]->ColumnName;
			aTextColumn->HeaderText = this->ds->Tables->Item[S"凭证明细表"]->Columns->Item[S"摘要"]->ColumnName;
			aTextColumn->NullText = S"";
			aTextColumn->Format = S"D";
			ts->GridColumnStyles->Add(aTextColumn);


			this->dgrdDetail->TableStyles->Add(ts);
		}
		//------------------设置数据绑定----------------------
        void DataBidings()
		{
			this->tBoxWarrentCodeShow->DataBindings->Add("Text",this->ds->Tables->Item[S"凭证表"],"凭证编号");
			this->cmbWarrentNumber->DataBindings->Add("Text",this->ds->Tables->Item[S"凭证表"],"凭证字号");
			this->tBoxDate->DataBindings->Add("Text",this->ds->Tables->Item[S"凭证表"],"日期");
			this->tBoxOperator->DataBindings->Add("Text",this->ds->Tables->Item[S"凭证表"],S"制单");
			this->tBoxAccountDateShow->DataBindings->Add("Text",this->ds->Tables->Item[S"凭证表"],"会计期间");
			this->tBoxExportCredit->DataBindings->Add("Text",this->ds->Tables->Item[S"凭证表"],"过帐状态");
			this->tBoxDebitTotal->DataBindings->Add("Text",this->ds->Tables->Item[S"凭证表"],"借方合计");
			this->tBoxLoanTotal->DataBindings->Add("Text",this->ds->Tables->Item[S"凭证表"],"贷方合计");						
		}
		//-----------------设置控件属性-----------------------
		void SetModify(bool isModifiable)
		{
			this->tBoxWarrentCodeShow->ReadOnly = !isModifiable;
			this->cmbWarrentNumber->Enabled = isModifiable;
			this->tBoxDate->ReadOnly = !isModifiable;
			this->tBoxOperator->ReadOnly = !isModifiable;
			this->tBoxAccountDateShow->ReadOnly = !isModifiable;
			this->tBoxExportCredit->ReadOnly = !isModifiable;			
			this->tBoxDebitTotal->ReadOnly = !isModifiable;
			this->tBoxLoanTotal->ReadOnly = !isModifiable;		
			this->IsModifyDetail = isModifiable;
			this->dgrdDetail->ReadOnly = !isModifiable;
		}	
private: System::Void btnSearch_Click(System::Object *  sender, System::EventArgs *  e)
		{
			this->ds->Clear();
			this->strSQL = String::Format(S"SELECT * FROM 凭证表  WHERE 凭证编号 LIKE '%{0}%' AND 会计期间 LIKE '%{1}%' ORDER BY 凭证编号",this->tBoxWarrentCode->Text->Trim(),this->tBoxAccountDate->Text->Trim());
			this->MyDataBase->SelectDataBase(this->WarrentAdapter,this->ds,this->strSQL,S"凭证表");

			if(this->ds->Tables->Item[S"凭证表"]->Rows->Count == 0)
				return;
			int row = this->dgrdWarrentTable->CurrentRowIndex;
			String* strWarrentCode = this->ds->Tables->Item[S"凭证表"]->Rows->Item[row]->Item[S"凭证编号"]->ToString()->Trim();
			this->strSQL = String::Format(S"SELECT 科目表.科目名称,分录表.* FROM 分录表,科目表 WHERE 科目表.科目代码 = 分录表.科目代码 AND 分录表.凭证编号 = '{0}'",strWarrentCode);
			this->MyDataBase->SelectDataBase(this->DetailAdapter,this->ds,this->strSQL,S"凭证明细表");
			this->dgrdDetail->ReadOnly = true;
			this->SetModify(false);
		}

private: System::Void dgrdWarrentTable_Click(System::Object *  sender, System::EventArgs *  e)
		{
			if(this->ds->Tables->Item[S"凭证表"]->Rows->Count == 0)
				return;
			this->ds->Tables->Item[S"凭证明细表"]->Clear();
			int row = this->dgrdWarrentTable->CurrentRowIndex;
			String* strWarrentCode = this->ds->Tables->Item[S"凭证表"]->Rows->Item[row]->Item[S"凭证编号"]->ToString()->Trim();
			this->strSQL = String::Format(S"SELECT 科目表.科目名称,分录表.* FROM 分录表,科目表 WHERE 科目表.科目代码 = 分录表.科目代码 AND 分录表.凭证编号 = '{0}'",strWarrentCode);
			this->MyDataBase->SelectDataBase(this->DetailAdapter,this->ds,this->strSQL,S"凭证明细表");
			this->dgrdDetail->ReadOnly = true;
			this->SetModify(false);
		}

private: System::Void dgrdDetail_DoubleClick(System::Object *  sender, System::EventArgs *  e)
		{
			if(this->IsModifyDetail)
			{
				SelectSubject* newFrm = new SelectSubject();
				if(newFrm->ShowDialog(this) == DialogResult::OK)
				{
					this->SubjectID = newFrm->SubjectID;
					this->SubjectName = newFrm->SubjectName;
					int row = this->dgrdDetail->CurrentRowIndex;
					this->dgrdDetail->set_Item(row,0,this->SubjectID);
					this->dgrdDetail->set_Item(row,1,this->SubjectName);					
					System::Windows::Forms::SendKeys::Send("{Tab}");
				}
			}
		}



private: System::Void toolBar1_ButtonClick(System::Object *  sender, System::Windows::Forms::ToolBarButtonClickEventArgs *  e)
		{
			if(String::Compare(e->Button->ToolTipText->Trim(),S"首记录") == 0)
			 {
				 this->dgrdWarrentTable->UnSelect(this->cmWarrent->Position);
				 this->cmWarrent->Position = 0;
				 this->dgrdWarrentTable->Select(this->cmWarrent->Position);
				 this->dgrdWarrentTable->CurrentRowIndex = this->cmWarrent->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"上一记录") == 0)
			 {
				 if(this->cmWarrent->Position > 0)
				 {
					 this->dgrdWarrentTable->UnSelect(this->cmWarrent->Position);
					 this->cmWarrent->Position--;
					 this->dgrdWarrentTable->Select(this->cmWarrent->Position);
					 this->dgrdWarrentTable->CurrentRowIndex = this->cmWarrent->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"下一记录") == 0)
			 {
				 if(this->cmWarrent->Position < this->cmWarrent->Count - 1)
				 {
					 this->dgrdWarrentTable->UnSelect(this->cmWarrent->Position);
					 this->cmWarrent->Position++;
					 this->dgrdWarrentTable->Select(this->cmWarrent->Position);
					 this->dgrdWarrentTable->CurrentRowIndex = this->cmWarrent->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"尾记录") == 0)
			 {
				 this->dgrdWarrentTable->UnSelect(this->cmWarrent->Position);
				 this->cmWarrent->Position = this->cmWarrent->Count - 1;
				 this->dgrdWarrentTable->Select(this->cmWarrent->Position);
				 this->dgrdWarrentTable->CurrentRowIndex = this->cmWarrent->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"新增记录") == 0)
			 {					 
				 this->cmWarrent->AddNew();
				 String* tempSQL = S"SELECT 取值 FROM 系统参数表 WHERE 参数名称 = '当前会计期间'";
				 SqlDataReader* reader = this->MyDataBase->SQLRead(tempSQL);
				 if(reader->Read())
				 {
					 this->tBoxAccountDateShow->Text = reader->Item[S"取值"]->ToString();
				 }
				 int MaxID = 1;
				 reader->Dispose();
				 tempSQL = S"SELECT MAX(凭证编号) 最大编号 FROM 凭证表";
				 reader = this->MyDataBase->SQLRead(tempSQL);
				 if(reader->Read() && reader->Item[S"最大编号"] != System::DBNull::Value)
				 {
					 MaxID = System::Convert::ToInt16(reader->Item[S"最大编号"]->ToString()) + 1;
				 }
				 else
				 {
					 MaxID = 1;
				 }
				 reader->Close();
				 switch(MaxID.ToString()->Length)
				 {
				 case 1:
					 this->tBoxWarrentCodeShow->Text = String::Format(S"00000{0}",MaxID.ToString());
					 break;
				 case 2:
					 this->tBoxWarrentCodeShow->Text = String::Format(S"0000{0}",MaxID.ToString());
					 break;
				 case 6:
					 this->tBoxWarrentCodeShow->Text = String::Format(S"0000{0}",MaxID.ToString());
					 break;
				 case 4:
					 this->tBoxWarrentCodeShow->Text = String::Format(S"00{0}",MaxID.ToString());
					 break;
				 case 5:
					 this->tBoxWarrentCodeShow->Text = String::Format(S"0{0}",MaxID.ToString());
					 break;
				 }
				 this->tBoxDate->Text = System::DateTime::Now.ToShortDateString();
				 this->tBoxExportCredit->Text = S"未过";
				 this->cmbWarrentNumber->SelectedIndex = 0;
				 this->ds->Tables->Item[S"凭证明细表"]->Clear();
				 this->SetModify(true);	
				 this->cmWarrent->EndCurrentEdit();
				 System::Windows::Forms::SendKeys::Send("{Tab}");
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"修改记录") == 0)
			 {					 
				 this->SetModify(true);				
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"删除记录") == 0)
			 {
				 if(MessageBox::Show(S"删除凭证记录及下属分记录?",S"删除记录",MessageBoxButtons::OKCancel) == DialogResult::OK)
				 {
					 if(this->cmWarrent->Count > 0)
					 {
						 //修改数据库
						 String* tempSQL = String::Format(S"Delete from 分录表 where 凭证编号 = '{0}'",this->tBoxWarrentCodeShow->Text);
						 this->MyDataBase->SQLOperate(tempSQL);
						 tempSQL = String::Format(S"Delete from 凭证表 where 凭证编号 = '{0}'",this->tBoxWarrentCodeShow->Text);
						 this->MyDataBase->SQLOperate(tempSQL);
						 //修改数据集
						 this->cmWarrent->RemoveAt(this->cmWarrent->Position);
					 }
				 }
				 else
				 {
					 MessageBox::Show(S"表中无可删除数据",S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"保存修改") == 0)
			 {
				 //检查新记录
				 if(System::Convert::ToDecimal(this->tBoxDebitTotal->Text) != System::Convert::ToDecimal(this->tBoxLoanTotal->Text))
				 {
					 MessageBox::Show(S"借贷双方不平衡,请修改分录数据",S"提示");
					 return;
				 }
				
				 //提交修改
				 this->cmWarrent->EndCurrentEdit();
				 if(this->ds->Tables->Item[S"凭证明细表"]->Rows->Count == 0)
				 {
					 MessageBox::Show(S"请输入凭证表分录数据",S"提示");
				 }
				 //更新数据库
				 if(this->ds->HasChanges(DataRowState::Modified))
					 this->MyDataBase->UpdateDataBase(this->WarrentAdapter,this->ds->GetChanges(DataRowState::Modified),S"凭证表");
				 if(this->ds->HasChanges(DataRowState::Added))
					 this->MyDataBase->UpdateDataBase(this->WarrentAdapter,this->ds->GetChanges(DataRowState::Added),S"凭证表");
				 this->ds->Tables->Item[S"凭证表"]->AcceptChanges();
				 if(this->ds->HasChanges())
					 this->MyDataBase->UpdateDataBase(this->DetailAdapter,this->ds,S"凭证明细表");

				 this->SetModify(false);
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"取消修改") == 0)
			 {
				 this->cmWarrent->CancelCurrentEdit();
			 }
			 else if(String::Compare(e->Button->ToolTipText->Trim(),S"退出") == 0)
			 {
				 this->Close();
			 }
		}






private: System::Void dgrdDetail_Click(System::Object *  sender, System::EventArgs *  e)
		 {
		 }

private: System::Void Total_TextChanged(System::Object *  sender, System::EventArgs *  e)
		 {
		 }

private: System::Void dgrdDetail_CurrentCellChanged(System::Object *  sender, System::EventArgs *  e)
		 {
			 
			 
			   if(this->ds->Tables->Item[S"凭证表"]->Rows->Count == 0)
				return;
			 Decimal debit = 0;
			 Decimal loan = 0;
			 for(int i =0;i < this->ds->Tables->Item[S"凭证明细表"]->Rows->Count;i++)
			 {
				 debit = debit + System::Convert::ToDecimal(this->ds->Tables->Item[S"凭证明细表"]->Rows->Item[i]->Item[S"借方"]->ToString());
				 loan = loan + System::Convert::ToDecimal(this->ds->Tables->Item[S"凭证明细表"]->Rows->Item[i]->Item[S"贷方"]->ToString());
				 this->ds->Tables->Item[S"凭证明细表"]->Rows->Item[i]->set_Item(S"凭证编号",this->tBoxWarrentCodeShow->Text);
				 this->ds->Tables->Item[S"凭证明细表"]->Rows->Item[i]->set_Item(S"数量",S"0");
			 }
			 this->tBoxDebitTotal->Text = debit.ToString();
			 this->tBoxLoanTotal->Text = loan.ToString();
		 }

};
}

⌨️ 快捷键说明

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