using System; using System.Collections.Generic; using System.Linq; using System.Text; using Infragistics.Win.UltraWinGrid; using System.Drawing; using System.Data; using Core.Mes.Client.Comm.Server; using CoreFS.CA06; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinMaskedEdit; using System.Windows.Forms; using System.Collections; using Core.Mes.Client.Comm.Control; using System.IO; namespace Core.StlMes.Client.YdmPipeManage.Tool { public class BaseMethod { /// /// UltraGrid可读 /// /// UltraGrid /// 可编辑列 public static void setOtherColumnReadOnly(UltraGrid ugr, string[] keys) { keys.ToArray(); foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns) { if (!keys.Contains(ugc.Key)) { ugc.CellActivation = Activation.ActivateOnly; } } } /// /// UltraGrid激活某行 /// /// UltraGrid /// 列名 /// 对应的值 public static void UltraGridLocation(UltraGrid ug, String[] keys, String[] values) { if (ug.Rows.Count == 0) { return; } if (keys.Length == 0 || values.Length == 0 || values.Length != keys.Length) { return; } foreach (UltraGridRow ugr in ug.Rows) { Boolean flag = true; for (int i = 0; i < keys.Length; i++) { if (!ugr.Cells[keys[i]].ToString().Equals(values[i])) { flag = false; } } if (flag == true) { ugr.Activate(); return; } } } /// /// 设置列字段显示位置在右 /// /// UltraGrid /// 要设置的列 public static void InitCellPosition(UltraGrid ug, string[] columnsKeys) { columnsKeys.ToArray(); foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns) { if (columnsKeys.Contains(ugc.Key.ToString())) { ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right; } } } /// /// 列求和 /// /// UltraGrid /// 列数组 public static void GridColumnSum(UltraGrid ug, string[] columnKeys) { if (columnKeys.Length == 0) { return; } for (int i = 0; i < columnKeys.Length; i++) { ug.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Sum, ug.DisplayLayout.Bands[0].Columns[columnKeys[i]], SummaryPosition.UseSummaryPositionColumn); } } /// /// 设置UltraGrid行颜色 /// /// UltraGrid /// 列 /// 值 /// 颜色 public static void SetUltraGridRowColor(UltraGrid ug, string[] columnKeys, string[] values, Color color) { if (ug.Rows.Count == 0 || columnKeys.Length == 0 || values.Length == 0 || color == null || values.Length != columnKeys.Length) { return; } foreach (UltraGridRow ugr in ug.Rows) { Boolean flag = true; for (int i = 0; i < columnKeys.Length; i++) { if (!ugr.Cells[columnKeys[i]].Value.ToString().Equals(values[i])) { flag = false; } } if (flag) { ugr.Appearance.BackColor = color; } } } /// /// 合并单元格 /// /// /// public static void MergedCell(UltraGrid ug, string[] columnKeys) { if (columnKeys.Length == 0) { return; } ug.DisplayLayout.Override.MergedCellStyle = MergedCellStyle.Never; for (int i = 0; i < columnKeys.Length; i++) { ug.DisplayLayout.Bands[0].Columns[columnKeys[i]].MergedCellStyle = MergedCellStyle.Always; } } /// /// 仓库数据权限 /// /// 页面配制信息(自定义参数) /// 用户数据权限 /// 可查看仓库组成的字符串 public static string[] WarehousePermissions(String customInfo, String[] validDataPurviewIds, OpeBase ob) { string storageType = "";//仓库类别 string storageAttr = "";//仓库类型 //if (customInfo.Length >= 0 && customInfo.Contains(",")) //{ // string[] strflg = customInfo.ToString().Split(new char[] { ',' }); // storageType = strflg[0]; // storageAttr = strflg[1]; //} if (customInfo.Length >= 0 ) { //string[] strflg = customInfo.ToString().Split(new char[] { ',' }); //storageType = strflg[0]; //storageAttr = strflg[1]; storageAttr = customInfo.ToString(); } //DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissions", new object[] { storageType, storageAttr, validDataPurviewIds }, ob); DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissionsStore", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { string[] storages = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { storages[i] = dt.Rows[i]["STORAGE_NO"].ToString(); } return storages; } else { return new string[1] { "" }; } } /// /// 销售组织权限 /// /// 数据权限 /// /// 字符串数组 public static string[] InitPermissions(string[] validDataPurviewIds, OpeBase ob) { string[] arr = null; DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getSalgPermissions", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { arr = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { arr[i] = dt.Rows[i][0].ToString(); } return arr; } else { return new string[1] { "" }; } } /// /// 通过数据权限找产线 /// /// /// /// public static string[] getPlineValid(string[] validDataPurviewIds, OpeBase ob) { string[] arr = null; DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getPlineValiData", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { arr = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { arr[i] = dt.Rows[i][0].ToString(); } return arr; } else { return new string[1] { "" }; } } /// /// 仓库数据权限(用于报表) /// /// 页面配制信息(自定义参数) /// 用户数据权限 /// 可查看仓库组成的字符串 public static string[] WarehousePermissionsStore(String[] validDataPurviewIds, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissionsStore", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { string[] storages = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { storages[i] = dt.Rows[i]["STORAGE_NO"].ToString(); } return storages; } else { return new string[1] { "" }; } } /// /// 把角色集合转换成数组 /// /// /// public static string[] getRole(List list) { string str = ""; string[] roles = new string[list.Count]; for (int i = 0; i < list.Count;i++) { str += list[i] + ','; } if (str.Length > 2) { str = str.Substring(0, str.LastIndexOf(',')); roles = str.Split(','); } return roles; } ///// ///// 通过角色获取数据权限(仓库) ///// ///// ///// ///// //public static string[] getRoleValidPurviewStore(string[] roleId, String[] validDataPurviewIds, OpeBase ob) //{ // DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.isGetVaild", new object[] { roleId }, ob); // if (dt != null && dt.Rows.Count > 0) // { // DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissionsStore", new object[] { validDataPurviewIds }, ob); // if (ds != null && ds.Rows.Count > 0) // { // string[] storages = new string[ds.Rows.Count]; // for (int i = 0; i < ds.Rows.Count; i++) // { // storages[i] = ds.Rows[i]["STORAGE_NO"].ToString(); // } // return storages; // } // else // { // return new string[1] { "" }; // } // } // else // { // return new string[1] { "" }; // } //} /// /// 通过角色获数据权限(所属权) /// /// /// /// public static string[] getRoleValidPurviewBelong(string mangementNo,string departMentId, OpeBase ob) { //DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.isGetVaildBelong", new object[] { roleId }, ob); //if (dt != null && dt.Rows.Count > 0) //{ DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getBelongVaild", new object[] { mangementNo, departMentId }, ob); if (ds != null && ds.Rows.Count > 0) { string[] storages = new string[ds.Rows.Count]; for (int i = 0; i < ds.Rows.Count; i++) { storages[i] = ds.Rows[i]["BELONG_ID"].ToString(); } return storages; } else { return new string[1] { "" }; } //} //else //{ // return new string[1] { "" }; //} } //调用本地程序打开查看服务器文件 /// /// 调用本地程序打开查看服务器文件 /// /// public static void ViewCarft_No(string pathName) { try { //删除本地文件 string tmpPath = Environment.CurrentDirectory + "\\Tmp\\"; DirectoryInfo di = new DirectoryInfo(tmpPath); if (di.Exists == false) { di.Create(); return; } foreach (FileInfo fi in di.GetFiles()) { try { fi.Delete(); } catch { continue; } } //下载写入本地Tmp目录 if (pathName == "" || pathName == null) return; List list = Core.Mes.Client.Comm.Server.FileHelper.Download(pathName); foreach (FileBean bean in list) { FileStream fs = new FileStream(tmpPath + bean.getFileName(), FileMode.Create); fs.Write(bean.getFile(), 0, bean.getFile().Length); fs.Flush(); fs.Close(); System.Diagnostics.Process MyProcess = new System.Diagnostics.Process(); MyProcess.StartInfo.FileName = tmpPath + bean.getFileName(); MyProcess.StartInfo.Verb = "Open"; MyProcess.StartInfo.CreateNoWindow = true; MyProcess.Start(); return; } } catch { } } /// /// 初始化仓库号下拉框 /// /// /// /// /// public static void InitStorage(UltraComboEditor uce, String customInfo, String[] validDataPurviewIds, OpeBase ob) { string storageType = "";//仓库类别 string storageAttr = "";//仓库类型 if (customInfo.Length >= 0 && customInfo.Contains(",")) { string[] strflg = customInfo.ToString().Split(new char[] { ',' }); storageType = strflg[0]; storageAttr = strflg[1]; } //if (customInfo.Length >= 0) //{ // string[] strflg = customInfo.ToString().Split(new char[] { ',' }); // storageType = strflg[0]; // storageAttr = strflg[1]; // //storageAttr = customInfo.ToString(); //} DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissions", new object[] { storageType, storageAttr, validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { uce.DataSource = dt; uce.DisplayMember = "STORAGE_NAME"; uce.ValueMember = "STORAGE_NO"; uce.SelectedIndex = 0; } else { uce.DataSource = null; } } /// /// 初始化仓库号下拉框 /// /// /// /// /// public static void InitStorage(UltraComboEditor uce,String[] validDataPurviewIds, OpeBase ob) { string storageType = "";//仓库类别 string storageAttr = "";//仓库类型 DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissionsStore", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { uce.DataSource = dt; uce.DisplayMember = "STORAGE_NAME"; uce.ValueMember = "STORAGE_NO"; uce.SelectedIndex = 0; } else { uce.DataSource = null; } } /// /// 初始化仓库号下拉框 /// /// /// /// /// public static void InitStorageCom(UltraComboEditor uce, DataTable dataTable, String[] validDataPurviewIds, OpeBase ob) { string storageType = "";//仓库类别 string storageAttr = "";//仓库类型 DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissionsStore", new object[] { validDataPurviewIds }, ob); GridHelper.CopyDataToDatatable(ref dt, ref dataTable, true); } /// /// 初始化数据权限(科室)下拉框 /// /// /// /// /// public static void InitStorageBelog(UltraComboEditor uce, DataTable dataTable, String[] validDataPurviewIds, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissionsBelog", new object[] { validDataPurviewIds }, ob); GridHelper.CopyDataToDatatable(ref dt, ref dataTable, true); } /// /// 初始化下拉框材料类别 /// /// /// public static void InitProducFlagCom(UltraComboEditor uce, OpeBase ob) { DataTable dtProducFlag = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeMagement.queryMaterialSTyle", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dtProducFlag, "BASENAME", "BASECODE"); } /// /// 初始化下拉框材料状态 /// /// /// public static void InitMapStatusCom(UltraComboEditor uce, OpeBase ob) { DataTable dtMapStatus = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeMagement.queryMaterialStatus", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dtMapStatus, "BASENAME", "BASECODE"); } /// /// 初始化下拉框材料状态 /// /// /// public static void InitMapStatusCom(UltraComboEditor uce, OpeBase ob,string flag) { DataTable dtMapStatus = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeMagement.queryMaterialStatus", new object[] { flag }, ob); BaseMethod.InitComboEditor(uce, dtMapStatus, "BASENAME", "BASECODE"); } /// /// 初始下拉框 /// /// /// /// /// public static void InitComboEditor(UltraComboEditor uce, DataTable dt, String showName, String hideValue) { uce.DataSource = dt; uce.DisplayMember = showName; uce.ValueMember = hideValue; } /// /// 初始下拉框 /// /// /// /// /// public static void InitComboEditor1(UltraComboEditor uce, DataTable dt, String showName, String hideValue) { uce.DataSource = dt; uce.DisplayMember = showName; uce.ValueMember = hideValue; uce.SelectedIndex = 1; } /// /// 初始化下拉框产线 /// /// /// public static void InitPline(UltraComboEditor uce, OpeBase ob) { DataTable dtPline = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getPline", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dtPline, "PLINE_NAME", "PLINE_CODE"); } /// /// 初始化下拉框产线 /// /// /// public static void InitPline1(UltraComboEditor uce, OpeBase ob,string custom) { DataTable dtPline = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getPline1", new object[] { custom }, ob); BaseMethod.InitComboEditor(uce, dtPline, "PLINE_NAME", "PLINE_CODE"); } /// /// 初始化下拉框材料来源 /// /// /// public static void InitSourse(UltraComboEditor uce, OpeBase ob) { InitSourse(uce, ob, "8013"); } /// /// 初始化下拉框材料来源 /// /// /// public static void InitSourse(UltraComboEditor uce, OpeBase ob,string value) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getSourse", new object[] { value }, ob); BaseMethod.InitComboEditor1(uce, dt, "BASENAME", "BASECODE"); } /// /// 初始化下拉框钢种 /// /// /// public static void InitGrade(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeEnter.getGrade", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "GRADENAME", "GRADECODE"); } /// /// 获取规格 /// /// /// public static void InitSpec(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeEnter.getSpec", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "SPEC_NAME", "SPEC_CODE"); } /// /// 获取扣型 /// /// /// public static void InitModel(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeEnter.getModel", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "MODEL_DESC", "MODEL_CODE"); } /// /// 获取品名 /// /// /// public static void InitProcduce(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getProcduce", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "PRODUC_JX", "PRODUCCODE"); } /// /// 获取钢级 /// /// /// public static void InitSteel(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getSteel", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "STEELNAME", "STEELCODE"); } /// /// 获取标准类别 /// /// /// public static void InitStdStyle(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getStdStyle", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "STD_STYLE_DESC", "STD_STYLE"); } /// /// 获取标准名称 /// public static void InitStdName(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getStdName", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "STD_NAME", "STD_CODE"); } /// /// 获取轧管物料码 /// public static void InitMaterial(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getMaterial", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "OUT_MATERIAL_DESC", "OUT_MATERIAL_NO"); } /// /// 初始化下拉框原因 /// /// /// public static void InitReason(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getSourse", new object[] { "8012" }, ob); BaseMethod.InitComboEditor(uce, dt, "BASENAME", "BASECODE"); } /// /// 初始化下拉框综合判断结果 /// /// /// public static void InitJustResult(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getSourse", new object[] { "407407" }, ob); BaseMethod.InitComboEditor(uce, dt, "BASENAME", "BASECODE"); } /// /// 初始化下拉框所属权单位 /// /// /// public static void InitBelongCode(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getBelongCode", new object[] { }, ob); BaseMethod.InitComboEditor(uce, dt, "DEPARTNAME", "DEPARTID"); } /// /// 设置列显示位数 /// /// /// public static void setUltraGridColumnMaxInput(UltraGrid ug, string[] arr) { if (ug == null || arr == null || arr.Length == 0) { return; } arr.ToArray(); foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns) { if (arr.Contains(ugc.Key.ToString())) { ugc.MaskClipMode = MaskMode.IncludeLiterals; ugc.MaskInput = "{LOC}nn,nnn,nnn.nnn"; } } } /// /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中 /// /// UltraGrid /// /// 可以进行列名称 public static void setGridCopyActColumn(UltraGrid ugrid, KeyEventArgs e, params string[] strs) { if (e.Control && e.KeyCode == Keys.D) { if (ugrid != null && ugrid.ActiveRow != null) { UltraGridRow ugr = ugrid.ActiveRow; foreach (string colName in strs) { if (ugrid.ActiveCell.Column.Key == null) { return; } if (ugrid.ActiveCell.Column.Key.Equals(colName)) { if (ugr.Cells[colName].Activation != Activation.AllowEdit) { return; } ugrid.UpdateData(); ArrayList list = new ArrayList(); IQueryable checkRows = ugrid.Rows.AsQueryable().Where("CHK = 'True' "); if (checkRows.Count() == 0) { return; } foreach (UltraGridRow uRow in checkRows) { if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit) { uRow.Cells[colName].Value = ugr.Cells[colName].Value; } } } } } } }/// /// 初始年份 /// /// public static void InitYear(UltraComboEditor uce) { DataTable dtYear = new DataTable(); dtYear.Columns.Add("YEAR"); for (int i = 2000; i < 2200; i++) { DataRow dr = dtYear.NewRow(); dr["YEAR"] = i.ToString(); dtYear.Rows.Add(dr); } uce.DataSource = dtYear; uce.DisplayMember = "YEAR"; uce.ValueMember = "YEAR"; } /// /// 初始月份 /// /// public static void InitMonth(UltraComboEditor uce) { DataTable dtMonth = new DataTable(); dtMonth.Columns.Add("MONTH"); for (int i = 1; i < 13; i++) { DataRow dr = dtMonth.NewRow(); dr["MONTH"] = string.Format("{0:00}", i); dtMonth.Rows.Add(dr); } uce.DataSource = dtMonth; uce.DisplayMember = "MONTH"; uce.ValueMember = "MONTH"; } /// /// 通过科室查找对应的部门 /// /// 科室ID /// /// 部门ID public static string GetDepartIdBySectionId(string sectionId, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.PipeManageClassInfo.getDeptBySection", new object[] { sectionId }, ob); if (dt.Rows.Count > 0) { return dt.Rows[0]["DEPARTID"].ToString(); } else { return ""; } } /// /// 通过科室查找对应的部门 /// /// 科室ID /// /// 部门名称 public static string GetDepartBySectionId(string sectionId, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.PipeManageClassInfo.getDeptBySection", new object[] { sectionId }, ob); if (dt.Rows.Count > 0) { return dt.Rows[0]["DEPARTNAME"].ToString(); } else { return ""; } } /// /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中 /// /// UltraGrid /// /// 可以进行列名称 public static void setGridCopyActColumn1(UltraGrid ugrid, KeyEventArgs e, params string[] strs) { if (e.Control && e.KeyCode == Keys.D) { if (ugrid != null && ugrid.ActiveRow != null) { UltraGridRow ugr = ugrid.ActiveRow; foreach (string colName in strs) { if (ugrid.ActiveCell.Column.Key.Equals(colName)) { if (ugr.Cells[colName].Activation != Activation.AllowEdit) { return; } ugrid.UpdateData(); ArrayList list = new ArrayList(); IQueryable checkRows = ugrid.Rows.AsQueryable().Where("CHOOSE = 'True' "); if (checkRows.Count() == 0) { return; } foreach (UltraGridRow uRow in checkRows) { if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit) { uRow.Cells[colName].Value = ugr.Cells[colName].Value; } } } } } } } } }