Пример #1
0
        private void RefreshMemberListPassively()
        {
            var currentCheckInType = this.getCheckInType();
            var checkInAddress     = this.GetCheckInLocation();

            Task.Run(async() =>
            {
                try
                {
                    await MemberCheckInSingletonService.getAllMemberCheckInOnToday(currentCheckInType, checkInAddress);
                    this.m_SyncContext.Post(context =>
                    {
                        List <MemberCheckIn> data = context as List <MemberCheckIn>;
                        var total = data.Count(item => item.status == CheckInStatus.Waiting);
                        this.toolStripProgressBar1.Step  = 100 / total;
                        this.toolStripProgressBar1.Value = 0;
                        this.toolStripStatusLabel1.Text  = $"[{total}条记录]准备中...";
                    }, MemberCheckInSingletonService.Instance.membercheckinlist);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    throw ex;
                }
            });
        }
Пример #2
0
        /// <summary>
        /// 打卡类型变化事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void checkin_type_combox_SelectedValueChanged(object sender, EventArgs e)
        {
            if (!this.Initialized)
            {
                return;
            }

            await MemberCheckInSingletonService.getAllMemberCheckInOnToday(this.getCheckInType(), this.GetCheckInLocation());
        }
Пример #3
0
        private async void Init()
        {
            this.checkin_type_combox.SelectedIndex = 0;
            user = new AddUserDAL();
            await this.BindCheckInAddressDataMember();

            await MemberCheckInSingletonService.getAllMemberCheckInOnToday(this.getCheckInType(), this.GetCheckInLocation());

            await FaceSyncService.Instance.Run();

            this.Initialized = true;
        }
Пример #4
0
        // 重置打卡
        private void button3_Click(object sender, EventArgs e)
        {
            if (!this.Initialized)
            {
                return;
            }

            List <string> resetCheckInItems = new List <string>();

            for (int i = 0; i < this.error_checkin_datagrid.RowCount; i++)
            {
                if ((bool)this.error_checkin_datagrid.Rows[i].Cells[0].Value)
                {
                    Member member = (Member)this.error_checkin_datagrid.Rows[i].DataBoundItem;
                    resetCheckInItems.Add(member.ID);
                }
            }

            if (resetCheckInItems.Count > 0)
            {
                var currentCheckInType = this.getCheckInType();
                var checkInAddress     = this.GetCheckInLocation();

                Task.Run(async() =>
                {
                    bool result = await MemberCheckInSingletonService.resetErrorCheckIn(resetCheckInItems);

                    if (!result)
                    {
                        MessageBox.Show("重置打卡失败.");
                        return;
                    }

                    try
                    {
                        await MemberCheckInSingletonService.getAllMemberCheckInOnToday(currentCheckInType, checkInAddress);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        throw ex;
                    }
                });
            }
            else
            {
                MessageBox.Show("请选择所需要重置打卡的人员");
            }
        }
        private async void sendRequst(Dictionary <string, string> template, Uri requestUrl)
        {
            string ur = $"{string.Format("0")}\"\",\"\"";
            string openId, userId, timestamp, nonce, trade_source, signature, qrcodeid, longitude, latitude;

            template.TryGetValue("openid", out openId);
            template.TryGetValue("userid", out userId);
            template.TryGetValue("timestamp", out timestamp);
            template.TryGetValue("nonce", out nonce);
            template.TryGetValue("trade_source", out trade_source);
            template.TryGetValue("signature", out signature);
            template.TryGetValue("attach", out qrcodeid);

            var member = MemberCheckInSingletonService.Instance.membercheckinlist.Single(m => m.openId == openId);

            longitude = member.longitude.ToString();
            latitude  = member.latitude.ToString();

            string customParams = $"{{\"openid\":\"{openId}\",\"userid\":\"{userId}\",\"timestamp\":\"{timestamp}\",\"nonce\":\"{nonce}\",\"trade_source\":\"{trade_source}\",\"signature\":\"{signature}\",\"qrcodeid\":\"{qrcodeid}\",\"attentype\":\"morning\",\"longitude\":{longitude},\"latitude\":{latitude},\"cacheflag\":\"0\"}}";
            //"openid":"","userid":"510129760","timestamp":"1555230703033","nonce":"b422fca3-6745-45fb-942e-3277e4c2872f","trade_source":"HXQYH","signature":"C5B39A04405C819AB045BD54A3376D59","qrcodeid":"00000000000000105723","attentype":"morning","longitude":104.07,"latitude":30.67,"cacheflag":"0"
            string url = $"http://kqapi.hxlife.com/tms/api/QRcodeSign?callbackparam=success_jsonpCallback&params={customParams}&_={DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";

            string retString = await HttpUtil.Request(url);

            Regex regex = new Regex("success_jsonpCallback\\((.*)\\)");

            if (regex.IsMatch(retString))
            {
                var result        = regex.Match(retString).Groups[1].Value;
                var checkInResult = JsonConvert.DeserializeObject <CheckInServerResponse>(result);

                MemberCheckInSingletonService.updateMemberCheckInInformation(openId, checkInResult.result == "success" ? CheckInStatus.Success : CheckInStatus.Error, checkInResult.result, checkInResult.message, requestUrl.ToString());
            }
            else
            {
                MemberCheckInSingletonService.updateMemberCheckInInformation(openId, CheckInStatus.Error, null, retString, requestUrl.ToString());
            }
        }
Пример #6
0
        //左导航栏选择
        private async void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            if (!this.Initialized)
            {
                return;
            }
            if (e.TabPage.Text == "会员列表")
            {
                await this.BindDataMemberList();
            }

            /*else if (e.TabPage.Text == "会员注册")
             * {
             *  this.checkin_address_combox.DataSource = await user.getCheckInAddressList();
             *  this.checkin_address_combox.DisplayMember = "text";
             *  this.checkin_address_combox.ValueMember = "value";
             *  this.checkin_address_combox.SelectedIndex = 0;
             * }*/
            else if (e.TabPage.Text == "打卡管理")
            {
                await MemberCheckInSingletonService.getAllMemberCheckInOnToday(this.getCheckInType(), this.GetCheckInLocation());
            }
        }
Пример #7
0
        private void Instance_OnMessage(object sender, CustomEventArgs e)
        {
            Console.WriteLine("Handling SocketService.OnMessage................................");
            Console.WriteLine(JsonConvert.SerializeObject(e.Data));
            //MessageBox.Show(e.Data.op.ToString());
            //this.m_SyncContext.Post((data) =>
            //{
            //    MessageBox.Show(e.Data.op.ToString());
            //}, null);

            this.m_SyncContext.Post((data) =>
            {
                var checkInUrl = GetCheckInLocation()?.url;

                switch (e.Data.op)
                {
                case SocketOp.ACK:
                case SocketOp.PLAIN:
                    this.toolStripProgressBar1.Value      = 0;
                    this.toolStripStatusLabelPercent.Text = "";
                    this.toolStripStatusLabel1.Text       = $"[{e.Data.data.message}]";
                    break;

                case SocketOp.CHECK_IN_CREATED:
                    MemberCheckInSingletonService.createNewMemberCheckInformation(e.Data.data);
                    this.toolStripProgressBar1.Value      = 100;
                    this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                    this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]绑定完成";
                    break;

                case SocketOp.CHECK_IN_STARTED:
                    this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                    this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]开始打卡";
                    break;

                case SocketOp.CHECK_IN_SKIP:
                    if (Mode == CheckInMode.Batch && IsSomeoneWaiting(e.Data.data.id))
                    {
                        this.toolStripProgressBar1.ProgressBar.PerformStep();
                        this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                        this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]跳过";
                        SwitchCheckInMember();
                        var sleepMS = random.Next(lowerTimeSpan, higherTimeSpan);
                        Thread.Sleep(sleepMS);
                        CheckInSingleMember(checkInUrl);
                    }
                    else if (Mode == CheckInMode.Register)
                    {
                        this.toolStripProgressBar1.Value      = 100;
                        this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                        this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]重复绑定";
                    }
                    else if (this.IsWatcher)
                    {
                        this.toolStripProgressBar1.ProgressBar.PerformStep();
                        this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                        this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]跳过";
                    }
                    else
                    {
                        this.toolStripProgressBar1.Value      = 100;
                        this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                        this.toolStripStatusLabel1.Text       = "当前打卡完成";
                    }
                    break;

                case SocketOp.CHECK_IN_UPDATED:
                    Task.Run(async() =>
                    {
                        await MemberCheckInSingletonService.updateMemberCheckInInformation(e.Data.data);
                        if (Mode == CheckInMode.Register)
                        {
                            this.m_SyncContext.Post(context =>
                            {
                                this.toolStripProgressBar1.Value      = 100;
                                this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                                this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]完成注册";
                            }, this);
                        }
                        else if (Mode == CheckInMode.Batch && IsSomeoneWaiting(e.Data.data.id))
                        {
                            this.m_SyncContext.Post(context =>
                            {
                                this.toolStripProgressBar1.PerformStep();
                                this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                                this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]完成打卡";
                            }, this);
                            SwitchCheckInMember();
                            var sleepMS = random.Next(lowerTimeSpan, higherTimeSpan);
                            Thread.Sleep(sleepMS);
                            CheckInSingleMember(checkInUrl);
                        }
                        else if (NeedFace(e.Data.data.id))
                        {
                            this.m_SyncContext.Post(context =>
                            {
                                this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                                this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]开始打脸";
                            }, this);

                            if (MemberCheckInSingletonService.Instance.checkedInIds.Contains(e.Data.data.id))
                            {
                                MemberCheckInSingletonService.Instance.checkedInIds.Remove(e.Data.data.id);
                            }
                            MemberCheckIn memberCheckIn = MemberCheckInSingletonService.Instance.membercheckinlist.SingleOrDefault(m => m._id == e.Data.data.id);

                            if (!this.IsWatcher)
                            {
                                MonitorFaceDialog(memberCheckIn.faceList);
                            }
                        }
                        else
                        {
                            this.m_SyncContext.Post(context =>
                            {
                                this.toolStripProgressBar1.Value      = 100;
                                this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                                this.toolStripStatusLabel1.Text       = $"当前打卡完成";
                            }, this);
                        }
                    });
                    break;

                case SocketOp.MEMBER_NEED_CHECK_IN_UPDATED:
                    if (!this.IsWatcher)
                    {
                        // only Watcher need to refresh member list again.
                        RefreshMemberListPassively();
                        return;
                    }
                    break;
                }
            }, this);
        }
