예제 #1
0
        public override object GetData(ITabContext context)
        {
            try
            {
                var sitecoreData = _sitecoreRequest.GetData();

                if (!sitecoreData.HasData()) return null;

                var itemSummary = new ItemSummary(sitecoreData).Create();

                if (string.IsNullOrEmpty(itemSummary)) return null;

                var plugin = Plugin.Create("Item", itemSummary);

                var itemSection = new ItemSection(sitecoreData).Create();
                var contextSection = new ContextSection(sitecoreData).Create();
                var serverSection = new ServerSection(sitecoreData).Create();

                if (itemSection != null)
                    plugin.AddRow().Column("Item").Column(itemSection).Selected();

                if (contextSection != null)
                    plugin.AddRow().Column("Context").Column(contextSection).Quiet();

                if (serverSection != null)
                    plugin.AddRow().Column("Server").Column(serverSection);

                return plugin;
            }
            catch (Exception ex)
            {
                return new { Exception = ex };
            }
        }
예제 #2
0
        public static void FixMechDiag(SEGRepository segR)
        {
            using (SEGContext seg = segR.GetContext())
            {
                DiagnosticsType dtGen = seg.DiagnosticsTypes.FirstOrDefault(a => a.Name == "General");
                DiagnosticsType dtMec = seg.DiagnosticsTypes.FirstOrDefault(a => a.Name == "Mechanical");
                DiagnosticsType dtEle = seg.DiagnosticsTypes.FirstOrDefault(a => a.Name == "Electrical");

                ItemClass icGen = seg.ItemClasses.FirstOrDefault(a => a.Name == "General");
                ItemClass icMec = seg.ItemClasses.FirstOrDefault(a => a.Name == "Mechanical");
                ItemClass icEle = seg.ItemClasses.FirstOrDefault(a => a.Name == "Electrical");

                bool hasSS = false;
                int idx = 0;
                ItemSection iS = null;
                ItemSubSection iSS = null;

                List<Item> fItems = seg.Items.Where(x => x.ItemClassId == icMec.Id).ToList();
                List<ItemSection> fItemSections = new List<ItemSection>();
                List<ItemSubSection> fItemSubSections = new List<ItemSubSection>();
                foreach (Item i in fItems)
                {
                    ItemSection aiS = null;
                    if(fItemSections.Count>0)
                        aiS = fItemSections.FirstOrDefault(x => x.Id == i.ItemSectionId);
                    if(aiS==null)
                    {
                        aiS = seg.ItemSections.FirstOrDefault(x => x.Id == i.ItemSectionId);
                        fItemSections.Add(aiS);
                    }

                    if (i.ItemSubSectionId != Guid.Empty)
                    {
                        ItemSubSection aiSS = null;
                        if (fItemSubSections.Count > 0)
                            aiSS = fItemSubSections.FirstOrDefault(x => x.Id == i.ItemSubSectionId);
                        if (aiSS == null)
                        {
                            aiSS = seg.ItemSubSections.FirstOrDefault(x => x.Id == i.ItemSubSectionId);
                            fItemSubSections.Add(aiSS);
                        }
                    }
                }

                StreamReader sr = new StreamReader(@"Data\mechanical2.txt", System.Text.Encoding.GetEncoding(1252), true);
                while (!sr.EndOfStream)
                {
                    string sline = sr.ReadLine();
                    char[] delimiters = new char[] { '\t' };
                    string[] sitems = sline.Split(delimiters);

                    // Let's see what the first value has
                    if (sitems[0] == "section")
                    {
                        iS = new ItemSection();
                        string scode = sitems[1].Trim();
                        iS.Code = scode;
                        iS.Title = sitems[5].Replace("\"", "").Trim();

                        // Now we try to find the code within fItemSections
                        if (fItemSections.FirstOrDefault(x => x.Code == iS.Code) == null)
                        {
                            // We now add it
                            seg.ItemSections.Add(iS);
                            seg.SaveChanges();
                            Console.WriteLine("Added Section :" + iS.Code);
                        }
                        else
                            iS = fItemSections.FirstOrDefault(x => x.Code == iS.Code);

                        hasSS = false;
                    }
                    else if (sitems[0] == "print")
                    {
                        iSS = new ItemSubSection();
                        iSS.ItemSectionId = iS.Id;

                        string scode = sitems[1].Trim();
                        scode = scode + "." + sitems[2].Trim();
                        // Check if item 3 is a 0 or empty
                        if (sitems[3].Trim() == "0" || sitems[3].Trim() == "")
                        {
                            // Nothing
                        }
                        else
                        {
                            scode = scode + "." + sitems[3].Trim();
                        }
                        if (sitems[4].Trim().Length > 0)
                        {
                            scode = scode + "|" + sitems[4].Trim();
                        }
                        else
                        {
                            // Nothing
                        }

                        iSS.Code = scode;
                        iSS.Title = sitems[5].Replace("\"", "").Trim();

                        // Now we try to find the code within fItemSections
                        if (fItemSubSections.FirstOrDefault(x => x.Code == iSS.Code) == null)
                        {
                            // We now add it
                            seg.ItemSubSections.Add(iSS);
                            seg.SaveChanges();
                            Console.WriteLine("Added SubSection :" + iSS.Code);
                        }
                        else
                            iSS = fItemSubSections.FirstOrDefault(x => x.Code == iSS.Code);

                        hasSS = false;
                    }
                    else
                    {
                        // Check code, and based on the last item, see if it is in SS or not
                        string scode = sitems[1].Trim();
                        scode = scode + "." + sitems[2].Trim();
                        // Check if item 3 is a 0
                        if (sitems[3].Trim() == "0" || sitems[3].Trim() == "")
                        {
                            // Nothing
                        }
                        else
                        {
                            scode = scode + "." + sitems[3].Trim();
                        }

                        if (sitems[4].Trim().Length > 0)
                        {
                            scode = scode + "|" + sitems[4].Trim();
                            hasSS = true;
                        }
                        else
                        {
                            hasSS = false;
                        }

                        Item i = new Item();
                        i.Index = idx;
                        i.ItemSectionId = iS.Id;
                        if (hasSS)
                            i.ItemSubSectionId = iSS.Id;
                        else
                            i.ItemSubSectionId = Guid.Empty;
                        i.ItemClassId = icMec.Id;
                        i.Code = scode;
                        i.Title = sitems[5].Replace("\"", "").Trim();

                        if (fItems.FirstOrDefault(x => x.Code == i.Code) == null)
                        {
                            // We now add it
                            seg.Items.Add(i);
                            seg.SaveChanges();
                            Console.WriteLine("Added Item :" + i.Code);
                        }
                        else
                        {
                            i = seg.Items.FirstOrDefault(x => x.Code == i.Code && x.ItemClassId == icMec.Id);
                            i.Index = idx;
                            seg.SaveChanges();
                        }
                        idx++;
                    }
                }
                sr.Close();
            }
        }
        public void Update(ItemSection section, int viewSize, int imageSize)
        {
            _titleTextView.Text = section.Title;

            ItemsView.SetAdapter(new ItemCarouselAdapter(section.Items, viewSize, imageSize));
        }
예제 #4
0
        // Methods
        public void PostItem(
            string name,
            string description,
            ItemSection section,
            int categoryId,
            int amount,
            ItemCondition condition,
            ItemWarranty warranty,
            ItemDuration duration,
            int userId)
        {
            // Check if parameters are valid...
            if (string.IsNullOrEmpty(name.Trim()) | name.Trim().Length > 50)
            {
                throw new ValidationException("Item name is either blank or has exceeded 50 characters.");
            }

            if (string.IsNullOrEmpty(description.Trim()) | description.Trim().Length > 500)
            {
                throw new ValidationException("Description is either blank or has exceeded 500 characters.");
            }

            if (categoryId <= 0)
            {
                throw new ValidationException("Category is invalid.");
            }

            if (amount <= 0)
            {
                throw new ValidationException("Amount is invalid");
            }

            if (userId <= 0)
            {
                throw new ValidationException("User is invalid.");
            }

            // Get date and time stamps...
            var timeStamp = DateTime.Now;

            // Insert header...
            var header = _headerRepository.Insert(
                new Header()
            {
                Title   = name,
                UserId  = userId,
                Created = timeStamp,
                Updated = timeStamp
            });

            if (header.Id <= 0)
            {
                throw new ApplicationException(@"Failure inserting to table ""Header"".");
            }

            // Insert entry...
            var entry = _entryRepository.Insert(
                new Entry()
            {
                Message  = description,
                HeaderId = header.Id,
                UserId   = userId,
                Created  = timeStamp,
                Updated  = timeStamp
            });

            // Insert item...
            var item = _itemRepository.Insert(
                new Item()
            {
                HeaderId   = header.Id,
                CategoryId = categoryId,
                UserId     = userId,
                Amount     = amount,
                Section    = section,
                Condition  = condition,
                Warranty   = warranty,
                Created    = timeStamp,
                Updated    = timeStamp,
                Expiry     = timeStamp.AddDays((int)duration)
            });

            // Commit - let the caller of this method handle the transaction...
            //var inserted = _unitOfWork.Commit();
            //return inserted;
        }