Inheritance: ITreeViewItem
示例#1
0
        /// <summary>
        /// Builds the directory tree. A value of null for 'parentItem' denotes the root node.
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="parentItem"></param>
        /// <returns>A TreeViewItem structure</returns>
        public TreeViewItemModel GetDirectoryRecursive(DirectoryInfo directory, TreeViewItemModel parentItem, HttpContextBase ctx)
        {
            // If 'parentNode' is null, assume we're starting at the upload path
            string path = parentItem != null ?
                Path.Combine(parentItem.Value, directory.Name) :
                directory.FullName;

            // Get or initalize list in session
            if (ctx.Session[NetAdvImageSettings._netAdvImageTreeStateSessionKey] == null)
                ctx.Session[NetAdvImageSettings._netAdvImageTreeStateSessionKey] = new List<string>();
            List<string> expandedNodes = ctx.Session[NetAdvImageSettings._netAdvImageTreeStateSessionKey] as List<string>;

            // Create a new TreeViewItem
            TreeViewItemModel item = new TreeViewItemModel()
            {
                Text = directory.Name,
                Value = path,
                ImageUrl = "/Scripts/tiny_mce/plugins/netadvimage/img/folder-horizontal.gif",
                Enabled = true,
                Expanded = parentItem == null ?
                    true : // Expand the root node
                    expandedNodes.Contains(path) // Or... get expanded state from session
            };

            // Recurse through the current directory's sub-directories
            foreach (DirectoryInfo child in directory.GetDirectories())
            {
                TreeViewItemModel childNode = GetDirectoryRecursive(child, item, ctx);
                item.Items.Add(childNode);
            }

            return item;
        }
