public void Exporters_XlsExporter_insertRowLinks_RelativeLink()
        {
            FileInfo outfile = new FileInfo(@"X:\noWhere.xlsx");

            string[] exportFields        = new string[] { "DOCID", "BEGATT", "VOLUME", "NATIVE" };
            Representative.FileType type = Representative.FileType.Native;
            string display = null;
            int    index   = 3;

            docs.First().Metadata["NATIVE"] = @"\NATIVE\0001\DOC000001.XLSX";
            docs.First().Representatives.First().Files["DOC000001"] = @"\NATIVE\0001\DOC000001.XLSX";
            HyperLinkInfo link = new HyperLinkInfo(type, display, index);

            HyperLinkInfo[] links  = new HyperLinkInfo[] { link };
            TestExporter    tester = new TestExporter(outfile, exportFields, links);
            DataTable       dt      = tester.getMetaDataTable(this.docs);
            FileInfo        file    = new FileInfo("test.xlsx");
            ExcelPackage    package = new ExcelPackage(file);
            ExcelWorksheet  ws      = package.Workbook.Worksheets.Add("Sheet1");

            ws.Cells[1, 1].LoadFromDataTable(dt, true);
            Document doc       = docs.First();
            int      row       = 0;
            int      col       = 3;
            string   linkValue = @".\NATIVE\0001\DOC000001.XLSX";

            tester.insertRowLinks(ws, dt, doc, row);
            string expected = String.Format(
                "HYPERLINK(\"{0}\", \"{1}\")", linkValue, "\\NATIVE\\0001\\DOC000001.XLSX");
            string actual = ws.Cells[row + 2, col + 1].Formula;

            Assert.AreEqual(expected, actual);
        }
        public void Exporters_XlsExporter_insertRowLinks_NoLink()
        {
            FileInfo outfile = new FileInfo(@"X:\noWhere.xlsx");

            string[] exportFields        = new string[] { "DOCID", "BEGATT", "VOLUME", "NATIVE" };
            Representative.FileType type = Representative.FileType.Native;
            string        display        = null;
            int           index          = 3;
            HyperLinkInfo link           = new HyperLinkInfo(type, display, index);

            HyperLinkInfo[] links   = new HyperLinkInfo[] { link };
            TestExporter    tester  = new TestExporter(outfile, exportFields, links);
            DataTable       dt      = tester.getMetaDataTable(this.docs);
            FileInfo        file    = new FileInfo("test.xlsx");
            ExcelPackage    package = new ExcelPackage(file);
            ExcelWorksheet  ws      = package.Workbook.Worksheets.Add("Sheet1");

            ws.Cells[1, 1].LoadFromDataTable(dt, true);
            Document doc = docs[1];
            int      row = 0;
            int      col = 3;

            tester.insertRowLinks(ws, dt, doc, row);
            string expected = String.Empty;
            string actual   = ws.Cells[row + 2, col + 1].Formula;

            Assert.AreEqual(expected, actual);
        }
        public void Exporters_XlsExporter_getMetaDataTable()
        {
            FileInfo outfile = new FileInfo(@"X:\noWhere.xlsx");

            string[]        exportFields = new string[] { "DOCID", "BEGATT", "VOLUME", "NATIVE" };
            HyperLinkInfo[] links        = new HyperLinkInfo[] { };
            TestExporter    tester       = new TestExporter(outfile, exportFields, links);
            DataTable       dt           = tester.getMetaDataTable(this.docs);

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                string expected = exportFields[i];
                string actual   = dt.Columns[i].ColumnName;
                Assert.AreEqual(expected, actual);
            }

            for (int row = 0; row < dt.Rows.Count; row++)
            {
                for (int col = 0; col < dt.Columns.Count; col++)
                {
                    string expected = docs[row].Metadata[dt.Columns[col].ColumnName];
                    string actual   = dt.Rows[row][col].ToString();
                    Assert.AreEqual(expected, actual);
                }
            }
        }
Beispiel #4
0
        void GetGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower() != "add")
            {
                return;
            }

            var row = (e.CommandSource as Control).Parent.Parent as GridViewRow;
            var htd = new Hashtable();

            foreach (TemplateField tf in GridViewManager1.GridView.Columns)
            {
                var item = tf.FooterTemplate as GenericItem;
                if (item == null)
                {
                    continue;
                }
                try
                {
                    foreach (DictionaryEntry de in item.ExtractValues(row))
                    {
                        htd.Add(de.Key, de.Value);
                    }
                }
                catch (Exception ex)
                {
                    Exceptions.Logger.Error(ex);
                    HtmlHelper.Alert(ex.Message, Page);
                    return;
                }
            }

            try
            {
                var ctrl = new HyperLinkController();
                var info = new HyperLinkInfo();
                foreach (System.Reflection.PropertyInfo property in CBO.GetPropertyInfo(typeof(HyperLinkInfo)))
                {
                    if (htd[property.Name] != null)
                    {
                        property.SetValue(info, htd[property.Name], null);
                    }
                }
                ctrl.InsertHyperLink(info);
                GridViewManager1.GridView.PageIndex = GridViewManager1.GridView.PageCount;
                GridViewManager1.LoadData();
            }
            catch (Exception ex)
            {
                Exceptions.Logger.Error(ex);
                HtmlHelper.Alert(ex.Message, Page);
            }
        }
        public void Exporters_XlsExporter_insertLinkColumns_ExLinkIndex()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("one");
            dt.Columns.Add("two");
            List <HyperLinkInfo> links = new List <HyperLinkInfo>();

            Representative.FileType type = Representative.FileType.Native;
            string        display        = "display text";
            int           index          = 5;
            HyperLinkInfo link           = new HyperLinkInfo(type, display, index);

            links.Add(link);

            TestExporter tester = new TestExporter();

            tester.insertLinkColumns(dt, links.ToArray());
        }
        public void Exporters_XlsExporter_insertLinkColumns_NullName()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("one");
            dt.Columns.Add("two");
            List <HyperLinkInfo> links = new List <HyperLinkInfo>();

            Representative.FileType type = Representative.FileType.Native;
            string        display        = null;
            int           index          = 1;
            HyperLinkInfo link           = new HyperLinkInfo(type, display, index);

            links.Add(link);

            TestExporter tester = new TestExporter();

            tester.insertLinkColumns(dt, links.ToArray());
            Assert.AreEqual(dt.Columns[index].ColumnName, "two");
        }
 /// <summary>
 /// Initializes a new instance of <see cref="Hyperlink"/>.
 /// </summary>
 /// <param name="link">The settings used to build this object.</param>
 public Hyperlink(HyperLinkInfo link)
 {
     this.FileType    = link.GetFileType();
     this.DisplayText = link.GetDisplayText();
     this.ColumnIndex = link.GetColumnIndex();
 }