Exemplo n.º 1
0
        void GetProduct(Backend.Objects.Product product = null)
        {
            product = product ?? Product;

            //Get
            if (product is object && User is object && Store is object)
            {
                lblProductName.Text    = product.Name;
                lblProductId.Text      = product.Id;
                lblProductPrice.Text   = string.Format("{0} {1}", Store.CurrencySign, product.RetailPrice.ToString());
                lblProductBarcode.Text = product.Barcode;
                lblCurrentStock.Text   = product.Stock.ToString();

                // If is from Search Item then Get Supplier .. Since the couldn't be fetched in another query
                if (product.IsSearchItem)
                {
                    product.Supplier = ProductSupplier.GetSupplier(product.Supplier.Id);
                    product.Image    = Backend.Database.Queries.Product.GetImage(product.ImageBlobId, product.Name, product.Color);
                    //Update
                    Product = product;
                }

                imgProductImage.Image      = product.Image;
                lblProductSupplier.Text    = product.Supplier.Name;
                lblProductSupplyPrice.Text = product.SupplyPrice.ToString();
                lblProductPrice.Text       = product.RetailPrice.ToString();
            }
            else
            {
                Alert.Show("Error", $"Something wrong occured", Alert.AlertType.Error);
            }
        }
Exemplo n.º 2
0
        void Initialize()
        {
            //Get
            if (Product is object && User is object && Store is object)
            {
                if (!Util.Func.IsUserAllowed(User))
                {
                    btnEdit.Visible = false;
                }

                lblProductName.Text = Product.Name;
                lblProductId.Text   = Product.Id;
                lblRetailPrice.Text = string.Format("{0} {1}", Store.CurrencySign, Product.RetailPrice.ToString());
                lblStock.Text       = Product.Stock.ToString();

                lblCreatedDate.Text = Product.CreatedAt.ToShortDateString();

                // If is from Search Item then Get Brand .. Since the couldn't be fetched in another query
                if (Product.IsSearchItem)
                {
                    Product.Tax      = Tax.GetTax(Product.Tax.Id);
                    Product.Brand    = ProductBrand.GetBrand(Product.Brand.Id);
                    Product.Supplier = ProductSupplier.GetSupplier(Product.Supplier.Id);
                    Product.Type     = ProductType.GetTypeById(Product.Type.Id);
                    Product.Image    = Backend.Database.Queries.Product.GetImage(Product.ImageBlobId, Product.Name, Product.Color);
                }

                pnlProductColor.BackColor = Product.Color;
                imgProductImage.Image     = Product.Image;
                lblBrandName.Text         = Product.Brand.Name;
                lblSupplierName.Text      = Product.Supplier.Name;
            }
            else
            {
                Alert.Show("Error", $"Something wrong occured", Alert.AlertType.Error);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get Product
        /// </summary>
        public Response Get(Objects.Product product, bool isSellItem = false)
        {
            //Props
            int      statusCode = 200;
            Response response = new Response();
            string   taxId = null, typeId = null, brandId = null, supplierId = null;

            try
            {
                Database.Connection.Open();

                var noramlQuery   = "SELECT * FROM Products WHERE (ProductId=@ProductId OR  Barcode=@Barcode)";
                var sellItemQuery = " SELECT DISTINCT Products.*, ProductDiscounts.DiscountId,  " +
                                    " IF(ProductDiscounts.DiscountId IS NOT NULL AND " +
                                    "       ( NOW() BETWEEN( SELECT Discounts.StartDate FROM Discounts " +
                                    "       WHERE Discounts.DiscountId = ProductDiscounts.DiscountId )   " +
                                    "       AND( SELECT Discounts.EndDate FROM Discounts WHERE Discounts.DiscountId = ProductDiscounts.DiscountId))," +
                                    "       TRUE, FALSE) " +
                                    " AS IsDiscounted FROM Products " +

                                    " LEFT JOIN ProductDiscounts " +
                                    "   ON(Products.ProductId = ProductDiscounts.ProductId) " +
                                    " LEFT JOIN Discounts " +
                                    "   ON(Discounts.DiscountId = ProductDiscounts.DiscountId) " +
                                    " WHERE (Products.ProductId=@ProductId OR  Products.Barcode=@Barcode) ";

                var query = (isSellItem) ? sellItemQuery : noramlQuery;

                //Execute Query
                MySqlCommand Command = new MySqlCommand(query, Database.Connection);
                Command.Parameters.AddWithValue("ProductId", product.Id);
                Command.Parameters.AddWithValue("Barcode", product.Barcode);
                MySqlDataReader DataReader = Command.ExecuteReader();

                //Read Data
                while (DataReader.Read())
                {
                    product.Id          = DataReader["ProductId"].ToString();
                    product.Barcode     = DataReader["Barcode"].ToString();
                    product.Name        = DataReader["Name"].ToString();
                    product.Description = DataReader["Description"].ToString();

                    product.Stock             = Func.ToDecimal(DataReader["Stock"].ToString());
                    product.IsBalanceRequired = Func.ToBoolean(DataReader["IsBalanceRequired"].ToString());

                    if (isSellItem)
                    {
                        product.IsDiscounted = Func.ToBoolean(DataReader["IsDiscounted"].ToString());
                        product.Discount     = new Objects.DiscountProduct
                        {
                            DiscountId = DataReader["DiscountId"].ToString(),
                            ProductId  = DataReader["ProductId"].ToString(),
                        };
                    }

                    product.SupplyPrice = Func.ToDecimal(DataReader["SupplyPrice"].ToString());
                    product.RetailPrice = Func.ToDecimal(DataReader["RetailPrice"].ToString());
                    product.Markup      = Func.ToDecimal(DataReader["Markup"].ToString());
                    product.ImageBlobId = DataReader["ImageBlobId"].ToString();
                    product.Color       = ColorUtil.HEXToColor(DataReader["Color"].ToString());

                    product.UpdatedAt = Convert.ToDateTime(DataReader["UpdatedAt"].ToString());
                    product.CreatedAt = Convert.ToDateTime(DataReader["CreatedAt"].ToString());

                    taxId      = DataReader["TaxId"].ToString();
                    typeId     = DataReader["TaxId"].ToString();
                    brandId    = DataReader["TaxId"].ToString();
                    supplierId = DataReader["TaxId"].ToString();
                }
                if (!DataReader.HasRows)
                {
                    // Bad Request
                    statusCode = 400;
                }
                else
                {
                    // OK
                    statusCode = 200;
                }

                //Close Connection
                Database.Connection.Close();

                if (statusCode == 200)
                {
                    product.Image = GetImage(product.ImageBlobId, product.Name, product.Color);
                }

                // Get Objects
                product.Type     = ProductType.GetTypeById(typeId);
                product.Brand    = ProductBrand.GetBrand(brandId);
                product.Supplier = ProductSupplier.GetSupplier(supplierId);
                product.Tax      = Tax.GetTax(taxId);

                //Response
                response.StatusCode = statusCode;
                response.Data       = product;
            }
            catch (MySqlException e)
            {
                Logger.QueryError(e, "Product", "Getting Product");
                // Internal Error :
                response.StatusCode = 500;
            }
            //Close Connection if Open
            if (Database.Connection.State == ConnectionState.Open)
            {
                Database.Connection.Close();
            }

            return(response);
        }