public int createTransform(int cdsID, TransformModel transformModel)
        {
            var dbTransform = new Transform
                {
                    ConvertedDataSetID = cdsID,
                    Name = transformModel.Name
                };
            _context.Transforms.Add(dbTransform);

            foreach (var filterModel in transformModel.Filters)
            {
                var dbFilter = new Filter
                    {
                        FieldName = filterModel.FieldName,
                        Transform = dbTransform,
                        FilterType = (int?) filterModel.FilterType,
                        Value = filterModel.Value.ToString()
                    };
                _context.Filters.Add(dbFilter);
            }
            var order = 10;
            foreach (var operationModel in transformModel.Operations)
            {
                var dbOperation = new Operation
                    {
                        Name = operationModel.Name,
                        Transform = dbTransform,
                        FieldName = operationModel.FieldName,
                        OperationType = (int?) operationModel.OperationType,
                        Value = operationModel.Value.ToString(),
                        Order = order
                    };
                _context.Operations.Add(dbOperation);
                order += 10;
            }
            _context.SaveChanges();

            return dbTransform.ID;
        }
        private void btnYeniTransform_Click(object sender, EventArgs e)
        {
            if (this._convertedDataSet != null)
            {
                var service = new ConvertedDataSetService();
                //this._convertedDataSet.Transforms.Add();
                var tranName = "Transform ";
                var i = 1;
                while (this._convertedDataSet.Transforms.Any(x => x.Name == tranName + i.ToString()))
                    i++;
                tranName += i.ToString();
                var tran = new TransformModel
                    {
                        Name = tranName,
                        Operations = new List<OperationModel>(),
                        Filters = new List<FilterModel>()
                    };
                service.createTransform(this._convertedDataSet.ID, tran);

                reloadTree();

            }
        }
Exemple #3
0
        private void frmTransform_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(this.SourceXML))
                txtSourceXml.Text = this.SourceXML;

            if (!String.IsNullOrWhiteSpace(txtSourceXml.Text))
            {
                btnLoad_Click(null, null);
            }

            if (this.Transform == null)
            {
                this.Transform = new TransformModel();
            }
            else
            {
                var filterStr = "";
                foreach (var filterModel in this.Transform.Filters)
                {
                    var col = gView.Columns[filterModel.FieldName];
                    if (col == null) continue;

                    var filter = new ColumnFilterInfo(ColumnFilterType.Value, filterModel.Value.ToString(), "");
                    //filter.Type = ColumnFilterType.Value;
                    //filter.Value = String.Format("[{0}] = '{1}'", filterModel.FieldName, filterModel.Value);

                    gView.ActiveFilter.Add(col, filter);

                    //filterStr += String.Format(" AND [{0}] = '{1}'", filterModel.FieldName, filterModel.Value);
                }
                //if (filterStr.Length >= 5)
                //{
                //    gView.ActiveFilterString = filterStr.Substring(5);
                //}
                foreach (var operationModel in this.Transform.Operations)
                {
                    this.OperationList.Add(operationModel);
                    listBox1.Items.Add(operationModel);
                }
                txtTransformName.Text = this.Transform.Name;
            }
        }
        public bool updateTransform(TransformModel transformModel)
        {
            var transform = _context.Transforms.FirstOrDefault(x => x.ID == transformModel.ID);
            if (transform == null)
                return false;

            transform.Name = transformModel.Name;
            _context.SaveChanges();

            var filterList = transform.Filters.ToList();

            this.Sync(transformModel.Filters, filterList, (filterModel, dbFilter) => filterModel.ID.CompareTo(dbFilter.ID),
                        (filterModel, dbFilter) =>
                            {
                                if (dbFilter.FieldName != filterModel.FieldName)
                                    dbFilter.FieldName = filterModel.FieldName;
                                if (dbFilter.FilterType != (int?) filterModel.FilterType)
                                    dbFilter.FilterType = (int?) filterModel.FilterType;
                                if (dbFilter.Value != filterModel.Value.ToString())
                                    dbFilter.Value = filterModel.Value.ToString();
                                if (dbFilter.Transform == null)
                                    dbFilter.Transform = transform;
                                return true;
                            });

            var opList = transform.Operations.ToList();
            this.Sync(transformModel.Operations, opList, (opModel, dbOp) => opModel.ID.CompareTo(dbOp.ID),
                        (opModel, dbOp) =>
                            {
                                if (dbOp.Name != opModel.Name)
                                    dbOp.Name = opModel.Name;
                                if (dbOp.FieldName != opModel.FieldName)
                                    dbOp.FieldName = opModel.FieldName;
                                if (dbOp.OperationType != (int) opModel.OperationType)
                                    dbOp.OperationType = (int) opModel.OperationType;
                                if (dbOp.Value != opModel.Value.ToString())
                                    dbOp.Value = opModel.Value.ToString();
                                if (dbOp.Order != opModel.Order)
                                    dbOp.Order = opModel.Order;
                                if (dbOp.Transform == null)
                                    dbOp.Transform = transform;
                                return true;
                            });
            _context.SaveChanges();

            return true;
        }
        public TransformModel getTransform(int transformId)
        {
            var transform = _context.Transforms.FirstOrDefault(x => x.ID == transformId);

            if (transform == null)
                return null;

            var model = new TransformModel
                {
                    ID = transform.ID,
                    Name = transform.Name,
                    Filters = transform.Filters.Select(y => new FilterModel
                        {
                            FieldName = y.FieldName,
                            FilterType = (FilterTypeEnum) (y.FilterType ?? 1),
                            Value = y.Value
                        }).ToList(),
                    Operations = transform.Operations.OrderBy(y => y.Order).Select(y => new OperationModel
                        {
                            Name = y.Name,
                            FieldName = y.FieldName,
                            OperationType = (OperationTypeEnum) (y.OperationType ?? 0),
                            //DataType = y.
                            Value = y.Value,
                            Order = y.Order
                        }).ToList()
                };

            return model;
        }
 public bool updateTransform(TransformModel transform)
 {
     return _repository.updateTransform(transform);
 }
 public int createTransform(int cdsID, TransformModel transform)
 {
     return _repository.createTransform(cdsID, transform);
 }