82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Drawing;
|
|||
|
|
using System.Reflection;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
using WeiSha.Common;
|
|||
|
|
|
|||
|
|
using Song.ServiceInterfaces;
|
|||
|
|
using Song.Entities;
|
|||
|
|
using WeiSha.Common.Param;
|
|||
|
|
|
|||
|
|
namespace Song.Extend
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ɶ<EFBFBD>ά<EFBFBD><CEAC>
|
|||
|
|
/// </summary>
|
|||
|
|
public class QrCode
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// ͨ<><CDA8>ʵ<EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD>ɶ<EFBFBD>ά<EFBFBD><CEAC>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="entity"></param>
|
|||
|
|
/// <param name="template"><3E><>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3></param>
|
|||
|
|
/// <param name="wh"><3E><><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="qrcodeImgPath"><3E><>ά<EFBFBD><CEAC><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string Creat4Entity(WeiSha.Data.Entity entity, string template, string qrcodeImgPath, int wh)
|
|||
|
|
{
|
|||
|
|
Type info = entity.GetType();
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
|
PropertyInfo[] properties = info.GetProperties();
|
|||
|
|
for (int i = 0; i < properties.Length; i++)
|
|||
|
|
{
|
|||
|
|
PropertyInfo pi = properties[i];
|
|||
|
|
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD>Ե<EFBFBD>ֵ
|
|||
|
|
object obj = info.GetProperty(pi.Name).GetValue(entity, null);
|
|||
|
|
string patt = @"{\#\s*{0}\s*}";
|
|||
|
|
patt = patt.Replace("{0}", pi.Name);
|
|||
|
|
Regex re = new Regex(patt, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
|
|||
|
|
template = re.Replace(template, obj == null ? "" : obj.ToString());
|
|||
|
|
}
|
|||
|
|
template = QrCode.tranUrl(template);
|
|||
|
|
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>logo
|
|||
|
|
bool isCenterImg = Business.Do<ISystemPara>()["IsQrConterImage"].Boolean ?? true;
|
|||
|
|
string color = Business.Do<ISystemPara>()["QrColor"].String;
|
|||
|
|
System.Drawing.Image image=null;
|
|||
|
|
if (isCenterImg)
|
|||
|
|
{
|
|||
|
|
string centerImg = Upload.Get["Org"].Physics + "QrCodeLogo.png";
|
|||
|
|
image = WeiSha.Common.QrcodeHepler.Encode(template, wh, centerImg, color, null);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
image = WeiSha.Common.QrcodeHepler.Encode(template, wh, color, null);
|
|||
|
|
}
|
|||
|
|
image.Save(qrcodeImgPath);
|
|||
|
|
return qrcodeImgPath;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><CEAC>ģ<EFBFBD><C4A3><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD>~תΪ<D7AA><CEAA>·<EFBFBD><C2B7>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="url"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private static string tranUrl(string url)
|
|||
|
|
{
|
|||
|
|
Song.Entities.Organization org = Business.Do<IOrganization>().OrganDefault();
|
|||
|
|
//<2F><>ҵ<EFBFBD><D2B5>վ<EFBFBD><D5BE><EFBFBD><EFBFBD>
|
|||
|
|
string domain = org.Org_WebSite;
|
|||
|
|
if (domain != null && domain != "" && domain.Length >= 7)
|
|||
|
|
{
|
|||
|
|
if (domain.Substring(0, 7).ToLower() != "http://")
|
|||
|
|
{
|
|||
|
|
domain = "http://" + domain;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
url = url.Replace("~", domain);
|
|||
|
|
return url;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|