示例#1
0
文件: Procedure.cs 项目: clbouc/test
        /// <summary>
        /// 根据文件夹查找文件,同时将其读取并根据DateTime合并,并返回sql语句(主键要自动生成)
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="folder">csv数据文件存放目录,确保只有一层</param>
        /// <returns>insert sql语句</returns>
        public static List <String> MergeCsvFile2InsertSql(String tableName, String folder)
        {
            String fileprefix = folder;
            List <List <ModelCommon> > datas = new List <List <ModelCommon> >();
            int i = 0;

            foreach (String file in kingdataFiles)
            {
                String filepath = fileprefix + file + ".csv";
                datas.Add(readFunc[i++](filepath));
            }
            //store 合并后的 data
            List <List <List <ModelCommon> > > temporaryResult = new List <List <List <ModelCommon> > >();

            //decorate to use MergeByDateTimeMapRepeat
            foreach (var datai in datas)
            {
                List <List <ModelCommon> > modelCommonss = new List <List <ModelCommon> >();
                foreach (var model in datai)
                {
                    List <ModelCommon> temp = new List <ModelCommon>();
                    temp.Add(model);
                    modelCommonss.Add(temp);
                }
                temporaryResult.Add(modelCommonss);
            }
            //合并为一个
            while (temporaryResult.Count > 1)
            {
                var res00 = temporaryResult[0];
                var res01 = temporaryResult[1];
                temporaryResult.RemoveAt(1);
                temporaryResult.RemoveAt(0);
                temporaryResult.Add(ModelUtil.MergeByDateTimeMapRepeat <ModelCommon, ModelCommon>(res00, res01));
            }

            List <List <ValAndFieldName> > valFieldAndNameList = ModelUtil.GenerateListValAndFieldName(temporaryResult[0]);

            List <String> sqlInsertList = new List <string>();

            foreach (var d in valFieldAndNameList)
            {
                String str = DbGenerateUtil.GenerateInsertDbSql(tableName, d);
                sqlInsertList.Add(str);
            }

            Console.WriteLine("\n" + sqlInsertList.Count + "\n");
            return(sqlInsertList);
        }
示例#2
0
文件: Procedure.cs 项目: clbouc/test
 /// <summary>
 /// 创建表 根据 table.csv
 /// </summary>
 /// <param name="csvconfigfile">table.csv文件</param>
 /// <param name="tableName"></param>
 public static void CreateTableInProgram(String csvconfigfile, String tableName)
 {
     DbGenerateUtil.CreateTable(csvconfigfile, csvconfigfile + ".rename", tableName);
 }