Exemplo n.º 1
0
        public async Task <IActionResult> OnPostCategory(string category, int?p)
        {
            Category cat = await _db.Categories.Where(c => c.Name == category).FirstOrDefaultAsync();

            if (cat != null)
            {
                Recipes = await PaginatedList <Recipe>
                          .CreateAsync(_db.Recipes
                                       .Where(r => r.Category.Name == category)
                                       .Include(r => r.Category)
                                       .Include(r => r.Author)
                                       .ToList(),
                                       p ?? 1, 16);

                return(new JsonResult(Recipes.Count()));
            }

            return(new JsonResult(false));
        }
Exemplo n.º 2
0
 //删除产品
 private void ExecuteDeleteRecipesCommand(object parameter)
 {
     try
     {
         if (Recipes.Count() == 0)
         {
             return;
         }
         if (MessageBox.Show($"是否删除产品目录", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             int index = Recipes.Count();
             foreach (var _recipe in Recipes)
             {
                 _recipe.Dispose();
             }
             Recipes.Clear();
             GC.Collect();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemplo n.º 3
0
        //加载产品
        private void ExecuteLoadRecipesCommand(object parameter)
        {
            try
            {
                if (Recipes.Count() != 0)
                {
                    return;
                }
                string xmlPath;
                using (System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog())
                {
                    ofd.Multiselect      = false;
                    ofd.InitialDirectory = FilePath.ProductDirectory;
                    if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }
                    xmlPath = ofd.FileName;
                }

                string recipePath = $"{Directory.GetParent(xmlPath).ToString()}\\Recipe\\";
                string modelsPath = $"{Directory.GetParent(xmlPath).ToString()}\\Models\\";
                FilePath.ProductDirectory = Directory.GetParent(Directory.GetParent(modelsPath).ToString()).ToString();

                XElement root = XElement.Load(xmlPath);
                if (root == null)
                {
                    return;
                }

                //1216
                window_Loading = new Window_Loading("正在加载产品......");
                window_Loading.Show();

                foreach (var element in root.Elements())
                {
                    IRecipe recipe = null;
                    switch (element.Name.ToString())
                    {
                    case "IniRecipe":
                        recipe       = new IniRecipe();
                        xmlDirectory = $"{recipePath}Reference\\";
                        break;

                    case "FrameRecipe":
                        recipe       = new FrameRecipe(int.Parse(element.Attribute("Index").Value));
                        xmlDirectory = $"{recipePath}Frame{recipe.RecipeIndex}\\";
                        break;

                    case "ICRecipe":
                        recipe       = new ICRecipe(int.Parse(element.Attribute("Index").Value));
                        xmlDirectory = $"{recipePath}IC{recipe.RecipeIndex}\\";
                        break;

                    case "EpoxyRecipe":
                        recipe       = new EpoxyRecipe(int.Parse(element.Attribute("Index").Value));
                        xmlDirectory = $"{recipePath}Epoxy{recipe.RecipeIndex}\\";
                        break;

                    case "BondRecipe":
                        recipe       = new BondRecipe(int.Parse(element.Attribute("Index").Value));
                        xmlDirectory = $"{recipePath}BondMatch{recipe.RecipeIndex}\\";
                        break;

                    case "BondMeasureRecipe":
                        recipe       = new BondMeasureRecipe(int.Parse(element.Attribute("Index").Value));
                        xmlDirectory = $"{recipePath}BondMeasure{recipe.RecipeIndex}\\";
                        break;

                    case "WireRecipe":
                        recipe       = new WireRecipe(int.Parse(element.Attribute("Index").Value));
                        xmlDirectory = $"{recipePath}Wire{recipe.RecipeIndex}\\";
                        break;

                    case "CutRegionRecipe":
                        recipe       = new CutRegionRecipe();
                        xmlDirectory = $"{recipePath}CutRegion\\";
                        break;

                    case "SurfaceDetectionRecipe":
                        recipe       = new SurfaceDetectionRecipe(int.Parse(element.Attribute("Index").Value));
                        xmlDirectory = $"{recipePath}SurfaceDetection{recipe.RecipeIndex}\\";
                        break;

                    case "FreeRegionRecipe":
                        recipe       = new FreeRegionRecipe(int.Parse(element.Attribute("Index").Value));
                        xmlDirectory = $"{recipePath}FreeRegion{recipe.RecipeIndex}\\";
                        break;

                    case "AroundBallRegionRecipe":
                        recipe       = new AroundBallRegionRecipe();
                        xmlDirectory = $"{recipePath}AroundBallRegion\\";
                        break;

                    default:
                        break;
                    }
                    if (recipe != null)
                    {
                        Recipes.Add(recipe);
                        if (!File.Exists($"{xmlDirectory}{element.Name.ToString()}.xml"))
                        {
                            MessageBox.Show($"{element.Name.ToString()}.xml 文件不存在!");
                        }
                        else
                        {
                            recipe.LoadXML($"{xmlDirectory}{element.Name.ToString()}.xml");
                        }
                    }
                }
                SelectedRecipe = Recipes[0];

                //1216
                window_Loading.Close();
            }
            catch (Exception ex)
            {
                //1216
                window_Loading.Close();
                MessageBox.Show(ex.ToString());
            }
        }