private Border GetReportFieldButton(ReportField field)
        {
            Button button = new Button
            {
                Content           = field.Name,
                Style             = Resources["Flat_Button"] as Style,
                UseLayoutRounding = true
            };

            button.MouseEnter += Button_MouseEnter;
            button.MouseLeave += Button_MouseLeave;

            Border border = new Border
            {
                BorderBrush       = System.Windows.Media.Brushes.DimGray,
                BorderThickness   = new Thickness(2),
                CornerRadius      = new CornerRadius(5),
                Margin            = new Thickness(5),
                Tag               = field,
                UseLayoutRounding = true,
                Child             = button
            };

            border.Drop             += Border_Drop;
            border.PreviewMouseMove += Border_MouseMove;
            return(border);
        }
        private void ReportButton_Clicked(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            LoadReports();
            try
            {
                AllFieldsPanel.Children.Clear();
                SelectedFieldsPanel.Children.Clear();
                Button selectedbutton = (Button)sender;
                ActiveReport   = selectedbutton.Tag as Report;
                Header.Content = $"AppDev Report Generator: {ActiveReport.Name}";

                #region add to panels - fixed for worksheet columns in wrong order
                ActiveReport.GetReportHeaders();

                //ServicePro exports in a random order, so must get column id by name
                int sourceindex = 1;
                foreach (string header in ActiveReport.DefinitionHeaders)
                {
                    ReportField field = ActiveReport.Fields.Where(x => x.ExportName.ToLower() == header.ToLower()).First();
                    field.SourceIndex = sourceindex;
                    sourceindex++;
                }
                foreach (ReportField field in ActiveReport.Fields)
                {
                    Border fieldbutton = GetReportFieldButton(field);
                    if (field.ExportIndex > 0)
                    {
                        SelectedFieldsPanel.Children.Add(fieldbutton);
                    }                                                                              // Automatically add fields with an export index (in the JSON file) greater than 0 to the right panel
                    else
                    {
                        AllFieldsPanel.Children.Add(fieldbutton);
                    }                                                   // Fields that are defined but have an export value less than or equal to zero go in the middle panel
                }
                #endregion

                ToggleExportButton(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unable to load report definition: {ex.StackTrace}");
                MessageBox.Show($"Unable to load report definition: {ex.Message}.", "Error Loading Report");
            }
            finally
            {
                Mouse.OverrideCursor = Cursors.Arrow;
            }
        }
Esempio n. 3
0
        public Row GetDividerRow(Excel.Range range)
        {
            if (string.IsNullOrEmpty(Divider))
            {
                return(null);
            }                                                    // report has no divider

            Row dividerrow = new Row {
                IsDivider = true, AddedToReport = true, Cells = new List <Cell>()
            };
            bool   match        = false;
            string comparevalue = string.Empty;
            int    i            = FirstRowIndex;

            foreach (Row row in Rows)
            {
                ReportField dividerfield = GetDividerField();
                if (match == false)
                {
                    string currentvalue = GetExcelText(range.Cells[i, dividerfield.SourceIndex].Value2, dividerfield);
                    if (!string.IsNullOrEmpty(comparevalue) && comparevalue != currentvalue)
                    {
                        foreach (ReportField field in Fields.Where(x => x.ExportIndex > 0))
                        {
                            dividerrow.Cells.Add(new Cell {
                                ColumnNumber = field.ExportIndex, Value = string.Empty, ColumnWidth = field.ColumnWidth
                            });
                        }
                        match            = true;
                        dividerrow.Index = i - FirstRowIndex;
                        return(dividerrow);
                    }
                    else
                    {
                        comparevalue = currentvalue;
                    }
                }
                i++;
            }
            return(null);
        }
Esempio n. 4
0
        public string GetExcelText(object value, ReportField field)
        {
            string result = field.NullValue;

            if (value != null)
            {
                switch (field.DataType)
                {
                case "string":
                    result = value.ToString().Replace("|", "\r\n");      // Unfortunately, newlines do not export from ServicePro properly, users must use this token to indicate where a newline should be inserted
                    break;

                case "date":
                    result = Convert.ToDateTime(value.ToString()).ToString("MM/dd/yyyy");
                    break;

                default:      // int and bool
                    result = value.ToString();
                    break;
                }
            }
            return(result);
        }