/// <summary> /// APP通用数据访问接口(CRUD) /// </summary> /// <param name="parameters">请求接口所带的参数模型对象</param> /// <returns>请求结果</returns> public JsonResult Index(CommonApiModel parameters) { var bllEntity = BllFactory.GetBllInstance(parameters.TableName); var entityType = bllEntity.GetType(); var methodName = parameters.Operate.ToString(); var invokeParameters = PrepareInvokeParameters(parameters); try { if (parameters.Operate == DbOperateType.BulkInsert) { entityType.InvokeMember(methodName, BindingFlags.InvokeMethod, null, bllEntity, invokeParameters); return(Json(ErrorModel.BulkInsertSuccess)); } var result = entityType.InvokeMember(methodName, BindingFlags.InvokeMethod, null, bllEntity, invokeParameters); var jsonObj = ErrorModel.GetDataSuccess(result, parameters.TableName); return(new CustomJsonResult { Data = jsonObj, MaxJsonLength = int.MaxValue, FormateStr = "yyyy-MM-dd HH:mm:ss" }); } catch (Exception ex) { ExceptionLogBll.ExceptionPersistence("AppController.cs", "AppController", ex); return(Json(ErrorModel.InputError, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 对数据的批量更新 /// </summary> /// <param name="tableName">目标表格名称</param> /// <param name="startId">当前更新记录开始位置(不包括所传入的id)</param> /// <param name="updateType">更新类型枚举</param> public static void BulkUpdate(string tableName, int startId, DataUpdateType updateType = DataUpdateType.Insert) { var bllEntity = BllFactory.GetBllInstance(tableName); var bllType = bllEntity.GetType(); try { var whereStr = "Id>" + startId; var idList = (IEnumerable <object>)bllType.InvokeMember("QuerySingleColumn", BindingFlags.InvokeMethod, null, bllEntity, new object[] { whereStr, "Id" }); var updateModelList = idList.Select(id => new DbUpdateLog { TableName = tableName, TargetId = (int)id, UpdateType = (int)updateType, UpdateTime = DateTime.Now }); UpdateBll.BulkInsert(updateModelList); } catch (Exception ex) { ExceptionLogBll.ExceptionPersistence("DataUpdateLog.cs", "DataUpdateLog", ex); } }
private List <Func <bool> > CreateDbupadwLogDelegates(Dictionary <string, object> data) { var delegates = new List <Func <bool> >(); foreach (var couple in data) { var t = couple.Key; if (t.Equals("DbUpdateLog")) { var json = JsonHelper.Serialize(couple.Value); delegates.Add(() => { var bllInstance = BllFactory.GetBllInstance(t) as IBll; var format = "SET IDENTITY_INSERT [dbo].[{0}] {1};"; var setOnSql = string.Format(format, t, "ON"); bllInstance.ExecuteSql(setOnSql); bllInstance.BulkInsert(json); var setOffSql = string.Format(format, t, "OFF"); bllInstance.ExecuteSql(setOffSql); return(true); }); } } return(delegates); }
public object List() { List <Category> List = BllFactory.GetCategoryBLL().GetList(); var result = new GridResult <Category>(List); return(new JsonResult(result)); }
public JsonResult GetListForVue(string json) { var param = JsonHelper.Deserialize <JObject>(json); var page = param.Value <int>("page"); var size = param.Value <int>("size"); var order = param.Value <string>("order"); // 排序字段 var desc = param.Value <bool>("desc"); // 是否降序 var table = param.Value <string>("table"); var conditions = param.Value <JObject>("conditions"); var query = BuildQueryCondition(table, conditions); var bll = BllFactory.GetBllInstance(table); if (bll != null) { var type = bll.GetType(); var arguments = new object[] { page, size, query, order, desc, 0 }; var list = type.InvokeMember("QueryPageList", BindingFlags.InvokeMethod, null, bll, arguments); return(Json(ErrorModel.GetDataSuccess(new { total = (int)arguments[5], list }))); } return(Json(ErrorModel.GetDataFailed)); }
private void initBll() { BllFactory.DLLBasePath = Application.StartupPath; recordBll = BllFactory.GetMemberCardRecordBll(); cardBll = BllFactory.GetMemberCardBll(); catBll = BllFactory.GetMemberCardCategoryBll(); }
public JsonResult GetSingle(int id, string target) { if (string.IsNullOrEmpty(target) || id == 0) { return(Json(ErrorModel.InputError)); } var bllInstance = BllFactory.GetBllInstance(target); if (bllInstance == null) { return(Json(ErrorModel.InputError)); } var type = bllInstance.GetType(); var data = type.InvokeMember("QuerySingle", BindingFlags.InvokeMethod, null, bllInstance, new object[] { id, null }); if (data == null) { return(Json(ErrorModel.GetDataFailed)); } return(Json(ErrorModel.GetDataSuccess(data))); }
public object LoadModel(int?page) { // 说明:参数page表示分页数,方法名LoadModel其实可以【随便取】。 // 根据用户选择的界面风格,计算实现要呈现的页面路径。 string papeUrl = this.GetTargetPageUrl("Customers.aspx"); if (this.IsStyle2) { // Style2 风格下,页面不需要绑定数据。数据由JS通过AJAX方式获取 return(new PageResult(papeUrl, null)); } // 为Style1 风格获取数据。 CustomerSearchInfo info = new CustomerSearchInfo(); info.SearchWord = string.Empty; info.PageIndex = page.HasValue ? page.Value - 1 : 0; info.PageSize = AppHelper.DefaultPageSize; CustomersPageModel result = new CustomersPageModel(); result.PagingInfo = info; result.List = BllFactory.GetCustomerBLL().GetList(info); result.RequestUrlEncodeRawUrl = HttpUtility.UrlEncode(this.HttpContext.Request.RawUrl); return(new PageResult(papeUrl, result)); }
private List <Func <bool> > GetDelegates(Dictionary <string, object> data) { var delegates = new List <Func <bool> >(); foreach (var couple in data) { var t = couple.Key; var json = JsonHelper.Serialize(couple.Value); // 1. 打开主键插入开关 SET IDENTITY_INSERT [dbo].[ExamType] ON // 2. 插入数据 // 3. 关闭主键插入开关 SET IDENTITY_INSERT [dbo].[ExamType] OFF delegates.Add(() => { var bllInstance = BllFactory.GetBllInstance(t) as IBll; var format = "SET IDENTITY_INSERT [dbo].[{0}] {1};"; var setOnSql = string.Format(format, t, "ON"); bllInstance.ExecuteSql(setOnSql); bllInstance.BulkInsert(json); var setOffSql = string.Format(format, t, "OFF"); bllInstance.ExecuteSql(setOffSql); return(true); }); } return(delegates); }
public void ChangeProductQuantity(int productId, int quantity) { if (productId < 0) { throw new MyMessageException("没有指定ProductID"); } BllFactory.GetProductBLL().ChangeProductQuantity(productId, quantity); }
/// <summary> /// 获取数据列表的公共方法(通过表名反映获取) /// </summary> /// <returns></returns> public JsonResult GetList() { var instructorId = Request["instructorId"].ToInt32(); var month = Request["month"].ToDateTime(); var tableName = Request["target"]; if (string.IsNullOrEmpty(tableName)) { return(Json(ErrorModel.InputError)); } var json = JqueryDataTableAjaxHelper.GetPageListJson( Request, (pageIndex, pageSize) => { var bllInstance = BllFactory.GetBllInstance(tableName); if (bllInstance != null) { var type = bllInstance.GetType(); try { // build condition var conditionList = new List <string>(); if (instructorId > 0) { conditionList.Add("InstructorId=" + instructorId); } if (month != default(DateTime)) { var start = month.AddDays(-1); var end = month.AddMonths(1); conditionList.Add($"UploadTime>'{start}' AND UploadTime<'{end}'"); } var condition = string.Join(" AND ", conditionList); var orderField = Request["order"] ?? "UploadTime"; var arguments = new object[] { pageIndex, pageSize, condition, orderField, true, 0 }; var list = type.InvokeMember("QueryPageList", BindingFlags.InvokeMethod, null, bllInstance, arguments); return(new KeyValuePair <int, object>((int)arguments[5], list)); } catch (Exception ex) { ExceptionLogBll.ExceptionPersistence("InstructorController.cs", "InstructorController", ex); return(new KeyValuePair <int, object>()); } } return(new KeyValuePair <int, object>()); }); return(Json(json)); }
public void SetOrderStatus(int id, bool finished) { if (id <= 0) { throw new MyMessageException("没有指定OrderId"); } BllFactory.GetOrderBLL().SetOrderStatus(id, finished); }
public object List(CustomerSearchInfo pagingInfo) { pagingInfo.CheckPagingInfoState(); List <Customer> List = BllFactory.GetCustomerBLL().GetList(pagingInfo); var result = new GridResult <Customer>(List, pagingInfo.TotalRecords); return(new JsonResult(result)); }
public object List(ProductSearchInfo pagingInfo) { pagingInfo.CheckPagingInfoState(); List <Product> List = BllFactory.GetProductBLL().SearchProduct(pagingInfo); var result = new GridResult <Product>(List, pagingInfo.TotalRecords); return(new JsonResult(result)); }
private void FrmSaleLog_Load(object sender, EventArgs e) { BllFactory.DLLBasePath = Application.StartupPath; bll = BllFactory.GetReportBll(); logBll = BllFactory.GetSaleLogBll(); goodsBll = BllFactory.GetGoodsBll(); catBll = BllFactory.GetGoodsCategoryBll(); loadData(); }
public object Search2(OrderSearchInfo info) { info.CheckPagingInfoState(); List <Order> list = BllFactory.GetOrderBLL().Search(info); var result = new GridResult <Order>(list, info.TotalRecords); return(new JsonResult(result)); }
public object GetById(int id) { Customer customer = BllFactory.GetCustomerBLL().GetById(id); if (customer == null) { throw new MyMessageException("指定的ID值无效。不能找到对应的记录。"); } return(new JsonResult(customer)); }
public object GetById(int id) { Order item = BllFactory.GetOrderBLL().GetOrderById(id); if (item == null) { throw new MyMessageException("指定的ID值无效。不能找到对应的记录。"); } return(new JsonResult(item)); }
public object Show(int id) { Customer customer = BllFactory.GetCustomerBLL().GetById(id); if (customer == null) { throw new MyMessageException("指定的ID值无效。不能找到对应的记录。"); } return(new PageResult("/Pages/Style1/Controls/CustomerInfo.cshtml", customer)); }
public object GetById(int id) { Product product = BllFactory.GetProductBLL().GetProductById(id); if (product == null) { throw new MyMessageException("指定的ID值无效。不能找到对应的记录。"); } return(new JsonResult(product)); }
public object Search(OrderSearchInfo info, int?page) { info.PageIndex = page.HasValue ? page.Value - 1 : 0; info.PageSize = AppHelper.DefaultPageSize; OrderListModel data = new OrderListModel(); // 搜索数据库 data.List = BllFactory.GetOrderBLL().Search(info); data.SearchInfo = info; return(new PageResult("/Pages/Style1/Controls/OrderList.cshtml", data)); }
public object Delete(int id, string returnUrl) { BllFactory.GetProductBLL().Delete(id); if (string.IsNullOrEmpty(returnUrl)) { return(null); } else { return(new RedirectResult(returnUrl)); } }
private static Dictionary <string, int> GetNewStartsDict() { var tables = Utils.GetClient2ServerTables(); var newStartsDict = new Dictionary <string, int>(); tables.ForEach(t => { var bllInstance = BllFactory.GetBllInstance(t) as IBll; var maxId = (int)bllInstance.GetMaxId(); newStartsDict.Add(t, maxId); }); return(newStartsDict); }
public object Show(int id) { Product product = BllFactory.GetProductBLL().GetProductById(id); if (product == null) { throw new MyMessageException("指定的ID值无效。不能找到对应的记录。"); } List <Category> categories = BllFactory.GetCategoryBLL().GetList(); ProductInfoModel data = new ProductInfoModel(categories, product); return(new PageResult("/Pages/Style1/Controls/ProductInfo.cshtml", data)); }
/// <summary> /// 根据流程类型获取当前登录人对应的流程 /// </summary> /// <param name="context"></param> /// <param name="TYPE_CODE"></param> /// <returns></returns> public static string getFlowDefineId(HttpContext context, string TYPE_CODE) { string orgid = getOrgId(context); List <FLOW_DERIVE_RELATION> list = BllFactory.GetFlow_Derive_RelationBLL().GetList(" and CHILD_FRISTSTEP_DEPID='" + orgid + "' and TYPE_CODE='" + TYPE_CODE + "'").ToList <FLOW_DERIVE_RELATION>(); if (list.Count > 0) { return(list[0].define_code_child); } else { return(""); } }
public object ShowCustomerPicker(string searchWord, int?page) { CustomerSearchInfo info = new CustomerSearchInfo(); info.SearchWord = searchWord ?? string.Empty; info.PageIndex = page.HasValue ? page.Value - 1 : 0; info.PageSize = AppHelper.DefaultPageSize; CustomerPickerModel data = new CustomerPickerModel(); data.SearchInfo = info; data.List = BllFactory.GetCustomerBLL().GetList(info); return(new PageResult("/Pages/Style1/Controls/CustomerPicker.cshtml", data)); }
public object Show(int id) { if (id <= 0) { throw new MyMessageException("没有指定OrderId"); } Order item = BllFactory.GetOrderBLL().GetOrderById(id); if (item == null) { throw new MyMessageException("指定的ID值无效。不能找到对应的记录。"); } return(new PageResult("/Pages/Style1/Controls/OrderInfo.cshtml", item)); }
public static Dictionary <string, string> getMyFlowDefine(HttpContext context) { string orgid = getOrgId(context); //WorkFlow.BLL.Operate.get List <FLOW_DERIVE_RELATION> list = BllFactory.GetFlow_Derive_RelationBLL().GetList(" and CHILD_FRISTSTEP_DEPID='" + orgid + "'").ToList <FLOW_DERIVE_RELATION>(); Dictionary <string, string> dclist = new Dictionary <string, string>(); foreach (FLOW_DERIVE_RELATION model in list) { dclist.Add(model.define_code_child, model.TYPE_CODE); } return(dclist); }
public object LoadModel(int?categoryId, int?page) { string papeUrl = this.GetTargetPageUrl("Products.aspx"); if (this.IsStyle2) { // Style2 风格下,页面不需要绑定数据。数据由JS通过AJAX方式获取 return(new PageResult(papeUrl, null)); } ProductsPageModel result = new ProductsPageModel(); result.Categories = BllFactory.GetCategoryBLL().GetList(); if (result.Categories.Count == 0) { return(new RedirectResult("/Pages/Categories.aspx")); } // 获取当前用户选择的商品分类ID ProductSearchInfo info = new ProductSearchInfo(); info.CategoryId = categoryId.HasValue ? categoryId.Value : 0; if (info.CategoryId == 0) { info.CategoryId = result.Categories[0].CategoryID; } info.PageIndex = page.HasValue ? page.Value - 1 : 0; info.PageSize = AppHelper.DefaultPageSize; result.ProductInfo = new ProductInfoModel( result.Categories, new Product { CategoryID = info.CategoryId }); result.PagingInfo = info; result.CurrentCategoryId = info.CategoryId; result.RequestUrlEncodeRawUrl = HttpUtility.UrlEncode(this.HttpContext.Request.RawUrl); // 加载商品列表 result.Products = BllFactory.GetProductBLL().SearchProduct(info); return(new PageResult(papeUrl, result)); }
private List <Func <bool> > CreateUpdateDelegates(Dictionary <string, object> data) { var delegates = new List <Func <bool> >(); foreach (var couple in data) { var t = couple.Key; var list = couple.Value as List <object>; var bllInstance = BllFactory.GetBllInstance(t) as IBll; foreach (var o in list) { delegates.Add(() => bllInstance.Update(o)); } } return(delegates); }