예제 #1
0
        public void InstanceDeserializeWithData()
        {
            DEEntityInstanceBase sourceInstance = MockData.CreateEntityInstance();

            string json = JSONSerializerExecute.Serialize(sourceInstance);

            DEEntityInstanceBase deserializedInstance = JSONSerializerExecute.Deserialize <DEEntityInstanceBase>(json);

            foreach (var sourceField in sourceInstance.Fields)
            {
                EntityFieldValue deserializedField = deserializedInstance.Fields.Where(p => p.Definition.Name == sourceField.Definition.Name).FirstOrDefault();

                Assert.IsNotNull(deserializedField);

                if (sourceField.Definition.FieldType == FieldTypeEnum.Collection)
                {
                    DEEntityInstanceBaseCollection sourceChildren       = sourceField.GetRealValue() as DEEntityInstanceBaseCollection;
                    DEEntityInstanceBaseCollection deserializedChildren = deserializedField.GetRealValue() as DEEntityInstanceBaseCollection;

                    foreach (var sourceChild in sourceChildren)
                    {
                        var deserializedChild = deserializedChildren[sourceChild.ID];

                        Assert.IsNotNull(deserializedChild);
                    }
                }
                else
                {
                    Assert.AreEqual(sourceField.StringValue, deserializedField.StringValue);
                }
            }
        }
        /// <summary>
        /// 检查数据的状态
        /// </summary>
        /// <param name="objsToCheck"></param>
        protected void CheckObjectStatus(params DEEntityInstanceBase[] objsToCheck)
        {
            List <DEEntityInstanceBase> normalizedObjsToCheck = new List <DEEntityInstanceBase>();

            InSqlClauseBuilder idBuilder = new InSqlClauseBuilder("ID");

            normalizedObjsToCheck.ForEach(o => idBuilder.AppendItem(o.ID));

            if (idBuilder.IsEmpty == false)
            {
                DEEntityInstanceBaseCollection originalDataList = DEInstanceAdapter.Instance.Load(idBuilder);

                string opName = EnumItemDescriptionAttribute.GetDescription(this.OperationType);

                foreach (DEEntityInstanceBase objToCheck in normalizedObjsToCheck)
                {
                    if (originalDataList.ContainsKey(objToCheck.ID) == false)
                    {
                        throw new DEStatusCheckException(string.Format("ID为\"{0}\"的对象不存在,不能执行{1}操作", objToCheck.ID, opName));
                    }

                    DEEntityInstanceBase originalData = originalDataList[objToCheck.ID];

                    if (originalData.Status != SchemaObjectStatus.Normal)
                    {
                        throw new DEStatusCheckException(string.Format("ID为\"{0}\"动态实体对象状态不正常,不能执行{1}操作", objToCheck.ID, opName));
                    }
                }
            }
        }
예제 #3
0
        //public

        public bool Exist(string id)
        {
            id.NullCheck("id");

            InSqlClauseBuilder inBuilder = new InSqlClauseBuilder("ID");

            inBuilder.AppendItem(id);

            DEEntityInstanceBaseCollection objs = Load(inBuilder);

            return(objs.Any());
        }
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="type"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            //反序列化
            EntityFieldValue data      = new EntityFieldValue();
            string           codeName  = dictionary.GetValue("CodeName", string.Empty);
            string           fieldName = dictionary.GetValue("FieldName", string.Empty);
            //todo:这需要做时间穿梭测试

            DynamicEntity entity = null;

            entity = DEDynamicEntityAdapter.Instance.LoadByCodeName(codeName) as DynamicEntity;
            entity.NullCheck("反序列化字段是找不到字段所对应的实体");

            var field = entity.Fields.FirstOrDefault(p => p.Name.Equals(fieldName));

            field.NullCheck(string.Format("EntityFieldValue反序列化出错,不能找到名称为{0}的对象!", fieldName));

            data.Definition = field;
            object stringValue = string.Empty;

            dictionary.TryGetValue("StringValue", out stringValue);
            if (data.Definition.FieldType == Enums.FieldTypeEnum.Collection)
            {
                if (stringValue != null && !string.IsNullOrEmpty(stringValue.ToString().Trim()))
                {
                    var values = JSONSerializerExecute.Deserialize <List <DEEntityInstanceBase> >(dictionary.GetValue("StringValue", new ArrayList())) ?? new List <DEEntityInstanceBase>();

                    DEEntityInstanceBaseCollection intances = new DEEntityInstanceBaseCollection();
                    foreach (var instanceBase in values)
                    {
                        if (string.IsNullOrEmpty(instanceBase.ID))
                        {
                            instanceBase.ID = Guid.NewGuid().ToString();
                        }
                        intances.Add(instanceBase);
                    }
                    data.StringValue = intances.ToString();
                }
            }
            else
            {
                data.StringValue = dictionary.GetValue("StringValue", Convert.ToString(stringValue));
            }


            return(data);
        }
예제 #5
0
        /// <summary>
        /// 根据ID和时间载入对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns><see cref="DESchemaObjectBase"/>的派生类型的实例</returns>
        public DEEntityInstanceBase Load(string id)
        {
            id.NullCheck("id");

            InSqlClauseBuilder inBuilder = new InSqlClauseBuilder("ID");

            inBuilder.AppendItem(id);

            DEEntityInstanceBaseCollection objs = Load(inBuilder);

            if (!objs.Any())
            {
                throw new Exception(string.Format("不能找到编码为{0}的实例", id));
            }

            return(objs.Single());
        }
예제 #6
0
        /// <summary>
        /// 创建一个主表加子表的实体定义的实例化数据
        /// </summary>
        /// <returns></returns>
        public static DEEntityInstanceBase CreateEntityInstance()
        {
            //创建Mock实体定义
            DynamicEntity entity = CreateEntityWithReferenceEntity();
            //Mock实体实例
            DEEntityInstanceBase instance = entity.CreateInstance();

            //集合字段类型赋值
            #region
            var children = entity.Fields.Where(p => p.FieldType == FieldTypeEnum.Collection);

            foreach (var child in children)
            {
                DEEntityInstanceBaseCollection entityItems = new DEEntityInstanceBaseCollection();

                //创建两条字表数据
                for (int i = 0; i < 2; i++)
                {
                    DEEntityInstanceBase childInstance = child.ReferenceEntity.CreateInstance();
                    childInstance.ID = Guid.NewGuid().ToString();

                    foreach (var field in childInstance.Fields)
                    {
                        childInstance.Fields.TrySetValue(field.Definition.Name, field.Definition.Name + "Value" + i);
                    }

                    entityItems.Add(childInstance);
                }

                instance.Fields.SetValue(child.Name, entityItems);
            }
            #endregion

            //普通字段赋值
            #region
            instance.Fields.ForEach(p =>
            {
                if (p.Definition.FieldType != FieldTypeEnum.Collection)
                {
                    p.StringValue = p.Definition.Name + "Value";
                }
            });
            #endregion

            return(instance);
        }
        /// <summary>
        /// 验证实体实例的值得类型是否合法
        /// </summary>
        /// <param name="objectToValidate"></param>
        /// <param name="currentObject"></param>
        /// <param name="key"></param>
        /// <param name="validateResults"></param>
        protected override void DoValidate(object objectToValidate, object currentObject, string key, Validation.ValidationResults validateResults)
        {
            DEEntityInstance instanceData = objectToValidate as DEEntityInstance;

            instanceData.Fields.ForEach(f =>
            {
                //字段的值
                object fieldValue = f.GetRealValue();

                if (f.Definition.FieldType == Enums.FieldTypeEnum.Collection)
                {
                    DEEntityInstanceBaseCollection childEntities = f.GetRealValue() as DEEntityInstanceBaseCollection;
                    if (fieldValue is string)
                    {
                        //"实体实例'{0}'(实体的ID:{1})的字段'{2}'长度没有通过验证"
                        RecordValidationResult(validateResults,
                                               string.Format(this.MessageTemplate, f.Definition.ID),
                                               instanceData,
                                               key);
                    }
                    childEntities.ForEach(ce =>
                    {
                        ce.Validate();
                    });
                }
                else
                {
                    //添加验证,调用值转换函数
                    if (!IsOk(f.Definition.FieldType.ToString(), f.StringValue))
                    {
                        RecordValidationResult(validateResults,
                                               string.Format(this.MessageTemplate, f.Definition.ID),
                                               instanceData,
                                               key);
                    }
                    //if (f.StringValue is string && f.Definition.FieldType != Enums.FieldTypeEnum.String)
                    //{
                    //    RecordValidationResult(validateResults,
                    //        string.Format(this.MessageTemplate, instanceData.Name, instanceData.ID, f.Definition.Name),
                    //        instanceData,
                    //        key);
                    //}
                }
            });
        }
        /// <summary>
        /// 序列化
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();
            EntityFieldValue            data       = (EntityFieldValue)obj;

            //dictionary.AddNonDefaultValue("FieldID", data.Definition.ID);
            dictionary.AddNonDefaultValue("CodeName", data.Definition.CodeName);
            if (!string.IsNullOrEmpty(data.Definition.ReferenceEntityCodeName))
            {
                dictionary.AddNonDefaultValue("EntityCodeName", data.Definition.ReferenceEntityCodeName);
            }
            dictionary.AddNonDefaultValue("FieldName", data.Definition.Name);

            if (data.Definition.FieldType == Enums.FieldTypeEnum.Collection)
            {
                DEEntityInstanceBaseCollection coll = data.GetRealValue() as DEEntityInstanceBaseCollection;
                if (coll != null)
                {
                    coll.ForEach(i =>
                    {
                        i._notSerialize = true;
                    });
                    dictionary.AddNonDefaultValue("StringValue", coll);
                }
                //else
                //{
                //    dictionary.AddNonDefaultValue("StringValue", " ");
                //}
            }
            else
            {
                if (string.IsNullOrEmpty(data.StringValue))
                {
                    //dictionary.AddNonDefaultValue("StringValue", " ");
                }
                else
                {
                    dictionary.AddNonDefaultValue("StringValue", data.StringValue);
                }
            }
            return(dictionary);
        }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public DEEntityInstanceBaseCollection LoadByEntityID(string entityID, int pageIndex, int pageSize, ref int totalNum)
        {
            DataView dataView = InnerQuery(entityID, pageIndex, pageSize, "CreateDate", ref totalNum);

            DataTable table = dataView.ToTable();

            Dictionary <string, DynamicEntity> schemaElements = new Dictionary <string, DynamicEntity>(StringComparer.OrdinalIgnoreCase);

            DEEntityInstanceBaseCollection instanceCollection = new DEEntityInstanceBaseCollection();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                DynamicEntity dynamicEntity = null;

                string entityCode = table.Rows[i]["EntityCode"].ToString();
                string data       = table.Rows[i]["Data"].ToString();

                if (schemaElements.TryGetValue(entityCode, out dynamicEntity) == false)
                {
                    dynamicEntity = DESchemaObjectAdapter.Instance.Load(entityCode) as DynamicEntity;
                    schemaElements.Add(entityCode, dynamicEntity);
                }

                if (dynamicEntity != null)
                {
                    DEEntityInstance obj = (DEEntityInstance)dynamicEntity.CreateInstance();

                    obj.FromString(data);

                    ORMapping.DataRowToObject(table.Rows[i], obj);

                    if (instanceCollection.ContainsKey(obj.ID) == false)
                    {
                        instanceCollection.Add(obj);
                    }
                }
            }

            return(instanceCollection);
        }
