protected void ForceCloseButton_Click(object sender, EventArgs e) { bool reasonExists = true; MessageUserControl.TryRun(() => { // Data to send to the BLL int poID = int.Parse(PurchaseOrderID.Text); string forceCloseReason = ForceCloseTextBox.Text; List <OpenOrderDetail> OODs = new List <OpenOrderDetail>(); // Ensure a reason for force close is provided if (string.IsNullOrEmpty(forceCloseReason)) { reasonExists = false; } else { // Pull stock item ID and outstanding qty from each detail row foreach (GridViewRow row in ReceivingGrid.Rows) { OpenOrderDetail openOrderDetail = new OpenOrderDetail(); openOrderDetail.StockItemID = int.Parse((row.FindControl("StockItemIDLabel") as Label).Text); openOrderDetail.QtyOutstanding = int.Parse((row.FindControl("QtyOutstandingLabel") as Label).Text); OODs.Add(openOrderDetail); } // Call BLL and send force close information OpenOrderController sysmgr = new OpenOrderController(); sysmgr.OpenOrder_ForceClose(poID, forceCloseReason, OODs); // Reload page content ReloadPageContent(); } }, "Order Closed", "Purchase order was successfully closed"); // External validation message if (!reasonExists) { MessageUserControl.ShowInfo( "Reason Void", "A reason is required for a force close of an order"); } }
/// <summary> /// If a trading competition, cancel open trade if outside 1st position /// </summary> /// <returns>OpenOrderDetail when complete</returns> private OpenOrderDetail TradingCompetitionCheck(OpenOrderDetail ooDetail) { var lastPrice = _tradeType == TradeType.BUY ? _lastSell : _lastBuy; var currentPrice = 0.00000000M; if (_tradeType == TradeType.BUY) { currentPrice = OrderBookSellPrice(); } else { currentPrice = OrderBookBuyPrice(); } _resistanceGotten = true; if (currentPrice == _lastPrice) { _samePriceCheck++; } else { _samePriceCheck = 0; } if (currentPrice == lastPrice) { return(ooDetail); } int? position = _trader.GetPricePostion(ooDetail.price); long unixTime = 0; long timeDiff = 0; if (_botSettings.openOrderTimeMS > 0) { unixTime = _dtHelper.UTCtoUnixTimeMilliseconds(); timeDiff = ooDetail.timestamp + _botSettings.openOrderTimeMS; } if ((position >= 3 && _samePriceCheck < 19) || (unixTime > 0 && unixTime >= timeDiff && currentPrice != _lastPrice)) { _lastPrice = currentPrice; _trader.CancelOpenOrders(); return(null); } _lastPrice = currentPrice; return(ooDetail); }
/// <summary> /// If the set orders have moved out of range, cancel open orders /// </summary> /// <returns>OpenOrderDetail when complete</returns> private OpenOrderDetail CeilingFloorCheck(OpenOrderDetail ooDetail) { var price = 0.00000000M; if (_tradeType == TradeType.SELL) { price = OrderBookSellPrice(); _resistanceGotten = true; } else { price = OrderBookBuyPrice(); _supportGotten = true; } if (price == 0.00000000M) { _trader.CancelOpenOrders(); return(null); } return(ooDetail); }
protected void ReceiveButton_Click(object sender, EventArgs e) { bool qtyIsValid = true; // Tracks if any invalid receive or return quantities were entered bool reasonEntry = true; // Tracks if a reason is not entered for a returned quantity bool userEntry = false; // Tracks if the user has made any entry attempts MessageUserControl.TryRun(() => { // Data to send to the BLL int poID = int.Parse(PurchaseOrderID.Text); List <OpenOrderDetail> OODs = new List <OpenOrderDetail>(); List <int> UPICs = new List <int>(); // Capture received and returned entries foreach (GridViewRow row in ReceivingGrid.Rows) { TextBox qtyReceivedCtrl = row.FindControl("QtyReceived") as TextBox; TextBox qtyReturnedCtrl = row.FindControl("QtyReturned") as TextBox; TextBox returnReasonCtrl = row.FindControl("ReturnReason") as TextBox; int qtyReceived; int qtyReturned; int qtyOutstanding = int.Parse((row.FindControl("QtyOutstandingLabel") as Label).Text); // Validate received quantity if (int.TryParse(qtyReceivedCtrl.Text, out qtyReceived)) { userEntry = true; if (qtyReceived > 0) { // User can not receive more than the outstanding quantity if (qtyReceived > qtyOutstanding) { qtyIsValid = false; SetTextBoxValidity(qtyReceivedCtrl, false); } } else // Invalid entry { qtyIsValid = false; SetTextBoxValidity(qtyReceivedCtrl, false); } } // Validate returned quantity if (int.TryParse(qtyReturnedCtrl.Text, out qtyReturned)) { userEntry = true; if (qtyReturned > 0) { // Return is required to have a reason entered if (string.IsNullOrEmpty(returnReasonCtrl.Text)) { reasonEntry = false; SetTextBoxValidity(returnReasonCtrl, false, InvalidType.Warning); } } else // Invalid entry { qtyIsValid = false; SetTextBoxValidity(qtyReturnedCtrl, false); } } // Only capture and hold open order detail if valid quantities are entered (or text fields are empty) if (qtyIsValid && reasonEntry) { OpenOrderDetail openOrderDetail = new OpenOrderDetail(); openOrderDetail.POID = poID; openOrderDetail.PODetailID = int.Parse((row.FindControl("PODetailIDLabel") as Label).Text); openOrderDetail.StockItemID = int.Parse((row.FindControl("StockItemIDLabel") as Label).Text); openOrderDetail.Description = (row.FindControl("DescriptionLabel") as Label).Text; openOrderDetail.QtyOrdered = int.Parse((row.FindControl("QtyOrderedLabel") as Label).Text); openOrderDetail.QtyOutstanding = qtyOutstanding; openOrderDetail.QtyReceived = qtyReceived; openOrderDetail.QtyReturned = qtyReturned; openOrderDetail.ReturnReason = returnReasonCtrl.Text; OODs.Add(openOrderDetail); } } // Only continue with transaction if valid quantities are entered if (qtyIsValid && reasonEntry) { // Load list with data from previous postbacks UPICs = Session["Session_CartList"] as List <int>; // Ensure the use has made entries (either received items, returns, or unordered items) if (userEntry || UPICs.Count > 0) { userEntry = true; // Call BLL and send updated order details and unordered return cart IDs OpenOrderController sysmgr = new OpenOrderController(); bool isClosed = sysmgr.OpenOrder_Receive(poID, OODs, UPICs); // Reload page content if (isClosed) { ReloadPageContent(); } else { ReloadPageContent(poID); } } } }, "Order Received", "Purchase order was successfully processed"); // External validation messages if (qtyIsValid == false) { MessageUserControl.ShowInfo( "Invalid Quantities", "Receive and Return fields require a valid number (greater than zero & received qty less than the outstanding qty)"); } else if (reasonEntry == false) { MessageUserControl.ShowInfo( "Reason Field(s) Void", "Returned quantities require a reason entry"); } else if (userEntry == false) { MessageUserControl.ShowInfo( "No Entries", "No entries were made for receiving or returning"); } }