none
How to put two distinct queries in a search entity framework

    Question

  • Hello

    Afternoon friends with wisdom if someone guides me please I'm making a product sale application I have a part where I should look for bulk products I have a bar code that does the search

    My problem is generated when I have to sell products in bulk
    My table products

    IdProduct barcode  name Product price IdMeasure IdSubFamilia

    I wanted to make a query that brings the products with the bar code and the idmeasure = 3 (this is kilogram)

    You have to open a bulk form


    And if the measure is different from 3

    Ask me the other query



    This query that works alone


    It's in text box



    Barcode

      Private void Txtbarcorde_KeyPress (object sender, KeyPressEventArgs e)
            {
                If (TxtCodigoBarras.Text.Length> 0)
                {
                    If (e.KeyChar == Convert.ToChar (Keys.Return))
                    {
                        DetailDentaDTO eDeta = new DetailDentaDTO ();
                        PRODUCT eProd = new PRODUCT ();
                        EProd = objProducto.GetBybarcorde (Txtbarcorde.Text);
                        // eProd = objProducto.GetByCodigoBarras (Txtbarcorde.Text);
                        If (eProd == null)
                        {
                            If (MessageBoxButton.Show ("Product does not exist, Do you want to add it?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                            {
                                Form frm = this.MdiChildren.FirstOrDefault (x => x is FrmProducts);
                                If (frm! = Null)
                                {
                                    Frm.BringToFront ();
                                    Return;
                                }
                                Frm = new FrmProductos (idUsuario);
                                Frm.MdiParent = this.MdiParent;
                                Frm.Show ();
                            }
                            Return;
                        }
                        If (eProd.Stock <= 0)
                        {
                            MessageBox.Show ("Not enough stock to sell", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Return;
                        }


                        EDeta.Quantity = 1;



                        EDeta.barcorde = eProd.barcorde;

                        EDeta.FeedReg = DateTime.Now;
                        EDeta.IdDetalle = 0;
                        EDeta.IdProduct = eProd.IdProduct;
                        EDeta.IdVenta = 0;
                        EDeta.Import = eProd.Price * eDeta.Quantity;
                        EDeta.ProductName = ProductProductName;
                        EDeta.PorcentageIVA = Imposed. Tax rate;
                        EDeta.Price = eProd.Price;
                        Details.Add (eDeta);
                        //DgvDetalle.DataSource = null;
                        DgvDetalle.DataSource = Details;
                        Txtbarcorde.Clear ();
                        Txtbarcorde.Focus ();
                    }
                }
            }

    This is what is in the entity framewok layer

    Public PRODUCT GetBybarcorde (string Code)
            {
                DAL.IRepository repository = new Template.Repository ();
                Try
                {
                    Var product = repository.FindEntity <PRODUCT> (a => a.barcorde == Code, "Sale_Details", "Shopping_Details", "Measure", "SubFamilyProduct");
                    If (product! = Null)
                    {
                        Product.IdFamilia = product.SubFamiliaProducto.IdFamilia;
                        Var fami = new FamilyProduct ();
                        Fami = repository.FindEntity <ProductProduct> (x => x.IdFamilia == product.SubfamilyProduct.IdFamily);
                        Product.familyName = familyfamilyName;
                        Product.MeasureName = product.Measure.Measure1;
                        Product.SubfamilyName = product.SubfamilyProduct.SubfamilyName;
                                
    
                    }
                    Else
                    {
                        Product = null;
                    }
                    Return product;
                }
                Catch (Exception ex)
                {
                    Throw new Exception (ex.Message);
                }
            }

    I am missing some query to filter me by the IdMeasure = 3 (which is kilogram)
    I need to have two setups one for IdMeasure = 3 and one that is different from IdMeasure
    I'm trapped in this by fa
    • Edited by djnilo Tuesday, May 2, 2017 11:46 PM
    Tuesday, May 2, 2017 8:15 PM

All replies

  • The question is kind of clear yet reviewing the code it's unclear where you are stuck.

    For example, I see you are looking for a production in your repository via FindEntity yet not sure why you new up a FamilyProduct then not check to see if the FindEnity is not null (same as newing up Prodcut), if you don't new up a FamilyProduct and FindEntity returns one then you have one else it's null.

    Looking at the TxtCodeKeyBarras, this too is unclear.

    Lastly, I would advise at some point in time creating a class to do the work outside of the forms.

    I suggest editing your post and provide better more concise details and code should only before the parts you have questions on. Strip the code down to bare essentials.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, May 2, 2017 11:19 PM
    Moderator