Ejemplo n.º 1
0
        public async Task <ActionResult> _ViewMonitor()
        {
            var config = await YummyOnlineManager.GetSystemConfig();

            ViewBag.WebSocketLocation = $"ws://{config.TcpServerIp}:{config.WebSocketPort}";
            return(View());
        }
Ejemplo n.º 2
0
 public async Task <JsonResult> GetCustomers(int countPerPage, int currPage)
 {
     return(Json(new {
         Users = await YummyOnlineManager.GetUsers(Role.Customer, countPerPage, currPage, true),
         Count = await YummyOnlineManager.GetUserCount(Role.Customer)
     }));
 }
Ejemplo n.º 3
0
        public async Task <JsonResult> MergePartition(int?hotelId, DateTime dateTime)
        {
            FunctionResult result;

            if (hotelId.HasValue)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                result = await new OriginSql(hotel.AdminConnectionString).Merge(dateTime);
            }
            else
            {
                result = await new OriginSql(YummyOnlineManager.ConnectionString).Merge(dateTime);
            }

            if (!result.Succeeded)
            {
                await logPartition(hotelId, nameof(MergePartition), result.Message);

                return(Json(new JsonError(result.Message)));
            }
            await logPartition(hotelId, nameof(MergePartition));

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 4
0
        public async Task <JsonResult> GetDbPartitionDetailByHotelId(int?hotelId)
        {
            Hotel     hotel;
            OriginSql dbPartition;

            if (hotelId.HasValue)
            {
                hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                dbPartition = new OriginSql(hotel.AdminConnectionString);
            }
            else
            {
                hotel       = null;
                dbPartition = new OriginSql(YummyOnlineManager.ConnectionString);
            }

            return(Json(new {
                Hotel = hotel == null ? null : new {
                    hotel.Id,
                    hotel.Name
                },
                DbPartitionInfos = await dbPartition.GetDbPartitionInfos(),
                FileGroupInfos = await dbPartition.GetFileGroupInfos()
            }));
        }
Ejemplo n.º 5
0
        public async Task <JsonResult> GetDbPartitionDetails()
        {
            var hotels = await YummyOnlineManager.GetHotels();

            List <dynamic> partitionDetails = new List <dynamic>();

            partitionDetails.Add(new {
                DbPartitionInfos = await new OriginSql(YummyOnlineManager.ConnectionString).GetDbPartitionInfos()
            });

            foreach (Hotel h in hotels)
            {
                if (h.ConnectionString == null)
                {
                    continue;
                }
                partitionDetails.Add(new {
                    Hotel = new {
                        h.Id,
                        h.Name
                    },
                    DbPartitionInfos = await new OriginSql(h.AdminConnectionString).GetDbPartitionInfos()
                });
            }

            return(Json(partitionDetails));
        }
Ejemplo n.º 6
0
        public async Task <JsonResult> ExecuteSql(List <int> hotelIds, string sql)
        {
            StringBuilder sb = new StringBuilder();

            foreach (int id in hotelIds)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(id);

                OriginSql      originSql = new OriginSql(hotel.AdminConnectionString);
                FunctionResult result    = await originSql.ExecuteSql(sql);

                if (!result.Succeeded)
                {
                    sb.Append($"{hotel.Name}({hotel.Id}) Error, {result.Message}</br>");
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"Execute SQL {hotel.Name}({hotel.Id}) Failed",
                                                       $"Error: {result.Message}, SQL: {sql}");
                }
                else
                {
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"Execute SQL {hotel.Name}({hotel.Id}) Successfully", sql);
                }
            }
            if (sb.Length != 0)
            {
                return(Json(new JsonError(sb.ToString())));
            }
            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 7
