예제 #1
0
 public void RemoveContainerRow(ContainerRow row) {
     this.Rows.Remove(row);
 }
예제 #2
0
 public void AddContainerRow(ContainerRow row) {
     this.Rows.Add(row);
 }
예제 #3
0
        public ContainerRow[] Divide(List <Container> containers)
        {
            // Verify total weight is sufficient
            int totalWeight = containers.Sum(c => c.Weight);

            if (totalWeight > MaxWeight)
            {
                throw new Exception("Too much weight");
            }
            if (totalWeight < MaxWeight / 2.0d)
            {
                throw new Exception("Not enough weight");
            }

            if (containers.Any(c => (double)c.Weight / totalWeight > 0.7d))
            {
                throw new Exception("Unbalanced because one container is too heavy");
            }

            ContainerRow[] rows = new ContainerRow[Width];
            for (int i = 0; i < Width; i++)
            {
                rows[i] = new ContainerRow(Length);
            }

            List <Container> sortedContainers = containers.OrderByDescending(v => v.Type.HasFlag(ContainerType.Coolable)).ThenByDescending(v => v.Type.HasFlag(ContainerType.Valuable)).ThenByDescending(v => v.Weight).ToList();

            foreach (var a in sortedContainers)
            {
                Console.WriteLine($"Type: {a.Type}, Weight: {a.Weight}");
            }

            Console.WriteLine("\n\n");

            for (int i = 0; i < sortedContainers.Count; i++)
            {
                bool successful = false;

                // Sort rows by least current containers, and keep original indices (since we need them later on for a check)
                List <KeyValuePair <ContainerRow, int> > a = rows.Select((x, i) => new KeyValuePair <ContainerRow, int>(x, i))
                                                             .OrderBy(r => r.Key.GetTotalContainers())
                                                             .ToList();
                ContainerRow[] sortedRows = a.Select(x => x.Key).ToArray();
                //ContainerRow[] sortedRows = rows;
                int[] originalIndices = a.Select(x => x.Value).ToArray();

                for (int j = 0; j < sortedRows.Length; j++)
                {
                    if (TryAddContainer(rows, originalIndices[j], sortedContainers[i]))
                    {
                        successful = true;
                        break;
                    }
                }

                if (!successful)
                {
                    throw new Exception($"Could not add container (Type: {sortedContainers[i].Type}) to ship!");
                }
            }

            Rows = rows;
            return(rows);
        }
예제 #4
0
 public ContainerRowChangeEvent(ContainerRow row, global::System.Data.DataRowAction action) {
     this.eventRow = row;
     this.eventAction = action;
 }
예제 #5
0
    protected void Bind()
    {
        if (m_checklistRow == null)
        {
            return;
        }

        ContainerRow containerRow = m_checklistRow as ContainerRow;
        ContentRow   contentRow   = m_checklistRow as ContentRow;
        CheckboxRow  checkboxRow  = m_checklistRow as CheckboxRow;

        // Container rows are subclasses of contentrow, so check for contentrow last.
        if (containerRow != null)
        {
            mvItem.SetActiveView(vwRepeater);
            if (!NoHeader)
            {
                lblHeader.Text = HttpUtility.HtmlEncode(m_checklistRow.Content ?? string.Empty);
            }

            List <ChecklistRow> contents   = new List <ChecklistRow>();
            List <ChecklistRow> tabs       = new List <ChecklistRow>();
            List <ChecklistRow> headers    = new List <ChecklistRow>();
            List <ChecklistRow> subheaders = new List <ChecklistRow>();


            foreach (ChecklistRow ckl in containerRow.ContainedItems)
            {
                if (ckl is TabContainer)
                {
                    tabs.Add(ckl);
                }
                else if (ckl is HeaderContainer)
                {
                    headers.Add(ckl);
                }
                else if (ckl is SubHeaderContainer)
                {
                    subheaders.Add(ckl);
                }
                else
                {
                    contents.Add(ckl);
                }
            }

            // OK.  First bind the leaf content nodes - plain text and checkbox items.
            rptRows.DataSource = contents;
            rptRows.DataBind();

            // Now bind subheaders
            if (subheaders.Count != 0)
            {
                rptSubHeaders.DataSource = subheaders;
                rptSubHeaders.DataBind();
            }

            // Now bind the header rows:
            accordionRows.DataSource = headers;
            accordionRows.DataBind();

            // Finally, do any tabs
            for (int i = 0; i < tabs.Count; i++)
            {
                ChecklistRow tabRow            = tabs[i];
                AjaxControlToolkit.TabPanel tp = new AjaxControlToolkit.TabPanel();
                tabRows.Tabs.Add(tp);
                tp.HeaderText = HttpUtility.HtmlEncode(tabRow.Content);
                tp.ID         = String.Format(CultureInfo.InvariantCulture, "cklTabItem{0}", i);
                Controls_ChecklistControls_ChecklistItem ckli = (Controls_ChecklistControls_ChecklistItem)LoadControl("~/Controls/ChecklistControls/ChecklistItem.ascx");
                tp.Controls.Add(ckli);
                ckli.NoHeader = true;
                ckli.DataItem = tabRow;
            }
        }
        else if (checkboxRow != null || contentRow != null)
        {
            rptRows.DataSource = new ChecklistRow[] { m_checklistRow };
            rptRows.DataBind();
        }
    }