コード例 #1
0
        private void CreateRow(IField field)
        {
            if (CurrentMode == Mode.ReadOnly || !(field is CardListRelationField))
            {
                if (field is CardListRelationField)
                {
                    var listRelation = field as CardListRelationField;

                    if (listRelation.Card.IsAncestor && listRelation.Entity.AncestorID == Convert.ToInt32(listRelation.Card.Entity.ID))
                    {
                        return;
                    }
                }

                if (field is CardRelationField)
                {
                    var f = field as CardRelationField;

                    if (f.SystemName == "Person_erp_Executive")
                    {
                    }


                    Card currentCard;
                    Cards.TryGetValue(Convert.ToInt32(f.Card.Entity.ID), out currentCard);

                    if (currentCard.EntityInstance == null)
                    {
                        DataBaseReader.FillEntityInstance(currentCard, "");
                    }

                    var constraint = currentCard.EntityInstance.Constraints.First(c => c.ConstraintName == field.SystemName);

                    if (constraint.IsIdentified && currentCard.Entity.AncestorID != -1)
                    {
                        return;
                    }
                }



                var row = new TableRow();

                var headerCell = new TableHeaderCell();

                headerCell.Controls.Add(new Literal {
                    Text = field.Name
                });


                if (CurrentMode != Mode.ReadOnly && !field.IsNullable)
                {
                    headerCell.Controls.Add(new Literal {
                        Text = "<span style='color:red'>*</span>"
                    });
                }


                row.Cells.Add(headerCell);

                var dataCell = new TableCell();

                row.Cells.Add(dataCell);

                FillDataCell(field, dataCell);

                Table.Rows.Add(row);
            }
        }
コード例 #2
0
        private void FillDataCellWhenEditMode(IField field, TableCell cell)
        {
            Card currentCard;

            if (field is CardRelationField)
            {
                var f = field as CardRelationField;

                var label = new Label {
                    Text = f.Value
                };

                cell.Controls.Add(label);

                Cards.TryGetValue(Convert.ToInt32(f.Card.Entity.ID), out currentCard);

                if (currentCard.EntityInstance == null)
                {
                    DataBaseReader.FillEntityInstance(currentCard, "");
                }

                Constraint constraint = currentCard.EntityInstance.Constraints.First(c => c.ConstraintName == field.SystemName);


                //если режим создания объекта
                if (string.IsNullOrEmpty(currentCard.EntityInstance.EntityInstanceID))
                {
                    var RelationEditedButton = CreateRelationEditedButton(f);
                    cell.Controls.Add(RelationEditedButton);

                    if (constraint.IsNullable)
                    {
                        var RelationClearedButton = CreateRelationClearedButton(f);
                        cell.Controls.Add(RelationClearedButton);
                    }
                }
                else if (!constraint.IsIdentified)
                {
                    var RelationEditedButton = CreateRelationEditedButton(f);
                    cell.Controls.Add(RelationEditedButton);

                    if (constraint.IsNullable)
                    {
                        var RelationClearedButton = CreateRelationClearedButton(f);
                        cell.Controls.Add(RelationClearedButton);
                    }
                }
            }
            else if (field is CardSelfField)
            {
                WebControl control = null;

                var f = field as CardSelfField;

                Cards.TryGetValue(Convert.ToInt32(f.Card.Entity.ID), out currentCard);

                if (f.IsReadOnly(CurrentMode))
                {
                    control = new Label {
                        Text = f.Value.ToString()
                    }
                }
                ;
                else
                {
                    switch (f.TypeCode)
                    {
                    case CardSelfField.Type.Object:
                        control = new TextBox
                        {
                            TextMode = TextBoxMode.MultiLine,
                            Text     = f.Value.ToString()
                        };
                        break;

                    case CardSelfField.Type.Boolean:
                        if (f.Value == "")
                        {
                            f.Value = false;         // очень явно, для случая очистки всех полей при создании
                        }
                        control = new CheckBox {
                            Checked = (bool)f.Value
                        };
                        break;

                    case CardSelfField.Type.FileName:
                        control = new FileUpload();

                        if (f.ContainsNonEmptyValue())
                        {
                            cell.Controls.Add(new Literal {
                                Text = (f.Value as File).FileName
                            });
                        }
                        break;

                    case CardSelfField.Type.Float:
                    case CardSelfField.Type.ShortString:
                    case CardSelfField.Type.Numeric:
                        control = new TextBox {
                            Text = f.Value.ToString()
                        };
                        break;

                    case CardSelfField.Type.DateTime:
                        var textBox = new TextBox();
                        control = textBox;

                        if (f.ContainsNonEmptyValue())
                        {
                            var date = DateTime.Parse(f.Value.ToString());

                            textBox.Text = date.ToString("yyyy-MM-dd");
                        }
                        break;

                    default:
                        throw new NotImplementedException("Не реализована часть для варианта " + f.TypeCode.ToString());
                    }
                }
                if (control != null)
                {
                    if (control is TextBox)
                    {
                        var textBox = control as TextBox;

                        var entityType = Schema.Entities.First(e => e.ID.ToString() == currentCard.Entity.ID.ToString());
                        var attribute  = entityType.Attributes.Single(a => a.ID.ToString() == f.ID);

                        textBox.ApplyType(attribute.Type);
                    }

                    cell.Controls.Add(control);
                    WebControls.Add(field.SystemName, control);
                }
            }
        }