0
        public async Task <JsonResult> GetDineForPrinting(int hotelId, string dineId, List <int> dineMenuIds)
        {
            string connStr = await YummyOnlineManager.GetHotelConnectionStringById(hotelId);

            var tHotel = new YummyOnlineManager().GetHotelForPrintingById(hotelId);

            Task <Dine> tDine = null;

            if (dineId == "00000000000000")
            {
                tDine = generateTestDine();
            }
            else
            {
                tDine = new HotelManager(connStr).GetDineForPrintingById(dineId, dineMenuIds);
            }

            var tPrinterFormat = new HotelManager(connStr).GetPrinterFormatForPrinting();
            var tUser          = new YummyOnlineManager().GetUserForPrintingById((await tDine).UserId);

            return(Json(new DineForPrinting {
                Hotel = await tHotel,
                Dine = await tDine,
                User = await tUser,
                PrinterFormat = await tPrinterFormat
            }));
        }
Ejemplo n.º 8
0
        public async Task <JsonResult> GetDineDailyCount()
        {
            List <dynamic> list   = new List <dynamic>();
            List <Hotel>   hotels = await YummyOnlineManager.GetHotels();

            foreach (Hotel h in hotels)
            {
                if (h.ConnectionString == null)
                {
                    continue;
                }
                List <dynamic> dailyCount   = new List <dynamic>();
                HotelManager   hotelManager = new HotelManager(h.ConnectionString);
                for (int i = -30; i <= 0; i++)
                {
                    DateTime t     = DateTime.Now.AddDays(i);
                    int      count = await hotelManager.GetDineCount(t);

                    dailyCount.Add(new {
                        DateTime = t,
                        Count    = count
                    });
                }

                list.Add(new {
                    HotelName  = h.Name,
                    DailyCount = dailyCount
                });
            }

            return(Json(list));
        }
Ejemplo n.º 9
0
        // GET: 店小二点菜系统入口 Home/Index/[hotelId]/[qrCode]
        public async Task <ActionResult> Index(int?hotelId, string qrCode)
        {
            if (hotelId == null || qrCode == null)
            {
                if (CurrHotel != null && Session["CurrentDesk"] != null)
                {
                    return(View());
                }
                return(RedirectToAction("HotelMissing", "Error"));
            }

            Hotel hotel = await YummyOnlineManager.GetHotelById(Convert.ToInt32(hotelId));

            if (hotel == null)
            {
                return(RedirectToAction("HotelMissing", "Error"));
            }
            if (!hotel.Usable)
            {
                return(RedirectToAction("HotelUnavailable", "Error"));
            }

            CurrHotel = new CurrHotelInfo(hotel.Id, hotel.ConnectionString);

            Desk desk = await new HotelManager(hotel.ConnectionString).GetDeskByQrCode(qrCode);

            if (desk == null)
            {
                return(RedirectToAction("HotelMissing", "Error"));
            }

            Session["CurrentDesk"] = desk;
            return(View());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 生成短信验证码并且发送
        /// </summary>
        /// <param name="phoneNumber">手机号</param>
        /// <returns>短信验证码</returns>
        private FunctionResult generateSmsCodeAndSend(string phoneNumber)
        {
            DateTime?LastSmsDateTime = Session["LastSmsDateTime"] as DateTime?;

            if (LastSmsDateTime.HasValue && (DateTime.Now - LastSmsDateTime.Value).TotalSeconds < 50)
            {
                return(new FunctionResult(false, "您还不能发送短信验证码"));
            }

            Random rand = new Random(unchecked ((int)DateTime.Now.Ticks));
            string code = "";

            for (int i = 0; i < 6; i++)
            {
                code += rand.Next(10);
            }
            Session["LastSmsDateTime"] = DateTime.Now;

#if DEBUG
            var _ = YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Debug, phoneNumber + " : " + code);
#else
            if (!Utility.SMSSender.Send(phoneNumber, code))
            {
                return(new FunctionResult(false, "发送失败"));
            }
#endif
            return(new FunctionResult {
                Succeeded = true,
                Data = code
            });
        }
