Exemplo n.º 1
0
        static DataMemory()
        {
            checkerInfoCached  = new Dictionary <string, string>();
            exporterInfoCached = new Dictionary <string, string>();

            exporterCached      = new Dictionary <ExportType, IExporter>();
            exporterOption      = new Dictionary <ExportType, List <Options> >();
            exporterOptionsForm = new OptionsForm();

            sheetCached = new Dictionary <string, DataTable>();

            IniMemory();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 检查用户输入信息
        /// </summary>
        public static string ParseCheckerUserInput()
        {
            string      error      = null;
            OptionsForm optionForm = DataMemory.GetOptionsFrom();

            if (optionForm == null)
            {
                error = "工具底层异常,请程序检查!";
            }
            else if (string.IsNullOrEmpty(optionForm.XlsxSrcPath))
            {
                error = "Xlsx表格路径不能为空!";
            }
            return(error);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 处理导出选项参数前事件
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public static void BeforeExporterOptionForm()
        {
            DataMemory.SetExportTotalCount(0);

            OptionsForm       optionForm = DataMemory.GetOptionsFrom();
            List <ExportType> typeList   = DataMemory.GetOptionsFromTypes();

            if (typeList.Count <= 0)
            {
                return;
            }
            if (optionForm.XlsxSrcPath.Length <= 0)
            {
                return;
            }
            if (optionForm.XlsxDstPath.Length <= 0)
            {
                return;
            }
            if (!Directory.Exists(optionForm.XlsxSrcPath))
            {
                return;
            }

            string[] files = Directory.GetFiles(optionForm.XlsxSrcPath, "*.xlsx", SearchOption.AllDirectories);
            if (files.Length <= 0)
            {
                return;
            }
            int count = 0;

            foreach (string srcFile in files)
            {
                string fileName = string.Empty;
                string xlsxName = Path.GetFileNameWithoutExtension(srcFile);
                fileName = xlsxName;
                foreach (ExportType type in typeList)
                {
                    string  outFileName = string.Format("{0}.{1}", fileName, type);
                    string  dstFile     = Path.Combine(optionForm.XlsxDstPath, outFileName);
                    Options option      = Options.ConvertToOption(srcFile, dstFile, type);
                    DataMemory.SetExportOption(type, option);
                    count++;
                }
            }

            DataMemory.SetExportTotalCount(count);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 检查用户输入信息
        /// </summary>
        public static string ParseExportUserInput()
        {
            string error = ParseCheckerUserInput();

            if (!string.IsNullOrEmpty(error))
            {
                return(error);
            }
            OptionsForm optionForm = DataMemory.GetOptionsFrom();

            if (string.IsNullOrEmpty(optionForm.XlsxDstPath))
            {
                error = "文本导出路径不能为空!";
            }
            else if (optionForm.ExporterList.Count <= 0)
            {
                error = "请至少选择一种导出类型!";
            }
            return(error);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 命令行模式
        /// </summary>
        /// <param name="args"></param>
        private static void ConsoleMode(string[] args)
        {
            DateTime   startTime = DateTime.Now;
            OptionCmmd options   = new OptionCmmd();

            CommandLine.Parser parser = new CommandLine.Parser((with) => {
                with.HelpWriter = Console.Error;
            });

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-1)))
            {
                try {
                    OptionsForm optionForm = new OptionsForm();
                    optionForm.XlsxSrcPath = options.InputPath;
                    optionForm.XlsxDstPath = options.OutputPath;

                    optionForm.SetExportType(ExportType.cs);
                    optionForm.SetExportType(ExportType.txt);
                    DataMemory.SetOptionForm(optionForm);

                    ExprotCallbackArgv argv = new ExprotCallbackArgv();
                    argv.OnProgressChanged = (int progress) => {
                        //Console.WriteLine(string.Format("Export progress {0}", progress));
                    };
                    argv.OnRunChanged      = (string message) => {
                        Console.WriteLine(string.Format("Export message {0}", message));
                    };

                    Facade.BeforeExporterOptionForm();
                    Facade.RunXlsxForm(argv);
                    Facade.AfterExporterOptionForm();
                } catch (Exception ex) {
                    Console.WriteLine("Error: " + ex.Message);
                }
            }
            TimeSpan expend = DateTime.Now - startTime;

            Console.WriteLine(string.Format("Expend time [{0} millisecond].", expend.Milliseconds));
        }
Exemplo n.º 6
0
 /// <summary>
 /// 设置选项参数
 /// </summary>
 /// <param name="option"></param>
 public static void SetOptionForm(OptionsForm option)
 {
     exporterOptionsForm = option;
 }