| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- using System;
- using Core.Mes.Client.Comm.Server;
- using Infragistics.Win.UltraWinEditors;
- using CoreFS.CA06;
- using System.Data;
- using Infragistics.Win.UltraWinGrid;
- using System.Drawing;
- using Infragistics.Win;
- using System.Text.RegularExpressions;
- using Core.Mes.Client.Comm.Control;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace Core.StlMes.Client.PnCost
- {
- class PnCostBaseClass
- {
- /// <summary>
- /// 初始化下拉框(增强型)
- /// </summary>
- /// <param name="uce">下拉框</param>
- /// <param name="methodId">请求的服务</param>
- /// <param name="valueMember">值成员</param>
- /// <param name="textMember">显示成员</param>
- /// <param name="ob">ob对象</param>
- /// <param name="isEmpty">是否添加空行</param>
- public static void InitComboEditorNew(UltraComboEditor uce, string methodId, string valueMember, string textMember, OpeBase ob, bool isEmpty)
- {
- InitComboEditor(uce, methodId, valueMember, ob, isEmpty);
- uce.DisplayMember = textMember;
- }
- /// <summary>
- /// 初始化下拉框
- /// </summary>
- /// <param name="uce">下拉框</param>
- /// <param name="methodId">请求的服务</param>
- /// <param name="valueMember">值成员</param>
- /// <param name="ob">ob对象</param>
- /// <param name="isEmpty">是否有空行</param>
- public static void InitComboEditor(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty)
- {
- DataTable dt = ServerHelper.GetData(methodId, null, ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- if (isEmpty)
- {
- Object[] obj = new Object[] { "", "" };
- DataRow dr = dt.NewRow();
- dr.ItemArray = obj;
- dt.Rows.InsertAt(dr, 0);
- }
- uce.DataSource = dt;
- uce.ValueMember = valueMember;
- SetComboItemHeight(uce);
- }
- }
- /// <summary>
- /// 初始化下拉框 --带参数的
- /// </summary>
- /// <param name="uce"></param>
- /// <param name="methodId"></param>
- /// <param name="valueMember"></param>
- /// <param name="ob"></param>
- /// <param name="isEmpty"></param>
- /// <param name="obj"></param>
- public static void InitComboEditorWithParm(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty, Object[] parm)
- {
- DataTable dt = ServerHelper.GetData(methodId, parm, ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- if (isEmpty)
- {
- Object[] obj = new Object[] { "", "" };
- DataRow dr = dt.NewRow();
- dr.ItemArray = obj;
- dt.Rows.InsertAt(dr, 0);
- }
- uce.DataSource = dt;
- uce.ValueMember = valueMember;
- SetComboItemHeight(uce);
- }
- }
- /// <summary>
- /// 设置GRID行的颜色
- /// </summary>
- /// <param name="ultragrid">要设置的GRID</param>
- public static void SetGridRowColor(UltraGrid ultragrid)
- {
- if (ultragrid == null)
- return;
- foreach (UltraGridRow row in ultragrid.Rows)
- {
- if (row.Cells["VALIDFLAG"].Value.ToString().ToUpper() != "TRUE" && row.Cells["VALIDFLAG"].Value.ToString() != "有效")
- {
- row.Appearance.ForeColor = Color.Red;
- }
- else
- {
- row.Appearance.ForeColor = Color.Black;
- }
- if (row.HasChild() && row.ChildBands[0].Rows.Count > 0) //主从表--子表
- {
- foreach (UltraGridRow crow in row.ChildBands[0].Rows)
- {
- if (crow.Cells["VALIDFLAG"].Value.ToString().ToUpper() != "TRUE" && crow.Cells["VALIDFLAG"].Value.ToString() != "有效")
- {
- crow.Appearance.ForeColor = Color.Red;
- }
- else
- {
- crow.Appearance.ForeColor = Color.Black;
- }
- }
- }
- }
- }
- /// <summary>
- ///设置GRID不可编辑 不带选择框
- /// </summary>
- /// <param name="ug">GRID</param>
- public static void SetGridActivateOnly(UltraGrid ug)
- {
- if (ug == null)
- return;
- foreach (UltraGridRow row in ug.Rows)
- {
- for (int i = 0; i < row.Cells.Count; i++)
- row.Cells[i].Activation = Activation.ActivateOnly;
- }
- }
- /// <summary>
- /// 设置UltraComboEditor中的中文和非中文统一高度。
- /// </summary>
- /// <param name="cmb"></param>
- public static void SetComboItemHeight(UltraComboEditor cmb)
- {
- foreach (ValueListItem item in cmb.Items)
- {
- if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
- {
- item.Appearance.FontData.SizeInPoints = 9.0F;
- }
- else
- {
- item.Appearance.FontData.SizeInPoints = 10.5F;
- }
- }
- }
- /// <summary>
- /// 用于基础信息表的操作后的定位
- /// </summary>
- /// <param name="ultragrid">要定位的GRID</param>
- /// <param name="colName">要定位的列名</param>
- /// <param name="keyword">关键字</param>
- public static void Postioning(UltraGrid ultragrid, string colName, string keyword)
- {
- foreach (UltraGridRow row in ultragrid.Rows)
- {
- if (row.Cells[colName].Value.ToString() == keyword)
- {
- row.Activate();
- break;
- }
- }
- }
- /// <summary>
- /// GRID列自适应 除了备注列
- /// </summary>
- /// <param name="ug">GRID</param>
- public static void SetColAutoSizeExceptMemo(UltraGrid ug)
- {
- UltraGridColumn[] col = new UltraGridColumn[] { ug.DisplayLayout.Bands[0].Columns["MEMO"] };
- GridHelper.RefreshAndAutoSizeExceptColumns(ug, col);
- }
- /// <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)
- {
- for (int i = 0; i < dt2.Rows.Count; i++)
- {
- string conditionValue = dt2.Rows[i][condition].ToString();
- DataRow[] dr = dt1.Select(condition + "='" + conditionValue + "'");
- if (dr == null || dr.Length == 0)
- dt2.Rows[i].Delete();
- }
- dt2.AcceptChanges();
- return dt2;
- }
- return null;
- }
- /// <summary>
- /// 将下拉框绑定到GRID列
- /// </summary>
- /// <param name="uce">下拉框(已经初始化完成)</param>
- /// <param name="ColumnName">列名</param>
- /// <param name="con">空间集合(每次只需填入this.Controls)</param>
- /// <param name="ug">GRID</param>
- /// <param name="i">GRID的第几层结构</param>
- public static void BindColumn(UltraComboEditor uce, string ColumnName, System.Windows.Forms.Control.ControlCollection con, UltraGrid ug, int i)
- {
- con.Add(uce);
- uce.Visible = false;
- ug.DisplayLayout.Bands[i].Columns[ColumnName].EditorComponent = uce;
- ug.DisplayLayout.Bands[i].Columns[ColumnName].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDown;
- SetComboItemHeight(uce);
- }
- /// <summary>
- /// 绑定生成一个有树结构的下拉菜单
- /// </summary>
- /// <param name= "dtNodeSets "> 菜单记录数据所在的表 </param>
- /// <param name= "strParentColumn "> 表中用于标记父记录的字段 </param>
- /// <param name= "strRootValue "> 第一层记录的父记录值(通常设计为0或者-1或者Null)用来表示没有父记录 </param>
- /// <param name= "strIndexColumn "> 索引字段,也就是放在DropDownList的Value里面的字段 </param>
- /// <param name= "strTextColumn "> 显示文本字段,也就是放在DropDownList的Text里面的字段 </param>
- /// <param name= "drpBind "> 需要绑定的DropDownList </param>
- /// <param name= "i "> 用来控制缩入量的值,请输入-1 </param>
- public static void MakeTree(DataTable dtNodeSets, string strParentColumn, string strRootValue, string strIndexColumn, string strTextColumn, TreeNodeCollection drpBind, int i)
- {
- //每向下一层,多一个缩入单位
- i++;
- DataView dvNodeSets = new DataView(dtNodeSets);
- string filter = string.IsNullOrEmpty(strRootValue) ? strParentColumn + " is null" : string.Format(strParentColumn + "='{0}'", strRootValue);
- dvNodeSets.RowFilter = filter;
- string strPading = " "; //缩入字符
- //通过i来控制缩入字符的长度,我这里设定的是一个全角的空格
- for (int j = 0; j < i; j++)
- strPading += " ";//如果要增加缩入的长度,改成两个全角的空格就可以了
- foreach (DataRowView drv in dvNodeSets)
- {
- TreeNode tnNode = new TreeNode();
- tnNode = new TreeNode();//建立一个新节点(学名叫:一个实例)
- tnNode.Tag = drv[strIndexColumn].ToString();//节点的Value值,一般为数据库的id值
- tnNode.Text = drv[strTextColumn].ToString();//节点的Text,节点的文本显示
- if (!string.IsNullOrEmpty(drv["PID"].ToString()))
- {
- tnNode.ToolTipText = drv["PID"].ToString();
- }
- else
- {
- tnNode.ImageIndex = 0;
- }
- //ListItem li = new ListItem(strPading + "|- " + drv[strTextColumn].ToString(), drv[strIndexColumn].ToString());
- drpBind.Add(tnNode);
- MakeTree(dtNodeSets, strParentColumn, drv[strIndexColumn].ToString(), strIndexColumn, strTextColumn, tnNode.Nodes, i);
- }
- //递归结束,要回到上一层,所以缩入量减少一个单位
- i--;
- }
- /// <summary>
- /// 时间计算返回月
- /// </summary>
- /// <param name="startTime">开始时间</param>
- /// <param name="endTime">结束时间</param>
- /// <returns></returns>
- public static int getMonth(DateTime startTime, DateTime endTime)
- {
- int year1 = startTime.Year;
- int year2 = endTime.Year;
- int month1 = startTime.Month;
- int month2 = endTime.Month;
- int months = 12 * (year2 - year1) + (month2 - month1);
- return months;
- }
- }
- }
|