예제 #10
0
        /// <summary>
        /// 得到强类型的值
        /// </summary>
        /// <returns></returns>
        public object GetRealValue()
        {
            object result = this.StringValue;

            if (this.Definition.FieldType == FieldTypeEnum.Collection)
            {
                if (this.StringValue.IsNotEmpty())
                {
                    DEEntityInstanceBaseCollection collection = new DEEntityInstanceBaseCollection();
                    IEnumerable <XElement>         objs       = XElement.Parse(this.StringValue).XPathSelectElements("Object");

                    objs.ForEach(p =>
                    {
                        //这里需要优化,得到一个实体的定义,应该通过缓存逻辑实现。或者在Instance中,直接保存定义信息
                        DynamicEntity entity =
                            DESchemaObjectAdapter.Instance.Load(p.AttributeValue("EntityID")) as DynamicEntity;
                        DEEntityInstanceBase item = entity.CreateInstance();

                        item.FromXElement(p);

                        collection.Add(item);
                    });

                    result = collection;
                }
            }
            else
            {
                Type realType = typeof(string);

                //author haoyk 2014-3-3
                if (this.Definition.FieldType.TryToRealType(out realType))
                {
                    result = DataConverter.ChangeType(result, realType);
                }
            }

            return(result);
        }
예제 #11
0
        /// <summary>
        /// 根据<see cref="IConnectiveSqlClause"/>指定的条件和时间点载入对象
        /// </summary>
        /// <param name="condition">表示条件的<see cref="IConnectiveSqlClause"/></param>
        /// <returns>一个<see cref="DESchemaObjectCollection"/>,包含条件指定的对象。</returns>
        public DEEntityInstanceBaseCollection Load(IConnectiveSqlClause condition)
        {
            //var timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint);

            DEEntityInstanceBaseCollection result = new DEEntityInstanceBaseCollection();

            if (condition.IsEmpty == false)
            {
                ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(condition);

                using (DbContext context = DbContext.GetContext(this.GetConnectionName()))
                {
                    VersionedObjectAdapterHelper.Instance.FillData(GetMappingInfo().TableName, connectiveBuilder, this.GetConnectionName(),
                                                                   reader =>
                    {
                        result.LoadFromDataReader(reader);
                    });
                }
            }

            return(result);
        }
