Пример #1
0
        public virtual bool IsCellReadOnly(DataGridViewCell cell)
        {
            if (spectra[0].Container.ParentProject.IsBusy)
            {
                return(true);
            }
            if (cell is DataGridViewParameterCell)
            {
                IParameter parameter = ((DataGridViewParameterCell)cell).Parameter;
                //if (parameter.Expression != null)
                //    return true;
                //IGroup group = container.Spectra[cell.RowIndex - 1].Parameters[groupDefinition.name];
                if (!(cell.OwningRow is DataGridViewSpectrumRow))
                {
                    return(true);
                }
                IGroup group = ((DataGridViewSpectrumRow)cell.OwningRow).Spectrum.Parameters[groupDefinition.name];
                if ((parameter.Definition.Properties & ParameterProperties.Readonly) == ParameterProperties.Readonly)
                {
                    return(true);
                }
                //if intensity of first component then readonly
                if ((parameter.Definition.Properties & ParameterProperties.ComponentIntensity) > 0 &&
                    ((parameter.Status & ParameterStatus.Free) == ParameterStatus.Free) &&
                    (parameter.Parent == group.Components[0] || (spectra[0].Container.ParentProject.CalculatedValues && groupDefinition.name != "prompt")))
                {
                    return(true);
                }
                if ((parameter.HasReferenceValue && !(parameter.BindingParameter && cell.RowIndex == 1)) ||
                    (cell.RowIndex != 1 && spectra[0].Container.ParentProject.CalculatedValues && ((parameter.Status & (ParameterStatus.Local | ParameterStatus.Free)) == (ParameterStatus.Local | ParameterStatus.Free))))
                {
                    return(true);
                }
            }
            else if (cell is DataGridViewCustomValueCell)
            {
                return(true);
            }
            else if (cell is DataGridViewComboBoxCell)
            {
                DataGridParameterView grid = (DataGridParameterView)cell.DataGridView;
                int compId = (int)Math.Floor((double)(cell.ColumnIndex - grid.FixedCols) / groupDefinition.parameters.Length);
                int parId  = (cell.ColumnIndex - grid.FixedCols) % groupDefinition.parameters.Length;
                if (grid[cell.ColumnIndex, cell.RowIndex + 1] is DataGridViewParameterCell)
                {
                    return(compId == 0 && parId == 0 && ((DataGridViewParameterCell)grid[cell.ColumnIndex, cell.RowIndex + 1]).Parameter.Definition.Name.ToLower().Contains("int"));
                }


                //if (compId == 0 && parId == 0 && spectra[0].Container.Spectra[0].Parameters[groupDefinition.name].Components[compId][parId].Definition.Name == "int")
                //    return true;
            }
            else if (cell is DataGridViewTextBoxCell)
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
        public virtual void CellFormatting(Object sender, DataGridViewCellFormattingEventArgs e)
        {
            DataGridParameterView grid = (DataGridParameterView)sender;

            if (e.Value != null)
            {
                if (grid[e.ColumnIndex, e.RowIndex] is DataGridViewParameterCell)
                {
                    IParameter parameter = ((DataGridViewParameterCell)grid[e.ColumnIndex, e.RowIndex]).Parameter;
                    if ((parameter.HasReferenceValue && !(parameter.BindingParameter && e.RowIndex == 1)) || (e.RowIndex != 1 && spectra[0].Container.ParentProject.CalculatedValues &&
                                                                                                              ((parameter.Status & (ParameterStatus.Local | ParameterStatus.Free)) == (ParameterStatus.Local | ParameterStatus.Free))) ||
                        (e.RowIndex == 1 && (parameter.Definition.Properties & ParameterProperties.ComponentIntensity) > 0 && spectra[0].Container.ParentProject.CalculatedValues && (parameter.Status & ParameterStatus.Free) == ParameterStatus.Free))
                    {
                        e.Value = "-";
                        grid[e.ColumnIndex, e.RowIndex].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    }
                    else
                    {
                        DataGridViewParameterCell cell = (DataGridViewParameterCell)grid[e.ColumnIndex, e.RowIndex];
                        if (cell.UserError > (double)cell.Value || cell.UserError == 0 || double.IsNaN(cell.UserError) || double.IsInfinity(cell.UserError))
                        {
                            e.Value = ((double)cell.Value).ToString("G06", numberFormat);
                        }
                        else if (cell.UserError > 0 && cell.UserError < 1)
                        {
                            e.Value = ((double)cell.Value).ToString(String.Format("F{0}", Math.Ceiling(Math.Abs(Math.Log10(cell.UserError))), numberFormat));
                        }
                        else   //if (cell.UserError > 1) {
                        {
                            e.Value = ((double)cell.Value).ToString("F0", numberFormat);
                        }
                        //}
                        grid[e.ColumnIndex, e.RowIndex].Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
                    }
                }
                else if (grid[e.ColumnIndex, e.RowIndex] is DataGridViewCustomValueCell)
                {
                    //e.Value = e.Value.ToString("F3");
                    grid[e.ColumnIndex, e.RowIndex].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                }
                else
                {
                    if ((e.RowIndex == 0) && (e.ColumnIndex >= grid.FixedCols))
                    {
                        if (e.Value is CellParameterStatus)
                        {
                            e.CellStyle.ForeColor = ((CellParameterStatus)e.Value).ValueColor;
                        }
                    }
                    else
                    {
                        e.Value = e.Value.ToString();
                    }
                }
                e.FormattingApplied = true;
            }
            if ((grid[e.ColumnIndex, e.RowIndex].ReadOnly = IsCellReadOnly(grid[e.ColumnIndex, e.RowIndex])) && e.ColumnIndex >= grid.FixedCols)
            {
                e.CellStyle.ForeColor = Color.Black;
            }
        }