设置查询一次,然后过滤

时间:2019-02-18 21:43:45

标签: c#

我有一个首先执行的方法,例如:

 AssignDesign(tvTable, designFolioList, parent, designName, currentProjectNumber, iDesign, "BDCD", "IS NULL", 0);

如您所见,我发送了一个参数:"IS NULL"是我在方法中使用的查询的条件:

完整方法:

   private void AssignDesign(DataTable designItemList, DataTable designFolioList, TreeNode parent, string designName, string legacyKey, int indexProject, string DesignType, string Conditional, int currDesign)
        {
            var iDesign = 0;


            foreach (var currentDesignItem in designItemList.Select($"[Design Name] = '{designName}' AND [Project Number] = {legacyKey}  AND [ParentDesignKey] {Conditional}"))
            {
                var designItemName = currentDesignItem["DesignItemName"] as string;
                var designItemKey = currentDesignItem["DesignKey"] as int?;
                var designItemStatus = currentDesignItem["Design Status"] as string;
                var designItemIsLocked = currentDesignItem["IsLocked"] as bool?;
                var designItemStatusKey = currentDesignItem["StatusKey"] as int?;
                var designItemCreated = currentDesignItem["Design Created"] as DateTime?;
                var designItemRunCount = currentDesignItem["RunCount"] as int?;
                var designItemRunUnConCount = currentDesignItem["RunUnconCnt"] as int?;
                var designItemShopsStatus = currentDesignItem["ShopsStatus"] as int?;
                var designItemShopStatusExtended = currentDesignItem["ShopStatusExtended"] as string;
                var designItemFolio = designFolioList.Select($"[DesignKey] ={designItemKey}").FirstOrDefault()["Folio"].ToString();
                var changeOrderParentDesignKey = currentDesignItem["ParentDesignKey"] as int?;
                //var designConfirmDeliveryDate = currentDesignItem["ConfirmDeliveryDate"] as DateTime?;

                if (designItemName is null || designItemShopsStatus is null || designItemShopStatusExtended is null || designItemKey is null || designItemStatus is null || designItemStatusKey is null || designItemCreated is null || designItemRunCount is null || designItemRunUnConCount is null || designItemIsLocked is null) continue;


                //var hasConfirmDeliveryDate = designConfirmDeliveryDate != null ? $"|{designConfirmDeliveryDate}": null;

                //Create lowest level and assign their tree nodes
                var projectIndex = parent.Index;
                TreeNodeCollection parentNodes;
                if (DesignType == "BDCD")
                {
                    parent.Nodes[indexProject].Nodes.Add(designItemName);
                    parent.Nodes[indexProject].Nodes[iDesign].Tag = $"{designItemKey.Value}|{projectIndex}|BDCD";
                    parent.Nodes[indexProject].Nodes[iDesign].Name = "Design";
                    parent.Nodes[indexProject].Nodes[iDesign].ToolTipText = $"Design: {designItemName} - Folio: {designItemFolio}";
                    parent.Nodes[indexProject].Nodes[iDesign].ContextMenuStrip = contextMenuDesign;
                    this.LoadDesignStatusNodeIcon(parent.Nodes[indexProject].Nodes, iDesign, designItemStatusKey.Value, designItemIsLocked.Value);
                    parentNodes = parent.Nodes[indexProject].Nodes[iDesign].Nodes;

                }
                else
                {
                    var designTypeString = designItemName.Contains("CO") ? "Change Order:" : "Added Part:";
                    TreeNode tn = parent.Nodes[indexProject].Nodes[currDesign].Nodes.Add(designItemName);
                    parent.Nodes[indexProject].Nodes[currDesign].Nodes[tn.Index].Tag = $"{designItemKey.Value}|{projectIndex}|CO";
                    parent.Nodes[indexProject].Nodes[currDesign].Nodes[tn.Index].Name = "Design";
                    parent.Nodes[indexProject].Nodes[currDesign].Nodes[tn.Index].ToolTipText = $"{designTypeString} {designItemName} - Folio: {designItemFolio}";
                    parent.Nodes[indexProject].Nodes[currDesign].Nodes[tn.Index].ContextMenuStrip = contextMenuDesign;
                    this.LoadChangeOrderNodeIcon(parent.Nodes[indexProject].Nodes[currDesign].Nodes[tn.Index], currDesign, designItemStatusKey.Value, designItemIsLocked.Value);
                    parentNodes = parent.Nodes[indexProject].Nodes[currDesign].LastNode.Nodes;
                }



                parentNodes.Add(new TreeNode($"{designItemCreated.Value.ToLongDateString()} ({designItemCreated.Value.ToString("yyMMdd")})", 8, 8)
                {
                    Name = "Created Date",
                    ToolTipText = "Created Date"
                });
                parentNodes.Add(new TreeNode(designItemStatus, 18, 18)
                {
                    Name = "Design Status",
                    ToolTipText = "Design Status",
                    Tag = $"{designItemStatusKey.Value}|{designItemIsLocked}"
                });
                var imgKey = LoadShopsNodeIcon(designItemShopsStatus.Value);

                parentNodes.Add(new TreeNode(designItemShopStatusExtended, imgKey, imgKey)
                {
                    Name = "Shops Drawing Status",
                    ToolTipText = "Shops Drawing Status",
                    Tag = designItemShopsStatus.Value
                });

                if (designItemRunCount.Value == 0 && designItemRunUnConCount.Value > 0)
                {
                    parentNodes.Add(new TreeNode("Unconsolidated Runs: " + designItemRunUnConCount.Value)
                    {
                        Name = "Unconsolidated Runs",
                        ToolTipText = "Unconsolidated Runs",
                        Tag = designItemRunUnConCount.Value
                    });
                }
                else
                {
                    parentNodes.Add(new TreeNode("Run Count: " + designItemRunCount.Value)
                    {
                        Name = "Run Count",
                        ToolTipText = "Run Count",
                        Tag = designItemRunCount.Value
                    });
                }

                var lastItem = string.Empty;

                foreach (var item in designItemList.Select($"[Design Name] = '{designName}' AND [Project Number] = {legacyKey} AND [ParentDesignKey] = {designItemKey}"))
                {
                    if (lastItem != parent.Text)
                    {
                        AssignDesign(designItemList, designFolioList, parent, designName, legacyKey, indexProject, "COAP", $"= {designItemKey}", iDesign);
                    }
                    lastItem = parent.Text;
                }

                iDesign++;

            }
             }

在方法的最后,我使用此方法的递归,但是我发送了另一个条件:$"= {designItemKey}"

您可以看到我两次执行相同的查询,但是使用了不同的过滤器...有什么方法可以只执行一次查询,然后在需要时进行过滤?问候

0 个答案:

没有答案