![]() |
Georgetown Cleaning Services |
A view is a technique of creating a query, that is, a means of isolating a few records based on data from an existing table, a query, or another view. To create a view in Microsoft Access, you use the ADO library with the following SQL syntax: CREATE VIEW ViewName AS SELECT Statement The creation of a view starts with the CREATE VIEW expression followed by a name. After the name of the view, use the AS keyword to indicate that you are ready to define the view. Because a view is like a query, it can be defined using a SELECT statement, following the same rules we applied for data sorting or filtering. Here is an example that creates a view: Private Sub cmdCreateRegistration_Click()
Dim conDatabase As ADODB.Connection
Dim SQL As String
Set conDatabase = Application.CurrentProject.Connection
SQL = "CREATE VIEW StudentsIdentification " & _
"AS SELECT FirstName, LastName FROM Students"
conDatabase.Execute SQL
conDatabase.Close
Set conDatabase = Nothing
End Sub
After creating the view, it is internally available to all objects of your database like a query but, because Microsoft Access doesn't have a Views section, you cannot see the view in the Database window. |
|
|
Private Sub Form_Load()
Dim conDatabase As ADODB.Connection
Dim strSQL As String
Set conDatabase = Application.CurrentProject.Connection
strSQL = "CREATE VIEW CleaningOrder " & _
"AS SELECT CustomerName, CustomerPhone, DateLeft, " & _
"TimeLeft, DateExpected, TimeExpected, " & _
"ShirtsUnitPrice, ShirtsQuantity, ShirtsSubTotal, " & _
"PantsUnitPrice, PantsQuantity, Item1Name, " & _
"Item1UnitPrice, Item1Quantity, Item1SubTotal, " & _
"Item2Name, Item2UnitPrice, Item2Quantity, " & _
"Item2SubTotal, Item3Name, Item3UnitPrice, " & _
"Item3Quantity, Item3SubTotal, Item4Name, " & _
"Item4UnitPrice, Item4Quantity, Item4SubTotal, " & _
"CleaningTotal, TaxRate, TaxAmount, " & _
"OrderTotal FROM CleaningOrders;"
conDatabase.Execute strSQL
MsgBox "A data view named CleaningOrder has been created"
conDatabase.Close
Set conDatabase = Nothing
End Sub
|
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||






