| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using DevExpress.XtraEditors;
- using DevExpress.XtraEditors.Repository;
- using System;
- using System.Data;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Windows.Forms;
- using UAS_DeviceMonitor.DataOperate;
- using DevExpress.Utils;
- namespace UAS_DeviceMonitor.PublicMethod
- {
- class BaseUtil
- {
-
- [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
- public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
- public static void FillComBoxEditWidthDataTable(RepositoryItemComboBox combo, string TextField, string ValueField, DataTable dt)
- {
- combo.Items.Clear();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- ComboBoxData item = new ComboBoxData();
- item.Value = dt.Rows[i][ValueField].ToString();
- item.Text = dt.Rows[i][TextField].ToString();
- combo.Items.Add(item);
- }
- }
- public static void FillComBoxEditWidthDataTable(ComboBoxEdit combo, string TextField, string ValueField, DataTable dt)
- {
- combo.Properties.Items.Clear();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- ComboBoxData item = new ComboBoxData();
- item.Value = dt.Rows[i][ValueField].ToString();
- item.Text = dt.Rows[i][TextField].ToString();
- combo.Properties.Items.Add(item);
- }
- combo.SelectedIndex = 0;
- }
- public static DataTable ToDataTable(DataRow[] rows)
- {
- if (rows == null || rows.Length == 0) return new DataTable();
- DataTable tmp = rows[0].Table.Clone(); // 复制DataRow的表结构
- foreach (DataRow row in rows)
- tmp.Rows.Add(row.ItemArray); // 将DataRow添加到DataTable中
- return tmp;
- }
- public static string GetComboxEditValue(ComboBoxEdit ComBox)
- {
- if (ComBox.SelectedItem == null)
- return ComBox.Text;
- else
- return (ComBox.SelectedItem as ComboBoxData).Value;
- }
- /// <summary>
- /// 获取LRC
- /// </summary>
- /// <param name="SQL"></param>
- public static string getLRC(string SENDMESSAGE)
- {
- string message = SENDMESSAGE.Trim();
- if (message.Length % 2 != 0)
- {
- message = message + "0";
- }
- int LRC = 0x0;
- for (int i = 0; i < message.Length; i = i + 2)
- {
- int inside = int.Parse(message.Substring(i, 1).ToString() + message.Substring(i + 1, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
- LRC += inside;
- }
- string _LRC = string.Format("{0:X2}", LRC);
- string LRCre = "";
- for (int i = 0; i < _LRC.Length; i++)
- {
- int index;
- index = 0xF - int.Parse(_LRC.Substring(i, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
- LRCre += string.Format("{0:X}", index);
- }
- LRCre = string.Format("{0:X}", int.Parse(LRCre, System.Globalization.NumberStyles.HexNumber) + 1);
- return LRCre;
- }
- public static string ByteToHexadecimalString(byte[] b, int length)
- {
- string returnStr = "";
- if (b != null)
- {
- for (int i = 0; i < length; i++)
- {
- returnStr += Convert.ToString(b[i], 16);//ToString("X2") 为C#中的字符串格式控制符
- }
- }
- return returnStr;
- }
- public static void CleanMemory()
- {
- GC.Collect();
- GC.WaitForPendingFinalizers();
- if (Environment.OSVersion.Platform == PlatformID.Win32NT)
- {
- SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
- }
- }
- private static ToolTipControllerShowEventArgs args;
- public static ToolTipController MyToolTipClt { get; private set; }
- public static void NewToolTip(Control ctl, string title, string content, int showTime, ToolTipType toolTipType, ToolTipLocation tipLocation, bool isAutoHide, ToolTipIconType tipIconType, ImageList imgList, int imgIndex)
- {
- try
- {
- MyToolTipClt = new ToolTipController();
- args = MyToolTipClt.CreateShowArgs();
- content = (string.IsNullOrEmpty(content) ? "???" : content);
- title = string.IsNullOrEmpty(title) ? "温馨提示" : title;
- MyToolTipClt.ImageList = imgList;
- MyToolTipClt.ImageIndex = (imgList == null ? 0 : imgIndex);
- args.AutoHide = isAutoHide;
- MyToolTipClt.ShowBeak = true;
- MyToolTipClt.ShowShadow = true;
- MyToolTipClt.Rounded = true;
- MyToolTipClt.AutoPopDelay = (showTime == 0 ? 2000 : showTime);
- MyToolTipClt.SetToolTip(ctl, content);
- MyToolTipClt.SetTitle(ctl, title);
- MyToolTipClt.SetToolTipIconType(ctl, tipIconType);
- MyToolTipClt.Active = true;
- MyToolTipClt.HideHint();
- MyToolTipClt.ShowHint(content, title, ctl, tipLocation);
- }
- catch (Exception)
- {
-
- }
- }
- }
- }
|