Пример #1
0
    private bool CheckIfCanSale(int productId, int quantity)
    {
        Deposit dep = new Deposit();
        User user = new User();
        CompanyManager cManager = new CompanyManager(this);
        InventoryManager iManager = new InventoryManager(this);

        //
        // Verifies wich deposit are the active deposit to this Company / User
        //
        user.UserId = (Page as InfoControl.Web.UI.DataPage).User.Identity.UserId;
        dep = cManager.GetCurrentDeposit(user.UserId, Company.CompanyId);

        //
        // Get the data of the respectively inventory
        //
        var prod = iManager.GetProductInventory(Company.CompanyId, productId, Deposit.DepositId);

        //
        // Compare the Inventory Quantity wich the Sale quantity, if the Sale Quantity are 
        // less than the Inventory, the Can Sale flag will be true, else the sale will be canceled
        //
        if (quantity <= prod.Quantity) return true;
        else return false;


    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //Manager
        InventoryManager iManager = new InventoryManager(this);
        CompanyManager cManager = new CompanyManager(this);

        //these Objects are Initialized in loop because its necessary provide the Insert with new objects
        Inventory inv;
        InventoryMoviment mov;
        InventoryHistory his;

        DataTable productList = (DataTable)Page.ViewState["ProductList"];
        Inventory inventoryData = new Inventory();
        Product prod = new Product();
        Deposit dep = new Deposit();

        if (productList.Rows.Count <= 1)
        {
            ShowError(Resources.Exception.SelectProduct);
            return;
        }

        productList.Rows.RemoveAt(0);

        dep = cManager.GetCurrentDeposit(User.Identity.UserId, Company.CompanyId);
        try
        {
            foreach (DataRow row in productList.Rows)
            {
                inv = new Inventory();

                if (Deposit != null)
                    inv.DepositId = dep.DepositId;

                inv.CompanyId = Company.CompanyId;
                inv.ProductId = Convert.ToInt16(row["ProductId"]);
                inv.Quantity = Convert.ToInt16(row["Quantity"]);

                mov = new InventoryMoviment();
                mov.CompanyId = inv.CompanyId;
                mov.DepositId = inv.DepositId;
                mov.DepositDestinationId = Convert.ToInt16(cboDeposit.SelectedValue);
                mov.ModifiedDate = DateTime.Now;
                mov.ProductId = inv.ProductId;
                mov.Quantity = inv.Quantity;
                mov.CompanyDestinationId = Convert.ToInt16(cboCompany.SelectedValue);
                mov.Refused = false;

                if (Deposit != null)
                {
                    iManager.InsertStockMovement(inv, mov, Convert.ToInt32(row["Quantity"]), User.Identity.UserId);
                }
                else
                {
                    ShowError("O usuário não está vinculado a nenhum inventário!");
                    return;
                }

                Session["CompanySender"] = Company.CompanyId;
            }
        }
        catch (InvalidOperationException ex)
        {
            ShowError(Resources.Exception.InvalidStockQuantity);
            return;
        }
        InSuccess();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        DataTable productList = (DataTable)Page.ViewState["ProductList"];
        Inventory inv = new Inventory();
        Product prod = new Product();
        Deposit dep = new Deposit();
        InventoryMoviment mov = new InventoryMoviment();
        InventoryManager iManager = new InventoryManager(this);
        CompanyManager cManager = new CompanyManager(this);

        if (productList.Rows.Count < 1)
        {
            ShowError("Deve haver pelo menos uma linha com dados do produto.");
            return;
        }
        foreach (DataRow row in productList.Rows)
        {
            if (row.Table.Rows.IndexOf(row) != 0)
            {
                if (!CheckIfCanSale(Convert.ToInt16(row["ProductId"]), Convert.ToInt16(row["Quantity"])))
                {
                    ShowError("O estoque da linha <b>" + Convert.ToInt16((row.Table.Rows.IndexOf(row)) + 1).ToString() + "</b> não pode ficar negativo<br />");
                    return;
                }
            }
        }




        productList.Rows.RemoveAt(0);

        dep = cManager.GetCurrentDeposit(User.Identity.UserId, Company.CompanyId);

        foreach (DataRow row in productList.Rows)
        {
            inv.CompanyId = Company.CompanyId;
            inv.DepositId = dep.DepositId;
            inv.ProductId = Convert.ToInt16(row["ProductId"]);
            inv.Quantity = Convert.ToInt16(row["Quantity"]);

            mov.CompanyId = inv.CompanyId;
            mov.DepositId = inv.DepositId;
            mov.DepositDestinationId = Convert.ToInt16(cboDeposit.SelectedValue);
            mov.ModifiedDate = DateTime.Now;
            mov.ProductId = inv.ProductId;
            mov.Quantity = inv.Quantity;

            iManager.InventoryDrop(inv, 0, (int)DropType.Transfer, null);
            iManager.InsertStockMovement(inv, mov, inv.Quantity, User.Identity.UserId);
        }
        InSuccess();
    }