System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
IsNewOrder = true;
this->oleDbDataAdapter1->Fill(this->dsCleaningOrders1);
}
|
private: System::Void btnReset_Click(System::Object * sender, System::EventArgs * e)
{
IsNewOrder = true;
this->txtCustomerName->Text = S"";
this->txtCustomerPhone->Text = S"";
this->dtpDateLeft->Value = DateTime::Today;
this->dtpTimeLeft->Value = DateTime::Now;
this->dtpDateExpected->Value = DateTime::Today;
this->dtpTimeExpected->Value = DateTime::Now;
this->txtShirtsUnitPrice->Text = S"0.95";
this->txtShirtsQuantity->Text = S"0";
this->txtShirtsSubTotal->Text = S"0.00";
this->txtPantsUnitPrice->Text = S"1.95";
this->txtPantsQuantity->Text = S"0";
this->txtPantsSubTotal->Text = S"0.00";
this->cboItem1->SelectedIndex = 0;
this->txtItem1UnitPrice->Text = S"0.00";
this->txtItem1Quantity->Text = S"0";
this->txtItem1SubTotal->Text = S"0.00";
this->cboItem2->SelectedIndex = 0;
this->txtItem2UnitPrice->Text = S"0.00";
this->txtItem2Quantity->Text = S"0";
this->txtItem2SubTotal->Text = S"0.00";
this->cboItem3->SelectedIndex = 0;
this->txtItem3UnitPrice->Text = S"0.00";
this->txtItem3Quantity->Text = S"0";
this->txtItem3SubTotal->Text = S"0.00";
this->cboItem4->SelectedIndex = 0;
this->txtItem4UnitPrice->Text = S"0.00";
this->txtItem4Quantity->Text = S"0";
this->txtItem4SubTotal->Text = S"0.00";
this->txtCleaningTotal->Text = S"0.00";
this->txtTaxRate->Text = S"5.75";
this->txtTaxAmount->Text = S"0.00";
this->txtOrderTotal->Text = S"0.00";
this->txtReceiptNumber->Text = S"0"
this->txtCustomerName->Focus();
}
|
void CalculateCleaningOrder(void)
{
double unitPriceShirts = 0.95, unitPricePants = 1.75, unitPrice1 = 0.00,
unitPrice2 = 0.00, unitPrice3 = 0.00, unitPrice4 = 0.00;
int qtyShirts = 1, qtyPants = 1, quantity1 = 1,
quantity2 = 1, quantity3 = 1, quantity4 = 1;
double subTotalShirts = 0, subTotalPants = 0, subTotal1 = 0,
subTotal2 = 0, subTotal3 = 0, subTotal4;
double cleaningTotal = 0.00, taxRate = 5.75,
taxAmount = 0.00, orderTotal = 0.00;
// Retrieve the unit price of this item
// Just in case the user types an invalid value, we are using a try...catch
try {
unitPriceShirts = this->txtShirtsUnitPrice->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered for the price of shirts is not valid"
S"\nPlease try again");
}
// Retrieve the number of this item
// Just in case the user types an invalid value, we are using a try...catch
try {
qtyShirts = this->txtShirtsQuantity->Text->ToInt16(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered for the number of shirts is not valid"
S"\nPlease try again");
}
// Calculate the sub-total for this item
subTotalShirts = unitPriceShirts * qtyShirts;
// Display the sub-total in the corresponding text box
this->txtShirtsSubTotal->Text = subTotalShirts.ToString(S"F");
try {
unitPricePants = this->txtPantsUnitPrice->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered for the price of pants is not valid"
S"\nPlease try again");
}
try {
qtyPants = this->txtPantsQuantity->Text->ToInt16(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered for the number of pants is not valid"
S"\nPlease try again");
}
subTotalPants = unitPricePants * qtyPants;
this->txtPantsSubTotal->Text = subTotalPants.ToString("F");
try {
unitPrice1 = this->txtItem1UnitPrice->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered for the price is not valid"
S"\nPlease try again");
}
try {
quantity1 = this->txtItem1Quantity->Text->ToInt16(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered is not valid"
S"\nPlease try again");
}
subTotal1 = unitPrice1 * quantity1;
this->txtItem1SubTotal->Text = subTotal1.ToString("F");
try {
unitPrice2 = this->txtItem2UnitPrice->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered for the price is not valid"
S"\nPlease try again");
}
try {
quantity2 = this->txtItem2Quantity->Text->ToInt16(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered is not valid"
S"\nPlease try again");
}
subTotal2 = quantity2 * unitPrice2;
this->txtItem2SubTotal->Text = subTotal2.ToString("F");
try {
quantity3 = this->txtItem3Quantity->Text->ToInt16(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered is not valid"
S"\nPlease try again");
}
try {
unitPrice3 = this->txtItem3UnitPrice->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered for the price is not valid"
S"\nPlease try again");
}
subTotal3 = quantity3 * unitPrice3;
this->txtItem3SubTotal->Text = subTotal3.ToString("F");
try {
unitPrice4 = this->txtItem4UnitPrice->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered for the price is not valid"
S"\nPlease try again");
}
try {
quantity4 = this->txtItem4Quantity->Text->ToInt16(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The value you entered is not valid"
S"\nPlease try again");
}
subTotal4 = quantity4 * unitPrice4;
this->txtItem4SubTotal->Text = subTotal4.ToString("F");
// Calculate the total
cleaningTotal = subTotalShirts + subTotalPants + subTotal1 +
subTotal2 + subTotal3 + subTotal4;
// Retrieve the value of the tax rate
try {
taxRate = this->txtTaxRate->Text->ToDouble(0);
}
catch(FormatException *)
{
MessageBox::Show(S"The tax rate you entered is invalid"
S"\nPlease try again");
}
// Calculate the amount owed for the taxes
taxAmount = cleaningTotal * taxRate / 100;
// Add the tax amount to the total order
orderTotal = cleaningTotal + taxAmount;
// Display the values of the order summary
this->txtCleaningTotal->Text = cleaningTotal.ToString(S"F");
this->txtTaxAmount->Text = taxAmount.ToString(S"F");
this->txtOrderTotal->Text = orderTotal.ToString(S"F");
}
|
System::Void btnSave_Click(System::Object * sender, System::EventArgs * e)
{
if( IsNewOrder == true )
{
String *strInsert = String::Concat(S"INSERT INTO CleaningOrders(",
S"CustomerName, CustomerPhone, DateLeft, ",
S"TimeLeft, DateExpected, TimeExpected, ",
S"ShirtsUnitPrice, ShirtsQuantity, ",
S"ShirtsSubTotal, PantsUnitPrice, ",
S"PantsQuantity, PantsSubTotal, Item1Name, ",
S"Item1UnitPrice, Item1Quantity, ",
S"Item1SubTotal, Item2Name, Item2UnitPrice, ",
S"Item2Quantity, Item2SubTotal, Item3Name, ",
S"Item3UnitPrice, Item3Quantity, ",
S"Item3SubTotal, Item4Name, Item4UnitPrice, ",
S"Item4Quantity, Item4SubTotal, CleaningTotal, ",
S"TaxRate, TaxAmount, OrderTotal) VALUES(",
S"'", txtCustomerName->Text,
S"', '", txtCustomerPhone->Text,
S"', '", dtpDateLeft->Value,
S"', '", dtpTimeLeft->Value,
S"', '", dtpDateExpected->Value,
S"', '", dtpTimeExpected->Value,
S"', '", txtShirtsUnitPrice->Text,
S"', '", txtShirtsQuantity->Text,
S"', '", txtShirtsSubTotal->Text,
S"', '", txtPantsUnitPrice->Text,
S"', '", txtPantsQuantity->Text,
S"', '", txtPantsSubTotal->Text,
S"', '", cboItem1->Text,
S"', '", txtItem1UnitPrice->Text,
S"', '", txtItem1Quantity->Text,
S"', '", txtItem1SubTotal->Text,
S"', '", cboItem2->Text,
S"', '", txtItem2UnitPrice->Text,
S"', '", txtItem2Quantity->Text,
S"', '", txtItem2SubTotal->Text,
S"', '", cboItem3->Text,
S"', '", txtItem3UnitPrice->Text,
S"', '", txtItem3Quantity->Text,
S"', '", txtItem3SubTotal->Text,
S"', '", cboItem4->Text,
S"', '", txtItem4UnitPrice->Text,
S"', '", txtItem4Quantity->Text,
S"', '", txtItem4SubTotal->Text,
S"', '", txtCleaningTotal->Text,
S"', '", txtTaxRate->Text,
S"', '", txtTaxAmount->Text,
S"', '", txtOrderTotal->Text, S"');");
OleDbCommand *cmdDatabase = new OleDbCommand(strInsert, oleDbConnection1);
oleDbConnection1->Open();
cmdDatabase->ExecuteNonQuery();
oleDbConnection1->Close();
this->btnReset_Click(sender, e);
}
}
|
|
|
||
| Previous | Copyright © 2005-2010 FunctionX, Inc. | Next |
|
|
||