Ejemplo n.º 11
0
        public async Task <JsonResult> CreateHotel(int hotelId, string databaseName)
        {
            // 创建空数据库
            OriginSql originSql = new OriginSql(new YummyOnlineContext().Database.Connection.ConnectionString);
            var       result    = await originSql.CreateDatabase(databaseName);

            if (!result.Succeeded)
            {
                return(Json(new JsonError(result.Message)));
            }
            // 总数据库记录连接字符串等信息
            await YummyOnlineManager.CreateHotel(hotelId, databaseName);

            // 新数据库写入所有表格等架构
            Hotel newHotel = await YummyOnlineManager.GetHotelById(hotelId);

            originSql = new OriginSql(newHotel.AdminConnectionString);
            result    = await originSql.InitializeHotel();

            if (!result.Succeeded)
            {
                return(Json(new JsonError(result.Message)));
            }

            // 新数据库初始化
            string staffId = await YummyOnlineManager.GetHotelAdminId(hotelId);

            HotelManager hotelManager = new HotelManager(newHotel.AdminConnectionString);
            await hotelManager.InitializeHotel(hotelId, staffId);

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> _ViewSpecification()
        {
            SystemConfig config = await YummyOnlineManager.GetSystemConfig();

            Dictionary <string, List <FileInfo> > dirFiles = new Dictionary <string, List <FileInfo> >();

            string[] dirs = Directory.GetDirectories(config.SpecificationDir);

            foreach (string dir in dirs)
            {
                string[] files = Directory.GetFiles(dir);

                string dirStr = dir.Split('\\').Last();
                dirFiles.Add(dirStr, new List <FileInfo>());

                foreach (string file in files)
                {
                    dirFiles[dirStr].Add(new FileInfo(file));
                }
            }

            ViewBag.DirFiles = dirFiles;

            return(View());
        }
Ejemplo n.º 13
0
        public async Task Initialize()
        {
            YummyOnlineManager manager = new YummyOnlineManager();

            waitingForVerificationClients = new WaitingForVerificationClients(log, send);
            systemClient         = new SystemClient(log, send, GetTcpServerStatus);
            newDineInformClients = new NewDineInformClients(log, send, await manager.GetGuids());
            printerClients       = new PrinterClients(log, send, await manager.GetHotels());

            log($"Binding {ip}:{port}", Log.LogLevel.Info);

            tcp.StartListening(IPAddress.Parse(ip), port, client => {
                TcpClientInfo clientInfo = new TcpClientInfo(client);
                waitingForVerificationClients.Add(clientInfo);

                log($"{clientInfo.OriginalRemotePoint} Connected, Waiting for verification", Log.LogLevel.Info);
            });

            System.Timers.Timer timer = new System.Timers.Timer(10 * 1000);
            timer.Elapsed += (e, o) => {
                // 30秒之内已连接但是未发送身份信息的socket断开
                waitingForVerificationClients.HandleTimeOut();

                //60秒之内没有接收到心跳包的socket断开, 或发送心跳包失败的socket断开
                systemClient.HandleTimeOut();
                newDineInformClients.HandleTimeOut();
                printerClients.HandleTimeOut();
            };
            timer.Start();
        }
Ejemplo n.º 14
0
        public async Task <JsonResult> UpdateHotel(Hotel hotel)
        {
            await YummyOnlineManager.UpdateHotel(hotel);

            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, $"Hotel {hotel.Id} Updated");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 15
0
        public ActionResult Index()
        {
            YummyOnlineManager manager = new YummyOnlineManager();
            var ids = manager.GetHotelIds();


            return(Json(ids, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 16
0
        public async Task <JsonResult> GetAllDineIds(int hotelId, DateTime?dateTime)
        {
            dateTime = dateTime ?? DateTime.Now;

            string connStr = await YummyOnlineManager.GetHotelConnectionStringById(hotelId);

            return(Json(await new HotelManager(connStr).GetAllDineIds(dateTime.Value)));
        }
Ejemplo n.º 17
0
        public async Task <JsonResult> DeleteAdmin(string id)
        {
            await UserManager.RemoveFromRoleAsync(id, Role.Admin);

            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, $"User {id} Removed from Admin");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 18
0
        public async Task <JsonResult> GetHotelNames()
        {
            List <Hotel> hotels = await YummyOnlineManager.GetHotels();

            return(Json(hotels.Select(p => new {
                p.Id,
                p.Name,
            })));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 收银员台支付
        /// </summary>
        public async Task <ActionResult> ManagerPay(Cart cart, ManagerCartAddition cartAddition)
        {
            SystemConfig system = await YummyOnlineManager.GetSystemConfig();

            if (system.Token != cartAddition.Token)
            {
                return(Json(new JsonError("身份验证失败")));
            }

            var hotel = await YummyOnlineManager.GetHotelById(cartAddition.HotelId);

            CurrHotel = new CurrHotelInfo(hotel.Id, hotel.ConnectionString);

            if (!hotel.Usable)
            {
                return(RedirectToAction("HotelUnavailable", "Error"));
            }

            cart.PayKindId = await new HotelManager(CurrHotel.ConnectionString).GetOtherPayKindId();
            CartAddition addition = new CartAddition {
                WaiterId     = cartAddition.WaiterId,
                DineType     = cartAddition.DineType,
                Discount     = cartAddition.Discount,
                DiscountName = cartAddition.DiscountName,
                GiftMenus    = cartAddition.GiftMenus,
                From         = DineFrom.Manager
            };

            User user = await UserManager.FindByIdAsync(cartAddition.UserId);

            addition.UserId = user?.Id;

            // 创建新订单
            FunctionResult result = await OrderManager.CreateDine(cart, addition);

            if (!result.Succeeded)
            {
                if (await UserManager.IsInRoleAsync(user.Id, Role.Nemo))
                {
                    await UserManager.DeleteAsync(user);

                    await YummyOnlineManager.RecordLog(YummyOnlineDAO.Models.Log.LogProgram.Identity, YummyOnlineDAO.Models.Log.LogLevel.Warning, $"Anonymous User Deleted {user.Id}, Via Manager");
                }
                await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Error, $"{result.Detail}, Host:{Request.UserHostAddress}", HttpPost.GetPostData(Request));

                return(Json(new JsonError(result.Message)));
            }

            Dine dine = ((Dine)result.Data);

            await newDineInform(dine, "Manager");

            return(Json(new JsonSuccess {
                Data = dine.Id
            }));
        }
Ejemplo n.º 20
0
        public async Task <JsonResult> GetPrintersForPrinting(int hotelId)
        {
            string connStr = await YummyOnlineManager.GetHotelConnectionStringById(hotelId);

            var manager = new HotelManager(connStr);

            return(Json(new PrintersForPrinting {
                Printers = await manager.GetPrinters()
            }));
        }
Ejemplo n.º 21
0
        public async Task <JsonResult> StopSite(int siteId)
        {
            if (IISManager.StopSite(siteId))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, $"Site {IISManager.GetSiteById(siteId).Name} Stoped");

                return(Json(new JsonSuccess()));
            }
            return(Json(new JsonError("无法停止")));
        }
Ejemplo n.º 22
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (CurrHotel != null)
            {
                ViewBag.HotelId      = CurrHotel?.Id;
                ViewBag.CssThemePath = AsyncInline.Run(() => { return(YummyOnlineManager.GetHotelById(CurrHotel.Id)); }).CssThemePath;
            }

            base.OnActionExecuted(filterContext);
        }
Ejemplo n.º 23
0
        public virtual async Task <JsonResult> Signup(SignupViewModel model)
        {
            if ((string)Session["SmsCode"] != model.Code)
            {
                return(Json(new JsonError("验证码不正确", "code")));
            }
            if (model.PhoneNumber == null)
            {
                return(Json(new JsonError("手机号不能为空")));
            }
            if (model.Password == null)
            {
                return(Json(new JsonError("密码不能为空")));
            }
            if (model.Password == model.PasswordAga)
            {
                return(Json(new JsonError("密码不一致")));
            }
            User user;
            bool succeeded;

            if (await SigninManager.IsAuthenticated())
            {
                user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                user.PhoneNumber  = model.PhoneNumber;
                user.UserName     = model.PhoneNumber;
                user.PasswordHash = UserManager.GetMd5(model.Password);
                succeeded         = await UserManager.UpdateAsync(user);

                await UserManager.RemoveFromRoleAsync(user.Id, Role.Nemo);

                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Update: {User.Identity.GetUserId()}");
            }
            else
            {
                user = new User {
                    PhoneNumber = model.PhoneNumber,
                    UserName    = model.PhoneNumber
                };
                succeeded = await UserManager.CreateAsync(user, model.Password);
            }

            if (!succeeded)
            {
                return(Json(new JsonError("注册失败")));
            }
            await UserManager.AddToRoleAsync(user.Id, Role.Customer);

            SigninManager.Signin(user, true);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"User Signup: {user.Id} ({user.PhoneNumber})");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 24
0
        public async Task <JsonResult> DeleteGuid(Guid guid)
        {
            if (!await YummyOnlineManager.DeleteGuid(guid))
            {
                return(Json(new JsonError()));
            }
            SystemTcpClient.SendSystemCommand(SystemCommandType.RefreshNewDineClients);
            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, $"Guid {guid} Removed");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 25
0
        public virtual async Task <JsonResult> Forget(ForgetViewModel model)
        {
            if (Session["SMSForgetCode"] == null || Session["SMSForgetCode"].ToString() != model.Code)
            {
                return(Json(new JsonError("验证码不正确", "code")));
            }
            await UserManager.ChangePasswordAsync(model.PhoneNumber, model.Password);

            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"{model.PhoneNumber} {model.Password} Change Password");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 26
0
        public async Task <JsonResult> StopTcpServer()
        {
            bool result = TcpServerProcess.StopTcpServer();

            if (result)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, "TcpServer Stoped");

                return(Json(new JsonSuccess()));
            }
            return(Json(new JsonError("关闭失败")));
        }
Ejemplo n.º 27
0
        private async Task logPartition(int?hotelId, string method)
        {
            if (hotelId.HasValue)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"{method} On {hotel.Name} ({hotel.Id}) Successfully");
            }
            else
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"{method} On YummyOnlineDB Successfully");
            }
        }
Ejemplo n.º 28
0
        private async Task logPartition(int?hotelId, string method, string errorMessage)
        {
            if (hotelId.HasValue)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"{method} On {hotel.Name} ({hotel.Id}) Failed, {errorMessage}");
            }
            else
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"{method} On YummyOnlineDB Failed, {errorMessage}");
            }
        }
Ejemplo n.º 29
0
        public async Task <JsonResult> AddGuid(Guid guid, string description)
        {
            if (!await YummyOnlineManager.AddGuid(new NewDineInformClientGuid {
                Guid = guid,
                Description = description
            }))
            {
                return(Json(new JsonError()));
            }
            SystemTcpClient.SendSystemCommand(SystemCommandType.RefreshNewDineClients);
            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"Guid {guid} ({description}) Added");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 30
0
        protected void Application_Start()
        {
            var _ = new YummyOnlineManager().RecordLog(YummyOnlineDAO.Models.Log.LogProgram.OrderSystem_Waiter, YummyOnlineDAO.Models.Log.LogLevel.Info, "OrderSystem.Waiter Initializing");

            _ = NewDineInformTcpClient.Initialize(async() => {
                await new YummyOnlineManager().RecordLog(YummyOnlineDAO.Models.Log.LogProgram.OrderSystem_Waiter, YummyOnlineDAO.Models.Log.LogLevel.Success, "TcpServer Connected");
            }, async e => {
                await new YummyOnlineManager().RecordLog(YummyOnlineDAO.Models.Log.LogProgram.OrderSystem_Waiter, YummyOnlineDAO.Models.Log.LogLevel.Error, e.Message);
            });

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }