using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Reflection; using System.Text.RegularExpressions; namespace SZUM.ZHZF.Framework.Utility { public class ComFunction { public static Version GetSystemVersion() { Assembly ass = Assembly.GetExecutingAssembly(); return ass.GetName().Version; } public static DateTime GetSystemUpdateDate() { Assembly ass = Assembly.GetExecutingAssembly(); string path = ToFilePath(ass.CodeBase); return File.GetLastWriteTime(path); } private static string ToFilePath(string url) { string ret = url.Replace("file:///", string.Empty); return ret.Replace("/", "//"); } public static void AddListItem(ListControl control, string value, string text) { ListItem item = new ListItem(); item.Text = text; item.Value = value; control.Items.Add(item); } /// <summary> /// 清页面 /// by wilson.fu /// </summary> /// <param name="parentControl"></param> public static void ClearText(Control parentControl) { foreach (Control childControl in parentControl.Controls) { if (childControl is TextBox) { (childControl as TextBox).Text = ""; } else if (childControl is DropDownList) { DropDownList ddl = childControl as DropDownList; if(ddl.Items.Count>0)ddl.SelectedIndex = 0; } else if (childControl is CheckBox) { (childControl as CheckBox).Checked = false; } else if (childControl is ListControl) { ListControl listControl = (childControl as ListControl); if (listControl != null) { foreach (ListItem li in listControl.Items) { li.Selected = false; } } } ClearText(childControl); } } public static void SetControlStatus(Control parentControl, bool isEnable) { foreach (Control childControl in parentControl.Controls) { if (childControl is WebControl) { WebControl webControl = childControl as WebControl; webControl.Enabled = isEnable; SetControlStatus(webControl, isEnable); } } } public static void DisableTextBox(TextBox textBox) { textBox.Attributes.Add("readonly", "true"); } public static string FormatDateTime(DateTime dateTime) { if (dateTime != DateTime.MinValue) { dateTime = dateTime.ToLocalTime(); return dateTime.ToString("yyyy-MM-dd HH:mm:ss"); } else { return ""; } } public static void SetListControlSelected(ListControl listControl, bool isSelected) { foreach (ListItem li in listControl.Items) { li.Selected = isSelected; } } public static string GetSystemTime() { return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } /// <summary> /// 读取客户端IP /// </summary> /// <returns></returns> public static string GetClientIP() { string ipAddress = ""; if (HttpContext.Current.Request["HTTP_X_FORWARDED_FOR"] == null) { ipAddress = HttpContext.Current.Request["Remote_Addr"]; } else { ipAddress = HttpContext.Current.Request["HTTP_X_FORWARDED_FOR"]; } return ipAddress; } / <summary> / 根据工作流定义ID读取表单信息 / </summary> / <param name="workflowId">工作流定义ID</param> / <returns>表单信息</returns> //public static ApprovalFormData FetchApprovalFormByWorkflowId(Guid workflowId) //{ // return ApprovalFormBLL.FetchApprovalFormByWorkflowId(workflowId); //} / <summary> / 根据用户ID读取工作流 / </summary> / <param name="userId"></param> / <returns></returns> //public static List<Guid> FetchSecondDeptWorkFlowByUserId(Guid userId) //{ // List<Guid> workflowIds = new List<Guid>(); // Guid secondDeptId = FetUserSecondDeptId(userId); // FetchWorkflowParameter fwfp = new FetchWorkflowParameter(); // fwfp.WorkflowStatus = WorkflowStatus.Normal; // fwfp.DepartmentID = secondDeptId; // WorkflowDataCollection wfdc = StateMachineWorkflowDefinitionManager.GetWorkflowDataList(fwfp); // foreach (WorkflowData workflow in wfdc) // { // workflowIds.Add(workflow.ID); // } // return workflowIds; //} //public static Guid FetchflowIdByUserIdAndDocType(Guid userId, int documentFlow) //{ // Guid secondDeptId = FetUserSecondDeptId(userId); // return DocumentWorkflowRelateDataBLL.GetWorkflowID(secondDeptId, documentFlow); //} //public static MembershipDataCollection FetchUserForRoleId(Guid roleId) //{ // MembershipDataCollection userDatas = null; // MembershipFetchResult result = MembershipManager.GetUsersForRole(roleId, true); // if (result.Succeed) // { // userDatas = result.ExecuteResult; // } // return userDatas; //} / <summary> / 取用户二级部门Id / </summary> / <param name="userId"></param> / <returns></returns> //public static Guid FetUserSecondDeptId(Guid userId) //{ // Guid secondDeptId = Guid.Empty; // #region // //MembershipData membershipData = MembershipManager.GetUserById(userId); // //Guid defaultDeptId = membershipData.DefaultDepartmentID; // //DepartmentFetchResult result = DepartmentManager.GetDepartments(defaultDeptId, 1, true); // //if (result.Succeed) // //{ // // DepartmentDataCollection deptCol = result.ExecuteResult; // // if (deptCol.Count > 0) // // { // // secondDeptId = deptCol[0].ID; // // } // // else // // { // // secondDeptId = defaultDeptId; // // } // //} // #endregion // secondDeptId = PMIHelperBLL.GetUserSencondDeptId(userId); // return secondDeptId; //} / <summary> / 判断环节是否为工作流的终止环节 / </summary> / <param name="workflowInstanceId">工作流实例Id</param> / <param name="activityId">环节标识</param> / <returns></returns> //public static bool CheckIsEndActivity(Guid workflowInstanceId, Guid activityId, bool isDefault) //{ // bool result = false; // InstanceData instanceData = null; // if (isDefault) // { // instanceData = StateMachineWorkflowRuntimeManager.GetDefaultNextStates(workflowInstanceId, null); // } // else // { // instanceData = StateMachineWorkflowRuntimeManager.GetAttemperStates(workflowInstanceId, null); // } // foreach (ActivityInstanceData actInst in instanceData.ActivityInstances) // { // if (actInst.Activity.ActivityIdentifier == activityId) // { // if (actInst.Activity.ActivityType == ActivityType.Stop || // actInst.Activity.ActivityType == ActivityType.Completed) // { // result = true; // break; // } // } // } // return result; //} //public class SmsInfo //{ // private Guid senderId; // private Guid targetUserId; // private string content; // public Guid SendId // { // set // { // this.senderId = value; // } // get // { // return this.senderId; // } // } // public Guid TargetUserId // { // set // { // this.targetUserId = value; // } // get // { // return this.targetUserId; // } // } // public string Content // { // get // { // return this.content; // } // set // { // this.content = value; // } // } //} / <summary> / 发送个人短信 / </summary> / <param name="senderId">发送者ID</param> / <param name="targetUserId">接受者Id</param> / <param name="content">短信内容</param> //public static void SendUserSmsByThreadPool(Guid senderId, Guid targetUserId, string content) //{ // try // { // SmsInfo sms = new SmsInfo(); // sms.SendId = senderId; // sms.TargetUserId = targetUserId; // sms.Content = content; // System.Threading.WaitCallback mycall = new System.Threading.WaitCallback(ComFunction.SendUserSmsBySmsInfo); // System.Threading.ThreadPool.QueueUserWorkItem(mycall, sms); // } // catch (System.Exception ex) // { // throw new Exception(ex.Message); // } //} / <summary> / 构造以线程池的方式发送SMS / </summary> / <param name="mysms"></param> //private static void SendUserSmsBySmsInfo(object mysms) //{ // SmsInfo sms = (SmsInfo)mysms; // ComFunction.SendUserSms(sms.SendId, sms.TargetUserId, sms.Content); //} / <summary> / 发送个人短信 / </summary> / <param name="senderId">发送者ID</param> / <param name="targetUserId">接受者Id</param> / <param name="content">短信内容</param> //public static void SendUserSms(Guid senderId, Guid targetUserId, string content) //{ // Topevery.PMI.ObjectModel.AddressData addressData = AddressManager.GetAddressbyID(targetUserId); // string mobileNo = addressData.Mobile; // using (TransactionScope ts = new TransactionScope()) // { // SmsSendData smsData = null; // if (!string.IsNullOrEmpty(mobileNo)) // { // smsData = new SmsSendData(); // smsData.ID = Guid.NewGuid(); // smsData.Flag = 1; // smsData.OrderNum = 0; // smsData.DbCreatedID = senderId; // smsData.DbLastUpdatedID = senderId; // smsData.DbCreatedDate = DateTime.Now; // smsData.DbLastUpdatedDate = DateTime.Now; // smsData.DbStatus = 0; // smsData.AcceptNum = mobileNo; // smsData.SendDatetime = DateTime.Now; // smsData.Content = content; // smsData.SendType = 3; // smsData.SenderID = senderId; // smsData.SuccessSendDatetime = DateTime.Now; // //smsData.StatusCode=""; // //smsData.SenderSmsCode = ""; // //smsData.FID = ""; // //smsData.IsStencil = ""; // SmsSendManager.InsertSmsSend(smsData); // } // if (IsLianTou(mobileNo)) // SMSManager.SendLianTou(mobileNo, content); // else if (IsYiDong(mobileNo)) // SMSManager.SendSMSDataExchange(smsData); // else // throw new Exception("该号码不是有效的号码!"); // ts.Complete(); // } //} / <summary> / 发送个人短信 / </summary> / <param name="senderId">发送者ID</param> / <param name="targetUserId">接受者Id</param> / <param name="content">短信内容</param> //public static void SendDeptSmsByThreadPool(Guid senderId, Guid targetUserId, string content) //{ // try // { // SmsInfo sms = new SmsInfo(); // sms.SendId = senderId; // sms.TargetUserId = targetUserId; // sms.Content = content; // System.Threading.WaitCallback mycall = new System.Threading.WaitCallback(ComFunction.SendUDeptSmsBySmsInfo); // System.Threading.ThreadPool.QueueUserWorkItem(mycall, sms); // } // catch (System.Exception ex) // { // throw new Exception(ex.Message); // } //} / <summary> / 构造以线程池的方式发送SMS / </summary> / <param name="mysms"></param> //private static void SendUDeptSmsBySmsInfo(object mysms) //{ // SmsInfo sms = (SmsInfo)mysms; // ComFunction.SendDeptSms(sms.SendId, sms.TargetUserId, sms.Content); //} / <summary> / 发送部门短信 / </summary> / <param name="senderId">发送者ID</param> / <param name="targetDeptId">接受部门ID</param> / <param name="content">短信内容</param> //public static void SendDeptSms(Guid senderId, Guid targetDeptId, string content) //{ // MembershipFetchResult result = MembershipManager.GetUsersForDepartment(targetDeptId, false); // if (result.Succeed) // { // MembershipDataCollection userCol = result.ExecuteResult; // foreach (MembershipData userData in userCol) // { // SendUserSms(senderId, userData.ID, content); // } // } //} //是否联通手机号码 private static bool IsLianTou(string num) { Regex r = new Regex(@"^13[0123]/d{8}|15[36]/d{8}$"); return r.IsMatch(num); } //是否移动 private static bool IsYiDong(string num) { Regex r = new Regex(@"^13[456789]/d{8}|15[089]/d{8}$"); return r.IsMatch(num); } /// <summary> /// Eric.Xu /// /// 切割字符转换成Guid /// </summary> /// <param name="queryValue"></param> /// <param name="querySplit"></param> /// <returns></returns> public static List<Guid> StringSplitConvertToGuid(string queryValue, char querySplit) { List<Guid> result = new List<Guid>(); string[] vals = queryValue.Split(querySplit); foreach (string i in vals) { if (!string.IsNullOrEmpty(i)) { result.Add(new Guid(i)); } } return result; } } } 以上为源码. 需要时可以直接使用.