コード例 #1
0
        internal bool SaveChanges(FormRecordValidationResult result)//Validation da diğer Record larda bakılsın Diye.
        {
            if (result.Validated && this.mode != CrudMode.None)//Örnepğin
            {
                IEntityCommandExecute cmd;
                switch (this.mode)
                {
                    case CrudMode.Update:
                        cmd = this.card.Factory.CreateEntityCommand(EntityCommandType.Update);
                        break;
                    case CrudMode.Upsert:
                    case CrudMode.Full:
                        cmd = this.card.Factory.CreateEntityCommand(EntityCommandType.Upsert);
                        break;
                    default:
                        throw new NotSupportedException(this.mode.ToString());
                }

                Record record = result.ValidatedRecord;
                RecordTableMetaDataProvider provider = result.MetaDataProvider;

                this.Keys.SetKeyValuesToRecord(record);

                IEntityMetaData metaData = provider.CreateEntityMetaData();

                bool identityEnabled = false;
                object preExecutePkValue = null;
                PropertyMetaData pkProperty = metaData.GetPrimaryKey();
                if (null != pkProperty)
                {
                    StoreGeneratedPattern identityPattern = pkProperty.Schema.DatabaseGeneratedOption;
                    if (identityPattern == StoreGeneratedPattern.Identity || identityPattern == StoreGeneratedPattern.SequenceAuto)
                    {
                        identityEnabled = true;
                        preExecutePkValue = pkProperty.Property.GetValue(record);//Upsert de değiştirilmeyen değer tutuluyor
                    }
                }

                cmd.Execute(record, provider);//Oracle da Execute upsert de -1 dönüyor.
                if (identityEnabled && ((Int32)this.mode) > 1)//Yani Tekil PK + Identity ve mode upsert / full
                {
                    object executeCompletePkValue = pkProperty.Property.GetValue(record);//execute Sonrası değer alınıyor.
                    if (!Object.Equals(preExecutePkValue, executeCompletePkValue))// farklıysa yanı insert olup identity atandı ise.
                    {
                        DbKey parentKey = this.Keys.First();
                        if (!(parentKey.DatabaseGeneratedOption == StoreGeneratedPattern.Identity || parentKey.DatabaseGeneratedOption == StoreGeneratedPattern.SequenceAuto)) throw new InvalidOperationException("Parent Key must be Identity");
                        parentKey.Value = pkProperty.Property.GetValue(record);
                    }
                }

                return true;
            }

            return false;
        }
コード例 #2
0
        internal FormRecordValidationResult ValidateInputs()
        {
            FormRecordValidationResult ret = new FormRecordValidationResult();

            RecordTable template = this.Template;
            Record newRecord = template.NewRecord();

            RecordTableMetaDataProvider provider = new RecordTableMetaDataProvider(template);
            using (Binding binding = new Binding(newRecord, provider, this.Controls))
            {
                if (binding.ReadValues())
                {
                    ret.Validated = true;
                    ret.ValidatedRecord = newRecord;
                    ret.MetaDataProvider = provider;
                }
            }

            return ret;//if validation fails returns null.
        }