예제 #1
0
        private void SyncUserNew()
        {
            try {
                //檢查CardReaderSyncTime的時間範圍,是否符合可執行的時段
                if (!getIsSync())
                {
                    return;
                }

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

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

                    this.dtCardReader = BO.getCardReader(TerminalID.ToString());
                    DataTable dtSyncCardReaderUserLog = BO.getSyncCardReaderUserLog(TerminalID.ToString(), SyncTimeSEQ.ToString());

                    //判斷今天是否已同步完成
                    if (dtSyncCardReaderUserLog.Rows.Count == 0)
                    {
                        if (dtCardReader.Rows[0]["IsSyncAll"].ToString().Equals("1"))
                        {
                            DeleteAllUser();
                            BO.UpdateCardReaderIsSyncAll(TerminalID.ToString());
                        }

                        int       addCount = 0, delCount = 0, AllCount = 0;
                        DataTable dt = BO.getPersonCardToCardReader(TerminalID.ToString());
                        foreach (DataRow dr in dt.Rows)
                        {
                            User user = new User
                            {
                                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(1000).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    = ""
                            };

                            int RCount = addCount + delCount;
                            if (dr["State"].ToString().Equals("D"))
                            {
                                if (GetOneUser(user.UserID) == 1)
                                {
                                    if (UserDeletionRequest(user.UserID) == 1)
                                    {
                                        delCount++;
                                    }
                                    else if (UserDeletionRequest(user.UserID) == 1)
                                    {
                                        delCount++;
                                    }
                                    else if (UserDeletionRequest(user.UserID) == 1)
                                    {
                                        delCount++;
                                    }
                                    else if (UserDeletionRequest(user.UserID) == 1)
                                    {
                                        delCount++;
                                    }
                                }
                                else
                                {
                                    delCount++;
                                }
                            }
                            else
                            {
                                if (AddUser(user))
                                {
                                    addCount++;
                                }
                                else if (AddUser(user))
                                {
                                    addCount++;
                                }
                                else if (AddUser(user))
                                {
                                    addCount++;
                                }
                                else if (AddUser(user))
                                {
                                    addCount++;
                                }
                            }

                            if (RCount < (delCount + addCount))
                            {
                                BO.sp_TFSyncUserSuccess(dr["SEQ"].ToString());
                            }
                        }

                        Msg = String.Format(@"已同步【白名單】,人員筆數:{0},更新筆數:{1},刪除筆數:{2},失敗筆數:{3},TerminalID={4}, MacAddress={5}"
                                            , dt.Rows.Count.ToString(), addCount.ToString(), delCount.ToString()
                                            , (dt.Rows.Count - addCount - delCount).ToString()
                                            , TerminalID, MacAddress);
                        EventLog.Write("{0}-{1}", "SyncUser", Msg);

                        BO.insertSyncUserLog(TerminalID.ToString(), Msg);

                        if ((addCount + delCount) == dt.Rows.Count)
                        {
                            BO.insertSyncCardReaderUserLog(TerminalID.ToString(), SyncTimeSEQ.ToString());

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

                            blTodayIsSyncOK = true;
                        }
                    }
                    else
                    {
                        blTodayIsSyncOK = true;
                    }
                }
                EventLog.Write("{0}-{1}", "SyncUserNew", "End-Sync User");
            }
            catch (Exception ex) { EventLog.WriteError("{0}-{1}", "SyncUserNew", ex.ToString()); }
        }
예제 #2
0
 private void getCardReader()
 {
     this.dtCardReader = BO.getCardReader();
 }