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

📄 mcppbankoperations.cpp

📁 ADOAPP.zip
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		paddr->Name="paddr";
		paddr->Size = Drawing::Size(150, 40);		
		paddr->TabIndex = 2;
		paddr->Location = Drawing::Point(width/2-120, height - 300);
		Controls->Add(paddr);

		heading = new Label();
		heading->Text="Mailing Address";
		heading->Size = Drawing::Size(100, 20);		
		heading->Location = Drawing::Point(width/2-240, height - 280);
		Controls->Add(heading);

		maddr = new TextBox();
		maddr->Name="maddr";
		maddr->Size = Drawing::Size(150, 40);		
		maddr->TabIndex = 2;
		maddr->Location = Drawing::Point(width/2-120, height - 280);
		Controls->Add(maddr);

		heading = new Label();
		heading->Text="Phone No:";
		heading->Size = Drawing::Size(100, 20);		
		heading->Location = Drawing::Point(width/2-240, height - 260);
		Controls->Add(heading);

		phno = new TextBox();
		phno->Name="phno";
		phno->Size = Drawing::Size(150, 40);		
		phno->TabIndex = 2;
		phno->Location = Drawing::Point(width/2-120, height - 260);
		Controls->Add(phno);

		heading = new Label();
		heading->Text="Email id:";
		heading->Size = Drawing::Size(100, 20);		
		heading->Location = Drawing::Point(width/2-240, height - 240);
		Controls->Add(heading);

		emailid = new TextBox();
		emailid->Name="emailid";
		emailid->Size = Drawing::Size(150, 40);		
		emailid->TabIndex = 2;
		emailid->Location = Drawing::Point(width/2-120, height - 240);
		Controls->Add(emailid);

		heading = new Label();
		heading->Text="Referal A/C no:";
		heading->Size = Drawing::Size(100, 20);		
		heading->Location = Drawing::Point(width/2-240, height - 220);
		Controls->Add(heading);

		refacno = new TextBox();
		refacno->Name="refacno";
		refacno->Size = Drawing::Size(150, 40);		
		refacno->TabIndex = 2;
		refacno->Location = Drawing::Point(width/2-120, height - 220);
		Controls->Add(refacno);

		heading = new Label();
		heading->Text="Amount:";
		heading->Size = Drawing::Size(50, 40);		
		heading->Location = Drawing::Point(width/2+40, height - 360);
		Controls->Add(heading);

		amount = new TextBox();
		amount->Name="amt";
		amount->Size = Drawing::Size(80, 40);		
		amount->TabIndex = 2;
		amount->Location = Drawing::Point(width/2+100, height - 360);
		Controls->Add(amount);

		// These are some of the hidden fields to store the values
		// that are required in the table but are not modified by
		// the user
		va = new TextBox();
		va->Name="validacc";
		va->Text="VA";
		va->Visible = false;		
		Controls->Add(va);

		typeac = new TextBox();
		typeac->Name="typeofacc";
		typeac->Text="S";
		typeac->Visible = false;		
		Controls->Add(typeac);

		// application heading
		heading = new Label();
		heading->Text="SaveMyMoneyBank Application";
		heading->Size = Drawing::Size(180, 50);		
		heading->Location = Drawing::Point(width/2-80, height - 380);
		Controls->Add(heading);

		// Setup Clear fields button
		clearfields = new Button();
		clearfields->Text = "Clear Fields";
		clearfields->Size = Drawing::Size(100, 30);
		clearfields->TabIndex = 0;
		clearfields->Location = Drawing::Point(width/2+80, height - 320);
		clearfields->Click += (new EventHandler(this, &BankForm::OnClearFields));
		Controls->Add(clearfields);

		// Setup Insert record button
		insertrecord = new Button();
		insertrecord->Text = "Insert New Record";
		insertrecord->Size = Drawing::Size(100, 30);
		insertrecord->TabIndex = 0;
		insertrecord->Location = Drawing::Point(width/2+80, height - 280);
		insertrecord->Click += (new EventHandler(this, &BankForm::OnInsertRecord));
		Controls->Add(insertrecord);

		// Setup the Update record button 
		updaterecord = new Button();
		updaterecord->Text = "Update Current Record";
		updaterecord->Size = Drawing::Size(100, 30);
		updaterecord->TabIndex = 0;
		updaterecord->Location = Drawing::Point(width/2+80, height - 240);
		updaterecord->Click += (new EventHandler(this, &BankForm::OnUpdateRecord));
		Controls->Add(updaterecord);

	}
	
	// function to handle the clear fields button click
	void OnClearFields(Object *sender, EventArgs *e) 
	{
		ClearForm();
	}

	// The following function is called on insert record click
	// make sure to click the clearfields button, enter values and
	// then click on this button

	void OnInsertRecord(Object *sender, EventArgs *e) 
	{
	    
		if (flag==false)
		{
			ClearForm();
			flag=true;
			insertrecord->Text="Submit";
			return;
		}
		if (ValidateForm()==true)
		{
		flag=false;
		insertrecord->Text="Insert New Record";
		DataRow *dr;
		// create a new datarow object
		dr = ds->get_Tables()->get_Item(0)->NewRow(); 
		
		// fill each Datarow field with the values on the form

		dr->set_Item("First_name", fname->Text->ToString());
		dr->set_Item("Last_name",lname->Text->ToString());
		dr->set_Item("date_birth",dob->Text->ToString());
		dr->set_Item("Permanent_Addr",paddr->Text->ToString());
		dr->set_Item("Mailing_Addr",maddr->Text->ToString());
		dr->set_Item("Phone_Number",phno->Text->ToString());
		dr->set_Item("eMailID",emailid->Text->ToString());
		dr->set_Item("Ref_Acc_no",refacno->Text);
		dr->set_Item("Balance",amount->Text);

		// random account number generation 
		// this can be replaced by some logic
		dr->set_Item("Account_number",amount->Text);

		// default values picked up for update requirements
		dr->set_Item("Type_account",typeac->Text);
		dr->set_Item("Valid_acc",va->Text);
		//dr->set_Item("curr_date",dob->Text->ToString());

		// add the row to the data set
		ds->get_Tables()->get_Item(0)->get_Rows()->Add(dr);
		
		// use the update method of the adapter to update the 
		// database from the contents of the dataset.
		// this can also be called later at any point
		myAdapter->Update(ds,"Account_Detail");

		// the following function is to refresh the form with the latest data
		FetchData();
		MessageBox::Show("Record added successfully.");
		}
	}
	
	// when the current record is displayed
	// the user changes any field and clicks on the update button
	// this function will ensure that it is updated in the database 

	void OnUpdateRecord(Object *sender, EventArgs *e) 
	{
		if (ValidateForm()==true)
		{
	  DataTable *dtab = new DataTable();
	  DataRow *dr;

	  // set an alias for the data table collections
      dtab = ds->get_Tables()->get_Item(0);
	
	  //set an alias for the data row collections for the current row
	  dr = dtab->get_Rows()->get_Item(currentrec);

	// fill each Datarow members with the latest values
		dr->set_Item("First_name", fname->Text->ToString());
		dr->set_Item("Last_name",lname->Text->ToString());
		dr->set_Item("date_birth",dob->Text->ToString());
		dr->set_Item("Permanent_Addr",paddr->Text->ToString());
		dr->set_Item("Mailing_Addr",maddr->Text->ToString());
		dr->set_Item("Phone_Number",phno->Text->ToString());
		dr->set_Item("eMailID",emailid->Text->ToString());
		dr->set_Item("Ref_Acc_no",refacno->Text);
		dr->set_Item("Balance",amount->Text);

		// random account number generation 
		// this can be replaced by some logic
		dr->set_Item("Account_number",amount->Text);

		// default values picked up for update requirements
		dr->set_Item("Type_account",typeac->Text);
		dr->set_Item("Valid_acc",va->Text);
//		dr->set_Item("curr_date",dob->Text->ToString());
	
		// use the update method of the adapter to update the 
		// database from the contents of the dataset.
		// this can also be called later at any point
		myAdapter->Update(ds,"Account_Detail");

		// the following function is to refresh the form with the latest data
		FetchData();
		MessageBox::Show("Record updated successfully.");
		}
	}
	
/** close the application **/
	void OnFileExit(Object *sender, EventArgs *e) 
	{
		Close();
	}

	void OnFirstRecord(Object *sender, EventArgs *e)
	{
	// call the functions to fill the fields with the records
	// passing 0 is for the first row
	  FillFields(0);
	  currentrec = 0;
	}

	void OnPrevRecord(Object *sender, EventArgs *e)
	{
	// call the functions to fill the fields with the records
	// pass current record - 1 for the prev row
	  if(currentrec != 0)
	  {
		  FillFields(currentrec-1);
		  currentrec = currentrec-1;
	  }
	}

	void OnNextRecord(Object *sender, EventArgs *e)
	{
	// call the functions to fill the fields with the records
    lastrow = (ds->get_Tables()->get_Item(0)->get_Rows()->get_Count() - 1);

	if(currentrec != lastrow)
		{
			FillFields(currentrec+1);
			currentrec = currentrec+1;
		}
	}

	void OnLastRecord(Object *sender, EventArgs *e)
	{
	// call the functions to fill the fields with the records
	// passing lastrow-1 for the last row
		lastrow = (ds->get_Tables()->get_Item(0)->get_Rows()->get_Count() - 1);
	    FillFields(lastrow);
	    currentrec = lastrow;
	}

	//*** Function to actually make the database connectione etc.
	//and populate the dataset **/
	void FetchData()
	{
		// user id and password
		String *userId = "sa";
		String *password = "";	

		// Connect to the SQL Database and issue a SELECT command all in one statement
		String *query = S"SELECT * FROM Account_Detail";

		// build connect string with the userid and password
		String *connectString = String::Format(S"Data Source=localhost;Database=Banking;UID={0};Password={1};", userId, password);

		// Create the connection object
		SqlConnection* sqlconn = new SqlConnection(connectString);
		sqlconn->Open();
	    
		// Create the command object - actually not required
		//SqlCommand* myCommand = new SqlCommand(query,sqlconn);

		// set the adapter with the main command
		myAdapter = new SqlDataAdapter(query,sqlconn);
		
		// set the Various commands to be operated on the database
		SqlCommandBuilder* DataAdapterCommands = new SqlCommandBuilder(myAdapter);
		
		// Create the Dataset
		ds = new DataSet();

		// Fill the dataset using the fill method of the adapter
		// also include which table has to be used to populate it
		myAdapter->Fill(ds, "Account_Detail");

		// call the functions to fill the fields with the records
		// passing 0 is for the first row
		FillFields(currentrec);

		// Close the connecition
		sqlconn->Close();
	}
	//function to clear the form
	void ClearForm()
	{
		fname->set_Text("");
		lname->set_Text("");
		dob->set_Text("");
		paddr->set_Text("");
		maddr->set_Text("");
		phno->set_Text("");
		emailid->set_Text("");
		refacno->set_Text("");
		amount->set_Text("");
	}
	//HACK Made changes here
	bool ValidateForm()
	{
		if (fname->Text->get_Length()==0)
		{
			error->SetError(fname,"Invalid name");
			return false;
		}
		else
			error->SetError(fname,"");
		if (lname->Text->get_Length()==0)
		{
			error->SetError(lname,"Invalid name");
			return false;
		}
		else
			error->SetError(lname,"");
		if (dob->Text->get_Length()==0)
		{
			error->SetError(dob,"Invalid date of birth");
			return false;
		}
		else
			error->SetError(dob,"");
		if (paddr->Text->get_Length()==0)
		{
			error->SetError(paddr,"Invalid permanent address");
			return false;
		}
		else
			error->SetError(paddr,"");

		if (maddr->Text->get_Length()==0)
		{
			error->SetError(maddr,"Invalid mailing address");
			return false;
		}
		else
			error->SetError(maddr,"");
		if (phno->Text->get_Length()==0)
		{
			error->SetError(phno,"Invalid phone number");
			return false;
		}
		else
			error->SetError(phno,"");
		if (emailid->Text->get_Length()==0)
		{
			error->SetError(emailid,"Invalid e-mail ID");
			return false;
		}
		else
			error->SetError(emailid,"");

		if (refacno->Text->get_Length()==0)
		{
			error->SetError(refacno,"Invalid referral account number");
			return false;
		}
		else
			error->SetError(refacno,"");
		if (amount->Text->get_Length()==0)
		{
			error->SetError(amount,"Invalid amount");
			return false;
		}
		else
			error->SetError(amount,"");
		try
		{
			Convert::ToDouble(amount->Text);
			Convert::ToInt32(refacno->Text);
		}
		catch(...)
		{
			MessageBox::Show("Please specify the amount and referral account number as integers.");
			return false;
		}
		return true;
	}
	/*** function to write into the fields displayed on the form ***/
	void FillFields(int i)
	{
	  DataTable *dtab = new DataTable();

	  DataRow *dr;

	  // set an alias for the data table collections
      dtab = ds->get_Tables()->get_Item(0);

	  //set an alias for the data row collections
	  // based on the value of i
	  dr = dtab->get_Rows()->get_Item(i);

	  if(dr != NULL)
	  {
	  // fill each field on the form with the current dataset row
	  	fname->set_Text(dr->get_Item("First_name")->ToString());
		lname->set_Text(dr->get_Item("Last_name")->ToString());
		dob->set_Text(dr->get_Item("date_birth")->ToString());
		paddr->set_Text(dr->get_Item("Permanent_Addr")->ToString());
		maddr->set_Text(dr->get_Item("Mailing_Addr")->ToString());
		phno->set_Text(dr->get_Item("Phone_Number")->ToString());
		emailid->set_Text(dr->get_Item("eMailID")->ToString());
		refacno->set_Text(dr->get_Item("Ref_Acc_no")->ToString());
		amount->set_Text(dr->get_Item("Balance")->ToString());
	  }
	}
};

// This is the entry point for this application
void main(void)
{
	int iscorrectlogin;
	iscorrectlogin = 1;

	// Call the function to display the bank form
	Application::Run(new BankForm()); 
}

⌨️ 快捷键说明

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