Ejemplo n.º 1
0
 internal void OrderBy(Func <T, String> func)
 {
     Rows = Rows.OrderBy(func).ToList();
     for (var i = 0; i < Rows.Count(); i++)
     {
         Rows[i].RowNumber = i + 1;
     }
 }
Ejemplo n.º 2
0
 protected void ObjectInvariant()
 {
     Contract.Invariant(Header.Width > 0);
     Contract.Invariant(Header.Height > 0);
     Contract.Invariant(Header.BytesPerPixelComponent > 0);
     Contract.Invariant(Rows.Count() == Header.Height);
     Contract.Invariant(Rows.All(row => row.Count() == Header.Width * Header.Components.Count));
     Contract.Invariant(Rows.All(row => row.All(IsPixelComponentInRange)));
 }
Ejemplo n.º 3
0
 public override void Render(MarkdownContainer container)
 {
     if (Rows.Count() == 0)
     {
         RenderEmptyTable(container);
     }
     else
     {
         RenderNonEmptyTable(Rows, Metadatas, Sampler, container);
     }
 }
Ejemplo n.º 4
0
        public int GetBottomAttachCells(ExcelCell cell)
        {
            int result = 0;

            if (cell.BottomAttachRow != null)
            {
                var bi = Rows.IndexOf(cell.BottomAttachRow);
                var ti = Rows.IndexOf(cell.Row);
                result = (bi - ti) - 1;
                return(result < 0 ? 0 : result);
            }

            return(Rows.Count(y => y.YPosition > cell.Row.YPosition &&
                              y.YPosition < (cell.Row.YPosition + cell.ActualHeight) - Tolerance));
        }
Ejemplo n.º 5
0
 private void CreateTableIfPossible(ExcelWorksheet worksheet)
 {
     try
     {
         var tableStartRow = (Titles?.Count ?? 0) + 1;
         var tableEndRow   = tableStartRow + (Rows?.Count() ?? 0);
         var columnsCount  = (Columns?.Count ?? 1);
         var tableRange    = worksheet.Cells[tableStartRow, 1, tableEndRow, columnsCount];
         worksheet.Tables.Add(tableRange, StringHelper.GenerateRandomTableName()).TableStyle = TableStyles.None;
     }
     catch
     {
         // ignored
     }
 }
Ejemplo n.º 6
0
 public ImportAttempt ToAttempt()
 {
     return(new ImportAttempt
     {
         Date = Date,
         RowsFailed = null == Rows ? 0 : Rows.Count(x => null != x.Problems && x.Problems.Count > 0),
         RowsProcessed = null == Rows ? 0 : Rows.Count(x => null == x.Problems || x.Problems.Count == 0),
         Step = Step,
         Success = Success,
         Problems = (Problems ?? new List <string>()).Concat(
             (Rows ?? new List <ImportResultRow>())
             .Where(x => x.Problems != null && x.Problems.Count > 0)
             .SelectMany(x => x.Problems))
                    .Take(10).ToList(),
     });
 }
Ejemplo n.º 7
0
        protected virtual void RenderNonEmptyTable(IEnumerable <T> rows, IEnumerable <ColumnMetadata> metadatas, ISampler <T> sampler, MarkdownContainer container)
        {
            var extendedDefinitions = BuildExtendedMetadatas(rows.ElementAt(0), metadatas);

            container.Append($"Result-set with {rows.Count()} row{(rows.Count() > 1 ? "s" : string.Empty)}".ToMarkdownParagraph());
            container.Append(new TableExtended()
            {
                Columns = RenderColumns(extendedDefinitions), Rows = RenderRows(Sampler.GetResult(), extendedDefinitions)
            });

            if (Sampler.GetIsSampled())
            {
                var rowsSkipped = $"{Sampler.GetExcludedRowCount()} (of {Rows.Count()}) rows have been skipped for display purpose.";
                container.Append(rowsSkipped.ToMarkdownParagraph());
            }
        }
        private bool ShouldUpdateMessages(PagedResult <StoredMessage> pagedResult)
        {
            if (FocusedRow == null)
            {
                return(true);
            }

            var hasNewMessageInConversation = Rows.Count(m => m.ConversationId == FocusedRow.ConversationId) != pagedResult.Result.Count(p => p.ConversationId == FocusedRow.ConversationId);

            if (hasNewMessageInConversation)
            {
                return(true);
            }

            var messagesInConversation        = Rows.Where(m => m.ConversationId == FocusedRow.ConversationId);
            var anyConversationMessageChanged = messagesInConversation.Any(message => ShouldUpdateMessage(message, pagedResult.Result.FirstOrDefault(m => m.Id == message.Id)));

            return(anyConversationMessageChanged);
        }
