public IActionResult CustomStatusUpload() { var customId = Request.Form["CustomId"].ToString().ToInt(); try { if (customId > 0) { if (!Request.Form["CustomStatus"].Equals(string.Empty)) { var customStatus = Request.Form["CustomStatus"].ObjToInt(); SugarHandler db = new SugarHandler(); if (db.Update <retail_custom>(x => new retail_custom() { Status = customStatus }, q => q.Id == customId)) { return(Ok("信息更新成功")); } } } return(Problem("更新失败,请检查参数是否准确")); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult MachineBindUpload() { try { var companyId = Request.Headers["CompanyId"].ToString().ToInt(); var companyPid = Request.Headers["CompanyPid"].ToString().ToInt(); int machineId = Request.Form["machineId"].ToString().ToInt(); string bindUid = Request.Form["bindUid"].ToString(); string bindComputerName = Request.Form["bindComputerName"].ToString(); if (string.IsNullOrEmpty(bindUid)) { return(Problem("绑定Uid不允许为空")); } SugarHandler db = new SugarHandler(); var machine = db.Single <retail_machine>(x => x.Id == machineId && x.CompanyId == companyId); if (machine == null) { return(Problem("查询不到对应的机器")); } if (!string.IsNullOrEmpty(machine.BindUid) && !machine.BindUid.Equals(bindUid, StringComparison.OrdinalIgnoreCase)) { return(Problem("该机器号已被绑定")); } db.Update <retail_machine>(x => new retail_machine() { BindUid = bindUid, BindComputerName = bindComputerName }, q => q.Id == machineId, false); return(Ok("机器绑定成功")); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult GetCompanyInfo() { try { string code = Request.Form["code"].ToString(); if (string.IsNullOrEmpty(code)) { return(Problem("参数有误")); } SugarHandler db = new SugarHandler(); var company = db.Single <retail_company>(x => x.UniqueCode == code); if (company == null || company.Id == 0) { return(Problem("编码有误")); } var machines = db.GetList <retail_machine>(x => x.CompanyId == company.Id); var employees = db.GetList <retail_employee>(x => x.CompanyId == company.Id); Dictionary <string, object> dict = new Dictionary <string, object>(); dict["Company"] = company; dict["Machines"] = machines; dict["Employees"] = employees; return(Ok(dict)); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult CategoryUpload() { SugarHandler db = new SugarHandler(); try { //企业Id var companyId = Request.Headers["companyId"].ToString().ToInt(); //企业Pid var companyPid = Request.Headers["companyPid"].ToString().ToInt(); string jsonCategory = Request.Form["jsonCategory"].ToString(); if (string.IsNullOrEmpty(jsonCategory)) { return(Problem("参数不正确")); } JObject obj = JsonConvert.DeserializeObject <JObject>(jsonCategory); var category = obj.JObjectTransToModel <retail_category>(); category.Id = obj["categoryId"].ToString().ToInt(); if (category.Id == 0) { category.CompanyPid = companyPid; category.Status = 1; var result = (category.Id = db.AddReturnId(category)) > 0; retail_ref_company_category company_Category = new retail_ref_company_category() { CategoryId = category.Id, CompanyId = companyId, CompanyPid = companyPid }; result = db.Add(company_Category); db.CommitTran(); if (result) { return(Ok(category)); } } else { var result = db.Update <retail_category>(x => new retail_category() { CategoryCode = category.CategoryCode, CategoryName = category.CategoryName, SordIndex = category.SordIndex, CategoryType = category.CategoryType, ParentId = category.ParentId }, q => q.Id == category.Id, false); db.CommitTran(); if (result) { return(Ok("更新成功")); } } return(Problem("参数有误")); } catch (Exception ex) { db.RollbackTran(); return(Problem(ex.Message)); } }
public IActionResult GetArea() { try { SugarHandler db = new SugarHandler(); return(new JsonResult(db.Queryable <retail_area>().OrderBy(x => x.CityId).ToList())); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult GetCity() { try { SugarHandler db = new SugarHandler(); return(Ok(db.Queryable <retail_city>().OrderBy(x => x.ProvinceId).ToList())); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult Index() { var db = SugarHandler.Instance(); var aa = new QueryDescriptor(); var lst = db.QueryWhereList <SysLinkItem>(o => o.Status == 1); var ct = 0; var lst2 = db.QueryPageList <SysLinkItem>(aa, out ct); return(Json(lst)); }
public IActionResult CustomUpload() { LogHelper.WriteLog(LogType.BASE, "进入客户信息上传接口"); try { //企业Id var companyId = Request.Headers["companyId"].ToString().ToInt(); LogHelper.WriteLog(LogType.BASE, $"企业id:{companyId}"); //企业Pid var companyPid = Request.Headers["companyPid"].ToString().ToInt(); LogHelper.WriteLog(LogType.BASE, $"企业id:{companyPid}"); SugarHandler db = new SugarHandler(); string jsonCustom = Request.Form["jsonCustom"].ToString(); LogHelper.WriteLog(LogType.BASE, $"客户信息:{jsonCustom}"); JObject jObject = (JObject)JsonConvert.DeserializeObject(jsonCustom); retail_custom custom = new retail_custom(); custom = jObject.JTokenTransToModel <retail_custom>(); custom.CompanyPid = companyPid; custom.Id = jObject["CustomId"].ObjToInt(); if (custom.Id == 0) { LogHelper.WriteLog(LogType.BASE, $"新增客户"); custom.Status = 1; custom.CreateDate = DateTime.Now; custom.ModifyDate = DateTime.Now; custom.Id = db.AddReturnId(custom); retail_ref_company_custom company_Custom = new retail_ref_company_custom(); company_Custom.CustomId = custom.Id; company_Custom.CompanyId = companyId; db.AddReturnBool(company_Custom); JObject obj = new JObject(); obj["CustomId"] = custom.Id; return(Ok(custom)); } else { LogHelper.WriteLog(LogType.BASE, $"更新客户"); if (db.Update <retail_custom>(x => new retail_custom { CustomCode = custom.CustomCode, CustomName = custom.CustomName, ProvinceId = custom.ProvinceId, CityId = custom.CityId, AreaId = custom.AreaId, LegalPerson = custom.LegalPerson, Phone = custom.Phone, Fax = custom.Fax, Address = custom.Address, Relation = custom.Relation, RelationPhone = custom.RelationPhone, Remark = custom.Remark, ModifyDate = DateTime.Now }, q => q.Id == custom.Id, false)) { return(Ok(true)); } } return(Problem("更新失败,请检查参数")); } catch (Exception ex) { LogHelper.WriteErrorLog(LogType.BASE, ex); return(Problem("参数异常:" + ex.Message)); } }
public IActionResult GetProductSizeInfo() { var companyId = Request.Headers["CompanyId"].ToString().ToInt(); try { SugarHandler db = new SugarHandler(); var products = db.Queryable <retail_product_size, retail_product, retail_ref_company_product>((t1, t2, t3) => new object[] { JoinType.Inner, t1.ProductId == t2.Id, JoinType.Inner, t2.Id == t3.ProductId }).Where((t1, t2, t3) => (t3.CompanyId == companyId && t2.Status == 1)).ToList(); return(Ok(products)); } catch (SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult GetUnit() { var companyId = Request.Headers["CompanyId"].ObjToInt(); try { SugarHandler db = new SugarHandler(); var units = db.Queryable <retail_unit, retail_ref_company_unit>((t1, t2) => new object[] { JoinType.Inner, t1.Id == t2.UnitId }).Where((t1, t2) => t2.CompanyId == companyId).ToList(); return(Ok(units)); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult GetCustom() { var companyId = Request.Headers["CompanyId"].ObjToInt(); var companyPid = Request.Headers["CompanyPid"].ObjToInt(); try { SugarHandler db = new SugarHandler(); var customs = db.Queryable <retail_custom, retail_ref_company_custom>((t1, t2) => new object[] { JoinType.Inner, t1.Id == t2.CustomId }).Where((t1, t2) => t2.CompanyId == companyId && t1.CompanyPid == companyPid && t1.Status == 1).ToList(); return(Ok(customs)); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
static void Main(string[] args) { // The other part of the client code constructs the actual chain. var Milk = new MilkHandler(); var Sugar = new SugarHandler(); var Coffee = new CoffeeHandler(); Milk.SetNext(Sugar).SetNext(Coffee); // The client should be able to send a request to any handler, not // just the first one in the chain. Console.WriteLine("Chain: Milk > Sugar > Coffee\n"); Context.ContextCode(Milk); Console.WriteLine(); Console.WriteLine("Subchain: Sugar > Coffee\n"); Context.ContextCode(Sugar); }
public override void OnActionExecuting(ActionExecutingContext context) { if (context == null) { return; } var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor; if (controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true) .Any(a => a.GetType().Equals(typeof(NoCompanyRequiredAttribute)))) { return; } if (context.ModelState.IsValid) { var companyId = context.HttpContext.Request.Headers["CompanyId"].ToString().ToInt(); var companyPid = context.HttpContext.Request.Headers["CompanyPid"].ToString().ToInt(); var isValid = companyId > 0; if (isValid) { try { SugarHandler db = new SugarHandler(); var company = db.Single <retail_company>(x => x.Id == companyId); isValid = company != null && company.ParentId == companyPid; } catch (Exception ex) { LogHelper.WriteErrorLog(LogType.BASE, ex); isValid = false; } } if (!isValid) { context.Result = new ObjectResult(new ProblemDetails() { Detail = "企业信息不正确" }); } } }
public IActionResult OrderInfoUpload() { var companyId = Request.Headers["CompanyId"].ToString().ToInt(); var companyPid = Request.Headers["CompanyPid"].ToString().ToInt(); HttpContext.Response.ContentType = "application/json"; string jsonOrder = ""; using (var sr = new StreamReader(Request.Body, Encoding.UTF8)) { var v = sr.ReadToEndAsync();//或者sr.ReadToEnd() v.Wait(); jsonOrder = v.Result; } JObject orderObj = (JObject)JsonConvert.DeserializeObject(jsonOrder); string orderNum = orderObj["OrderNum"].ToString(); SugarHandler db = new SugarHandler(); var orderModel = db.Single <retail_order>(x => x.OrderNum == orderNum); if (orderModel == null) { orderModel = new retail_order(); } orderModel = orderObj.JObjectTransToModel <retail_order>(); JArray jArray = (JArray)JsonConvert.DeserializeObject(orderObj["OrderDetail"].ObjToString()); List <retail_order_item> orderDetails = new List <retail_order_item>(); foreach (var item in jArray) { retail_order_item orderDetail = new retail_order_item(); orderDetail = item.JTokenTransToModel <retail_order_item>(); orderDetails.Add(orderDetail); } db.BeginTran(); try { if (orderModel.Id > 0) { db.Update <retail_order>(x => new retail_order() { CustomId = orderModel.CustomId, CustomName = orderModel.CustomName, Relation = orderModel.Relation, RelationPhone = orderModel.RelationPhone, Address = orderModel.Address, PayMentType = orderModel.PayMentType, OriginalPrice = orderModel.OriginalPrice, OrderDiscount = orderModel.OrderDiscount, OrderDiscountAmount = orderModel.OrderDiscountAmount, ReceivePrice = orderModel.ReceivePrice, PayStatus = orderModel.PayStatus, PayDate = orderModel.PayDate, OrderStatus = orderModel.OrderStatus, Remark = orderModel.Remark, SaleMan = orderModel.SaleMan }, q => q.Id == orderModel.Id, false); } else { orderModel.Id = db.AddReturnId(orderModel); } foreach (var item in orderDetails) { var existsItem = db.Single <retail_order_item>(x => x.OrderNum == item.OrderNum && x.ItemGuid == item.ItemGuid); if (existsItem != null && existsItem.Id > 0) { db.Update <retail_order_item>(x => new retail_order_item() { ProductId = item.ProductId, ProductName = item.ProductName, ProductUnitName = item.ProductUnitName, SizeId = item.SizeId, SizeName = item.SizeName, IsSingleSize = item.IsSingleSize, OriginalPrice = item.OriginalPrice, ItemDiscount = item.ItemDiscount, ItemDiscountPrice = item.ItemDiscountPrice, PromotionPrice = item.PromotionPrice, BuyPrice = item.BuyPrice, BuyCount = item.BuyCount, PackUnitName = item.PackUnitName, ConversionValue = item.ConversionValue, ProductDescription = item.ProductDescription, Remark = item.Remark }, q => q.Id == existsItem.Id, false); } else { item.CreateDate = AppSetting.TimeNow; item.Id = db.AddReturnId(item); } } return(Ok("订单上传成功")); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }