コード例 #1
0
ファイル: DataSource.cs プロジェクト: foxbill/xbase-2018.01
        public List <ListDataRow> sub(string table, Dictionary <string, string> pk)
        {
            SubTableSchema     subSchema = DataSourceComm.getSubTableSchema(table, _schema);
            List <ListDataRow> rows      = getSubTableRows(pk, subSchema);

            return(rows);
        }
コード例 #2
0
ファイル: DataSource.cs プロジェクト: foxbill/xbase-2018.01
        private List <ListDataRow> getSubTableRows(Dictionary <string, string> pks, SubTableSchema subSchema)
        {
            DatabaseAdmin dba   = DatabaseAdmin.getInstance();
            DataSource    subDs = new DataSource(subSchema.Name);

            DataSourceSchema dss = subDs.getSchema();

            if (dss.SelectCommand.CommandType != CommandType.TableDirect)
            {
                throw new XException(string.Format(Lang.SubTableSelCommandTypeOnlyIsTable, subSchema.Name));
            }

            StringBuilder sb = new StringBuilder("select * from ");

            sb.Append(dss.SelectCommand.CommandText);
            sb.Append(" ");
            sb.Append(" where ");
            Hashtable ps = new Hashtable();

            for (int i = 0; i < subSchema.Fks.Count; i++)
            {
                string fk = subSchema.Fks[i];
                string pk = _schema.PrimaryKeys[i];
                sb.Append(fk);
                sb.Append("=@");
                sb.Append(pk);
                sb.Append(" and ");
                ps.Add("@" + pk, pks[pk].ToString());
            }
            sb.Remove(sb.Length - 5, 5);
            DbCommand cmd = dba.getSqlStringCommand(sb.ToString());

            foreach (string key in ps.Keys)
            {
                dba.addInParameter(cmd, key, DbType.String, ps[key]);
            }
            DataTable tb = dba.executeTable(cmd);

            List <ListDataRow> rows = new List <ListDataRow>();

            foreach (DataRow row in tb.Rows)
            {
                rows.Add(DataSourceComm.readRow(tb, dss, row));
            }
            return(rows);
        }
コード例 #3
0
ファイル: DataSource.cs プロジェクト: foxbill/xbase-2018.01
        private void updateSubTables(ListDataRow row, List <SubTable> subTables)
        {
            if (subTables == null || subTables.Count < 1)
            {
                return;
            }
            for (int c = 0; c < subTables.Count; c++)
            {
                string           subTable = subTables[c].Name;
                DataSourceSchema ds       = DataSourceSchemaContainer.Instance().GetItem(subTable);
                if (ds.SelectCommand.CommandType != CommandType.TableDirect)
                {
                    throw new XException(string.Format(Lang.SubTableSelCommandTypeOnlyIsTable, subTable));
                }

                SubTableSchema sds = DataSourceComm.getSubTableSchema(subTable, _schema);
                Dictionary <string, string> parametes = new Dictionary <string, string>();


                for (int i = 0; i < sds.Fks.Count; i++)
                {
                    string fk = sds.Fks[i];
                    parametes.Add("@" + fk, row[_schema.PrimaryKeys[i]]);
                }


                DsAdapter dsa = new DsAdapterCustomer(ds);

                List <ListDataRow> subRows = subTables[c].Rows;
                for (int i = 0; i < subRows.Count; i++)
                {
                    ListDataRow subRow = subRows[i];
                    if (DataSourceComm.isNewRow(subRow))
                    {
                        dsa.insert(subRow, parametes);
                    }
                    else
                    {
                        dsa.update(subRow, parametes);
                    }
                }
            }
        }