软件中,我们经常要进行一些输入数据的合法性验证,下例给出了在Sbo中如何判断在matrix数据控件中,是否存在具有相同的数据特点的数据行?
 
显然,这是一个非常有用的函数,因为在数据行中,除了关键字之外(Primary Key)之外,可能还是需要其他的唯一数据行,而这些数据唯一性使用Unique Index又存在一些业务上的约束或者要求。那么这个函数就非常有用了。
 
        public Boolean IsExistsSameLine4Matrix(SAPbouiCOM.Matrix mtx, string[] strColumns, string strFocusId, string strShowMsg)
        {
            for (int j = 1; j <= mtx.RowCount; j++)
            {
                string[] strValues = new string[strColumns.Length];
                for (int m = 0; m < strValues.Length; m++) strValues[m] = GetMtxEditValue(mtx, strColumns[m], j);
                for (int k = j + 1; k <= mtx.RowCount; k++)
                {
                    Boolean bExistSameLine = true;
                    for (int m = 0; m < strValues.Length; m++)
                        if (strValues[m] != GetMtxEditValue(mtx, strColumns[m], k))
                        {
                            bExistSameLine = false;
                            break;
                        }
                    if (bExistSameLine)
                    {
                        string strMsg = "";
                        for (int m = 0; m < strValues.Length; m++) strMsg += " - " + strValues[m];
                        if (IsNull(strShowMsg, "").Length < 1) strShowMsg = "信息:重复的数据行";
                        ShowMsg(strShowMsg + strMsg);
                        if (IsNull(strFocusId, "").Length > 0) SetMtxFocus(mtx, strFocusId, j);
                        return bExistSameLine;
                    }
                }
            }
            return false;
        }
 
此函数在VS 2005/2008+Sbo 2005B/2007B中调试通过。