示例#2
0
        public IEnumerable GetEmployees(TreeViewItemModel node)
        {
            NorthwindDataContext northwind = new NorthwindDataContext();

            int? parentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

            IEnumerable nodes = from item in northwind.Employees
                                where item.ReportsTo == parentId || (parentId == null && item.ReportsTo == null)
                                select new TreeViewItemModel
                                {
                                    Text = item.FirstName + " " + item.LastName,
                                    Value = item.EmployeeID.ToString(),
                                    LoadOnDemand = item.Employees.Count > 0
                                };

              return nodes;
        }
        public ActionResult _AjaxLoadingTree(TreeViewItem node)
        {
            try
            {
                string parentId = !String.IsNullOrEmpty(node.Value) ? (node.Value) : null;
                IList<TreeViewItemModel> nodes = new List<TreeViewItemModel>();

                if (parentId != null)
                {
                    string[] s = parentId.Split(';');
                    if (s != null && s.Length == 4)
                    {
                        FlowDetail currentFlowDetail = new FlowDetail();
                        currentFlowDetail.Item = s[0];
                        string locationFrom = s[1];
                        currentFlowDetail.Flow = s[2];
                        currentFlowDetail.Bom = s[3];
                        var locationFroms = locationFrom.Split(',');
                        currentFlowDetail.DefaultLocationFrom = locationFroms[0];
                        if (locationFroms.Length == 2)
                        {
                            currentFlowDetail.DefaultExtraLocationFrom = locationFroms[1];
                        }
                        currentFlowDetail.CurrentFlowMaster = this.genericMgr.FindById<FlowMaster>(currentFlowDetail.Flow);

                        var newFlowDetails = new List<FlowDetail>();
                        if (currentFlowDetail.CurrentFlowMaster.Type == CodeMaster.OrderType.Production
                            || currentFlowDetail.CurrentFlowMaster.Type == CodeMaster.OrderType.SubContract)
                        {
                            string bom = string.IsNullOrWhiteSpace(currentFlowDetail.Bom) ? currentFlowDetail.Item : currentFlowDetail.Bom;

                            var bomDetails = bomMgr.GetFlatBomDetail(bom, DateTime.Now);
                            newFlowDetails.AddRange(bomDetails.Select(p => new FlowDetail
                            {
                                Item = p.Item,
                                DefaultLocationFrom = string.IsNullOrWhiteSpace(p.Location) ? currentFlowDetail.DefaultLocationFrom : p.Location,
                                DefaultExtraLocationFrom = currentFlowDetail.DefaultExtraLocationFrom
                            }));
                        }
                        else
                        {
                            newFlowDetails.Add(new FlowDetail
                            {
                                Item = currentFlowDetail.Item,
                                DefaultLocationFrom = currentFlowDetail.DefaultLocationFrom,
                                DefaultExtraLocationFrom = currentFlowDetail.DefaultExtraLocationFrom
                            });
                            if (!string.IsNullOrWhiteSpace(currentFlowDetail.Bom)
                                && currentFlowDetail.CurrentFlowMaster.Type == CodeMaster.OrderType.Procurement)
                            {
                                var bomDetails = bomMgr.GetFlatBomDetail(currentFlowDetail.Bom, DateTime.Now);
                                newFlowDetails.AddRange(bomDetails.Select(p => new FlowDetail
                                {
                                    Item = p.Item,
                                    DefaultLocationFrom = string.IsNullOrWhiteSpace(p.Location) ? currentFlowDetail.DefaultLocationFrom : p.Location,
                                    DefaultExtraLocationFrom = currentFlowDetail.DefaultExtraLocationFrom
                                }));
                            }
                        }

                        var flowDetailList = this.genericMgr.FindAllIn<FlowDetail>
                            (" from FlowDetail where Item in(?", newFlowDetails.Select(p => p.Item).Distinct());
                        foreach (var flowDetail in flowDetailList)
                        {
                            flowDetail.CurrentFlowMaster = genericMgr.FindById<FlowMaster>(flowDetail.Flow);
                            flowDetail.DefaultLocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom)
                                ? flowDetail.CurrentFlowMaster.LocationFrom : flowDetail.LocationFrom;
                            flowDetail.DefaultLocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo)
                                ? flowDetail.CurrentFlowMaster.LocationTo : flowDetail.LocationTo;
                            flowDetail.DefaultExtraLocationFrom = string.IsNullOrWhiteSpace(flowDetail.ExtraLocationFrom)
                                ? flowDetail.CurrentFlowMaster.ExtraLocationFrom : flowDetail.ExtraLocationFrom;
                            flowDetail.DefaultExtraLocationTo = string.IsNullOrWhiteSpace(flowDetail.ExtraLocationTo)
                                ? flowDetail.CurrentFlowMaster.ExtraLocationTo : flowDetail.ExtraLocationTo;
                        }

                        foreach (var newFlowDetail in newFlowDetails)
                        {
                            flowDetailList = flowDetailList.Where(p => p.Item == newFlowDetail.Item).ToList();
                            var nextFlowDetails = flowDetailList.Where(p => newFlowDetail.DefaultLocationFrom == p.DefaultLocationTo);

                            #region 如果没有找到,考虑其他来源库位
                            if (nextFlowDetails.Count() == 0 && !string.IsNullOrWhiteSpace(newFlowDetail.DefaultExtraLocationFrom))
                            {
                                var locations = newFlowDetail.DefaultExtraLocationFrom.Split('|').Distinct();
                                foreach (var location in locations)
                                {
                                    nextFlowDetails = flowDetailList.Where(f => f.DefaultLocationTo == location);
                                    if (nextFlowDetails.Count() > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            #endregion

                            #region 如果没有找到,考虑其他目的库位
                            if (nextFlowDetails.Count() == 0)
                            {
                                var locations = flowDetailList.Where(p => !string.IsNullOrWhiteSpace(p.DefaultExtraLocationTo))
                                    .SelectMany(p => p.DefaultExtraLocationTo.Split('|')).Distinct();
                                foreach (var location in locations)
                                {
                                    nextFlowDetails = flowDetailList.Where(f => location == newFlowDetail.DefaultLocationFrom);
                                    if (nextFlowDetails.Count() > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            #endregion

                            FillFlowDetial(nextFlowDetails);
                            foreach (var nextFlowDetail in nextFlowDetails)
                            {
                                Item item = itemMgr.GetCacheItem(nextFlowDetail.Item);
                                TreeViewItemModel tvim = new TreeViewItemModel();
                                tvim.Text = string.Format(Resources.EXT.ControllerLan.Con_LineMaterialLocationFromLocationToMRPweights,
                                    nextFlowDetail.Flow, nextFlowDetail.CurrentFlowMaster.Description, nextFlowDetail.Item,
                                    item.Description, nextFlowDetail.LocationFrom, nextFlowDetail.LocationTo,
                                    nextFlowDetail.MrpWeight, nextFlowDetail.CurrentFlowMaster.FlowTypeDescription);
                                tvim.Value = string.Format("{0};{1};{2};{3}",
                                     nextFlowDetail.Item, nextFlowDetail.LocationFrom, nextFlowDetail.Flow, nextFlowDetail.Bom);
                                tvim.LoadOnDemand = true;
                                nodes.Add(tvim);
                            }
                        }
                    }
                }
                return new JsonResult { Data = nodes };
            }
            catch (Exception ex)
            {
                SaveErrorMessage(ex);
                return new JsonResult { };
            }
        }
        public ActionResult _AjaxLoadingTree(TreeViewItem node)
        {
            try
            {
                string parentId = !String.IsNullOrEmpty(node.Value) ? (node.Value) : null;
                IList<TreeViewItemModel> nodes = new List<TreeViewItemModel>();

                if (parentId != null)
                {
                    string[] s = parentId.Split(',');
                    if (s != null && s.Length == 5)
                    {
                        string hql = string.Empty;
                        bool isDown = bool.Parse(s[0]);
                        DateTime planVersion = DateTime.Parse(s[1]);
                        string fgCode = s[2];
                        string dateIndex = s[3];
                        CodeMaster.TimeUnit dateType = (CodeMaster.TimeUnit)(int.Parse(s[4]));
                        DateTime effdate = DateTime.Now;
                        if (dateType == CodeMaster.TimeUnit.Month)
                        {
                            effdate = DateTime.Parse(string.Format("{0}-01", dateIndex));
                        }
                        else
                        {
                            effdate = Utility.DateTimeHelper.GetWeekIndexDateFrom(dateIndex);
                        }

                        IList<BomDetail> bomDetails = new List<BomDetail>();
                        if (isDown)
                        {
                            bomDetails = bomMgr.GetOnlyNextLevelBomDetail(fgCode, effdate);
                        }
                        else
                        {
                            bomDetails = this.genericMgr.FindAll<BomDetail>
                                (@"select bd from BomDetail as bd where bd.Item = ? and bd.StartDate <= ? 
                                   and (bd.EndDate is null or bd.EndDate >= ?)",
                                 new object[] { fgCode, effdate, effdate });
                        }

                        foreach (var bomDetail in bomDetails)
                        {
                            var bomMaster = this.bomMgr.GetCacheBomMaster(bomDetail.Bom);
                            Item fg = itemMgr.GetCacheItem(bomDetail.Bom);
                            var item = this.itemMgr.GetCacheItem(bomDetail.Item);
                            string currentItemCode = string.Empty;
                            decimal calculatedQty = 1;
                            //1.将bomMaster的单位转成基本单位 
                            var fgQty = itemMgr.ConvertItemUomQty(bomDetail.Bom, bomMaster.Uom, 1, fg.Uom);
                            //2.将BomDetail的单位转成基本单位
                            var itemQty = itemMgr.ConvertItemUomQty(item.Code, bomDetail.Uom, bomDetail.RateQty * (1 + bomDetail.ScrapPercentage) / bomMaster.Qty, item.Uom);
                            //3.单位成品基本用量
                            calculatedQty = itemQty / fgQty;

                            if (isDown)
                            {
                                currentItemCode = bomDetail.Item;
                            }
                            else
                            {
                                currentItemCode = bomDetail.Bom;
                            }

                            var rccpTransGroups = this.genericMgr.FindAll<RccpTransGroup>
                                ("from RccpTransGroup where DateIndex = ? and DateType =? and Item =? and PlanVersion =? ",
                                new object[] { dateIndex, dateType, currentItemCode, planVersion });
                            foreach (var rccpTransGroup in rccpTransGroups)
                            {
                                Item currentItem = itemMgr.GetCacheItem(currentItemCode);

                                TreeViewItemModel tvim = new TreeViewItemModel();
                                tvim.Text = string.Format(Resources.EXT.ControllerLan.Con_ItemRequirementQuantityBomUomScraptRate,
                                    currentItem.Code, currentItem.Description, rccpTransGroup.Qty.ToString("0.####"),
                                    calculatedQty.ToString("0.####"), bomDetail.ScrapPercentage.ToString("0.####"), currentItem.Uom, bomDetail.Uom);

                                tvim.Value = isDown + "," + planVersion + "," + currentItemCode + "," + dateIndex + "," + (int)dateType;
                                tvim.LoadOnDemand = true;
                                nodes.Add(tvim);
                            }
                        }
                    }
                }
                return new JsonResult { Data = nodes };
            }
            catch (Exception ex)
            {
                SaveErrorMessage(ex);
                return new JsonResult { };
            }
        }