using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using CoreFS.CA06; using Infragistics.Win; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinGrid; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; namespace Pur.balance { class YdmBaseClass { /// /// 初始化下拉框(增强型) /// /// 下拉框 /// 请求的服务 /// 值成员 /// 显示成员 /// ob对象 /// 是否添加空行 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; } /// /// 初始化下拉框 /// /// 下拉框 /// 请求的服务 /// 值成员 /// ob对象 /// 是否有空行 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); } } /// /// 初始化下拉框 --带参数的 /// /// /// /// /// /// /// 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); } } /// /// 设置GRID行的颜色 /// /// 要设置的GRID 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; } } } } } /// ///设置GRID不可编辑 不带选择框 /// /// GRID 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; } } /// /// 设置UltraComboEditor中的中文和非中文统一高度。 /// /// 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; } } } /// /// 用于基础信息表的操作后的定位 /// /// 要定位的GRID /// 要定位的列名 /// 关键字 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; } } } /// /// GRID列自适应 除了备注列 /// /// GRID public static void SetColAutoSizeExceptMemo(UltraGrid ug) { UltraGridColumn[] col = new UltraGridColumn[] { ug.DisplayLayout.Bands[0].Columns["MEMO"] }; GridHelper.RefreshAndAutoSizeExceptColumns(ug, col); } /// /// 过滤主表中没有但从表有的记录 /// /// 主表 /// 从表 /// 关联主键 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; } /// /// 将下拉框绑定到GRID列 /// /// 下拉框(已经初始化完成) /// 列名 /// 空间集合(每次只需填入this.Controls) /// GRID /// GRID的第几层结构 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; uce.Appearance.FontData.SizeInPoints = 9.0F; //SetComboItemHeight(uce); } /// /// 绑定生成一个有树结构的下拉菜单 /// /// 菜单记录数据所在的表 /// 表中用于标记父记录的字段 /// 第一层记录的父记录值(通常设计为0或者-1或者Null)用来表示没有父记录 /// 索引字段,也就是放在DropDownList的Value里面的字段 /// 显示文本字段,也就是放在DropDownList的Text里面的字段 /// 需要绑定的DropDownList /// 用来控制缩入量的值,请输入-1 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--; } /// /// 时间计算返回月 /// /// 开始时间 /// 结束时间 /// 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; } /// /// 判断是否有中文 /// /// 待判断的字符串 /// public static bool WordsIScn(string words) { Regex rx = new Regex(@"[\\u4e00-\\u9fa5]"); return rx.IsMatch(words.Trim(), 0); } /// /// 初始化科室下拉框 /// /// /// /// /// public static void InitSection(UltraComboEditor uce, String[] validDataPurviewIds, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getBaseSection", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { uce.DataSource = dt; uce.DisplayMember = "DEPARTNAME"; uce.ValueMember = "DEPARTID"; } else { uce.DataSource = null; } } /// /// 销售片区数据权限 /// /// /// /// public static string[] Section(String[] validDataPurviewIds, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getSection", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { string[] section = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { section[i] = dt.Rows[i]["SALE_AREA_NO"].ToString(); } return section; } else { return new string[1] { "" }; } } /// /// 科室数据权限(1)基础信息 /// /// /// /// public static string[] BaseSection(String[] validDataPurviewIds, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getBaseSection", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { string[] section = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { section[i] = dt.Rows[i]["DEPARTID"].ToString(); } return section; } else { return new string[1] { "" }; } } /// /// 根据部门获取PCode /// /// user_depatment /// public static string GetPCode(string Department, OpeBase ob) { string Pcode = ""; DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.common.PlanService.getQueryDepPlineCode", new Object[] { Department }, ob); if (dt.Rows.Count > 0) { Pcode = dt.Rows[0]["pline_code"].ToString(); } return Pcode; } /// /// 根据工艺文件号获取工艺文件 /// /// user_depatment /// public static string getQueryCraftNo(string CraftNo, OpeBase ob) { string craftNo = ""; DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.common.PlanService.getQueryCraftNo", new Object[] { CraftNo }, ob); if (dt.Rows.Count > 0) { craftNo = dt.Rows[0]["CRAFT_PATH"].ToString(); } return craftNo; } /// /// 获取仓库 /// /// user_depatment /// public static string GetStorage(string Department, string deparNo, OpeBase ob) { string Pcode = ""; DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.common.PlanService.getStorage", new Object[] { Department, deparNo }, ob); if (dt.Rows.Count > 0) { Pcode = dt.Rows[0]["STORAGE_NO"].ToString(); } return Pcode; } ///镦拔扩获取仓库 public static string GetStorage1(string Department, string deparNo, string storageAttr, string storageTypeNo, OpeBase ob) { string Pcode = ""; DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.common.PlanService.getStorage1", new Object[] { Department, deparNo, storageAttr, storageTypeNo }, ob); if (dt.Rows.Count > 0) { Pcode = dt.Rows[0]["STORAGE_NO"].ToString(); } return Pcode; } } }