using System;
|
using System.Collections.Generic;
|
using System.Data.Entity;
|
using System.Text;
|
using WindowsFormsApp1.entity;
|
using WindowsFormsApp1.utils;
|
|
namespace WindowsFormsApp1
|
{
|
class DocUtil
|
{
|
|
public static List<FirstOrderSubInfo> ydGoodsList=new List<FirstOrderSubInfo>();
|
public static List<FirstOrderSubInfo> spGoodsList = new List<FirstOrderSubInfo>();
|
|
public static void AddYDGoods(FirstOrderSubInfo info) {
|
foreach (FirstOrderSubInfo i in ydGoodsList) {
|
if (i.GoodsId == info.GoodsId)
|
return;
|
}
|
ydGoodsList.Add(info);
|
}
|
|
public static void AddYDGoods(List<FirstOrderSubInfo> infoList)
|
{
|
if(infoList!=null)
|
foreach (FirstOrderSubInfo i in infoList)
|
{
|
AddYDGoods(i);
|
}
|
}
|
|
|
public static void AddSPGoods(FirstOrderSubInfo info)
|
{
|
foreach (FirstOrderSubInfo i in spGoodsList)
|
{
|
if (i.GoodsId == info.GoodsId)
|
return;
|
}
|
spGoodsList.Add(info);
|
}
|
|
|
public static void AddSPGoods(List<FirstOrderSubInfo> infoList)
|
{
|
foreach (FirstOrderSubInfo i in infoList)
|
{
|
AddSPGoods(i);
|
}
|
}
|
|
|
//表达式是否正确
|
public static bool IsRight(String doc) {
|
//匹配两个中括号
|
int start1= doc.IndexOf("[");
|
if (start1 <= -1) {
|
return false;
|
}
|
|
int end1 = doc.IndexOf("]", start1);
|
if (end1 <= -1) {
|
return false;
|
}
|
|
int start2 = doc.IndexOf("[", end1);
|
if (start2 <= -1)
|
{
|
return false;
|
}
|
|
int end2 = doc.IndexOf("]", start2);
|
if (end2 <= -1)
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
/**
|
* 获取模板
|
* 返回引单与实拍单的模板
|
*/
|
public static String[] GetOutSideTemplate(String doc) {
|
//匹配两个中括号
|
int start1 = doc.IndexOf("[");
|
if (start1 <= -1)
|
{
|
return null;
|
}
|
|
int end1 = doc.IndexOf("]", start1);
|
if (end1 <= -1)
|
{
|
return null;
|
}
|
|
int start2 = doc.IndexOf("[", end1);
|
if (start2 <= -1)
|
{
|
return null;
|
}
|
|
int end2 = doc.IndexOf("]", start2);
|
if (end2 <= -1)
|
{
|
return null;
|
}
|
String[] sts = new string[] { doc.Substring(start1+1, end1-(start1+1)), doc.Substring(start2+1, end2-(start2+1)) };
|
|
return sts;
|
}
|
|
//生成文案
|
public static String BuildDoc() {
|
String courseUrl = "http://www.baidu.com";
|
Config config = SQLiteDataBaseUtil.getInstance().GetConfig("sdlj_doc_template_own");
|
if (config == null) {
|
config = SQLiteDataBaseUtil.getInstance().GetConfig("sdlj_doc_template");
|
}
|
|
String template = config.Value;
|
|
String[] sts= GetOutSideTemplate(template);
|
if (sts == null||sts.Length<2)
|
return null;
|
//引单商品填充
|
StringBuilder ydSt = new StringBuilder();
|
for (int i = 0; i < ydGoodsList.Count; i++)
|
{
|
ydSt.Append(sts[0].Replace("{引单商品链接}", ydGoodsList[i].ItemUrl).Replace("{引单礼金面额}", ydGoodsList[i].LijinAmount).Replace("{引单教程链接}", courseUrl).Replace("{引单商品口令}", ydGoodsList[i].Tkl).Replace("{链接位置}", (i + 1) + ""));
|
if(i< ydGoodsList.Count-1)
|
ydSt.Append("\r\n");
|
}
|
|
StringBuilder spSt = new StringBuilder();
|
|
for (int i = 0; i < spGoodsList.Count; i++)
|
{
|
spSt.Append(sts[1].Replace("{实拍商品到手价}", spGoodsList[i].ActualPrice).Replace("{实拍商品标题}", spGoodsList[i].Title).Replace("{实拍商品链接}", spGoodsList[i].ItemUrl).Replace("{实拍商品口令}", spGoodsList[i].Tkl) + "\r\n");
|
}
|
|
return template.Replace("[" + sts[0] + "]", ydSt.ToString()).Replace("[" + sts[1] + "]", spSt.ToString());
|
}
|
}
|
}
|