protected Dictionary <string, object> GetArgumentPairs(ReportArgument arg)
        {
            if (arg != null && arg.ReportArgumentQueryId.HasValue)
            {
                var pairs = new Dictionary <string, object>();

                using (var cmd = db.Database.GetDbConnection().CreateCommand()) {
                    cmd.CommandText = arg.ReportArgumentQuery.ArgQuery;
                    db.Database.GetDbConnection().Open();

                    using (var reader = cmd.ExecuteReader()) {
                        while (reader.Read())
                        {
                            var key   = reader.GetString(0);
                            var value = reader.GetValue(1);
                            pairs.Add(key, value);
                        }
                    }
                    db.Database.GetDbConnection().Close();
                }

                return(pairs);
            }
            return(null);
        }
Exemple #2
0
        private void Seed()
        {
            using (var context = new DatabaseContext(databaseContextOptions, httpAccessorMock.Object)) {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                argumentQuery = new ReportArgumentQuery()
                {
                    ArgQuery = "query", ReportArgumentQueryId = 1
                };
                reportArgument = new ReportArgument {
                    Name = "date", ReportArgumentId = 1, ArgType = "DateTime", ReportId = 1
                };
                group = new ReportGroup()
                {
                    Name = "groupName", ReportGroupId = 1
                };
                report = new Report()
                {
                    Description     = "someDescription",
                    Name            = "someName",
                    ReportId        = reportArgument.ReportId,
                    ReportArguments = new List <ReportArgument>()
                    {
                        reportArgument
                    },
                    ReportGroupId = group.ReportGroupId
                };

                context.AddRange(argumentQuery, reportArgument, group, report);
                context.SaveChanges();
            }
        }
        public ParameterNode(Variables variables, ReportArgument parameter)
        {
            m_variables = variables;

            if (parameter != null)
            {
                Name      = parameter.Name;
                ValueType = parameter.ValueType;

                if (ValueType == ReportArgumentValueType.Variable)
                {
                    Variable = parameter.Value;
                }
                else
                {
                    Value = parameter.Value;
                }
            }
            ;
        }
Exemple #4
0
        public void GetReportArgumentShouldReturnObject()
        {
            //arrange
            var reportArgument = new ReportArgument()
            {
                ReportArgumentId = 1,
                ArgName          = "argName",
                ArgType          = "string"
            };

            serviceMock.Setup(s => s.GetReportArgument(It.IsAny <int>())).Returns(reportArgument);

            //act
            var result = reportArgumentController.Get(1);

            //assert
            var viewResult = result.Should().BeAssignableTo <ObjectResult>();

            viewResult.Which.Value.Should().BeEquivalentTo(reportArgument);
            serviceMock.Verify(s => s.GetReportArgument(It.IsAny <int>()), Times.Once);
        }
Exemple #5
0
        /// <summary>
        /// ページを描画する
        /// </summary>
        /// <param name="dch">ドローイングコンテキスト</param>
        /// <param name="arg">レポート引数</param>
        protected override void DrawingPage(DrawingContextHelper dch, ReportArgument arg)
        {
            var titleFont = new FontInfo("Meiryo", true, 32, Brushes.Black);

            // ヘッダの描画
            dch.DrawText("蔵書リスト", titleFont, CM2PX(1.0d), CM2PX(1.5d));
            dch.DrawText(string.Format("Page.{0}", arg.PageNo), CM2PX(26.5d), CM2PX(1.4d));

            Table.HeaderColumns[0].DrawText("No", TextAlignment.Right, dch);
            Table.HeaderColumns[1].DrawText("書名", TextAlignment.Left, dch);
            Table.HeaderColumns[2].DrawText("著者名", TextAlignment.Left, dch);
            Table.HeaderColumns[3].DrawText("出版社", TextAlignment.Left, dch);
            Table.HeaderColumns[4].DrawText("カテゴリ", TextAlignment.Left, dch);
            Table.HeaderColumns[5].DrawText("価格", TextAlignment.Right, dch);
            Table.HeaderColumns[6].DrawText("購入日", TextAlignment.Center, dch);
            Table.HeaderColumns[7].DrawText("評価点", TextAlignment.Left, dch);

            // 明細の描画
            Table.RowIndex = 0;
            while (DataRowIndex < BookList.Count)
            {
                // 1ページ分明細行を印刷したらブレイク
                if (Table.PageBreak)
                {
                    break;
                }

                if (Table.RowIndex % 2 != 0)
                {
                    Table.DrawRowBorder(Table.RowIndex, null, new Thickness(0.0d), Brushes.WhiteSmoke, dch);
                }

                var book = BookList[DataRowIndex];
                Table[0].DrawText(book.Id.ToString(), TextAlignment.Right, dch);
                Table[1].DrawText(book.Title, TextAlignment.Left, dch);
                Table[2].DrawText(book.Author, TextAlignment.Left, dch);
                Table[3].DrawText(book.Publisher, TextAlignment.Left, dch);
                if (book.Category.HasValue)
                {
                    Table[4].DrawText(AttributeUtil.GetEnumFieldDisplayName(book.Category.Value), TextAlignment.Left, dch);
                }
                if (book.Price.HasValue)
                {
                    Table[5].DrawText(book.Price.Value.ToString("#,##0円"), TextAlignment.Right, dch);
                }
                if (book.PurchaseDate.HasValue)
                {
                    Table[6].DrawText(book.PurchaseDate.Value.ToString("yyyy/MM/dd"), TextAlignment.Center, dch);
                }
                if (book.ReviewPoint.HasValue)
                {
                    Table[7].DrawText(new String('★', book.ReviewPoint.Value), TextAlignment.Left, dch);
                }

                DataRowIndex++;
                Table.RowIndex++;
            }

            // 枠線の描画
            Table.DrawBorder(dch.DefaulBrush, new Thickness(1.0d), null, dch);
            Table.DrawHeaderBorder(dch.DefaulBrush, new Thickness(0.0d, 0.0d, 0.0d, 1.0d), null, dch);

            // 印刷すべきデータがまだあれば印刷を継続する
            arg.PrintTerminate = (DataRowIndex >= BookList.Count);
        }
