//登录到数据库 public JsonResult LoginDB(string userAccount, string userPwd, string localIP) { try { string strConnction = string.Concat(new string[] { "SERVER=", localIP, ";DATABASE=MASTER;UID=", userAccount, ";PWD=", userPwd }); string sqlStr = "SELECT NAME FROM SYSDATABASES ORDER BY NAME"; string message = (string)null; ArrayList dataByConAndSql = dbHelper.GetDataByConAndSql(strConnction, sqlStr, out message); if (dataByConAndSql.Count <= 0) { return(Json(new { message = "Fail", content = "没有对应的数据库 ! " })); } else { //暂时存入缓存 CacheGeneral.SetCache("key_userAccount", userAccount); CacheGeneral.SetCache("key_userPwd", userPwd); CacheGeneral.SetCache("key_localIP", localIP); return(Json(new { message = "Success", content = JsonConvert.SerializeObject(dataByConAndSql) })); } } catch (Exception ex) { //报错记录错误 Log4net.log4netCreate(typeof(GeneratedFileController), log4netPath) .Error("LoginDB(string userAccount, string userPwd, string localIP) ----> " + ex.Message); return(Json(new { message = "Fail", content = "登录失败 ! " })); } }
//读取模板 public JsonResult ReadTemplate(int marking) { string TemplateType = string.Empty; switch (marking) { case (int)TemplateEnum.BLL: TemplateType = "BLLTemplate.txt"; break; case (int)TemplateEnum.Model: TemplateType = "ModelTemplate.txt"; break; case (int)TemplateEnum.DAL: TemplateType = "DALTemplate.txt"; break; } string TemplatePath = Server.MapPath("~/App_Data/Template/" + TemplateType); //文件路径计入缓存 CacheGeneral.SetCache("TemplatePath", TemplatePath); //读取模板 string strTxt = ReadTxt(TemplatePath); if (strTxt.Contains("读取模板错误")) { return(Json(new { message = "Fail", content = "读取模板错误 ! " })); } else { return(Json(new { message = "Success", content = strTxt })); } }