using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Xml;
using System.Text;
using ZWL.DBUtility;
namespace ZWL.Common
{
///
/// PublicMethod 的摘要说明
///
public class PublicMethod
{
public PublicMethod()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
///
/// 将树形菜单的各个节点对应的权限加载进入指定的CheckBoxList中
///
///
public static void AddItmesInCheCKList(CheckBoxList MYCHK)
{
DataSet MYDT = ZWL.DBUtility.DbHelperSQL.GetDataSet("select * from ERPTreeList where NavigateUrlStr!='' and NavigateUrlStr is not null order by PaiXuStr asc,ParentID asc,ID asc");
for (int i = 0; i < MYDT.Tables[0].Rows.Count; i++)
{
string[] CheckItems = new string[8] { "", "", "", "", "", "", "", "" };
CheckItems[0] = MYDT.Tables[0].Rows[i]["ValueStr"].ToString() + "_" + ZWL.DBUtility.DbHelperSQL.GetSHSL("select top 1 TextStr from ERPTreeList where ID=" + MYDT.Tables[0].Rows[i]["ParentID"].ToString()) + "--" + MYDT.Tables[0].Rows[i]["TextStr"].ToString() + "--查看";
string[] QuanXianList = MYDT.Tables[0].Rows[i]["QuanXianList"].ToString().Split('|');
for (int j = 0; j < QuanXianList.Length; j++)
{
CheckItems[j + 1] = QuanXianList[j];
}
//将前面设置好的CheckItems数组加入到CheckBoxList中
for (int k = 0; k < CheckItems.Length; k++)
{
if (CheckItems[k].Trim().Length <= 0)
{
ListItem ItemsTemp = new ListItem("", "");
MYCHK.Items.Add(ItemsTemp);
}
else
{
if (k == 0)
{
ListItem ItemsTemp = new ListItem(CheckItems[k].Split('_')[1], CheckItems[k].Split('_')[0]);
MYCHK.Items.Add(ItemsTemp);
}
else
{
ListItem ItemsTemp = new ListItem(CheckItems[k].Split('_')[1], MYDT.Tables[0].Rows[i]["ValueStr"].ToString() + CheckItems[k].Split('_')[0]);
MYCHK.Items.Add(ItemsTemp);
}
}
}
}
}
///
/// 将传入的用户名列表,按照工作委托的要求,自动置换成受委托后的用户名字符串,然后返回
///
///
///
public static string WorkWeiTuoUserList(string UserList)
{
string ReturnList = "";
string[] UserArray = UserList.Split(',');
for (int i = 0; i < UserArray.Length; i++)
{
if (UserArray[i].ToString().Trim().Length > 0)
{
string WeiTuoUser = ZWL.DBUtility.DbHelperSQL.GetSHSL("select top 1 ToUser from ERPNWorkFlowWT where FromUser='" + UserArray[i].ToString() + "'");
if (WeiTuoUser.Trim().Length > 0)
{
if (ReturnList.Trim().Length > 0)
{
if (StrIFIn("," + WeiTuoUser + ",", "," + ReturnList + ",") == false)
{
ReturnList = ReturnList + "," + WeiTuoUser;
}
}
else
{
ReturnList = WeiTuoUser;
}
}
else
{
if (ReturnList.Trim().Length > 0)
{
if (StrIFIn("," + UserArray[i].ToString() + ",", "," + ReturnList + ",") == false)
{
ReturnList = ReturnList + "," + UserArray[i].ToString();
}
}
else
{
ReturnList = UserArray[i].ToString();
}
}
}
}
return ReturnList;
}
//修改web.config节点的值
public static void EditAppValue(string KeyNameStr, string SetValueStr)
{
//修改web.config
XmlDocument xDoc = new XmlDocument();
try
{
//打开web.config
xDoc.Load(System.Web.HttpContext.Current.Request.MapPath("../Web.config"));
//string key;
XmlNode app;
app = xDoc.SelectSingleNode("/configuration/appSettings/add[@key='" + KeyNameStr + "']");
app.Attributes["value"].Value = SetValueStr;
//关闭
xDoc.Save(System.Web.HttpContext.Current.Request.MapPath("../web.config"));
System.Web.HttpContext.Current.Response.Write("");
}
catch (Exception ex)
{
System.Web.HttpContext.Current.Response.Write("");
}
finally
{
xDoc = null;
}
}
//得到文件列表--真实文件名
public static string GetWenJian(string WenJianList, string DirStr)
{
if (!string.IsNullOrEmpty(WenJianList))
{
string[] MyRange = WenJianList.Split('|');
string MyReturn = string.Empty;
for (int i = 0; i < MyRange.Length; i++)
{
if (MyRange[i].ToString().Trim().Length > 0)
{
if (MyReturn.Trim().Length > 0)
{
if (MyRange[i].ToString().IndexOf("MailAttachments/") >= 0)
{
MyReturn = MyReturn + "
" + MyRange[i].ToString().Replace("MailAttachments/", "") + "";
}
else
{
string OldNameStr = ZWL.DBUtility.DbHelperSQL.GetSHSL("select OldName from ERPSaveFileName where NowName='" + MyRange[i].ToString().Replace("MailAttachments/", "") + "'");
if (OldNameStr.Trim().Length <= 0)
{
OldNameStr = MyRange[i].ToString().Replace("MailAttachments/", "");
}
MyReturn = MyReturn + "
" + OldNameStr + "
";
}
}
else
{
if (MyRange[i].ToString().IndexOf("MailAttachments/") >= 0)
{
MyReturn = "
" + MyRange[i].ToString().Replace("MailAttachments/", "") + "";
}
else
{
string OldNameStr = ZWL.DBUtility.DbHelperSQL.GetSHSL("select OldName from ERPSaveFileName where NowName='" + MyRange[i].ToString().Replace("MailAttachments/", "") + "'");
if (OldNameStr.Trim().Length <= 0)
{
OldNameStr = MyRange[i].ToString().Replace("MailAttachments/", "");
}
MyReturn = "
" + OldNameStr + "
";
}
}
}
}
if (MyReturn.ToString().Trim().Length <= 0)
{
MyReturn = MyReturn + "无文件!";
}
return MyReturn;
}
return "无文件!";
}
//得到文件列表--32位数字串
public static string GetWenJian111(string WenJianList, string DirStr)
{
if (!string.IsNullOrEmpty(WenJianList))
{
string[] MyRange = WenJianList.Split('|');
string MyReturn = string.Empty;
for (int i = 0; i < MyRange.Length; i++)
{
if (MyRange[i].ToString().Trim().Length > 0)
{
if (MyReturn.Trim().Length > 0)
{
if (MyRange[i].ToString().IndexOf("MailAttachments/") >= 0)
{
MyReturn = MyReturn + "
" + MyRange[i].ToString().Replace("MailAttachments/", "") + "";
}
else
{
string OldNameStr = ZWL.DBUtility.DbHelperSQL.GetSHSL("select OldName from ERPSaveFileName where NowName='" + MyRange[i].ToString().Replace("MailAttachments/", "") + "'");
if (OldNameStr.Trim().Length <= 0)
{
OldNameStr = MyRange[i].ToString().Replace("MailAttachments/", "");
}
MyReturn = MyReturn + "
" + OldNameStr + "
";
}
}
else
{
if (MyRange[i].ToString().IndexOf("MailAttachments/") >= 0)
{
MyReturn = "
" + MyRange[i].ToString().Replace("MailAttachments/", "") + "";
}
else
{
string OldNameStr = ZWL.DBUtility.DbHelperSQL.GetSHSL("select OldName from ERPSaveFileName where NowName='" + MyRange[i].ToString().Replace("MailAttachments/", "") + "'");
if (OldNameStr.Trim().Length <= 0)
{
OldNameStr = MyRange[i].ToString().Replace("MailAttachments/", "");
}
MyReturn = "
" + OldNameStr + "
";
}
}
}
}
if (MyReturn.ToString().Trim().Length <= 0)
{
MyReturn = MyReturn + "无文件!";
}
return MyReturn;
}
return "无文件!";
}
///
/// 获取文件链接,同时加上阅读、编辑
///
///
///
///
public static string GetWenJian2(string WenJianList, string DirStr)
{
if (!string.IsNullOrEmpty(WenJianList))
{
string[] MyRange = WenJianList.Split('|');
string MyReturn = string.Empty;
for (int i = 0; i < MyRange.Length; i++)
{
if (MyRange[i].ToString().Trim().Length > 0)
{
if (MyReturn.Trim().Length > 0)
{
if (MyRange[i].ToString().IndexOf("MailAttachments/") >= 0)
{
MyReturn = MyReturn + "
" + MyRange[i].ToString().Replace("MailAttachments/", "") + "";
}
else
{
string OldNameStr = ZWL.DBUtility.DbHelperSQL.GetSHSL("select OldName from ERPSaveFileName where NowName='" + MyRange[i].ToString().Replace("MailAttachments/", "") + "'");
if (OldNameStr.Trim().Length <= 0)
{
OldNameStr = MyRange[i].ToString().Replace("MailAttachments/", "");
}
MyReturn = MyReturn + "
" + OldNameStr + "
";
}
}
else
{
if (MyRange[i].ToString().IndexOf("MailAttachments/") >= 0)
{
MyReturn = "
" + MyRange[i].ToString().Replace("MailAttachments/", "") + "";
}
else
{
string OldNameStr = ZWL.DBUtility.DbHelperSQL.GetSHSL("select OldName from ERPSaveFileName where NowName='" + MyRange[i].ToString().Replace("MailAttachments/", "") + "'");
if (OldNameStr.Trim().Length <= 0)
{
OldNameStr = MyRange[i].ToString().Replace("MailAttachments/", "");
}
MyReturn = "
" + OldNameStr + "
";
}
}
}
}
if (MyReturn.ToString().Trim().Length <= 0)
{
MyReturn = MyReturn + "无文件!";
}
return MyReturn;
}
return "无文件!";
}
//将ListItem1中的选中项加入ListItem2中,或者从ListItem2中减去选中项,CanShu1代表是添加,或者去除,CanShu2代表是全部选中项
public static string GetListStr(ListBox List1, ListBox List2, string CanShu1, string CanShu2)
{
if (CanShu1 == "添加")
{
if (CanShu2 == "全部")
{
//全部添加
for (int i = 0; i < List1.Items.Count; i++)
{
if (List2.Items.IndexOf(List1.Items[i]) < 0)
{
List2.Items.Add(List1.Items[i]);
}
}
}
else
{
//部分添加
for (int i = 0; i < List1.Items.Count; i++)
{
if (List1.Items[i].Selected == true)
{
if (List2.Items.IndexOf(List1.Items[i]) < 0)
{
List2.Items.Add(List1.Items[i]);
}
}
}
}
}
else
{
if (CanShu2 == "全部")
{
//全部去除
List2.Items.Clear();
}
else
{
//部分去除
for (int i = 0; i < List2.Items.Count; i++)
{
if (List2.Items[i].Selected == true)
{
List2.Items.Remove(List2.Items[i]);
i = i - 1;
}
}
}
}
//返回选中项的构建字符串
string ReturnStr = string.Empty;
for (int j = 0; j < List2.Items.Count; j++)
{
if (ReturnStr.Trim().Length > 0)
{
ReturnStr = ReturnStr + "," + List2.Items[j].Value.Trim();
}
else
{
ReturnStr = List2.Items[j].Value.Trim();
}
}
return ReturnStr;
}
//从checkBoxList里面读取选中的值
public static string GetStringFromCheckList(CheckBoxList MyChk)
{
string ReturnStr = string.Empty;
for (int i = 0; i < MyChk.Items.Count; i++)
{
if (MyChk.Items[i].Selected == true)
{
ReturnStr = ReturnStr + "|" + MyChk.Items[i].Value.ToString() + "|";
}
}
return ReturnStr;
}
//从checkBoxList里面读中字符串中有的值
public static void GetCheckList(CheckBoxList MyChk, string PerStr)
{
for (int i = 0; i < MyChk.Items.Count; i++)
{
if (StrIFIn("|" + MyChk.Items[i].Value.ToString() + "|", PerStr) == true)
{
MyChk.Items[i].Selected = true;
}
else
{
MyChk.Items[i].Selected = false;
}
}
}
//绑定字符串分隔开的到CheckBoxList--获得真实文件名
public static void BindDDL(CheckBoxList MyDDL, string FenGeStr)
{
MyDDL.Items.Clear();
string[] MyRange = FenGeStr.Split('|');
for (int i = 0; i < MyRange.Length; i++)
{
if (MyRange[i].ToString().Trim().Length > 0)
{
//将附件显示的text改为真实文件名
//string OldNameStr = ZWL.DBUtility.DbHelperSQL.GetSHSL("select OldName from ERPSaveFileName where NowName='" + MyRange[i].ToString().Replace("MailAttachments/", "") + "'");
string OldName = ZWL.DBUtility.DbHelperSQL.GetSHSL("select OldName from ERPSaveFileName where NowName = '" + MyRange[i].ToString().Trim() + "'");
ListItem MyListItem = new ListItem();
//MyListItem.Text = MyRange[i].ToString().Replace("MailAttachments/", "");
MyListItem.Text = OldName;
MyListItem.Value = MyRange[i].ToString();
MyDDL.Items.Add(MyListItem);
}
}
}
//绑定字符串分隔开的到dropdownlist
public static void BindDDLForEmPty(DropDownList MyDDL, string FenGeStr)
{
ListItem MyListItem1 = new ListItem();
MyListItem1.Text = "";
MyListItem1.Value = "";
MyDDL.Items.Add(MyListItem1);
string[] MyRange = FenGeStr.Split('|');
for (int i = 0; i < MyRange.Length; i++)
{
if (MyRange[i].ToString().Trim().Length > 0)
{
ListItem MyListItem = new ListItem();
MyListItem.Text = MyRange[i].ToString();
MyListItem.Value = MyRange[i].ToString();
MyDDL.Items.Add(MyListItem);
}
}
}
//绑定字符串分隔开的到CheckBoxList
public static void BindDDL(DropDownList MyDDL, string FenGeStr)
{
MyDDL.Items.Clear();
ListItem MyListItem1 = new ListItem();
string[] MyRange = FenGeStr.Split('|');
for (int i = 0; i < MyRange.Length; i++)
{
if (MyRange[i].ToString().Trim().Length > 0)
{
ListItem MyListItem = new ListItem();
MyListItem.Text = MyRange[i].ToString();
MyListItem.Value = MyRange[i].ToString();
MyDDL.Items.Add(MyListItem);
}
}
}
//在RowDataBound事件时使用
public static void GridViewRowDataBound(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E4F4FF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}
//判断GridView里面被选中的ID
public static string CheckCbx(GridView GVData, string CheckBoxName, string LabID)
{
string str = "";
for (int i = 0; i < GVData.Rows.Count; i++)
{
GridViewRow row = GVData.Rows[i];
CheckBox Chk = (CheckBox)row.FindControl(CheckBoxName);
Label LabVis = (Label)row.FindControl(LabID);
if (Chk.Checked == true)
{
if (str == "")
{
str = LabVis.Text.ToString();
}
else
{
str = str + "," + LabVis.Text.ToString();
}
}
}
return str;
}
//判断Str1是否是在Str2这个长的字符串中
public static bool StrIFIn(string Str1, string Str2)
{
if (Str2.IndexOf(Str1) < 0)
{
return false;
}
else
{
return true;
}
}
//将长字符串取前面250个,然后返回
public static string LongToShortStr(string LongStr, int StrNum)
{
try
{
return LongStr.Substring(0, StrNum);
}
catch
{
return LongStr;
}
}
//提取Html中的文字信息
public static string StripHTML(string strHtml)
{
string[] aryReg = { @"", @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>", @"([\r\n])[\s]+", @"&(quot|#34);", @"&(amp|#38);", @"&(lt|#60);", @"&(gt|#62);", @"&(nbsp|#160);", @"&(iexcl|#161);", @"&(cent|#162);", @"&(pound|#163);", @"&(copy|#169);", @"(\d+);", @"-->", @"