Ejemplo n.º 1
0
        public JsonResult ImportExcelFile(HttpPostedFileBase file)
        {
            try
            {
                if (file.ContentLength == 0)
                {
                    return this.Json(new { IsSuccess = false, ErrorMsg = "没有文件!" });
                }

                // 生成文件名
                var fileName = Path.Combine(Request.MapPath("~/Upload/" + DateTime.Now.ToString("yyyyMM")), Guid.NewGuid().ToString().ToUpper() + Path.GetFileName(file.FileName));

                // 按月存储文件
                if (Directory.Exists(Request.MapPath("~/Upload/" + DateTime.Now.ToString("yyyyMM"))) == false)
                {
                    Directory.CreateDirectory(Request.MapPath("~/Upload/" + DateTime.Now.ToString("yyyyMM")));
                }

                // 存储文件
                file.SaveAs(fileName);

                BGetTableDefineFromExcel bll = new BGetTableDefineFromExcel();
                var result = bll.GetTableDefineListFromExcel(fileName);

                BGeneratorSQL generatorSql = new BGeneratorSQL();
                var sqlResult = generatorSql.GeneratorSQL(result);
                return this.Json(new { IsSuccess = true, Result = sqlResult });
            }
            catch (Exception ex)
            {
                return this.Json(new { IsSuccess = false, ErrorMsg = ex.Message.ToString() });
            }
        }
Ejemplo n.º 2
0
        public static void TestSQL()
        {
            BGetTableDefineFromExcel bll = new BGetTableDefineFromExcel();
            var db = bll.GetTableDefineListFromExcel(@"D:\01code\02mine\01component\HelpWeb\HelpWeb\Upload\UserManageDB.xls");

            string json = JsonConvert.SerializeObject(db);
            BGeneratorSQL sqlBll = new BGeneratorSQL();
            var ret = sqlBll.GeneratorSQL(db);
            string jsonRet = JsonConvert.SerializeObject(ret);
        }