Exemple #1
0
        private void placeOrderAddItemBtn_Click(object sender, EventArgs e)
        {
            if (placeOrderItemNameCbox.Text.ToString().CompareTo("") != 0)
            {
                try
                {
                    ItemDataAccess      itemOb  = new ItemDataAccess();
                    OrderInfoDataAccess orderOb = new OrderInfoDataAccess();
                    string itemName             = placeOrderItemNameCbox.Text.ToString();
                    double itemUnitPrice        = itemOb.getItemUnitPrice(itemName);
                    int    qty = Convert.ToInt32(placeOrderQtyUpDown.Value);
                    int    orderId;

                    if (placeOrderIdLabel.Text.ToString().CompareTo("") == 0)
                    {
                        string sql = "Insert into ORDERINFO (ID,STATUS) VALUES(order_orderid_seq.NEXTVAL,'FALSE')";
                        orderOb.addOrderDetails(sql);
                        orderId = orderOb.getCurrentOrderId();
                        placeOrderIdLabel.Text       = Convert.ToString(orderId);
                        placeOrder_orderTotal.Text   = "0.0";
                        placeOrder_vatTotal.Text     = "0.0";
                        placeOrder_netTotal.Text     = "0.0";
                        placeOrder_discountTbox.Text = "0.0";
                    }
                    orderId = Convert.ToInt32(placeOrderIdLabel.Text.ToString());
                    string addOrderdItemSql = "Insert into ORDEREDITEM VALUES(" + orderId + "," + qty + "," + itemUnitPrice + ",'" + itemName + "')";
                    orderOb.addOrderDetails(addOrderdItemSql);


                    string           connStr = "Data Source=localhost; User Id= Tokee; Password=12345";
                    OracleConnection conn    = new OracleConnection(connStr);

                    string orderedItemListSql = "select ITEMNAME, ITEMUNITPRICE, ITEMQTY from ORDEREDITEM where ORDERID =" + orderId + "";


                    OracleDataAdapter adapter = new OracleDataAdapter(orderedItemListSql, conn);
                    DataTable         dt      = new DataTable();
                    adapter.Fill(dt);
                    placeOrderItemList.DataSource = dt;


                    orderTotal = orderTotal + (itemUnitPrice * qty);
                    vatTotal   = orderTotal * 0.15;
                    netTotal   = orderTotal + vatTotal;
                    placeOrder_orderTotal.Text = Convert.ToString(orderTotal);
                    placeOrder_vatTotal.Text   = Convert.ToString(vatTotal);
                    placeOrder_netTotal.Text   = Convert.ToString(netTotal);

                    placeOrderItemNameCbox.Items.Clear();
                    placeOrderItemCategoryCbox.Items.Clear();
                    itemCategoryComboboxFill();
                    itemListCategoryComboboxDefaultSelect();
                    placeOrderQtyUpDown.Value = placeOrderQtyUpDown.Minimum;
                }

                catch (Exception exc)
                {
                    MetroFramework.MetroMessageBox.Show(this, exc.ToString());
                }
            }
            else
            {
                MetroFramework.MetroMessageBox.Show(this, "No Item Selected");
            }
        }