/// <summary> /// 添加记录操作 /// </summary> protected void AddRecord() { HttpContext context = HttpContext.Current; HttpRequest request = context.Request; HttpResponse response = context.Response; WebPage webPage = new WebPage(); webPage.AddTime = DateTime.Now; webPage.UpdateTime = DateTime.Now; webPage.Description = request.Params["textDescription"]; webPage.PageId = Guid.NewGuid().ToString("N"); webPage.PageName = request.Params["textPageName"]; webPage.Url = request.Params["textUrl"]; ResultModel result = WebPageBll.Insert(webPage); string jsonString = JsonConvert.SerializeObject(result); response.Write(result); }
/// <summary> /// 修改某条记录 /// </summary> /// <param name="user">要修改记录对应的实体</param> /// <param name="isLog">是否写入日志</param> /// <returns>修改结果,包括是否修改成功、记录主键等信息</returns> public static ResultModel Update(WebPage webPage, bool isLog) { if (isLog) return Update(webPage); ResultModel result = new ResultModel(); try { WebPageDal.Update(webPage); result.IsSuccess = true; result.ObjectRecordId = webPage.PageId; result.ResultCode = SymbolicConstant.RESULTCODE_UPDATE_SUCCESS; result.ResultMessage = SymbolicConstant.RESULTMESSAGE_UPDATE_SUCCESS; return result; } catch (Exception exception) { result.IsSuccess = false; result.ObjectRecordId =webPage.PageId; result.ResultCode = SymbolicConstant.RESULTCODE_UPDATE_ERROR; result.ResultMessage = exception.Message; return result; } }
/// <summary> /// 修改某条记录 /// </summary> /// <param name="user">要修改记录对应的实体</param> /// <returns>修改结果,包括是否修改成功、记录主键等信息</returns> public static ResultModel Update(WebPage webPage) { OperationLog log = new OperationLog(); ResultModel result = new ResultModel(); try { log.AddTime = DateTime.Now; log.IsSuccessId = SymbolicConstant.ISSUCCESS_TRUE; log.LogId = System.Guid.NewGuid().ToString("N"); log.OperationContent = SymbolicConstant.OPERATIONCONTENT_UPDATE; log.OperationTable = typeof(WebPage).Name; log.OperationTypeCode = SymbolicConstant.OPERATIONTYPE_UPDATE; log.ResultCode = SymbolicConstant.RESULTCODE_UPDATE_SUCCESS; log.ResultMessage=SymbolicConstant.RESULTMESSAGE_UPDATE_SUCCESS; log.SystemUserId = CurrentSession.getUser().UserId; log.ObjectRecordId = webPage.PageId; WebPageDal.Update(webPage); result.IsSuccess = true; result.ObjectRecordId = webPage.PageId; result.ResultCode = SymbolicConstant.RESULTCODE_UPDATE_SUCCESS; result.ResultMessage = SymbolicConstant.RESULTMESSAGE_UPDATE_SUCCESS; return result; } catch (Exception exception) { log.ResultCode = SymbolicConstant.RESULTCODE_UPDATE_ERROR; log.IsSuccessId = SymbolicConstant.ISSUCCESS_FALSE; log.ResultMessage=exception.Message; result.IsSuccess = false; result.ObjectRecordId =webPage.PageId; result.ResultCode = SymbolicConstant.RESULTCODE_UPDATE_ERROR; result.ResultMessage = exception.Message; return result; } finally { OperationLogBll.Insert(log); } }
/// <summary> /// 添加一条新记录 /// </summary> /// <param name="webPage">WebPage实体</param> /// <param name="isLog">是否写入日志</param> /// <returns>添加结果,包括是否插入成功、记录主键等信息</returns> public static ResultModel Insert(WebPage webPage, bool isLog) { if (isLog) return Insert(webPage); ResultModel result = new ResultModel(); object id = ""; try { id = WebPageDal.Insert(webPage); result.IsSuccess = true; result.ObjectRecordId = id.ToString(); result.ResultCode = SymbolicConstant.RESULTCODE_INSERT_SUCCESS; result.ResultMessage = SymbolicConstant.RESULTMESSAGE_INSERT_SUCCESS; return result; } catch (Exception exception) { result.IsSuccess = false; result.ObjectRecordId = id.ToString(); result.ResultCode = SymbolicConstant.RESULTCODE_INSERT_ERROR; result.ResultMessage = exception.Message; return result; } }
/// <summary> /// 根据主键查询指定记录 /// </summary> /// <param name="webPageId">主键</param> /// <param name="isLog">是否写入日志</param> /// <returns>查询结果,封装了查询出的实体</returns> public static ResultModel GetWebPageById(string webPageId, bool isLog) { if (isLog) return GetWebPageById(webPageId); WebPage webPage = new WebPage(); ResultModel result = new ResultModel(); try { webPage= WebPageDal.GetModel(webPageId); result.Data = webPage; result.IsSuccess = true; result.ResultCode = SymbolicConstant.RESULTCODE_GETMODEL_SUCCESS; result.ResultMessage=SymbolicConstant.RESULTMESSAGE_GETMODEL_SUCCESS; return result; } catch (Exception exception) { result.IsSuccess = false; result.ResultCode = SymbolicConstant.RESULTCODE_GETMODEL_ERROR; result.ResultMessage = exception.Message; return result; } }
protected void Generate(string rootDir, DirectoryInfo directory) { FileInfo[] files = directory.GetFiles("*.htm"); List<string> urlList = new List<string>(); foreach (FileInfo item in files) { //输入的根目录不正确 if (item.FullName.IndexOf(rootDir) != 0) { return; } //相对路径 string url = item.FullName.Substring(rootDir.Length, item.FullName.Length - rootDir.Length); //前面的directory.GetFiles("*.htm")会把*.html的文件也获取进去,这里进行过滤 string ext = Path.GetExtension(url).ToLower(); if (ext != ".htm") continue; url = url.Replace("\\", "/"); if (!IfHavePage(url)) { WebPage page = new WebPage(); page.Url = url; page.PageName = "自动生成的模块"; page.Description = "自动生成的模块,没有描述"; page.PageId = Guid.NewGuid().ToString("N"); page.AddTime = DateTime.Now; page.UpdateTime = DateTime.Now; WebPageBll.Insert(page); } } DirectoryInfo[] dirs = directory.GetDirectories(); foreach (DirectoryInfo item in dirs) { Generate(rootDir, item); } }
/// <summary> /// 修改WebPage表中的某条记录 /// </summary> /// <param name="user">要修改记录对应的实体</param> public static void Update(WebPage webPage) { DataAccessUtility.Update<WebPage>(webPage); }
/// <summary> /// 插入一条新记录 /// </summary> /// <param name="webPage">WebPage实体</param> /// <returns>插入记录的主键</returns> public static object Insert(WebPage webPage) { Object id = DataAccessUtility.Insert<WebPage>(webPage); return id; }
/// <summary> /// 删除WebPage表中的某条记录 /// </summary> /// <param name="user">要删除记录的对应的实体</param> public static void Delete(WebPage webPage) { DataAccessUtility.Delete<WebPage>(webPage); }