Esempio n. 1
0
        /// <summary>
        /// Add selected shared parameters to cart DataTable.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (gridParams.SelectedItems.Count > 0)
            {
                foreach (DataRowView dr in gridParams.SelectedItems)
                {
                    //DataRow selectedParam = (System.Data.DataRow)gridParams.SelectedItems[i];
                    if (dr != null)
                    {
                        ImportProcess.dtCart.Rows.Add(dr.Row.ItemArray);
                    }

                    // Update status text
                    if (gridParams.SelectedItems.Count == 1)
                    {
                        UpdateStatusText("Added (1) parameter to list of parameters to be added.");
                    }
                    if (gridParams.SelectedItems.Count > 1)
                    {
                        UpdateStatusText("Added (" + gridParams.SelectedItems.Count.ToString() + ") parameters to list of parameters to be added.");
                    }
                }
            }

            // Remove duplicate entries
            ImportProcess.dtCart = ImportProcess.RemoveDuplicateRows(ImportProcess.dtCart, "name");

            // Refresh DataGrid
            gridCart.Items.Refresh();
        }
Esempio n. 2
0
        /// <summary>
        /// Refreshes all data including DataTables, DataViews, DataContext, etc.
        /// </summary>
        public void RefreshData()
        {
            // Convert Json to list
            LocalFiles.JsonToList();

            // Convert list to DataTable
            ImportProcess.dtParams = SharedParameter.ToDataTable(LocalFiles.sharedParams);

            // Creates new view object of DataTable for customizing columns
            DataView view = new DataView(ImportProcess.dtParams);

            // Bind all parameter properties to the DataGrid
            gridParams.DataContext = ImportProcess.dtParams.DefaultView;

            // Create DataTable for cart to add parameters to and display in grid
            ImportProcess.dtCart = SharedParameter.ToDataTable(LocalFiles.sharedParams);
            // Clear the cart DataTable - we only add DataContext to create identical columns. Is there a better way?
            ImportProcess.dtCart.Clear();
            gridCart.DataContext = ImportProcess.dtCart.DefaultView;

            ImportProcess.blv = ImportProcess.dtParams.DefaultView;

            // Set the BindingListView to show approved parameters by default
            ImportProcess.blv.Filter = "state = 'Approved'";

            // Populate combobox with DataType options for filtering
            // Create a view of distinct datatypes
            DataTable dtParamsDistinct = view.ToTable(true, "datatype");

            dtParamsDistinct.DefaultView.Sort = "datatype asc";
            comboDataType.ItemsSource         = dtParamsDistinct.DefaultView;

            // Populate Group combobox with parameter groups
            DataTable dtParamGroups = view.ToTable(true, "group");

            dtParamGroups.DefaultView.Sort = "group asc";
            comboParamGroup.ItemsSource    = dtParamGroups.DefaultView;

            // Populate combobox with parameter sets
            List <string> _newSets    = new List <string>();
            DataTable     dtParamSets = view.ToTable(true, "parameter_sets");

            // Split comma separated values for parameters with multiple tags
            foreach (DataRow _dr in dtParamSets.Rows)
            {
                if (_dr[0].ToString().Contains(", "))
                {
                    // Split multiple values
                    foreach (string s in _dr[0].ToString().Split(','))
                    {
                        _newSets.Add(s);
                    }
                }
            }

            // Remove rows that have multiple values
            for (int i = dtParamSets.Rows.Count - 1; i >= 0; i--)
            {
                DataRow dr = dtParamSets.Rows[i];
                if (dr[0].ToString().Contains(", "))
                {
                    dr.Delete();
                }
            }
            dtParamSets.AcceptChanges();

            for (int i = 0; i < _newSets.Count(); i++)
            {
                // Remove extra space from split
                if (_newSets[i].StartsWith(" "))
                {
                    _newSets[i] = _newSets[i].Substring(1);
                }

                // Add parameter sets from list as data rows
                DataRow _newRow = dtParamSets.NewRow();
                _newRow[0] = _newSets[i];
                dtParamSets.Rows.Add(_newRow);
            }

            // Remove duplicates
            ImportProcess.RemoveDuplicateRows(dtParamSets, 0);
            dtParamSets.DefaultView.Sort  = "parameter_sets asc";
            comboParameterSet.ItemsSource = dtParamSets.DefaultView;
        }