private void cmbStorage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            lblError.Content = null;
            if (dbIf != null)
                dbIf.Dispose();
            dbIf = null;
            dbView = null;

            lblDataCount.Content = null;
            grdDatasetFields.ItemsSource = null;

            datasetConfig = cmbStorage.SelectedItem as DatasetConfig;
            dbIf = StorageHelper.GetStorage(datasetConfig, null);
            dbIf.Connect_To_Database(datasetConfig.Storage);
            dbView = dbIf as IDBViewable;
            dbViewSQL = dbIf as IDBViewableSQL;

            txtSQL.IsEnabled = false;
            cmdSQL.IsEnabled = false;
            txtSearch.IsEnabled = false;
            cmdSearch.IsEnabled = false;

            try
            {
                if (dbView != null)
                {
                    txtSQL.Text = "";
                    CurrentNumber = 0;
                    DataTable tbl = dbView.ReadData(datasetConfig, null, CurrentNumber,  1000, null, null);
                    if (tbl != null)
                        grdDatasetFields.ItemsSource = tbl.DefaultView;
                    lblDataCount.Content = dbView.ReadCount(datasetConfig);
                }

                if (!string.IsNullOrEmpty(datasetConfig.DateTimeDatabaseField))
                {
                    /*dbFieldNames = datasetConfig.DateTimeDatabaseField;
                    foreach (var datasetConfigRow in datasetConfig.DatasetConfigRows)
                    {
                        if (datasetConfigRow.DatabaseField.ToLower().Trim() != datasetConfig.DateTimeDatabaseField.ToLower().Trim())
                            dbFieldNames += ", " + datasetConfigRow.DatabaseField;
                    }*/
                    dbFieldNames = datasetConfig.DateTimeDatabaseField + ",*";
                }

                if (dbViewSQL != null)
                {
                    txtSQL.Text = "SELECT " + dbFieldNames + " FROM " + datasetConfig.Name + " ORDER BY id DESC LIMIT " + 1000.ToString();
                    txtSQL.IsEnabled = true;
                    cmdSQL.IsEnabled = true;
                    txtSearch.IsEnabled = true;
                    cmdSearch.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                lblError.Content = ex.Message;
            }
        }
示例#2
0
        private void cmbStorage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            lblError.Content = null;
            if (dbIf != null)
            {
                dbIf.Dispose();
            }
            dbIf   = null;
            dbView = null;

            lblDataCount.Content         = null;
            grdDatasetFields.ItemsSource = null;

            datasetConfig = cmbStorage.SelectedItem as DatasetConfig;
            dbIf          = StorageHelper.GetStorage(datasetConfig, null);
            dbIf.Connect_To_Database(datasetConfig.Storage);
            dbView    = dbIf as IDBViewable;
            dbViewSQL = dbIf as IDBViewableSQL;

            txtSQL.IsEnabled    = false;
            cmdSQL.IsEnabled    = false;
            txtSearch.IsEnabled = false;
            cmdSearch.IsEnabled = false;

            try
            {
                if (dbView != null)
                {
                    txtSQL.Text   = "";
                    CurrentNumber = 0;
                    DataTable tbl = dbView.ReadData(datasetConfig, null, CurrentNumber, 1000, null, null);
                    if (tbl != null)
                    {
                        grdDatasetFields.ItemsSource = tbl.DefaultView;
                    }
                    lblDataCount.Content = dbView.ReadCount(datasetConfig);
                }

                if (!string.IsNullOrEmpty(datasetConfig.DateTimeDatabaseField))
                {
                    /*dbFieldNames = datasetConfig.DateTimeDatabaseField;
                     * foreach (var datasetConfigRow in datasetConfig.DatasetConfigRows)
                     * {
                     *  if (datasetConfigRow.DatabaseField.ToLower().Trim() != datasetConfig.DateTimeDatabaseField.ToLower().Trim())
                     *      dbFieldNames += ", " + datasetConfigRow.DatabaseField;
                     * }*/
                    dbFieldNames = datasetConfig.DateTimeDatabaseField + ",*";
                }

                if (dbViewSQL != null)
                {
                    txtSQL.Text         = "SELECT " + dbFieldNames + " FROM " + datasetConfig.Name + " ORDER BY id DESC LIMIT " + 1000.ToString();
                    txtSQL.IsEnabled    = true;
                    cmdSQL.IsEnabled    = true;
                    txtSearch.IsEnabled = true;
                    cmdSearch.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                lblError.Content = ex.Message;
            }
        }