Ejemplo n.º 1
0
        //
        // Display_OrderItems()
        //
        // This function displays the contents of a table. ctdbFirstRecord() and
        // ctdbNextRecord() fetch the record. Then each field is parsed and displayed
        //

        static void Display_OrderItems()
        {
            string itemnumb;
            string ordrnumb;

            Console.WriteLine("\n\tOrderItems Table...");

            try
            {
                // read first record
                if (recordOrdrItem.First())
                {
                    do
                    {
                        // get field data from record buffer
                        ordrnumb = recordOrdrItem.GetFieldAsString(2);
                        itemnumb = recordOrdrItem.GetFieldAsString(3);

                        // display data
                        Console.WriteLine("\t   {0}   {1}", ordrnumb, itemnumb);
                    }
                    // read next record until end of file
                    while (recordOrdrItem.Next());
                }
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Ejemplo n.º 2
0
        //
        // Display_CustomerOrders()
        //
        // This function displays the contents of a table. ctdbFirstRecord() and
        // ctdbNextRecord() fetch the record. Then each field is parsed and displayed
        //

        static void Display_CustomerOrders()
        {
            string custnumb;
            string ordrnumb;

            Console.WriteLine("\tCustomerOrder table...");

            try
            {
                // read first record
                if (recordCustOrdr.First())
                {
                    do
                    {
                        ordrnumb = recordCustOrdr.GetFieldAsString(2);
                        custnumb = recordCustOrdr.GetFieldAsString(3);

                        // display data
                        Console.WriteLine("\t   {0}   {1}", ordrnumb, custnumb);
                    }
                    // read next record until end of file
                    while (recordCustOrdr.Next());
                }
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Ejemplo n.º 3
0
        //
        // Display_Records()
        //
        // This function displays the contents of a table. First() and Next()
        // fetch the record. Then each field is parsed and displayed
        //

        static void Display_Records()
        {
            bool   found;
            string custnumb;
            string custname;

            Console.Write("\tDisplay records...");

            try
            {
                // read first record
                found = MyRecord.First();

                while (found)
                {
                    custnumb = MyRecord.GetFieldAsString(0);
                    custname = MyRecord.GetFieldAsString(4);

                    Console.WriteLine("\n\t\t{0,-8}{1,-20}", custnumb, custname);

                    // read next record
                    found = MyRecord.Next();
                }
            }

            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Ejemplo n.º 4
0
        //
        // Delete_Records()
        //
        // This function deletes all the records in the table
        //

        static void Delete_Records(CTRecord record)
        {
            bool found;

            Console.WriteLine("\tDelete records...");

            try
            {
                // enable session-wide lock flag
                MySession.Lock(LOCK_MODE.WRITE_BLOCK_LOCK);

                // read first record
                found = record.First();

                while (found) // while records are found
                {
                    // delete record
                    record.Delete();
                    // read next record
                    found = record.Next();
                }

                // reset session-wide locks
                MySession.Unlock();
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Ejemplo n.º 5
0
        //
        // Delete_Records()
        //
        // This function deletes all the records in the table
        //

        static void Delete_Records()
        {
            bool found;

            Console.WriteLine("\tDelete records...");

            try
            {
                // read first record
                found = MyRecord.First();

                while (found)                  // while records are found
                {
                    // delete record
                    MyRecord.Delete();
                    // read next record
                    found = MyRecord.Next();
                }
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Ejemplo n.º 6
0
        //
        // Delete_Records()
        //
        // This function deletes all the records in the table
        //

        static void Delete_Records(CTRecord record)
        {
            bool found;

            Console.WriteLine("\tDelete records...");

            try
            {
                // write lock required for transaction updates
                record.Lock(LOCK_MODE.WRITE_LOCK);

                // start a transaction
                record.Begin();

                // read first record
                found = record.First();

                while (found) // while records are found
                {
                    // delete record
                    record.Delete();
                    // read next record
                    found = record.Next();
                }

                // commit transaction
                record.Commit();

                // free locks
                record.Unlock();
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Ejemplo n.º 7
0
        //
        // Manage()
        //
        // Populates table and perform a simple query
        //

        static void Manage()
        {
            int    quantity;
            double price, total;
            string itemnumb, custnumb, ordrnumb, custname;
            bool   isOrderFound, isItemFound;

            Console.WriteLine("MANAGE");

            // populate the tables with data
            Add_CustomerMaster_Records();
            Add_CustomerOrders_Records();
            Add_OrderItems_Records();
            Add_ItemMaster_Records();

            // perform a query:
            // list customer name and total amount per order

            // name               total
            // @@@@@@@@@@@@@      $xx.xx

            // for each order in the CustomerOrders table
            //    fetch order number
            //    fetch customer number
            //    fetch name from CustomerMaster table based on customer number
            //    for each order item in OrderItems table
            //       fetch item quantity
            //       fetch item number
            //       fetch item price from ItemMaster table based on item number
            //    next
            // next

            Console.WriteLine("\n\tQuery Results");

            try
            {
                // get the first order
                isOrderFound = recordCustOrdr.First();

                while (isOrderFound) // for each order in the CustomerOrders table
                {
                    // fetch order number
                    ordrnumb = recordCustOrdr.GetFieldAsString(2);
                    // fetch customer number
                    custnumb = recordCustOrdr.GetFieldAsString(3);

                    // fetch name from CustomerMaster table based on customer number
                    recordCustMast.Clear();
                    recordCustMast.SetFieldAsString(0, custnumb);
                    if (!recordCustMast.Find(FIND_MODE.EQ))
                    {
                        continue; // not possible in our canned example
                    }
                    custname = recordCustMast.GetFieldAsString(4);

                    // fetch item price from OrderItems table
                    recordOrdrItem.Clear();
                    recordOrdrItem.SetFieldAsString(2, ordrnumb);
                    // define a recordset to scan only items applicable to this order
                    recordOrdrItem.RecordSetOn(6);
                    isItemFound = recordOrdrItem.First();

                    total = 0;
                    while (isItemFound) // for each order item in OrderItems table
                    {
                        // fetch item quantity
                        recordOrdrItem.GetFieldValue(1, out quantity);
                        // fetch item number
                        itemnumb = recordOrdrItem.GetFieldAsString(3);

                        // fetch item price from ItemMaster table based on item number
                        recordItemMast.Clear();
                        recordItemMast.SetFieldAsString(2, itemnumb);
                        recordItemMast.Find(FIND_MODE.EQ);
                        recordItemMast.GetFieldValue(1, out price);

                        // calculate order total
                        total += (price * quantity);

                        isItemFound = recordOrdrItem.Next();
                    }

                    recordOrdrItem.RecordSetOff();

                    // output data to stdout
                    Console.WriteLine("\t\t{0,-20}{1,-8}", custname, total);

                    // read next order
                    if (!recordCustOrdr.Next())
                    {
                        isOrderFound = false;
                    }
                }
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }