📄 labelmanage.cs
字号:
namespace PowerEasy.Templates
{
using PowerEasy.Components;
using PowerEasy.Enumerations;
using PowerEasy.IDal.TemplateProc;
using PowerEasy.Model.TemplateProc;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Xml;
public sealed class LabelManage
{
private static readonly ILabelManage dal = DataAccess.CreateLabelManage();
private LabelManage()
{
}
public static bool Add(LabelManageInfo ainfo)
{
string path = HttpContext.Current.Server.MapPath("~/" + LabelLibPath);
try
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
if (!Exists(ainfo.Name))
{
File.WriteAllText(HttpContext.Current.Server.MapPath("~/" + LabelLibPath) + @"\" + ainfo.Name + ".config", ainfo.Define.ToString(), Encoding.UTF8);
return true;
}
return false;
}
catch (IOException)
{
return false;
}
}
public static bool AddAttribute(string xmlfilepath, string attributename, string defaultvalue, string intro)
{
if (!string.IsNullOrEmpty(attributename))
{
string strA = attributename.ToLower();
if ((((string.Compare(strA, "id") != 0) && (string.Compare(strA, "page") != 0)) && ((string.Compare(strA, "pagesize") != 0) && (string.Compare(strA, "begintime") != 0))) && ((string.Compare(strA, "endtime") != 0) && (string.Compare(strA, "outtime") != 0)))
{
XmlDocument document = new XmlDocument();
try
{
document.Load(xmlfilepath);
XmlNode node = document.SelectSingleNode("root");
XmlElement newChild = document.CreateElement("", "attributes", "");
XmlElement element2 = document.CreateElement("", "name", "");
XmlText text = document.CreateTextNode(attributename);
element2.AppendChild(text);
newChild.AppendChild(element2);
element2 = document.CreateElement("", "default", "");
text = document.CreateTextNode(defaultvalue);
element2.AppendChild(text);
newChild.AppendChild(element2);
element2 = document.CreateElement("", "intro", "");
text = document.CreateTextNode(intro);
element2.AppendChild(text);
newChild.AppendChild(element2);
node.AppendChild(newChild);
document.Save(xmlfilepath);
return true;
}
catch (XmlException)
{
return false;
}
}
}
return false;
}
public static bool AttributeExists(string xmlfilepath, string attributename)
{
XmlDocument document = new XmlDocument();
try
{
bool flag = true;
document.Load(xmlfilepath);
foreach (XmlNode node in document.SelectNodes("root/attributes"))
{
if (string.Compare(attributename, node.FirstChild.InnerText, true) == 0)
{
flag = false;
break;
}
}
return flag;
}
catch (XmlException)
{
return true;
}
}
public static bool Copy(string labelName)
{
string sourceFileName = HttpContext.Current.Server.MapPath("~/" + LabelLibPath) + @"\" + labelName + ".config";
string destFileName = HttpContext.Current.Server.MapPath("~/" + LabelLibPath) + @"\";
for (int i = 1; i < 100; i++)
{
string path = destFileName + labelName + "(" + i.ToString() + ").config";
if (!File.Exists(path))
{
destFileName = path;
break;
}
}
try
{
File.Copy(sourceFileName, destFileName, false);
}
catch (IOException)
{
return false;
}
return true;
}
public static bool Delete(string labelNames)
{
foreach (string str in labelNames.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
{
string path = HttpContext.Current.Server.MapPath("~/" + LabelLibPath) + @"\" + str + ".config";
try
{
if (File.Exists(path))
{
File.Delete(path);
}
}
catch (IOException)
{
return false;
}
}
return true;
}
public static bool DeleteAttribute(string xmlfilepath, string attributename)
{
XmlDocument document = new XmlDocument();
try
{
document.Load(xmlfilepath);
foreach (XmlNode node in document.SelectNodes("root/attributes"))
{
if (string.Compare(node.FirstChild.InnerText, attributename, true) == 0)
{
node.ParentNode.RemoveChild(node);
break;
}
}
document.Save(xmlfilepath);
return true;
}
catch (XmlException)
{
return false;
}
}
public static bool Exists(string iname)
{
return File.Exists(HttpContext.Current.Server.MapPath("~/" + LabelLibPath) + @"\" + iname + ".config");
}
public static IList<LabelAttributeInfo> GetAttributeList(string xmlfilepath)
{
XmlDocument document = new XmlDocument();
IList<LabelAttributeInfo> list = new List<LabelAttributeInfo>();
if (string.IsNullOrEmpty(xmlfilepath))
{
return list;
}
try
{
document.Load(xmlfilepath);
foreach (XmlNode node in document.SelectNodes("root/attributes"))
{
LabelAttributeInfo item = new LabelAttributeInfo(node.ChildNodes.Item(0).InnerText, node.ChildNodes.Item(1).InnerText, node.ChildNodes.Item(2).InnerText);
list.Add(item);
}
return list;
}
catch (XmlException exception)
{
LabelAttributeInfo info2 = new LabelAttributeInfo("error", string.Empty, exception.ToString());
list.Add(info2);
return list;
}
}
public static LabelManageInfo GetCacheLabelByName(string labelName)
{
string str2;
string key = "CK_Label_LabelManageInfo_" + labelName;
if (HttpContext.Current != null)
{
str2 = HttpContext.Current.Server.MapPath("~/" + LabelLibPath) + @"\" + labelName + ".config";
}
else
{
str2 = AppDomain.CurrentDomain.BaseDirectory + LabelLibPath + @"\" + labelName + ".config";
}
LabelManageInfo labelByName = SiteCache.Get(key) as LabelManageInfo;
if (labelByName == null)
{
labelByName = GetLabelByName(labelName);
if (File.Exists(str2))
{
SiteCache.Insert(key, labelByName, new CacheDependency(str2));
}
}
return labelByName;
}
public static string GetDBQuery(string dbtype, string dbconn, string sqlstr, XmlNodeList attrib)
{
switch (dbtype)
{
case "sql_sysquery":
return dal.GetMainDBQuery(sqlstr, attrib, false);
case "sql_sysstoredquery":
return dal.GetMainDBQuery(sqlstr, attrib, true);
case "sql_outquery":
return dal.GetOutSqlDBQuery(dbconn, sqlstr);
case "ole_read":
return dal.GetOleDBQuery(dbconn, sqlstr);
case "odbc_read":
return dal.GetOdbcDBQuery(dbconn, sqlstr);
case "orc_read":
return dal.GetOracleDBQuery(dbconn, sqlstr);
}
return string.Empty;
}
public static LabelManageInfo GetLabelByName(string labelName)
{
string str;
XmlDocument document = new XmlDocument();
LabelManageInfo info = new LabelManageInfo();
if (HttpContext.Current != null)
{
str = HttpContext.Current.Server.MapPath("~/" + LabelLibPath) + @"\" + labelName + ".config";
}
else
{
str = AppDomain.CurrentDomain.BaseDirectory + LabelLibPath + @"\" + labelName + ".config";
}
if (!File.Exists(str))
{
return new LabelManageInfo(true);
}
try
{
FileInfo info2 = new FileInfo(str);
using (StreamReader reader = info2.OpenText())
{
document.Load(reader);
info.Name = labelName;
info.Type = document.SelectSingleNode("root/LabelType").InnerText;
info.Define = new StringBuilder(document.InnerXml.ToString());
info.Template = new StringBuilder(document.SelectSingleNode("root/LabelTemplate").InnerText);
return info;
}
}
catch (XmlException)
{
return new LabelManageInfo(true);
}
return info;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -