示例#1
0
 private void EnableDisableFillRanges()
 {
     if (dashboardHelper.IsColumnNumeric(sourceColumnName) && DestinationFieldType.Equals(DashboardVariableType.Text))
     {
         btnFillRanges.Enabled = true;
     }
     else
     {
         btnFillRanges.Enabled = false;
     }
 }
示例#2
0
        /// <summary>
        /// Fills the data grid view with the appropriate columns
        /// </summary>
        private void FillDataGrid()
        {
            DataTable     dt     = new DataTable("recode");
            Configuration config = dashboardHelper.Config;

            dataGridViewRecode.Columns.Clear();
            dataGridViewRecode.AllowUserToAddRows = true;

            if (dashboardHelper.IsUsingEpiProject && View.Fields.Contains(sourceColumnName))
            {
                Field sourceField = dashboardHelper.View.Fields[sourceColumnName];

                if (sourceField is NumberField || sourceField is DateTimeField || sourceField is OptionField)
                {
                    DataColumn col1 = new DataColumn(COL_FROM, typeof(string));
                    DataColumn col2 = new DataColumn(COL_TO, typeof(string));
                    dt.Columns.Add(col1);
                    dt.Columns.Add(col2);
                }
                else
                {
                    DataColumn col1 = new DataColumn(COL_FROM, typeof(string));
                    dt.Columns.Add(col1);
                }
            }
            else
            {
                if (dashboardHelper.IsColumnNumeric(sourceColumnName) || dashboardHelper.IsColumnDateTime(sourceColumnName))
                {
                    DataColumn col1 = new DataColumn(COL_FROM, typeof(string));
                    DataColumn col2 = new DataColumn(COL_TO, typeof(string));
                    dt.Columns.Add(col1);
                    dt.Columns.Add(col2);
                }
                else
                {
                    DataColumn col1 = new DataColumn(COL_FROM, typeof(string));
                    dt.Columns.Add(col1);
                }
            }

            DataColumn col3 = new DataColumn(COL_REPRESENTATION, typeof(string));

            bool isTableBasedDropDown = false;

            if (dashboardHelper.IsUsingEpiProject && View.Fields.Contains(sourceColumnName))
            {
                Field field = dashboardHelper.View.Fields[sourceColumnName];
                if (field is TableBasedDropDownField)
                {
                    isTableBasedDropDown = true;
                }
            }

            if (DestinationFieldType.Equals(DashboardVariableType.Numeric))
            {
                dt.Columns.Add(col3);
            }
            else if (DestinationFieldType.Equals(DashboardVariableType.YesNo) && !(isTableBasedDropDown))
            {
                col3.ReadOnly = true;

                dataGridViewRecode.AllowUserToAddRows = true;

                dt.Columns.Add(col3);
                if (dt.Columns.Count == 2)
                {
                    dt.Rows.Add(null, config.Settings.RepresentationOfYes);
                    dt.Rows.Add(null, config.Settings.RepresentationOfNo);
                }
                else
                {
                    dt.Rows.Add(null, null, config.Settings.RepresentationOfYes);
                    dt.Rows.Add(null, null, config.Settings.RepresentationOfNo);
                }
            }
            else
            {
                dt.Columns.Add(col3);
            }

            if (isTableBasedDropDown && dashboardHelper.IsUsingEpiProject)
            {
                Field     sourceField   = View.Fields[sourceColumnName];
                DataTable codeDataTable = ((TableBasedDropDownField)sourceField).GetSourceData();
                Dictionary <string, string> fieldValues = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

                foreach (System.Data.DataRow row in codeDataTable.Rows)
                {
                    string Key = row[((TableBasedDropDownField)sourceField).TextColumnName.Trim()].ToString();

                    if (sourceField is DDLFieldOfCommentLegal)
                    {
                        int dashLocation = Key.IndexOf('-');
                        Key = Key.Substring(0, dashLocation);
                    }

                    if (!fieldValues.ContainsKey(Key))
                    {
                        fieldValues.Add(Key, Key);
                    }
                }

                int i = 0;
                foreach (KeyValuePair <string, string> kvp in fieldValues)
                {
                    if (kvp.Key.Length > 0)
                    {
                        if (DestinationFieldType.Equals(DashboardVariableType.YesNo))
                        {
                            if (i % 2 == 1)
                            {
                                dt.Rows.Add(kvp.Key, config.Settings.RepresentationOfYes);
                            }
                            else
                            {
                                dt.Rows.Add(kvp.Key, config.Settings.RepresentationOfNo);
                            }
                            i++;
                        }
                        else
                        {
                            dt.Rows.Add(kvp.Key, null);
                        }
                    }
                }
            }
            else if (dt.Rows.Count <= 0)
            {
                if (dt.Columns.Count == 2)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        dt.Rows.Add(null, null);
                    }
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        dt.Rows.Add(null, null, null);
                    }
                }
            }

            dataGridViewRecode.DataSource = dt;
        }