/// <summary>
        /// 最后监听时间为 DateTime.MinValue
        /// </summary>
        /// <param name="mateWeb"></param>
        /// <returns></returns>
        private void InsertWeb(MateWeb mateWeb)
        {
            try
            {
                OpenCon();

                string sql = "INSERT INTO [Web] ([WebName],[WebUrl] ,[DetectionInterval],[LastCommunicationTime]) "
                             + " VALUES (@WebName,@WebUrl ,@DetectionInterval,@LastCommunicationTime);";
                _cmd = new SQLiteCommand(_conn);
                _cmd.Parameters.Add(new SQLiteParameter {
                    ParameterName = "@WebName", DbType = DbType.String, Value = mateWeb.WebName
                });
                _cmd.Parameters.Add(new SQLiteParameter {
                    ParameterName = "@WebUrl", DbType = DbType.String, Value = mateWeb.WebUrl
                });
                _cmd.Parameters.Add(new SQLiteParameter {
                    ParameterName = "@DetectionInterval", DbType = DbType.Int64, Value = mateWeb.DetectionInterval
                });
                _cmd.Parameters.Add(new SQLiteParameter {
                    ParameterName = "@LastCommunicationTime", DbType = DbType.DateTime, Value = DateTime.MinValue
                });

                _cmd.CommandText = sql;
                _cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("保存监听网站失败 : {0}  \t{1}", mateWeb.WebUrl, ex);
            }
            return;
        }
        /// <summary>
        /// 只更新网站名、网站监听间隔
        /// </summary>
        /// <param name="mateWeb"></param>
        private void UpdataWeb(MateWeb mateWeb)
        {
            try
            {
                OpenCon();
                string sql = "UPDATE [Web] SET [WebName] = @WebName , [DetectionInterval] = @DetectionInterval WHERE [Id] = @Id";

                _cmd = new SQLiteCommand(_conn);
                _cmd.Parameters.Add(new SQLiteParameter {
                    ParameterName = "@Id", DbType = DbType.Int32, Value = mateWeb.Id
                });
                _cmd.Parameters.Add(new SQLiteParameter {
                    ParameterName = "@WebName", DbType = DbType.String, Value = mateWeb.WebName
                });
                _cmd.Parameters.Add(new SQLiteParameter {
                    ParameterName = "@DetectionInterval", DbType = DbType.Int64, Value = mateWeb.DetectionInterval
                });
                _cmd.CommandText = sql;
                _cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("更新监听网站数据失败 : {0} \t{1}", mateWeb.WebUrl, ex);
            }
        }
        public int SaveWeb(MateWeb mateWeb, bool isSaveNoticeUser = false)
        {
            if (string.IsNullOrWhiteSpace(mateWeb.WebUrl))
            {
                throw new DbException(@"网站URL不存在");
            }

            int result = GetWebId(mateWeb.WebUrl);

            if (result < 0)
            {
                InsertWeb(mateWeb);
                result = GetWebId(mateWeb.WebUrl);
            }
            else
            {
                UpdataWeb(mateWeb);
            }
            if (isSaveNoticeUser)
            {
                mateWeb.Id = result;
                DeleteWebAllNoticeUser(mateWeb);

                foreach (MateNoticeUser noticeUser in mateWeb.NoticeUsers)
                {
                    OpenTransaction();
                    InsertNoticeUser(mateWeb.Id, noticeUser);
                    CloseTransaction();
                }
            }
            return(result);
        }
        private MateWeb SetMateWeb(DbDataReader read, bool isWithNoticeUser)
        {
            MateWeb result = new MateWeb()
            {
                Id                    = int.Parse(ObjToString(read["Id"])),
                WebName               = ObjToString(read["WebName"]),
                WebUrl                = ObjToString(read["WebUrl"]),
                DetectionInterval     = long.Parse(ObjToString(read["DetectionInterval"])),
                LastCommunicationTime = DateTime.Parse(ObjToString(read["LastCommunicationTime"]))
            };

            if (isWithNoticeUser)
            {
                result.NoticeUsers.AddRange(GetNoticeUsers(result));
            }

            return(result);
        }
        private void DeleteWebAllNoticeUser(MateWeb mateWeb)
        {
            try
            {
                OpenCon();
                string sql = "DELETE FROM [NoticeUser] WHERE [WebId] = @WebId;";

                _cmd = new SQLiteCommand(_conn);
                _cmd.Parameters.Add(new SQLiteParameter {
                    ParameterName = "@WebId", DbType = DbType.Int32, Value = mateWeb.Id
                });
                _cmd.CommandText = sql;
                _cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("删除监听网站通知用户失败 : {0} \t{1}", mateWeb.WebUrl, ex);
            }
        }
        public MateWeb GetWebErrorLogs(MateWeb mateWeb)
        {
            OpenCon();
            string sql = "SELECT * FROM [ErrorLog] WHERE [WebId] = @WebId ";

            _cmd = new SQLiteCommand(_conn)
            {
                CommandText = sql
            };
            _cmd.Parameters.Add(new SQLiteParameter {
                ParameterName = "@WebId", DbType = DbType.String, Value = mateWeb.Id
            });

            SQLiteDataReader read = _cmd.ExecuteReader();

            while (read.Read())
            {
                mateWeb.ErrorLogs.Add(SetErrorLog(read));
            }

            return(mateWeb);
        }
        private IEnumerable <MateNoticeUser> GetNoticeUsers(MateWeb mateWeb)
        {
            List <MateNoticeUser> result = new List <MateNoticeUser>();

            OpenCon();
            string sql = "SELECT * FROM [NoticeUser] WHERE [WebId] = @WebId ";

            _cmd = new SQLiteCommand(_conn)
            {
                CommandText = sql
            };
            _cmd.Parameters.Add(new SQLiteParameter {
                ParameterName = "@WebId", DbType = DbType.String, Value = mateWeb.Id
            });

            SQLiteDataReader read = _cmd.ExecuteReader();

            while (read.Read())
            {
                result.Add(SetMateNoticeUser(read));
            }
            return(result);
        }