/// <summary> /// 写INI文件 /// </summary> /// <param name="Section"></param> /// <param name="Key"></param> /// <param name="Value"></param> public void IniWriteValue(string Section, string Key, string Value) { try { WritePrivateProfileString(Section, Key, Value, this.path); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "IniWriteValue", ex.ToString(), Section, Key, Value); } finally { } }
/// <summary> /// 文档签入 /// </summary> /// <param name="siteUrl">指定站点地址</param> /// <param name="folderName">指定文档库名称</param> /// <param name="fileName">指定文档名称</param> /// <param name="comment">签入的注释</param> /// <returns>返回操作提示</returns> public string CheckIn(string folderName, string fileName, string comment) { //声明一个操作提示 string result = null; try { if (clientContext != null) { //创建客户端对象模型 using (clientContext) { //设置默认凭据 //通过标题获取文档库 Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(folderName); //加载该文档库 LoadMethod(documentsList); //加载该文档库的文档集合 LoadMethod(documentsList.RootFolder.Files); //循环遍历该文档库里的文档 foreach (var item in documentsList.RootFolder.Files) { //获取指定名称的文档 if (item.Name.Equals(fileName)) { //加载文档的版本控制 LoadMethod(item.Versions); //签入文档 item.CheckIn(comment, CheckinType.MajorCheckIn); //执行操作 clientContext.ExecuteQuery(); //生成提示 result = "签入成功"; } } } } } catch (Exception ex) { //生成提示 result = "该文档已签入"; MethodLb.CreateLog(this.GetType().FullName, "CheckIn", ex.ToString(), folderName, fileName, comment); } finally { } return(result); }
/// <summary> /// 控件关联 /// </summary> /// <param name="LayouRoot">拖动对象的终极父容器</param> /// <param name="stack1">字段区域</param> private void ControlInit(Grid LayouRoot, StackPanel stack1) { try { //拖动对象的终极父容器 this.gridLayouRoot = LayouRoot; //字段区域 this.stackPanel1 = stack1; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ControlInit", ex.ToString(), LayouRoot, stack1); } }
/// <summary> /// 移动文档 /// </summary> /// <param name="siteUrl">指定站点地址</param> /// <param name="folderName1">指定文档库名称(移动源)</param> /// <param name="folderName2">指定文档库名称(移动目标)</param> /// <param name="fileName">指定文档名称</param> /// <returns>返回操作提示</returns> public string MoveFile(string folderName1, string folderName2, string fileName) { //操作结果提示 string result = null; try { if (clientContext != null) { //创建客户端对象模型 using (clientContext) { //设置默认凭据 //通过标题获取文档库 Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(folderName1); LoadMethod(documentsList); LoadMethod(documentsList.RootFolder.Files); Microsoft.SharePoint.Client.File file = null; foreach (var item in documentsList.RootFolder.Files) { if (item.Name.Equals(fileName)) { file = item; } } //通过标题获取文档库 Microsoft.SharePoint.Client.List documentsList2 = clientContext.Web.Lists.GetByTitle(folderName2); LoadMethod(documentsList2); LoadMethod(documentsList2.RootFolder); //获取文档库url var d = documentsList2.RootFolder.ServerRelativeUrl; file.MoveTo(d + "/" + fileName, MoveOperations.Overwrite); clientContext.ExecuteQuery(); result = "文档移动成功"; } } } catch (Exception ex) { result = "文档移动失败"; MethodLb.CreateLog(this.GetType().FullName, "MoveFile", ex.ToString(), folderName1, folderName2, fileName); } finally { } return(result); }
public static void Kill(Microsoft.Office.Interop.Excel.Application excel) { try { IntPtr t = new IntPtr(excel.Hwnd); //得到这个句柄,具体作用是得到这块内存入口 int k = 0; GetWindowThreadProcessId(t, out k); //得到本进程唯一标志k System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k); //得到对进程k的引用 p.Kill(); //关闭进程k } catch (Exception ex) { MethodLb.CreateLog(typeof(CommonMethod).FullName, "Kill", ex.ToString(), excel); } }
public byte[] IniReadValues(string section, string key) { byte[] temp = new byte[10000]; try { int i = GetPrivateProfileString(section, key, "", temp, 10000, this.path); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "IniReadValues", ex.ToString(), section, key); } finally { } return(temp); }
/// <summary> /// 获取Item的集合 /// </summary> /// <param name="siteURL">指定站点Uri</param> /// <param name="documentListName">指定文档库名称</param> /// <param name="name">指定字段引用</param> /// <param name="value">指定文件名称</param> /// <param name="rowLimit">指定限定限制</param> /// <returns>返回Item的集合</returns> Microsoft.SharePoint.Client.ListItemCollection GetListItemCollectionFromSP(string documentListName, string name, string value, int rowLimit) { //声明一个item的集合 Microsoft.SharePoint.Client.ListItemCollection listItems = null; try { if (clientContext != null) { //创建客户端对象模型 using (clientContext) { //设置默认凭据 //通过文档库名称获取文档库 Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(documentListName); //创建一个查询 CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = @"<View> <Query> <Where> <Eq> <FieldRef Name=""" + name + @"""/> <Value Type="" + type + "">" + value + @"</Value> </Eq> </Where> <RowLimit>" + rowLimit.ToString() + @"</RowLimit> </Query> </View>"; //通过查询获取item的集合 listItems = documentsList.GetItems(camlQuery); //执行 clientContext.Load(documentsList); clientContext.Load(listItems); clientContext.ExecuteQuery(); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "GetListItemCollectionFromSP", ex.ToString(), documentListName, name, value, rowLimit); } finally { } return(listItems); }
internal static BitmapImage GeTheSource(string imageUri) { BitmapImage imageSource = null; try { imageSource = new BitmapImage(new Uri(GetCurrentRoot(imageUri), UriKind.RelativeOrAbsolute)); } catch (Exception ex) { MethodLb.CreateLog(typeof(FrameworkElement).ToString(), "GeTheSource", ex.ToString(), imageUri); } finally { } return(imageSource); }
/// <summary> /// 指定property里的图片名称,得到其画刷 /// </summary> /// <param name="symbolName"></param> /// <returns></returns> public static ImageBrush GetCurrentImagebrush(string ImageName) { ImageBrush imageBrush = new ImageBrush(); try { imageBrush.ImageSource = new BitmapImage(new Uri(GetCurrentRoot(ImageName), UriKind.RelativeOrAbsolute)); } catch (Exception ex) { MethodLb.CreateLog(typeof(FrameworkElement).ToString(), "GetCurrentImagebrush", ex.ToString(), ImageName); } finally { } return(imageBrush); }
private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { try { FrameworkElement element = sender as FrameworkElement; StartPoint = e.GetPosition(layout); element.CaptureMouse(); isDrag = true; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "StackPanel_MouseLeftButtonDown", ex.ToString(), sender, e); } finally { } }
public ElementTuoDong(UIElement element, Grid LayoutRoot) { try { element.MouseLeftButtonDown += new MouseButtonEventHandler(StackPanel_MouseLeftButtonDown); element.MouseLeftButtonUp += new MouseButtonEventHandler(StackPanel_MouseLeftButtonUp); element.MouseMove += new MouseEventHandler(StackPanel_MouseMove); layout = LayoutRoot; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ElementTuoDong", ex.ToString(), element, LayoutRoot); } finally { } }
/// <summary> /// 指定property里的图片名称,得到其画刷 /// </summary> /// <param name="symbolName"></param> /// <returns></returns> public static ImageBrush GetImagebrush(Bitmap bitmap) { ImageBrush imageBrush = new ImageBrush(); try { imageBrush.ImageSource = GetImageSource(bitmap); } catch (Exception ex) { MethodLb.CreateLog(typeof(FrameworkElement).ToString(), "GetImagebrush", ex.ToString(), bitmap); } finally { } return(imageBrush); }
/// <summary> /// 下载信息初始化 /// </summary> /// <param name="typeName">文件类型名称</param> /// <param name="fileName">文件名称</param> /// <param name="fileSize">文件大小(/MB或/KB)</param> /// <param name="upLoadStatu">文件下载状态(模板)</param> public FileInformationLb(string strTypeName, string strFileName, string strFileSize, ControlTemplate temUpLoadStatu) { try { System.Resources.ResourceManager rm = MhczTBG.Properties.Resources.ResourceManager; StrFileName = strFileName; StrFileSize = strFileSize; TemUpLoadStatu = temUpLoadStatu; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "FileInformationLb", ex.ToString(), strTypeName, strFileName, strFileSize, temUpLoadStatu); } finally { } }
public static void FileDown(string fileUrl) { try { //打开下载框 FileDown dcWindown = new FileDown(fileUrl, Proxy.UserName, Proxy.Password, Proxy.Domain); //如果对话框取消,则关闭控件显示 if (dcWindown.needDownload == true) { dcWindown.ShowDialog(); } } catch (Exception ex) { MethodLb.CreateLog(typeof(CommonMethod).FullName, "FileDown", ex.ToString(), fileUrl); } }
/// <summary> /// 上传一个文档 /// </summary> /// <param name="siteUrl">指定站点</param> /// <param name="documentListName">指定文档库名称</param> /// <param name="documentListURL">指定文档库的Url</param> /// <param name="documentName">设置上传文件的名称</param> /// <param name="documentStream">缓冲区</param> /// <returns>返回操作提示</returns> public string UploadFileToDocumntLibrary(string siteUrl, string folderName, string fileName, byte[] documentStream) { string result = string.Empty; try { if (clientContext != null) { using (clientContext) { Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(folderName); LoadMethod(documentsList); var fileCreationInformation = new FileCreationInformation(); fileCreationInformation.Content = documentStream; fileCreationInformation.Overwrite = true; LoadMethod(documentsList.RootFolder); //获取文档库url var d = documentsList.RootFolder.ServerRelativeUrl; string a = d.Replace(documentsList.ParentWebUrl + "/", ""); //文件信息的uri fileCreationInformation.Url = siteUrl + "/" + a + "/" + fileName; Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(fileCreationInformation); uploadFile.ListItemAllFields.Update(); clientContext.ExecuteQuery(); result = "上传成功"; } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "UploadFileToDocumntLibrary", ex.ToString(), siteUrl, folderName, documentStream); } finally { } return(result); }
/// <summary> /// 获取时间差 /// </summary> /// /// <param name="dStart"></param> /// <param name="dEnd"></param> /// <returns>返回具体时间差</returns> public static string TimeDistance(DateTime dStart, DateTime dEnd) { string timeDsiance = string.Empty; try { TimeSpan sp = dStart - dEnd; timeDsiance = string.Format("{0}年,{1}月,{2}天,{3}时,{4}分,{5}秒", (dStart.Year - dEnd.Year), (dStart.Month - dEnd.Month), sp.Days, sp.Hours, sp.Minutes, sp.Seconds); } catch (Exception ex) { MethodLb.CreateLog(typeof(FrameworkElement).ToString(), "TimeDistance", ex.ToString(), dStart, dEnd); } finally { } return(timeDsiance); }
/// <summary> /// excel关闭窗体时结束进程 /// </summary> /// <param name="Wb"></param> /// <param name="Cancel"></param> static void excelother_WorkbookBeforeClose(Microsoft.Office.Interop.Excel.Workbook Wb, ref bool Cancel) { try { Wb.Application.WorkbookBeforeClose -= excelother_WorkbookBeforeClose; var workBooksCount = Wb.Application.Workbooks.Count; if (workBooksCount == 1) { CommonMethod.Kill(Wb.Application); _excelother = null; } } catch (Exception ex) { MethodLb.CreateLog(typeof(CommonMethod).FullName, "excelother_WorkbookBeforeClose", ex.ToString(), Wb, Cancel); } }
/// <summary> /// 获取文档 /// </summary> /// <param name="siteUrl">指定站点地址</param> /// <param name="folderName">指定文档库名称</param> /// <returns>返回当前文档库里的所有文档</returns> public List <Microsoft.SharePoint.Client.File> GetFiles(string siteUrl, string folderName) { List <Microsoft.SharePoint.Client.File> fileList = new List <Microsoft.SharePoint.Client.File>(); try { if (clientContext != null) { //创建客户端对象模型 using (clientContext) { //设置默认凭据 //通过标题获取文档库 Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(folderName); //加载该文档库 LoadMethod(documentsList); //加载该文档库的文档集合 LoadMethod(documentsList.RootFolder.Files); //循环遍历该文档库里的文档 foreach (var item in documentsList.RootFolder.Files) { //加载文档创建者 LoadMethod(item.Author); //加载文档修改者 LoadMethod(item.ModifiedBy); //加载文档版本控制 LoadMethod(item.Versions); //加载文档 fileList.Add(item); } } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "GetFiles", ex.ToString(), siteUrl, folderName); } finally { } //返回该文档库中所有文档 return(fileList); }
/// <summary> /// 上传文件 /// </summary> /// <param name="siteURL">网站url</param> /// <param name="documentListName">列表名称</param> /// <param name="documentListURL">文件地址</param> /// <param name="documentName">文件名称</param> /// <param name="documentStream">字节数组</param> public void UploadDocument(string siteURL, string documentListName, string documentListURL, string documentName, byte[] documentStream) { try { if (clientContext != null) { //通过客户端对象模型来上传文件 using (clientContext) { //获取文档库 List documentsList = clientContext.Web.Lists.GetByTitle(documentListName); //文件创建信息 var fileCreationInformation = new FileCreationInformation(); //指定内容 byte[]数组,这里是 documentStream fileCreationInformation.Content = documentStream; //允许文档覆盖 fileCreationInformation.Overwrite = true; //上载 URL地址 fileCreationInformation.Url = siteURL + documentListURL + documentName; Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(fileCreationInformation); //更新元数据信息,这里是一个显示名为“描述”的字段,其字段名为“Description0” uploadFile.ListItemAllFields["Description0"] = "内容"; //先更新一下 uploadFile.ListItemAllFields.Update(); //然后再执行 clientContext.ExecuteQuery(); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "UploadDocument", ex.ToString(), siteURL, documentListName, documentListURL, documentName, documentStream); } finally { } }
/// <summary> /// 获取到最终的父容器 /// </summary> FrameworkElement GetRootParent(FrameworkElement element, int intCount) { FrameworkElement fraParent = null; try { for (int i = 0; i < intCount; i++) { element = element.Parent as FrameworkElement; string strName = element.Name; } fraParent = element; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "GetRootParent", ex.ToString(), element, intCount); } return(fraParent); }
/// <summary> /// 读取INI文件 /// </summary> /// <param name="Section"></param> /// <param name="Key"></param> /// <returns></returns> public string IniReadValue(string Section, string Key) { string result = string.Empty; try { StringBuilder temp = new StringBuilder(10000); int i = GetPrivateProfileString(Section, Key, "", temp, 10000, this.path); result = temp.ToString(); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "IniReadValue", ex.ToString(), Section, Key); } finally { } return(result); }
/// <summary> /// 获取文档 /// </summary> /// <param name="siteUrl">指定站点地址</param> /// <param name="folderName">指定文档库名称</param> /// <param name="fileName">指定文档名称</param> /// <returns>返回指定名称的文档</returns> public Microsoft.SharePoint.Client.File GetFile(string folderName, string fileName) { //声明将要返回的文档 Microsoft.SharePoint.Client.File file = null; try { if (clientContext != null) { //创建客户端对象模型 using (clientContext) { //设置默认凭据 //通过标题获取文档库 Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(folderName); //加载该文档库 LoadMethod(documentsList); //加载该文档库的文档集合 LoadMethod(documentsList.RootFolder.Files); //循环遍历该文档库里的文档 foreach (var item in documentsList.RootFolder.Files) { //获取指定名称的文档 if (item.Name.Equals(fileName)) { //加载文档的版本控制 LoadMethod(item.Versions); file = item; } } } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "GetFiles", ex.ToString(), folderName, fileName); } finally { } return(file); }
//解密过程 public static string frombase(string password) { string factString = string.Empty; try { byte[] myByte; Encoding myEncoding = Encoding.GetEncoding("utf-8"); myByte = Convert.FromBase64String(password); factString = myEncoding.GetString(myByte); } catch (Exception ex) { MethodLb.CreateLog(typeof(FrameworkElement).ToString(), "frombase", ex.ToString(), password); } finally { } return(factString); }
//加密过程 public static string tobase(string password) { string Base64Str = string.Empty; try { byte[] myByte; Encoding myEncoding = Encoding.GetEncoding("utf-8"); myByte = myEncoding.GetBytes(password); Base64Str = Convert.ToBase64String(myByte); } catch (Exception ex) { MethodLb.CreateLog(typeof(FrameworkElement).ToString(), "tobase", ex.ToString(), password); } finally { } return(Base64Str); }
/// <summary> /// 指定property里的图片名称,得到其画刷 /// </summary> /// <param name="symbolName"></param> /// <returns></returns> public static ImageBrush GetImagebrush(string ImageName) { ImageBrush imageBrush = new ImageBrush(); try { System.Resources.ResourceManager rm = MhczTBG.Properties.Resources.ResourceManager; System.Drawing.Bitmap b = (System.Drawing.Bitmap)rm.GetObject(ImageName); imageBrush.ImageSource = GetImageSource(b); } catch (Exception ex) { MethodLb.CreateLog(typeof(FrameworkElement).ToString(), "GetImagebrush", ex.ToString(), ImageName); } finally { } return(imageBrush); }
/// <summary> /// 加载快捷方法 /// </summary> /// <param name="clientContext">客户端对象模型</param> /// <param name="obj">要加载的对象</param> public void LoadMethod(ClientObject obj) { try { if (clientContext != null) { //加载该对象 clientContext.Load(obj); //执行操作 clientContext.ExecuteQuery(); } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "LoadMethod", ex.ToString(), obj); } finally { } }
/// <summary> /// 获取时间差 /// </summary> /// <param name="strStart"></param> /// <param name="strEnd"></param> /// /// <returns>返回具体时间差</returns> public static string TimeDistance(string strStart, string strEnd) { string timeDsiance = string.Empty; try { DateTime d1 = Convert.ToDateTime(strStart); DateTime d2 = Convert.ToDateTime(strEnd); TimeSpan sp = d1 - d2; timeDsiance = string.Format("{0}年,{1}月,{2}天,{3}时,{4}分,{5}秒", (d1.Year - d2.Year), (d1.Month - d2.Month), sp.Days, sp.Hours, sp.Minutes, sp.Seconds); } catch (Exception ex) { MethodLb.CreateLog(typeof(FrameworkElement).ToString(), "TimeDistance", ex.ToString(), strStart, strEnd); } finally { } return(timeDsiance); }
/// <summary> /// 通过查询语句获取表单所有数据 /// </summary> /// <param name="website">站点地址</param> /// <param name="listName">指定列表名称</param> /// <param name="querystring">指定查询语句</param> /// <returns>返回子项的集合</returns> public List <Dictionary <string, object> > ClientGetDic(string website, string listName, string querystring) { List <Dictionary <string, object> > dicList = new List <Dictionary <string, object> >(); try { if (clientContext != null) { //创建客户端对象模型 using (clientContext) { //获取列表 List oList = clientContext.Web.Lists.GetByTitle(listName); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = querystring; //获取当前列表的所有项 Microsoft.SharePoint.Client.ListItemCollection collListItem = oList.GetItems(camlQuery); //执行 clientContext.Load(collListItem); clientContext.ExecuteQuery(); foreach (var item in collListItem) { dicList.Add(item.FieldValues); } } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ClientGetDic", ex.ToString(), website, listName, querystring); } finally { } return(dicList); }
/// <summary> /// 收集故障信息集合 /// </summary> /// <param name="assessment"></param> public AssessmentControl(SafetyAssessment assessment) { try { //故障信息之间的空隙 this.Margin = new Thickness(5, 0, 5, 15); //集中故障实例的属性值 List <string> assessmentAll = new List <string>() { assessment.Time, assessment.Cause, assessment.TrainEffect, assessment.DelayTime, assessment.Section, assessment.Bureau, assessment.Check, }; //生成一个信息集 StringBuilder builder = new StringBuilder(); foreach (var asse in assessmentAll) { TextBlock lbl = new TextBlock(); lbl.FontSize = 12; lbl.Text = asse; lbl.TextWrapping = TextWrapping.Wrap; this.Children.Add(lbl); //信息集收集信息 builder.Append(asse); } //收集 InformationCollection.builderCollection.Add(builder); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "AssessmentControl", ex.ToString(), assessment); } finally { } }
/// <summary> /// 新建一个文档库 /// </summary> /// <param name="siteUrl">站点的uri地址</param> /// <param name="DocumentLibraryName">文档库的显示名称</param> /// <returns>返回操作的信息</returns> public List CreateDocumentLibrary(string folderName, ListTemplateType folderType) { //新建一个List Microsoft.SharePoint.Client.List newList = null; try { if (clientContext != null) { //文档库创建信息操作类 ListCreationInformation newListInfo = new ListCreationInformation(); //文档库的显示标题 newListInfo.Title = folderName; //文档库 newListInfo.TemplateType = (int)folderType; //创建客户端对象模型 using (clientContext) { //设置默认凭据 //获取站点(site) Web site = clientContext.Web; //添加文档库 newList = site.Lists.Add(newListInfo); //加载文档库并执行 clientContext.Load(newList); clientContext.ExecuteQuery(); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "CreateDocumentLibrary", ex.ToString(), folderName, folderType); } finally { } return(newList); }