protected void DeleteOrder_Click(object sender, EventArgs e)
 {
     if (int.Parse(VendorDropDown.SelectedValue) == 0)
     {
         MessageUserControl.ShowInfo("", "Error: you must select a vendor");
     }
     else
     {
         MessageUserControl.TryRun(() =>
         {
             PurchasingController sysmgr = new PurchasingController();
             List <OrderDetailsViewModel> orderDetails = GetOrderDetailsFromGridview();
             string comment       = Comments.Text;
             int orderId          = int.Parse(OrderID.Text);
             OrderViewModel order = new OrderViewModel
             {
                 Comment  = Comments.Text,
                 SubTotal = decimal.Parse(SubTotal.Text),
                 Tax      = decimal.Parse(Tax.Text),
                 Total    = decimal.Parse(Total.Text),
                 OrderID  = int.Parse(OrderID.Text)
             };
             sysmgr.DeletePurchaseOrder(int.Parse(VendorDropDown.SelectedValue), order, orderDetails);
         }, "", "SUCCESS: Order Deleted");
         VendorDropDown.SelectedIndex = 0;
         List <OrderDetailsViewModel> resetOrderDetails = new List <OrderDetailsViewModel>();
         VendorViewModel info = new VendorViewModel();
         SetVendor(info.VendorName, info.Contact, info.Phone, info.VendorID);
         OrderViewModel resetOrder = new OrderViewModel();
         SetOrder(resetOrder.Comment, resetOrder.SubTotal, resetOrder.Tax, resetOrder.Total, resetOrder.OrderID);
         OrderDetailsGrid.DataSource = resetOrderDetails;
         OrderDetailsGrid.DataBind();
     }
 }
 protected void InventoryList_ItemCommand(object sender, ListViewCommandEventArgs e)
 {
     if (e.CommandName == "AddToMyOrder")
     {
         OrderDetailsViewModel        product      = GetItemFromListToAddToOrderDetails(e.Item);
         List <OrderDetailsViewModel> orderDetails = GetOrderDetailsFromGridview();
         bool itemAlreadyOnOrder = false;
         foreach (OrderDetailsViewModel item in orderDetails)
         {
             if (item.ProductId == product.ProductId)
             {
                 itemAlreadyOnOrder = true;
             }
         }
         if (itemAlreadyOnOrder)
         {
             MessageUserControl.ShowInfo("", "Error: Cannot have duplicate items in order");
         }
         else
         {
             orderDetails.Add(product);
             OrderDetailsGrid.DataSource = orderDetails;
             OrderDetailsGrid.DataBind();
             string comment = Comments.Text;
             int    orderId = int.Parse(OrderID.Text);
             SetOrder(comment, orderDetails.Sum(x => x.ExtendedCost), orderDetails.Sum(x => x.ExtendedCost) * .05M, orderDetails.Sum(x => x.ExtendedCost) * 1.05M, orderId);
         }
         e.Handled = true;
     }
 }
        protected void SaveOrder_Click(object sender, EventArgs e)
        {
            PurchasingController sysmgr = new PurchasingController();

            if (int.Parse(VendorDropDown.SelectedValue) == 0)
            {
                MessageUserControl.ShowInfo("", "Error: you must select a vendor");
            }
            else
            {
                MessageUserControl.TryRun(() =>
                {
                    List <OrderDetailsViewModel> saveOrderDetails = GetOrderDetailsFromGridview();
                    OrderDetailsGrid.DataSource = saveOrderDetails;
                    OrderDetailsGrid.DataBind();
                    string comment = Comments.Text;
                    int orderId    = int.Parse(OrderID.Text);
                    SetOrder(comment, saveOrderDetails.Sum(x => x.ExtendedCost), saveOrderDetails.Sum(x => x.ExtendedCost) * .05M, saveOrderDetails.Sum(x => x.ExtendedCost) * 1.05M, orderId);
                    OrderViewModel saveOrder = new OrderViewModel
                    {
                        Comment  = Comments.Text,
                        SubTotal = decimal.Parse(SubTotal.Text),
                        Tax      = decimal.Parse(Tax.Text),
                        Total    = decimal.Parse(Total.Text),
                        OrderID  = int.Parse(OrderID.Text)
                    };
                    sysmgr.SavePurchaseOrder(int.Parse(VendorDropDown.SelectedValue), saveOrder, saveOrderDetails);
                }, "", "SUCCESS: Order Saved");
                var order = sysmgr.GetActiveOrder(int.Parse(VendorDropDown.SelectedValue));
                SetOrder(order.Comment, order.SubTotal, order.Tax, order.Total, order.OrderID);
                List <OrderDetailsViewModel> orderDetail = sysmgr.GetActiveOrderDetails(int.Parse(VendorDropDown.SelectedValue));
                OrderDetailsGrid.DataSource = orderDetail;
                OrderDetailsGrid.DataBind();
            }
        }
        protected void OrderDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            var controller = new PurchasingController();
            int rowIndex   = Convert.ToInt32(e.CommandArgument);
            List <OrderDetailsViewModel> orderDetails = GetOrderDetailsFromGridview();
            OrderDetailsViewModel        orderDetail  = orderDetails[rowIndex];

            if (e.CommandName == "Remove_Command")
            {
                orderDetails.Remove(orderDetail);
                OrderDetailsGrid.DataSource = orderDetails;
                OrderDetailsGrid.DataBind();
                string comment = Comments.Text;
                int    orderId = int.Parse(OrderID.Text);
                SetOrder(comment, orderDetails.Sum(x => x.ExtendedCost), orderDetails.Sum(x => x.ExtendedCost) * .05M, orderDetails.Sum(x => x.ExtendedCost) * 1.05M, orderId);
            }
            else if (e.CommandName == "Refresh_Command")
            {
                orderDetails = GetOrderDetailsFromGridview();
                OrderDetailsGrid.DataSource = orderDetails;
                OrderDetailsGrid.DataBind();
                foreach (GridViewRow row in OrderDetailsGrid.Rows)
                {
                    if (row.FindTextBox("UnitCost").Text.ToDecimal() / row.FindLabel("OrderUnitSize").Text.ToInt() >= controller.GetProductSellingPrice(row.FindLabel("ProductId").Text.ToInt()))
                    {
                        row.FindLabel("Warning").Visible = true;
                    }
                }
                string comment = Comments.Text;
                int    orderId = int.Parse(OrderID.Text);
                SetOrder(comment, orderDetails.Sum(x => x.ExtendedCost), orderDetails.Sum(x => x.ExtendedCost) * .05M, orderDetails.Sum(x => x.ExtendedCost) * 1.05M, orderId);
            }
        }
        protected void Refresh_Command(object sender, EventArgs e)
        {
            List <OrderDetailsViewModel> orderDetails = GetOrderDetailsFromGridview();

            OrderDetailsGrid.DataSource = orderDetails;
            OrderDetailsGrid.DataBind();
            string comment = Comments.Text;
            int    orderId = int.Parse(OrderID.Text);

            SetOrder(comment, orderDetails.Sum(x => x.ExtendedCost), orderDetails.Sum(x => x.ExtendedCost) * .05M, orderDetails.Sum(x => x.ExtendedCost) * 1.05M, orderId);
        }
        protected void CancelSelection_Click(object sender, EventArgs e)
        {
            VendorDropDown.SelectedIndex = 0;
            List <OrderDetailsViewModel> orderDetails = new List <OrderDetailsViewModel>();
            VendorViewModel info = new VendorViewModel();

            SetVendor(info.VendorName, info.Contact, info.Phone, info.VendorID);
            OrderViewModel order = new OrderViewModel();

            SetOrder(order.Comment, order.SubTotal, order.Tax, order.Total, order.OrderID);
            OrderDetailsGrid.DataSource = orderDetails;
            OrderDetailsGrid.DataBind();
        }
        protected void OrderDetailsGrid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
        {
            if (e.VisibleIndex == -1)
            {
                return;
            }

            var returnQuanityControl = (OrderDetailsGrid.FindRowCellTemplateControl(e.VisibleIndex, OrderDetailsGrid.Columns[9] as GridViewDataColumn, "ReturnQuantity") as ASPxSpinEdit);
            var quantity             = (OrderDetailsGrid.GetRowValues(e.VisibleIndex, "Quantity") as int?) ?? 0;

            if (quantity > 0)
            {
                returnQuanityControl.Value    = quantity;
                returnQuanityControl.MinValue = 0;
                returnQuanityControl.MaxValue = quantity;
            }
        }
 protected void SelectVendor_Click(object sender, EventArgs e)
 {
     if (VendorDropDown.SelectedIndex == 0)
     {
         MessageUserControl.ShowInfo("", "Error: you must select a vendor");
     }
     else
     {
         var controller = new PurchasingController();
         var info       = controller.GetVendorByID(int.Parse(VendorDropDown.SelectedValue));
         SetVendor(info.VendorName, info.Contact, info.Phone, info.VendorID);
         var order = controller.GetActiveOrder(int.Parse(VendorDropDown.SelectedValue));
         SetOrder(order.Comment, order.SubTotal, order.Tax, order.Total, order.OrderID);
         List <OrderDetailsViewModel> orderDetail = controller.GetActiveOrderDetails(int.Parse(VendorDropDown.SelectedValue));
         OrderDetailsGrid.DataSource = orderDetail;
         OrderDetailsGrid.DataBind();
     }
 }
        protected void SaveLinkButton_OnClick(object sender, EventArgs e)
        {
            var returnType   = Convert.ToInt32(ReturnType.SelectedItem.Value);
            var returnAmount = ReturnAmount.Number;

            var model = new SellInfo
            {
                TotalCashback   = returnAmount,
                IsCashBack      = returnType == 1,
                ReturnOrderID   = _orderID,
                OperatorStockID = _operatorStockID
            };

            model.Goods   = new List <SellGoodInfo>();
            model.Tickets = new List <SellTicketsInfo>();

            for (int i = 0; i < OrderDetailsGrid.VisibleRowCount; i++)
            {
                var returnQuanityControl = (OrderDetailsGrid.FindRowCellTemplateControl(i, OrderDetailsGrid.Columns[9] as GridViewDataColumn, "ReturnQuantity") as ASPxSpinEdit);
                var returnQuantity       = Convert.ToInt32(returnQuanityControl.Value.ToString());
                var goodsID  = OrderDetailsGrid.GetRowValues(i, "GoodsID");
                var ticketID = OrderDetailsGrid.GetRowValues(i, "TicketID");
                var isGoods  = (OrderDetailsGrid.GetRowValues(i, "IsGoods").ToString().ToLower() == "true");

                if (returnQuantity > 0)
                {
                    if (isGoods)
                    {
                        model.Goods.Add(new SellGoodInfo
                        {
                            GoodsID = int.Parse(goodsID.ToString()),
                            Count   = returnQuantity
                        });
                    }
                    else
                    {
                        model.Tickets.Add(new SellTicketsInfo
                        {
                            TicketID = int.Parse(ticketID.ToString())
                        });
                    }
                }
            }

            var xsSubmit = new XmlSerializer(typeof(SellInfo));
            var sww      = new StringWriter();

            xsSubmit.Serialize(XmlWriter.Create(sww), model);
            var xml = sww.ToString();


            var order = new Order();

            order.TX_Order(4, xml);

            if (order.IsError)
            {
                HeaderHF.Text = string.Format("<script>alert('{0}');</script>", order.ErrorMessage);
            }
            else
            {
                HeaderHF.Text = @"<script>Utilities.ClosePopup(0);</script>";
            }
        }