public FolderSearchModel(FolderSearch Search, IList<Folder> Folders)
 {
     this.Search = Search;
     this.Folders = Folders;
 }
        public FolderSearchModel Search(FolderSearch packet)
        {
            FolderSearchModel result = new FolderSearchModel();

            SqlServerUtility sql = new SqlServerUtility();

            sql.AddParameter("@id", SqlDbType.Int, GetSqlValue(packet.Id > 0 ? (object)packet.Id : null));
            sql.AddParameter("@foldername", SqlDbType.NVarChar, GetSqlValue(packet.FolderName));
            sql.AddParameter("@keyword", SqlDbType.NVarChar, GetSqlValue(packet.KeyWord));
            sql.AddParameter("@photographer", SqlDbType.NVarChar, GetSqlValue(packet.Photographer));
            sql.AddParameter("@leader", SqlDbType.NVarChar, GetSqlValue(packet.Leader));
            sql.AddParameter("@otherleader", SqlDbType.NVarChar, GetSqlValue(packet.OtherLeader));
            sql.AddParameter("@guest", SqlDbType.NVarChar, GetSqlValue(packet.Guest));
            sql.AddParameter("@location", SqlDbType.NVarChar, GetSqlValue(packet.Location));
            sql.AddParameter("@eventinfo", SqlDbType.Int, GetSqlValue(packet.EventInfo > 0 ? (object)packet.EventInfo : null));
            sql.AddParameter("@eventdesc", SqlDbType.NVarChar, GetSqlValue(packet.EventInfoDesc));
            sql.AddParameter("@status", SqlDbType.Int, packet.Status != null ? (object)packet.Status.Value : (object)DBNull.Value);
            SqlDataReader reader = sql.ExecuteSqlReader(SqlSearch);

            IList<Folder> folders = new List<Folder>();

            if (reader != null)
            {
                while (reader.Read())
                {
                    Core.Business.PicNode picNode = new Core.Business.PicNode();

                    if (!reader.IsDBNull(0)) picNode.Id = reader.GetInt32(0);
                    if (!reader.IsDBNull(1)) picNode.Status = reader.GetInt32(1);
                    if (!reader.IsDBNull(2)) picNode.IsFile = reader.GetBoolean(2);
                    if (!reader.IsDBNull(3)) picNode.Root = reader.GetString(3);
                    if (!reader.IsDBNull(4)) picNode.Path = reader.GetString(4);
                    if (!reader.IsDBNull(5)) picNode.Name = reader.GetString(5);

                    picNode.MarkOld();

                    FolderDesc folderDesc = new FolderDesc();

                    if (!reader.IsDBNull(6)) folderDesc.Id = reader.GetInt32(6);
                    if (!reader.IsDBNull(7)) folderDesc.EventInfo = reader.GetInt32(7);
                    if (!reader.IsDBNull(8)) folderDesc.StartDate = reader.GetDateTime(8);
                    if (!reader.IsDBNull(9)) folderDesc.EndDate = reader.GetDateTime(9);
                    if (!reader.IsDBNull(10)) folderDesc.KeyWord = reader.GetString(10);
                    if (!reader.IsDBNull(11)) folderDesc.Photographer = reader.GetString(11);
                    if (!reader.IsDBNull(12)) folderDesc.Leader = reader.GetString(12);
                    if (!reader.IsDBNull(13)) folderDesc.OtherLeader = reader.GetString(13);
                    if (!reader.IsDBNull(14)) folderDesc.Guest = reader.GetString(14);
                    if (!reader.IsDBNull(15)) folderDesc.InnerLocation = reader.GetString(15);
                    if (!reader.IsDBNull(16)) folderDesc.OuterLocation = reader.GetString(16);
                    if (!reader.IsDBNull(17)) folderDesc.EventDesc = reader.GetString(17);

                    folders.Add(new Folder(picNode, folderDesc));
                }
                reader.Close();
            }

            result.Folders = folders;
            result.Search = packet;

            return result;
        }