예제 #1
0
        private static void SetDefaultInsertControlValues(MetaTable table, DetailsView detailsView, IDictionary <string, object> parameterValues)
        {
            foreach (MetaColumn column in table.Columns)
            {
                string controlValue = null;

                var fkColumn = column as MetaForeignKeyColumn;
                if (fkColumn != null)
                {
                    IList <object> list = new List <object>();
                    foreach (string fkName in fkColumn.ForeignKeyNames)
                    {
                        object val;
                        if (parameterValues.TryGetValue(fkName, out val))
                        {
                            list.Add(val);
                        }
                    }
                    if (list.Count != fkColumn.ForeignKeyNames.Count)
                    {
                        continue;
                    }

                    controlValue = fkColumn.ParentTable.GetPrimaryKeyString(list);
                }
                else if (column.ColumnType == typeof(bool))
                {
                    object val;
                    if (parameterValues.TryGetValue(column.Name, out val))
                    {
                        controlValue = Convert.ToString(val);
                    }
                }

                if (controlValue == null)
                {
                    continue;
                }

                var ftuc = detailsView.FindFieldTemplate(column.Name) as FieldTemplateUserControl;
                if (ftuc == null)
                {
                    continue;
                }
                if (ftuc.DataControl is ListControl)
                {
                    var      ddl  = ftuc.DataControl as ListControl;
                    ListItem item = ddl.Items.FindByValue(controlValue);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
                else if (ftuc.DataControl is CheckBox)
                {
                    var cb = ftuc.DataControl as CheckBox;
                    cb.Checked = string.Compare(controlValue, "true", true) == 0;
                }
            }
        }