/// <summary> /// 下拉選項單一table單一鍵值使用 /// </summary> /// <param name="pTableCode">資料表</param> /// <param name="pFieldCode">欄位鍵值</param> /// <param name="pFieldName">欄位名稱</param> /// <param name="pShowType">A:全秀(預設),B:秀值,C:秀名</param> /// <returns></returns> public List <DDLList> Get_DDLOption(string pTableCode, string pFieldCode = "", string pFieldName = "", string pShowType = "A") { List <DDLList> list = new List <DDLList>(); string sSql = ""; sSql = "SELECT " + pFieldCode + " as field_code, " + pFieldName + " as field_name, '" + pShowType + "' as show_type FROM " + pTableCode + " order by " + pFieldCode + " "; using (SqlConnection con_db = Set_DBConnection()) { SqlCommand sqlCommand = new SqlCommand(sSql); sqlCommand.Connection = con_db; SqlDataReader reader = sqlCommand.ExecuteReader(); sqlCommand.Parameters.Add(new SqlParameter("@code_code", pFieldCode)); while (reader.Read()) { DDLList data = new DDLList(); data.field_code = reader["field_code"].ToString(); data.field_name = reader["field_name"].ToString(); data.show_type = reader["show_type"].ToString(); list.Add(data); } } return(list); }
/// <summary> /// 取得下拉選項的資料來源 /// </summary> /// <param name="pCode">選項代碼關聯BDP210</param> /// <returns></returns> public List <DDLList> Get_DDLOption(string pCode) { List <DDLList> list = new List <DDLList>(); string sSql = ""; //使用BDP210的設定值 //if (pType == "A") //{ sSql = "SELECT field_code, field_name, (SELECT show_type FROM BDP21_0000 WHERE code_code=@code_code ) as show_type FROM BDP21_0100 where code_code=@code_code and is_use='Y' order by scr_no"; //} using (SqlConnection con_db = Set_DBConnection()) { SqlCommand sqlCommand = new SqlCommand(sSql); sqlCommand.Connection = con_db; //if (pType == "A") //{ sqlCommand.Parameters.Add(new SqlParameter("@code_code", pCode)); //} SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { DDLList data = new DDLList(); data.field_code = reader["field_code"].ToString(); data.field_name = reader["field_name"].ToString(); data.show_type = reader["show_type"].ToString(); list.Add(data); } } return(list); }
/// <summary> /// 取得下拉選項資料來源 用自訂的SQL語法 /// </summary> /// <param name="pSql">自定義有field_code,field_name的sql語法</param> /// <param name="pShowType">A:全秀(預設),B:秀值,C:秀名</param> /// <returns></returns> public List <DDLList> Get_DDLOption(string pSql, string pShowType = "A") { List <DDLList> list = new List <DDLList>(); string sSql = ""; sSql = pSql; using (SqlConnection con_db = Set_DBConnection()) { SqlCommand sqlCommand = new SqlCommand(sSql); sqlCommand.Connection = con_db; SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { DDLList data = new DDLList(); data.field_code = reader["field_code"].ToString(); data.field_name = reader["field_name"].ToString(); data.show_type = pShowType; list.Add(data); } } return(list); }