Exemplo n.º 1
0
        private void InitializeComponentValue()
        {
            OptionsForm option = DataMemory.ReviewOptionForm();

            if (option == null)
            {
                return;
            }
            SetInputPath(option.XlsxSrcPath);
            SetOutputPath(option.XlsxDstPath);

            foreach (ExportType type in option.ExporterList)
            {
                foreach (object obj in this.groupBox2.Controls)
                {
                    if (!(obj is CheckBox))
                    {
                        continue;
                    }
                    CheckBox   b = obj as CheckBox;
                    ExportType t = b.Text.ToEnum <ExportType>();
                    if (type == t)
                    {
                        b.Checked = true;
                    }
                }
            }
            DataMemory.SetOptionForm(option);
        }
Exemplo n.º 2
0
 private void BeforeExporterForm()
 {
     progressBar1.Minimum = 0;
     progressBar1.Maximum = DataMemory.GetExportTotalCount();
     textBox4.Text        = "";
     textBox4.Refresh();
     button1.Enabled = false;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 检查运行器
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public static void RunCheckerXlsx(CheckeCallbackArgv argv)
        {
            if (argv == null)
            {
                throw new Exception("Run xlsx form argv is null.");
            }

            if (argv.OnRunChanged != null)
            {
                argv.OnRunChanged("=================检查开始=================");
            }

            OptionsForm optionForm = DataMemory.GetOptionsFrom();

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

            string[] files = Directory.GetFiles(optionForm.XlsxSrcPath, "*.xlsx", SearchOption.AllDirectories);
            if (files.Length <= 0)
            {
                return;
            }
            // 注意xlsx文件命名规则: 标号_英文名_中文名
            foreach (string file in files)
            {
                string   fileName        = string.Empty;
                string   xlsxOutExtName  = Path.GetFileNameWithoutExtension(file);
                string   xlsxWithExtName = Path.GetFileName(file);
                string[] xlsxNameArray   = xlsxOutExtName.Split('_');
                if (xlsxNameArray.Length <= 1)
                {
                    if (argv.OnRunChanged != null)
                    {
                        argv.OnRunChanged(string.Format("{0}    name error", xlsxWithExtName));
                    }
                }
                else
                {
                    if (argv.OnRunChanged != null)
                    {
                        argv.OnRunChanged(string.Format("{0}    ok", xlsxWithExtName));
                    }
                }
                Thread.Sleep(10);
            }
            if (argv.OnRunChanged != null)
            {
                argv.OnRunChanged("=================检查完毕=================");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 输入 路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            TextBox box = sender as TextBox;

            if (box == null)
            {
                return;
            }
            DataMemory.SetOptionFormSrcPath(box.Text);
        }
Exemplo n.º 5
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.º 6
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.º 7
0
        private static void RunExporterAll()
        {
            List <ExportType> typeList = DataMemory.GetOptionsFromTypes();

            foreach (ExportType type in typeList)
            {
                ExporterAll all = new ExporterAll();
                all.OptionList = DataMemory.GetExportOptions(type);
                all.Coding     = Coding;
                all.ExpType    = type;
                all.OutPath    = GetExporterPath(type);

                all.Init();
                all.Process();
                all.Clear();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 执行导出器
        /// </summary>
        /// <param name="type"></param>
        /// <param name="sheet"></param>
        /// <param name="option"></param>
        /// <param name="coding"></param>
        private static void RunExporter(ExportType type, DataTable sheet, Options option)
        {
            IExporter exporter = null;

            string path = Options.ConvertToString(type, option);

            if (path.Contains(Config.LANGUAGE))
            {
                if (type == ExportType.txt)
                {
                    languageCount++;
                    exporter = DataMemory.GetExporter(ExportType.i18n);
                    if (exporter != null)
                    {
                        exporter.Sheet  = sheet;
                        exporter.Option = option;
                        exporter.Coding = Coding;

                        exporter.Init();
                        if (languageCount == DataMemory.GetExportLanguageTotalCount())
                        {
                            exporter.Process();
                        }
                        else
                        {
                            exporter.Process(false);
                        }
                        exporter.Clear();
                    }
                }
            }
            else
            {
                exporter = DataMemory.GetExporter(type);
                if (exporter != null)
                {
                    exporter.Sheet  = sheet;
                    exporter.Option = option;
                    exporter.Coding = Coding;

                    exporter.Init();
                    exporter.Process();
                    exporter.Clear();
                }
            }
        }
Exemplo n.º 9
0
        private void OnCheckedChanged(object sender, EventArgs e)
        {
            CheckBox check = sender as CheckBox;

            if (check == null)
            {
                return;
            }
            ExportType type = check.Text.ToEnum <ExportType>();

            if (check.Checked)
            {
                DataMemory.SetOptionFormType(type);
            }
            else
            {
                DataMemory.RemOptionFromType(type);
            }
        }
Exemplo n.º 10
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.º 11
0
        /// <summary>
        /// 根据窗口参数,执行Excel数据导出工作
        /// </summary>
        /// <param name="options">命令行参数</param>
        public static void RunXlsxForm(ExprotCallbackArgv argv)
        {
            if (argv == null)
            {
                throw new Exception("Run xlsx form argv is null.");
            }

            if (argv.OnRunChanged != null)
            {
                argv.OnRunChanged("=================开始导出=================");
            }

            int curreExportCount       = 0;
            List <ExportType> typeList = DataMemory.GetOptionsFromTypes();

            foreach (ExportType type in typeList)
            {
                List <Options> optionList = DataMemory.GetExportOptions(type);
                foreach (Options option in optionList)
                {
                    Options result = CmdXlsx(type, option);
                    if (argv.OnRunChanged != null)
                    {
                        argv.OnRunChanged(Options.ConvertToString(type, result));
                    }
                    curreExportCount++;
                    if (argv.OnProgressChanged != null)
                    {
                        argv.OnProgressChanged(curreExportCount);
                    }
                    Thread.Sleep(1);
                }
            }

            RunExporterAll();

            if (argv.OnRunChanged != null)
            {
                argv.OnRunChanged("=================导出完毕=================");
            }
        }
Exemplo n.º 12
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.º 13
0
        /// <summary>
        /// 加载表单(使用缓存机制提高效率)
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private static DataTable LoadSheet(string path)
        {
            DataTable sheet = null;

            sheet = DataMemory.GetSheet(path);
            if (sheet != null)
            {
                return(sheet);
            }
            else
            {
                try
                {
                    FileStream       stream      = File.Open(path, FileMode.Open, FileAccess.Read);
                    IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                    excelReader.IsFirstRowAsColumnNames = true;
                    DataSet datSet = excelReader.AsDataSet();

                    if (datSet.Tables.Count < 1)
                    {
                        throw new Exception("Excel not found sheet: " + path);
                    }

                    sheet = datSet.Tables[0];
                    if (sheet.Rows.Count <= 0)
                    {
                        throw new Exception("Excel sheet not data: " + path);
                    }

                    DataMemory.SetSheet(path, sheet);

                    excelReader.Close();
                } catch (System.Exception ex) {
                    throw new Exception(ex.StackTrace);
                }
                return(sheet);
            }
        }
Exemplo n.º 14
0
 private void XlsxForm_Close(object sender, EventArgs e)
 {
     DataMemory.CacheOptionFrom();
 }
Exemplo n.º 15
0
 private static string GetExporterPath(ExportType type)
 {
     return(string.Format("{0}/{1}", DataMemory.GetOptionsFrom().XlsxDstPath, type.ToString()));
 }
Exemplo n.º 16
0
 /// <summary>
 /// 处理导出选项参数后事件
 /// </summary>
 public static void AfterExporterOptionForm()
 {
     DataMemory.Destroy();
 }