公共方法
来源:互联网 发布:origin软件中文版 编辑:程序博客网 时间:2024/04/25 13:50
1, dataTable过滤的行组成新的dataTable
配置文件如下:
6,某对象是null或空
// 把行集合中的数据覆盖到datatable public static DataTable GetDataTable(DataTable dtOrigin, DataRow[] DRS) { DataTable dtTmp = dtOrigin.Clone(); try { if (DRS != null && DRS.Length > 0) { foreach (DataRow row in DRS) { dtTmp.Rows.Add(row.ItemArray); } } } catch (Exception ex) { //MessageBox.Show(ex.Message); } return dtTmp; }
2, 判断数组中是否包含某个项
public static bool ArrayHasItem(string[] arr, string sItem) { bool bFind = false; foreach (string s in arr) { if (s == sItem) { bFind = true; break; } } return bFind; }
3, 删除数组/泛型数组中重复的项
/// <summary> /// 删除数组中的重复项 泛型方法 /// </summary> /// <param name="values">数组</param> /// <returns></returns> public static List<T> RemoveDuplicate<T>(List<T> values) { List<T> list = new List<T>(); for (int i = 0; i < values.Count; i++)//遍历数组成员 { if (list.IndexOf(values[i]) == -1)//对每个成员做一次新数组查询如果没有相等的则加到新数组 list.Add(values[i]); } return list; }调用方法:
List<string> aWordNew = new List<string>();
// -----
aWordNew = RemoveDuplicate<string>(aWordNew);
4,创建DataTable
public static DataTable CreateDataTable(int iColumnCount) { DataTable dt = new DataTable(); for (int i = 0; i < iColumnCount; i++) { dt.Columns.Add("Column" + i); } return dt; }5,设置 / 读取 配置文件中某个节点的值
public static void SetAppSettingsKeyValue(string AppKey, string AppValue) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config"); XmlNode xNode; XmlElement xElem1; XmlElement xElem2; xNode = xDoc.SelectSingleNode("//appSettings"); xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']"); if (xElem1 != null) xElem1.SetAttribute("value", AppValue); else { xElem2 = xDoc.CreateElement("add"); xElem2.SetAttribute("key", AppKey); xElem2.SetAttribute("value", AppValue); xNode.AppendChild(xElem2); } xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config"); } public static string GetAppValue(string sKeyName) { object oResult = System.Configuration.ConfigurationManager.AppSettings[sKeyName]; if (oResult!=null) { return oResult.ToString(); } return ""; }
配置文件如下:
<?xml version="1.0"?><configuration><startup><supportedRuntime version="v2.0.50727"/></startup> <appSettings> <add key="SqliteDbPath" value="Data\EnglishWords.db"/> <add key="TestSourcePath" value="Data\Dictionary_English.docx"/> <add key="RunMode" value="DEV"/> <!--运行模式:DEV,USER --> </appSettings></configuration>
6,某对象是null或空
public static bool IsNullOrEmptyObject(object oSource) { if (oSource != null) { return string.IsNullOrEmpty(oSource.ToString()); } return true; }7,检查字符串是不是包含中文字符
检查字符串是不是包含中文字符 public static bool CheckEncode(string srcString) { int strLen = srcString.Length; //字符串的长度,一个字母和汉字都算一个 int bytLeng = System.Text.Encoding.UTF8.GetBytes(srcString).Length; //字符串的字节数,字母占1位,汉字占2位,注意,一定要UTF8 bool chkResult = false; if (strLen < bytLeng) //如果字符串的长度比字符串的字节数小,当然就是其中有汉字啦^-^ { chkResult = true; } return chkResult; }8, 提示信息
public static bool DeleteConfirmation() { return MessageBox.Show("确定要删除吗?", "删除确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK; } public static bool DeleteConfirmation(string sItem) { return MessageBox.Show("确定要删除 " + sItem + " 吗?", "删除确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK; } public static bool Confirmation(string sMsg) { return MessageBox.Show(sMsg, "确认信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK; } public static bool SingleConfirmation(string sMsg) { return MessageBox.Show(sMsg, "确认信息", MessageBoxButtons.OK, MessageBoxIcon.Question) == DialogResult.OK; }
- 公共方法
- 公共方法
- 公共方法
- 一些常用公共方法
- 公共方法弹出
- 公共的分页方法
- ongl 公共静态方法
- Spring 公共方法
- 公共类方法
- javascript公共方法
- STRING公共方法
- YII2自定义公共方法
- iOS常用公共方法
- iOS常用公共方法
- iOS 常用公共方法
- ios 常用公共方法
- ios 常用公共方法
- iOS 常用公共方法
- android将图片转成字符串,再将字符串转成图片 (base64处理的字符串)
- (转) 虚函数表放在哪里?
- C++中异常处理的语法 try catch throw
- NSEntityDescription和NSManagedObject
- Cstring中的Find()、Mid()、Replace()用法
- 公共方法
- nil Nil NULL NSNull
- 献给你:准设计师以及入行未满三年的新手设计师
- DB2 错误代码大全[转]
- 程序员修炼之路(六)编写自己的工具(JAVA注册系统级快捷键源码>jintellitype<)
- 在IOS上利用ArcGIS API For IOS进行移动GIS开发新建程序的配置步骤
- Starling第二篇
- Android中dip(dp)与px之间单位转换
- webspere7.0安装for linux5.6