- 新增 BpjaDAC(SelectPage/SelectCount/SelectBPJAIndex) - dsBPJAGrid 改 ObjectDataSource;Search/Selected/DataBound 調整
107 lines
3.3 KiB
C#
107 lines
3.3 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Text;
|
|
using System.ComponentModel;
|
|
using Wellan.Data;
|
|
|
|
/// <summary>
|
|
/// 年度職稱設定的資料處理類別
|
|
/// </summary>
|
|
[DataObject(true)]
|
|
public class BpjaDAC : Wellan.Data.WDAC
|
|
{
|
|
public BpjaDAC()
|
|
{
|
|
}
|
|
|
|
public BpjaDAC(string connectionConfig, string connectionConfigName)
|
|
: this()
|
|
{
|
|
this._connectionConfig = connectionConfig;
|
|
this._connectionConfigName = connectionConfigName;
|
|
}
|
|
|
|
public BpjaDAC(WQuery query)
|
|
{
|
|
this._query = query;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 年度職稱設定 Grid 分頁查詢
|
|
/// </summary>
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public DataTable SelectPage(int startRowIndex, int maximumRows, string BPPYN)
|
|
{
|
|
DbCommand cmd = Query.NewCommand();
|
|
|
|
StringBuilder filter = new StringBuilder();
|
|
BuildFilter(filter, cmd, BPPYN);
|
|
|
|
cmd.CommandText = String.Format(
|
|
@"SELECT * FROM
|
|
(
|
|
SELECT *, ROW_NUMBER() OVER (ORDER BY BPPYN, BPJNO) AS ROWID
|
|
FROM BPJA WHERE 1=1 {0}
|
|
) AS TMP
|
|
WHERE ROWID BETWEEN @STARTROWINDEX + 1 AND @STARTROWINDEX + @MAXIMUMROWS
|
|
ORDER BY ROWID",
|
|
filter.ToString());
|
|
cmd.Parameters.Add(Query.NewParameter("STARTROWINDEX", startRowIndex));
|
|
cmd.Parameters.Add(Query.NewParameter("MAXIMUMROWS", maximumRows));
|
|
|
|
return Query.Select(cmd);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 年度職稱設定 Grid 查詢筆數
|
|
/// </summary>
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public int SelectCount(string BPPYN)
|
|
{
|
|
DbCommand cmd = Query.NewCommand();
|
|
|
|
StringBuilder filter = new StringBuilder();
|
|
BuildFilter(filter, cmd, BPPYN);
|
|
|
|
cmd.CommandText = String.Format("SELECT COUNT(*) FROM BPJA WHERE 1=1 {0}", filter.ToString());
|
|
return WDAC.GetInt32Value(Query.ExecuteScalar(cmd));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得指定職稱在查詢結果中的序號 (0 起算)
|
|
/// </summary>
|
|
public int SelectBPJAIndex(string targetBPPYN, string targetBPJNO, string BPPYN)
|
|
{
|
|
DbCommand cmd = Query.NewCommand();
|
|
|
|
StringBuilder filter = new StringBuilder();
|
|
BuildFilter(filter, cmd, BPPYN);
|
|
|
|
cmd.CommandText = String.Format(
|
|
@"SELECT ROWID - 1 FROM
|
|
(
|
|
SELECT BPPYN, BPJNO, ROW_NUMBER() OVER (ORDER BY BPPYN, BPJNO) AS ROWID
|
|
FROM BPJA WHERE 1=1 {0}
|
|
) AS TMP WHERE BPPYN = @TARGET_BPPYN AND BPJNO = @TARGET_BPJNO",
|
|
filter.ToString());
|
|
cmd.Parameters.Add(Query.NewParameter("TARGET_BPPYN", targetBPPYN));
|
|
cmd.Parameters.Add(Query.NewParameter("TARGET_BPJNO", targetBPJNO));
|
|
|
|
object o = Query.ExecuteScalar(cmd);
|
|
return (o is Int32 || o is Int64) ? WDAC.GetInt32Value(o) : -1;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 組出年度職稱設定 Grid 的查詢條件 (與舊 AddSearch 行為一致)
|
|
/// </summary>
|
|
private void BuildFilter(StringBuilder sb, DbCommand cmd, string BPPYN)
|
|
{
|
|
if (!string.IsNullOrEmpty(BPPYN))
|
|
{
|
|
sb.Append(" AND BPPYN LIKE @BPPYN1 ");
|
|
cmd.Parameters.Add(Query.NewParameter("BPPYN1", BPPYN + "%"));
|
|
}
|
|
}
|
|
}
|