/// <summary>返回数字的保留2位小数格式</summary> /// <param name="dnum">数字</param> /// <returns>返回数字的保留2位小数格式</returns> public static double GetDouble(string dnum) { if (!Often.IsNum(dnum)) { dnum = "0"; } return(Convert.ToDouble(dnum)); }
/// <summary>如果输入的字符串不是数字则返回默认字符串值</summary> /// <param name="str">输入的字符串</param> /// <param name="defstr">默认字符串值</param> /// <returns>如果输入的字符串不是数字则返回默认字符串值</returns> public static string GetNum(string str, string defstr) { if (!Often.IsNum(str)) { return(defstr); } return(str); }
/// <summary>返回数字的保留2位小数格式</summary> /// <param name="dnum">数字</param> /// <param name="defval">默认值</param> /// <returns>返回数字的保留2位小数格式</returns> public static double GetDouble(string dnum, string defval) { if (!Often.IsNum(dnum)) { dnum = defval; } return(Convert.ToDouble(dnum)); }
/// <summary>返回数字的保留2位小数格式</summary> /// <param name="dnum">数字</param> /// <returns>返回数字的保留2位小数格式</returns> public static double GetNumber(string dnum) { if (!Often.IsNum(dnum)) { dnum = "0"; } return(GetHoldDigit(Convert.ToDouble(dnum), 2)); }
/// <summary>返回数据表字段的数字格式</summary> /// <param name="dr">数据行集合</param> /// <param name="cname">列名</param> /// <param name="row">行索引</param> /// <param name="defval">默认值</param> /// <returns>返回数据表字段的数字格式</returns> public static double GetDouble(DataRow[] dr, string cname, int row, string defval) { string val = DataOften.GetStr(dr, cname, row); if (!Often.IsNum(val)) { val = defval; } return(Convert.ToDouble(val)); }
/// <summary>返回数据表字段的数字格式</summary> /// <param name="dt">数据表</param> /// <param name="cname">列名</param> /// <param name="defval">默认值</param> /// <returns>返回数据表字段的数字格式</returns> public static double GetDouble(DataTable dt, string cname, string defval) { string val = DataOften.GetStr(dt, cname); if (!Often.IsNum(val)) { val = defval; } return(Convert.ToDouble(val)); }
/// <summary>返回数据表字段的数字格式</summary> /// <param name="dr">数据行集合</param> /// <param name="cname">列名</param> /// <returns>返回数据表字段的数字格式</returns> public static double GetDouble(DataRow[] dr, string cname) { string val = DataOften.GetStr(dr, cname); if (!Often.IsNum(val)) { val = "0"; } return(Convert.ToDouble(val)); }
/// <summary>返回数据表字段的数字格式</summary> /// <param name="dt">数据表</param> /// <param name="cname">列名</param> /// <param name="row">行索引</param> /// <param name="defval">默认值</param> /// <returns>返回数据表字段的数字格式</returns> public static double GetNumber(DataTable dt, string cname, int row, string defval) { string val = DataOften.GetStr(dt, cname, row); if (!Often.IsNum(val)) { val = defval; } return(GetHoldDigit(Convert.ToDouble(val), 2)); }
/// <summary>返回数据表字段的数字格式</summary> /// <param name="dt">数据表</param> /// <param name="cname">列名</param> /// <param name="row">行索引</param> /// <returns>返回数据表字段的数字格式</returns> public static double GetDouble(DataTable dt, string cname, int row) { string val = DataOften.GetStr(dt, cname, row); if (!Often.IsNum(val)) { val = "0"; } return(Convert.ToDouble(val)); }
/// <summary>返回数据表字段的数字格式</summary> /// <param name="dr">数据行集合</param> /// <param name="cname">列名</param> /// <param name="defval">默认值</param> /// <returns>返回数据表字段的数字格式</returns> public static double GetNumber(DataRow[] dr, string cname, string defval) { string val = DataOften.GetStr(dr, cname); if (!Often.IsNum(val)) { val = defval; } return(GetHoldDigit(Convert.ToDouble(val), 2)); }
/// <summary>返回数字的Byte整数格式,如果不是数字则返回0</summary> /// <param name="dnum">数字</param> /// <returns>返回数字的Byte整数格式,如果不是数字则返回0</returns> public static byte GetByte(string dnum) { if (Often.IsNum(dnum)) { double d = Convert.ToDouble(dnum); if (Often.IsByte(d)) { return(Convert.ToByte(d)); } } return(0); }
/// <summary>返回数据表字段的正整数格式</summary> /// <param name="dnum">数字</param> /// <returns>返回数据表字段的正整数格式</returns> public static int GetPInt(string dnum) { if (Often.IsNum(dnum)) { double d = Convert.ToDouble(dnum); if (Often.IsInt32(d) && d > 0) { return(Convert.ToInt32(d)); } } return(0); }
/// <summary>如果输入的字符串不是长整数则返回默认字符串值</summary> /// <param name="str">输入的字符串</param> /// <param name="defstr">默认字符串值</param> /// <returns>如果输入的字符串不是长整数则返回默认字符串值</returns> public static string GetInt64(string str, string defstr) { if (Often.IsNum(str)) { double d = Convert.ToDouble(str); if (Often.IsInt64(d)) { return(Convert.ToInt64(d).ToString()); } } return(defstr); }
/// <summary>返回数字的整数格式</summary> /// <param name="dnum">数字</param> /// <param name="defval">默认值</param> /// <returns>返回数字的整数格式</returns> public static int GetInt(string dnum, string defval) { if (Often.IsNum(dnum)) { double d = Convert.ToDouble(dnum); if (Often.IsInt32(d)) { return(Convert.ToInt32(d)); } } return(Convert.ToInt32(defval)); }
/// <summary>返回数据表字段的正数格式</summary> /// <param name="dnum">数字</param> /// <returns>返回数据表字段的正数格式</returns> public static double GetPDouble(string dnum) { if (!Often.IsNum(dnum)) { dnum = "0"; } double d = Convert.ToDouble(dnum); if (d < 0) { return(0); } return(d); }
/// <summary>返回数字的正数并保留2位小数格式</summary> /// <param name="dnum">数字</param> /// <returns>返回数字的正数并保留2位小数格式</returns> public static double GetPNumber(string dnum) { if (!Often.IsNum(dnum)) { dnum = "0"; } double d = Convert.ToDouble(dnum); if (d < 0) { return(0); } else { return(GetHoldDigit(Convert.ToDouble(dnum), 2)); } }
/// <summary>根据当前Url与Url内容采集数据</summary> public void GatherOper() { int cindex = 0; while (NowUrl.Trim() != "" && ListLinkContent.Trim() != "") { if (!IsListLinkEcho(NowUrl)) { string ListLinkArea = ""; if (gi.ws.UrlRangeRule != "") { ListLinkArea = wapp.GatherApp.GetRegTxtString(ListLinkContent, gi.ws.UrlRangeRule, gi.ws.UrlRangeRuleIndex); lout.OT(1, "获取内容页链接列表范围匹配内容。[" + ListLinkArea.Length.ToString() + "]"); } else { ListLinkArea = ListLinkContent; } if (ListLinkArea.Trim() != "") { List <string> linklist = wapp.GatherApp.GetRegTxtList(ListLinkArea, gi.ws.UrlRule, gi.ws.UrlRuleIndex); lout.OT(1, "获取内容页链接匹配数组[" + linklist.Count.ToString() + "]"); for (int x = 0; x < linklist.Count; x++) { StartDate = DateTime.Now; EndDate = StartDate; string links = wapp.GatherApp.FormatUrl(NowUrl, linklist[x].Trim()); if (!IsContLinkEcho(links)) { string actlink = links; NowContLinkList.Add(actlink); string errs = ""; string conts = wapp.GatherApp.GetHttp(det, actlink, gi.ws.CodingMode, ref PageEncoding, ref PageCoding, ref errs); if (errs != "") { lout.OT(1, "获取内容页起始url内容失败,错误信息:" + errs + "。[Url:" + actlink + "]"); } else { lout.OT(1, "获取内容页起始url内容。[" + actlink + "][" + conts.Length.ToString() + "]"); } DataRow nsdr = gi.gdt.NewRow(); for (int si = 0; si < gi.wsilist.Count; si++) { string sconts = ""; if (gi.wsilist[si].ContentRangeRule != "") { sconts = wapp.GatherApp.GetRegTxtString(conts, gi.wsilist[si].ContentRangeRule, gi.wsilist[si].ContentRangeRuleIndex); } else { sconts = conts; } string sis = ""; if (gi.wsilist[si].ContentType == 2) { sis = wapp.GatherApp.FormatDate(Often.OutTxt(wapp.GatherApp.GetUnCode(wapp.GatherApp.GetRegsTxt(sconts, gi.wsilist[si].ContentRule, gi.wsilist[si].ContentRuleIndex), gi.wsilist[si].ContentCodeMode))); } else { sis = wapp.GatherApp.GetUnCode(wapp.GatherApp.GetRegsTxt(sconts, gi.wsilist[si].ContentRule, gi.wsilist[si].ContentRuleIndex), gi.wsilist[si].ContentCodeMode); } if (gi.wsilist[si].ContentType == 1 && Often.IsNum(sis)) { nsdr[si] = sis; } else if (gi.wsilist[si].ContentType == 2 && Often.IsDate(sis)) { nsdr[si] = sis; } else { nsdr[si] = sis; } if (sis != "") { lout.OT(1, "[" + gi.wsilist[si].ListTitle + "(" + gi.wsilist[si].ListCode + ")]内容:[" + sis + "]采集成功!"); } } gi.gdt.Rows.Add(nsdr); GatherCount++; if (GatherCount >= gi.ws.GatherMaxNum) { return; } #region 保存采集内存表中的信息到数据库 if (gi.gdt.Rows.Count > 999) { string savefile = GetExcelSaveFileName(); lout.OT(1, "保存数据到Excel文件操作开始[文件名:" + savefile + "]..."); wapp.Excel ex = new wapp.Excel(); ex.DataTableToExcel(gi.gdt); ex.WriteFile(savefile); gi.gdt.Clear(); lout.OT(1, "保存数据到Excel文件操作结束[文件名:" + savefile + "]"); } #endregion } } } } string listurl = NowUrl; NowUrlList.Add(NowUrl); NowUrl = ""; if (gi.ws.IsNext == 1) { if (gi.ws.NextMode == 1) { #region 采集内容链接列表分页(列表分页为单页采集模式) if (CentUrlList.Count > 0 && cindex < CentUrlList.Count) { NowUrl = CentUrlList[cindex].Trim(); cindex++; } #endregion } else { #region 采集内容链接列表分页(列表分页为多页采集模式) if (gi.ws.NextRangeRule != "") { string s = wapp.GatherApp.GetRegTxtString(ListLinkContent, gi.ws.NextRangeRule, gi.ws.NextRangeRuleIndex); if (s != "") { s = wapp.GatherApp.GetRegsTxt(s, gi.ws.NextRule, gi.ws.NextRuleIndex); if (s != "") { NowUrl = wapp.GatherApp.GetUrls(wapp.GatherApp.FormatUrl(listurl, s)); } } } else { string s = wapp.GatherApp.GetRegsTxt(ListLinkContent, gi.ws.NextRule, gi.ws.NextRuleIndex); if (s != "") { NowUrl = wapp.GatherApp.GetUrls(wapp.GatherApp.FormatUrl(listurl, s)); } } #endregion } if (NowUrl != "" && !IsListLinkEcho(NowUrl)) { string errs = ""; ListLinkContent = wapp.GatherApp.GetHttp(det, NowUrl, gi.ws.CodingMode, ref PageEncoding, ref PageCoding, ref errs); if (errs != "") { ListLinkContent = ""; lout.OT(1, "列表页采集失败,错误信息:" + errs + ",[Url:" + NowUrl + "]"); } } else { ListLinkContent = ""; } } NowUrlCount++; } }
private void btbuild_Click(object sender, EventArgs e) { string s = rBa.Text; List <string> li = new List <string>(); if (rBa1.Checked) { string[] arr = s.Split(','); li = new List <string>(arr); } else if (rBa2.Checked) { string[] arr = s.Split('\n'); li = new List <string>(arr); } else if (rBa3.Checked) { string[] arr = s.Split('\r'); li = new List <string>(arr); } else if (rBa4.Checked) { string[] arr = s.Split('\t'); li = new List <string>(arr); } else if (rBa5.Checked) { string[] arr = s.Split('\v'); li = new List <string>(arr); } else if (rBa6.Checked) { string[] arr = s.Split('\f'); li = new List <string>(arr); } else if (rBa7.Checked) { string[] arr = Often.Split(s, rBta.Text); li = new List <string>(arr); } int js = 0; double zj = 0; bool isss = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < li.Count; i++) { string str = li[i].Trim(); if (str != "") { if (sb.Length > 0) { string fgf = ""; if (rBb1.Checked) { fgf = ","; } else if (rBb2.Checked) { fgf = "\n"; } else if (rBb3.Checked) { fgf = "\r"; } else if (rBb4.Checked) { fgf = "\t"; } else if (rBb5.Checked) { fgf = "\v"; } else if (rBb6.Checked) { fgf = "\f"; } else if (rBb7.Checked) { fgf = rBtb.Text; } sb.Append(fgf); } if (rBb7.Checked && rBtb.Text.Trim() == "+" && Often.IsNum(str)) { zj = zj + Convert.ToDouble(str); isss = true; js += 1; } else if (rBb7.Checked && rBtb.Text.Trim() == "-" && Often.IsNum(str)) { zj = zj - Convert.ToDouble(str); isss = true; js += 1; } else if (rBb7.Checked && rBtb.Text.Trim() == "*" && Often.IsNum(str)) { zj = zj * Convert.ToDouble(str); isss = true; js += 1; } else if (rBb7.Checked && rBtb.Text.Trim() == "/" && Often.IsNum(str)) { zj = zj / Convert.ToDouble(str); isss = true; js += 1; } sb.Append(rBtb1.Text); sb.Append(str); sb.Append(rBtb2.Text); } } if (isss) { sb.Append("\n\n累计次数:" + js.ToString() + ",总计:" + zj.ToString()); } rBb.Text = sb.ToString(); }