Sbo通用数据选择功能的实现
生活随笔
收集整理的這篇文章主要介紹了
Sbo通用数据选择功能的实现
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
本文著作權(quán)屬于江湖浪子@IT,任何人未經(jīng)作者本人批準(zhǔn),不得轉(zhuǎn)載。 ? 在Sbo Addon開發(fā)中,經(jīng)常為了業(yè)務(wù)實現(xiàn),需要從當(dāng)前的業(yè)務(wù)數(shù)據(jù)庫中列舉出符合條件信息,供業(yè)務(wù)操作人員進(jìn)行選擇,并且將選擇之后的數(shù)據(jù)及其相關(guān)信息傳遞到當(dāng)前的業(yè)務(wù)界面,或者填充當(dāng)前的業(yè)務(wù)控件(比如編輯文本、下拉框等),或者填充Matrix中的指定Column,以及更加個性化的業(yè)務(wù)處理(比如根據(jù)選擇的數(shù)據(jù)進(jìn)行業(yè)務(wù)初始化、業(yè)務(wù)流程處理等)。 這的確是一個很常用的功能,有必要對其進(jìn)行業(yè)務(wù)抽象和歸納,形成一個通用的數(shù)據(jù)選擇功能。富盛Sbo程序開發(fā)框架有效的解決了這一問題。 因為業(yè)務(wù)不同,需要選擇的業(yè)務(wù)數(shù)據(jù)也不同。就是說,這個通用的數(shù)據(jù)選擇提供的選擇數(shù)據(jù)是不確定的,自然選擇條件是不確定的,提供操作用戶的表示數(shù)據(jù)是不確定的,選擇之后的傳遞到業(yè)務(wù)界面上的數(shù)據(jù)和業(yè)務(wù)操作也是不確定的。 1、檢索條件、數(shù)據(jù)展示定制化 要展示不同的數(shù)據(jù)選擇內(nèi)容,并且展示數(shù)據(jù)可能來自不同的數(shù)據(jù)表中,甚至選擇數(shù)據(jù)集的來源可能是SELECT語句,也完全可能是存儲過程的返回集合,能夠滿足這種展示條件的只有使用Grid控件了。而Grid控件的數(shù)據(jù)來源是可以定制的,這又滿足了數(shù)據(jù)檢索條件不確定性的要求。 實現(xiàn)如下: fsSbo.AddButton2Form(ref oForm, "btnChoose", "選擇", 315, 10, 65, 20);
??????????????????????????? fsSbo.AddItem2Form(ref oForm, "2", BoFormItemTypes.it_BUTTON, 315, 80, 65, 20); Grid grd = fsSbo.AddGrid2Form(ref oForm, "grdData", 5, 5, 530, 300);
??????????????????????????? grd.DataTable = oForm.DataSources.DataTables.Add("dtData");
??????????????????????????? grd.SelectionMode = BoMatrixSelect.ms_Single; grd.DataTable.ExecuteQuery(strChooseDataSQL);
??????????????????????????? for (int i = 0; i < grd.DataTable.Columns.Count; i++)
??????????????????????????? {
??????????????????????????????? if (grd.DataTable.Columns.Item(i).Type == BoFieldsType.ft_Integer || grd.DataTable.Columns.Item(i).Type == BoFieldsType.ft_Float)
??????????????????????????????????? grd.Columns.Item(i).RightJustified = true; grd.Columns.Item(i).Editable = false; if (grd.Columns.Item(i).UniqueID.StartsWith("$$")) grd.Columns.Item(i).Visible = false;
??????????????????????????? } grd.AutoResizeColumns(); 當(dāng)然,在數(shù)據(jù)展示的時候,應(yīng)該考慮到行業(yè)習(xí)慣,Grid數(shù)據(jù)欄目如果是數(shù)據(jù)類型應(yīng)該自動將其展示為右對齊,顯然,這是可以辦到的。 檢索條件自動化、展示數(shù)據(jù)自動化、展示數(shù)據(jù)慣例化,看來都不是問題。在接下來要解決的是選擇結(jié)果定制化,這也完全可以辦到。 2、數(shù)據(jù)選擇業(yè)務(wù)處理定制化 在選擇數(shù)據(jù)窗口中,通過參數(shù)獲得調(diào)用窗體及數(shù)據(jù)信息需要回寫的控件Id,當(dāng)然了,如果需要回寫到Matrix中,除了需要指定這個Matrix的數(shù)據(jù)回寫的列欄目,還應(yīng)該指定需要回寫的對應(yīng)行;當(dāng)然了,對于個性化的業(yè)務(wù)處理,在調(diào)用窗體中定義一個回調(diào)函數(shù),在數(shù)據(jù)選擇窗體的選擇事件通過回調(diào)函數(shù)來完成個性化業(yè)務(wù)處理。 實現(xiàn)方法如下: string[] strColumns = strFatherFields.Split(',');
??????????????????? string[] strValues = new string[strFatherFields.Length == 0 || frmFather != null ? dt.Columns.Count : strColumns.Length];
??????????????????? for (int i = 0; i < strValues.Length; i++)
??????????????????? {
??????????????????????? string strValue = "";
??????????????????????? if (dt.Columns.Item(i).Cells.Item(nSelectedRow).Value != null) strValue = dt.Columns.Item(i).Cells.Item(nSelectedRow).Value.ToString();
??????????????????????? if (i < dt.Columns.Count) strValues[i] = strValue;
??????????????????? } if (strFatherFId.Length > 0 && strColumns.Length > 0)
??????????????????? {
??????????????????????? Form frm = fsSbo.fsSboApplication.Forms.Item(strFatherFId); oForm.Close(); frm.Freeze(true);
??????????????????????? for (int i = 0; i < strColumns.Length; i++)
??????????????????????? {
??????????????????????????? if (strMtxId.Length > 0 && nMtxRow > 0)
??????????????????????????? {
??????????????????????????????? Matrix mtx = (Matrix)frm.Items.Item(strMtxId).Specific;
??????????????????????????????? Column oColumn = mtx.Columns.Item(strColumns[i]); if (oColumn.Type == BoFormItemTypes.it_EDIT || oColumn.Type == BoFormItemTypes.it_EXTEDIT)
??????????????????????????????????? fsSbo.SetValue2MtxEditText(ref mtx, strColumns[i], nMtxRow, strValues[i]);
??????????????????????????????? else if (oColumn.Type == BoFormItemTypes.it_COMBO_BOX)
??????????????????????????????????? fsSbo.SetValue2MtxCombox(ref mtx, strColumns[i], nMtxRow, strValues[i]);
??????????????????????????? }
??????????????????????????? else
??????????????????????????? {
??????????????????????????????? Item oItem = frm.Items.Item(strColumns[i]);
??????????????????????????????? if (oItem.Type == BoFormItemTypes.it_COMBO_BOX)
??????????????????????????????????? fsSbo.SetValue2Combox(ref frm, strColumns[i], strValues[i]);
??????????????????????????????? else if (oItem.Type == BoFormItemTypes.it_EDIT || oItem.Type == BoFormItemTypes.it_EXTEDIT)
??????????????????????????????????? fsSbo.SetValue2EditText(ref frm, strColumns[i], strValues[i]);
??????????????????????????? }
??????????????????????? } if (frm.Mode != BoFormMode.fm_ADD_MODE) frm.Mode = BoFormMode.fm_UPDATE_MODE; frm.Freeze(false);
??????????????????????? frm.Refresh();
??????????????????????? frm.Update();
??????????????????? }
??????????????????? else if (frmFather != null)
??????????????????? {
??????????????????????? string strFormId = oForm.UniqueID; oForm.Close(); frmFather.SetReturnValue4SelectForm(strValues, strFatherFields);
??????????????????? } 3、如何調(diào)用 既然完成了業(yè)務(wù)處理,調(diào)用這個通用的數(shù)據(jù)選擇功能就很簡單了。當(dāng)然將這個調(diào)用寫成一個通用的函數(shù)是個很好的習(xí)慣。富盛Sbo程序開發(fā)框架就是這樣完成的。 public Boolean OpenChooseDataForm(string strTitle, string strFatherId, string strQuerySQL, string strFatherFields, string strMtxId, int nMtxRow)
??????? {
??????????? Boolean bRet = false;
??????????? try
??????????? {
??????????????? fsSboChooseDataBase frm = new fsSboChooseDataBase(this);
??????????????? frm.ChooseDataSQL = strQuerySQL;
??????????????? frm.FatherFields = strFatherFields;
??????????????? frm.FatherFormId = strFatherId;
??????????????? if (strMtxId.Length > 0 && nMtxRow > 0)
??????????????? {
??????????????????? frm.FatherMatrixId = strMtxId;
??????????????????? frm.FatherMatrixRow = nMtxRow;
??????????????? }
???????????????
??????????????? bRet = ShowForm(frm, "ChooseData" + strFatherId, strTitle);
??????????? }
??????????? catch (Exception ex)
??????????? {
??????????????? ShowMsg("錯誤:" + ex.Message);
??????????? } return bRet;
??????? } 這里的fsSboChooseDataBase就是上述我們討論的通用數(shù)據(jù)選擇業(yè)務(wù)實現(xiàn)類了。 4、實例 在富盛打葉復(fù)烤生產(chǎn)管理系統(tǒng)中,廣泛的使用這一通用數(shù)據(jù)選擇功能。 4.1 通過以下代碼實現(xiàn)加工協(xié)議選擇,選擇之后的信息被回填到業(yè)務(wù)選擇界面的編輯文本中。 string strSQL = "", strTitle = "", strFields = ""; strTitle = "選擇加工協(xié)議";
??????????????????? strSQL = "SELECT DocEntry as [$$DocEntry], U_DealCode 加工協(xié)議, U_DealName 協(xié)議描述, U_DealNo 檔案編號, U_WrkBatNo 生產(chǎn)批次, U_CardCode 委托方, U_CardName 委托方名稱, U_PlanSD 計劃開始, U_PlanED 計劃結(jié)束? FROM [@FSCXFWORKDEALINFO] WHERE IsNull(U_Stts,'0') in ('2','3')";
??????????????????? strFields = "DealEntry,emDealCode,emDealName,emDealNo,emBatNo,emCardCode,emCardName"; bRet = fsSbo.OpenChooseDataForm(strTitle, oForm.UniqueID, strSQL, strFields, "", -1); 實現(xiàn)的數(shù)據(jù)選擇界面如下: 選后數(shù)據(jù)回寫到以下界面 4.2 通過以下代碼實現(xiàn)加工物料選擇,選擇之后的信息被回填到業(yè)務(wù)選擇界面的Matrix中。 string strSQL = "", strTitle = "選擇投料"; string strDealEntry = fsSbo.GetValue4EditText(oForm, "DealEntry");
??????????????? if (strDealEntry.Length > 0)
??????????????? {
??????????????????????? strSQL = "SELECT U_ItemCode 物料代碼, U_ItemName 物料描述, U_BaseItem as [$$BaseItem], U_BaseCode as [$$BaseCode], U_GrdEntry as [$$GrdEntry], U_GrdCode 等級, U_FromCode as [$$FromCode], U_FromName [產(chǎn)地], U_ItemAge 年限, IsNull(U_Qty,0) - IsNull(U_Qtyed,0) [$$RemQty], U_ItemGrp [$$ItemGrp], U_WhsCode [$$WhsCode], DocEntry as [$$DocEntry], U_Qty 計劃加工, U_Qtyed 已加工, U_Notes 備注 FROM [@FSCXFWORKDEALLINE1] WHERE U_ItemGrp in (" + fsSbo.fsSboMes4CxF.ItemGroupCodeBeforePick + ") AND DocEntry=" + strDealEntry + (strItemList.Length > 0 ? " AND U_ItemCode not in (" + strItemList + ")" : "");
??????????????????? bRet = fsSbo.OpenChooseDataForm(strTitle, this, strSQL, "REQUEST");
??????????????? } 數(shù)據(jù)選擇界面如下: 選后數(shù)據(jù)回寫到以下界面: <>
??????????????????????????? fsSbo.AddItem2Form(ref oForm, "2", BoFormItemTypes.it_BUTTON, 315, 80, 65, 20); Grid grd = fsSbo.AddGrid2Form(ref oForm, "grdData", 5, 5, 530, 300);
??????????????????????????? grd.DataTable = oForm.DataSources.DataTables.Add("dtData");
??????????????????????????? grd.SelectionMode = BoMatrixSelect.ms_Single; grd.DataTable.ExecuteQuery(strChooseDataSQL);
??????????????????????????? for (int i = 0; i < grd.DataTable.Columns.Count; i++)
??????????????????????????? {
??????????????????????????????? if (grd.DataTable.Columns.Item(i).Type == BoFieldsType.ft_Integer || grd.DataTable.Columns.Item(i).Type == BoFieldsType.ft_Float)
??????????????????????????????????? grd.Columns.Item(i).RightJustified = true; grd.Columns.Item(i).Editable = false; if (grd.Columns.Item(i).UniqueID.StartsWith("$$")) grd.Columns.Item(i).Visible = false;
??????????????????????????? } grd.AutoResizeColumns(); 當(dāng)然,在數(shù)據(jù)展示的時候,應(yīng)該考慮到行業(yè)習(xí)慣,Grid數(shù)據(jù)欄目如果是數(shù)據(jù)類型應(yīng)該自動將其展示為右對齊,顯然,這是可以辦到的。 檢索條件自動化、展示數(shù)據(jù)自動化、展示數(shù)據(jù)慣例化,看來都不是問題。在接下來要解決的是選擇結(jié)果定制化,這也完全可以辦到。 2、數(shù)據(jù)選擇業(yè)務(wù)處理定制化 在選擇數(shù)據(jù)窗口中,通過參數(shù)獲得調(diào)用窗體及數(shù)據(jù)信息需要回寫的控件Id,當(dāng)然了,如果需要回寫到Matrix中,除了需要指定這個Matrix的數(shù)據(jù)回寫的列欄目,還應(yīng)該指定需要回寫的對應(yīng)行;當(dāng)然了,對于個性化的業(yè)務(wù)處理,在調(diào)用窗體中定義一個回調(diào)函數(shù),在數(shù)據(jù)選擇窗體的選擇事件通過回調(diào)函數(shù)來完成個性化業(yè)務(wù)處理。 實現(xiàn)方法如下: string[] strColumns = strFatherFields.Split(',');
??????????????????? string[] strValues = new string[strFatherFields.Length == 0 || frmFather != null ? dt.Columns.Count : strColumns.Length];
??????????????????? for (int i = 0; i < strValues.Length; i++)
??????????????????? {
??????????????????????? string strValue = "";
??????????????????????? if (dt.Columns.Item(i).Cells.Item(nSelectedRow).Value != null) strValue = dt.Columns.Item(i).Cells.Item(nSelectedRow).Value.ToString();
??????????????????????? if (i < dt.Columns.Count) strValues[i] = strValue;
??????????????????? } if (strFatherFId.Length > 0 && strColumns.Length > 0)
??????????????????? {
??????????????????????? Form frm = fsSbo.fsSboApplication.Forms.Item(strFatherFId); oForm.Close(); frm.Freeze(true);
??????????????????????? for (int i = 0; i < strColumns.Length; i++)
??????????????????????? {
??????????????????????????? if (strMtxId.Length > 0 && nMtxRow > 0)
??????????????????????????? {
??????????????????????????????? Matrix mtx = (Matrix)frm.Items.Item(strMtxId).Specific;
??????????????????????????????? Column oColumn = mtx.Columns.Item(strColumns[i]); if (oColumn.Type == BoFormItemTypes.it_EDIT || oColumn.Type == BoFormItemTypes.it_EXTEDIT)
??????????????????????????????????? fsSbo.SetValue2MtxEditText(ref mtx, strColumns[i], nMtxRow, strValues[i]);
??????????????????????????????? else if (oColumn.Type == BoFormItemTypes.it_COMBO_BOX)
??????????????????????????????????? fsSbo.SetValue2MtxCombox(ref mtx, strColumns[i], nMtxRow, strValues[i]);
??????????????????????????? }
??????????????????????????? else
??????????????????????????? {
??????????????????????????????? Item oItem = frm.Items.Item(strColumns[i]);
??????????????????????????????? if (oItem.Type == BoFormItemTypes.it_COMBO_BOX)
??????????????????????????????????? fsSbo.SetValue2Combox(ref frm, strColumns[i], strValues[i]);
??????????????????????????????? else if (oItem.Type == BoFormItemTypes.it_EDIT || oItem.Type == BoFormItemTypes.it_EXTEDIT)
??????????????????????????????????? fsSbo.SetValue2EditText(ref frm, strColumns[i], strValues[i]);
??????????????????????????? }
??????????????????????? } if (frm.Mode != BoFormMode.fm_ADD_MODE) frm.Mode = BoFormMode.fm_UPDATE_MODE; frm.Freeze(false);
??????????????????????? frm.Refresh();
??????????????????????? frm.Update();
??????????????????? }
??????????????????? else if (frmFather != null)
??????????????????? {
??????????????????????? string strFormId = oForm.UniqueID; oForm.Close(); frmFather.SetReturnValue4SelectForm(strValues, strFatherFields);
??????????????????? } 3、如何調(diào)用 既然完成了業(yè)務(wù)處理,調(diào)用這個通用的數(shù)據(jù)選擇功能就很簡單了。當(dāng)然將這個調(diào)用寫成一個通用的函數(shù)是個很好的習(xí)慣。富盛Sbo程序開發(fā)框架就是這樣完成的。 public Boolean OpenChooseDataForm(string strTitle, string strFatherId, string strQuerySQL, string strFatherFields, string strMtxId, int nMtxRow)
??????? {
??????????? Boolean bRet = false;
??????????? try
??????????? {
??????????????? fsSboChooseDataBase frm = new fsSboChooseDataBase(this);
??????????????? frm.ChooseDataSQL = strQuerySQL;
??????????????? frm.FatherFields = strFatherFields;
??????????????? frm.FatherFormId = strFatherId;
??????????????? if (strMtxId.Length > 0 && nMtxRow > 0)
??????????????? {
??????????????????? frm.FatherMatrixId = strMtxId;
??????????????????? frm.FatherMatrixRow = nMtxRow;
??????????????? }
???????????????
??????????????? bRet = ShowForm(frm, "ChooseData" + strFatherId, strTitle);
??????????? }
??????????? catch (Exception ex)
??????????? {
??????????????? ShowMsg("錯誤:" + ex.Message);
??????????? } return bRet;
??????? } 這里的fsSboChooseDataBase就是上述我們討論的通用數(shù)據(jù)選擇業(yè)務(wù)實現(xiàn)類了。 4、實例 在富盛打葉復(fù)烤生產(chǎn)管理系統(tǒng)中,廣泛的使用這一通用數(shù)據(jù)選擇功能。 4.1 通過以下代碼實現(xiàn)加工協(xié)議選擇,選擇之后的信息被回填到業(yè)務(wù)選擇界面的編輯文本中。 string strSQL = "", strTitle = "", strFields = ""; strTitle = "選擇加工協(xié)議";
??????????????????? strSQL = "SELECT DocEntry as [$$DocEntry], U_DealCode 加工協(xié)議, U_DealName 協(xié)議描述, U_DealNo 檔案編號, U_WrkBatNo 生產(chǎn)批次, U_CardCode 委托方, U_CardName 委托方名稱, U_PlanSD 計劃開始, U_PlanED 計劃結(jié)束? FROM [@FSCXFWORKDEALINFO] WHERE IsNull(U_Stts,'0') in ('2','3')";
??????????????????? strFields = "DealEntry,emDealCode,emDealName,emDealNo,emBatNo,emCardCode,emCardName"; bRet = fsSbo.OpenChooseDataForm(strTitle, oForm.UniqueID, strSQL, strFields, "", -1); 實現(xiàn)的數(shù)據(jù)選擇界面如下: 選后數(shù)據(jù)回寫到以下界面 4.2 通過以下代碼實現(xiàn)加工物料選擇,選擇之后的信息被回填到業(yè)務(wù)選擇界面的Matrix中。 string strSQL = "", strTitle = "選擇投料"; string strDealEntry = fsSbo.GetValue4EditText(oForm, "DealEntry");
??????????????? if (strDealEntry.Length > 0)
??????????????? {
??????????????????????? strSQL = "SELECT U_ItemCode 物料代碼, U_ItemName 物料描述, U_BaseItem as [$$BaseItem], U_BaseCode as [$$BaseCode], U_GrdEntry as [$$GrdEntry], U_GrdCode 等級, U_FromCode as [$$FromCode], U_FromName [產(chǎn)地], U_ItemAge 年限, IsNull(U_Qty,0) - IsNull(U_Qtyed,0) [$$RemQty], U_ItemGrp [$$ItemGrp], U_WhsCode [$$WhsCode], DocEntry as [$$DocEntry], U_Qty 計劃加工, U_Qtyed 已加工, U_Notes 備注 FROM [@FSCXFWORKDEALLINE1] WHERE U_ItemGrp in (" + fsSbo.fsSboMes4CxF.ItemGroupCodeBeforePick + ") AND DocEntry=" + strDealEntry + (strItemList.Length > 0 ? " AND U_ItemCode not in (" + strItemList + ")" : "");
??????????????????? bRet = fsSbo.OpenChooseDataForm(strTitle, this, strSQL, "REQUEST");
??????????????? } 數(shù)據(jù)選擇界面如下: 選后數(shù)據(jù)回寫到以下界面: <>
轉(zhuǎn)載于:https://blog.51cto.com/foresun/94859
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的Sbo通用数据选择功能的实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你还在担任“消防队员”的角色么?
- 下一篇: ASP+MSSQL注入工具 web版 b