protected void bthnoteok_Click(object sender, EventArgs e)
        {
            UserScanDAO userscan     = new UserScanDAO();
            int         memberuserid = Convert.ToInt32(this.DecryptQueryString("userid").ToString());
            DataTable   dt           = userscan.GetUserScanByIDMember(memberuserid);

            if (dt.Rows.Count > 0)
            {
                if (txtcomment.Text.Trim() != "")
                {
                    string datetimeup   = dt.Rows[0]["datetime_up"].ToString();
                    string datetimedown = dt.Rows[0]["datetime_down"].ToString();

                    if (datetimeup == "ยังไม่ได้สแกน")
                    {
                        if (chkup.Checked == true)
                        {
                            userscan.UpdateUserScanByIDMember_Up(memberuserid, txtcomment.Text.Trim());
                            userscan.UpdateUserScanByIDMember_Noteup(memberuserid, 1);
                        }
                    }

                    if (datetimedown == "ยังไม่ได้สแกน")
                    {
                        if (chkdown.Checked == true)
                        {
                            userscan.UpdateUserScanByIDMember_Down(memberuserid, txtcomment.Text.Trim());
                            userscan.UpdateUserScanByIDMember_Notedown(memberuserid, 1);
                        }
                    }
                }
            }
        }
Пример #2
0
        public void UpdateUserScanByMemberid(string trunscan, string topicsearch) // สถานะการสแกน
        {
            client.ProtocolVersion = MqttProtocolVersion.Version_3_1;
            try
            {
                client.Connect(Guid.NewGuid().ToString(),
                               "fjhgvxul",
                               "cT9BYUzB5yCR",
                               true,                               // will retain flag
                               MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, // will QoS
                               true,                               // will flag
                               "/test",                            // will topic
                               "default",                          // will message
                               true,
                               60);
            }
            catch
            {
                Debug.WriteLine("Error Connect");
            }

            client.MqttMsgPublishReceived += client_MqttMsgPublishRecieved_GetSubscribe;
            // client.Subscribe(new string[] { topicup,topicdown }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE , MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE});
            client.Subscribe(new string[] { topicsearch }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });

            Debug.WriteLine("OnGetSubscribeUp");

            void client_MqttMsgPublishRecieved_GetSubscribe(object sender, MqttMsgPublishEventArgs e)
            {
                UserScanDAO userscan = new UserScanDAO();

                if (trunscan == "ขึ้นรถรับส่งเด็กนักเรียน")
                {
                    string fingerprintid = Encoding.UTF8.GetString(e.Message);
                    int    memberuserid  = Convert.ToInt32(fingerprintid);
                    Debug.WriteLine("Received = " + fingerprintid + "\ron topic = " + e.Topic + "\rtrunscan = " + trunscan + DateTime.Now.ToString("dd-MM-yyyy เวลา HH:mm:ss\r"));
                    userscan.UpdateUserScanByIDMember_Up(memberuserid, DateTime.Now.ToString("dd-MM-yyyy เวลา HH:mm:ss"));
                    //userscan.UpdateUserScanByFingerprintid_Up(fingerprintid, DateTime.Now.ToString("dd-MM-yyyy เวลา HH:mm:ss"));
                    Debug.WriteLine("OKScanup");
                    client.Disconnect();
                }

                if (trunscan == "ลงรถรับส่งเด็กนักเรียน")
                {
                    string fingerprintid = Encoding.UTF8.GetString(e.Message);
                    int    memberuserid  = Convert.ToInt32(fingerprintid);
                    Debug.WriteLine("Received = " + fingerprintid + "\ron topic = " + e.Topic + "\rtrunscan = " + trunscan + DateTime.Now.ToString("dd-MM-yyyy เวลา HH:mm:ss\n"));
                    userscan.UpdateUserScanByIDMember_Down(memberuserid, DateTime.Now.ToString("dd-MM-yyyy เวลา HH:mm:ss"));
                    //userscan.UpdateUserScanByFingerprintid_Down(fingerprintid, DateTime.Now.ToString("dd-MM-yyyy เวลา HH:mm:ss"));

                    Debug.WriteLine("OKScanDown");
                    client.Disconnect();
                }
            }
        }
        public void client_MqttMsgPublishRecieved_GetSubscribe(object sender, MqttMsgPublishEventArgs e)
        {
            UserScanDAO userscan = new UserScanDAO();
            string      trunscan = ViewState["trunscan"].ToString();

            if (trunscan == "ขึ้นรถรับส่งเด็กนักเรียน")
            {
                string fingerprintid = Encoding.UTF8.GetString(e.Message);

                if (fingerprintid == "disconnect")
                {
                    Debug.WriteLine("Received = " + fingerprintid + "\ron topic = " + e.Topic + "\rtrunscan = " + trunscan + datetime());
                    client_scan.Disconnect();
                }
                else if (fingerprintid == "fail")
                {
                    Debug.WriteLine("Disconnect");
                    client_scan.Disconnect();
                    Timer = true;
                }
                else
                {
                    int memberuserid = Convert.ToInt32(fingerprintid);
                    Debug.WriteLine("Received = " + fingerprintid + "\ron topic = " + e.Topic + "\rtrunscan = " + trunscan + datetime());
                    userscan.UpdateUserScanByIDMember_Noteup(memberuserid, 0);
                    userscan.UpdateUserScanByIDMember_Up(memberuserid, datetime());

                    //userscan.UpdateUserScanByFingerprintid_Up(fingerprintid, DateTime.Now.ToString("dd-MM-yyyy เวลา HH:mm:ss"));
                    Debug.WriteLine("OKScanup");
                    client_scan.Disconnect();
                    Timer = true;
                }
            }

            if (trunscan == "ลงรถรับส่งเด็กนักเรียน")
            {
                string fingerprintid = Encoding.UTF8.GetString(e.Message);

                if (fingerprintid == "disconnect")
                {
                    Debug.WriteLine("Received = " + fingerprintid + "\ron topic = " + e.Topic + "\rtrunscan = " + trunscan + datetime());
                    client_scan.Disconnect();
                    Timer = true;
                }
                else if (fingerprintid == "fail")
                {
                    Debug.WriteLine("Disconnect");
                    client_scan.Disconnect();
                    Timer = true;
                }
                else
                {
                    int memberuserid = Convert.ToInt32(fingerprintid);
                    Debug.WriteLine("Received = " + fingerprintid + "\ron topic = " + e.Topic + "\rtrunscan = " + trunscan + datetime());
                    userscan.UpdateUserScanByIDMember_Notedown(memberuserid, 0);
                    userscan.UpdateUserScanByIDMember_Down(memberuserid, datetime());

                    //userscan.UpdateUserScanByFingerprintid_Down(fingerprintid, DateTime.Now.ToString("dd-MM-yyyy เวลา HH:mm:ss"));

                    Debug.WriteLine("OKScanDown");
                    client_scan.Disconnect();
                    Timer = true;
                }
            }
        }