Ejemplo n.º 1
0
        public static DataRow GetDefaultRowProxy(string tblname, SqlConnection conn)
        {
            DataRow    row   = null;
            TableCache cache = null;
            DataTable  tbl   = null;

            if (mDefRowTables.ContainsKey(tblname))
            {
                cache = mDefRowTables[tblname];
                tbl   = cache.Table;
            }

            if (tbl == null)
            {
                tbl = GetDataTableTopRowProxy(tblname, conn);
                bool bRet = false;
                if (tbl.Rows.Count > 0)
                {
                    row  = tbl.Rows[0];
                    bRet = true;
                    foreach (DataColumn col in tbl.PrimaryKey)
                    {
                        if (row[col].ToString() != "0")
                        {
                            bRet = false;
                            break;
                        }
                    }
                    if (!bRet)
                    {
                        row = null;
                    }
                }
                cache = new TableCache(tbl, bRet);
                mDefRowTables[tblname] = cache;
            }
            else
            {
                if (cache.HasDefVal)
                {
                    row = tbl.Rows[0];
                }
                else
                {
                    row = null;
                }
            }

            return(row);
        }
Ejemplo n.º 2
0
        public static DataRow GetDefaultRowProxy(string tblname, SqlConnection conn)
        {
            DataRow row = null;
            TableCache cache = null;
            DataTable tbl = null;
            if (mDefRowTables.ContainsKey(tblname))
            {
                cache = mDefRowTables[tblname];
                tbl = cache.Table;
            }

            if (tbl == null)
            {
                tbl = GetDataTableTopRowProxy(tblname, conn);
                bool bRet = false;
                if (tbl.Rows.Count > 0)
                {
                    row = tbl.Rows[0];
                    bRet = true;
                    foreach (DataColumn col in tbl.PrimaryKey)
                    {
                        if (row[col].ToString() != "0")
                        {
                            bRet = false;
                            break;
                        }
                    }
                    if (!bRet)
                    {
                        row = null;
                    }
                }
                cache = new TableCache(tbl, bRet);
                mDefRowTables[tblname] = cache;
            }
            else
            {
                if (cache.HasDefVal)
                {
                    row = tbl.Rows[0];
                }
                else
                {
                    row = null;
                }
            }

            return row;
        }