Ejemplo n.º 9
0
        private bool UpdateFile()
        {
            foreach (var row in Rows.Where(row => row.State == RowState.Dirty || row.State == RowState.Added))
            {
                if (Rows.Count(x => x.GetKey() == row.GetKey()) > 1)
                {
                    if (!MessageService.ShowYesNoQuestion(m_editor, string.Format("WARNING ! Found duplicated keys '{0}'. The file may save but a row will be deleted", row.GetKey()) +
                                                          "Continue saving anyway ?"))
                    {
                        SearchType = "Key";
                        SearchText = row.GetKey();
                        OnFindNext(null);
                        return(false);
                    }
                }

                if (row is D2ITextRow)
                {
                    m_file.SetText((row as D2ITextRow).Id, row.Text);
                }
                if (row is D2ITextUiRow)
                {
                    m_file.SetText((row as D2ITextUiRow).Id, row.Text);
                }

                row.State = RowState.None;
            }

            while (m_deletedRows.Count > 0)
            {
                var row = m_deletedRows.Pop();
                if (row is D2ITextRow)
                {
                    m_file.DeleteText((row as D2ITextRow).Id);
                }
                if (row is D2ITextUiRow)
                {
                    m_file.DeleteText((row as D2ITextUiRow).Id);
                }
            }

            return(true);
        }
Ejemplo n.º 10
0
        internal void MergeDown(TableRow tableRow, int cellIndex, int value)
        {
            if (value == 0)
            {
                throw new ArgumentException("Value must be greater than zero. Cannot merge a cell with itself.");
            }

            if (value >= Rows.Count())
            {
                throw new ArgumentOutOfRangeException(nameof(value), $"Value {value} must be less than {Rows.Count()}");
            }

            var rows     = Rows.ToList();
            var rowIndex = rows.IndexOf(tableRow);

            for (int i = 1; i <= value; i++)
            {
                rows[i].Cells[cellIndex].GetVerticalMerge().Val = MergedCellValues.Continue;
            }
        }
        private Summary <dynamic> GetTotalIncentiveDiscount()
        {
            double tid = 0;

            for (int i = 0; i < Rows.Count(); i++)
            {
                var row = (IncentiveReportRow)Rows.ElementAt(i);

                tid += row.Discount;
            }

            var totalIncentiveDiscountForPeriod = new Summary <dynamic>()
            {
                Name   = "Total Incentive Discount",
                Value  = tid,
                Format = ti => string.Format("{0:N2}", (double)ti),
            };

            return(totalIncentiveDiscountForPeriod);
        }
        private Summary <dynamic> GetTotalIncomeSummary()
        {
            double totalIncome = 0;

            for (int i = 0; i < Rows.Count(); i++)
            {
                var row = (ExpectedRoomIncomeReportRow)Rows.ElementAt(i);

                totalIncome += row.NightlyIncome;
            }

            var totalIncomeForPeriod = new Summary <dynamic>()
            {
                Name   = "Total Income",
                Value  = totalIncome,
                Format = ti => string.Format("{0:N2}", (double)ti),
            };

            return(totalIncomeForPeriod);
        }
        public SNums[] UpdateSNArrayWithLicenseAndSKU(DataSet objCryptoLgrDS, SNums[] tempSNArray)
        {
            CommonBL  objCommonBL = new CommonBL();
            DataTable dtSKU       = objCryptoLgrDS.Tables[0];

            for (int n = 0; n < tempSNArray.Count(); n++)
            {
                DataRow[] Rows;

                string str = "SNumTemp like '" + tempSNArray[n].SNum + "'";
                if (str.Contains('%') || str.Contains('*') || str.Contains('-'))
                {
                    str = str.Replace('%', '/');
                }

                else
                {
                    if (str.IsValidString())
                    {
                        Rows = objCryptoLgrDS.Tables[0].Select(str);


                        if (Rows.Count() > 0)
                        {
                            string[] arrSKU = new string[Rows.Count()];

                            for (int s = 0; s < Rows.Count(); s++)
                            {
                                DataRow dr = Rows[s];
                                arrSKU[s] = dr["PartName"].ToString();
                                tempSNArray[n].IsLicensableSNum = true;
                            }
                            tempSNArray[n].SKU = objCommonBL.GetSKUDetailInfo(arrSKU, tempSNArray[n].SNum);
                        }
                    }
                }
            }
            return(tempSNArray);
        }
