1. 程式人生 > 其它 >windows10 安裝mysql

windows10 安裝mysql

using System;
using System.Collections.Generic;
using System.Text;
using H3;

public  class D150516CGtools : H3.SmartForm.SmartFormController
{
    public  D150516CGtools(H3.SmartForm.SmartFormRequest request) : base(request)
    {
    }

    protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response)
    {
        
base.OnLoad(response); } protected override void OnSubmit(string actionName, H3.SmartForm.SmartFormPostValue postValue, H3.SmartForm.SubmitSmartFormResponse response) { base.OnSubmit(actionName, postValue, response); } } public class Utils { public Utils() { } /* 拷貝基礎公共類中的日誌方法 新增表單訪問日誌 schemaName 表單名稱 schemaCode 表單code userId 當前登入人id by:lins date:2020-07-29
*/ public static void addLog(string context, string schemaCode, string userId , H3.IEngine engine) { string[] sArray=context.Split(',');// 一定是單引 string schemaName = sArray[0]; string IsMobileDevice = "false"; if(sArray.Length > 1 ) IsMobileDevice = sArray[1];
string accessCategory = ""; switch(sArray[2]){ case "Create": accessCategory = "建立"; break; case "Edit": accessCategory = "修改"; break; case "View": accessCategory = "預覽"; break; case "Remove": accessCategory = "刪除"; break; default : accessCategory = sArray[2]; break; } string sourceId = ""; if(sArray.Length > 3){ sourceId = sArray[3]; } //獲取當前登入人的人員Id(只能在表單設計後端類、列表設計後端類中獲取) //獲取D00021testtable表單的表單結構物件 H3.DataModel.BizObjectSchema aSchema = engine.BizObjectManager.GetPublishedSchema("D002033backStageMangementLog"); //new一個D00021testtable表單的業務物件 H3.DataModel.BizObject aBo = new H3.DataModel.BizObject(engine, aSchema, userId); //根據表單code查詢業務表單資料,獲取應用id H3.Data.Filter.Filter filter = new H3.Data.Filter.Filter(); H3.Data.Filter.And and = new H3.Data.Filter.And(); and.Add(new H3.Data.Filter.ItemMatcher("Schema", H3.Data.ComparisonOperatorType.Equal, schemaCode)); //主表ID filter.Matcher = and; H3.DataModel.BizObjectSchema schema = engine.BizObjectManager.GetPublishedSchema("D002033formMenu"); //業務表單 D002033formMenu H3.DataModel.BizObject[] result = H3.DataModel.BizObject.GetList(engine, H3.Organization.User.SystemUserId, schema, H3.DataModel.GetListScopeType.GlobalAll, filter); if(result != null && result.Length > 0) { aBo["application"] = Convert.ToString(result[0]["joinApplication"]); aBo["joinFormMenu"] = Convert.ToString(result[0]["ObjectId"]); } string accessType = "PC"; if(IsMobileDevice == "true") { accessType = "mobile"; } //設定業務物件的建立人為當前登入人 aBo.CreatedBy = userId; aBo["SchemaName"] = schemaName; aBo["Schema"] = schemaCode; aBo["accessType"] = accessType; aBo["sourceId"] = sourceId; aBo["accessCategory"] = accessCategory; //設定業務物件資料為生效狀態 aBo.Status = H3.DataModel.BizObjectStatus.Effective; //查詢日誌表中的相同的記錄,獲取最近一條判斷時間間隔是否在15秒內,在15秒內不新增日誌 H3.Data.Filter.Filter filter1 = new H3.Data.Filter.Filter(); H3.Data.Filter.And and1 = new H3.Data.Filter.And(); and1.Add(new H3.Data.Filter.ItemMatcher("Schema", H3.Data.ComparisonOperatorType.Equal, schemaCode)); //表單編碼 and1.Add(new H3.Data.Filter.ItemMatcher("SchemaName", H3.Data.ComparisonOperatorType.Equal, schemaName)); //表單名稱 and1.Add(new H3.Data.Filter.ItemMatcher("CreatedBy", H3.Data.ComparisonOperatorType.Equal, userId)); //建立人 and1.Add(new H3.Data.Filter.ItemMatcher("accessType", H3.Data.ComparisonOperatorType.Equal, accessType)); //訪問方式 and1.Add(new H3.Data.Filter.ItemMatcher("accessCategory", H3.Data.ComparisonOperatorType.Equal, accessCategory)); //訪問型別 filter1.Matcher = and1; filter1.AddSortBy("CreatedTime", H3.Data.Filter.SortDirection.Descending); H3.DataModel.BizObjectSchema schema1 = engine.BizObjectManager.GetPublishedSchema("D002033backStageMangementLog"); //業務表單 D002033backStageMangementLog H3.DataModel.BizObject[] result1 = H3.DataModel.BizObject.GetList(engine, H3.Organization.User.SystemUserId, schema1, H3.DataModel.GetListScopeType.GlobalAll, filter1); if(result1 != null && result1.Length > 0) { DateTime date = (DateTime) result1[0]["CreatedTime"]; double seconds = (DateTime.Now - date).TotalSeconds; if(seconds > 15) { //將業務物件建立到資料庫中 aBo.Create(); } } else { //將業務物件建立到資料庫中 aBo.Create(); } } /*=========================================================================================================================================*/ /* 重新整理合併唯一編碼 入參: 表單編碼,where條件,合併欄位,是否重新整理標示,氚雲引擎 where條件: 書寫格式示例 -> " where field1 = 'xxx' AND field2 = 'xxx' " 記得新增where,一般情況下約束專案工程或合同。 表單編碼: 書寫格式示例 -> "D002033zjglProClass" 合併欄位: 書寫格式示例 -> " concat(field1, field2, ...) " concat必須小寫 by:lins date:2020-06-19 */ public static void refreshMergeOnlyCoding( string schemaCode, string where, string field, bool isRefresh, H3.IEngine engine) { //資料傳入示例: concat(field1, field2, ...) //將連結欄位轉換成原始欄位,用於查詢 示例: concat(field1, field2) -> field1, field2 string oldField = field.Replace("concat(", ""); oldField = oldField.Replace(")", ""); //將連結欄位轉換成資料庫操作欄位,用於更新 示例: concat(field1, field2) -> concat(b.field1, b.field2) field = field.Replace("(", "( b."); field = field.Replace(",", ",b."); //使用sql語句根據拼接規則進行更新合併唯一編碼 將重新整理標識改成1。 其中a為更新表單, b為資料來源。 string sql = " UPDATE I_" + schemaCode + " AS a , (SELECT objectid, " + oldField + " FROM I_" + schemaCode + " "; sql += getWhere(isRefresh, where); sql += " ) AS b SET a.mergeOnlyCoding = " + field + " WHERE a.objectid = b.objectid "; engine.Query.QueryTable(sql, null); } /*=========================================================================================================================================*/ /* 重新整理排序編碼 入參: 表單編碼,where條件,拼接欄位,需要處理的欄位,是否重新整理標示,氚雲引擎 表單編碼: 書寫格式示例 -> "D002033zjglProClass" where條件: 書寫格式示例 -> " where field1 = 'xxx' AND field2 = 'xxx' " 記得新增where,一般情況下約束專案工程或合同。 拼接欄位: 書寫格式示例 -> " contractCoding " 需要處理欄位: 書寫格式示例 -> " projWBSNo " by:lins date:2020-06-20 */ public static void refreshSortCoding( string schemaCode, string where, string field, string handleField, bool isRefresh, H3.IEngine engine) { //按條件獲取資料。 string sql = "SELECT objectid," + handleField + " FROM I_" + schemaCode; sql += getWhere(isRefresh, where); System.Data.DataTable table = engine.Query.QueryTable(sql, null); if(table != null && table.Rows.Count > 0) { //遍歷資料進行新增修改排序編號 例 1.1.1 -> 010101 for(int i = 0;i < table.Rows.Count; i++) { string num = Convert.ToString(table.Rows[i][handleField]); string parentNum = getSortCode(num); //將新的排序編碼儲存進資料庫 string concat = " CONCAT('" + parentNum + "') "; if(field != null && field != "") { concat = " CONCAT(" + field + ", '" + parentNum + "') "; } sql = " UPDATE I_" + schemaCode + " SET sequenceCoding = " + concat + " WHERE objectid = '" + table.Rows[i]["objectid"] + "' "; engine.Query.QueryTable(sql, null); } } } /*=========================================================================================================================================*/ /* 重新整理編碼等級 入參: 表單編碼,where條件,分級依據,是否重新整理標示,氚雲引擎 where條件: 書寫格式示例 -> " where field1 = 'xxx' AND field2 = 'xxx' " 記得新增where,一般情況下約束專案工程或合同。 表單編碼: 書寫格式示例 -> "D002033zjglProClass" 分級依據: 書寫格式示例 -> " projWBSNo " 用專案編碼 1 1.1 1.1.1 by:lins date:2020-06-20 */ public static void refreshLevel( string schemaCode, string where, string field, bool isRefresh, H3.IEngine engine) { //使用sql語句根據拼接規則進行更新等級 將重新整理標識改成1。 其中a為更新表單, b為資料來源。 //關鍵程式碼解析:CONCAT( (LENGTH("+field+") + 1) - LENGTH(REPLACE("+field+", '.', '') ), '級') //CONCAT為字串拼接, length獲取字串長度並將原始長度+1。例:1 沒有.則是1-1=0 不成立。應1+1-1=1再拼接級。 string sql = " UPDATE I_" + schemaCode + " AS a, (SELECT objectId, "+field; sql += " , CONCAT( (LENGTH("+field+") + 1) - LENGTH(REPLACE("+field+", '.', '') ), '級') AS lv FROM I_" + schemaCode + " "; sql += getWhere(isRefresh, where); sql += " ) AS b SET a.level = b.lv WHERE a.objectid = b.objectid "; engine.Query.QueryTable(sql, null); } /*=========================================================================================================================================*/ /* 重新整理子項標識 入參: 表單編碼,where條件,分級依據,是否重新整理標示,氚雲引擎 where條件: 書寫格式示例 -> " where field1 = 'xxx' AND field2 = 'xxx' " 記得新增where,一般情況下約束專案工程或合同。 表單編碼: 書寫格式示例 -> "D002033zjglProClass" 重新整理依據: 書寫格式示例 -> " projWBSNo " 用專案編碼 1 1.1 1.1.1 by:lins date:2020-07-27 */ public static void refreshChildFlag(string schemaCode, string where, string field, bool isRefresh, H3.IEngine engine){ string newWhere = getWhere(isRefresh, where); string sql = " UPDATE I_" + schemaCode + " AS a SET childFlag = CASE WHEN ( SELECT count(1) "; sql += " FROM ( SELECT "+field+" FROM I_" + schemaCode; if(string.IsNullOrEmpty(newWhere)) { sql += " WHERE static = '有效' ) AS b "; } else { sql += newWhere + " AND static = '有效' ) AS b "; } //AND static = '有效' ) AS b WHERE b.sequenceCoding LIKE CONCAT(a.sequenceCoding sql += " WHERE b."+field+" LIKE CONCAT(a."+field+", '%')) < 2 THEN '1' ELSE '0' END "; if(string.IsNullOrEmpty(newWhere)) { sql += " WHERE static = '有效' "; } else { sql += newWhere + " AND static = '有效' "; } engine.Query.QueryTable(sql, null); } /*=========================================================================================================================================*/ /* 更新增量標示 入參: 表單編碼,where條件,是否重新整理標示,氚雲引擎 where條件: 書寫格式示例 -> " where field1 = 'xxx' AND field2 = 'xxx' " 記得新增where,一般情況下約束專案工程或合同。 by:lins date:2020-06-23 */ public static void updateRefreshFlag( string schemaCode, string where, bool isRefresh, H3.IEngine engine ) { string sql = " UPDATE I_" + schemaCode + " SET refreshFlag = 1 "; sql += getWhere(isRefresh, where); engine.Query.QueryTable(sql, null); } /*=========================================================================================================================================*/ /* 通過列舉的方式獲取資料來源的where條件。 示例: 00 01 10 11 根據兩個標識的狀態返回where條件, by:lins date:2020-07-27 */ public static string getFilter(string joinProjectEngineering){ string sql = ""; if(!(string.IsNullOrEmpty(joinProjectEngineering))){ sql += " WHERE joinProjectEngineering = '" + joinProjectEngineering + "' "; } return sql; } /*=========================================================================================================================================*/ /* 將wbs編碼轉換成排序編碼 入參: 需要處理的編碼(具體編碼值) 出參: 排序後編碼 by:lins date: 2020-06-21 */ public static string getSortCode(string sourceCode) { string parentNum = ""; int n = 0; string[] numArray = sourceCode.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if(numArray.Length > 0) { //第一級wbs編碼為數字則在前面補0 if(int.TryParse(numArray[0],out n)){ parentNum = Convert.ToString(numArray[0]).PadLeft(3, '0'); } //不為數字則在前面補9 else { parentNum = Convert.ToString(numArray[0]).PadLeft(3, '9'); } //判斷編碼位數,用0填充 for(int i = 1;i < numArray.Length; i++) { if(numArray[i].IndexOf("-") > -1) { string[] numArray2 = numArray[i].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); for(int j = 0; j < numArray2.Length; j++) { parentNum += Convert.ToString(numArray2[j]).PadLeft(3, '0'); } } else{ parentNum += Convert.ToString(numArray[i]).PadLeft(3, '0'); } } } return parentNum; } /*=========================================================================================================================================*/ /* 通過列舉的方式獲取資料來源的where條件。 示例: 00 01 10 11 根據兩個標識的狀態返回where條件, by:lins date:2020-06-20 */ public static string getWhere(bool isRefresh, string where) { string sql = ""; //判斷where有沒有資料,如果沒有則返回true 否則返回false bool whereFlag = string.IsNullOrEmpty(where); //如果重新整理標識為真,則只更新重新整理標識為0的資料,否則全部更新。 更新完畢後把重新整理標識改成1. //isRefresh && whereFlag where沒有資料且只需要更新重新整理標示的資料。 11 if(isRefresh && whereFlag) { sql += " WHERE refreshFlag <> 1 "; } //isRefresh && !whereFlag where有資料且需要更新重新整理標示的資料。 10 else if(isRefresh && !whereFlag) { sql += where + " AND refreshFlag <> 1 "; } //!isRefresh && !whereFlag where有資料且需要全部更新。 //剩下一種可能性 -> 需要更新全部資料且沒有特定的where條件 00 else if(!isRefresh && !whereFlag) { sql += where; } //!isRefresh && whereFlag 需要更新全部資料且沒有特定的where, 無須額外書寫程式碼。 01 return sql; } /*=========================================================================================================================================*/ /* 根據使用者id獲取使用者資訊 入參: 使用者id, 氚雲引擎 出參: 當前使用者id的全部使用者資訊 by: lins, date: 2020-08-01 */ public static System.Data.DataTable getPersonnel(string userId, H3.IEngine engine){ string sql = " SELECT * "; sql += " FROM I_D002033personnelManagement WHERE personnel = '" + userId + "' AND static = '有效'"; return engine.Query.QueryTable(sql, null); } /*=========================================================================================================================================*/ /* 將字串型別轉換為2位小數的雙精度浮點型別 入參: 需要處理的字串(以物件的形式傳入) 出參: 處理後的雙精度浮點 by: lins, date: 2020-08-17 */ public static double toDoubleByString(object str){ //將字串轉換為雙精度浮點後加0.0001 double dou = Convert.ToDouble(str) + 0.0001; //將雙精度浮點保留兩位小數後返回 return Math.Round(dou, 3); } /*=========================================================================================================================================*/ /* 根據登陸使用者的工程全線控制載入列表的資料 入參: 列表請求, 列表響應, 是否對合同做控制 監理:對所在工程下的所有資料可見,如果工程為空,則所有資料都不可見 安裝單位:對所在工程下的所有資料可見,如果工程為空,則所有資料都不可見 專案部:對所在工程下的所有資料可見,如果工程為空,則所有工程都可見 廠家:對所在工程和合同下的資料可見 by: lins, date: 2020-08-20 */ public static void defaultInit(H3.SmartForm.ListViewRequest request, H3.SmartForm.LoadListViewResponse response, bool engineeringContractFlag) { //jinx 2020-07-15 //根據曹總提出的需求,將新增合同文件許可權 string userId = request.UserContext.UserId; //獲取當前使用者id H3.Data.Filter.Filter filter = new H3.Data.Filter.Filter(); //構建過濾器 H3.Data.Filter.And andMatcher = new H3.Data.Filter.And(); //構造and匹配器 string sql = "SELECT * FROM I_D002033personnelManagement WHERE personnel='" + userId + "' AND static ='有效' "; //personnel personnelID D002033personnelManagement 使用者資訊 System.Data.DataTable table = request.Engine.Query.QueryTable(sql, null); if(table != null && table.Rows.Count > 0) { //獲取當前人員是否含有標段(合同) //start 關聯多選儲存位置為 I_表單編碼_關聯多選控制元件編碼 string sqlCT = "SELECT * FROM I_D002033personnelManagement_joinEngineeringContract WHERE objectid = '" + table.Rows[0]["objectId"] + "' "; System.Data.DataTable tableCT = request.Engine.Query.QueryTable(sqlCT, null); //end string personnelstatic = table.Rows[0]["personnelstatic"] + string.Empty; //人員狀態 sql = "SELECT * FROM I_D002033engineeringPermissions WHERE joinPersonnelManagement ='" + table.Rows[0]["objectId"] + "' AND static ='有效' "; System.Data.DataTable table1 = request.Engine.Query.QueryTable(sql, null); if(table1 != null && table1.Rows.Count > 0) { for(int i = 0;i < table1.Rows.Count; i++) { if(Convert.ToString(table1.Rows[i]["role"]) != "超級管理員") { string joinProjectEngineering = table1.Rows[i]["joinProjectEngineering"] + string.Empty; sql = "SELECT objectId FROM I_D002033engineeringContrac WHERE joinProjectEngineering = '" + joinProjectEngineering + "' AND static = '有效' LIMIT 0, 1 "; // 識別工程是否有效(工程是否有合同) System.Data.DataTable table2 = request.Engine.Query.QueryTable(sql, null); //工程是有效工程 if(table2 != null && table2.Rows.Count > 0) { //jinx 20200529 //新增合同過濾 string joinUnitType = table.Rows[0]["joinUnitType"] + string.Empty; //單位型別 switch(joinUnitType) { case "a0afdc46-ec0f-4668-998e-e77565562a94": //建設單位 要求甲方人員必須是員工表中的人員 if(table.Rows[0]["joinEmployee"] != null && table.Rows[0]["joinEmployee"] + string.Empty != "") { string sql4 = "SELECT objectid FROM I_D002033employee WHERE objectid = '" + table.Rows[0]["joinEmployee"] + string.Empty + "' AND employee = '" + table.Rows[0]["personnelID"] + string.Empty + "' "; System.Data.DataTable table4 = request.Engine.Query.QueryTable(sql4, null); if(table4 != null && table4.Rows.Count > 0) { //建設單位員工只能看到當前所屬工程下的資料 andMatcher.Add(new H3.Data.Filter.ItemMatcher("joinProjectEngineering", H3.Data.ComparisonOperatorType.Equal, joinProjectEngineering)); //新增工程篩選條件 } //員工表中沒有當前使用者 else { andMatcher.Add(new H3.Data.Filter.ItemMatcher("ObjectId", H3.Data.ComparisonOperatorType.Equal, "")); //新增篩選條件 } } //甲方員工欄位為空 else { andMatcher.Add(new H3.Data.Filter.ItemMatcher("ObjectId", H3.Data.ComparisonOperatorType.Equal, "")); //新增篩選條件 } break; case "983c4806-0983-4484-bf6a-080edcc662b6": //監理 if(!string.IsNullOrEmpty(joinProjectEngineering)){ andMatcher.Add(new H3.Data.Filter.ItemMatcher("joinProjectEngineering", H3.Data.ComparisonOperatorType.Equal, joinProjectEngineering)); //新增工程篩選條件 } break; default: andMatcher.Add(new H3.Data.Filter.ItemMatcher("joinProjectEngineering", H3.Data.ComparisonOperatorType.Equal, joinProjectEngineering)); //新增工程篩選條件 //施工能看的範圍:所屬工程 + 未掛合同(合同控制元件為空) ;所屬工程 + 掛所在單位的合同(合同控制元件不為空, 且所掛合同包含了本單位簽訂的合同) ,下方程式碼據此修改 //2020-08-13 jinx 修改施工許可權 if(personnelstatic != null && personnelstatic != "" && personnelstatic != "離開狀態") { if(tableCT != null && tableCT.Rows.Count > 0) { List < string > tabList = new List<string>(); for(int j = 0;j < tableCT.Rows.Count; j++) { //如果當前登入人所在標段中有合同是機電安裝合同且合同狀態為執行中或初始的有效合同則不對當前登入人做合同限制並隱藏價格 string propertyvalue = tableCT.Rows[j]["propertyvalue"] + string.Empty; string sql3 = "SELECT * FROM I_D002033engineeringContrac WHERE objectid = '" + propertyvalue + "' "; sql3 += " AND joinProjectEngineering ='" + joinProjectEngineering + "' AND serviceContractType = 'd71e631a-a5d0-4010-9a77-ca7f479105f1' "; sql3 += " AND static = '有效' AND (joinContractstatic = '2b20a013-0d20-4d9b-b18c-ea147f68cb59' OR joinContractstatic = '2a20bc9f-d0b3-4854-85fa-019939c94028') "; if(request.Engine.Query.QueryTable(sql3, null).Rows.Count > 0){ engineeringContractFlag = false; //如果存在價格欄位則隱藏 if(response.Columns.ContainsKey("price")) response.Columns.Remove("price"); //價格 } tabList.Add(propertyvalue);//將使用者資訊表中的標段新增進過濾集合中 } //如果對合同做控制 使用or連線掛接當前單位合同與未掛接合同的過濾條件 if(engineeringContractFlag) { H3.Data.Filter.Or orMatcher = new H3.Data.Filter.Or(); orMatcher.Add(new H3.Data.Filter.ItemMatcher("joinEngineeringContract", H3.Data.ComparisonOperatorType.Equal, null)); //將合同為空新增進過濾集合中 orMatcher.Add(new H3.Data.Filter.ItemMatcher("joinEngineeringContract", H3.Data.ComparisonOperatorType.In, tabList.ToArray())); //將合同表中該單位的合同新增進過濾集合中 andMatcher.Add(orMatcher); } } else { List < string > tabList = new List<string>(); string sql2 = "SELECT objectid FROM I_D002033engineeringContrac WHERE vendor = '" + table.Rows[0]["joinCompanyUnit"] + string.Empty + "' "; //propertyvalue 為關聯表單多選 ID,在此為合同ID System.Data.DataTable table5 = request.Engine.Query.QueryTable(sql2, null); if(table5 != null && table5.Rows.Count > 0) { for(int j = 0;j < table5.Rows.Count; j++) { tabList.Add(table5.Rows[j]["objectid"] + string.Empty);//將合同表中該單位的合同新增進過濾集合中 } } //如果對合同做控制 使用or連線掛接當前單位合同與未掛接合同的過濾條件 if(engineeringContractFlag) { H3.Data.Filter.Or orMatcher = new H3.Data.Filter.Or(); orMatcher.Add(new H3.Data.Filter.ItemMatcher("joinEngineeringContract", H3.Data.ComparisonOperatorType.Equal, null)); //將合同為空新增進過濾集合中 orMatcher.Add(new H3.Data.Filter.ItemMatcher("joinEngineeringContract", H3.Data.ComparisonOperatorType.In, tabList.ToArray())); //將合同表中該單位的合同新增進過濾集合中 andMatcher.Add(orMatcher); } } } else { andMatcher.Add(new H3.Data.Filter.ItemMatcher("ObjectId", H3.Data.ComparisonOperatorType.Equal, "")); //新增篩選條件 } break; } } else { //未掛工程 //2020-08-17 jinx 無工程業主不進行工程限制 string joinUnitType = table.Rows[0]["joinUnitType"] + string.Empty; //單位型別 //如果為業主單位、監理單位人員(使用者資訊表的單位型別為業主單位),則可以訪問 if(joinUnitType != "a0afdc46-ec0f-4668-998e-e77565562a94" && joinUnitType != "983c4806-0983-4484-bf6a-080edcc662b6") { andMatcher.Add(new H3.Data.Filter.ItemMatcher("joinProjectEngineering", H3.Data.ComparisonOperatorType.Equal, "")); //新增篩選條件 } } } } } else { //2020-08-17 jinx 無工程業主不進行工程限制 string joinUnitType = table.Rows[0]["joinUnitType"] + string.Empty; //單位型別 //如果為業主單位、監理單位人員(使用者資訊表的單位型別為業主單位),則可以訪問 if(joinUnitType != "a0afdc46-ec0f-4668-998e-e77565562a94" && joinUnitType != "983c4806-0983-4484-bf6a-080edcc662b6") { andMatcher.Add(new H3.Data.Filter.ItemMatcher("joinProjectEngineering", H3.Data.ComparisonOperatorType.Equal, "")); //新增篩選條件 } }; } //人員資訊表中沒有當前使用者 else { andMatcher.Add(new H3.Data.Filter.ItemMatcher("joinProjectEngineering", H3.Data.ComparisonOperatorType.Equal, "")); //新增篩選條件 } filter.Matcher = andMatcher; request.Filter = filter; } /*=========================================================================================================================================*/ /* 如果登入人不是超級管理員則將thisId隱藏 by: lins, date: 2020-09-07 */ public static void hiddenThisId(H3.SmartForm.ListViewRequest request, H3.SmartForm.LoadListViewResponse response){ string userId = request.UserContext.UserId; //獲取當前使用者id string sql = "SELECT * FROM I_D002033personnelManagement WHERE personnel='" + userId + "' AND static ='有效' "; //personnel personnelID D002033personnelManagement 使用者資訊 System.Data.DataTable table = request.Engine.Query.QueryTable(sql, null); if(table.Rows.Count > 0 && table != null) { string objectId = table.Rows[0]["objectId"] + string.Empty; sql = "SELECT * FROM I_D002033engineeringPermissions WHERE joinPersonnelManagement ='" + objectId + "' AND static ='有效' "; System.Data.DataTable table1 = request.Engine.Query.QueryTable(sql, null); if(table1 != null && table1.Rows.Count > 0) { for(int i = 0;i < table1.Rows.Count; i++) { if(Convert.ToString(table1.Rows[i]["role"]) != "超級管理員") { if(response.Columns.ContainsKey("thisID")) response.Columns.Remove("thisID"); //thisID } } } } } /*=========================================================================================================================================*/ /* 修改資料標題 */ public static H3.SmartForm.LoadListViewResponse changeTitle(H3.SmartForm.LoadListViewResponse response, string titleCode , string titleValue) { Dictionary < string, H3.SmartForm.ListViewColumn > columns=new Dictionary<string, H3.SmartForm.ListViewColumn>(); foreach(string key in response.Columns.Keys) { if(key == titleCode) { //將Name列的列名稱改成 合同編碼 H3.SmartForm.ListViewColumn newCol = new H3.SmartForm.ListViewColumn( titleCode,//列編碼(對應控制元件編碼) titleValue,//列名稱 response.Columns[key].Visible, response.Columns[key].Sortable, response.Columns[key].Url, response.Columns[key].Align, response.Columns[key].IsLabel, response.Columns[key].ShowMode ); columns.Add(titleCode, newCol); } else { columns.Add(key, response.Columns[key]); } } response.Columns = columns; return response; } /*=========================================================================================================================================*/ /* 通過關聯表單獲取人員單選 或通過人員單選獲取關聯表單 雙向使用 */ public static string getPersonnelByRelation(string relation, H3.IEngine engine){ string sql = " SELECT objectId FROM I_D002033personnelManagement WHERE personnel = '"+relation+"' AND static = '有效' "; System.Data.DataTable dt = engine.Query.QueryTable(sql, null); string param = ""; if(dt != null && dt.Rows.Count > 0){ param = dt.Rows[0]["objectId"] + string.Empty; } else{ sql = " SELECT personnel FROM I_D002033personnelManagement WHERE objectId = '"+relation+"' AND static = '有效' "; dt = engine.Query.QueryTable(sql, null); if(dt != null && dt.Rows.Count > 0){ param = dt.Rows[0]["personnel"] + string.Empty; } } return param; } /*=========================================================================================================================================*/ /* 通過部套登記表 返回當前有裝置供應合同關係的供貨廠商id集 以逗號分割 入參: 工程, 引擎, 出參: 供貨廠商id集 */ public static string getManufacturerCollation(string joinProjectEngineering, IEngine engine){ string sql = " SELECT manufacturer FROM I_D002033deviceDelivery "; string result = ""; if(!(string.IsNullOrEmpty(joinProjectEngineering))) { sql += " WHERE joinProjectEngineering = '"+joinProjectEngineering+"' "; } sql += " GROUP BY manufacturer "; System.Data.DataTable dt = engine.Query.QueryTable(sql, null); int count = dt.Rows.Count; if(dt != null && count > 0){ for(int i=0; i<count; i++) { result += dt.Rows[i]["manufacturer"] + ","; } } return result; } /*=========================================================================================================================================*/ /* 通過部套登記表 返回當前有裝置供應合同關係的機組號id集 以逗號分割 入參: 工程, 部套號, 引擎, 出參: 供貨廠商id集 */ public static string getJoinGeneratorUnitString(string joinProjectEngineering, string joinVendorDeviceCode, IEngine engine){ string sql = " SELECT joinGeneratorUnit FROM I_D002033deviceDelivery "; sql += " WHERE 1=1 "; if(!string.IsNullOrEmpty(joinProjectEngineering)){ sql += " AND joinProjectEngineering = '"+joinProjectEngineering+"' "; } if(!string.IsNullOrEmpty(joinVendorDeviceCode)){ sql += " AND joinVendorDeviceCode = '"+joinVendorDeviceCode+"' "; } sql += " GROUP BY joinGeneratorUnit "; System.Data.DataTable dt = engine.Query.QueryTable(sql, null); string result = ""; int count = dt.Rows.Count; if(dt != null && count > 0){ for(int i=0; i<count; i++) { result += dt.Rows[i]["joinGeneratorUnit"] + ","; } } return result; } /*=========================================================================================================================================*/ /* 根據合同和工程返回查詢條件, 用and連結 by: lins, date: 2020-12-10 */ public static string getProAndCon(string joinProjectEngineering, string joinEngineeringContract){ bool proFlag = !(string.IsNullOrEmpty(joinProjectEngineering)); bool conFlag = !(string.IsNullOrEmpty(joinEngineeringContract)); if(proFlag && conFlag) return " AND joinProjectEngineering = '"+joinProjectEngineering+"' AND joinEngineeringContract = '"+joinEngineeringContract+"' "; if(!proFlag && conFlag) return " AND joinEngineeringContract = '"+joinEngineeringContract+"' "; if(proFlag && !conFlag) return " AND joinProjectEngineering = '"+joinProjectEngineering+"' "; return ""; } /*=========================================================================================================================================*/ /* 獲取交貨狀態 通過狀態程式碼獲取id 雙向使用 by: lins, date: 2020-12-10 */ public static string getDevicestaticId(string param, H3.IEngine engine){ string sql = " SELECT objectId FROM I_D002033devicestatic WHERE static = 1 AND staticCode = '"+param+"' "; System.Data.DataTable dt = engine.Query.QueryTable(sql, null); if(dt != null && dt.Rows.Count > 0) return dt.Rows[0]["objectId"] + string.Empty; sql = " SELECT staticCode FROM I_D002033devicestatic WHERE static = 1 AND objectId = '"+param+"' "; dt = engine.Query.QueryTable(sql, null); if(dt != null && dt.Rows.Count > 0) return dt.Rows[0]["staticCode"] + string.Empty; return ""; } /*=========================================================================================================================================*/ /* 獲取交貨狀態 通過id獲取狀態程式碼 雙向使用 by: lins, date: 2020-12-10 */ public static string getDevicestaticCode(string param, H3.IEngine engine){ string sql = " SELECT staticCode FROM I_D002033devicestatic WHERE static = 1 AND objectId = '"+param+"' "; System.Data.DataTable dt = engine.Query.QueryTable(sql, null); if(dt != null && dt.Rows.Count > 0) return dt.Rows[0]["staticCode"] + string.Empty; return ""; } /*=========================================================================================================================================*/ /* 獲取最大值編碼 入參: 資料庫返回集, 依據, 出參: 最大值 by: lins date: 2021-03-16 */ public static int getMaxCode(System.Data.DataTable dt, string paramName) { //最大值初始值 int max = 0; if(dt != null && dt.Rows.Count > 0) { for(int i = 0; i < dt.Rows.Count; i++) { string sourceCode = dt.Rows[i][paramName] + string.Empty; if(!(string.IsNullOrEmpty(sourceCode))) { //如果字串中存在'.'則執行 if(sourceCode.IndexOf('.') > 0) { //獲取編碼中'.'後面的資料 int start = sourceCode.LastIndexOf('.') + 1; //開始下標 +1因為獲取的是'.'的位置 需要+1獲取'.'後面的字元 int len = sourceCode.Length - start; //字元長度-開始下標 string str = sourceCode.Substring(start, len); //轉換為int並和max比較, 如果大於max則賦值 int param = Int32.Parse(str);//Convert.ToInt32(str); //如果新值比最大值大則使用新值 if(max < param) { max = param; } } else { int param = Int32.Parse(sourceCode);//Convert.ToInt32(sourceCode); if(max < param) { max = param; } } } } } max += 1; return max; } /*=========================================================================================================================================*/ /* 隱藏控制元件 僅隱藏空值控制元件 by:lins, date: 2021-03-31 */ public static H3.SmartForm.LoadSmartFormResponse addHider(H3.SmartForm.SmartFormRequest request, H3.SmartForm.LoadSmartFormResponse response, List < string > controlCodes) { H3.DataModel.BizObject masterBo = H3.DataModel.BizObject.Load(request.UserContext.UserId, request.Engine, request.SchemaCode, request.BizObjectId, false); foreach(string controlCode in controlCodes) { //判斷不為建立模式 if(!(request.FormMode.ToString() == "Create")) { //子表 if(controlCode.IndexOf("D002033") > -1) { H3.DataModel.BizObject[] childBoList = (H3.DataModel.BizObject[]) masterBo[controlCode]; //子表內不存在資料 if(childBoList != null && childBoList.Length > 0) { } else { //獲取子表結構 Dictionary < string, object > taskObj =(Dictionary<string, object>) response.ReturnData[controlCode].Value; //獲取子表列結構 Dictionary < string, H3.SmartForm.SmartFormResponseDataItem > taskobject = (Dictionary<string, H3.SmartForm.SmartFormResponseDataItem>) taskObj["T"]; foreach(string key in taskobject.Keys) { taskobject[key].Visible = false; //設定子表列隱藏 } } } //非子表 else { //判斷控制元件內是否為空 //文字、下拉框、日期 if(string.IsNullOrEmpty(masterBo[controlCode] + string.Empty)) { response.ReturnData[controlCode].Visible = false; //設定欄位不可見 } else if(masterBo[controlCode] is string) { } else if(masterBo[controlCode] is double) { } else if(masterBo[controlCode] is DateTime) { } //判斷控制元件內是否為空 //關聯表單多選 else if(((string[]) masterBo[controlCode]).Length < 1) { response.ReturnData[controlCode].Visible = false; //設定欄位不可見 } } } //判斷當前是否為編輯狀態 if(request.FormMode.ToString() == "Edit") { response.ReturnData[controlCode].Visible = true; //設定欄位可見 } } return response; } }