| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114 |
- using System;
- using System.Data;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- using System.Text.RegularExpressions;
- using System.Reflection;
- using System.Diagnostics;
- using System.IO;
- using CoreFS.CA06;
- using Core.Mes.Client.Comm;
- public class Globals
- {
- /// <summary>
- /// 从服务端查询数据(query)
- /// </summary>
- /// <param name="methodId">服务端MethodId</param>
- /// <param name="param">参数数组,需与服务端方法参数一致</param>
- /// <param name="ob">界面OB对象</param>
- /// <exception cref="MESException">自定义异常</exception>
- /// <returns>查询数据集</returns>
- public static DataTable GetData(string methodId, object[] param, OpeBase ob)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
- ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
- ccp.ServerParams = param;
- ccp = ob.ExecuteSortResultByQueryToDataTable(ccp, CoreInvokeType.Internal);
- if (ccp == null)
- {
- throw new MESException("服务端处理失败!");
- }
- if (ccp.ReturnCode < 0)
- {
- throw new MESException("服务端处理失败!", ccp.ReturnCode, ccp.ReturnInfo);
- }
- return ccp.SourceDataTable;
- }
- /// <summary>
- /// 向服务端设置数据(insert、update、delete、procedure)
- /// </summary>
- /// <param name="methodId">服务端MethodId</param>
- /// <param name="param">参数数组,需与服务端方法参数一致</param>
- /// <param name="ob">界面OB对象</param>
- /// <exception cref="MESException">自定义异常</exception>
- /// <returns>count处理数据行数,0 or -num表示失败</returns>
- public static int SetData(string methodId, object[] param, OpeBase ob)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
- ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
- ccp.ServerParams = param;
- ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp == null)
- {
- throw new MESException("服务端处理失败!");
- }
- if (ccp.ReturnCode < 0)
- {
- throw new MESException("服务端处理失败!", ccp.ReturnCode, ccp.ReturnInfo);
- }
- int count = 0;
- if (!int.TryParse(ccp.ReturnObject!=null?ccp.ReturnObject.ToString():null, out count))
- {
- throw new MESException("服务端处理成功,但返回处理数量不是数字!");
- }
- return count;
- }
- /// <summary>
- /// 初始化Combox数据
- /// </summary>
- /// <param name="cmbx">ComboBox控件</param>
- /// <param name="dset">DataSet数据源</param>
- public static void FillComboxItems(ComboBox cmbx, DataSet dset)
- {
- if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
- {
- ArrayList aryTmp = new ArrayList();
- for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
- {
- aryTmp.Add(new ValueListItem(dset.Tables[0].Rows[i][0].ToString(), dset.Tables[0].Rows[i][1].ToString()));
- }
- cmbx.DataSource = aryTmp;
- cmbx.DisplayMember = "Name";
- cmbx.ValueMember = "ID";
- }
- }
- /// <summary>
- /// 初始化Combox数据,加入数据筛选
- /// </summary>
- /// <param name="cmbx">ComboBox控件</param>
- /// <param name="dset">DataSet数据源</param>
- /// <param name="filterCondition">RowFilter条件</param>
- public static void FillComboxItems(ComboBox cmbx, DataSet dset, string filterCondition)
- {
- if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
- {
- DataView dvw = dset.Tables[0].DefaultView;
- dvw.RowFilter = filterCondition;
- ArrayList aryTmp = new ArrayList();
- for (int i = 0; i < dvw.Count; i++)
- {
- aryTmp.Add(new ValueListItem(dvw[i][0].ToString(), dvw[i][1].ToString()));
- }
- cmbx.DataSource = aryTmp;
- cmbx.DisplayMember = "Name";
- cmbx.ValueMember = "ID";
- }
- }
- /// <summary>
- /// 初始化UltraCombo数据
- /// </summary>
- /// <param name="ulcme">ultraComboEditor控件</param>
- /// <param name="dset">DataSet数据源</param>
- public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset)
- {
- if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
- {
- for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
- ulcme.Items.Add(dset.Tables[0].Rows[i][0].ToString(), dset.Tables[0].Rows[i][1].ToString());
- }
- }
- /// <summary>
- /// 初始化CheckedListBox数据,加入数据筛选
- /// </summary>
- /// <param name="list">CheckedListBox控件</param>
- /// <param name="ds">DataSet数据源</param>
- /// <param name="filterConddition">RowFilter条件</param>
- public static void FillCHKItems(CheckedListBox list, DataSet ds, string filterConddition)
- {
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Columns.Count > 1)
- {
- DataView dvw = ds.Tables[0].DefaultView;
- dvw.RowFilter = filterConddition;
- System.Web.UI.WebControls.ListItem item;
- for (int i = 0; i < dvw.Count; i++)
- {
- item = new System.Web.UI.WebControls.ListItem(dvw[i][1].ToString(), dvw[i][0].ToString());
- list.Items.Add(item);
- }
- }
- }
- /// <summary>
- /// 初始化UltraComboEditor数据
- /// </summary>
- /// <param name="ulcme"></param>
- /// <param name="dt"></param>
- public static void FillUlcmeItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataTable dt)
- {
- if (dt.Columns.Count > 0)
- {
- ulcme.Items.Clear();
- for (int i = 0; i < dt.Rows.Count; i++)
- ulcme.Items.Add(dt.Rows[i][0].ToString());
- }
- }
- /// <summary>
- /// 初始化UltraCombo数据,加入数据筛选
- /// </summary>
- /// <param name="ulcme">ultraComboEditor控件</param>
- /// <param name="dset">DataSet数据源</param>
- /// <param name="filterCondition">RowFilter条件</param>
- public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset, string filterCondition)
- {
- if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
- {
- DataView dvw = dset.Tables[0].DefaultView;
- dvw.RowFilter = filterCondition;
- for (int i = 0; i < dvw.Count; i++)
- ulcme.Items.Add(dvw[i][0].ToString(), dvw[i][1].ToString());
- }
- }
- /// <summary>
- /// 初始化UltraCombo数据
- /// </summary>
- /// <param name="ulcme"></param>
- /// <param name="dt">DataTable</param>
- public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataTable dt)
- {
- if (dt.Columns.Count > 1)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- ulcme.Items.Add(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString());
- }
- }
- /// <summary>
- /// 初始化UltraCombo数据
- /// </summary>
- /// <param name="ulcme"></param>
- /// <param name="dv">DataView</param>
- public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataView dv)
- {
- if (dv.Count > 0)
- {
- for (int i = 0; i < dv.Count; i++)
- ulcme.Items.Add(dv[i]["BASECODE"].ToString(), dv[i]["BASENAME"].ToString());
- }
- }
- /// <summary>
- /// 初始化UltraCombo数据,并添加“空”
- /// </summary>
- /// <param name="ulcme">ultraComboEditor控件</param>
- /// <param name="dset">DataSet数据源</param>
- public static void FillUlcmItemsAddEmpty(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset)
- {
- ulcme.Items.Add("", "空");
- FillUltraComboItems(ulcme, dset);
- }
- /// <summary>
- /// 初始化UltraCombo数据,并添加“空”;加入数据筛选
- /// </summary>
- /// <param name="ulcme">ultraComboEditor控件</param>
- /// <param name="dset">DataSet数据源</param>
- /// <param name="filterCondition">RowFilter条件</param>
- public static void FillUlcmItemsAddEmpty(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset, string filterCondition)
- {
- ulcme.Items.Add("", "空");
- FillUltraComboItems(ulcme, dset, filterCondition);
- }
- /// <summary>
- /// 字符串转是否能转换成非负数
- /// </summary>
- /// <param name="str"></param>
- /// <returns></returns>
- public static bool Is_Below_zero(string str)
- {
- try
- {
- if (IsDouble(str) && double.Parse(str) > 0)
- return true;
- else
- return false;
- }
- catch
- {
- return false;
- }
- }
- /// <summary>
- /// 删除记录激活指定行
- /// </summary>
- /// <param name="grid">ultraGrid</param>
- /// <param name="delRowIndex">删除行的索引</param>
- public static void GridAfterDelRow_ReSelectRow(ref Infragistics.Win.UltraWinGrid.UltraGrid grid, int delRowIndex)
- {
- if (grid.Rows.Count == 0) return;
- if ((delRowIndex + 1) > grid.Rows.Count)
- {
- grid.Rows[delRowIndex - 1].Activate();
- grid.Rows[delRowIndex - 1].Selected = true;
- }
- else
- {
- grid.Rows[delRowIndex].Activate();
- grid.Rows[delRowIndex].Selected = true;
- }
- }
- /// <summary>
- /// 全单位修约(GB 8170-87)
- /// </summary>
- /// <param name="sOriVal">原始值</param>
- /// <param name="ten_interval">10的n次方修约间隔</param>
- /// <returns>修约后值</returns>
- public static string XYFullUnit(string sOriVal, sbyte ten_interval)
- {
- try
- {
- decimal interval = Convert.ToDecimal(Math.Pow(10, ten_interval));//修约间隔
- decimal d = decimal.Parse(sOriVal) / interval;
- bool isPlus = (d > 0); //是否为正数
- d = Math.Abs(d);
- int i = (int)d;
- if ((d - i) < 0.5m)
- {
- d = i * interval;
- }
- else if ((d - i) > 0.5m)
- {
- d = (i + 1) * interval;
- }
- else //(d-i) == 0.5m
- {
- if ((i % 2) == 0) //双数舍去
- d = i * interval;
- else //单数进一
- d = (i + 1) * interval;
- }
- if (!isPlus)
- d = 0 - d;
- if (ten_interval >= 0)
- return d.ToString();
- else
- return ValWithDigits(d.ToString(), Math.Abs(ten_interval));
- }
- catch
- {
- return "";
- }
- }
- /// <summary>
- /// 保留指定位数小数
- /// </summary>
- /// <param name="sVal"></param>
- /// <param name="Digits"></param>
- /// <returns></returns>
- public static string ValWithDigits(string sVal, int Digits)
- {
- try
- {
- decimal d = decimal.Parse(sVal);
- string sFormat = "0";
- if (Digits > 0)
- {
- sFormat += ".";
- for (int i = 0; i < Digits; i++)
- sFormat += "0";
- }
- return d.ToString(sFormat);
- }
- catch
- {
- return "";
- }
- }
- /// <summary>
- /// 单元格复制内容
- /// </summary>
- /// <param name="strMessage"></param>
- public static void cellCopy(string strMessage)
- {
- Clipboard.SetDataObject(strMessage, false);
- }
- /// <summary>
- /// 清除UltraGrid的DataSource的数据
- /// </summary>
- /// <param name="ulGrid"></param>
- public static void ClearGridDataSourceData(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid)
- {
- if (ulGrid.DataSource is DataSet)
- {
- for (int i = ((DataSet)ulGrid.DataSource).Tables.Count - 1; i >= 0; i--)
- {
- ((DataSet)ulGrid.DataSource).Tables[i].Rows.Clear();
- }
- }
- }
- #region "数据验证"
- /// <summary>
- /// 验证DataTable是否为空
- /// </summary>
- /// <param name="dt">DataTable数据</param>
- /// <returns>true为空值</returns>
- public static bool IsNullTable(DataTable dt)
- {
- if (dt == null || dt.Rows.Count <= 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 校验字符串是否只包含字母与数字
- /// </summary>
- /// <param name="toVerified">需要校验的字符串</param>
- /// <returns>true表示符合要求,false表示不符合要求</returns>
- public static bool IsOnlyLetterAndDigit(string toVerified)
- {
- Regex rx = new Regex(@"^[a-zA-Z0-9-]*$");
- return rx.IsMatch(toVerified.Trim(), 0);
- }
- /// <summary>
- /// 检验是否是整数
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为整数:true是整数,false非整数</returns>
- public static bool IsInt(string str)
- {
- Regex rx = new Regex(@"^[0123456789]+$");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验是否是整数(庹建勇)
- /// </summary>
- /// <param name="sVal"></param>
- /// <returns></returns>
- public static bool IsInt32(string sVal)
- {
- try
- {
- Int32.Parse(sVal);
- return true;
- }
- catch
- {
- return false;
- }
- }
- /// <summary>
- /// 校验是否为正的浮点数
- /// </summary>
- /// <param name="price">需要检验的字符串</param>
- /// <returns>是否为正浮点,是返回true,否则返回false</returns>
- public static bool IsFloat(string str)
- {
- Regex rx = new Regex(@"^[0-9]*(.)?[0-9]+$", RegexOptions.IgnoreCase);
- return rx.IsMatch(str.Trim());
- }
- /// <summary>
- /// 验证浮点数
- /// </summary>
- /// <param name="sVal"></param>
- /// <returns></returns>
- public static bool IsDouble(string sVal)
- {
- try
- {
- Double.Parse(sVal);
- return true;
- }
- catch
- {
- return false;
- }
- }
- /// <summary>
- /// 检验是否为数字
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为数字:true代表是,false代表否</returns>
- public static bool IsNumber(string str)
- {
- Regex rx = new Regex(@"^[+-]?[0123456789]*[.]?[0123456789]*$");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验字符串是否为日期时间
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为日期时间:true代表是,false代表否</returns>
- public static bool IsNotDateTime(string str)
- {
- DateTime dt = new DateTime();
- return (!(DateTime.TryParse(str, out dt)));
- }
- /// <summary>
- /// 检验字符串是否为邮政编码
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为邮政编码:true代表是,false代表否</returns>
- public static bool IsPostCode(string str)
- {
- Regex rx = new Regex(@"^[0123456789]{6}$");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验字符串是否为身份证号
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为身份证号:true代表是,false代表否</returns>
- public static bool IsCode(string str)
- {
- Regex rx = new Regex(@"^[0123456789]{15,18}$");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验字符串是否为电子邮件
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为电子邮件:true代表是,false代表否</returns>
- public static bool IsEMail(string str)
- {
- Regex rx = new Regex(@"w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验字符串是否为中国地区的电话号码
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为中国地区的电话号码:true代表是,false代表否</returns>
- public static bool IsPhoneNumber(string str)
- {
- Regex rx = new Regex(@"((d{3,4})|d{3,4}-)?d{7,8}(-d{3})*");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验字符串是否为汉字
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为汉字:true代表是,false代表否</returns>
- public static bool IsChinese(string str)
- {
- Regex rx = new Regex(@"u4e00-u9fa5");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验字符串是否为双字节字符(包括汉字)
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为双字节字符:true代表是,false代表否</returns>
- public static bool IsDoubleByteChar(string str)
- {
- Regex rx = new Regex(@"[^x00-xff]");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验字符串是否为URL地址
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为URL地址:true代表是,false代表否</returns>
- public static bool IsURLAddress(string str)
- {
- Regex rx = new Regex(@"[a-zA-z]+://[^s]*");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 检验字符串是否为IP地址
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>是否为IP地址:true代表是,false代表否</returns>
- public static bool IsIPAddress(string str)
- {
- Regex rx = new Regex(@"d+.d+.d+.d+");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 清除字符串中的HTML标签(对于复杂的嵌套标签有时不准确)
- /// </summary>
- /// <param name="toEvaluate">指定的要被处理的字符串</param>
- /// <returns>清除HTML标签后的字符串</returns>
- public static string RemoveHtmlTags(string toEvaluate)
- {
- Regex rx = new Regex(@"s/<[a-zA-Z/][^>]*>//g", RegexOptions.IgnoreCase);
- return rx.Replace(toEvaluate, "");
- }
- /// <summary>
- /// 判断输入的字符串是否完全匹配正则
- /// </summary>
- /// <param name="RegexExpression">正则表达式</param>
- /// <param name="str">待判断的字符串</param>
- /// <returns></returns>
- public static bool IsValiable(string RegexExpression, string str)
- {
- bool blResult = false;
- Regex rep = new Regex(RegexExpression, RegexOptions.IgnoreCase);
- //blResult = rep.IsMatch(str);
- Match mc = rep.Match(str);
- if (mc.Success)
- {
- if (mc.Value == str) blResult = true;
- }
- return blResult;
- }
- /// <summary>
- /// 判断DataSet是否是空值
- /// </summary>
- /// <param name="ds">DataSet数据</param>
- /// <returns>true 空值</returns>
- public static bool IsNullData(DataSet ds)
- {
- if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 值比对 sSign:符号,sMin:最小值,sMax:最大值,sRealVal:实际值
- /// </summary>
- /// <param name="sSign"></param>
- /// <param name="sMin"></param>
- /// <param name="sMax"></param>
- /// <param name="sRealVal"></param>
- /// <returns></returns>
- public static bool ValIsEligible(string sSign, string sMin, string sMax, string sRealVal)
- {
- try
- {
- switch (sSign)
- {
- case ">":
- return (double.Parse(sMin) < double.Parse(sRealVal));
- case ">=":
- return (double.Parse(sMin) <= double.Parse(sRealVal));
- case "=":
- if (Globals.IsDouble(sMin))
- return (double.Parse(sMin) == double.Parse(sRealVal));
- else
- return (sMin == sRealVal);
- case "<":
- return (double.Parse(sMax) > double.Parse(sRealVal));
- case "<=":
- return (double.Parse(sMax) >= double.Parse(sRealVal));
- default:
- return true;
- }
- }
- catch
- {
- return false;
- }
- }
- #endregion
- /// <summary>
- /// 数字转换成中文数字
- /// </summary>
- /// <param name="strNum"></param>
- /// <returns></returns>
- public static string ConvertNumberToChinese(string strNum)
- {
- string[] Nums = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
- string[] Digits = { "", "拾", "佰", "仟" };
- string[] Units = { "元", "万", "亿", "万亿" };
- string x, y, z = "";
- if (strNum.Length > 2)
- {
- x = strNum.Substring(0, strNum.Length - 2);
- y = strNum.Substring(strNum.Length - 2, 2);
- }
- else
- {
- x = "";
- y = strNum;
- }
- if (y.Length == 2)
- {
- int n = Convert.ToInt32(y.Substring(0, 1));
- z = Nums[n] + "角";
- }
- if (y.Length > 0)
- {
- int n = Convert.ToInt32(y.Substring(y.Length - 1, 1));
- z += Nums[n] + "分";
- }
- if (y.Length == 0)
- {
- if (x.Length == 0)
- z = "零元整";
- else
- z = "整";
- }
- string S = ""; //返回值
- int p = 0; //字符位置指针
- int m = x.Length % 4; //取模
- // 四位一组得到组数
- int k = (m > 0 ? x.Length / 4 + 1 : x.Length / 4);
- // 外层循环在所有组中循环
- // 从左到右 高位到低位 四位一组 逐组处理
- // 每组最后加上一个单位: "[万亿]","[亿]","[万]"
- for (int i = k; i > 0; i--)
- {
- int L = 4;
- if (i == k && m != 0)
- {
- L = m;
- }
- // 得到一组四位数 最高位组有可能不足四位
- string s = x.Substring(p, L);
- int l = s.Length;
- // 内层循环在该组中的每一位数上循环 从左到右 高位到低位
- for (int j = 0; j < l; j++)
- {
- //处理改组中的每一位数加上所在位: "仟","佰","拾",""(个)
- int n = Convert.ToInt32(s.Substring(j, 1));
- if (n == 0)
- {
- if (j < l - 1
- && Convert.ToInt32(s.Substring(j + 1, 1)) > 0 //后一位(右低)
- && !S.EndsWith(Nums[n]))
- {
- S += Nums[n];
- }
- }
- else
- {
- //处理 1013 一千零"十三", 1113 一千一百"一十三"
- if (!(n == 1 && (S.EndsWith(Nums[0]) | S.Length == 0) && j == l - 2))
- {
- S += Nums[n];
- }
- S += Digits[l - j - 1];
- }
- }
- p += L;
- // 每组最后加上一个单位: [万],[亿] 等
- if (i < k) //不是最高位的一组
- {
- if (Convert.ToInt32(s) != 0)
- {
- //如果所有 4 位不全是 0 则加上单位 [万],[亿] 等
- S += Units[i - 1];
- }
- }
- else
- {
- //处理最高位的一组,最后必须加上单位
- S += Units[i - 1];
- }
- }
- return S + z;
- }
-
- /// <summary>
- /// 打开其他工程中的窗体
- /// </summary>
- /// <param name="vParentFrm">主窗体 (this.MdiParent)</param>
- /// <param name="vKey">一般为窗体的全称 + 配置信息(可无)</param>
- /// <param name="vAssemblyName">程序集名</param>
- /// <param name="vClassName">窗体的全称</param>
- /// <param name="vCaption">窗体的中文名</param>
- public static void OpenOtherAssemblyForm(Form vParentFrm, string vKey, string vAssemblyName,
- string vClassName, string vCaption)
- {
- //检查窗体是否已经打开
- foreach (Form mdiChild in vParentFrm.MdiChildren)
- {
- if ((mdiChild as FrmBase).Key == vKey)
- {
- mdiChild.Activate();
- return;
- }
- }
- //实例化窗体并打开
- try
- {
- Assembly baseFormAssembly = Assembly.Load(vAssemblyName);
- Type type = baseFormAssembly.GetType(vClassName);
- System.Diagnostics.Debug.Assert(type.IsSubclassOf(typeof(FrmBase)));
- FrmBase form = Activator.CreateInstance(type, true) as FrmBase;
- form.MdiParent = vParentFrm;
- form.Text = vCaption;
- form.Key = vKey;
- form.Show();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- ///// <summary>
- ///// 获取当前班次
- ///// </summary>
- ///// <returns></returns>
- //public static string GetCurrentClass(RemotingHelp RemotingHelp)
- //{
- // string szOut = "";
- // CallingMessage par = new CallingMessage();
- // par.ServerName = "lgJobMgt";
- // par.AssemblyName = "Core.LgMes.Server.lgJobMgt";
- // par.ClassName = "Core.LgMes.Server.lgJobMgt.classCommonModule";
- // par.MethodName = "GetCurrDuty";
- // par.args = null;
- // object obj = ClientCommon._RemotingHelp.ExecuteMethod(par, out szOut);
- // if (szOut == "" && obj != null)
- // {
- // return obj as string;
- // }
- // return "";
- //}
- /// <summary>
- /// 班次转换
- /// </summary>
- /// <returns></returns>
- public static string ClassConvert(string szClassID)
- {
- if (szClassID.Trim() == "")
- return "";
- if (szClassID.Length == 2)
- szClassID = szClassID.Substring(1);
- string szClassName = "";
- switch (szClassID)
- {
- case "1":
- szClassName = "甲";
- break;
- case "2":
- szClassName = "乙";
- break;
- case "3":
- szClassName = "丙";
- break;
- case "4":
- szClassName = "丁";
- break;
- default:
- break;
- }
- return szClassName;
- }
- /// <summary>
- /// 时间计算返回分
- /// </summary>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <returns></returns>
- public static int caculateTime(DateTime startTime, DateTime endTime)
- {
- int lStayDuration = 0;
- TimeSpan odtSpan;
- if (endTime > startTime)
- {
- odtSpan = endTime - startTime;
- lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalMinutes));
- }
- else if (startTime != endTime)
- {
- if (startTime > DateTime.Now)
- lStayDuration = 0;
- else
- {
- odtSpan = DateTime.Now - startTime;
- lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalMinutes));
- }
- }
- return lStayDuration;
- }
- /// <summary>
- /// 时间计算返回秒
- /// </summary>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <returns></returns>
- public static int caculateTimeSeconds(DateTime startTime, DateTime endTime)
- {
- int lStayDuration = 0;
- TimeSpan odtSpan;
- if (endTime > startTime)
- {
- odtSpan = endTime - startTime;
- lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalSeconds));
- }
- else if (startTime != endTime)
- {
- if (startTime > DateTime.Now)
- lStayDuration = 0;
- else
- {
- odtSpan = DateTime.Now - startTime;
- lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalSeconds));
- }
- }
- return lStayDuration;
- }
- /// <summary>
- /// 获取两个时间段的差值
- /// </summary>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <returns></returns>
- public static int JudgeTime(DateTime startTime, DateTime endTime)
- {
- int lStayDuration = 0;
- TimeSpan odtSpan;
- if (endTime > startTime)
- {
- odtSpan = endTime - startTime;
- lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalMinutes));
- }
- return lStayDuration;
- }
- /// <summary>
- /// 将ultragrid的数据导出到Excel中
- /// </summary>
- /// <param name="ulGrid">要导出数据的ulGrid名称</param>
- /// <param name="sFileName">Excel文件名</param>
- public static void ulGridToExcel(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid, string sFileName)
- {
- try
- {
- Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ulGridExt = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter();
- //ulGridExt.CellExporting += new Infragistics.Win.UltraWinGrid.ExcelExport.CellExportingEventHandler(ultraGridExcelExporter1_CellExporting);
- System.Windows.Forms.SaveFileDialog saveFileDialog1 = new SaveFileDialog();
- if (ulGrid.Rows.Count == 0)
- {
- MessageBox.Show("没有数据!", "提示");
- return;
- }
- saveFileDialog1.FileName = sFileName + DateTime.Now.ToString("yyMMdd");
- saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- string sFullName = saveFileDialog1.FileName;
- ulGridExt.Export(ulGrid, sFullName);
- ProcessStartInfo p = new ProcessStartInfo(sFullName);
- p.WorkingDirectory = Path.GetDirectoryName(sFullName);
- Process.Start(p);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("导出失败,原因:" + ex.Message);
- }
- }
- /// <summary>
- /// 将ultragrid的数据导出到Excel中
- /// </summary>
- /// <param name="ulGridList">ulGrid组</param>
- /// <param name="sheetNameList">顺序对应的Sheet名称</param>
- /// <param name="sFileName">Excel文件名</param>
- public static void ulGridToExcel(ArrayList ulGridList, ArrayList sheetNameList, string sFileName)
- {
- try
- {
- Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ulGridExt = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter();
- //ulGridExt.CellExporting += new Infragistics.Win.UltraWinGrid.ExcelExport.CellExportingEventHandler(ultraGridExcelExporter1_CellExporting);
- System.Windows.Forms.SaveFileDialog saveFileDialog1 = new SaveFileDialog();
- saveFileDialog1.FileName = sFileName + DateTime.Now.ToString("yyMMdd") + ".xls";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- string sFullName = saveFileDialog1.FileName;
- Infragistics.Excel.Workbook workbook1 = new Infragistics.Excel.Workbook();
- for (int i = 0; i < ulGridList.Count; i++)
- {
- Infragistics.Win.UltraWinGrid.UltraGrid itemGrid = ulGridList[i] as Infragistics.Win.UltraWinGrid.UltraGrid;
- string sheetname = (sheetNameList.Count > i && sheetNameList[i].ToString() != "")
- ? sheetNameList[i].ToString() : ("sheet" + i.ToString());
- workbook1.Worksheets.Add(sheetname);
- //没有数据时会出错,所以没有数据的面不不调用
- if (itemGrid.Rows.Count > 0)
- ulGridExt.Export(itemGrid, workbook1.Worksheets[i]);
- }
- workbook1.Save(sFullName);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("导出失败,原因:" + ex.Message);
- }
- }
- ///// <summary>
- ///// 当Grid导出EXCEL时,列字段中的值为编码时,将编码转换成中文
- ///// </summary>
- ///// <param name="sender"></param>
- ///// <param name="e"></param>
- //public static void ultraGridExcelExporter1_CellExporting(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.CellExportingEventArgs e)
- //{
- // try
- // {
- // if (e.GridColumn.RowLayoutColumnInfo.LabelPosition == Infragistics.Win.UltraWinGrid.LabelPosition.LabelOnly)
- // {
- // e.Cancel = true;
- // }
- // if (e.GridColumn.EditorControl != null || e.GridColumn.ValueList != null)
- // {
- // e.Value = e.GridRow.GetCellText(e.GridColumn);
- // }
- // }
- // catch
- // {
- // }
- //}
- /// <summary>
- /// 清除Grid的列过滤
- /// </summary>
- /// <param name="ulGrid">Grid名称</param>
- public static void ClearUlGridFilter(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid)
- {
- ulGrid.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters();
- }
- /// <summary>
- /// 增加Grid的列过滤
- /// </summary>
- /// <param name="ulGrid"></param>
- public static void AddUlGridFilter(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid)
- {
- ulGrid.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
- }
- //查找treeView结点的父结点
- public static TreeNode findParentNode(TreeNode preLvlNode, string parentKey)
- {
- if (preLvlNode.Name == parentKey) return preLvlNode;
- foreach (TreeNode node in preLvlNode.Nodes)
- {
- if (node.Name.Length <= parentKey.Length)
- {
- if (node.Nodes.Count > 0)
- {
- TreeNode tNode = findParentNode(node, parentKey);
- if (tNode != null)
- return tNode;
- }
- else
- if (node.Name == parentKey)
- return node;
- }
- else
- return null;
- }
- return null;
- }
- }
- public class ValueListItem
- {
- string _id = "";
- string _name = "";
- public string ID
- {
- get { return _id; }
- set { _id = value; }
- }
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
- public ValueListItem(string sID, string sName)
- {
- _id = sID;
- _name = sName;
- }
- public override string ToString()
- {
- return _name;
- }
- }
|