Beispiel #1
0
        /// <summary>
        /// Advances to the next QueryRow in the results, or false
        /// if there are no more results.
        /// </summary>
        public QueryRow GetRow(Int32 index)
        {
            var row = Rows.ElementAt(index);

            row.Database = Database; // Avoid multiple enumerations by doing this here instead of the constructor.
            return(row);
        }
Beispiel #2
0
 public void ZoomRows(double scale)
 {
     if (scale <= 0.0)
     {
         return;
     }
     //The following ensures the screen is not refreshed in any way, saving a lot of redraw time and rows now resize smoothly.
     grid.AllowGridResize = false;
     EnableDisableHandlers(false);
     //sets the new rowheight
     rowHeight = (int)(rowHeight * scale);
     //Updastes all rows with new rowheight
     foreach (Row r in Rows)
     {
         if (r.Height * scale > grid.Height)
         {
             continue;                                                 //Don't scale a row beyond the grid height. How big do you need it?
         }
         r.Height = (int)(r.Height * scale);
     }
     //Enables handlers and refreshes row and grid heights.
     EnableDisableHandlers();
     grid.AllowGridResize = true;
     LayoutRows();
     Rows.ElementAt(0).Height = Rows.ElementAt(0).Height;
 }
Beispiel #3
0
        public string GetData()
        {
            if (Columns.Count == 0)
            {
                return("");
            }
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0,-20}", "id");
            foreach (var column in Columns)
            {
                sb.AppendFormat("|{0,-20}", column.Name);
            }
            if (Rows.Count == 0)
            {
                return(sb.ToString());
            }
            sb.AppendLine();
            for (int i = 0; i < Rows.Count; ++i)
            {
                JObject jObject = JObject.Parse(Rows.ElementAt(i).Data);
                sb.AppendFormat("{0, -20}", i.ToString());
                foreach (var column in Columns)
                {
                    sb.AppendFormat("|{0,-20}", jObject[column.Name].ToString());
                }
                sb.AppendLine();
            }
            return(sb.ToString());
        }
Beispiel #4
0
 public void ZoomRows(double scale)
 {
     if (scale <= 0.0)
     {
         return;
     }
     //The following ensures the screen is not refreshed in any way, saving a lot of redraw time and rows now resize smoothly.
     grid.AllowGridResize = false;
     EnableDisableHandlers(false);
     //sets the new row height
     rowHeight = (int)(rowHeight * scale);
     //Updates all rows with new row height
     foreach (Row r in Rows)
     {
         if (r.Height * scale > grid.Height)
         {
             continue;                                                 //Don't scale a row beyond the grid height. How big do you need it?
         }
         r.Height = (int)(r.Height * scale);
     }
     //Enables handlers and refreshes row and grid heights.
     EnableDisableHandlers();
     grid.AllowGridResize = true;
     LayoutRows();
     //This seemingly do nothing line of code actually forces the row to fire the row height changed to
     //compensate for the events being disabled in the code above that actually makes the changes
     Rows.ElementAt(0).Height = Rows.ElementAt(0).Height;
 }
Beispiel #5
0
 /// <summary>
 /// Gets the query row at the given index
 /// </summary>
 /// <returns>The data for the row of the data set</returns>
 /// <param name="path">The index to grab</param>
 public virtual QueryRow RowAtIndexPath(NSIndexPath path)
 {
     if (path.Section == 0)
     {
         return(Rows.ElementAt(path.Row));
     }
     return(null);
 }
Beispiel #6
0
 public void Delete(string Name)
 {
     if (!int.TryParse(Name, out int id) || Rows.Count <= id)
     {
         throw new System.ArgumentException();
     }
     Rows.Remove(Rows.ElementAt(id));
 }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.KeyCode == Keys.Delete)
            {
                var row = Rows.ElementAt(_selectedRow);
                row.Items.Remove(_selectedItem);
            }
        }
Beispiel #8
0
        public void Edit(string data, string newdata)
        {
            if (!int.TryParse(data, out int id) || Rows.Count <= id)
            {
                throw new System.ArgumentException();
            }
            var rowEdit = Rows.ElementAt(id);
            var RowData = CreateSpecific.Row(Columns);

            rowEdit.Data = RowData;
            //ДОПИСАТИ
        }
Beispiel #9
0
        public void UpdateMainHeaderRow(string[] tags)
        {
            MainHeaderRowCount = 0;

            if (Rows.Count != 0)
            {
                var searchRowsCount = Rows.Count < 50 ? Rows.Count : 50;

                var allTags = Tag.FromStrings(tags);
                var exTags  = allTags.Where(t => t.Direction == TagDirection.Exclude).ToArray();
                var inTags  = allTags.Where(t => t.Direction == TagDirection.Include).ToArray();

                Dictionary <int, double> weightDict = new Dictionary <int, double>();
                for (var i = searchRowsCount - 1; i >= 0; i--)
                {
                    if (!Rows[i].IsEmpty)
                    {
                        double weight      = 0.0;
                        var    uniqueCells = Rows[i].UniqueNotEmptyCells.Select(c => c.Value.Trim().ToLower()).ToArray();
                        weight = exTags.Any(t => uniqueCells.Any(c => c.Like(t.Value)))
                                ? 0
                                : uniqueCells.Count(c => inTags.Any(t => c.Like(t.Value))) + uniqueCells.Count(c => inTags.Where(t => t.IsStrong).Any(t => c.Like(t.Value))) * 5;
                        weightDict.Add(i, weight);
                    }
                }

                double maxWeight = weightDict.Select(kvp => kvp.Value).OrderByDescending(i => i).FirstOrDefault();
                if (maxWeight > 0)
                {
                    var headerRows      = weightDict.Where(kvp => kvp.Value == maxWeight).Select(kvp => kvp.Key).OrderBy(kvp => kvp);
                    int mainHeaderIndex = headerRows.FirstOrDefault();

                    int mainHeaderCnt = 1;
                    for (mainHeaderCnt = 1; mainHeaderCnt < headerRows.Count(); mainHeaderCnt++)
                    {
                        if (!headerRows.Contains(mainHeaderIndex + mainHeaderCnt))
                        {
                            break;
                        }
                    }

                    MainHeaderRowCount = mainHeaderCnt > 4 ? 1 : mainHeaderCnt;
                    MainHeader         = Rows.ElementAt(mainHeaderIndex);
                    return;
                }
            }
            MainHeader         = Rows.FirstOrDefault();
            MainHeaderRowCount = 1;
        }
        private void ReadCsvPart(object o)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "CSV|*.csv";
            if (ofd.ShowDialog() == true)
            {
                FirstLines = String.Empty;
                allLines   = File.ReadAllLines(ofd.FileName).ToList();
                for (int i = 0; i < allLines.Count; i++)
                {
                    FirstLines += allLines[i] + "\r\n";
                    if (i >= 3)
                    {
                        break;
                    }
                }

                Columns.Clear();
                Rows.Clear();
                allLines[0].Split(DefaultSeperator).ToList().ForEach(s => Columns.Add(s)); Rows.Add(new ObservableCollection <string>());

                foreach (var line in allLines.Skip(1))
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    try
                    {
                        int i      = 0;
                        var splits = line.Split(DefaultSeperator).ToList();
                        foreach (var s in splits)
                        {
                            Rows.ElementAt(i).Add(s);
                            i++;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Log.Error($"Could not parse {line}. {ex}");
                        continue;
                    }
                }
            }
        }
        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);
        }
        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);
        }
Beispiel #13
0
        public void ResetRowHeight()
        {
            //Resets all row heights back to default
            //ensure that rows are completed before refreshing allowing a smooth transistion.
            EnableDisableHandlers(false);
            grid.AllowGridResize = false;
            rowHeight            = (int)(DefaultRowHeight * ScalingTools.GetScaleFactor());
            foreach (Row row in Rows)
            {
                if (row.Height != rowHeight)
                {
                    row.Height = rowHeight;
                }
            }

            EnableDisableHandlers();
            grid.AllowGridResize = true;
            LayoutRows();
            Rows.ElementAt(0).Height = Rows.ElementAt(0).Height;
        }
Beispiel #14
0
        protected override void RenderNonEmptyTable(JsonWriter writer)
        {
            var extendedMetadata = ExtendMetadata(Rows.ElementAt(0).Table, Metadatas);

            RenderNonEmptyTable(Rows, extendedMetadata, Sampler, writer);
        }
 public void AddToSelectionFrom(int row, int column)
 {
     _selectedCells.Add(Rows.ElementAt(row).Cells.ElementAt(column));
 }
 public DistanceElement GetResult(int index)
 {
     return(Rows.ElementAt(0).Elements.ElementAt(index));
 }
Beispiel #17
0
 /// <summary>
 /// Gets the query result at the given index
 /// </summary>
 /// <returns>The data for the row of the data set</returns>
 /// <param name="index">The index to grab</param>
 public virtual QueryRow RowAtIndex(int index)
 {
     return(Rows.ElementAt(index));
 }
Beispiel #18
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));
                }
            }
        }
Beispiel #19
0
 public Row this[int index] => Rows.ElementAt(index);
Beispiel #20
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));
            }
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            //Cursor = Cursors.Hand;
            var mouseMovePosition       = new Point(e.X, e.Y);
            var mouseMoveScrollPosition = mouseMovePosition - new Size(AutoScrollPosition);

            var row     = RowCoord.Where(d => (isNumberInRange(mouseMoveScrollPosition.Y, d.FirstCoord, d.SecondCoord))).SingleOrDefault();
            var moveRow = row != null ? row.RowIndex : -1;

            var column =
                ColumnCoord.Where(d => (isNumberInRange(mouseMoveScrollPosition.X, d.FirstCoord, d.SecondCoord))).SingleOrDefault();

            WeekPlannerItem hittedItem = null;

            if (listRows.Count > 0 && moveRow != -1 && listRows.Count > moveRow)
            {
                var plannerRow = listRows.ElementAt(moveRow);

                if (plannerRow.LeftMarginBackColor != Color.White)
                {
                    plannerRow.LeftMarginOldBackColor = plannerRow.LeftMarginBackColor;
                }

                hittedItem = GetItemAt(mouseMoveScrollPosition, plannerRow.Items);
                if (outHittedItem != hittedItem && hittedItem != null)
                {
                    outHittedItem = hittedItem;
                }


                //to detect cursor movement above left margin column
                if (mouseMoveScrollPosition.X < LeftMargin)
                {
                    //to detect cursor movement during changing rows
                    if (outRow != moveRow)
                    {
                        plannerRow.LeftMarginBackColor = Color.White;
                        //sets row color when cursor moves above the row
                        if (plannerRow.IsCollapsible)
                        {
                            //plannerRow.LeftMarginBackColor = Color.White;
                            Cursor = Cursors.Hand;
                        }
                        else
                        {
                            Cursor = Cursors.Default;
                        }

                        //finds row which has left cursor and sets back color
                        if (outRow != -1)
                        {
                            var oRow = listRows.ElementAt(outRow);
                            oRow.LeftMarginBackColor = oRow.LeftMarginOldBackColor;
                            if (oRow.IsCollapsible)
                            {
                                //oRow.LeftMarginBackColor = oRow.LeftMarginOldBackColor;
                            }
                        }

                        outRow = moveRow;
                    }
                }

                //to detect when cursor leaves left margin column
                else
                {
                    if (plannerRow.IsCollapsible)
                    {
                        //plannerRow.LeftMarginBackColor = plannerRow.LeftMarginOldBackColor;
                    }
                    plannerRow.LeftMarginBackColor = plannerRow.LeftMarginOldBackColor;
                    outRow = -1;
                }
            }


            // to detect cursor movement below left margin column
            if (moveRow == -1 && outRow != -1)
            {
                var r = listRows.ElementAt(outRow);
                if (r.IsCollapsible)
                {
                    outRow = -1;
                    //r.LeftMarginBackColor = r.LeftMarginOldBackColor;
                    Cursor = Cursors.Default;
                }
                r.LeftMarginBackColor = r.LeftMarginOldBackColor;
            }


            switch (State)
            {
            case PlannerState.Idle:
                Cursor should = Cursors.Default;

                if (hittedItem != null)
                {
                    if ((hittedItem.ResizeEndDateZone(mouseMoveScrollPosition) || hittedItem.ResizeStartDateZone(mouseMoveScrollPosition)))
                    {
                        should = Cursors.SizeWE;
                    }

                    planner.OnItemMouseHover(new WeekPlannerItemEventArgs(hittedItem));
                }
                if (!Cursor.Equals(should) && mouseMoveScrollPosition.X > LeftMargin)
                {
                    Cursor = should;
                }

                if (hittedItem == null && outHittedItem != null)
                {
                    planner.OnItemMouseLeave(new WeekPlannerItemEventArgs(outHittedItem));
                    outHittedItem = null;
                }

                break;

            case PlannerState.DraggingItem:

                if (column != null)
                {
                    moveDate = column.DateValue;
                }

                itemOnState.StartDate = moveDate.AddDays(durationStart.Days);
                itemOnState.EndDate   = moveDate.AddDays(durationEnd.Days);

                if (rowNumer != moveRow && moveRow != -1 && IsAllowedDraggingBetweenRows)
                {
                    try
                    {
                        var oldRowNumber = rowNumer;
                        rowNumer = moveRow;

                        var newRow = Rows.ElementAt(rowNumer);
                        var oldRow = Rows.ElementAt(oldRowNumber);

                        var newItem = new WeekPlannerItem(this);
                        newItem = itemOnState;


                        var addedItem = newRow.Items.Add(newItem);
                        oldRow.Items.Remove(itemOnState);
                        _selectedItem = addedItem;
                        itemOnState   = addedItem;
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("it did it again");
                    }
                }
                itemOnStateChanged = true;
                break;

            case PlannerState.ResizingItem:
                if (column != null)
                {
                    moveDate = column.DateValue;
                }

                if (itemOnState.IsResizingStartDate && moveDate <= itemOnState.EndDate.Date)
                {
                    itemOnState.StartDate = moveDate.AddDays(durationStart.Days);
                }
                else if (itemOnState.IsResizingEndDate && moveDate >= itemOnState.StartDate.Date)
                {
                    itemOnState.EndDate = moveDate.AddDays(durationEnd.Days);
                }
                itemOnStateChanged = true;
                break;

            case PlannerState.EditingItemText:
                break;
            }
        }