📄 surveymanager.cs
字号:
namespace PowerEasy.Survey
{
using PowerEasy.Common;
using PowerEasy.IDal.Survey;
using PowerEasy.Model.Survey;
using System;
using System.Collections.Generic;
public sealed class SurveyManager
{
private static readonly ISurveyManager dal = DataAccess.CreateSurvey();
private SurveyManager()
{
}
public static bool Add(SurveyInfo surveyInfo)
{
return dal.Add(DoHtmlEncode(surveyInfo));
}
private static bool CheckBlackLockIP(double checkIP, string[] arrBlackLockIP)
{
foreach (string str in arrBlackLockIP)
{
string[] strArray = str.Split(new string[] { "----" }, StringSplitOptions.RemoveEmptyEntries);
if (((strArray.Length == 2) && (DataConverter.CDouble(strArray[0]) <= checkIP)) && (checkIP <= DataConverter.CDouble(strArray[1])))
{
return true;
}
}
return false;
}
public static bool CheckIPLock(string userIP, SurveyInfo surveyInfo)
{
bool flag = false;
string[] strArray = surveyInfo.SetIPLock.Split(new string[] { "|||" }, StringSplitOptions.None);
if (strArray.Length >= 2)
{
double checkIP = StringHelper.EncodeIP(userIP);
string[] arrWhiteLockIP = strArray[0].Split(new string[] { "$$$" }, StringSplitOptions.RemoveEmptyEntries);
string[] arrBlackLockIP = strArray[1].Split(new string[] { "$$$" }, StringSplitOptions.RemoveEmptyEntries);
switch (surveyInfo.LockIPType)
{
case 1:
return !CheckWhiteLockIP(checkIP, arrWhiteLockIP);
case 2:
return CheckBlackLockIP(checkIP, arrBlackLockIP);
case 3:
if (CheckWhiteLockIP(checkIP, arrWhiteLockIP))
{
if (CheckBlackLockIP(checkIP, arrBlackLockIP))
{
flag = true;
}
return flag;
}
return true;
case 4:
return (CheckBlackLockIP(checkIP, arrBlackLockIP) && !CheckWhiteLockIP(checkIP, arrWhiteLockIP));
}
}
return flag;
}
public static bool CheckLockUrl(string url, SurveyInfo surveyInfo)
{
return (string.IsNullOrEmpty(surveyInfo.LockUrl) || StringHelper.FoundInArr(surveyInfo.LockUrl, url, "\n"));
}
public static bool CheckRepeatIP(string userIP, int surveyId, SurveyInfo surveyInfo)
{
return (dal.GetRecordNumByIP(userIP, surveyId) >= surveyInfo.IPRepeat);
}
private static bool CheckWhiteLockIP(double checkIP, string[] arrWhiteLockIP)
{
foreach (string str in arrWhiteLockIP)
{
string[] strArray = str.Split(new string[] { "----" }, StringSplitOptions.RemoveEmptyEntries);
if (((strArray.Length == 2) && (DataConverter.CDouble(strArray[0]) <= checkIP)) && (checkIP <= DataConverter.CDouble(strArray[1])))
{
return true;
}
}
return false;
}
public static bool Delete(string surveyId)
{
bool flag = false;
if (!string.IsNullOrEmpty(surveyId) && DataValidator.IsValidId(surveyId))
{
flag = dal.Delete(surveyId);
if (!flag)
{
return flag;
}
SurveyVote.Delete(surveyId);
foreach (string str in surveyId.Split(new char[] { ',' }))
{
SurveyRecord.DeleteTable(DataConverter.CLng(str));
}
}
return flag;
}
private static SurveyInfo DoHtmlDecode(SurveyInfo surveyInfo)
{
surveyInfo.Description = DataSecurity.HtmlDecode(surveyInfo.Description);
surveyInfo.FileName = DataSecurity.HtmlDecode(surveyInfo.FileName);
surveyInfo.LockUrl = DataSecurity.HtmlDecode(surveyInfo.LockUrl);
surveyInfo.SurveyName = DataSecurity.HtmlDecode(surveyInfo.SurveyName);
surveyInfo.Template = DataSecurity.HtmlDecode(surveyInfo.Template);
return surveyInfo;
}
private static SurveyInfo DoHtmlEncode(SurveyInfo surveyInfo)
{
surveyInfo.Description = DataSecurity.HtmlEncode(surveyInfo.Description);
surveyInfo.FileName = DataSecurity.HtmlEncode(surveyInfo.FileName);
surveyInfo.LockUrl = DataSecurity.HtmlEncode(surveyInfo.LockUrl);
surveyInfo.SurveyName = DataSecurity.HtmlEncode(surveyInfo.SurveyName);
surveyInfo.Template = DataSecurity.HtmlEncode(surveyInfo.Template);
return surveyInfo;
}
public static string GetDecodeLockIP(string lockIP, int ipType)
{
string[] strArray = lockIP.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
try
{
return StringHelper.DecodeLockIP(strArray[ipType]);
}
catch (IndexOutOfRangeException)
{
return "";
}
}
public static IList<SurveyInfo> GetList(int startRowIndexId, int maxNumberRows, int searchType, string keyword)
{
if (((searchType == 1) || (searchType == 2)) && !string.IsNullOrEmpty(keyword))
{
keyword = DataConverter.CDate(keyword).ToString("yyyy-MM-dd");
}
return dal.GetList(startRowIndexId, maxNumberRows, searchType, keyword);
}
public static int GetMaxId()
{
return dal.GetMaxId();
}
public static string GetStateName(int surveyState)
{
switch (surveyState)
{
case 0:
return "未启用";
case 1:
return "启用";
case 2:
return "禁用";
}
return "未启用";
}
public static SurveyInfo GetSurveyById(int id)
{
return GetSurveyById(id, true);
}
public static SurveyInfo GetSurveyById(int id, bool isDecode)
{
SurveyInfo surveyById = dal.GetSurveyById(id);
if (isDecode)
{
surveyById = DoHtmlDecode(surveyById);
}
return surveyById;
}
public static int GetTotalOfSurvey(int searchType, string keyword)
{
return dal.GetTotalOfSurvey();
}
public static bool SetForbid(int surveyId)
{
return dal.SetForbid(surveyId);
}
public static bool SetPassed(int surveyId)
{
bool flag = false;
if (dal.SetPassed(surveyId))
{
flag = true;
string questionField = dal.GetSurveyById(surveyId).QuestionField;
string tableName = "PE_SurveyRecord" + surveyId;
IList<SurveyFieldInfo> list = new List<SurveyFieldInfo>();
foreach (SurveyFieldInfo info2 in SurveyField.DeserializeFieldList(questionField))
{
if (!SurveyField.AddFieldToTable(info2, tableName))
{
return false;
}
}
}
return flag;
}
public static bool SetPassedOfForbid(int surveyId)
{
return dal.SetPassedOfForbid(surveyId);
}
public static bool SurveyIdOfPassedExists(int surveyId)
{
return dal.SurveyIdOfPassedExists(surveyId);
}
public static bool Update(SurveyInfo surveyInfo)
{
return dal.Update(DoHtmlEncode(surveyInfo));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -