Exemplo n.º 1
0
    public MainPage()
    {
        InitializeComponent();
        PurchasePriceModel model = new PurchasePriceModel();

        BindingContext = model;
    }
        /// <summary>
        /// Updates the purchase prices when registering a purchase invoice
        /// </summary>
        public void UpdatePurchasePrices(List <PurchaseOrderDetails_Join> PurchaseOrderContentList, int purchaseOrderId)
        {
            foreach (PurchaseOrderDetails_Join row in PurchaseOrderContentList)
            {
                PurchasePriceModel purchasePrice = GlobalConfig.Connection.GetPurchasePrice_By_Id(purchaseOrderId, row.ProductId, PurchaseOrderContentList.IndexOf(row));
                purchasePrice.PurchasePrice = row.PurchasePrice;
                purchasePrice.TaxId         = row.TaxId;

                GlobalConfig.Connection.UpdatePurchasePriceModel(purchasePrice);
            }
        }
        /// <summary>
        /// Updates the selected price(in the UI/database)
        /// </summary>
        private void UpdateProductPriceButton_Click(object sender, EventArgs e)
        {
            PurchasePriceModel purchasePrice = (PurchasePriceModel)SelectedProductPricesListBox.SelectedItem;

            if (purchasePrice != null)
            {
                purchasePrice.PurchasePrice = decimal.Parse(PriceTextBox.Text);
                GlobalConfig.Connection.UpdatePurchasePriceModel(purchasePrice);

                ProductPurchasePriceList = GlobalConfig.Connection.GetPurchasePrices_All();
                UpdateSelectedProduct_PriceListBox();
            }
        }
        /// <summary>
        /// Creates a purchase price for the product on the "row" recieved as a parameter
        /// </summary>
        public void CreatePurchaseOrderPrice(int orderId, int rowIndex, PurchaseOrderDetails_Join row, DateTime documentPostingDate)
        {
            PurchasePriceModel purchasePrice = new PurchasePriceModel()
            {
                ProductId       = row.ProductId,
                PurchasePrice   = row.PurchasePrice,
                PurchaseDate    = documentPostingDate.Date,
                PurchaseOrderId = orderId,
                RowIndex        = rowIndex,
                TaxId           = row.TaxId
            };

            GlobalConfig.Connection.CreatePurchasePrice(purchasePrice);
        }
        /// <summary>
        /// Display in the UI/listbox/textbox changes made to the selected price
        /// </summary>
        private void UpdateSelectedPriceFields()
        {
            PurchasePriceModel purchasePrice = (PurchasePriceModel)SelectedProductPricesListBox.SelectedItem;

            if (purchasePrice != null)
            {
                PriceTextBox.Text      = purchasePrice.PurchasePrice.ToString();
                PurchaseDateLabel.Text = purchasePrice.PurchaseDate.ToShortDateString();
            }
            else
            {
                PriceTextBox.Text      = "";
                PurchaseDateLabel.Text = "Purchase Date";
            }
        }