199 lines
5.7 KiB
C#
199 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace SuperMap.RealEstate.HighWay.Handler.CommonInterface
|
|
{
|
|
public class CommonHelper
|
|
{
|
|
public const string charSet = "1,2,3,4,5,6,7,8,9";
|
|
|
|
#region 方法 -> 生成验证码
|
|
/// <summary>
|
|
/// 生成验证码
|
|
/// <param name="n">位数</param>
|
|
/// <returns>验证码字符串</returns>
|
|
public static string CreateRandomCode(int n)
|
|
{
|
|
string[] CharArray = charSet.Split(',');
|
|
string randomCode = "";
|
|
int temp = -1;
|
|
Random rand = new Random();
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
if (temp != -1)
|
|
{
|
|
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
|
|
}
|
|
int t = rand.Next(CharArray.Length - 1);
|
|
if (temp == t)
|
|
{
|
|
return CreateRandomCode(n);
|
|
}
|
|
temp = t;
|
|
randomCode += CharArray[t];
|
|
}
|
|
return randomCode;
|
|
}
|
|
#endregion
|
|
|
|
#region 方法 -> 获取get,post传参的值
|
|
public static string Request(string key)
|
|
{
|
|
|
|
var v = HttpContext.Current.Request.Form[key];
|
|
|
|
if (v == null)
|
|
{
|
|
v = HttpContext.Current.Request.QueryString[key];
|
|
}
|
|
|
|
return v ?? string.Empty;
|
|
}
|
|
#endregion
|
|
|
|
#region 方法 -> 获取DataTable前几条数据
|
|
/// <summary>
|
|
/// 获取DataTable前几条数据
|
|
/// </summary>
|
|
/// <param name="TopItem">前N条数据</param>
|
|
/// <param name="oDT">源DataTable</param>
|
|
/// <returns></returns>
|
|
public static DataTable DtSelectTop(int TopItem, DataTable oDT)
|
|
{
|
|
if (oDT.Rows.Count < TopItem) return oDT;
|
|
|
|
DataTable NewTable = oDT.Clone();
|
|
DataRow[] rows = oDT.Select("1=1");
|
|
for (int i = 0; i < TopItem; i++)
|
|
{
|
|
NewTable.ImportRow((DataRow)rows[i]);
|
|
}
|
|
return NewTable;
|
|
}
|
|
#endregion
|
|
|
|
#region 对象 -> 通用对象
|
|
/// <summary>
|
|
/// 通用对象
|
|
/// </summary>
|
|
/// <param name="ResultCode">返回结果</param>
|
|
/// <param name="FirstParameter">参数1</param>
|
|
/// <param name="SecondParameter">参数2</param>
|
|
/// <param name="ThirdParameter">参数3</param>
|
|
/// <param name="FourthParameter">参数4</param>
|
|
/// <param name="FifthParameter">参数5</param>
|
|
/// <param name="ResultDesc">备注信息</param>
|
|
public class ResultObject
|
|
{
|
|
/// <summary>
|
|
/// 返回结果
|
|
/// </summary>
|
|
public string ResultCode
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 参数1
|
|
/// </summary>
|
|
public string FirstParameter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 参数2
|
|
/// </summary>
|
|
public string SecondParameter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 参数3
|
|
/// </summary>
|
|
public string ThirdParameter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 参数4
|
|
/// </summary>
|
|
public string FourthParameter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 参数5
|
|
/// </summary>
|
|
public string FifthParameter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 参数6
|
|
/// </summary>
|
|
public string SixthParameter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 参数7
|
|
/// </summary>
|
|
public string SeventhParameter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 参数8
|
|
/// </summary>
|
|
public string EighthParameter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
/// <summary>
|
|
/// 备注
|
|
/// </summary>
|
|
public string ResultDesc
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 方法 -> 存储图片文件
|
|
public static bool UploadImg(byte[] fileBytes, string FilePath, string FileName)
|
|
{
|
|
bool flag = false;
|
|
try
|
|
{
|
|
string filePath = FilePath + FileName;//图片要保存的路径及文件名
|
|
using (MemoryStream memoryStream = new MemoryStream(fileBytes))//1.定义并实例化一个内存流,以存放提交上来的字节数组。
|
|
{
|
|
using (FileStream fileUpload = new FileStream(filePath, FileMode.Create))//2.定义实际文件对象,保存上载的文件。
|
|
{
|
|
memoryStream.WriteTo(fileUpload); ///3.把内存流里的数据写入物理文件
|
|
flag = true;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
SuperMap.RealEstate.Utility.ErrorLogHelper.Write(ex);
|
|
}
|
|
return flag;
|
|
}
|
|
#endregion
|
|
}
|
|
} |