public static void RemoveGuest(GuestInfo guest) { var id = guest.Id; RemoveGuest(id); if (guest.ParentId != null) { var parent = GlobalConfigs.Guests.FirstOrDefault(x => x.Id == guest.ParentId); if (parent != null && !string.IsNullOrEmpty(parent.Entourage)) { var pEntourages = parent.Entourage.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < pEntourages.Length; i++) { if (pEntourages[i] == guest.Name) { pEntourages[i] = null; break; } } parent.Entourage = string.Join(",", pEntourages.Where(x => x != null)); var num = pEntourages.Count(x => x != null); parent.EntourageNum = num; } } GlobalConfigs.Guests.RemoveAll(x => x.ParentId == id || x.Id == id); GlobalConfigMgr.SaveGuests(); }
private void trackBarThreshold_LostFocus(object sender, EventArgs e) { if (GlobalConfigs.Configurations.Threshold != trackBarThreshold.Value && trackBarThreshold.Value > 0d) { GlobalConfigs.Configurations.Threshold = trackBarThreshold.Value; GlobalConfigMgr.SaveConfig(); } }
private void trackBarSpeed_ValueChanged(object sender, EventArgs e) { if (GlobalConfigs.Configurations.Speed != trackBarSpeed.Value && trackBarSpeed.Value > 0d) { GlobalConfigs.Configurations.Speed = trackBarSpeed.Value; guestViewer.SetAlphaAccel(GlobalConfigs.Configurations.Speed / 100F); GlobalConfigMgr.SaveConfig(); } }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); log4net.Config.XmlConfigurator.Configure(); try { GlobalConfigMgr.Load(); Application.Run(new MainForm()); } catch (Exception ex) { Logger.Error(ex.Message); MessageBox.Show("程序发生异常"); } }
private void Attend(GuestInfo target) { target.IsAttend = true; target.AttendTime = DateTime.Now; var children = GlobalConfigs.Guests.Where(x => x.ParentId == target.Id); if (children != null && children.Any()) { foreach (var child in children.ToList()) { child.IsAttend = true; child.AttendTime = DateTime.Now; } } GlobalConfigMgr.SaveGuests(); SetAttendance(GlobalConfigs.Guests.Count(x => x.IsAttend)); }
private void FixGuest() { if (GlobalConfigs.Guests.Any()) { foreach (var item in GlobalConfigs.Guests) { if (string.IsNullOrEmpty(item.FullName)) { item.FullName = item.Name; } if (item.Name.Contains("_")) { var index = item.Name.IndexOf('_'); var trueName = item.Name.Substring(index + 1); item.Name = trueName; } } GlobalConfigs.Guests = GlobalConfigs.Guests.OrderBy(x => x.TableNo, new TableComparer()).ThenBy(x => x.FullName).ToList(); GlobalConfigMgr.SaveGuests(); } }
public static bool UpdateGuestInfo(GuestInfo info) { try { var guest = GlobalConfigs.Guests.FirstOrDefault(x => x.Name == info.Name); var oldName = guest.Name; guest.Name = info.Name; guest.Gender = info.Gender; guest.GuestType = info.GuestType; guest.Labels = info.Labels; guest.TableNo = info.TableNo; guest.ImagePath = info.ImagePath; guest.CashGift = info.CashGift; guest.CreateTime = DateTime.Now; guest.IsAttend = info.IsAttend; guest.AttendTime = info.AttendTime; var entourages = info.Entourage.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); var entourageNum = entourages.Count(); if (guest.Entourage != info.Entourage) { GlobalConfigs.Guests.RemoveAll(x => x.ParentId == info.Id); guest.Entourage = info.Entourage; if (entourages != null) { foreach (var item in entourages) { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(), ParentId = info.Id, Name = $"{item}", FullName = $"{info.Name}_{item}", Gender = 0, GuestType = info.GuestType, Entourage = "", EntourageNum = 0, Labels = info.Labels, TableNo = info.TableNo, ImagePath = null, IsAttend = guest.IsAttend, AttendTime = guest.AttendTime, CreateTime = DateTime.Now, }); } } } #region 关联更新 var parent = GlobalConfigs.Guests.FirstOrDefault(x => x.Id == guest.ParentId); if (parent != null && !string.IsNullOrEmpty(parent.Entourage)) { var pEntourages = parent.Entourage.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < pEntourages.Length; i++) { if (pEntourages[i] == oldName) { pEntourages[i] = guest.Name; } } parent.Entourage = string.Join(",", pEntourages); guest.EntourageNum = pEntourages.Count(); guest.FullName = $"{parent.Name}_{guest.Name}"; } #endregion GlobalConfigMgr.SaveGuests(); return(true); } catch (Exception ex) { return(false); } }
public static bool SaveOrUpdateFace(GuestInfo info) { bool success = false; try { if (string.IsNullOrEmpty(info.Id)) { info.Id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } var guest = GlobalConfigs.Guests.FirstOrDefault(x => x.Id == info.Id); string imageFileName = null; if (!string.IsNullOrEmpty(info.ImagePath) && (info.ImagePath != guest?.ImagePath || guest == null)) { imageFileName = Path.Combine($"GuestImages\\{info.Id}.jpg"); var img = Bitmap.FromFile(info.ImagePath); var option = new FaceOption() { User_Info = $"姓名: {info.Name} \n身份: {info.Labels}\n桌号: {info.TableNo} ", }; var jObj = FaceApi.FaceSaveOrUpdate(new Bitmap(img), GlobalConfigs.Configurations.GroupId, guest != null ? guest.Id : info.Id, option); success = (jObj != null && jObj.error_code == 0); if (success) { var newImage = new Bitmap(img); img.Dispose(); if (File.Exists(imageFileName)) { File.Delete(imageFileName); } newImage.Save(imageFileName, ImageFormat.Jpeg); newImage.Dispose(); } } else { success = true; } if (success) { var entourageText = info.Entourage ?? ""; var entourages = entourageText.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); var entourageNum = entourages.Count(); if (guest == null)//新增 { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = info.Id, Name = info.Name, FullName = info.Name, Gender = info.Gender, GuestType = info.GuestType, Entourage = entourageText, EntourageNum = entourageNum, Labels = info.Labels, TableNo = info.TableNo, ImagePath = imageFileName, CashGift = info.CashGift, CreateTime = DateTime.Now, }); if (entourages != null) { foreach (var item in entourages) { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(), ParentId = info.Id, Name = $"{item}", FullName = $"{info.Name}_{item}", Gender = 0, GuestType = info.GuestType, Entourage = "", EntourageNum = 0, Labels = $"{info.Name} 随行人员", TableNo = info.TableNo, ImagePath = null, CreateTime = DateTime.Now, }); } } } else { var oldName = guest.Name; guest.Name = info.Name; guest.Gender = info.Gender; guest.GuestType = info.GuestType; guest.Labels = info.Labels; guest.TableNo = info.TableNo; guest.ImagePath = imageFileName; guest.CashGift = info.CashGift; guest.CreateTime = DateTime.Now; if (guest.Entourage != info.Entourage) { GlobalConfigs.Guests.RemoveAll(x => x.ParentId == info.Id); guest.Entourage = entourageText; guest.EntourageNum = entourageNum; if (entourages != null) { foreach (var item in entourages) { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(), ParentId = info.Id, Name = $"{item}", FullName = $"{info.Name}_{item}", Gender = 0, GuestType = info.GuestType, Entourage = "", EntourageNum = 0, Labels = $"{info.Name} 随行人员", TableNo = info.TableNo, ImagePath = null, IsAttend = guest.IsAttend, AttendTime = guest.AttendTime, CreateTime = DateTime.Now, }); } } } #region 关联更新 var parent = GlobalConfigs.Guests.FirstOrDefault(x => x.Id == guest.ParentId); if (parent != null && !string.IsNullOrEmpty(parent.Entourage)) { var pEntourages = parent.Entourage.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < pEntourages.Length; i++) { if (pEntourages[i] == oldName) { pEntourages[i] = guest.Name; } } parent.Entourage = string.Join(",", pEntourages); parent.EntourageNum = pEntourages.Count(); guest.FullName = $"{parent.Name}_{guest.Name}"; } #endregion } GlobalConfigMgr.SaveGuests(); } return(success); } catch (Exception ex) { return(false); } }