Exemple #1
0
        /**
         *将本月份的txt日志文件转换为xls文件,默认为当前月份
         */
        public static void LogToExcel(string datetime)
        {
            #region 创建自定义的DataTable
            //创建DataTable
            string[]        columNames = { "日期", "时间", "情况说明" };
            CreateDataTable cdt        = new CreateDataTable();
            cdt.SetDataTable(columNames);
            DataTable dt = cdt.GetDataTable();
            #endregion

            #region 获取txt日志文件
            if (datetime == null)
            {
                datetime = DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月";
            }
            string[] files = GetFiles(datetime);//获取所需月份的文件

            #endregion


            #region 写入日志到DataTable

            DataRow dr;
            for (int i = 0; i < files.Length; i++) //遍历文件
            {
                if (files[i] == null)
                {
                    break;
                }

                FileIO readFile = new FileIO();
                readFile.OpenReadFile(files[i]);

                while (!readFile.IsEof())
                {                                         //文件结束,跳出循环
                    string strings = readFile.ReadLine(); //按行读取文件

                    if (!strings.Equals(""))
                    {
                        string[] split = strings.Split(' ');
                        //将每一行写入到对应的列下
                        dr         = dt.NewRow();
                        dr["日期"]   = split[0];
                        dr["时间"]   = split[1];
                        dr["情况说明"] = split[2];

                        dt.Rows.Add(dr);
                    }
                }
            }

            #endregion
            //写入excel文件中
            Excel.Excel.CreateExcel(dt, "logfiles/" + datetime + ".xls");
        }
Exemple #2
0
 public void mapFile(string fileToMap)
 {
     if (File.Exists(fileToMap))
     {
         loadedFile = fileToMap;
         var strutsConfigXml = J2eeConfigFiles.getStrutsConfig(fileToMap);
         tableList_FormBeans.setDataTable(CreateDataTable_Local.fromGenericList(strutsConfigXml.formBeans));
         tableList_GlobalForwards.setDataTable(CreateDataTable.fromDictionary_StringString(strutsConfigXml.globalForwards, "name", "path"));
         tableList_ActionMappings.setDataTable(CreateDataTable_Local.fromGenericList(strutsConfigXml.actionmappings));
         tableList_PlugIns.setDataTable(CreateDataTable_Local.fromGenericList(strutsConfigXml.plugIns));
         //lbDescription.Text = webXml.description;
         //lbDisplayName.Text = webXml.displayName;
         //tableList_Filter.setDataTable(CreateDataTable.fromGenericList(webXml.filters));
         //tableList_FilterMappings.setDataTable(CreateDataTable.fromGenericList(webXml.filterMappings));
         //tableList_Servlets.setDataTable(CreateDataTable.fromGenericList(webXml.servlets));
         //tableList_ServletMappings.setDataTable(CreateDataTable.fromGenericList(webXml.servletMappings));
     }
 }
        private void updateDependenciesFlatList(Dictionary <string, string> dependencies)
        {
            tbDependenciesFlatList.invokeOnThread(
                () =>
            {
                var dependenciesText = new StringBuilder();
                tableListWithDependencies.setDataTable(CreateDataTable.fromDictionary_StringString(dependencies, "name", "location"));

                foreach (var dependency in dependencies)
                {
                    var splittedname = dependency.Key.Split(',');
                    if (splittedname.Count() > 0)
                    {
                        dependenciesText.AppendFormat("{0}          ( {1} )     : {2}\n", splittedname[0], dependency, dependency.Value);
                    }
                }
                tbDependenciesFlatList.Text = dependenciesText.ToString();
            });
        }
        public static DataTable dataTable <T>(this IEnumerable <T> collection, params string[] columnsToShow)
        {
            if (columnsToShow.empty())
            {
                return(CreateDataTable.from_List(collection.toList()));
            }
            var dataTable = new DataTable();

            if (typeof(T) == typeof(String))                    // we need to handle string seperately since it is also an IEnumerable
            {
                dataTable.add_Column("String");
                collection.toList <string>().forEach(value => dataTable.newRow(value));
            }
            else
            {
                var columnsToShowList = columnsToShow.ToList();
                typeof(T).properties().forEach(
                    (propertyInfo) =>
                {
                    if (columnsToShow == null || columnsToShow.size() == 0 || columnsToShowList.Contains(propertyInfo.Name))
                    {
                        dataTable.add_Column(propertyInfo.Name);
                    }
                });

                foreach (var item in collection)
                {
                    var row        = dataTable.newRow();
                    var pinnedItem = item;
                    dataTable.Columns.toList <DataColumn>().forEach(
                        (dataColumn) => {
                        row[dataColumn.ColumnName] = pinnedItem.property(dataColumn.ColumnName);
                    });
                }
            }
            return(dataTable);
        }