/// <summary>
 /// 开始同步
 /// </summary>
 public void Sync()
 {
     try
     {
         int allCount     = 0;
         int successCount = 0;
         int failCount    = 0;
         if (SyncProgress != null)
         {
             SyncProgress("开始获取数据...");
         }
         DataSet ds = GetAccessLogList();
         allCount = ds.Tables[0].Rows.Count;
         if (SyncProgress != null)
         {
             SyncProgress("获取记录" + allCount + "条");
         }
         SeatManage.SeatManageComm.WriteLog.Write("获取记录:" + allCount);
         foreach (DataRow dr in ds.Tables[0].Rows)
         {
             Model.AccessModelLog model = DataRowToModel(dr);
             if (!AddLog(model))
             {
                 if (SyncProgress != null)
                 {
                     SyncProgress("添加记录失败:" + model.VisitTime + " " + (string.IsNullOrEmpty(model.CardNo) ? model.CardID : model.CardNo) + " " + model.VisiterName);
                     SeatManage.SeatManageComm.WriteLog.Write("添加记录失败:" + model.VisitTime + " " + (string.IsNullOrEmpty(model.CardNo) ? model.CardID : model.CardNo) + " " + model.VisiterName);
                 }
                 failCount++;
             }
             else
             {
                 if (SyncProgress != null)
                 {
                     SyncProgress("添加门禁记录:" + model.VisitTime + " " + (string.IsNullOrEmpty(model.CardNo) ? model.CardID : model.CardNo) + " " + model.VisiterName);
                     SeatManage.SeatManageComm.WriteLog.Write("添加门禁记录:" + model.VisitTime + " " + (string.IsNullOrEmpty(model.CardNo) ? model.CardID : model.CardNo) + " " + model.VisiterName);
                 }
                 successCount++;
             }
         }
         if (SyncProgress != null)
         {
             SyncProgress("同步完成:总计" + allCount + "条,成功" + successCount + "条,失败" + failCount + "条");
             SeatManage.SeatManageComm.WriteLog.Write("同步完成:总计" + allCount + "条,成功" + successCount + "条,失败" + failCount + "条");
         }
     }
     catch (Exception ex)
     {
         if (SyncProgress != null)
         {
             SyncProgress("同步失败:" + ex.Message);
         }
     }
 }
 /// <summary>
 /// 转化moel
 /// </summary>
 /// <param name="dr"></param>
 /// <returns></returns>
 private Model.AccessModelLog DataRowToModel(DataRow dr)
 {
     Model.AccessModelLog model = new Model.AccessModelLog();
     if (dr.Table.Columns.Contains("VisitID"))
     {
         model.VisitID = int.Parse(dr["VisitID"].ToString());
     }
     if (dr.Table.Columns.Contains("VisitTime"))
     {
         SeatManage.SeatManageComm.WriteLog.Write(dr["VisitTime"].ToString());
         model.VisitTime = DateTime.Parse(dr["VisitTime"].ToString());
     }
     if (dr.Table.Columns.Contains("CardNo"))
     {
         model.CardNo = dr["CardNo"].ToString().Trim();
     }
     if (dr.Table.Columns.Contains("CardID"))
     {
         model.CardNo = dr["CardID"].ToString();
     }
     if (dr.Table.Columns.Contains("VisierName"))
     {
         model.VisiterName = dr["VisierName"].ToString();
     }
     if (dr.Table.Columns.Contains("EnterOrExit"))
     {
         model.Enter = (Model.EnterState) int.Parse(dr["EnterOrExit"].ToString());
     }
     if (dr.Table.Columns.Contains("ChannelNo"))
     {
         model.ChannelNo = dr["ChannelNo"].ToString();
     }
     if (dr.Table.Columns.Contains("Flag"))
     {
         model.Flag = int.Parse(dr["Flag"].ToString());
     }
     //特殊处理
     if (!string.IsNullOrEmpty(libNo))
     {
         model.LibraryNo = libNo;
     }
     return(model);
 }
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        private bool AddLog(Model.AccessModelLog model)
        {
            string cmdstr = "INSERT INTO [AccessSyncLog]([VisitID],[VisitTime],[CardNo],[CardID],[VisierName],[Library],[EnterOrExit],[ChannelNo],[Flag],[HandleFlag])"
                            + "values('" + model.VisitID + "','"
                            + model.VisitTime + "','"
                            + model.CardNo + "','"
                            + model.CardID + "','"
                            + model.VisiterName + "','"
                            + model.LibraryNo + "','"
                            + (int)model.Enter + "','"
                            + model.ChannelNo + "','"
                            + model.Flag + "','"
                            + false + "')";
            //string sqlStr = string.Format(cmdstr, model.VisitID, model.VisitTime.ToString(), model.CardNo, model.CardID, model.VisiterName, model.LibraryNo, (int)model.Enter, model.ChannelNo, model.Flag, false);
            //SeatManage.SeatManageComm.WriteLog.Write(sqlStr);
            SqlCommand sqlcmd = new SqlCommand(cmdstr, SeatConn);
            int        count  = -1;

            try
            {
                SeatConn.Open();
                count = sqlcmd.ExecuteNonQuery();
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                SeatManage.SeatManageComm.WriteLog.Write("记录插入失败:" + ex.Message);
                throw ex;
            }
            finally
            {
                SeatConn.Close();
            }
        }