using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Microsoft.Win32; using System.Management; using System.Net; using System.Globalization; using System.Data.SqlClient; using CommonLib; using DevExpress.XtraPrinting; using DevExpress.XtraPrinting.Preview; using DevExpress.Utils; using DevExpress.XtraEditors; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; namespace Ls { public class sysstr { public static string str1; public static string str2; public static string showid; public static string str3; public static string str4; public static string str5; public static string str6; public static string str7; public static string str8; } public class dx { public static int SaveXls(DevExpress.XtraGrid.GridControl GridControlPub) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "导出Excel"; saveFileDialog.Filter = "Excel文件(*.xls)|*.xls|Excel2007|*.xlsx|PDF文件|*.PDF|RTF文件|*.RTF|HTML文件|*.html"; DialogResult dialogResult = saveFileDialog.ShowDialog(); if (dialogResult == DialogResult.OK) { DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions(); if (saveFileDialog.FilterIndex == 1) { GridControlPub.ExportToXls(saveFileDialog.FileName); } if (saveFileDialog.FilterIndex == 2) { GridControlPub.ExportToXlsx(saveFileDialog.FileName); } if (saveFileDialog.FilterIndex == 3) { GridControlPub.ExportToPdf(saveFileDialog.FileName); } if (saveFileDialog.FilterIndex == 4) { GridControlPub.ExportToRtf(saveFileDialog.FileName); } if (saveFileDialog.FilterIndex == 5) { GridControlPub.ExportToHtml(saveFileDialog.FileName); } DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } return 1; } public static int Preview(DevExpress.XtraGrid.GridControl GridControlPub) { PrintingSystem ps = null; DevExpress.XtraPrinting.PrintableComponentLink link = null; ps = new DevExpress.XtraPrinting.PrintingSystem(); link = new DevExpress.XtraPrinting.PrintableComponentLink(ps); ps.Links.Add(link); link.Component = GridControlPub;//这里可以是可打印的部件 string _PrintHeader = "我的物料档案打印数据信息"; PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter; phf.Header.Content.Clear(); phf.Header.Content.AddRange(new string[] { "", _PrintHeader, "" }); phf.Header.Font = new System.Drawing.Font("宋体", 14, System.Drawing.FontStyle.Bold); phf.Header.LineAlignment = BrickAlignment.Center; link.CreateDocument(); //建立文档 ps.PreviewFormEx.Show(); return 1; } public static int CopyTitle(DevExpress.XtraGrid.Views.Grid.GridView gridView1) { StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder2 = new StringBuilder(); foreach (GridColumn gridColumn in gridView1.Columns) { if (gridColumn.Visible) { stringBuilder.AppendFormat("{0} ", gridColumn.Caption); } } int[] selectedRows = gridView1.GetSelectedRows(); int[] array = selectedRows; for (int i = 0; i < array.Length; i++) { int rowHandle = array[i]; foreach (GridColumn gridColumn in gridView1.Columns) { if (gridColumn.Visible) { stringBuilder2.AppendFormat("{0} ", gridView1.GetRowCellDisplayText(rowHandle, gridColumn.FieldName)); } } stringBuilder2.AppendLine(); } Clipboard.SetText(stringBuilder.ToString() + "\r\n" + stringBuilder2.ToString()); return 1; } public static string SetRowNb(object sender, RowIndicatorCustomDrawEventArgs e) { e.Appearance.TextOptions.HAlignment = HorzAlignment.Far; if (e.Info.IsRowIndicator) { if (e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } return ""; } public static string SelectRow(DevExpress.XtraGrid.Views.Grid.GridView GridViewpub) { GridViewpub.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus; GridViewpub.OptionsBehavior.Editable = false; GridViewpub.OptionsSelection.EnableAppearanceFocusedCell = false; return ""; } public static string Group(DevExpress.XtraGrid.Views.Grid.GridView GridViewpub) { if (GridViewpub.OptionsView.ShowGroupPanel == true) { GridViewpub.OptionsView.ShowGroupPanel = false; } else { GridViewpub.OptionsView.ShowGroupPanel = true; } return ""; } public static string find(DevExpress.XtraGrid.Views.Grid.GridView GridViewpub) { if (GridViewpub.OptionsFind.AlwaysVisible == true) { GridViewpub.OptionsFind.AlwaysVisible = false; } else { GridViewpub.OptionsFind.AlwaysVisible = true; } return ""; } } public class Ado { public static string message() { return Ls.Net.GetLocalHost(); } } public class contentsAdo { public static string message() { return Ls.Reg.GetRegistData("ServerName"); } } //注册表访问 public class Reg { public static string GetRegistData(string name) { string registData; RegistryKey hkml = Registry.CurrentUser; RegistryKey software = hkml.OpenSubKey("AA_LS_Erp V2.0", true); if (software == null) { return ""; } RegistryKey aimdir = software.OpenSubKey("File", true); if (aimdir == null) { return ""; } registData = aimdir.GetValue(name).ToString(); if (registData == null) { return ""; } return registData; } public static void WTRegedit(string name, string tovalue) { RegistryKey hkml = Registry.CurrentUser; RegistryKey software = hkml.CreateSubKey("AA_LS_Erp V2.0"); RegistryKey aimdir = software.CreateSubKey("File"); aimdir.SetValue(name, tovalue); } public static void SetValue(string keyName, string valueName, object value) { Registry.SetValue(keyName, valueName, value, RegistryValueKind.String); } public static object GetValue(string keyName, string valueName, object defaultValue) { object obj1 = Registry.GetValue(keyName, valueName, defaultValue); if (obj1 == null) { return defaultValue; } else { return obj1; } } } public class Net { public static string GetLocalHost() { return Dns.GetHostName(); } //获取本地IP地址 public static IPAddress[] GetLocalIP() { string name = Dns.GetHostName(); IPHostEntry me = Dns.GetHostEntry(name); return me.AddressList; } } public class IO { //建目录 public static bool CreatePath(string strPath) { try { if (strPath.Length == 0) { return false; } if (Directory.Exists(strPath)) { return true; } Directory.CreateDirectory(Path.GetDirectoryName(strPath)); return true; } catch { return false; } } //写文本日志 try catch (Exception ex) public static void WriteLog(string strFile, string strLog) { try { if (File.Exists(strFile)) { using (StreamWriter sw1 = File.AppendText(strFile)) { //", DateTime.Now.ToString("yyMMdd-HHmmss") sw1.WriteLine("[" + System.DateTime.Now.ToString("yyMMdd-HHmmss") + "]" + strLog); sw1.Close(); } } else { if (IO.CreatePath(strFile)) { using (StreamWriter sw2 = File.CreateText(strFile)) { sw2.WriteLine("[" + System.DateTime.Now.ToString("yyMMdd-HHmmss") + "]" + strLog); sw2.Close(); } } } } catch { } } } }