Esempio n. 1
0
        private void HandleEntity(SemacV14.Service.ExecuteArgz Ea)
        {
            string sCmd = "";

            try
            {
                sCmd = Ea.CommandType.ToString();
                switch (Ea.IsCompleted)
                {
                case true:
                    if (!(Ea.CallbackEntity == null))
                    {
                        EventLog.Write("{0}-{1}", "HandleEntity.Ea.IsCompleted=true", "成功:" + sCmd + ":" + Ea.CallbackEntity.ToMyString);
                    }
                    else
                    {
                        if (!(Ea.EntityList == null))
                        {
                            EventLog.Write("{0}-{1}", "HandleEntity.Ea.IsCompleted=true", "成功" + sCmd + ":筆數:" + Ea.EntityList.Count.ToString());
                        }
                    }
                    break;

                case false:
                    EventLog.Write("{0}-{1}", "HandleEntity.Ea.IsCompleted=false", "失敗:" + sCmd + ":" + Ea.ErrorMessage.ToString());
                    break;
                }
            }
            catch (Exception ex) { EventLog.WriteError("{0}-{1}", "HandleEntity", sCmd + ":" + ex.ToString()); }
        }
Esempio n. 2
0
        public bool AddUser(User _user)
        {
            try
            {
                if (!checkCardReader("AddUser"))
                {
                    return(false);
                }

                //EventLog.Write("{0}-{1}", "AddUser", "Start:" + _user.UserID + "-" + _user.UserName);

                var re = new SemacV14.Request.RegisterModifyUserDataRequest(TerminalID);

                re.UserID              = _user.UserID;
                re.EmployeeID          = _user.EmployeeID;
                re.OverWrite           = _user.OverWrite;
                re.CardNo              = _user.CardNo;
                re.UserName            = _user.UserName;
                re.CheckExpire         = _user.CheckExpire;
                re.ExpiredFrom         = _user.ExpiredFrom;
                re.ExpiredTo           = _user.ExpiredTo;
                re.EnabledStatus       = _user.EnabledStatus;
                re.UserType            = (Define.UserType)_user.UserType;
                re.Group01             = _user.Group01;
                re.Group02             = _user.Group02;
                re.Group03             = _user.Group03;
                re.Group04             = _user.Group04;
                re.BypassTimeZoneLevel = (Define.BypassTimeZoneLevel)_user.BypassTimeZoneLevel;
                re.PersonalPassword    = _user.PersonalPassword;

                SemacV14.Service.ExecuteArgz Ea = new SemacV14.Service.ExecuteArgz(ChannelID, re);

                //Execute
                SemacV14.Service.Actor Wrk = new Actor(Ea);
                Ea = Wrk.SendAndReceive(); //  'Send command,and return result

                // check the result
                if (Ea.IsCompleted == true)
                {
                    //EventLog.Write("{0}-{1}", "AddUser", "Success");
                    return(true);
                }
                else
                {
                    EventLog.Write("{0}-{1}", "AddUser", "Failure:" + _user.UserID + "-" + _user.UserName);
                    Msg = String.Format("加入使用者({0})發生錯誤:{1},TerminalID={2}, MacAddress={3}"
                                        , _user.UserID, Ea.ErrorMessage, TerminalID, MacAddress);
                    EventLog.Write("{0}-{1}", "AddUser", Msg);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Msg = String.Format("加入使用者({0})發生錯誤:{1},TerminalID={2}, MacAddress={3}"
                                    , _user.UserID, ex.Message, TerminalID, MacAddress);
                EventLog.WriteError("{0}-{1}", "AddUser", Msg);
                return(false);
            }
        }
Esempio n. 3
0
        public string QueryTheNumberOfAlreadyRegisteredUsers()
        {
            try
            {
                if (!checkCardReader("QueryTheNumberOfAlreadyRegisteredUsers"))
                {
                    return("99,99");
                }

                EventLog.Write("{0}-{1}", "QueryTheNumberOfAlreadyRegisteredUsers", "Start");

                var re = new SemacV14.Request.CommonRequest(TerminalID, Define.CommandType.QueryTheNumberOfAlreadyRegisteredUsers);
                var Ea = new SemacV14.Service.ExecuteArgz(ChannelID, re);

                //Execute
                SemacV14.Service.Actor Wrk = new Actor(Ea);
                Ea = Wrk.SendAndReceive(); //  'Send command,and return result

                // check the result
                if (Ea.IsCompleted == true)
                {
                    EventLog.Write("{0}-{1}", "QueryTheNumberOfAlreadyRegisteredUsers", "Success");

                    //Msg = String.Format("筆數:{0},TerminalID={1}, ChannelID={2}", Ea.EntityList.Count.ToString(), TerminalID, ChannelID);
                    //EventLog.Write("{0}-{1}", "QueryTheNumberOfAlreadyRegisteredUsers", Msg);

                    SemacV14.Entity.QueryTheNumberOfAlreadyRegisteredUsersEntity En = (SemacV14.Entity.QueryTheNumberOfAlreadyRegisteredUsersEntity)Ea.CallbackEntity;

                    BO.UpdateCardReaderUserCount(TerminalID.ToString(), En.RegisteredCount.ToString());

                    return("1," + En.RegisteredCount.ToString());
                }
                else
                {
                    EventLog.Write("{0}-{1}", "QueryTheNumberOfAlreadyRegisteredUsers", "Failure");
                    Msg = String.Format("ErrorMsg:{0},TerminalID={1}, ChannelID={2}", Ea.ErrorMessage, TerminalID, ChannelID);
                    EventLog.Write("{0}-{1}", "QueryTheNumberOfAlreadyRegisteredUsers", Msg);
                    return("0," + Ea.ErrorMessage);
                }
                //SemacV14.Service.Actor act = new Actor(Ea);

                //act.OnEntityDataArrival += HandleEntity;
                //act.Send();

                //return true;
            }
            catch (Exception ex)
            {
                Msg = String.Format("ErrorMsg:{0},TerminalID={1}, ChannelID={2}", ex.Message, TerminalID, ChannelID);
                EventLog.WriteError("{0}-{1}", "QueryTheNumberOfAlreadyRegisteredUsers", Msg);
                return("99,99");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 取得卡機內 UserID List
        /// </summary>
        /// <returns></returns>
        private int RetrievingUserIDList()
        {
            try
            {
                if (!checkCardReader("RetrievingUserIDList"))
                {
                    return(99);
                }

                var re = new SemacV14.Request.CommonRequest(TerminalID, Define.CommandType.RetrievingUserIDList);
                var Ea = new SemacV14.Service.ExecuteArgz(ChannelID, re);

                //Execute
                SemacV14.Service.Actor Wrk = new Actor(Ea);
                Wrk.TimeoutMinisecond = 10 * 60 * 1000; //those cmd may need more time,but in default , timeout checking was 10 seconds.
                Ea = Wrk.SendAndReceive();              //  'Send command,and return result

                // check the result
                if (Ea.IsCompleted == true)
                {
                    EventLog.Write("{0}-{1}", "RetrievingUserIDList", "Success");
                    SemacV14.Entity.RetrievingUserIDListEntity En = (SemacV14.Entity.RetrievingUserIDListEntity)Ea.CallbackEntity;

                    BO.insertCheckUserLog(TerminalID.ToString(), En.Count.ToString());
                    string SEQ = BO.getCheckUserLogSEQ(TerminalID.ToString());

                    int iCount = 0;
                    foreach (uint Item in En.Items)
                    {
                        iCount++;
                        Console.WriteLine(iCount.ToString() + "-" + String.Format("{0:X}", Convert.ToInt64(Item.ToString())));
                        BO.insertCheckUserList(TerminalID.ToString(), String.Format("{0:X}", Convert.ToInt64(Item.ToString())));
                        BO.insertCheckUserListTemp(SEQ, TerminalID.ToString(), String.Format("{0:X}", Convert.ToInt64(Item.ToString())));
                    }
                    return(1);
                }
                else
                {
                    EventLog.WriteCU("{0}-{1}", "RetrievingUserIDList.Ea.IsCompleted=false", "失敗:" + Ea.ErrorMessage.ToString());
                    //EventLog.Write("{0}-{1}", "RetrievingUserIDList", "Failure");
                    return(0);
                }
            }
            catch (Exception ex)
            {
                Msg = String.Format("ErrorMsg:{0},TerminalID={1}, ChannelID={2}", ex.Message, TerminalID, ChannelID);
                EventLog.WriteCU("{0}-{1}", "RetrievingUserIDList", Msg);
                return(99);
            }
        }
Esempio n. 5
0
 //Realtime
 private void HandleRealtime(SemacV14.Service.ExecuteArgz Ea)
 {
     try
     {
         if (!(Ea.EntityList == null))
         {
             foreach (SemacV14.Entity.DoorLogEntity En in Ea.EntityList)
             {
                 EventLog.Write("{0}-{1}", "HandleRealtime", En.ToMyString);
                 insertLog(En);
                 _timerDelAllLog.Enabled = false;
                 _timerDelAllLog.Enabled = true;
             }
         }
     }
     catch (Exception ex) { EventLog.WriteError("{0}-{1}", "HandleRealtime", ex.ToString()); }
 }
Esempio n. 6
0
        //private void SyncUser()
        //{
        //    DataTable dt = BO.getPersonCard();
        //    DataTable dtSyncCardReaderUserLog = BO.getSyncCardReaderUserLog();

        //    foreach (DataRow drT in TerminalTable.Rows)
        //    {
        //        ChannelID = drT["ChannelID"].ToString();
        //        TerminalID = Convert.ToInt32(drT["TerminalID"].ToString());
        //        MacAddress = drT["MacAddress"].ToString();

        //        //判斷今天是否已同步完成 0:未, 1:完成
        //        int iYN = 0;
        //        foreach (DataRow drCRUL in dtSyncCardReaderUserLog.Rows)
        //        {
        //            if (TerminalID.ToString().Equals(drCRUL["TerminalID"].ToString()))
        //            {
        //                Msg = String.Format("今日已同步【白名單】,TerminalID={0}, MacAddress={1}", TerminalID, MacAddress);
        //                EventLog.Write("{0}-{1}", "SyncUser", Msg);
        //                iYN = 1;
        //            }
        //        }

        //        if (iYN == 0)
        //        {
        //            Msg = String.Format("DeleteAllUser,TerminalID={0}, MacAddress={1}", TerminalID, MacAddress);
        //            EventLog.Write("{0}-{1}", "SyncUser", Msg);
        //            DeleteAllUser();
        //            System.Threading.Thread.Sleep(1000 * 10);
        //            Msg = String.Format("AddUser-Start,TerminalID={0}, MacAddress={1}", TerminalID, MacAddress);
        //            EventLog.Write("{0}-{1}", "SyncUser", Msg);
        //            int iCount = 0;
        //            foreach (DataRow dr in dt.Rows)
        //            {
        //                try {
        //                    User user = new User
        //                    {
        //                        //UserID = Convert.ToUInt32(dr["Uid"].ToString()),
        //                        UserID = UInt32.Parse(dr["HexCardOrderNo"].ToString(), System.Globalization.NumberStyles.HexNumber),
        //                        EmployeeID = UInt32.Parse(dr["HexCardOrderNo"].ToString(), System.Globalization.NumberStyles.HexNumber).ToString(),
        //                        OverWrite = true,
        //                        CardNo = UInt32.Parse(dr["HexCardOrderNo"].ToString(), System.Globalization.NumberStyles.HexNumber).ToString(),
        //                        UserName = dr["Cn"].ToString(),
        //                        CheckExpire = true,
        //                        ExpiredFrom = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy/MM/dd HH:mm:ss")),
        //                        ExpiredTo = Convert.ToDateTime(DateTime.Now.AddDays(30).ToString("yyyy/MM/dd HH:mm:ss")),
        //                        EnabledStatus = true,//!entry.Black && entry.ExpireOn.Value >= DateTime.Now,
        //                        UserType = 0,
        //                        Group01 = 1,
        //                        Group02 = 0,
        //                        Group03 = 0,
        //                        Group04 = 0,
        //                        BypassTimeZoneLevel = 1,
        //                        PersonalPassword = ""
        //                    };

        //                    if (GetOneUser(user.UserID) == 0)
        //                    {
        //                        if (!AddUser(user))
        //                            iCount++;
        //                        else if (!AddUser(user))
        //                            iCount++;
        //                        else if (!AddUser(user))
        //                            iCount++;
        //                        else if (!AddUser(user))
        //                            iCount++;
        //                    }
        //                    else
        //                        iCount++;

        //                    System.Threading.Thread.Sleep(500);
        //                }
        //                catch (Exception ex) {
        //                    iCount++;
        //                    EventLog.WriteError("{0}-{1}", "SyncUser", ex.ToString()); }
        //            }
        //            Msg = String.Format("已同步【白名單】,人員筆數:{0},成功筆數:{1},失敗筆數:{2},TerminalID={3}, MacAddress={4}"
        //                , dt.Rows.Count.ToString(), (dt.Rows.Count - iCount).ToString(), iCount.ToString(), TerminalID, MacAddress);
        //            EventLog.Write("{0}-{1}", "SyncUser", Msg);
        //            BO.insertSyncUserLog(TerminalID.ToString(), Msg);
        //            if (iCount == 0)
        //            {
        //                BO.insertSyncCardReaderUserLog(TerminalID.ToString());

        //                //查詢卡機人員筆數
        //                QueryTheNumberOfAlreadyRegisteredUsers();
        //            }
        //        }
        //    }

        //    //查檢今日是否都已同步完成
        //    dtSyncCardReaderUserLog = BO.getSyncCardReaderUserLog();
        //    foreach (DataRow drT in TerminalTable.Rows)
        //    {
        //        ChannelID = drT["ChannelID"].ToString();
        //        TerminalID = Convert.ToInt32(drT["TerminalID"].ToString());
        //        MacAddress = drT["MacAddress"].ToString();

        //        //判斷今天是否已同步完成 0:未, 1:完成
        //        foreach (DataRow drCRUL in dtSyncCardReaderUserLog.Rows)
        //        {
        //            if (TerminalID.ToString().Equals(drCRUL["TerminalID"].ToString()))
        //                _timer.Enabled = false;
        //        }
        //    }
        //}

        #region 卡機指令

        public string DeleteAllUser()
        {
            try
            {
                if (!checkCardReader("DeleteAllUser"))
                {
                    return("99,99");
                }

                EventLog.Write("{0}-{1}", "DeleteAllUser", "Start");

                var re = new SemacV14.Request.CommonRequest(TerminalID, Define.CommandType.AllUsersDeletion);
                var Ea = new SemacV14.Service.ExecuteArgz(ChannelID, re);

                //Execute
                SemacV14.Service.Actor Wrk = new Actor(Ea);
                Ea = Wrk.SendAndReceive(); //  'Send command,and return result

                // check the result
                if (Ea.IsCompleted == true)
                {
                    EventLog.Write("{0}-{1}", "DeleteAllUser", "Success");
                    return("1,1");
                }
                else
                {
                    EventLog.Write("{0}-{1}", "DeleteAllUser", "Fialure");
                    return("0," + Ea.ErrorMessage);
                }
                //SemacV14.Service.Actor act = new Actor(Ea);

                //act.OnEntityDataArrival += HandleEntity;
                //act.Send();

                //return true;
            }
            catch (Exception ex)
            {
                Msg = String.Format("刪除所有使用者發生錯誤:{0},TerminalID={1}, ChannelID={2}"
                                    , ex.Message, TerminalID, ChannelID);
                EventLog.WriteError("{0}-{1}", "DeleteAllUser", Msg);
                return("99,99");
            }
        }
Esempio n. 7
0
        /// <summary>刪除已接收過的讀卡紀錄</summary>
        public string DeletingAllEntryExitLog()
        {
            try
            {
                if (!checkCardReader("DeletingAllEntryExitLog"))
                {
                    return("99,99");
                }

                EventLog.Write("{0}-{1}", "DeletingAllEntryExitLog", "Start");

                var re = new SemacV14.Request.CommonRequest(TerminalID, Define.CommandType.DeletingAllEntryExitLog);
                var Ea = new SemacV14.Service.ExecuteArgz(ChannelID, re);

                //Execute
                SemacV14.Service.Actor Wrk = new Actor(Ea);
                Ea = Wrk.SendAndReceive(); //  'Send command,and return result

                // check the result
                if (Ea.IsCompleted == true)
                {
                    EventLog.Write("{0}-{1}", "DeletingAllEntryExitLog", "Success");

                    return("1,1");
                }
                else
                {
                    EventLog.Write("{0}-{1}", "DeletingAllEntryExitLog", "Failure");
                    Msg = String.Format("ErrorMsg:{0},TerminalID={1}, ChannelID={2}", Ea.ErrorMessage, TerminalID, ChannelID);
                    EventLog.Write("{0}-{1}", "DeletingAllEntryExitLog", Msg);
                    return("0," + Ea.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                Msg = String.Format("ErrorMsg:{0},TerminalID={1}, ChannelID={2}", ex.Message, TerminalID, ChannelID);
                EventLog.WriteError("{0}-{1}", "DeletingAllEntryExitLog", Msg);
                return("99,99");
            }
        }
Esempio n. 8
0
        private int UserDeletionRequest(UInt32 UserID)
        {
            try
            {
                if (!checkCardReader("UserDeletionRequest"))
                {
                    return(99);
                }

                //EventLog.Write("{0}-{1}", "UserDeletionRequest", "Start");

                SemacV14.Request.UserDeletionRequest Re = new SemacV14.Request.UserDeletionRequest(TerminalID, UserID);
                SemacV14.Service.ExecuteArgz         Ea = new SemacV14.Service.ExecuteArgz(ChannelID, Re);

                //Execute
                SemacV14.Service.Actor Wrk = new Actor(Ea);
                Wrk.TimeoutMinisecond = 10 * 60 * 1000; //those cmd may need more time,but in default , timeout checking was 10 seconds.
                Ea = Wrk.SendAndReceive();              //  'Send command,and return result

                // check the result
                if (Ea.IsCompleted == true)
                {
                    //EventLog.Write("{0}-{1}", "UserDeletionRequest", "Success");
                    return(1);
                }
                else
                {
                    EventLog.Write("{0}-{1}", "UserDeletionRequest", "Failure:" + UserID);
                    return(0);
                }
            }
            catch (Exception ex)
            {
                Msg = String.Format("刪除人員發生錯誤:{0},TerminalID={1}, ChannelID={2}"
                                    , ex.Message, TerminalID, ChannelID);
                EventLog.WriteError("{0}-{1}", "UserDeletionRequest", Msg);
                return(99);
            }
        }
Esempio n. 9
0
        private int GetOneUser(UInt32 UserID)
        {
            try
            {
                if (!checkCardReader("GetOneUser"))
                {
                    return(99);
                }

                SemacV14.Request.GetUserDataRequest Re = new SemacV14.Request.GetUserDataRequest(TerminalID, UserID);
                SemacV14.Service.ExecuteArgz        Ea = new SemacV14.Service.ExecuteArgz(ChannelID, Re);

                //Execute
                SemacV14.Service.Actor Wrk = new Actor(Ea);
                Ea = Wrk.SendAndReceive(); //  'Send command,and return result

                // check the result
                if (Ea.IsCompleted == true)
                {
                    SemacV14.Entity.GetUserDataEntity En = (SemacV14.Entity.GetUserDataEntity)Ea.CallbackEntity;
                    //MessageBox.Show(En.UserName);
                    //MessageBox.Show(En.CardNo );
                    return(1);
                }
                else
                {
                    //MessageBox.Show(Ea.ErrorMessage);  // Failed
                    return(0);
                }
            }
            catch (Exception ex)
            {
                Msg = String.Format("UserID:{0},ErrorMsg:{1},TerminalID={2}, ChannelID={3}", UserID.ToString(), ex.Message, TerminalID, ChannelID);
                EventLog.WriteError("{0}-{1}", "GetOneUser", Msg);
                return(99);
            }
        }
Esempio n. 10
0
        public int  SetNewTimeAndDate()
        {
            EventLog.Write("{0}-{1}", "SetNewTimeAndDate", "Start-Sync DateTime");
            try
            {
                if (!checkCardReader("SetNewTimeAndDate"))
                {
                    return(99);
                }

                SemacV14.Request.SetNewTimeAndDateRequest Re = new SemacV14.Request.SetNewTimeAndDateRequest(TerminalID, DateTime.Now);
                SemacV14.Service.ExecuteArgz Ea = new SemacV14.Service.ExecuteArgz(ChannelID, Re);

                //Execute
                SemacV14.Service.Actor Wrk = new Actor(Ea);
                Ea = Wrk.SendAndReceive(); //  'Send command,and return result

                // check the result
                if (Ea.IsCompleted == true)
                {
                    EventLog.Write("{0}-{1}", "SetNewTimeAndDate", "Sync DateTime Success");
                    return(1);
                }
                else
                {
                    EventLog.Write("{0}-{1}", "SetNewTimeAndDate", "Sync DateTime Failure");
                    return(0);
                }
            }
            catch (Exception ex)
            {
                Msg = String.Format("同步時間發生錯誤:{0},TerminalID={1}, ChannelID={2}"
                                    , ex.Message, TerminalID, ChannelID);
                EventLog.WriteError("{0}-{1}", "SetNewTimeAndDate", Msg);
                return(99);
            }


            //SemacV14.Define.CommandType cmd = SemacV14.Define.CommandType.SetNewTimeAndDate;
            //if (cmd <= 0) return;

            //DataTable dtSyncCardReaderUserLog = BO.getSyncCardReaderUserLog();

            //foreach (DataRow drT in TerminalTable.Rows)
            //{
            //    ChannelID = drT["ChannelID"].ToString();
            //    TerminalID = Convert.ToInt32(drT["TerminalID"].ToString());

            //    //判斷今天是否已同步完成 0:未, 1:完成
            //    int iYN = 0;
            //    foreach (DataRow drCRUL in dtSyncCardReaderUserLog.Rows)
            //    {
            //        if (TerminalID.Equals(drCRUL["TerminalID"].ToString()))
            //            iYN = 1;
            //    }

            //    if (iYN == 0)
            //    {
            //        var re = new SemacV14.Request.SetNewTimeAndDateRequest(TerminalID, DateTime.Now);

            //        var Ea = new SemacV14.Service.ExecuteArgz(ChannelID, re);

            //        if (Ea == null) return;
            //        SemacV14.Service.Actor act = new Actor(Ea);
            //        act.TimeoutMinisecond = 10 * 60 * 1000;  //those cmd may need more time,but in default , timeout checking was 10 seconds.

            //        act.OnEntityDataArrival += this.HandleEntity;
            //        act.Send();
            //    }
            //}
        }