/// <summary> /// 根据列名称将datatable转化list(模版列名不能变化) /// </summary> /// <param name="dt"></param> /// <returns></returns> private List <OpenRecord> datatableToList(DataTable dt, ref bool ERRFLAG) { List <OpenRecord> entityList = new List <OpenRecord>(); if (dt != null) { removeEmptyDataRow(ref dt); try { foreach (DataRow row in dt.Rows) { OpenRecord entity = new OpenRecord(); entity.lineName = row["线路名称"].ToString() + "路"; entity.carNum = row["车辆编号"].ToString(); entity.owiner = row["钥匙卡/持卡人"].ToString(); entity.ouCardNum = row["换出内胆编号"].ToString(); entity.inCardNum = row["换入内胆编号"].ToString(); entity.recordTime = DateTime.Parse(row["记录时间"].ToString(), new DateTimeFormatInfo() { FullDateTimePattern = "MM/dd/yyyy HH:mm" }).ToString("yyyy-MM-dd HH:mm"); entityList.Add(entity); } } catch (Exception err) { ERRFLAG = true; AppInfo.WriteLogs(err.Message); } } return(entityList); }
//获取最近N期 public override List <OpenRecord> GetOldOpenCode(int num) { HttpItem item = new HttpItem() { URL = base.Url + "/member/dresult?lottery=PK10JSC", Method = "Get", UserAgent = "Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit /537.36(KHTML,likeGecko)Chrome/58.0.3029.110Safari/537.36SE2.XMetaSr1.0", Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", Cookie = Cookie }; var res = helper.GetHtml(item); var regBalls = new Regex(@"<tr>\s+<td class=""period"">(?<expectNo>.*?)</td>\s+<td class=""drawTime"">(?<drawTime>.*?)</td>(?<numStr>.*?)<td class=""other1"">.*?</td>.*?</tr>", RegexOptions.Singleline); var matches = regBalls.Matches(res.Html); List <OpenRecord> records = new List <OpenRecord>(); foreach (Match m in matches) { var numStr = m.Groups["numStr"].Value; var numsReg = new Regex(@"<td class=""name ballname""><span class="".*?"">(?<num>.*?)</span></td>"); var numsMatch = numsReg.Matches(numStr); var openNum = ""; foreach (Match match in numsMatch) { var numCode = match.Groups["num"].Value; if (Convert.ToInt32(numCode) <= 9) { numCode = "0" + numCode; } openNum += numCode + ","; } openNum = openNum.Substring(0, openNum.Length - 1); var newRecord = new OpenRecord() { OpenTime = DateTime.Now.Year + "-" + m.Groups["drawTime"].Value.Substring(0, 5) + " " + m.Groups["drawTime"].Value.Substring(7), ExpectNo = m.Groups["expectNo"].Value, OpenNo = openNum }; records.Add(newRecord); } var resList = records.OrderByDescending(d => d.ExpectNo).Take(num).ToList(); return(resList); }
/// <summary> /// 根据列名称将datatable转化list(模版列名不能变化) /// </summary> /// <param name="dt"></param> /// <returns></returns> private List <OpenRecord> datatableToList(DataTable dt) { List <OpenRecord> entityList = new List <OpenRecord>(); if (dt != null) { foreach (DataRow row in dt.Rows) { OpenRecord entity = new OpenRecord(); entity.lineName = row["线路名称"].ToString() + "路"; entity.carNum = row["车辆编号"].ToString(); entity.owiner = row["钥匙卡/持卡人"].ToString(); entity.ouCardNum = row["换出内胆编号"].ToString(); entity.inCardNum = row["换入内胆编号"].ToString(); entity.recordTime = row["记录时间"].ToString(); entityList.Add(entity); } } return(entityList); }
/// <summary> /// 向数据库插入数据 /// </summary> /// <param name="entityList"></param> private void insertDataToDataBase(List <OpenRecord> entityList) { int minCount = 0; while (minCount < entityList.Count) { int maxCount = entityList.Count > 30 + minCount ? 30 + minCount : entityList.Count; StringBuilder sql = new StringBuilder("insert into gj_opencaserecords (线路名称,车牌号,持卡人,换出内胆编号,换入内胆编号,记录时间) select * from ( "); for (int i = minCount; i < maxCount; i++) { OpenRecord entity = entityList[i]; sql.Append("select '").Append(entity.lineName + "' 线路名称,'").Append(entity.carNum + "' 车牌号,'").Append(entity.owiner + "' 持卡人,'").Append(entity.ouCardNum + "' 换出内胆编号,'").Append(entity.inCardNum + " ' 换入内胆编号,'").Append(entity.recordTime).Append("' 记录时间 from dual "); if (i < maxCount - 1) { sql.Append(" union all "); } } sql.Append(" )"); bool result = RCD.RCDB.Execute(sql.ToString()); minCount += 30; } }
/// <summary> /// 向数据库插入数据 /// </summary> /// <param name="entityList"></param> private void insertDataToDataBase(List <OpenRecord> entityList, ref bool ERRFLAG) { if (ERRFLAG) { return; } int minCount = 0; try { while (minCount < entityList.Count) { int maxCount = entityList.Count > 30 + minCount ? 30 + minCount : entityList.Count; StringBuilder sql = new StringBuilder("insert into gj_opencaserecords (线路名称,车牌号,持卡人,换出内胆编号,换入内胆编号,记录时间) select * from ( "); for (int i = minCount; i < maxCount; i++) { OpenRecord entity = entityList[i]; sql.Append("select '").Append(entity.lineName + "' 线路名称,'").Append(entity.carNum + "' 车牌号,'").Append(entity.owiner + "' 持卡人,'").Append(entity.ouCardNum + "' 换出内胆编号,'").Append(entity.inCardNum + " ' 换入内胆编号,to_date('").Append(entity.recordTime).Append("','yyyy-MM-dd HH24:mi:ss') 记录时间 from dual "); if (i < maxCount - 1) { sql.Append(" union all "); } } sql.Append(" )"); //AppInfo.WriteLogs(sql.ToString()); //ORACLEHelper helper = new ORACLEHelper(); ORACLEHelper.ExecuteSql(sql.ToString()); //bool result = RCD.RCDB.Execute(sql.ToString()); minCount += 30; } } catch (Exception err) { ERRFLAG = true; AppInfo.WriteLogs(err.Message); } }