feat: fmBpaa GridView 改用 ObjectDataSource
- BpaaDAC 新增 SelectPage/SelectCount/SelectBPAAIndex - dsBPAAGrid 改 ObjectDataSource(EnablePaging) - Search/Selected/DataBound 調整;跳回選取列改用 SelectBPAAIndex - 計畫文檔更新
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
| # | 檔案 | GridView ID | SqlDataSource ID | 來源表 | 既有 DAC | 狀態 |
|
||||
|---|---|---|---|---|---|---|
|
||||
| 1 | forms/customer/fmBcus.ascx | gvBCUS | dsBCUSGrid | BCUS | 無→BcusDAC | **完成** |
|
||||
| 2 | forms/customer/fmBpaa.ascx | gvBPAA | dsBPAAGrid | BPAA | BpaaDAC(無 Select) | 待辦 |
|
||||
| 2 | forms/customer/fmBpaa.ascx | gvBPAA | dsBPAAGrid | BPAA | BpaaDAC(+Select) | **完成** |
|
||||
| 3 | forms/customer/fmBpab.ascx | gvBPAB | dsBPABGrid | BPAB | 無 | 待辦 |
|
||||
| 4 | forms/customer/fmBpabBig.ascx | gvBPAB | dsBPABGrid | BPAB | 無 | 待辦 |
|
||||
| 5 | forms/customer/fmBpabSmall.ascx | gvBPAB | dsBPABGrid | BPAB | 無 | 待辦 |
|
||||
@@ -143,3 +143,4 @@
|
||||
| 2026-09-10 | 以 LocalDB 合成資料(2 萬/10 萬筆)基準測試舊 SqlDataSource 與新 ObjectDataSource;結果:首頁列數 ~10,000×、記憶體趨近 0、DB 時間約 6×;深頁跳轉 reads 反而增加 |
|
||||
| 2026-09-10 | 分頁 SQL 形式比較:`BETWEEN` 與 `TOP` 相同(無改善);改採 KEYSET(窄集合算 ROWID 再 join 明細)並將 SelectCount/SelectBPENOIndex 改為窄集合。深頁 2,166ms/262萬 reads → 48ms/6,549 reads;count 714ms/608,176 reads → 110ms/6,253 reads;aspnet_compiler 編譯通過 |
|
||||
| 2026-09-10 | 轉換 fmBcus(BCUS):新增 BcusDAC;dsBCUSGrid 改 ObjectDataSource;跳回選取列改用 SelectBCNUMIndex;aspnet_compiler 編譯通過 |
|
||||
| 2026-09-10 | 轉換 fmBpaa(BPAA):BpaaDAC 新增 SelectPage/SelectCount/SelectBPAAIndex;dsBPAAGrid 改 ObjectDataSource;編譯通過 |
|
||||
|
||||
@@ -3,12 +3,15 @@ using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Data.Common;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using Wellan.Common;
|
||||
using Wellan.Data;
|
||||
|
||||
/// <summary>
|
||||
/// 取得專案年度接單資料
|
||||
/// </summary>
|
||||
[DataObject(true)]
|
||||
public class BpaaDAC : Wellan.Data.WDAC
|
||||
{
|
||||
public BpaaDAC()
|
||||
@@ -325,4 +328,96 @@ public class BpaaDAC : Wellan.Data.WDAC
|
||||
cmd.Parameters.Add(Query.NewParameter("BPPNM", bppnm));
|
||||
return WDAC.GetStringValue(Query.ExecuteScalar(cmd));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 年度接單 Grid 分頁查詢
|
||||
/// </summary>
|
||||
[DataObjectMethod(DataObjectMethodType.Select)]
|
||||
public DataTable SelectPage(int startRowIndex, int maximumRows, string BPPNM, string BPYER, string BPPYN, string BPPYM)
|
||||
{
|
||||
DbCommand cmd = Query.NewCommand();
|
||||
|
||||
StringBuilder filter = new StringBuilder();
|
||||
BuildFilter(filter, cmd, BPPNM, BPYER, BPPYN, BPPYM);
|
||||
|
||||
cmd.CommandText = String.Format(
|
||||
@"SELECT * FROM
|
||||
(
|
||||
SELECT *, ROW_NUMBER() OVER (ORDER BY BPPNM, BPYER) AS ROWID
|
||||
FROM BPAA 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 BPPNM, string BPYER, string BPPYN, string BPPYM)
|
||||
{
|
||||
DbCommand cmd = Query.NewCommand();
|
||||
|
||||
StringBuilder filter = new StringBuilder();
|
||||
BuildFilter(filter, cmd, BPPNM, BPYER, BPPYN, BPPYM);
|
||||
|
||||
cmd.CommandText = String.Format("SELECT COUNT(*) FROM BPAA WHERE 1=1 {0}", filter.ToString());
|
||||
return WDAC.GetInt32Value(Query.ExecuteScalar(cmd));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得指定年度接單在查詢結果中的序號 (0 起算)
|
||||
/// </summary>
|
||||
public int SelectBPAAIndex(string targetBPPNM, string targetBPYER, string BPPNM, string BPYER, string BPPYN, string BPPYM)
|
||||
{
|
||||
DbCommand cmd = Query.NewCommand();
|
||||
|
||||
StringBuilder filter = new StringBuilder();
|
||||
BuildFilter(filter, cmd, BPPNM, BPYER, BPPYN, BPPYM);
|
||||
|
||||
cmd.CommandText = String.Format(
|
||||
@"SELECT ROWID - 1 FROM
|
||||
(
|
||||
SELECT BPPNM, BPYER, ROW_NUMBER() OVER (ORDER BY BPPNM, BPYER) AS ROWID
|
||||
FROM BPAA WHERE 1=1 {0}
|
||||
) AS TMP WHERE BPPNM = @TARGET_BPPNM AND BPYER = @TARGET_BPYER",
|
||||
filter.ToString());
|
||||
cmd.Parameters.Add(Query.NewParameter("TARGET_BPPNM", targetBPPNM));
|
||||
cmd.Parameters.Add(Query.NewParameter("TARGET_BPYER", targetBPYER));
|
||||
|
||||
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 BPPNM, string BPYER, string BPPYN, string BPPYM)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(BPPNM))
|
||||
{
|
||||
sb.Append(" AND BPPNM LIKE @BPPNM1 ");
|
||||
cmd.Parameters.Add(Query.NewParameter("BPPNM1", BPPNM + "%"));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(BPYER))
|
||||
{
|
||||
sb.Append(" AND BPYER LIKE @BPYER1 ");
|
||||
cmd.Parameters.Add(Query.NewParameter("BPYER1", BPYER + "%"));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(BPPYN))
|
||||
{
|
||||
sb.Append(" AND BPPYN LIKE @BPPYN1 ");
|
||||
cmd.Parameters.Add(Query.NewParameter("BPPYN1", BPPYN + "%"));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(BPPYM))
|
||||
{
|
||||
sb.Append(" AND BPPYM LIKE @BPPYM1 ");
|
||||
cmd.Parameters.Add(Query.NewParameter("BPPYM1", BPPYM + "%"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,10 +66,16 @@
|
||||
TextMessageId="" Visible="False"></cc1:WLabel>
|
||||
</asp:View>
|
||||
<asp:View ID="EditView" runat="server">
|
||||
<asp:SqlDataSource ID="dsBPAAGrid" runat="server"
|
||||
ConflictDetection="CompareAllValues" SelectCommand="SELECT * FROM BPAA WHERE 1=0"
|
||||
ConnectionString="Data Source=(local);Initial Catalog=THINKYU_WEB;Persist Security Info=True;User ID=sa"
|
||||
ProviderName="System.Data.SqlClient" OnSelected="dsBPAAGrid_Selected"></asp:SqlDataSource>
|
||||
<asp:ObjectDataSource ID="dsBPAAGrid" runat="server"
|
||||
TypeName="BpaaDAC" SelectMethod="SelectPage" SelectCountMethod="SelectCount"
|
||||
EnablePaging="true" OnSelected="dsBPAAGrid_Selected">
|
||||
<SelectParameters>
|
||||
<asp:Parameter Name="BPPNM" Type="String" />
|
||||
<asp:Parameter Name="BPYER" Type="String" />
|
||||
<asp:Parameter Name="BPPYN" Type="String" />
|
||||
<asp:Parameter Name="BPPYM" Type="String" />
|
||||
</SelectParameters>
|
||||
</asp:ObjectDataSource>
|
||||
<asp:SqlDataSource ID="dsBPAAForm" runat="server"
|
||||
InsertCommand="INSERT INTO BPAA
|
||||
(BPPNM, BPYER, BPPYN, BPPYM, BPBGT, BPFED, BPSAL, BPOTT, BPOTD, BPALT, APPNO, TRDAT, TRMOD,
|
||||
|
||||
@@ -27,10 +27,6 @@ public partial class forms_customer_fmBpaa : Wellan.Web.UI.WUserControlBase
|
||||
private string _BPPYM = "";
|
||||
//private int _OLD_BPYER = 0;
|
||||
//private string _OLD_BPPYN = "";
|
||||
private string select = "SELECT * ";
|
||||
private string from = " FROM BPAA ";
|
||||
private string where = " WHERE 1=1 ";
|
||||
private string order = " ORDER BY BPPNM, BPYER";
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
@@ -42,7 +38,6 @@ public partial class forms_customer_fmBpaa : Wellan.Web.UI.WUserControlBase
|
||||
{
|
||||
base.OnInit(e);
|
||||
dsBPAAForm.ConnectionString = ConnectionString;
|
||||
dsBPAAGrid.ConnectionString = ConnectionString;
|
||||
|
||||
//_BPPNM = ViewState["BPPNM"] != null ? ViewState["BPPNM"].ToString() : "";
|
||||
//_BPYER = ViewState["BPYER"] != null ? ViewState["BPYER"].ToString() : "";
|
||||
@@ -113,17 +108,27 @@ public partial class forms_customer_fmBpaa : Wellan.Web.UI.WUserControlBase
|
||||
// 查詢動作
|
||||
private new void Search()
|
||||
{
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.Append(select);
|
||||
sql.Append(from);
|
||||
sql.Append(where);
|
||||
dsBPAAGrid.SelectParameters.Clear();
|
||||
AddSearch(sql, dsBPAAGrid, "BPPNM", _BPPNM, "", true);
|
||||
AddSearch(sql, dsBPAAGrid, "BPYER", _BPYER, "", true);
|
||||
AddSearch(sql, dsBPAAGrid, "BPPYN", _BPPYN, "", true);
|
||||
AddSearch(sql, dsBPAAGrid, "BPPYM", _BPPYM, "", true);
|
||||
sql.Append(order);
|
||||
dsBPAAGrid.SelectCommand = sql.ToString();
|
||||
dsBPAAGrid.SelectParameters["BPPNM"].DefaultValue = _BPPNM;
|
||||
dsBPAAGrid.SelectParameters["BPYER"].DefaultValue = _BPYER;
|
||||
dsBPAAGrid.SelectParameters["BPPYN"].DefaultValue = _BPPYN;
|
||||
dsBPAAGrid.SelectParameters["BPPYM"].DefaultValue = _BPPYM;
|
||||
|
||||
// 返回時,回到之前選擇的那一筆
|
||||
if (ParamList != null && ParamList.ContainsKey("BPPNM") && ParamList.ContainsKey("BPYER"))
|
||||
{
|
||||
int rowIndex = new BpaaDAC(Query).SelectBPAAIndex(
|
||||
WDAC.GetStringValue(ParamList["BPPNM"]),
|
||||
WDAC.GetStringValue(ParamList["BPYER"]),
|
||||
_BPPNM, _BPYER, _BPPYN, _BPPYM);
|
||||
|
||||
if (rowIndex >= 0)
|
||||
{
|
||||
gvBPAA.PageIndex = rowIndex / gvBPAA.PageSize;
|
||||
gvBPAA.SelectedIndex = rowIndex - gvBPAA.PageIndex * gvBPAA.PageSize;
|
||||
}
|
||||
|
||||
ParamList.Remove("BPYER");
|
||||
}
|
||||
}
|
||||
|
||||
private void CalcFields(System.Collections.Specialized.IOrderedDictionary values)
|
||||
@@ -155,22 +160,6 @@ public partial class forms_customer_fmBpaa : Wellan.Web.UI.WUserControlBase
|
||||
if (gvBPAA.SelectedIndex == -1)
|
||||
gvBPAA.SelectedIndex = 0;
|
||||
|
||||
// 返回時,回到之前選擇的那一筆
|
||||
if (ParamList.ContainsKey("BPPNM") && ParamList.ContainsKey("BPYER"))
|
||||
{
|
||||
DataView dv = dsBPAAGrid.Select(new DataSourceSelectArguments()) as DataView;
|
||||
dv.RowFilter = String.Format("BPPNM='{0}' and BPYER={1}", ParamList["BPPNM"], ParamList["BPYER"]);
|
||||
if (dv.Count > 0)
|
||||
{
|
||||
int rowIndex = dv.Table.Rows.IndexOf(dv[0].Row);
|
||||
gvBPAA.PageIndex = (rowIndex / gvBPAA.PageSize);
|
||||
gvBPAA.SelectedIndex = rowIndex - gvBPAA.PageIndex * gvBPAA.PageSize;
|
||||
}
|
||||
|
||||
// ParamList.Remove("BPPNM");
|
||||
ParamList.Remove("BPYER");
|
||||
}
|
||||
|
||||
fvBPAA.DataBind();
|
||||
}
|
||||
}
|
||||
@@ -182,9 +171,9 @@ public partial class forms_customer_fmBpaa : Wellan.Web.UI.WUserControlBase
|
||||
gvBPAA.DataBind();
|
||||
}
|
||||
|
||||
protected void dsBPAAGrid_Selected(object sender, SqlDataSourceStatusEventArgs e)
|
||||
protected void dsBPAAGrid_Selected(object sender, ObjectDataSourceStatusEventArgs e)
|
||||
{
|
||||
if (e.AffectedRows == 0)
|
||||
if (e.ReturnValue is Int32 && WDAC.GetInt32Value(e.ReturnValue) == 0)
|
||||
{
|
||||
fvBPAA.ChangeMode(FormViewMode.Insert);
|
||||
fvBPAA_ModeChanged(sender, e);
|
||||
|
||||
Reference in New Issue
Block a user