//add row for order, rows for order details and row for credit card. private bool addOrderDetails() { bool returnValue = true; int orderCode = 0; ItemStockTable itemStockT = new ItemStockTable(); ItemsTable itemT = new ItemsTable(); OrderDetailsTable orderDetailsT = new OrderDetailsTable(); //add order try { OrdersTable ordersTable = new OrdersTable(); DataRow rowToAdd = ordersTable.Dt.NewRow(); DataRow currentRow = OrderToAdd.BuildRow(); orderCode = int.Parse(currentRow["CodeOrder"].ToString()); rowToAdd["CodeOrder"] = currentRow["CodeOrder"]; rowToAdd["IDCust"] = currentRow["IDCust"]; rowToAdd["DateOrder"] = currentRow["DateOrder"]; returnValue = ordersTable.Add(rowToAdd); } catch (Exception) { returnValue = false; } //add order details OrderDetails detailToAdd; groupItemsList(); foreach (var item in ShoppingCartListItems) { if (item.ItemAmount > 0) { detailToAdd = new OrderDetails(); detailToAdd.CodeOrder = orderCode; detailToAdd.CodeItemStoke = itemStockT.getItemStockCode(item.ItemCode, item.ColorCode, item.SizeCode) + ""; //decrease amount of items in stock returnValue = decreaseAmountOfItemInStock(int.Parse(detailToAdd.CodeItemStoke), item.ItemAmount); detailToAdd.Amount = item.ItemAmount; detailToAdd.PriceItem = itemT.getItemPrice(item.ItemCode); detailToAdd.SaleItem = itemT.isSaleItem(item.ItemCode); try { DataRow rowToAdd = detailToAdd.BuildRow(); returnValue = orderDetailsT.Add(rowToAdd); } catch (Exception) { returnValue = false; } } } //add credit card details CreditCardOfCustomers card = new CreditCardOfCustomers(); CreditCardOfCustomersTable creditCardT = new CreditCardOfCustomersTable(); card.CodeCreditCard = creditCardT.getNextCode(); card.CodeOrder = orderCode; card.NumCreditCard = txtNumCard.Text; card.ValidityOfCreditCard = dtpValidate.Value; card.IdOwner = txtBID.Text; card.ThreeNumOnCard = int.Parse(txtBThree.Text); card.TotalOfPrice = lblPaymentSum.Text; card.NumOfPayments = (int)nudNumOfPayments.Value; card.KindOfDeal = "חיוב"; DataRow rowToAddToCreditCardT = card.BuildRow(); try { creditCardT.Add(rowToAddToCreditCardT); } catch (Exception) { returnValue = false; } return(returnValue); }