Esempio n. 1
0
        static void Add_Records()
        {
            DATA_RECORD[] data = new DATA_RECORD[4];
            data[0] = new DATA_RECORD("1000", "92867", "CA", "1", "Bryan Williams", "2999 Regency", "Orange");
            data[1] = new DATA_RECORD("1001", "61434", "CT", "1", "Michael Jordan", "13 Main", "Harford");
            data[2] = new DATA_RECORD("1002", "73677", "GA", "1", "Joshua Brown", "4356 Cambridge", "Atlanta");
            data[3] = new DATA_RECORD("1003", "10034", "MO", "1", "Keyon Dooling", "19771 Park Avenue", "Columbia");
            int nRecords = data.Length;

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

            try
            {
                for (int i = 0; i < nRecords; i++)
                {
                    MyRecord.Clear();

                    // populate record buffer with data
                    MyRecord.SetFieldAsString(0, data[i].number);
                    MyRecord.SetFieldAsString(1, data[i].zipcode);
                    MyRecord.SetFieldAsString(2, data[i].state);
                    MyRecord.SetFieldAsString(3, data[i].rating);
                    MyRecord.SetFieldAsString(4, data[i].name);
                    MyRecord.SetFieldAsString(5, data[i].address);
                    MyRecord.SetFieldAsString(6, data[i].city);

                    // add record
                    MyRecord.Write();
                }
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Esempio n. 2
0
        static void Add_ItemMaster_Records()
        {
            ITEM_DATA[] data = new ITEM_DATA[4];
            data[0] = new ITEM_DATA(10, (CTMoney)1995, "1", "Hammer");
            data[1] = new ITEM_DATA(3, (CTMoney)999, "2", "Wrench");
            data[2] = new ITEM_DATA(4, (CTMoney)1659, "3", "Saw");
            data[3] = new ITEM_DATA(1, (CTMoney)398, "4", "Pliers");
            int nRecords = data.Length;

            Delete_Records(recordItemMast);

            Console.WriteLine("\tAdd records in table ItemMaster...");

            try
            {
                for (int i = 0; i < nRecords; i++)
                {
                    recordItemMast.Clear();

                    // populate record buffer with data
                    recordItemMast.SetFieldValue(0, data[i].weight);
                    recordItemMast.SetFieldValue(1, data[i].price);
                    recordItemMast.SetFieldAsString(2, data[i].itemnum);
                    recordItemMast.SetFieldAsString(3, data[i].description);

                    // add record
                    recordItemMast.Write();
                }
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Esempio n. 3
0
        static void Add_OrderItems_Records()
        {
            ORDERITEM_DATA[] data = new ORDERITEM_DATA[4];
            data[0] = new ORDERITEM_DATA(1, 2, "1", "1");
            data[1] = new ORDERITEM_DATA(2, 1, "1", "2");
            data[2] = new ORDERITEM_DATA(3, 1, "1", "3");
            data[3] = new ORDERITEM_DATA(1, 3, "2", "3");
            int nRecords = data.Length;

            Delete_Records(recordOrdrItem);

            Console.WriteLine("\tAdd records in table OrderItems...");

            try
            {
                for (int i = 0; i < nRecords; i++)
                {
                    recordOrdrItem.Clear();

                    // populate record buffer with data
                    recordOrdrItem.SetFieldValue(0, data[i].sequencenum);
                    recordOrdrItem.SetFieldValue(1, data[i].quantity);
                    recordOrdrItem.SetFieldValue(2, data[i].ordernum);
                    recordOrdrItem.SetFieldValue(3, data[i].itemnum);

                    // add record
                    recordOrdrItem.Write();
                }
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Esempio n. 4
0
        static void Add_CustomerMaster_Records()
        {
            CUSTOMER_DATA[] data = new CUSTOMER_DATA[4];
            data[0] = new CUSTOMER_DATA("1000", "92867", "CA", "1", "Bryan Williams", "2999 Regency", "Orange");
            data[1] = new CUSTOMER_DATA("1001", "61434", "CT", "1", "Michael Jordan", "13 Main", "Harford");
            data[2] = new CUSTOMER_DATA("1002", "73677", "GA", "1", "Joshua Brown", "4356 Cambridge", "Atlanta");
            data[3] = new CUSTOMER_DATA("1003", "10034", "MO", "1", "Keyon Dooling", "19771 Park Avenue", "Columbia");
            int nRecords = data.Length;

            Delete_Records(recordCustMast);

            Console.WriteLine("\tAdd records in table CustomerMaster...");

            try
            {
                // start a transaction
                MySession.Begin();

                for (int i = 0; i < nRecords; i++)
                {
                    recordCustMast.Clear();

                    // populate record buffer with data
                    recordCustMast.SetFieldAsString(0, data[i].number);
                    recordCustMast.SetFieldAsString(1, data[i].zipcode);
                    recordCustMast.SetFieldAsString(2, data[i].state);
                    recordCustMast.SetFieldAsString(3, data[i].rating);
                    recordCustMast.SetFieldAsString(4, data[i].name);
                    recordCustMast.SetFieldAsString(5, data[i].address);
                    recordCustMast.SetFieldAsString(6, data[i].city);

                    // add record
                    recordCustMast.Write();
                }

                // commit transaction
                MySession.Commit();
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Esempio n. 5
0
        static void Add_CustomerOrders_Records()
        {
            ORDER_DATA[] data = new ORDER_DATA[2];
            data[0] = new ORDER_DATA("09/01/2002", "09/05/2002", "1", "1001");
            data[1] = new ORDER_DATA("09/02/2002", "09/06/2002", "2", "1002");
            int nRecords = data.Length;

            CTDate orderdate   = new CTDate();
            CTDate promisedate = new CTDate();

            Delete_Records(recordCustOrdr);

            Console.WriteLine("\tAdd records in table CustomerOrders...");

            try
            {
                for (int i = 0; i < nRecords; i++)
                {
                    recordCustOrdr.Clear();

                    orderdate.StringToDate(data[i].orderdate, DATE_TYPE.MDCY_DATE);
                    promisedate.StringToDate(data[i].promisedate, DATE_TYPE.MDCY_DATE);
                    // populate record buffer with data
                    recordCustOrdr.SetFieldValue(0, orderdate);
                    recordCustOrdr.SetFieldValue(1, promisedate);
                    recordCustOrdr.SetFieldAsString(2, data[i].ordernum);
                    recordCustOrdr.SetFieldAsString(3, data[i].customernum);

                    // add record
                    recordCustOrdr.Write();
                }
            }
            catch (CTException E)
            {
                Handle_Exception(E);
            }
        }
Esempio n. 6
0
        static void Add_Transactions()
        {
            ORDER_DATA[] orders = new ORDER_DATA[3];
            orders[0] = new ORDER_DATA("09/01/2002", "09/05/2002", "1", "1001");
            orders[1] = new ORDER_DATA("09/02/2002", "09/06/2002", "2", "9999"); // bad customer number
            orders[2] = new ORDER_DATA("09/22/2002", "09/26/2002", "3", "1003");
            int nOrders = orders.Length;

            ORDERITEM_DATA[] items = new ORDERITEM_DATA[6];
            items[0] = new ORDERITEM_DATA("1", 1, 2, "1");
            items[1] = new ORDERITEM_DATA("1", 2, 1, "2");
            items[2] = new ORDERITEM_DATA("2", 1, 1, "3");
            items[3] = new ORDERITEM_DATA("2", 2, 3, "4");
            items[4] = new ORDERITEM_DATA("3", 1, 2, "3");
            items[5] = new ORDERITEM_DATA("3", 2, 2, "99"); // bad item number
            int nItems = items.Length;

            CTDate orderdate = new CTDate();
            CTDate promdate  = new CTDate();
            int    savepoint;
            int    j = 0;

            Delete_Records(recordCustOrdr);
            Delete_Records(recordOrdrItem);

            Console.WriteLine("\tAdd transaction records...");

            // process orders
            for (int i = 0; i < nOrders; i++)
            {
                // start a transaction
                MySession.Begin();

                try
                {
                    recordCustOrdr.Clear();

                    // populate record buffer with order data
                    orderdate.StringToDate(orders[i].orderdate, DATE_TYPE.MDCY_DATE);
                    promdate.StringToDate(orders[i].promdate, DATE_TYPE.MDCY_DATE);
                    recordCustOrdr.SetFieldValue(0, orderdate);
                    recordCustOrdr.SetFieldValue(1, promdate);
                    recordCustOrdr.SetFieldAsString(2, orders[i].ordernum);
                    recordCustOrdr.SetFieldAsString(3, orders[i].custnum);

                    // add order record
                    recordCustOrdr.Write();
                }
                catch (CTException E)
                {
                    // abort transaction on error
                    Handle_Exception(E);
                }

                // set transaction savepoint
                savepoint = recordCustOrdr.SetSavePoint();

                // process order items
                while (items[j].ordernum == orders[i].ordernum)
                {
                    try
                    {
                        recordOrdrItem.Clear();

                        // populate record buffer with order item data
                        recordOrdrItem.SetFieldValue(0, items[j].seqnumber);
                        recordOrdrItem.SetFieldValue(1, items[j].quantity);
                        recordOrdrItem.SetFieldAsString(2, items[j].ordernum);
                        recordOrdrItem.SetFieldAsString(3, items[j].itemnum);

                        // add order item record
                        recordOrdrItem.Write();

                        // check that item exists in ItemMaster table
                        recordItemMast.Clear();
                        recordItemMast.SetFieldAsString(2, items[j].itemnum);
                        if (!recordItemMast.Find(FIND_MODE.EQ))
                        {
                            // if not found, restore back to previous savepoint
                            recordItemMast.RestoreSavePoint(savepoint);
                        }
                        else
                        {
                            // set transaction savepoint
                            savepoint = recordItemMast.SetSavePoint();
                        }
                    }
                    catch (CTException E)
                    {
                        // abort transaction on error
                        Handle_Exception(E);
                    }

                    // bump to next item
                    j++;

                    // exit the while loop on last item
                    if (j >= nItems)
                    {
                        break;
                    }
                }

                // check that customer exists in CustomerMaster table
                recordCustMast.Clear();
                recordCustMast.SetFieldAsString(0, orders[i].custnum);

                // commit or abort the transaction
                if (!recordCustMast.Find(FIND_MODE.EQ))
                {
                    MySession.Abort();
                }
                else
                {
                    MySession.Commit();
                }
            }
        }