Exemple #6
0
        private static void SelectDynamicReport(ReportArgument rArgument, SearchArgument sArgument, string orderBy, string companyName, string branchName, string foreignKeyName, int id, string UserName)
        {
            // IEnumerable<T> data;
            List <RollBackDistributionCompanyInfo> data;
            int count;

            if (!String.IsNullOrEmpty(foreignKeyName))
            {
                if (sArgument != null)
                {
                    data  = SelectDynamicSearchByFK(foreignKeyName, id, sArgument, orderBy).ToList <RollBackDistributionCompanyInfo>();
                    count = SelectSearchByFKCountCached(foreignKeyName, id, sArgument);
                }
                else
                {
                    data  = SelectDynamicByFK(foreignKeyName, id, orderBy).ToList <RollBackDistributionCompanyInfo>();
                    count = SelectByFKCountCached(foreignKeyName, id);
                }
            }
            else
            {
                if (sArgument != null)
                {
                    data  = SelectSearch(sArgument, orderBy).ToList <RollBackDistributionCompanyInfo>();
                    count = data.Count;
                    //count = SelectSearchCountCached(sArgument);
                }
                else
                {
                    data  = Select(orderBy).ToList <RollBackDistributionCompanyInfo>();
                    count = data.Count;
                    //count = SelectCountCached();
                }
            }
            int n = count;
            int m = rArgument.ReportArguments.Count;

            TypeCode[]     codes = new TypeCode[m];
            PropertyInfo[] infos = new PropertyInfo[m];
            bool           first = true;

            if (rArgument.Format == "PDF")
            {
                PDFCreators creator = new PDFCreators(rArgument.Orientation, rArgument.MarginLeft, rArgument.MarginRight, rArgument.MarginTop, rArgument.MarginBottom);

                creator.SetDocumentHeaderFooter(companyName);
                creator.OpenPDF();
                creator.SetTitle(rArgument.ReportName);
                string[] headers = new string[m];
                for (int i = 0; i < m; i++)
                {
                    headers[i] = rArgument.ReportArguments[i].HeaderText;
                }
                creator.CreateTable(m, true, headers, branchName);

                for (int i = 0; i < n; i++)
                {
                    object[] values = new object[m];
                    for (int j = 0; j < m; j++)
                    {
                        if (first)
                        {
                            infos[j] = typeof(RollBackDistributionCompanyInfo).GetProperty(rArgument.ReportArguments[j].PropertyField);
                            if (IsNullableType(infos[j].PropertyType))
                            {
                                NullableConverter nc = new NullableConverter(infos[j].PropertyType);
                                codes[j] = Type.GetTypeCode(nc.UnderlyingType);
                            }
                            else
                            {
                                codes[j] = Type.GetTypeCode(infos[j].PropertyType);
                            }
                        }
                        values[j] = infos[j].GetValue(data[i], null);
                        if (codes[j] == TypeCode.DateTime)
                        {
                            DateTime date = (DateTime)values[j];
                            values[j] = date.ToShortDateString();
                        }

                        if (codes[j] == TypeCode.Decimal)
                        {
                            decimal dec = (decimal)values[j];
                            values[j] = String.Format("{0:#,0.00}", dec);
                        }

                        if (codes[j] == TypeCode.Boolean)
                        {
                            bool temp = (bool)values[j];
                            if (temp == true)
                            {
                                values[j] = "Да";
                            }
                            else
                            {
                                values[j] = "Не";
                            }
                        }
                    }
                    first = false;
                    if (creator.AddDataRow(values, m, codes))
                    {
                        i--;
                    }
                }
                creator.AddTable();
                creator.FinishPDF();
            }

            //Creating Excel document
            else if (rArgument.Format == "XLS")
            {
                ExcelFileWriter <RollBackDistributionCompanyInfo> myExcel = new ExcelFileWriter <RollBackDistributionCompanyInfo>();
                string[] headers = new string[m];
                for (int i = 0; i < m; i++)
                {
                    headers[i] = rArgument.ReportArguments[i].HeaderText;
                }
                myExcel.Headers = headers;

                int    temp_num    = ('A') + m - 1;
                char   lastCol     = Convert.ToChar(temp_num);
                string finalColumn = lastCol + "1";

                myExcel.ColumnCount = m - 1;
                myExcel.RowCount    = n;

                myExcel.ActivateExcel();
                myExcel.FillHeaderColumn(headers, "A1", finalColumn);

                for (int i = 0; i < n; i++)
                {
                    object[] values = new object[m];

                    for (int j = 0; j < m; j++)
                    {
                        if (first)
                        {
                            infos[j] = typeof(RollBackDistributionCompanyInfo).GetProperty(rArgument.ReportArguments[j].PropertyField);
                            if (IsNullableType(infos[j].PropertyType))
                            {
                                NullableConverter nc = new NullableConverter(infos[j].PropertyType);
                                codes[j] = Type.GetTypeCode(nc.UnderlyingType);
                            }
                            else
                            {
                                codes[j] = Type.GetTypeCode(infos[j].PropertyType);
                            }
                        }
                        values[j] = infos[j].GetValue(data[i], null);

                        if (codes[j] == TypeCode.DateTime)
                        {
                            DateTime date = (DateTime)values[j];
                            values[j] = date.ToShortDateString();
                        }

                        if (codes[j] == TypeCode.Boolean)
                        {
                            bool temp = (bool)values[j];
                            if (temp == true)
                            {
                                values[j] = "Да";
                            }
                            else
                            {
                                values[j] = "Не";
                            }
                        }
                    }
                    first = false;
                    string fColumn = "A" + (i + 2).ToString();
                    string lColumn = lastCol + (i + 2).ToString();
                    myExcel.FillRowData_Mine(values, fColumn, lColumn);
                }
                string fileName = UserName + "_" + rArgument.ReportName + ".xls";
                myExcel.SaveExcel(fileName);
                myExcel.FinishExcel(fileName);
            }

            //Create Word document
            else if (rArgument.Format == "DOC")
            {
                WordFileWriter <RollBackDistributionCompanyInfo> myWord = new WordFileWriter <RollBackDistributionCompanyInfo>();
                myWord.Orientation = rArgument.Orientation;
                myWord.ActivateWord();

                //myWord.InsertingText(rArgument.ReportName);
                //myWord.InsertingText("Датум на извештај: " + DateTime.Now.ToShortDateString());

                string[] headers = new string[m];
                for (int i = 0; i < m; i++)
                {
                    headers[i] = rArgument.ReportArguments[i].HeaderText;
                }
                myWord.Headers           = headers;
                object[,] tempFillValues = new object[n, m];

                CultureInfo oldCI   = System.Threading.Thread.CurrentThread.CurrentCulture;
                CultureInfo oldUICI = System.Threading.Thread.CurrentThread.CurrentUICulture;

                System.Threading.Thread.CurrentThread.CurrentCulture   = new CultureInfo("mk-MK");
                System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("mk-MK");


                for (int i = 0; i < n; i++)
                {
                    object[] values = new object[m];
                    for (int j = 0; j < m; j++)
                    {
                        if (first)
                        {
                            infos[j] = typeof(RollBackDistributionCompanyInfo).GetProperty(rArgument.ReportArguments[j].PropertyField);
                            if (IsNullableType(infos[j].PropertyType))
                            {
                                NullableConverter nc = new NullableConverter(infos[j].PropertyType);
                                codes[j] = Type.GetTypeCode(nc.UnderlyingType);
                            }
                            else
                            {
                                codes[j] = Type.GetTypeCode(infos[j].PropertyType);
                            }
                        }
                        values[j] = infos[j].GetValue(data[i], null);

                        if (codes[j] == TypeCode.DateTime)
                        {
                            DateTime date = (DateTime)values[j];
                            values[j] = date.ToShortDateString();
                        }

                        if (codes[j] == TypeCode.Boolean)
                        {
                            bool temp = (bool)values[j];
                            if (temp == true)
                            {
                                values[j] = "Да";
                            }
                            else
                            {
                                values[j] = "Не";
                            }
                        }
                        tempFillValues[i, j] = values[j];
                    }
                    first = false;
                }

                System.Threading.Thread.CurrentThread.CurrentCulture   = oldCI;
                System.Threading.Thread.CurrentThread.CurrentUICulture = oldUICI;

                myWord.FillValues = tempFillValues;
                myWord.CreateTable(n, m);

                myWord.InsertFooter();
                myWord.InsertHeader(rArgument.BranchName);

                string fileName = UserName + "_" + rArgument.ReportName + ".doc";
                myWord.SaveDOC(fileName);
                myWord.FinishDOC(fileName);
            }
        }
Exemple #7
0
 public static IQueryable <RollBackDistributionCompanyInfo> SelectReport(ReportArgument rArgument, SearchArgument sArgument, string orderBy, string companyName, string branchName, string foreignKeyName, int id, string UserName)
 {
     SelectDynamicReport(rArgument, sArgument, orderBy, companyName, branchName, foreignKeyName, id, UserName);
     return(null);
 }