public static string GetRandomStr(int length, ContextString dbContext) { Random rd = new Random(); string str = "abcdefghijklmnopqrstuvwxyz0123456789"; bool isnewstr = true; string result = string.Empty; do { result = string.Empty; for (int i = 0; i < length; i++) { result += str[rd.Next(str.Length)]; } var count = dbContext.RandomStr.Where(i => i.Str == result).Count(); if (count <= 0) { dbContext.RandomStr.Add(new RandomStr { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Str = result, UpdateTime = DateTime.Now }); if (dbContext.SaveChanges() > 0) { isnewstr = false; } } } while (isnewstr); return(result); }
/// <summary> /// 删除文件记录及物理文件 /// </summary> /// <param name="filepath"></param> /// <param name="dbContext"></param> /// <returns></returns> public static async Task <bool> DelFile(string Code, ContextString dbContext) { bool _Result = false; try { var file = await dbContext.AssetFiles.Where(i => i.Code == Code).AsNoTracking().FirstOrDefaultAsync(); var path = Method._hostingEnvironment.WebRootPath + file.FilePath; DirectoryInfo info = new DirectoryInfo(path); Directory.Delete(info.Parent.FullName, true); dbContext.AssetFiles.Remove(file); if (await dbContext.SaveChangesAsync() > 0) { _Result = true; } } catch (Exception e) { QMLog qm = new QMLog(); qm.WriteLogToFile("删除文件出错", e.ToString()); } return(_Result); }
/// <summary> /// 获取当前用户用户名 /// </summary> /// <returns></returns> public static UserOnLine GetLoginUserName(ContextString dbContext, HttpContext context) { UserOnLine uol = new UserOnLine(); int? _ID = context.Session.GetInt32("AccountID"); if (_ID == null) { return(uol); } var _User = dbContext.Account.Where(i => i.ID == _ID).FirstOrDefault(); if (_User == null) { return(uol); } var mallcode = context.Session.GetString("MallCode"); uol.UserName = _User.AccountName; uol.UserCode = _User.Code; uol.MallCode = mallcode; uol.ID = _ID.Value; uol.SystemModule = _User.SystemModule; return(uol); }
void ShowUsingStatements(ContextString context, string contextName, StringBuilder output) { if (context.HasUsingStatements) { var usingStatements = context.GetUsingStatements(); foreach (var usingStatement in usingStatements) { output.Append("- " + contextName + " Using Statement: "); if (usingStatement.Type == UsingString.UsingType.AddPrefix) { output.AppendLine("Add " + usingStatement.PrefixToAdd.FormatWithSeparator('.')); } else if (usingStatement.Type == UsingString.UsingType.ReplacePrefix) { output.AppendLine("Replace " + usingStatement.PrefixToRemove.FormatWithSeparator('.') + " with " + usingStatement.PrefixToAdd.FormatWithSeparator('.')); } else { output.AppendLine("Unknown using type " + usingStatement.Type); } } } }
private ArrayList ParseBody(string body, string sqlMode) { bool flag = sqlMode.IndexOf("ANSI_QUOTES") != -1; bool flag2 = sqlMode.IndexOf("NO_BACKSLASH_ESCAPES") != -1; string text = flag ? "``\"\"" : "``"; ContextString contextString = new ContextString(text, !flag2); int num = contextString.IndexOf(body, '('); body = body.Substring(num + 1); int num2 = this.FindRightParen(body, text); string src = body.Substring(0, num2).Trim(); ContextString expr_71 = contextString; expr_71.ContextMarkers += "()"; ArrayList arrayList = new ArrayList(); string[] array = contextString.Split(src, ","); if (array.Length > 0) { string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string parmDef = array2[i]; arrayList.Add(this.ParseParameter(parmDef, contextString, sqlMode)); } } body = body.Substring(num2 + 1).Trim().ToLower(CultureInfo.InvariantCulture); if (body.StartsWith("returns")) { arrayList.Add(this.ParseParameter(body, contextString, sqlMode)); } return(arrayList); }
public async Task <IActionResult> AddDevice(Input_Device model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); //调用云端接口创建设备 var url = Method.MallSite + "API/IOT/AddDevice"; _Result = Method.PostMothsToObj(url, inputStr); if (_Result.Code == "200") { Pull pull = new Pull(); await pull.PullDevData(); } return(Json(_Result)); }
private async Task <List <MenuViewModel> > GetUserMenu(ContextString dbContext, int?ID, ArrayList TextEN) { string sql = ""; if (ID == null || ID == 0) { sql = "select a.[ID],a.[AddTime] ,a.[Icon],a.[Order],a.[ParentID],a.[PermissionID],a.[TextCH] ,a.[TextEN],a.[Href] from MallSite_Menu a where a.[Enable] = 1"; } else { sql = @"select a.[ID],a.[AddTime] ,a.[Icon],a.[Order],a.[ParentID],a.[PermissionID],a.[TextCH] ,a.[TextEN],a.[Href] from MallSite_Menu a left join MallSite_Permission b on a.PermissionID = b.PermissionID left join MallSite_RolePermissions c on c.PermissionCode = b.Code left join MallSite_Roles d on c.RoleCode = d.Code where d.RoleID in (select[RoleID] from MallSite_UserRoles where UserID = " + ID + ") and a.[Enable] = 1"; } if (TextEN != null && TextEN.Count > 0) { sql += "and a.[TextEN] not in ("; foreach (var item in TextEN) { sql += "'" + item + "',"; } sql += "'')"; } return(await dbContext.MenuViewModel.FromSql(sql).AsNoTracking().OrderBy(o => o.ParentID).ThenBy(t => t.Order).ToListAsync()); }
public async Task <IActionResult> GetMenuInfo([FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); try { var uol = Method.GetLoginUserName(dbContext, this.HttpContext); List <MenuViewModel> menus; if (uol == null || string.IsNullOrEmpty(uol.UserCode)) { _Result.Code = "401"; _Result.Msg = "请先登录"; _Result.Data = ""; return(Json(_Result)); } ArrayList notExixtsTextEn = new ArrayList(); bool isOpenChat = false; var fun = await dbContext.FuncInfo.Where(i => i.Name == "品牌发布端").FirstOrDefaultAsync(); if (fun != null) { var mall = await dbContext.MallFunc.Where(i => i.MallCode == uol.MallCode && i.FuncCode == fun.Code).FirstOrDefaultAsync(); if (mall != null) { isOpenChat = true; } } if (!isOpenChat) { notExixtsTextEn = WebChatMenu; } if (uol.SystemModule == "Manage") { menus = await GetUserMenu(dbContext, 0, notExixtsTextEn); } else { menus = await GetUserMenu(dbContext, uol.ID, notExixtsTextEn); } _Result.Code = "200"; _Result.Msg = "获取成功"; _Result.Data = menus; return(Json(_Result)); } catch (Exception e) { _Result.Code = "500"; _Result.Msg = "Erro: " + e.ToString(); _Result.Data = ""; return(Json(_Result)); } }
/// <summary> /// 创建一个用户 /// </summary> /// <param name="dbContext"></param> /// <param name="_Account"></param> /// <returns></returns> public async static Task <int> CreateAccount(ContextString dbContext, Account _Account) { dbContext.Account.Add(_Account); await dbContext.SaveChangesAsync(); return(_Account.ID); }
public IActionResult GetLocalIP([FromServices] ContextString dbContext) { try { var SecretId = HttpContext.Request.Headers["SecretId"].FirstOrDefault(); var user = dbContext.Account.Where(i => i.LoginSession == SecretId).FirstOrDefault(); int _ID = user.ID; string HostName = Dns.GetHostName(); //得到主机名 IPHostEntry IpEntry = Dns.GetHostEntry(HostName); string ip = ""; for (int i = 0; i < IpEntry.AddressList.Length; i++) { //从IP地址列表中筛选出IPv4类型的IP地址 //AddressFamily.InterNetwork表示此IP为IPv4, //AddressFamily.InterNetworkV6表示此地址为IPv6类型 if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork) { ip = ip + " | " + IpEntry.AddressList[i].ToString(); } } return(Json("ID:" + _ID + " IP:" + ip)); } catch (Exception ex) { return(Json("获取本机IP出错:" + ex.Message));; } }
private void ParseProcedureBody(DataTable parametersTable, string body, DataRow row, string nameToRestrict) { string sqlMode = row["SQL_MODE"].ToString(); bool ansiQuotes = sqlMode.IndexOf("ANSI_QUOTES") != -1; bool noBackslash = sqlMode.IndexOf("NO_BACKSLASH_ESCAPES") != -1; string quotePattern = ansiQuotes ? "``\"\"" : "``"; ContextString cs = new ContextString(quotePattern, !noBackslash); int leftParen = cs.IndexOf(body, '('); Debug.Assert(leftParen != -1); // trim off the first part body = body.Substring(leftParen + 1); int rightParen = FindRightParen(body, quotePattern); Debug.Assert(rightParen != -1); string parms = body.Substring(0, rightParen).Trim(); quotePattern += "()"; cs.ContextMarkers = quotePattern; string[] paramDefs = cs.Split(parms, ","); ArrayList parmArray = new ArrayList(paramDefs); body = body.Substring(rightParen + 1).Trim().ToLower(CultureInfo.InvariantCulture); if (body.StartsWith("returns")) { parmArray.Add(body); } int pos = 1; foreach (string def in parmArray) { DataRow parmRow = parametersTable.NewRow(); parmRow["ROUTINE_CATALOG"] = null; parmRow["ROUTINE_SCHEMA"] = row["ROUTINE_SCHEMA"]; parmRow["ROUTINE_NAME"] = row["ROUTINE_NAME"]; parmRow["ROUTINE_TYPE"] = row["ROUTINE_TYPE"]; ParseParameter(def, cs, sqlMode, parmRow); if (parmRow["IS_RESULT"].Equals("YES")) { parmRow["ORDINAL_POSITION"] = 0; } else { parmRow["ORDINAL_POSITION"] = pos++; } if (nameToRestrict == null || parmRow["PARAMETER_NAME"].ToString().ToLower() == nameToRestrict) { parametersTable.Rows.Add(parmRow); } } }
public static bool CreateServerToIOT() { DbContextOptions <ContextString> options = new DbContextOptions <ContextString>(); ContextString dbContext = new ContextString(options); QianMuResult _Result = new QianMuResult(); var serveriot = dbContext.ServerIOT.FirstOrDefault(); if (serveriot == null) { var servermac = Method.GetServerMac().Replace(":", ""); //调用云端接口创建设备 var url = Method.MallSite + "API/IOT/AddFrontServer"; var data = new { ServerMac = servermac, MallCode = Method.CusID }; try { _Result = Method.PostMothsToObj(url, JsonHelper.SerializeJSON(data)); if (_Result.Code == "200") { IOTReturn _IOTReturn = new IOTReturn(); _IOTReturn = (IOTReturn)Newtonsoft.Json.JsonConvert.DeserializeObject(_Result.Data.ToString(), _IOTReturn.GetType()); dbContext.ServerIOT.Add(new Models.ServerIOT { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Key = _IOTReturn.Key, Name = _IOTReturn.UserName, ServerMac = servermac, UpdateTime = DateTime.Now }); } if (dbContext.SaveChanges() >= 0) { return(true); } else { return(false); } } catch (Exception) { return(false); } } else { return(true); } }
public IActionResult GetMallByRegKey([FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); _Result.Code = "200"; _Result.Msg = ""; _Result.Data = Method.CusID; return(Json(_Result)); }
/// <summary> /// 获取建筑信息 /// </summary> /// <param name="ConstructionInfo"></param> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> GetConstList(string code, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); ////检测用户登录情况 //string username = Method.GetLoginUserName(dbContext, this.HttpContext); //if (string.IsNullOrEmpty(username)) //{ // _Result.Code = "401"; // _Result.Msg = "请登陆后再进行操作"; // _Result.Data = ""; // return Json(_Result); //} var buildings = await dbContext.Building.Where(i => !i.IsDel).AsNoTracking().ToListAsync(); if (!string.IsNullOrEmpty(code)) { buildings = buildings.Where(i => i.Code == code).ToList(); } ArrayList Buildings = new ArrayList(); foreach (var b in buildings) { var floors = await dbContext.Floor.Where(i => i.BuildingCode == b.Code && !i.IsDel).OrderBy(o => o.Order).AsNoTracking().ToListAsync(); ArrayList arrlist = new ArrayList(); foreach (var f in floors) { string Map = string.Empty; var mapfile = await dbContext.AssetFiles.Where(i => i.Code == f.Map).FirstOrDefaultAsync(); if (mapfile != null) { Map = mapfile.FilePath; } arrlist.Add(new { f.ID, f.Code, f.Name, f.NameEn, Map = Map, f.Order, f.AddTime }); } Buildings.Add(new { b.ID, b.Code, b.Name, b.NameEn, Order = b.Order, b.AddTime, Floors = arrlist }); } _Result.Code = "200"; _Result.Msg = "获取成功"; _Result.Data = Buildings; //var ip = Method.GetUserIp(this.HttpContext); //dbContext.SysLog.Add(new SysLog { AccountName = username, ModuleName = "建筑模块", LogMsg = username + "获取建筑信息", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "查询", IP = ip }); //dbContext.SaveChanges(); return(Json(_Result)); }
/// <summary> /// 获取店铺用户列表 /// </summary> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> GetStoreList([FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); var list = await dbContext.Mall.ToListAsync(); _Result.Code = "200"; _Result.Msg = "获取成功"; _Result.Data = list; return(Json(_Result)); }
/// <summary> /// 判断服务器是否有此用户 /// </summary> /// <param name="dbContext">数据库连接</param> /// <param name="_AccountName">用户名</param> /// <returns></returns> public static bool FindAllByName(ContextString dbContext, string _AccountName) { bool _R = false; if (dbContext.Account.Where(i => i.AccountName == _AccountName && i.Activity).Count() > 0) { _R = true; } return(_R); }
/// <summary> /// 获取信息 /// </summary> /// <param name="type"></param> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> GetInfo(Input_GetLiveInfo model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_GetLiveInfo)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (string.IsNullOrEmpty(model.Code)) { _Result.Code = "510"; _Result.Msg = "请输入编码"; _Result.Data = ""; return(Json(_Result)); } var live = await dbContext.Live.Where(i => !i.IsDel && i.Code == model.Code).Join(dbContext.ScreenInfo, l => l.ScreenCode, scr => scr.Code, (l, scr) => new { l.AddTime, l.BeingUsed, l.Code, l.ID, l.IsDel, l.Name, l.ScreenCode, l.UpdateTime, l.Url, Screen = scr.SName }).AsNoTracking().FirstOrDefaultAsync(); if (live == null) { _Result.Code = "510"; _Result.Msg = "无效的直播编码"; _Result.Data = ""; } else { _Result.Code = "200"; _Result.Msg = "获取成功"; _Result.Data = live; } return(Json(_Result)); }
/// <summary> /// 获取消息 /// </summary> /// <param name="model"></param> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> GetAuditInfo(string NewsCode, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); var news = await dbContext.StoreNews.Where(i => i.Code == NewsCode).Join(dbContext.Shops, sn => sn.ShopCode, s => s.Code, (sn, s) => new { sn.AddTime, sn.AduitStatus, sn.Code, sn.ID, sn.MgrCode, sn.News, sn.PlacingNum, sn.Reason, sn.ShopCode, sn.UpdateTime, sn.ValidityPeriod, s.Name, s.HouseNum }).FirstOrDefaultAsync(); var Imgs = await dbContext.NewsImg.Where(i => i.NewsCode == news.Code).Join(dbContext.AssetFiles, ni => ni.Img, af => af.Code, (ni, af) => new { //FilePath = Method.ServerAddr +"/MallSite/"+ af.FilePath, FilePath = Method.OSSServer + af.FilePath, af.Code, ni.IsSuspicious, af.Duration, af.FileSize, af.Height, af.Width }).ToListAsync(); _Result.Code = "200"; _Result.Msg = "获取成功"; var curDate = DateTime.Now; _Result.Data = new { news.AddTime, news.AduitStatus, news.Code, news.ID, news.News, news.ShopCode, news.UpdateTime, news.PlacingNum, news.Reason, news.HouseNum, news.Name, ValidityPeriod = news.ValidityPeriod.ToString("yyyy-MM-dd HH:mm"), Imgs, DateState = news.ValidityPeriod.AddDays(1) > curDate ? 5 : 7 }; return(Json(_Result)); }
/// <summary> /// 获取时间轴--时间段数据 /// </summary> /// <param name="mallCode">商场编码</param> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> GetInfo(string mallCode, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); if (string.IsNullOrEmpty(mallCode)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { mallCode = uol.MallCode; } } if (String.IsNullOrEmpty(mallCode)) { _Result.Code = "510"; _Result.Msg = "请输入店铺编码"; _Result.Data = ""; return(Json(_Result)); } var timeAxis = await dbContext.TimeAxis.Where(i => i.MallCode == mallCode).FirstOrDefaultAsync(); if (timeAxis != null) { var timeRelate = await dbContext.TimeRelate.Where(i => i.TimeAxisCode == timeAxis.Code).Join(dbContext.TimeSlot, tr => tr.TimeSlotCode, ts => ts.Code, (tr, ts) => new { tr.TimeAxisCode, TimeRelateCode = tr.Code, ts.BeginTimeSlot, ts.EndTimeSlot, tr.OpenTime, tr.TimeSlotCode, ts.ID }).OrderBy(i => i.BeginTimeSlot).ToListAsync(); _Result.Data = new { TimeAxis = timeAxis, TimeRelateList = timeRelate }; } else { _Result.Data = null; } _Result.Code = "200"; _Result.Msg = "获取成功"; return(Json(_Result)); }
/// <summary> /// 获取用户信息 /// </summary> /// <param name="ID"></param> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> GetUserInfo(int?ID, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); if (ID == null) { _Result.Code = "510"; _Result.Msg = "请输入一个ID"; _Result.Data = ""; return(Json(_Result)); } var count = await dbContext.Account.Where(i => i.Activity == true && i.ID == ID).CountAsync(); if (count <= 0) { _Result.Code = "510"; _Result.Msg = "无效的用户ID"; _Result.Data = ""; return(Json(_Result)); } var user = await dbContext.Account.Where(i => i.Activity == true && i.ID == ID).Join(dbContext.UserRoles, ac => ac.Code, ur => ur.UserCode, (ac, ur) => new { ac.ID, ac.AccountName, ac.NickName, ur.RoleCode, ac.AddTime, ac.Phone, ac.Email, ac.Code }).Join(dbContext.Roles, ac => ac.RoleCode, ro => ro.Code, (ac, ro) => new { ac.ID, ac.AccountName, ac.NickName, ac.RoleCode, RoleName = ro.Name, ac.Phone, ac.Email, ac.AddTime, ac.Code }).FirstOrDefaultAsync(); _Result.Code = "200"; _Result.Msg = "获取成功"; _Result.Data = user; return(Json(_Result)); }
/// <summary> /// 获取业态列表 /// </summary> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> GetShopFormatList(string mallCode, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); if (string.IsNullOrEmpty(mallCode)) { ////检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { mallCode = uol.MallCode; } } var sfs = await dbContext.ShopFormat.Where(i => i.ParentCode == string.Empty && i.MallCode == mallCode && !i.IsDel).OrderBy(o => o.AddTime).AsNoTracking().ToListAsync(); ArrayList list = new ArrayList(); foreach (var sf in sfs) { var count = await dbContext.ShopFormat.Where(i => i.ParentCode == sf.Code && !i.IsDel).CountAsync(); var iconFile = await dbContext.AssetFiles.Where(i => i.Code == sf.IconFile).FirstOrDefaultAsync(); string IconFilePath = ""; if (iconFile != null) { //IconFilePath = Method.ServerAddr + "/MallSite/" + iconFile.FilePath; IconFilePath = Method.OSSServer + iconFile.FilePath; } list.Add(new { sf.ID, sf.Name, sf.NameEn, ChildCount = count, sf.AddTime, sf.Color, IconFilePath, sf.Code }); } _Result.Code = "200"; _Result.Msg = "获取成功"; _Result.Data = list; //var ip = Method.GetUserIp(this.HttpContext); //dbContext.SysLog.Add(new SysLog { AccountName = username, ModuleName = "商铺模块", LogMsg = username + "获取业态列表", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "查询", IP = ip }); //dbContext.SaveChanges(); return(Json(_Result)); }
/* Function: CommonInit * Common initialization done from all the constructors. */ private void CommonInit() { isRootElement = false; maximumEffectiveChildAccessLevel = AccessLevel.Unknown; defaultDeclaredChildAccessLevel = AccessLevel.Unknown; defaultChildLanguageID = 0; defaultChildClassString = new ClassString(); defaultChildClassStringSet = false; childContextString = new ContextString(); childContextStringSet = false; endingPosition = new Position(-1, -1); }
public static void SendNoticeByProgram(ProgramOrder program, ContextString dbContext) { string remarks = program.Status == 2 ? "您的图片素材已通过审核,快去发布吧!" : "您的图片素材未通过审核,请查验后再次上传。"; var account = dbContext.ShopAccount.Where(i => i.ShopCode == program.ShopCode).FirstOrDefault(); if (account == null) { return; } var openID = account.UnionID; var data = "{\"keyword1\": {\"value\": \"" + program.PlacingNum + "\"},\"keyword2\": {\"value\": \"" + program.AddTime.ToString("yyyy年MM月dd日 HH:mm") + "\"},\"keyword3\": {\"value\": \"" + (program.Status == 2 ? "已通过" : "已拒绝") + "\"" + (program.Status == 2 ? "" : ",\"color\": \"#f00\"") + "} ,\"keyword4\": {\"value\": \"" + remarks + "\"}}"; SendWeChatNotice(openID, program.FormID, data); }
/// <summary> /// 获取角色列表 /// </summary> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> GetList([FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); var q = await dbContext.Roles.AsNoTracking().ToArrayAsync(); _Result.Code = "200"; _Result.Msg = "获取成功"; _Result.Data = q; return(Json(_Result)); }
public static void SendNoticeBySchedule(ScheduleOrder schedule, ContextString dbContext) { string remarks = schedule.Status == 2 ? "您的排期已申请通过,快去添加节目吧!" : "您的排期未能通过申请,请查看拒绝理由。"; var account = dbContext.ShopAccount.Where(i => i.ShopCode == schedule.ShopCode).FirstOrDefault(); if (account == null) { return; } var openID = account.UnionID; var data = "{\"keyword1\": {\"value\": \"" + schedule.PlacingNum + "\"},\"keyword2\": {\"value\": \"" + schedule.AddTime.ToString("yyyy年MM月dd日 HH:mm") + "\"},\"keyword3\": {\"value\": \"" + (schedule.Status == 2 ? "已通过" : "已拒绝") + "\"" + (schedule.Status == 2 ? "" : ",\"color\": \"#f00\"") + "} ,\"keyword4\": {\"value\": \"" + remarks + "\"}}"; SendWeChatNotice(openID, schedule.FormID, data); }
/// <summary> /// 获取所有节目 /// </summary> /// <param name="dbContext"></param> /// <returns></returns> private async Task <QianMuResult> GetEffectiveAllProgramList(string OrderBy, ContextString dbContext) { QianMuResult _Result = new QianMuResult(); try { var list = await dbContext.Programs.Where(i => i.LaunchTime <= DateTime.Now && i.ExpiryDate >= DateTime.Now).Join(dbContext.ScreenInfo, pr => pr.ProgScreenInfo, si => si.Code, (pr, si) => new { ID = pr.ID, pr.Code, PreviewSrc = pr.PreviewSrc == "" ? "" : Method.OSSServer + pr.PreviewSrc, ProgramName = pr.ProgramName, ProgType = pr.ProgType, ProgScreenInfo = si.SName, ScreenCode = si.Code, LaunchTime = pr.LaunchTime.ToString("yyyy-MM-dd "), ExpiryDate = pr.ExpiryDate.ToString("yyyy-MM-dd "), SwitchMode = pr.SwitchMode, SwitchTime = pr.SwitchTime, ScreenMatch = pr.ScreenMatch, AddTime = pr.AddTime }).ToListAsync(); if (!string.IsNullOrEmpty(OrderBy)) { if (OrderBy.ToLower() == "timeasc") { list = list.OrderBy(o => o.AddTime).ToList(); } if (OrderBy.ToLower() == "timedesc") { list = list.OrderByDescending(o => o.AddTime).ToList(); } } _Result.Code = "200"; _Result.Msg = "获取成功"; _Result.Data = list; } catch (Exception e) { _Result.Code = "500"; _Result.Msg = "Erro:" + e.ToString(); _Result.Data = ""; } return(_Result); }
/// <summary> /// 更新服务器状态 /// </summary> public static void UpdateDevState() { DateTime dt = DateTime.Now; try { QMLog qm = new QMLog(); qm.WriteLogToFile("", "Hangfire定时器执行"); DbContextOptions <ContextString> options = new DbContextOptions <ContextString>(); ContextString dbContext = new ContextString(options); var list = dbContext.Device.ToList(); foreach (var dev in list) { var de = Method.DeviceCommandList.Where(i => i.Code == dev.Code).FirstOrDefault(); if (de == null) { dev.DeviceOnline = false; dev.FrontOnline = false; } else { if (de.DevBreathTime >= dt.AddMinutes(-1)) { dev.DeviceOnline = true; } else { dev.DeviceOnline = false; } if (de.AppBreathTime >= dt.AddMinutes(-1)) { dev.FrontOnline = true; } else { dev.FrontOnline = false; } } } dbContext.Device.UpdateRange(list); dbContext.SaveChanges(); } catch (Exception e) { QMLog qm = new QMLog(); qm.WriteLogToFile("", e.ToString()); } }
public async static Task <bool> ServerSubIOT() { DbContextOptions <ContextString> options = new DbContextOptions <ContextString>(); ContextString dbContext = new ContextString(options); var serveriot = dbContext.ServerIOT.FirstOrDefault(); ServerMqttClient mqttClient = new ServerMqttClient(Method.BaiduIOT, 1883, serveriot.ServerMac, serveriot.Name, serveriot.Key); mqttClient.InitAsync(); mqttClient.Sub(); var isStop = false; if (serveriot != null) { Thread thread = new Thread(new ThreadStart(() => { while (!isStop) { Thread.Sleep(120000); try { var jsonstr = "{\"reported\": " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "}"; //await mqttClient.PublishAsync(serveriot.ServerMac, jsonstr); mqttClient.PublishAsync(serveriot.ServerMac, jsonstr); } catch (Exception ex) { QMLog qMLog = new QMLog(); qMLog.WriteLogToFile("", ex.ToString()); } finally { Thread.Sleep(10000); } } })); thread.IsBackground = true; thread.Start(); } return(true); }
public static string GetCusID(ContextString dbContext, string regkey) { var prj = dbContext.ProjectInfo.Where(i => i.RegKey == regkey).FirstOrDefault(); if (prj == null) { var url = Method.MallSite + "API/CDN/GetCusID"; QianMuResult qianMuResult = new QianMuResult(); var param = new { RegKey = regkey }; try { qianMuResult = Method.PostMothsToObj(url, JsonHelper.SerializeJSON(param)); if (qianMuResult.Code == "200") { dbContext.ProjectInfo.Add(new ProjectInfo { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), CusID = qianMuResult.Data.ToString(), RegKey = regkey, UpdateTime = DateTime.Now }); if (dbContext.SaveChanges() > 0) { return(qianMuResult.Data.ToString()); } else { return(string.Empty); } } else { return(string.Empty); } } catch (Exception) { return(string.Empty); } } else { return(prj.CusID); } }
private void ParseParameter(string parmDef, ContextString cs, string sqlMode, DataRow parmRow) { parmDef = parmDef.Trim(); string lowerDef = parmDef.ToLower(CultureInfo.InvariantCulture); parmRow["IS_RESULT"] = "NO"; parmRow["PARAMETER_MODE"] = "IN"; if (lowerDef.StartsWith("inout ")) { parmRow["PARAMETER_MODE"] = "INOUT"; parmDef = parmDef.Substring(6); } else if (lowerDef.StartsWith("out ")) { parmRow["PARAMETER_MODE"] = "OUT"; parmDef = parmDef.Substring(4); } else if (lowerDef.StartsWith("returns ")) { parmRow["PARAMETER_MODE"] = "OUT"; parmRow["IS_RESULT"] = "YES"; parmDef = parmDef.Substring(8); } else if (lowerDef.StartsWith("in ")) { parmDef = parmDef.Substring(3); } parmDef = parmDef.Trim(); string[] split = cs.Split(parmDef, " \t\r\n"); if (parmRow["IS_RESULT"].Equals("NO")) { parmRow["PARAMETER_NAME"] = String.Format("{0}{1}", connection.ParameterMarker, CleanParameterName(split[0])); parmDef = parmDef.Substring(split[0].Length); } else { lowerDef = parmDef.ToLower(CultureInfo.InvariantCulture); parmDef = parmDef.Substring(0, lowerDef.IndexOf("begin")); parmRow["PARAMETER_NAME"] = String.Format("{0}RETURN_VALUE", connection.ParameterMarker); } ParseType(parmDef, sqlMode, parmRow); }