예제 #12
0
        /// <summary>
        /// 创建带数据的实体实例
        /// </summary>
        /// <returns></returns>
        public static DEEntityInstanceBase CreateInstanceWithData()
        {
            //准备实体定义
            DynamicEntity header = MockData.CreateEntityWithReferenceEntity();

            //创建空实例
            DEEntityInstanceBase instance = header.CreateInstance();

            instance.Fields.SetValue("总金额", 200);

            DynamicEntityField field = instance.EntityDefine.Fields.FirstOrDefault(p => p.FieldType == FieldTypeEnum.Collection) as DynamicEntityField;

            DEEntityInstanceBaseCollection items = new DEEntityInstanceBaseCollection();

            #region
            //实例1
            DEEntityInstanceBase itemInstance = field.ReferenceEntity.CreateInstance();
            itemInstance.ID   = Guid.NewGuid().ToString();
            itemInstance.Name = "第一条数据";
            itemInstance.Fields.TrySetValue("物料名称", "鼠标");
            itemInstance.Fields.TrySetValue("物料数量", 1);
            itemInstance.Fields.TrySetValue("单价", 50);
            items.Add(itemInstance);

            //实例2
            DEEntityInstanceBase itemInstance1 = field.ReferenceEntity.CreateInstance();
            itemInstance1.ID   = Guid.NewGuid().ToString();
            itemInstance1.Name = "第二条数据";
            itemInstance1.Fields.TrySetValue("物料名称", "键盘");
            itemInstance1.Fields.TrySetValue("物料数量", 1);
            itemInstance1.Fields.TrySetValue("单价", 150);
            items.Add(itemInstance1);
            #endregion
            instance.Fields.SetValue("销售明细", items);

            DEInstanceAdapter.Instance.Update(instance);

            return(instance);
        }
        protected override void DoValidate(object objectToValidate, object currentObject, string key, Validation.ValidationResults validateResults)
        {
            DEEntityInstance instanceData = objectToValidate as DEEntityInstance;

            instanceData.Fields.ForEach(f =>
            {
                if (f.Definition.FieldType == Enums.FieldTypeEnum.Collection)
                {
                    DEEntityInstanceBaseCollection childEntities = f.GetRealValue() as DEEntityInstanceBaseCollection;
                    if (childEntities.Count > f.Definition.Length)
                    {
                        //"实体实例'{0}'(实体的ID:{1})的字段'{2}'长度没有通过验证"
                        RecordValidationResult(validateResults,
                                               string.Format(this.MessageTemplate, f.Definition.ID),
                                               instanceData,
                                               key);
                    }
                    childEntities.ForEach(ce =>
                    {
                        ce.Validate();
                    });
                }
                else
                {
                    if ((((f.Definition.FieldType == Enums.FieldTypeEnum.Bool) && (f.Definition.Length != 1)) ||
                         ((f.Definition.FieldType != Enums.FieldTypeEnum.Bool) && (f.StringValue.Length > f.Definition.Length))
                         ) && (f.Definition.FieldType != Enums.FieldTypeEnum.DateTime)
                        )
                    {
                        RecordValidationResult(validateResults,
                                               string.Format(this.MessageTemplate, f.Definition.ID),
                                               instanceData,
                                               key);
                    }
                }
            });
        }
        public ServerResult GetInstanceList(string entityCodeName, int pageIndex, int pageSize, ref int totalNum)
        {
            ServerResult result = new ServerResult();

            try
            {
                entityCodeName.CheckStringIsNullOrEmpty <ArgumentNullException>("实体定义CodeName不能为空");
                DynamicEntity entity = DEDynamicEntityAdapter.Instance.LoadByCodeName(entityCodeName) as DynamicEntity;

                //根据实例ID获取实例对象
                DEEntityInstanceBaseCollection instances = DEInstanceAdapter.Instance.LoadByEntityID(entity.ID, pageIndex, pageSize, ref totalNum);

                string json = JSONSerializerExecute.Serialize(instances);

                result.Result = json;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Result    = e.Message;
            }

            return(result);
        }
예제 #15
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //主表
            SaleOrderEntityMain_RFC main = new SaleOrderEntityMain_RFC();

            #region 子表

            #region //子表1 -- 以前的主表
            List <SaleOrderEntityChild_I_ZR5_SS02_RFC> child_I_ZR5_SS02 = new List <SaleOrderEntityChild_I_ZR5_SS02_RFC>();

            SaleOrderEntityChild_I_ZR5_SS02_RFC saleEntity = new SaleOrderEntityChild_I_ZR5_SS02_RFC();

            saleEntity.BUKRS    = this.BUKRS.SelectedValue;
            saleEntity.CZDAT    = DateTime.Parse(this.CZDAT.Text).ToString("yyyyMMdd");
            saleEntity.EDAT     = DateTime.Parse(this.EDAT.Text).ToString("yyyyMMdd");
            saleEntity.KUNNR    = this.KUNNR.SelectedValue;
            saleEntity.OIC_MOT  = this.OIC_MOT.Text;
            saleEntity.RMAN     = this.RMAN.Text;
            saleEntity.SALESNUM = this.SALESNUM.Text;
            saleEntity.VKBUR    = this.VKBUR.Text;
            saleEntity.VKORG    = this.VKORG.SelectedValue;
            saleEntity.VTWEG    = this.VTWEG.SelectedValue;
            saleEntity.YSHHS    = this.YSHHS.SelectedValue;

            child_I_ZR5_SS02.Add(saleEntity);
            #endregion


            #region 以前的子表
            DEEntityInstanceBaseCollection entityItemsChild_I_ZR5_SS02  = new DEEntityInstanceBaseCollection();
            DEEntityInstanceBaseCollection entityItemsChild_T_ZR5_SS02P = new DEEntityInstanceBaseCollection();
            List <SaleOrderEntityChild_T_ZR5_SS02P_RFC> dd = JSONSerializerExecute.Deserialize <List <SaleOrderEntityChild_T_ZR5_SS02P_RFC> >(hiddenDetail.Value);
            dd.ForEach(s =>
            {
                entityItemsChild_T_ZR5_SS02P.Add(s.Instance);
            });


            child_I_ZR5_SS02.ForEach(s =>
            {
                entityItemsChild_I_ZR5_SS02.Add(s.Instance);
            });
            #endregion

            #endregion

            main.Instance.Fields.SetValue("I_ZR5_SS02", entityItemsChild_I_ZR5_SS02);
            main.Instance.Fields.SetValue("T_ZR5_SS02P", entityItemsChild_T_ZR5_SS02P);
            //进库
            DEInstanceAdapter.Instance.Update(main.Instance);

            #region 调用sap接口
            //Saplocalhost.WebServiceConnectSAP sapServiece = new Saplocalhost.WebServiceConnectSAP();
            var sapServiece = new Saplocalhost.WebServiceConnectSAPSoapClient();

            #region 给sap参数赋值
            Saplocalhost.InstanceParam sappar = new Saplocalhost.InstanceParam();

            //SAPLoginParams Params = SAPLoginParams.GetConfig();

            sappar.SapType = Saplocalhost.InType.CustomInterface;

            var itemList = main.Instance.ToParams("ZR5_SDIF_MH003");

            List <Saplocalhost.SapValue> sapValueList = new List <Saplocalhost.SapValue>();

            for (int i = 0; i < itemList.Count; i++)
            {
                if (itemList[i].Value.GetType() == typeof(string))
                {
                    sapValueList.Add(new Saplocalhost.SapValue()
                    {
                        Key   = itemList[i].Key,
                        Value = itemList[i].Value
                    });
                }
                else
                {
                    var list = itemList[i].Value as List <SapValue>;
                    List <Saplocalhost.SapValue> child = new List <Saplocalhost.SapValue>();
                    foreach (var item in list)
                    {
                        var result = new List <Saplocalhost.SapValue>();
                        var items  = (List <SapValue>)item.Value;
                        foreach (var item3 in items)
                        {
                            result.Add(
                                new Saplocalhost.SapValue()
                            {
                                Key   = item3.Key,
                                Value = item3.Value
                            });
                        }
                        child.Add(new Saplocalhost.SapValue()
                        {
                            Key   = "mingxi",
                            Value = result.ToArray()
                        });
                    }

                    sapValueList.Add(new Saplocalhost.SapValue()
                    {
                        Key   = itemList[i].Key,
                        Value = child.ToArray()
                    });
                }
            }
            sappar.Values = sapValueList.ToArray();

            //sappar.RFCName = "ZR5_SDIF_MH003";
            #endregion

            string resultParam = string.Empty;
            //string result1 = sapServiece.ExecuteSAP(sappar, out resultParam);
            sapServiece.ExecuteSAPRFC("ZR5_SDIF_MH003", sappar, new SAPPara()
            {
                ApplicationServer = Params.ApplicationServer,
                Client            = Params.Client,
                Language          = Params.Language,
                Password          = Params.Password,
                SystemNumber      = int.Parse(Params.SystemNumber),
                User = Params.User
            });

            #endregion

            Response.Write(resultParam);
        }
예제 #16
0
        public void Update(DEEntityInstanceBaseCollection collection)
        {
            collection.NullCheck <ArgumentNullException>("实例集合collection不能为空");

            collection.ForEach(this.Update);
        }