コード例 #1
0
ファイル: CoreTest.cs プロジェクト: cfvbaibai/AllCheckins
        public void TestStorage()
        {
            using (IAllCheckinStorageProvider storageProvider = new AllCheckinSqlStorageProvider())
            {
                CheckinEntry entry = new CheckinEntry();
                entry.Id              = "111222";
                entry.Name            = "xxxxx";
                entry.TelephoneNumber = "3214323";
                storageProvider.SaveEntry(entry);

                storageProvider.SaveEntry(entry);
                entry.Id = "2222222";
                storageProvider.SaveEntry(entry);
            }
        }
コード例 #2
0
        public void SaveEntry(CheckinEntry entry)
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection  = conn;
                cmd.CommandText = "sp_kf_NewCheckinEntry_1";
                cmd.CommandType = CommandType.StoredProcedure;

                AddParameter(cmd, "@nvc_name", entry.Name);
                AddParameter(cmd, "@vc_idcard_number", entry.Id);
                AddParameter(cmd, "@si_gendre", (short)entry.Gendre);
                AddParameter(cmd, "@dt2_birthdate", entry.Birthdate);
                AddParameter(cmd, "@nvc_address", entry.Address);
                AddParameter(cmd, "@vc_cellphone_number", entry.CellPhoneNumber);
                AddParameter(cmd, "@vc_telephone_number", entry.TelephoneNumber);
                AddParameter(cmd, "@vc_mailbox", entry.Mailbox);
                AddParameter(cmd, "@dt2_checkin_time", entry.CheckinTime);
                cmd.ExecuteNonQuery();
            }
        }
コード例 #3
0
        private CheckinEntry ParseCheckinEntryFromRegexMatch(Match match)
        {
            var entry = new CheckinEntry();

            entry.Name = match.Groups["Name"].Value;
            entry.Id   = match.Groups["Id"].Value;
            var gendreText = match.Groups["Gendre"].Value;

            if (string.Equals("男", gendreText))
            {
                entry.Gendre = Gendre.Male;
            }
            else if (string.Equals("女", gendreText))
            {
                entry.Gendre = Gendre.Female;
            }
            else
            {
                entry.Gendre = Gendre.Other;
            }
            var      birthdateText = match.Groups["Birthdate"].Value;
            DateTime birthdate;

            if (DateTime.TryParseExact(
                    birthdateText, "yyyyMMdd", CultureInfo.InvariantCulture,
                    DateTimeStyles.None, out birthdate))
            {
                entry.Birthdate = birthdate;
            }
            entry.Address         = match.Groups["Address"].Value;
            entry.CellPhoneNumber = match.Groups["CellPhone"].Value;
            entry.TelephoneNumber = match.Groups["TelePhone"].Value;
            entry.Mailbox         = match.Groups["Mailbox"].Value;
            DateTime checkinTime;

            if (DateTime.TryParse(match.Groups["CheckinTime"].Value, out checkinTime))
            {
                entry.CheckinTime = checkinTime;
            }
            return(entry);
        }
コード例 #4
0
        public IEnumerable <CheckinEntry> GetEntries(QueryType queryType, string id)
        {
            string queryString = "";

            if (queryType == QueryType.Name)
            {
                queryString = "name=" + id + "&idcard=";
            }
            else if (queryType == QueryType.IdCardNumber)
            {
                queryString = "name=&idcard=" + id;
            }
            else
            {
                throw new ArgumentException("Invalid query type: " + queryType);
            }
            var response = webRobot.Post(QueryPageUrl, "application/x-www-form-urlencoded", queryString);

            /* response:
             * <table cellspacing="0" cellpadding="0" class="tb2">
             * <tr><th>姓名</th><th>证件</th><th>性别</th><th>生日</th><th>地址</th><th>手机</th><th>电话</th><th>邮箱</th><th>开房时间</th></tr>
             * <tr><td>周蓉琦</td><td>3</td><td>女</td><td></td><td>南大街14弄12号204-206室</td><td></td><td></td><td></td><td>2012-11-23 2:31:07</td></tr>
             * </table>
             */
            var result   = new List <CheckinEntry>();
            int iFirstTr = response.IndexOf("<tr>");

            if (iFirstTr < 0)
            {
                return(result);
            }
            int iTrBegin = response.IndexOf("<tr>", iFirstTr + 4);
            var lines    = new List <string>();

            while (iTrBegin >= 0)
            {
                int iTrEnd = response.IndexOf("</tr>", iTrBegin);
                if (iTrEnd < 0)
                {
                    lines.Add((response + "</tr>").Substring(iTrBegin));
                    iTrEnd = response.Length;
                }
                else
                {
                    lines.Add(response.Substring(iTrBegin, iTrEnd + 5 - iTrBegin));
                }
                iTrBegin = response.IndexOf("<tr>", iTrEnd + 5);
            }
            for (int i = 0; i < lines.Count; ++i)
            {
                var line = lines[i].ToString();
                line = line.Trim().Replace("\r\n", " ").Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ');
                var match = Regex.Match(line, EntryLinePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    CheckinEntry entry = ParseCheckinEntryFromRegexMatch(match);
                    result.Add(entry);
                }
                else
                {
                    Trace.TraceError("[id = {0}] Cannot parse entry line: {1}", id, line);
                }
            }
            return(result);
        }