Пример #8
0
        /// <summary>
        /// 批量打卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button1_Click(object sender, EventArgs e)
        {
            int lowerTimeSpanSeconds;
            int higherTimeSpanSeconds;

            try
            {
                lowerTimeSpanSeconds  = Convert.ToInt32(this.textBox1.Text);
                higherTimeSpanSeconds = Convert.ToInt32(this.textBox2.Text);
                if (lowerTimeSpan != 0 && higherTimeSpan != 0)
                {
                    this.lowerTimeSpan  = lowerTimeSpanSeconds * 1000;
                    this.higherTimeSpan = higherTimeSpanSeconds * 1000;
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Format error");
            }

            this.lowerTimeSpan = Convert.ToInt32(this.textBox1.Text);
            var todaySeparator = DateTime.Today;

            todaySeparator = todaySeparator.AddHours(10);
            todaySeparator = todaySeparator.AddMinutes(30);

            var systemCheckInType = DateTime.Now >= todaySeparator ? CheckInType.CheckOut : CheckInType.CheckIn;

            if (getCheckInType() != systemCheckInType)
            {
                MessageBox.Show($"请选择正确的打卡类型, 当前时间: {DateTime.Now}");
                return;
            }

            var checkInUrl = GetCheckInLocation()?.url;

            Mode = CheckInMode.Batch;
            List <string> checkitems = new List <string>();

            MemberCheckInSingletonService.Instance.checkedInIds = new HashSet <string>();
            MemberCheckInSingletonService.Instance.needFaceIds  = new HashSet <string>();

            for (int i = 0; i < this.wait_checkin_datagrid.RowCount; i++)
            {
                if ((bool)this.wait_checkin_datagrid.Rows[i].Cells[0].Value)
                {
                    Member member = (Member)this.wait_checkin_datagrid.Rows[i].DataBoundItem;
                    checkitems.Add(member.ID);
                }
            }
            if (checkitems.Count > 0)
            {
                Task.Run(async() =>
                {
                    this.m_SyncContext.Post((context) =>
                    {
                        this.toolStripStatusLabel1.Text  = "正在更新需要打卡人员...";
                        this.toolStripProgressBar1.Value = 0;
                    }, this);

                    bool result = await MemberCheckInSingletonService.updateNeedCheckIn(checkitems);

                    this.m_SyncContext.Post((context) =>
                    {
                        this.toolStripProgressBar1.Value = 100;
                    }, this);

                    if (!result)
                    {
                        this.m_SyncContext.Post((context) =>
                        {
                            this.toolStripStatusLabel1.Text = "更新需要打卡人员失败";
                        }, this);

                        return;
                    }

                    MemberCheckInSingletonService.Instance.membercheckinlist.ForEach((item) =>
                    {
                        if (checkitems.FirstOrDefault(a => a == item._id) != null)
                        {
                            item.needChecked = NeeChecked.Need;
                        }
                        else
                        {
                            item.needChecked = NeeChecked.NoNeed;
                        }
                    });

                    this.m_SyncContext.Post((context) =>
                    {
                        List <MemberCheckIn> data = context as List <MemberCheckIn>;
                        var total = data.Count(item => item.status == CheckInStatus.Waiting);
                        this.toolStripProgressBar1.Step  = 100 / total;
                        this.toolStripProgressBar1.Value = 0;
                        this.toolStripStatusLabel1.Text  = $"[{total}条记录]准备中...";
                    }, MemberCheckInSingletonService.Instance.membercheckinlist);

                    CheckInSingleMember(checkInUrl);
                });
            }
            else
            {
                MemberCheckInSingletonService.Instance.membercheckinlist.ForEach((item) =>
                {
                    item.needChecked = NeeChecked.NoNeed;
                });
            }
        }