Exemplo n.º 1
0
        public RecordIds(DbBase db, HluDataSet hluDataset,
                         TableAdapterManager hluTableAdapterMgr, ViewModelWindowMain.GeometryTypes gisLayerType)
        {
            if (db == null)
            {
                throw new ArgumentException("db");
            }
            if (hluDataset == null)
            {
                throw new ArgumentException("hluDataset");
            }
            if (hluTableAdapterMgr == null)
            {
                throw new ArgumentException("hluTableAdapterMgr");
            }

            _db                 = db;
            _hluDataset         = hluDataset;
            _hluTableAdapterMgr = hluTableAdapterMgr;
            _gisLayerType       = gisLayerType;
            if (_hluDataset.lut_last_incid.IsInitialized && _hluDataset.lut_last_incid.Count == 0)
            {
                if (_hluTableAdapterMgr.lut_last_incidTableAdapter == null)
                {
                    _hluTableAdapterMgr.lut_last_incidTableAdapter =
                        new HluTableAdapter <HluDataSet.lut_last_incidDataTable, HluDataSet.lut_last_incidRow>(_db);
                }
                _hluTableAdapterMgr.Fill(_hluDataset,
                                         new Type[] { typeof(HluDataSet.lut_last_incidDataTable) }, false);
            }
            _incidCurrentNumber = CurrentMaxIncidNumber(false);
            InitializeIncidChildRecordIds();
        }
Exemplo n.º 2
0
        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            TableAdapterManager tt    = new TableAdapterManager();
            DataTable           table = new DataTable();

            tt.Fill(table, cbDiemDi.SelectedValue.ToString(), cbDiemDen.SelectedValue.ToString(), dtpNgayDi.Value, cbLoaiVe.Text);
            dataGridView1.DataSource = table;
        }
Exemplo n.º 3
0
        private int CurrentMaxIncidNumber(bool increment)
        {
            try
            {
                int maxIncidNumber = 0;

                // check in-memory incid table
                if (_hluDataset.incid.Count > 0)
                {
                    _hluDataset.incid.Max(r => IncidNumber(r.incid));
                }

                // check lut_last_incid in DB
                _hluTableAdapterMgr.Fill(_hluDataset, typeof(HluDataSet.lut_last_incidDataTable), true);
                HluDataSet.lut_last_incidRow lastIncidRow = null;
                if (_hluDataset.lut_last_incid.Count > 0)
                {
                    lastIncidRow =
                        _hluDataset.lut_last_incid.ElementAt(_hluDataset.lut_last_incid.Count - 1);
                    if (lastIncidRow.last_incid > maxIncidNumber)
                    {
                        maxIncidNumber = lastIncidRow.last_incid;
                    }
                }

                // check DB incid table
                string sql = String.Format("SELECT MAX({0}) FROM {1}",
                                           _db.QuoteIdentifier(_hluDataset.incid.incidColumn.ColumnName),
                                           _db.QualifyTableName(_hluDataset.incid.TableName));
                object result = _db.ExecuteScalar(sql, _db.Connection.ConnectionTimeout, CommandType.Text);
                int    dbMax;
                if ((result != DBNull.Value) && (result != null) &&
                    ((dbMax = IncidNumber(result.ToString())) > maxIncidNumber))
                {
                    maxIncidNumber = dbMax;
                }

                if (increment)
                {
                    // increment the greatest value found and save to lut_last_incid
                    maxIncidNumber++;
                    if (lastIncidRow != null)
                    {
                        lastIncidRow.last_incid = maxIncidNumber;
                    }
                    else
                    {
                        lastIncidRow = _hluDataset.lut_last_incid.Addlut_last_incidRow(maxIncidNumber);
                    }
                    _hluTableAdapterMgr.lut_last_incidTableAdapter.Update(lastIncidRow);
                }

                return(maxIncidNumber);
            }
            catch { return(-1); }
        }