开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from 落云谷/QJ_OneLotus
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (3)
master
nemeng
Marketing
master
分支 (3)
master
nemeng
Marketing
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (3)
master
nemeng
Marketing
QJ_Single
/
QJY.API
/
CommonCode
/
CommonHelp.cs
QJ_Single
/
QJY.API
/
CommonCode
/
CommonHelp.cs
CommonHelp.cs 41.28 KB
一键复制 编辑 原始数据 按行查看 历史
一步莲华 提交于 2017年07月08日 21:42 +08:00 . 添加CRM模块中。。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using QJY.Data;
using System.Text.RegularExpressions;
using System.Net;
using System.Text;
using System.IO;
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
using System.Configuration;
using Newtonsoft.Json;
using NPOI.XSSF.UserModel;
namespace QJY.API
{
public class CommonHelp
{
/// <summary>
/// 从html中提取纯文本
/// </summary>
/// <param name="strHtml"></param>
/// <returns></returns>
public string StripHT(string strHtml) //从html中提取纯文本
{
Regex regex = new Regex("<.+?>", RegexOptions.IgnoreCase);
string strOutput = regex.Replace(strHtml, "");//替换掉"<"和">"之间的内容
strOutput = strOutput.Replace("<", "");
strOutput = strOutput.Replace(">", "");
strOutput = strOutput.Replace("&nbsp;", "");
return strOutput;
}
/// <summary>
/// 移除html标签
/// </summary>
/// <param name="html"></param>
/// <returns></returns>
public static string RemoveHtml(string html)
{
if (string.IsNullOrEmpty(html)) return html;
Regex regex = new Regex("<.+?>");
var matches = regex.Matches(html);
foreach (Match match in matches)
{
html = html.Replace(match.Value, "");
}
return html;
}
/// <summary>
/// 生成PCCode
/// </summary>
/// <param name="UserName"></param>
/// <returns></returns>
public static string CreatePCCode(JH_Auth_User user)
{
string strPCCode = EncrpytHelper.Encrypt(user.UserName + "@" + user.UserPass + "@" + DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
return strPCCode;
}
public static HttpWebResponse CreateHttpResponse(string url, IDictionary<string, string> parameters, int timeout, string userAgent, CookieCollection cookies, string strType = "POST")
{
HttpWebRequest request = null;
//如果是发送HTTPS请求
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
{
//ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
request = WebRequest.Create(url) as HttpWebRequest;
//request.ProtocolVersion = HttpVersion.Version10;
}
else
{
request = WebRequest.Create(url) as HttpWebRequest;
}
request.Method = strType;
request.ContentType = "application/x-www-form-urlencoded";
//设置代理UserAgent和超时
//request.UserAgent = userAgent;
//request.Timeout = timeout;
if (cookies != null)
{
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
}
//发送POST数据
if (!(parameters == null || parameters.Count == 0))
{
StringBuilder buffer = new StringBuilder();
int i = 0;
foreach (string key in parameters.Keys)
{
if (i > 0)
{
buffer.AppendFormat("&{0}={1}", key, parameters[key]);
}
else
{
buffer.AppendFormat("{0}={1}", key, parameters[key]);
i++;
}
}
byte[] data = Encoding.UTF8.GetBytes(buffer.ToString());
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
string[] values = request.Headers.GetValues("Content-Type");
return request.GetResponse() as HttpWebResponse;
}
/// <summary>
/// 创建POST方式的HTTP请求
/// </summary>
public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, int timeout, string userAgent, CookieCollection cookies, string strType = "POST")
{
HttpWebRequest request = null;
//如果是发送HTTPS请求
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
{
//ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
request = WebRequest.Create(url) as HttpWebRequest;
//request.ProtocolVersion = HttpVersion.Version10;
}
else
{
request = WebRequest.Create(url) as HttpWebRequest;
}
request.Method = strType;
request.ContentType = "application/x-www-form-urlencoded";
//设置代理UserAgent和超时
//request.UserAgent = userAgent;
//request.Timeout = timeout;
if (cookies != null)
{
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
}
//发送POST数据
if (!(parameters == null || parameters.Count == 0))
{
StringBuilder buffer = new StringBuilder();
int i = 0;
foreach (string key in parameters.Keys)
{
if (i > 0)
{
buffer.AppendFormat("&{0}={1}", key, parameters[key]);
}
else
{
buffer.AppendFormat("{0}={1}", key, parameters[key]);
i++;
}
}
byte[] data = Encoding.UTF8.GetBytes(buffer.ToString());
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
string[] values = request.Headers.GetValues("Content-Type");
return request.GetResponse() as HttpWebResponse;
}
/// <summary>
/// 获取请求的数据
/// </summary>
public static string GetResponseString(HttpWebResponse webresponse)
{
using (Stream s = webresponse.GetResponseStream())
{
StreamReader reader = new StreamReader(s, Encoding.Default);
return reader.ReadToEnd();
}
}
/// <summary>
/// 导出Excel
/// </summary>
/// <param name="table"></param>
/// <param name="fileName"></param>
public static MemoryStream RenderToExcel(DataTable table)
{
MemoryStream ms = new MemoryStream();
using (table)
{
IWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet();
IRow headerRow = sheet.CreateRow(0);
// handling header.
foreach (DataColumn column in table.Columns)
headerRow.CreateCell(column.Ordinal).SetCellValue(column.Caption);//If Caption not set, returns the ColumnName value
// handling value.
int rowIndex = 1;
foreach (DataRow row in table.Rows)
{
IRow dataRow = sheet.CreateRow(rowIndex);
foreach (DataColumn column in table.Columns)
{
dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());
}
rowIndex++;
}
workbook.Write(ms);
ms.Flush();
ms.Position = 0;
}
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
//{
// byte[] data = ms.ToArray();
// fs.Write(data, 0, data.Length);
// fs.Flush();
// data = null;
//}
return ms;
}
/// <summary>
/// excel转换为table
/// </summary>
/// <param name="upfile"></param>
/// <returns></returns>
public DataTable ExcelToTable(HttpPostedFile upfile, int headrow)
{
DataTable dt = new DataTable();
IWorkbook workbook = null;
Stream stream = upfile.InputStream;
string suffix = upfile.FileName.Substring(upfile.FileName.LastIndexOf(".") + 1).ToLower();
if (suffix == "xlsx") // 2007版本
{
workbook = new XSSFWorkbook(stream);
}
else if (suffix == "xls") // 2003版本
{
workbook = new HSSFWorkbook(stream);
}
//获取excel的第一个sheet
ISheet sheet = workbook.GetSheetAt(0);
//获取sheet的第一行
IRow headerRow = sheet.GetRow(headrow);
//一行最后一个方格的编号 即总的列数
int cellCount = headerRow.LastCellNum;
//最后一列的标号 即总的行数
int rowCount = sheet.LastRowNum;
//列名
for (int i = 0; i < cellCount; i++)
{
dt.Columns.Add(headerRow.GetCell(i).ToString());
}
for (int i = (sheet.FirstRowNum + headrow + 1); i <= sheet.LastRowNum; i++)
{
DataRow dr = dt.NewRow();
IRow row = sheet.GetRow(i);
for (int j = row.FirstCellNum; j < cellCount; j++)
{
if (row.GetCell(j) != null)
{
dr[j] = row.GetCell(j).ToString();
}
}
dt.Rows.Add(dr);
}
sheet = null;
workbook = null;
return dt;
}
static void RenderToBrowser(MemoryStream ms, HttpContext context, string fileName)
{
if (context.Request.Browser.Browser == "IE")
fileName = HttpUtility.UrlEncode(fileName);
context.Response.AddHeader("Content-Disposition", "attachment;fileName=" + fileName);
context.Response.BinaryWrite(ms.ToArray());
}
//
public static bool HasData(Stream excelFileStream)
{
using (excelFileStream)
{
IWorkbook workbook = new HSSFWorkbook(excelFileStream);
if (workbook.NumberOfSheets > 0)
{
ISheet sheet = workbook.GetSheetAt(0);
return sheet.PhysicalNumberOfRows > 0;
}
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="uploadUrl"></param>
/// <param name="fileToUpload"></param>
/// <param name="poststr"></param>
/// <returns></returns>
public static string PostFile(string uploadUrl, string fileToUpload, string poststr = "")
{
string result = "";
try
{
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uploadUrl);
webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
webrequest.Method = "POST";
StringBuilder sb = new StringBuilder();
if (poststr != "")
{
foreach (string c in poststr.Split('&'))
{
string[] item = c.Split('=');
if (item.Length != 2)
{
break;
}
string name = item[0];
string value = item[1];
sb.Append("–" + boundary);
sb.Append("\r\n");
sb.Append("Content-Disposition: form-data; name=\"" + name + "\"");
sb.Append("\r\n\r\n");
sb.Append(value);
sb.Append("\r\n");
}
}
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
sb.Append("Content-Disposition: form-data; name=\"file");
//sb.Append(fileFormName);
sb.Append("\"; filename=\"");
sb.Append(Path.GetFileName(fileToUpload));
sb.Append("\"");
sb.Append("\r\n");
sb.Append("Content-Type: application/octet-stream");
//sb.Append(contenttype);
sb.Append("\r\n");
sb.Append("\r\n");
string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);
byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
FileStream fileStream = new FileStream(fileToUpload, FileMode.Open, FileAccess.Read);
long length = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length;
webrequest.ContentLength = length;
Stream requestStream = webrequest.GetRequestStream();
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
byte[] buffer = new Byte[(int)fileStream.Length];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
requestStream.Write(buffer, 0, bytesRead);
}
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
fileStream.Close();
WebResponse responce = webrequest.GetResponse();
requestStream.Close();
using (Stream s = responce.GetResponseStream())
{
using (StreamReader sr = new StreamReader(s))
{
result = sr.ReadToEnd();
}
}
}
catch (Exception ex)
{
CommonHelp.WriteLOG(uploadUrl + "|||" + fileToUpload + "|||" + ex.ToString());
}
return result;
}
public static string ProcessWxIMG(string mediaIds, string strCode, JH_Auth_UserB.UserInfo UserInfo, string strType = ".jpg")
{
try
{
WXHelp wx = new WXHelp(UserInfo.QYinfo);
string ids = "";
foreach (var mediaId in mediaIds.Split(','))
{
string fileToUpload = wx.GetMediaFile(mediaId, strType);
string md5 = PostFile(UserInfo.QYinfo.FileServerUrl.TrimEnd('/') + "/fileupload?qycode=" + UserInfo.QYinfo.QYCode, fileToUpload);
System.IO.FileInfo f = new FileInfo(fileToUpload);
FT_File newfile = new FT_File();
newfile.ComId = UserInfo.User.ComId;
newfile.Name = f.Name;
newfile.FileMD5 = md5.Replace("\"", "");
newfile.FileSize = f.Length.ToString();
newfile.FileVersin = 0;
newfile.CRDate = DateTime.Now;
newfile.CRUser = UserInfo.User.UserName;
newfile.UPDDate = DateTime.Now;
newfile.UPUser = UserInfo.User.UserName;
newfile.FolderID = 3;
newfile.FileExtendName = f.Extension.Substring(1);
newfile.ISYL = "Y";
new FT_FileB().Insert(newfile);
if (ids == "")
{
ids = newfile.ID.ToString();
}
else
{
ids += "," + newfile.ID.ToString();
}
}
return ids;
}
catch (Exception ex)
{
CommonHelp.WriteLOG(ex.ToString());
return "";
}
}
public static string ProcessWxIMGUrl(string url, JH_Auth_UserB.UserInfo UserInfo, string strType = ".jpg")
{
try
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream reader = response.GetResponseStream();
string path = HttpContext.Current.Server.MapPath("\\temp\\");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string fileToUpload = path + Guid.NewGuid().ToString() + strType;
FileStream writer = new FileStream(fileToUpload, FileMode.OpenOrCreate, FileAccess.Write);
byte[] buff = new byte[512];
int c = 0; //实际读取的字节数
while ((c = reader.Read(buff, 0, buff.Length)) > 0)
{
writer.Write(buff, 0, c);
}
writer.Close();
writer.Dispose();
reader.Close();
reader.Dispose();
response.Close();
string URL = UserInfo.QYinfo.FileServerUrl + "fileupload?qycode=" + UserInfo.QYinfo.QYCode;
string md5 = PostFile(URL, fileToUpload);
System.IO.FileInfo f = new FileInfo(fileToUpload);
FT_File newfile = new FT_File();
newfile.ComId = UserInfo.User.ComId;
newfile.Name = f.Name;
newfile.FileMD5 = md5.Replace("\"", "");
newfile.FileSize = f.Length.ToString();
newfile.FileVersin = 0;
newfile.CRDate = DateTime.Now;
newfile.CRUser = UserInfo.User.UserName;
newfile.UPDDate = DateTime.Now;
newfile.UPUser = UserInfo.User.UserName;
newfile.FolderID = 3;
newfile.FileExtendName = f.Extension.Substring(1);
newfile.ISYL = "Y";
new FT_FileB().Insert(newfile);
return newfile.ID.ToString();
}
catch (Exception ex)
{
CommonHelp.WriteLOG(ex.ToString());
return "";
}
}
public static string SendDX(string Mobile, string Content, string SendTime)
{
try
{
string url = CommonHelp.GetConfig("DXURL") + "&Mobile=" + Mobile + "&Content=" + Content;
WebClient WC = new WebClient();
WC.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
int p = url.IndexOf("?");
string sData = url.Substring(p + 1);
url = url.Substring(0, p);
byte[] postData = Encoding.GetEncoding("gb2312").GetBytes(sData);
byte[] responseData = WC.UploadData(url, "POST", postData);
string returnData = Encoding.GetEncoding("gb2312").GetString(responseData);
return returnData;
}
catch (Exception Ex)
{
return Ex.Message;
}
}
public static string SendSMS(string telephone, string content, int ComId = 0)
{
string err = "";
try
{
string dxqz = "企捷科技";
decimal amcountmoney = 0;
var qy = new JH_Auth_QYB().GetEntity(d => d.ComId == ComId);
if (qy != null)
{
dxqz = qy.DXQZ;
amcountmoney = qy.AccountMoney.HasValue ? qy.AccountMoney.Value : 0;
}
string[] tels = telephone.Trim().Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace(',', ',').Split(',');
//判断金额是否够
decimal DXCost = decimal.Parse(CommonHelp.GetConfig("DXCost"));
decimal amount = tels.Length * DXCost;
if (ComId != 0 && amcountmoney < amount) //短信余额不足
{
err = "短信余额不足";
}
else
{
string re = "";
foreach (string tel in tels)
{
re = SendDX(tel, content + "【" + dxqz + "】", "");
}
err = "发送成功";
//扣款
if (ComId != 0 && qy != null)
{
qy.AccountMoney = qy.AccountMoney - amount;
new JH_Auth_QYB().Update(qy);
//记录明细
//SZHL_DDGL_ITEM im = new SZHL_DDGL_ITEM();
//im.ComId = qy.ComId;
//im.SerialID = DateTime.Now.ToString("yyyyMMddHHmmssfff");
//im.Change = -amount;
//im.Balance = amcountmoney - amount;
//im.Memo = "短信消费";
//im.Status = "已消费";
//im.CRDate = DateTime.Now;
//new SZHL_DDGL_ITEMB().Insert(im);
}
}
}
catch { }
return err;
}
private int rep = 0;
/// <summary>
/// 生成随机不重复的字符串(分享码用)
/// </summary>
/// <param name="codeCount"></param>
/// <returns></returns>
public string GenerateCheckCode(int codeCount)
{
string str = string.Empty;
long num2 = DateTime.Now.Ticks + this.rep;
this.rep++;
Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> this.rep)));
for (int i = 0; i < codeCount; i++)
{
char ch;
int num = random.Next();
if ((num % 2) == 0)
{
ch = (char)(0x30 + ((ushort)(num % 10)));
}
else
{
ch = (char)(0x41 + ((ushort)(num % 0x1a)));
}
str = str + ch.ToString();
}
return str;
}
/// <summary>
/// MD5加密
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string GetMD5(string content)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(content, "md5");
}
public static string GetConfig(string strKey,string strDefault="")
{
return ConfigurationManager.AppSettings[strKey] ?? strDefault;
}
/// <summary>
/// 获取数字验证码
/// </summary>
/// <param name="codenum"></param>
/// <returns></returns>
public static string numcode(int codenum)
{
string Vchar = "0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9";
string[] VcArray = Vchar.Split(',');
string[] stray = new string[codenum];
Random random = new Random();
for (int i = 0; i < codenum; i++)
{
int iNum = 0;
while ((iNum = Convert.ToInt32(VcArray.Length * random.NextDouble())) == VcArray.Length)
{
iNum = Convert.ToInt32(VcArray.Length * random.NextDouble());
}
stray[i] = VcArray[iNum];
}
string identifycode = string.Empty;
foreach (string s in stray)
{
identifycode += s;
}
return identifycode;
}
/// <summary>
/// 登录验证码
/// </summary>
/// <param name="codenum"></param>
/// <returns></returns>
public static string yzmcode(int codenum)
{
string Vchar = "0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,W,X,Y,Z";
string[] VcArray = Vchar.Split(',');
string[] stray = new string[codenum];
Random random = new Random();
for (int i = 0; i < codenum; i++)
{
int iNum = 0;
while ((iNum = Convert.ToInt32(VcArray.Length * random.NextDouble())) == VcArray.Length)
{
iNum = Convert.ToInt32(VcArray.Length * random.NextDouble());
}
stray[i] = VcArray[iNum];
}
string identifycode = string.Empty;
foreach (string s in stray)
{
identifycode += s;
}
return identifycode;
}
public static string getIPAddress()
{
string result = "";
try
{
result = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
// 如果使用代理,获取真实IP
if (result != null && result.IndexOf(".") == -1) //没有"."肯定是非IPv4格式
result = null;
else if (result != null)
{
if (result.IndexOf(",") != -1)
{
//有",",估计多个代理。取第一个不是内网的IP。
result = result.Replace(" ", "").Replace("'", "");
string[] temparyip = result.Split(",;".ToCharArray());
for (int i = 0; i < temparyip.Length; i++)
{
if (IsIPAddress(temparyip[i])
&& temparyip[i].Substring(0, 3) != "10."
&& temparyip[i].Substring(0, 7) != "192.168"
&& temparyip[i].Substring(0, 7) != "172.16.")
{
return temparyip[i]; //找到不是内网的地址
}
}
}
else if (IsIPAddress(result)) //代理即是IP格式
return result;
else
result = null; //代理中的内容 非IP,取IP
}
if (null == result || result == String.Empty)
result = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
if (result == null || result == String.Empty)
result = System.Web.HttpContext.Current.Request.UserHostAddress;
}
catch (Exception)
{
result = "";
}
return result;
}
private static bool IsIPAddress(string str1)
{
if (str1 == null || str1 == string.Empty || str1.Length < 7 || str1.Length > 15) return false;
string regformat = @"^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$";
Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
return regex.IsMatch(str1);
}
public static string getIpAddr(string ip = "")
{
string ipAddr = "";
try
{
string url = "http://1212.ip138.com/ic.asp";
System.Net.WebClient webClient = new System.Net.WebClient();
string strSource = webClient.DownloadString(url);
string regex = @"<center>.+</center>";
ipAddr = System.Text.RegularExpressions.Regex.Match(strSource, regex).ToString();
ipAddr = ipAddr.Replace("<center>您的IP是:", "");
ipAddr = ipAddr.Replace("</center>", "");
ipAddr = ipAddr.Replace("来自", "");
ipAddr = ipAddr.Split(':')[1];
ipAddr = ipAddr.Split(' ')[0];
}
catch (Exception ex)
{
return "";
}
return ipAddr;
}
public static void WriteLOG(string err)
{
try
{
string path = HttpContext.Current.Request.MapPath("/");
if (!Directory.Exists(path + "/log/"))
{
Directory.CreateDirectory(path + "/log/");
}
string name = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
if (!File.Exists(path + "/log/" + name))
{
FileInfo myfile = new FileInfo(path + "/log/" + name);
FileStream fs = myfile.Create();
fs.Close();
}
StreamWriter sw = File.AppendText(path + "/log/" + name);
sw.WriteLine(err + "\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
sw.Flush();
sw.Close();
}
catch (Exception)
{
}
}
/// <summary>
/// 获取导入excel的字段
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public List<IMPORTYZ> GetTable(string code, int comid)
{
string json = string.Empty;
switch (code)
{
case "KHGL":
json = "[{\"Name\":\"客户名称\",\"Length\":\"50\",\"IsNull\":\"1\",\"IsRepeat\":\"SZHL_CRM_KHGL|KHName\"},{\"Name\":\"客户类型\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"电话\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"邮箱\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"传真\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"网址\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"地址\",\"Length\":\"500\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"邮编\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"跟进状态\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"客户来源\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"所属行业\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"人员规模\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"负责人\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"备注\",\"Length\":\"0\",\"IsNull\":\"0\"}]";
break;
case "KHLXR":
json = "[{\"Name\":\"姓名\",\"Length\":\"50\",\"IsNull\":\"1\"},{\"Name\":\"对应客户\",\"Length\":\"50\",\"IsNull\":\"0\",\"IsExist\":\"SZHL_CRM_KHGL|KHName\"},"
+ "{\"Name\":\"手机\",\"Length\":\"11\",\"IsNull\":\"1\"},{\"Name\":\"邮箱\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"传真\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"网址\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"电话\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"分机\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"QQ\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"微信\",\"Length\":\"100\",\"IsNull\":\"0\"},"
//+ "{\"Name\":\"学历\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"公司\",\"Length\":\"100\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"部门\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"职位\",\"Length\":\"100\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"地址\",\"Length\":\"200\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"邮编\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"性别\",\"Length\":\"10\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"生日\",\"Length\":\"10\",\"IsNull\":\"0\"},{\"Name\":\"备注\",\"Length\":\"0\",\"IsNull\":\"0\"}]";
break;
case "HTGL":
json = "[{\"Name\":\"合同标题\",\"Length\":\"2500\",\"IsNull\":\"1\"},{\"Name\":\"合同类型\",\"Length\":\"50\",\"IsNull\":\"1\"},"
+ "{\"Name\":\"合同总金额\",\"Length\":\"100\",\"IsNull\":\"1\"},{\"Name\":\"签约日期\",\"Length\":\"10\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"对应客户\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"开始时间\",\"Length\":\"10\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"结束时间\",\"Length\":\"10\",\"IsNull\":\"0\"},{\"Name\":\"合同状态\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"关联产品\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"付款方式\",\"Length\":\"100\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"付款说明\",\"Length\":\"1500\",\"IsNull\":\"0\"},{\"Name\":\"有效期\",\"Length\":\"100\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"我方签约人\",\"Length\":\"50\",\"IsNull\":\"0\"},{\"Name\":\"客户方签约人\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"合同编号\",\"Length\":\"100\",\"IsNull\":\"0\"},{\"Name\":\"负责人\",\"Length\":\"50\",\"IsNull\":\"0\"},"
+ "{\"Name\":\"备注\",\"Length\":\"0\",\"IsNull\":\"0\"}]";
break;
}
if (comid != 0)
{
json = json.Substring(0, json.Length - 1);
DataTable dtExtColumn = new JH_Auth_ExtendModeB().GetExtColumnAll(comid, code);
foreach (DataRow drExt in dtExtColumn.Rows)
{
json = json + ",{\"Name\":\"" + drExt["TableFiledName"].ToString() + "\",\"Length\":\"0\",\"IsNull\":\"0\"}";
}
json = json + "]";
}
List<IMPORTYZ> cls = JsonConvert.DeserializeObject<List<IMPORTYZ>>(json);
return cls;
}
/// <summary>
/// 获取模板中的默认数据
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public string GetExcelData(string str)
{
string json = string.Empty;
switch (str)
{
case "KHGL":
json = "贸易公司, 普通客户,010-65881997,123@qq.com, 010-65881998, http://www.baidu.com/,"
+ "东三环中路101号,100000,初访,广告,服务,小于10人,13312345678,主营外贸销售,代理国外一线品牌";
break;
case "KHLXR":
json = "张三,贸易公司,13667894321,123@qq.com,010-65881997 ,http://www.baidu.com/,010-65881997,61601 ,1123213213,fassfd21421,"
+ "客户部,经理,东三环中路101号,100000,男,1983年09月13日,负责XX项目的实施";
break;
case "HTGL":
json = "XX项目,项目合同,12300,2015年07月08日,贸易公司,2015年07月08日,2015年12月08日,未开始,企业号项目, 银行转账,"
+ "服务,6个月,张经理,王经理,AC2001243251002,13312345678,合同备注";
break;
}
return json;
}
public class IMPORTYZ
{
public string Name { get; set; }
public int Length { get; set; }
public int IsNull { get; set; }
public string IsRepeat { get; set; }
public string IsExist { get; set; }
}
public string ExportToExcel(string Name, DataTable dt)
{
try
{
if (dt.Rows.Count > 0)
{
HSSFWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet("Sheet1");
ICellStyle HeadercellStyle = workbook.CreateCellStyle();
HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
HeadercellStyle.Alignment = HorizontalAlignment.Center;
HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
HeadercellStyle.FillPattern = FillPattern.SolidForeground;
HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
//字体
NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
headerfont.Boldweight = (short)FontBoldWeight.Bold;
headerfont.FontHeightInPoints = 12;
HeadercellStyle.SetFont(headerfont);
//用column name 作为列名
int icolIndex = 0;
IRow headerRow = sheet.CreateRow(0);
foreach (DataColumn dc in dt.Columns)
{
ICell cell = headerRow.CreateCell(icolIndex);
cell.SetCellValue(dc.ColumnName);
cell.CellStyle = HeadercellStyle;
icolIndex++;
}
ICellStyle cellStyle = workbook.CreateCellStyle();
//为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
cellfont.Boldweight = (short)FontBoldWeight.Normal;
cellStyle.SetFont(cellfont);
//建立内容行
int iRowIndex = 0;
foreach (DataRow dr in dt.Rows)
{
int iCellIndex = 0;
IRow irow = sheet.CreateRow(iRowIndex + 1);
for (int i = 0; i < dt.Columns.Count; i++)
{
string strsj = string.Empty;
if (dr[i] != null)
{
strsj = dr[i].ToString();
}
ICell cell = irow.CreateCell(iCellIndex);
cell.SetCellValue(strsj);
cell.CellStyle = cellStyle;
iCellIndex++;
}
iRowIndex++;
}
//自适应列宽度
for (int i = 0; i < icolIndex; i++)
{
sheet.AutoSizeColumn(i);
}
using (MemoryStream ms = new MemoryStream())
{
workbook.Write(ms);
HttpContext curContext = HttpContext.Current;
// 设置编码和附件格式
curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.ContentEncoding = Encoding.UTF8;
curContext.Response.Charset = "";
curContext.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + HttpUtility.UrlEncode(Name + "_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
curContext.Response.BinaryWrite(ms.GetBuffer());
workbook = null;
ms.Close();
ms.Dispose();
curContext.Response.End();
}
}
return "";
}
catch (Exception ex)
{
return "导出失败!";
}
}
public static string getIP(HttpContext context)
{
string ipAddr = "";
try
{
HttpRequest Request = context.Request;
// 如果使用代理,获取真实IP
if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != "")
ipAddr = Request.ServerVariables["REMOTE_ADDR"];
else
ipAddr = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddr == null || ipAddr == "")
ipAddr = Request.UserHostAddress;
return ipAddr;
}
catch (Exception ex)
{
return "";
}
return ipAddr;
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

基于微信企业号的协同工作平台
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/springjava/QJ_Single.git
git@gitee.com:springjava/QJ_Single.git
springjava
QJ_Single
QJ_Single
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /