| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513 |
- using Core.Mes.Client.Comm.Server;
- using Core.Mes.Client.Comm.Tool;
- using CoreFS.CA06;
- using Infragistics.Win.UltraWinEditors;
- using Infragistics.Win.UltraWinGrid;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Text.RegularExpressions;
- namespace Core.StlMes.Client.Qcm
- {
- /// <summary>
- /// 公共方法类
- /// </summary>
- public class QcmBaseCommon
- {
- /// <summary>
- /// 过滤主表中没有但从表有的记录
- /// </summary>
- /// <param name="dt1">主表</param>
- /// <param name="dt2">从表</param>
- /// <param name="condition">关联主键</param>
- public static DataTable FilterTable(DataTable dt1, DataTable dt2, string condition)
- {
- if (dt1 != null && dt1.Rows.Count > 0 && dt2 != null)
- {
- dt2.BeginInit();
- for (int i = 0; i < dt2.Rows.Count; i++)
- {
- string pic = dt2.Rows[i][condition].ToString();
- DataRow[] dr = dt1.Select(condition + "='" + pic + "'");
- if (dr == null || dr.Length == 0)
- dt2.Rows[i].Delete();
- }
- dt2.EndInit();
- dt2.AcceptChanges();
- return dt2;
- }
- return null;
- }
- /// <summary>
- /// 初始化上限符号
- /// </summary>
- /// <param name="uce">下拉框</param>
- public static void InitSignMax(UltraComboEditor uce)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("STDMAX_SIGN");
- DataRow dr1 = dt.NewRow();
- dr1["STDMAX_SIGN"] = "<";
- DataRow dr2 = dt.NewRow();
- dr2["STDMAX_SIGN"] = "<=";
- DataRow dr3 = dt.NewRow();
- dr3["STDMAX_SIGN"] = "";
- dt.Rows.Add(dr1);
- dt.Rows.Add(dr2);
- dt.Rows.Add(dr3);
- uce.DataSource = dt;
- uce.DisplayMember = "STDMAX_SIGN";
- }
- /// <summary>
- /// 初始化下限符号
- /// </summary>
- /// <param name="uce">下拉框</param>
- public static void InitSignMin(UltraComboEditor uce)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("STDMIN_SIGN");
- DataRow dr1 = dt.NewRow();
- dr1["STDMIN_SIGN"] = ">";
- DataRow dr2 = dt.NewRow();
- dr2["STDMIN_SIGN"] = ">=";
- DataRow dr3 = dt.NewRow();
- dr3["STDMIN_SIGN"] = "=";
- DataRow dr4 = dt.NewRow();
- dr4["STDMIN_SIGN"] = "";
- dt.Rows.Add(dr1);
- dt.Rows.Add(dr2);
- dt.Rows.Add(dr3);
- dt.Rows.Add(dr4);
- uce.DataSource = dt;
- uce.DisplayMember = "STDMIN_SIGN";
- }
- /// <summary>
- /// 让ultraGrid 不可以编辑(排除选择按钮)
- /// </summary>
- public static void SetUltraGridNoEdit(UltraGrid ultraGrid1)
- {
- for (int i = 0; i < ultraGrid1.Rows.Count; i++)
- {
- UltraGridRow ugr = ultraGrid1.Rows[i];
- for (int j = 0; j < ugr.Cells.Count; j++)
- {
- if (!ugr.Cells[j].Column.Key.Equals("CHC"))
- ugr.Cells[j].Activation = Activation.ActivateOnly;
- }
- if (ugr.HasChild())
- {
- for (int j = 0; j < ugr.ChildBands[0].Rows.Count; j++)
- {
- for (int k = 0; k < ugr.ChildBands[0].Rows[j].Cells.Count - 1; k++)
- {
- if (!ugr.ChildBands[0].Rows[j].Cells[k].Column.Key.Equals("CHC"))
- ugr.ChildBands[0].Rows[j].Cells[k].Activation = Activation.ActivateOnly;
- }
- }
- }
- }
- }
- /// <summary>
- /// 颜色区别
- /// </summary>
- /// <param name="ultraGrid">数据集</param>
- /// <param name="columnName">列</param>
- /// <param name="columnName">属性</param>
- public static void DistinguishColor(UltraGrid ultraGrid, string columnName, string state)
- {
- UltraGridRow row = null;
- UltraGridRow rowChild = null;
- for (int i = 0; i < ultraGrid.Rows.Count; i++)
- {
- row = ultraGrid.Rows[i];
- if (!row.Cells[columnName].Value.ToString().Equals(state))
- {
- row.Appearance.ForeColor = Color.Red;
- }
- if (row.HasChild())
- {
- for (int j = 0; j < row.ChildBands[0].Rows.Count; j++)
- {
- rowChild = row.ChildBands[0].Rows[j];
- if (!rowChild.Cells[columnName].Value.ToString().Equals(state))
- rowChild.Appearance.ForeColor = Color.Red;
- }
- }
- }
- }
- /// <summary>
- /// 颜色区别
- /// </summary>
- /// <param name="ultraGrid">数据集</param>
- /// <param name="columnName">列</param>
- /// <param name="columnName">属性</param>
- public static void SetGridColor(UltraGrid ultraGrid, string columnName, string state)
- {
- UltraGridRow row = null;
- UltraGridRow rowChild = null;
- for (int i = 0; i < ultraGrid.Rows.Count; i++)
- {
- row = ultraGrid.Rows[i];
- if (row.Cells[columnName].Value.ToString().Equals(state))
- {
- row.Appearance.ForeColor = Color.Red;
- }
- if (row.HasChild())
- {
- for (int j = 0; j < row.ChildBands[0].Rows.Count; j++)
- {
- rowChild = row.ChildBands[0].Rows[j];
- if (rowChild.Cells[columnName].Value.ToString().Equals(state))
- rowChild.Appearance.ForeColor = Color.Red;
- }
- }
- }
- }
- /// <summary>
- /// 初始化下拉框
- /// </summary>
- /// <param name="methodID">方法名</param>
- /// <param name="ob">OB对象</param>
- /// <param name="uce">下拉框</param>
- /// <param name="showValue">显示值</param>
- /// <param name="isNull">是否需要空白行</param>
- public static void InitDropUltraComEditor(UltraComboEditor uce, string methodID, string showValue, OpeBase ob, Boolean isNull)
- {
- DataTable dt = ServerHelper.GetData(methodID, new Object[] { }, ob);
- QcmBaseCommon.InitDropList(uce, dt, showValue, isNull);
- ClsBaseInfo.SetComboItemHeight(uce);
- }
- /// <summary>
- /// 初始下拉框
- /// </summary>
- public static void InitDropList(UltraComboEditor uce, DataTable dt, string showValue, Boolean isNull)
- {
- if (dt != null && dt.Rows.Count > 0)
- {
- DataTable dtNext = new DataTable();
- dtNext.Columns.Add("ID");
- dtNext.Columns.Add("NAME");
- if (isNull)
- {
- DataRow dr = dtNext.NewRow();
- dr["ID"] = "";
- dr["NAME"] = "";
- dtNext.Rows.Add(dr);
- }
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- DataRow dr = dtNext.NewRow();
- string str = "";
- for (int j = 0; j < dt.Columns.Count; j++)
- {
- if (dt.Columns[j].Caption.Equals(showValue))
- dr["NAME"] = dt.Rows[i][j].ToString();
- else
- {
- str = str + "@" + dt.Rows[i][j].ToString();
- }
- }
- dr["ID"] = str.Substring(1);
- dtNext.Rows.Add(dr);
- }
- uce.DataSource = dtNext;
- uce.DisplayMember = "NAME";
- uce.ValueMember = "ID";
- }
- }
- /// <summary>
- /// 初始化下拉框
- /// </summary>
- /// <param name="uce">下拉框</param>
- /// <param name="methodID">方法名</param>
- /// <param name="showName">显示值</param>
- /// <param name="value">隐藏值</param>
- /// <param name="isNull">是否有空行</param>
- /// <param name="ob">OB对象</param>
- public static void InitDrop(UltraComboEditor uce, string methodID, string showName, string value, Boolean isNull, OpeBase ob)
- {
- DataTable dt = ServerHelper.GetData(methodID, new Object[] { }, ob);
- if (dt != null && dt.Rows.Count > 0 && isNull)
- {
- DataRow dr = dt.NewRow();
- for (int i = 0; i < dt.Columns.Count; i++)
- {
- dr[i] = "";
- }
- dt.Rows.InsertAt(dr, 0);
- }
- uce.DataSource = dt;
- uce.DisplayMember = showName;
- uce.ValueMember = value;
- ClsBaseInfo.SetComboItemHeight(uce);
- }
- /// <summary>
- /// 展开
- /// </summary>
- /// <param name="expanl"></param>
- public static void Expanl(UltraGrid ultraGrid1, ref Dictionary<int, int> expanl)
- {
- if (expanl.Count == 0)
- {
- if (ultraGrid1.Rows.Count > 0)
- ultraGrid1.DisplayLayout.Rows[0].Activate();
- }
- else
- {
- Dictionary<int, int>.KeyCollection keycol = expanl.Keys;
- {
- foreach (int key in keycol)
- {
- if (key < ultraGrid1.Rows.Count)
- ultraGrid1.Rows[key].Activate();
- if (expanl[key] > -1)
- {
- if (key < ultraGrid1.Rows.Count)
- ultraGrid1.Rows[key].ExpandAll();
- }
- }
- }
- }
- expanl.Clear();
- }
- /// <summary>
- /// 检测公式的合法性(针对表达式是"外径","壁厚","径壁比"的四则运算)
- /// </summary>
- /// <param name="str">输入的公式</param>
- /// <returns>0代表合法,-1代表不合法</returns>
- public static int TestFormula(string str)
- {
- string formula = str.Replace("壁厚", "A"); //壁厚替换为A
- formula = formula.Replace("外径", "B"); //外径替换为B
- formula = formula.Replace("径壁比", "C"); //径壁比替换为C
- formula = formula.Replace("Axc", "D"); //试样面积替换为D
- formula = formula.Replace("(", "("); //中文括号替换为英文括号
- formula = formula.Replace(")", ")"); //中文括号替换为英文括号
- //由于下面的正则表达式有缺陷,这里手动判断括号的数量是否匹配(但不匹配是否成对)
- int left = 0;
- int right = 0;
- for (int i = 0; i < formula.Length; i++)
- {
- if (formula[i] == '(')
- left += 1;
- if (formula[i] == ')')
- right += 1;
- }
- if (left != right)
- {
- return -1;
- }
- char[] ch = { '(', ')', '+', '-', '*', '/', ' ', '^' }; //切割获取项目,+-*/空格 括号
- string[] element = formula.Split(ch, StringSplitOptions.RemoveEmptyEntries); //按ch数组切割,并去掉空格字符串
- for (int i = 0; i < element.Length; i++) //判断输入的是否是"外径","壁厚","径壁比"和数字
- {
- if (element[i] != "A" && element[i] != "B" && element[i] != "C" && element[i] != "D" && !StringUtil.IsInt(element[i]))
- {
- return -1;
- }
- }
- //输入规则是否符合四则运算规则。有缺陷,"(A+B" "A+B)"下面的正则表达式会认为这两种情况合法
- //string reg = @"^(\(*[A-C0-9]+(.[A-C0-9]+)*\)*(\+|-|/|\*))+[A-C0-9]+(.[A-C0-9]+)*\)*$";
- string reg = @"^(\(*[A-D0-9]+(.[A-D0-9]+)*\)*(\+|-|/|\*))+[A-D0-9]+(.[A-D0-9]+)*\)*$";
- if (Regex.IsMatch(formula, reg))
- {
- return 0;
- }
- else
- {
- return -1;
- }
- }
- /// <summary>
- /// ULTRAGRID不可编辑
- /// </summary>
- /// <param name="ug"></param>
- public static void SetNoEdit(UltraGrid ug)
- {
- if (ug == null || ug.Rows.Count <= 0)
- {
- return;
- }
- foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
- {
- if (!ugc.Key.Equals("CHC"))
- ugc.CellActivation = Activation.ActivateOnly;
- }
- }
- /// <summary>
- /// 检验公式是否合理
- /// </summary>
- /// <param name="formula">公式字符串</param>
- /// <returns>合理返回True,不合理返回False</returns>
- public static bool CheckElement(String formula, OpeBase ob)
- {
- //例:(0.21-C)*0.05+1.2>1.65?1.65:(0.21-C)*0.05+1.2 或 (0.21-C)*0.05+0.60
- //替换输入法的差异
- string str = formula.Replace("?", "?");
- str.Replace(":", ":");
- str.Replace(">=", ">");
- str.Replace("<=", ">");
- str.Replace("<", ">");
- str.Replace("=", ">");
- str.Replace(" ", "");
- str.Replace("(", "(");
- str.Replace(")", ")");
- ArrayList list = CheckFirst(str, ob);
- if (list == null)
- {
- return false;
- }
- string reStr = formula;
- for (int i = 0; i < list.Count; i++)
- {
- reStr = reStr.Replace(list[i].ToString(), "1");
- }
- decimal? result;
- result = reStr.CompileFormula();
- if (result == null)
- {
- return false;
- }
- //MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass();
- //sc.Language = "JavaScript";
- // try
- // {
- // double a =double.Parse( sc.Eval(reStr).ToString());
- // }
- // catch
- // {
- // return false;
- // }
- return true;
- }
- public static ArrayList CheckFirst(string str, OpeBase ob)
- {
- //为化学公式去除+-*/
- string[] strSp = str.Split('?', ':', '>', '+', '-', '/', '*', ')', '(');
- ArrayList elements = new ArrayList();
- for (int i = 0; i < strSp.Length; i++)
- {
- //判断是否为数字,如果不是纯数字,则表示是化学元素,添加到ArrayList中,传递到后台。
- if (!StringUtil.IsNumber(strSp[i]))
- {
- if (!elements.Contains(strSp[i]))
- {
- elements.Add(strSp[i]);
- }
- }
- }
- DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.checkElement", new Object[] { elements }, ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- int i = Convert.ToInt32(dt.Rows[0][0].ToString());
- if (i != elements.Count)
- {
- return null;
- }
- }
- return elements;
- }
- /// <summary>
- /// 理化标准界面的公式验证
- /// </summary>
- /// <param name="formula">输入的公式字符串</param>
- /// <returns>是否合法</returns>
- public static bool CheckCompositeFormula(string formula)
- {
- if (formula.Equals(""))
- {
- return false;
- }
- //if ()
- if (!formula.Contains("D") && !formula.Contains("t") && !formula.Contains("Axc") && !formula.Contains("C")
- && !formula.Contains("Rm"))
- {
- return false;
- }
- string str = formula.Replace("D", "1");
- str = str.Replace("t", "1");
- str = str.Replace("Axc", "1");
- str = str.Replace("Rm", "1");
- str = str.Replace("C", "1");
- decimal? result;
- result = str.CompileFormula();
- if (result == null)
- {
- return false;
- }
- //MSScriptControl控件只能在32位系统运行,64位系统不能使用。故使用了上面扩展到string类的方法。
- //MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass();
- //sc.Language = "JavaScript";
- //try
- //{
- // double a = double.Parse(sc.Eval(str).ToString());
- //}
- //catch
- //{
- // return false;
- //}
- return true;
- }
- /// <summary>
- /// 公差界面的公式验证
- /// </summary>
- /// <param name="formula">输入的公式</param>
- /// <returns>是否合法</returns>
- public static bool CheckToleranceFormula(string formula)
- {
- if (formula.Equals(""))
- {
- return false;
- }
- if (!formula.Contains("D") && !formula.Contains("t") && !formula.Contains("L"))
- {
- return false;
- }
- string str = formula.Replace("D", "1.0");
- str = str.Replace("t", "1.0");
- str = str.Replace("L", "1.0");
- decimal? result;
- result = str.CompileFormula();
- if (result == null)
- {
- return false;
- }
- return true;
- }
- }
- }
|