Ejemplo n.º 14
0
        private static int SlopeCheck(int horizontalMove, int verticalMove)
        {
            int treeCount     = 0;
            int horizontalPos = horizontalMove;

            for (int i = verticalMove; i < Rows.Count(); i += verticalMove)
            {
                string curRow = Rows[i];
                if (curRow[horizontalPos] == '#')
                {
                    treeCount++;
                }
                for (int k = 0; k < horizontalMove; k++)
                {
                    horizontalPos++;
                    if (horizontalPos == RowLength)
                    {
                        horizontalPos = 0;
                    }
                }
            }
            return(treeCount);
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     Wraps creation of an Excel worksheet
        /// </summary>
        internal void AppendWorksheet()
        {
            if (Package == null)
            {
                Package = new ExcelPackage();
            }

            ExcelWorksheet worksheet = Package.Workbook.Worksheets.Add(Name);

            var rowOffset = 0;

            //if no columns specified auto generate them with reflection
            if (Columns == null || !Columns.Any())
            {
                Columns = AutoGenerateColumns();
            }

            //render title rows
            if (Titles != null)
            {
                for (var i = 0; i < Titles.Count; i++)
                {
                    ExcelRange range = worksheet.Cells[rowOffset + 1 + i, 1, rowOffset + 1 + i, Columns.Count];
                    range.Merge = true;
                    range.Value = Titles[i].Title;

                    Configuration.ConfigureTitle?.Invoke(range);
                    Titles[i].ConfigureTitle?.Invoke(range);
                }

                rowOffset = rowOffset + Titles.Count;
            }

            //render headers
            if (AppendHeaderRow)
            {
                for (var i = 0; i < Columns.Count; i++)
                {
                    worksheet.Cells[rowOffset + 1, i + 1].Value = Columns[i].Header;
                    Configuration.ConfigureHeader?.Invoke(worksheet.Cells[rowOffset + 1, i + 1]);
                }

                //configure the header row
                if (Configuration.ConfigureHeaderRow != null)
                {
                    Configuration.ConfigureHeaderRow.Invoke(worksheet.Cells[rowOffset + 1, 1, rowOffset + 1, Columns.Count]);
                }

                rowOffset++;
            }

            CreateTableIfPossible(worksheet);

            //render data
            if (Rows != null)
            {
                for (var r = 0; r < Rows.Count(); r++)
                {
                    for (var c = 0; c < Columns.Count(); c++)
                    {
                        worksheet.Cells[r + rowOffset + 1, c + 1].Value = Columns[c].Map(Rows.ElementAt(r));

                        Configuration.ConfigureCell?.Invoke(worksheet.Cells[r + rowOffset + 1, c + 1], Rows.ElementAt(r));
                    }
                }
            }

            //configure columns
            for (var i = 0; i < Columns.Count; i++)
            {
                Configuration.ConfigureColumn?.Invoke(worksheet.Column(i + 1));
                Columns[i].ConfigureColumn?.Invoke(worksheet.Column(i + 1));
            }
        }
Ejemplo n.º 16
0
 public void AddRow(COBieRow cOBieRow)
 {
     cOBieRow.RowNumber = Rows.Count() + 1;
     Rows.Add((T)cOBieRow);
 }
Ejemplo n.º 17
0
 public void AddRow(T cOBieRow)
 {
     cOBieRow.RowNumber = Rows.Count() + 1;
     Rows.Add(cOBieRow);
 }
Ejemplo n.º 18
0
        public async Task <string> CreateBody(NicheShackContext context)
        {
            // Document
            HtmlDocument doc  = new HtmlDocument();
            HtmlNode     node = HtmlNode.CreateNode("<html><head></head><body></body></html>");

            doc.DocumentNode.AppendChild(node);
            node.SelectSingleNode("body").SetAttributeValue("style", "margin: 0;");

            // Meta
            HtmlNode meta = HtmlNode.CreateNode("<meta>");

            meta.SetAttributeValue("name", "viewport");
            meta.SetAttributeValue("content", "width=device-width, initial-scale=1");
            node.FirstChild.AppendChild(meta);


            // Style
            HtmlNode     style     = HtmlNode.CreateNode("<style>");
            HtmlTextNode styleText = doc.CreateTextNode(
                "a {text-decoration: none}" +
                "body {margin: 0}" +
                "ol, ul {margin-top: 0;margin-bottom: 0;}"
                );

            style.AppendChild(styleText);
            node.FirstChild.AppendChild(style);



            // Main Table
            HtmlNode mainTable = await Table.Create(doc.DocumentNode.FirstChild.LastChild, new TableOptions
            {
                Background = new Background {
                    Color = "#edf0f3"
                },
                CreateRow = true
            }, context);

            // Set alignment to center
            HtmlNode td = mainTable.SelectSingleNode("tr/td");

            td.SetAttributeValue("align", "center");


            // Body
            HtmlNode body = await Table.Create(td, new TableOptions
            {
                Width      = Width,
                Background = Background
            }, context);


            // Rows
            if (Rows != null && Rows.Count() > 0)
            {
                await CreateRows(Rows, body, context);
            }


            return(doc.DocumentNode.InnerHtml);
        }
Ejemplo n.º 19
0
 public HorizontalMatrix(IEnumerable <string> rows)
 {
     Rows   = rows.ToList();
     Height = Rows.Count();
     Length = Height != 0 ? Rows.First().Length : 0;
 }
Ejemplo n.º 20
0
 public bool IsNull()
 {
     return(Rows.Count() == 0 ? true : false);
 }
        public void Render()
        {
            _cells.Clear();
            LayoutRoot.Children.Clear();
            LayoutBorder.BorderBrush = Brush_TableBorder;
            LayoutRoot.RowDefinitions.Clear();
            LayoutRoot.ColumnDefinitions.Clear();

            Enumerable.Range(0, Rows.Count() + 2).ToList().ForEach(i => LayoutRoot.RowDefinitions.Add(new RowDefinition()));
            Enumerable.Range(0, Years.Count() + 2).ToList().ForEach(i => LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(GetColWidth(i))
            }));
            LayoutRoot.RowDefinitions[0].Height = new GridLength(25);

            // Row 1
            _cells.Add(Table.BuildTextBlock(SectionNumber, Brush_TitleCell, Brush_TitleCell, Brush_Title, true), new CellPosition(0, 0));
            _cells.Add(Table.BuildTextBlock(Title, Brush_TitleCell, Brush_TitleCell, Brush_Title), new CellPosition(0, 1, 1, Years.Count + 1));

            // Row 2
            _cells.Add(Table.BuildEmptyCell(Brush_Cell, Brush_CellBorder), new CellPosition(1, 0));
            _cells.Add(Table.BuildEmptyCell(Brush_Cell, Brush_CellBorder), new CellPosition(1, 1));
            Enumerable.Range(0, Years.Count).ToList().ForEach(i => _cells.Add(Table.BuildTextBlock(GetYearHeader(Years[i].Year), Brush_Cell, Brush_CellBorder, Brushes.White, true), new CellPosition(1, i + 2)));

            // Rows
            int r = 2;

            foreach (var row in Rows)
            {
                _cells.Add(Table.BuildTextBlock(row.Key.Last().ToString(), Brush_Cell, Brush_CellBorder, Brushes.White, true), new CellPosition(r, 0));
                _cells.Add(Table.BuildTextBlock(Table.GetRowDescription(row.Key), Brush_LabelCell, Brush_CellBorder, Brushes.White), new CellPosition(r, 1));

                var prop = row.Key;
                var expr = row.Value;

                int c = 2;
                foreach (var year in Years)
                {
                    int y = DocumentManager.CurrentDocument.City.C02 + year.Year;
                    if (year.IsEditable && IsRowEditable(row.Key))
                    {
                        var     valueString = FormatValue(prop, expr[y]);
                        TextBox tb          = Table.BuildTextBox(valueString, Brush_EditCell) as TextBox;
                        tb.GotFocus += (sender, e) =>
                        {
                            (sender as TextBox).BorderBrush     = Brushes.Black;
                            (sender as TextBox).BorderThickness = new Thickness(2);
                        };
                        tb.LostFocus += (sender, e) =>
                        {
                            (sender as TextBox).BorderBrush     = Brushes.WhiteSmoke;
                            (sender as TextBox).BorderThickness = new Thickness(0);

                            double num = 0;
                            double.TryParse((sender as TextBox).Text, out num);
                            if ((sender as TextBox).Text.Contains('%'))
                            {
                                if (double.TryParse((sender as TextBox).Text.Trim('%'), out num))
                                {
                                    num = Convert.ToDouble((sender as TextBox).Text.Trim('%')) / 100.0;
                                }
                            }
                            expr[y] = num;
                            (sender as TextBox).Text = FormatValue(prop, num);
                            base.OnUserInput(e);
                        };
                        _cells.Add(tb, new CellPosition(r, c));
                    }
                    else
                    {
                        double value = 0;
                        if (year.Year == YearDefinition.CodeForAverage)
                        {
                            var temp = Years.Where(x => YearDefinition.IsNormalYear(x.Year)).Select(x => row.Value[x.Year]).Where(x => !double.IsNaN(x));
                            value = temp.Count() > 0 ? temp.Average() : 0;
                            //value = row.Value.KnownYearsAverage;
                        }
                        else if (year.Year == YearDefinition.CodeForSum)
                        {
                            var temp = Years.Where(x => YearDefinition.IsNormalYear(x.Year)).Select(x => row.Value[x.Year]).Where(x => !double.IsNaN(x));
                            value = temp.Count() > 0 ? temp.Sum() : 0;
                            //value = row.Value.KnownYearsSum;
                        }
                        else
                        {
                            value = row.Value.Year(y);
                        }
                        _cells.Add(Table.BuildTextBlock(FormatValue(prop, value), Brush_Cell, Brush_CellBorder, Brushes.White), new CellPosition(r, c));
                    }
                    c++;
                }

                r++;
            }

            foreach (var cell in _cells)
            {
                Grid.SetRow(cell.Key, cell.Value.Row);
                Grid.SetRowSpan(cell.Key, cell.Value.RowSpan);
                Grid.SetColumn(cell.Key, cell.Value.Col);
                Grid.SetColumnSpan(cell.Key, cell.Value.ColSpan);
                LayoutRoot.Children.Add(cell.Key);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        ///     Wraps creation of an Excel worksheet
        /// </summary>
        internal void AppendWorksheet()
        {
            if (Package == null)
            {
                Package = new ExcelPackage();
            }

            ExcelWorksheet worksheet = Package.Workbook.Worksheets.Add(this.Name);

            var rowOffset = 0;

            //if no columns specified auto generate them with reflection
            if (Columns == null || !Columns.Any())
            {
                Columns = AutoGenerateColumns();
            }

            //render title rows
            if (Titles != null)
            {
                for (var i = 0; i < Titles.Count; i++)
                {
                    ExcelRange range = worksheet.Cells[rowOffset + 1, 1, rowOffset + 1, Columns.Count];
                    range.Merge = true;
                    range.Value = Titles[i].Title;
                    if (Titles[i].ConfigureTitle != null)
                    {
                        Titles[i].ConfigureTitle(range);
                    }
                }
                rowOffset = rowOffset + Titles.Count;
            }

            //render headers
            if (AppendHeaderRow)
            {
                for (var i = 0; i < Columns.Count; i++)
                {
                    worksheet.Cells[rowOffset + 1, i + 1].Value           = Columns[i].Header;
                    worksheet.Cells[rowOffset + 1, i + 1].Style.Font.Bold = true;

                    if (ConfigureHeader != null)
                    {
                        ConfigureHeader(worksheet.Cells[rowOffset + 1, i + 1]);
                    }

                    if (Columns[i].ConfigureHeader != null)
                    {
                        Columns[i].ConfigureHeader(worksheet.Cells[rowOffset + 1, i + 1]);
                    }
                }

                //configure the header row
                if (ConfigureHeaderRow != null)
                {
                    ConfigureHeaderRow(worksheet.Cells[rowOffset + 1, 1, rowOffset + 1, Columns.Count]);
                }
                else
                {
                    worksheet.Cells[rowOffset + 1, 1, rowOffset + 1, Columns.Count].AutoFilter = true;
                }

                rowOffset++;
            }

            //render data
            if (Rows != null)
            {
                for (var r = 0; r < Rows.Count(); r++)
                {
                    for (var c = 0; c < Columns.Count(); c++)
                    {
                        worksheet.Cells[r + rowOffset + 1, c + 1].Value = Columns[c].Map(Rows.ElementAt(r));

                        if (this.ConfigureCell != null)
                        {
                            this.ConfigureCell(worksheet.Cells[r + rowOffset + 1, c + 1], Rows.ElementAt(r));
                        }
                        if (Columns[c].ConfigureCell != null)
                        {
                            Columns[c].ConfigureCell(worksheet.Cells[r + rowOffset + 1, c + 1], Rows.ElementAt(r));
                        }
                    }
                }
            }

            //configure columns
            for (var i = 0; i < Columns.Count; i++)
            {
                if (ConfigureColumn != null)
                {
                    ConfigureColumn(worksheet.Column(i + 1));
                }
                if (Columns[i].ConfigureColumn != null)
                {
                    Columns[i].ConfigureColumn(worksheet.Column(i + 1));
                }
            }
        }