Exemplo n.º 1
0
        public CostDbItemSearchMaterial(string q, int categoryID0, int categoryID1, int categoryID2)
        {
            Values = new List <MyKeyValuePair>();
            if (categoryID0 == 0 && q.Length < 3)
            {
                return;
            }

            var db = new SpecificationDbEntities();
            var qs = new QueryStringForMaterialSearch(q);
            List <Model.Material> materials;

            if (categoryID0 > 0)
            {
                materials = db.Materials.Where(x => x.CategoryID0 == categoryID0 &&
                                               (categoryID1 == 0 | x.CategoryID1 == categoryID1) &&
                                               (categoryID2 == 0 | x.CategoryID2 == categoryID2))
                            .ToList();
            }
            else
            {
                materials = db.Materials.Where(x => x.MaterialCategory1.CategoryName.Contains(qs.Q0)).ToList();
            }

            Values = GetMaterialsFilteredByQueryString(qs, materials);
        }
Exemplo n.º 2
0
        private List <MyKeyValuePair> GetStandardItemsFilteredByQueryString(QueryStringForMaterialSearch qString, IEnumerable <EST_Cost_Template> options)
        {
            var values = new List <MyKeyValuePair>();

            foreach (var opt in options)
            {
                var name = opt.Name;
                var b0   = true;
                var b1   = true;
                var b2   = true;

                if (qString.QLength >= 1)
                {
                    if (!name.ToUpper().Contains(qString.Q0))
                    {
                        b0 = false;
                    }
                }
                if (qString.QLength >= 2)
                {
                    if (!name.ToUpper().Contains(qString.Q1))
                    {
                        b1 = false;
                    }
                }
                if (qString.QLength >= 3)
                {
                    if (!name.ToUpper().Contains(qString.Q2))
                    {
                        b2 = false;
                    }
                }
                if (!(b0 & b1 & b2))
                {
                    continue;
                }

                var value = new MyKeyValuePair()
                {
                    Value = name + "--" + 0.ToString("C2") + "/" + "EA",
                    Key   = opt.TemplateID,
                };
                values.Add(value);
            }
            return(values);
        }
Exemplo n.º 3
0
        private List <MyKeyValuePair> GetMaterialsFilteredByQueryString(QueryStringForMaterialSearch qString, IEnumerable <Model.Material> materials)
        {
            var values = new List <MyKeyValuePair>();

            foreach (var m in materials)
            {
                var name = MaterialCommon.GetMaterialName(m);
                var b0   = true;
                var b1   = true;
                var b2   = true;

                if (qString.QLength >= 1)
                {
                    if (!name.ToUpper().Contains(qString.Q0))
                    {
                        b0 = false;
                    }
                }
                if (qString.QLength >= 2)
                {
                    if (!name.ToUpper().Contains(qString.Q1))
                    {
                        b1 = false;
                    }
                }
                if (qString.QLength >= 3)
                {
                    if (!name.ToUpper().Contains(qString.Q2))
                    {
                        b2 = false;
                    }
                }
                if (!(b0 & b1 & b2))
                {
                    continue;
                }
                var value = new MyKeyValuePair()
                {
                    Value = name + "--" + m.Price.ToString("C2") + "/" + m.MaterialPriceUnit.UnitName,
                    Key   = m.MaterialID,
                };
                values.Add(value);
            }
            return(values);
        }
Exemplo n.º 4
0
        public CostDbItemSearchStandardItem(string q, int estItemID)
        {
            var db        = new SpecificationDbEntities();
            var quoteItem = db.EST_Item.Find(estItemID);
            var productID = quoteItem.ProductID;
            var options   = db.EST_Cost_Template.Where(x => x.ProductID == productID).ToList();

            if (MyConvert.IsNullString(q))
            {
                Values = options.Select(x => new MyKeyValuePair()
                {
                    Value = x.Name + "--" + 0.ToString("C2") + "/" + "EA",
                    Key   = x.TemplateID,
                }).ToList();
            }
            else
            {
                var qs = new QueryStringForMaterialSearch(q);
                Values = GetStandardItemsFilteredByQueryString(qs, options);
            }
        }