示例#1
0
        public async Task <string> Delete(string json)
        {
            foreach (int vsoId in JArray.Parse(json))
            {
                VisioMap visiomap = await db.VisioMaps
                                    .Include(e => e.Diagrams)
                                    .ThenInclude(e => e.Notations)
                                    .Include(e => e.Shapes)
                                    .Include(e => e.Relations)
                                    .FirstOrDefaultAsync(e => e.Id == vsoId);


                // Diagram에 있는 지 확인
                if (visiomap.Diagrams.Count() > 0)
                {
                    foreach (Diagram diagram in visiomap.Diagrams.Reverse())
                    {
                        foreach (Diagram notation in diagram.Notations.Reverse())
                        {
                            db.Remove(notation);
                        }

                        db.Remove(diagram);
                    }
                }

                // Visiomap 하위 Shape 삭제
                foreach (Shape shape in visiomap.Shapes.Reverse())
                {
                    db.Remove(shape);
                }

                foreach (RelationVisiomap relation in visiomap.Relations.Reverse())
                {
                    db.Remove(relation);
                }


                // log
                Log log = new Log
                {
                    ActionType = "Delete",
                    DataType   = "VisioMap",
                    RefId      = visiomap.Id,
                    Date       = DateTime.Now,
                    User       = User.Identity.Name,
                    ChangeData = new JObject {
                        { "EnableLayer", visiomap.EnableLayer }
                    }.ToString()
                };

                db.Add(log);
                db.Remove(visiomap);
            }

            db.SaveChanges();

            return("Success");
        }
示例#2
0
        public async void CopyVisiomaps(string json)
        {
            foreach (int visioId in JArray.Parse(json))
            {
                VisioMap oVisiomap = await db.VisioMaps
                                     .Include(e => e.Shapes)
                                     .ThenInclude(e => e.RelationShapes)
                                     .Include(e => e.Relations)
                                     .FirstOrDefaultAsync(e => e.Id == visioId);

                VisioMap nVisiomap = new VisioMap();

                nVisiomap      = (VisioMap)db.Entry(oVisiomap).GetDatabaseValues().ToObject();
                nVisiomap.Date = DateTime.Now;
                nVisiomap.User = User.Identity.Name;

                db.Add(nVisiomap);
                db.SaveChanges();


                foreach (Shape oShape in oVisiomap.Shapes)
                {
                    Shape newShape = new Shape();
                    newShape      = (Shape)db.Entry(oShape).GetDatabaseValues().ToObject();
                    newShape.Date = DateTime.Now;
                    newShape.User = User.Identity.Name;
                    nVisiomap.Shapes.Add(newShape);

                    foreach (RelationShape oReShape in oShape.RelationShapes)
                    {
                        RelationShape newReShape = new RelationShape();
                        newReShape = (RelationShape)db.Entry(oReShape).GetDatabaseValues().ToObject();
                        newShape.RelationShapes.Add(newReShape);
                    }
                }

                db.SaveChanges();


                // Relation
                foreach (RelationVisiomap oReVisio in oVisiomap.Relations)
                {
                    RelationVisiomap newReVisio = new RelationVisiomap();
                    newReVisio = (RelationVisiomap)db.Entry(oReVisio).GetDatabaseValues().ToObject();
                    nVisiomap.Relations.Add(newReVisio);
                }

                db.SaveChanges();
            }
        }
示例#3
0
        public void Edit(int id, int productId, string group, string title, string def, string enableLayer, int wordmapId, string strRelations)
        {
            VisioMap visiomap = db.VisioMaps.Find(id);
            bool     change   = false;

            JObject objJson = new JObject();

            JArray arrVisio = new JArray();

            objJson.Add("VisioMap", arrVisio);

            if (visiomap.ProductId != productId)
            {
                JObject obj = new JObject();
                obj.Add("Type", "ProductId");
                obj.Add("oValue", visiomap.ProductId);
                obj.Add("nValue", productId);
                arrVisio.Add(obj);

                visiomap.ProductId = productId;
                change             = true;
            }
            if (visiomap.Group != (group = string.IsNullOrEmpty(group) ? null : group.Trim()))
            {
                JObject obj = new JObject();
                obj.Add("Type", "Group");
                obj.Add("oValue", visiomap.Group);
                obj.Add("nValue", group);
                arrVisio.Add(obj);

                visiomap.Group = group;
                change         = true;
            }
            if (visiomap.Title != (title = string.IsNullOrEmpty(title) ? null : title.Trim()))
            {
                JObject obj = new JObject();
                obj.Add("Type", "Title");
                obj.Add("oValue", visiomap.Title);
                obj.Add("nValue", title);
                arrVisio.Add(obj);

                visiomap.Title = title;
                change         = true;
            }
            if (visiomap.Default != (def = string.IsNullOrEmpty(def) ? null : def.Trim()))
            {
                JObject obj = new JObject();
                obj.Add("Type", "Default");
                obj.Add("oValue", visiomap.Default);
                obj.Add("nValue", def);
                arrVisio.Add(obj);

                visiomap.Default = def;
                change           = true;
            }
            if (visiomap.EnableLayer != (enableLayer = string.IsNullOrEmpty(enableLayer) ? null : enableLayer.Trim()))
            {
                JObject obj = new JObject();
                obj.Add("Type", "EnableLayer");
                obj.Add("oValue", visiomap.EnableLayer);
                obj.Add("nValue", enableLayer);
                arrVisio.Add(obj);

                visiomap.EnableLayer = enableLayer;
                change = true;
            }
            if (visiomap.WordMapId != wordmapId)
            {
                JObject obj = new JObject();
                obj.Add("Type", "WordMapId");
                obj.Add("oValue", visiomap.WordMapId);
                obj.Add("nValue", wordmapId);
                arrVisio.Add(obj);

                visiomap.WordMapId = wordmapId;
                change             = true;
            }

            db.Update(visiomap);
            db.SaveChanges();


            if (!string.IsNullOrEmpty(strRelations))
            {
                JObject ob = JObject.Parse(strRelations);

                JToken arrShape    = ob["Shapes"];
                JToken arrRelation = ob["Relations"];


                #region Relation Layer
                foreach (JToken strRelation in arrRelation)
                {
                    string changeVal      = (string)strRelation["ChangeVal"];
                    string method         = (string)strRelation["Method"];
                    string value          = (string)strRelation["Value"];
                    string gaVariant      = (string)(strRelation["GAVariant"]);
                    string variantIds     = (string)strRelation["VariantIds"];
                    int?   intEquipmentId = (int?)strRelation["IntEquipmentId"];
                    int?   intProductId   = string.IsNullOrEmpty((string)strRelation["IntProductId"]) ? null : (int?)strRelation["IntProductId"];
                    int?   reLayerId      = string.IsNullOrEmpty((string)strRelation["ReLayerId"]) ? null : (int?)strRelation["ReLayerId"];
                    string reLayerValue   = string.IsNullOrEmpty((string)strRelation["ReLayerValue"]) ? null : (string)strRelation["ReLayerValue"];


                    if (changeVal == "A")
                    {
                        RelationVisiomap relation = new RelationVisiomap
                        {
                            VisiomapId     = visiomap.Id,
                            Method         = method,
                            Value          = value + (gaVariant == null ? "" : "," + gaVariant),
                            VariantIds     = variantIds,
                            IntEquipmentId = intEquipmentId,
                            IntProductId   = intProductId,
                            ReLayerId      = reLayerId,
                            ReLayerValue   = reLayerValue
                        };

                        db.Add(relation);
                    }
                    else if (changeVal == "D")
                    {
                        int?relationId            = (int?)strRelation["RelationId"];
                        RelationVisiomap relation = db.RelationVisiomaps.Find(relationId);

                        db.Remove(relation);
                    }
                    else
                    {
                        int?relationId            = (int?)strRelation["RelationId"];
                        RelationVisiomap relation = db.RelationVisiomaps.Find(relationId);

                        if (relation.Method != (method = string.IsNullOrEmpty(method) ? null : method.Trim()))
                        {
                            relation.Method = method;
                        }

                        if (relation.Value != (value = string.IsNullOrEmpty(value) ? null : value.Trim()))
                        {
                            relation.Value = value;
                        }

                        if (relation.VariantIds != (variantIds = string.IsNullOrEmpty(variantIds) ? null : variantIds.Trim()))
                        {
                            relation.VariantIds = variantIds;
                        }

                        if (relation.IntEquipmentId != intEquipmentId)
                        {
                            relation.IntEquipmentId = intEquipmentId;
                        }

                        if (relation.IntProductId != intProductId)
                        {
                            relation.IntProductId = intProductId;
                        }

                        if (relation.ReLayerId != reLayerId)
                        {
                            relation.ReLayerId = reLayerId;
                        }

                        if (relation.ReLayerValue != (reLayerValue = string.IsNullOrEmpty(reLayerValue) ? null : reLayerValue.Trim()))
                        {
                            relation.ReLayerValue = reLayerValue;
                        }

                        db.Update(relation);
                    }
                }
                #endregion


                #region Shape, Relation Shape
                JArray arrSha = new JArray();
                objJson.Add("Shape", arrSha);

                foreach (JToken strShape in arrShape)
                {
                    int?   shapeId   = string.IsNullOrEmpty((string)strShape["Id"]) ? null : (int?)strShape["Id"];
                    string changeVal = (string)strShape["ChangeVal"];
                    string type      = (string)strShape["Type"];
                    string name      = (string)strShape["Name"];
                    string text      = (string)strShape["Text"];

                    JToken arrReShape = strShape["ReShapes"];
                    Shape  shape      = changeVal == "A" ? new Shape() : db.Shapes.Find(shapeId);


                    if (changeVal == "D")
                    {
                        // 지워야 하는 shape가 포함된 diagram 삭제
                        IEnumerable <Diagram> diagrams = db.Diagrams.Where(e => e.ShapeId == shape.Id);
                        foreach (Diagram diagram in diagrams.Reverse())
                        {
                            db.Remove(diagram);
                        }

                        JObject obj = new JObject();
                        obj.Add("Action", "Delete");
                        obj.Add("Id", shape.Id);
                        obj.Add("Name", shape.Name);
                        arrSha.Add(obj);

                        db.Remove(shape);
                    }
                    else if (changeVal == "A")
                    {
                        shape.VisioMapId = visiomap.Id;
                        shape.Type       = string.IsNullOrEmpty(type) ? null : type.Trim();
                        shape.Name       = string.IsNullOrEmpty(name) ? null : name.Trim();
                        shape.Text       = string.IsNullOrEmpty(text) ? null : text.Trim();

                        shape.Date = DateTime.Now;
                        shape.User = User.Identity.Name;

                        db.Add(shape);
                    }
                    else
                    {
                        if (shape.Type != (type = string.IsNullOrEmpty(type) ? null : type.Trim()))
                        {
                            JObject obj = new JObject();
                            obj.Add("Type", "Type");
                            obj.Add("oValue", shape.Type);
                            obj.Add("nValue", type);
                            arrVisio.Add(obj);

                            shape.Type = type;
                            change     = true;
                        }
                        if (shape.Name != (name = string.IsNullOrEmpty(name) ? null : name.Trim()))
                        {
                            JObject obj = new JObject();
                            obj.Add("Type", "Name");
                            obj.Add("oValue", shape.Name);
                            obj.Add("nValue", name);
                            arrVisio.Add(obj);

                            shape.Name = name;
                            change     = true;
                        }
                        if (shape.Text != (text = string.IsNullOrEmpty(text) ? null : text.Trim()))
                        {
                            JObject obj = new JObject();
                            obj.Add("Type", "Text");
                            obj.Add("oValue", shape.Text);
                            obj.Add("nValue", text);
                            arrVisio.Add(obj);

                            shape.Text = text;
                            change     = true;
                        }
                        db.Update(shape);
                    }

                    foreach (JToken strReShape in arrReShape)
                    {
                        string reChangeVal = (string)strReShape["ChangeVal"];
                        int    reId        = (int)strReShape["Id"];

                        int?   reProductId = (int?)strReShape["ProductId"];
                        int?   reLayerId   = (int?)strReShape["LayerId"];
                        int?   reShapeId   = (int?)strReShape["ShapeId"];
                        string reMethod    = (string)strReShape["Method"];
                        string reVal       = (string)strReShape["Value"];

                        RelationShape reShape = reChangeVal == "A" ? new RelationShape() : db.RelationShapes.Find(reId);

                        if (reChangeVal == "D")
                        {
                            db.Remove(reShape);
                        }

                        else if (reChangeVal == "A")
                        {
                            reShape.ShapeId   = shape.Id;
                            reShape.ReShapeId = reShapeId;
                            reShape.Method    = string.IsNullOrEmpty(reMethod) ? null : reMethod.Trim();
                            reShape.Value     = string.IsNullOrEmpty(reVal) ? null : reVal.Trim();

                            db.Add(reShape);
                        }
                        else
                        {
                            if (reShape.ShapeId != shapeId)
                            {
                                reShape.ShapeId = shapeId;
                            }

                            if (reShape.ReShapeId != reShapeId)
                            {
                                reShape.ReShapeId = reShapeId;
                            }

                            if (reShape.Method != (reMethod = string.IsNullOrEmpty(reMethod) ? null : reMethod.Trim()))
                            {
                                reShape.Method = reMethod;
                            }

                            if (reShape.Value != (reVal = string.IsNullOrEmpty(reVal) ? null : reVal.Trim()))
                            {
                                reShape.Value = reVal;
                            }

                            db.Update(reShape);
                        }
                    }
                }
                #endregion
            }

            if (change)
            {
                Log log = new Log
                {
                    ActionType = "Edit",
                    DataType   = "VisioMap",
                    RefId      = visiomap.Id,
                    Date       = DateTime.Now,
                    User       = User.Identity.Name,
                    ChangeData = objJson.ToString()
                };

                db.Add(log);
            }

            db.SaveChanges();
        }
示例#4
0
        public void Create(VisioMap visiomap, string strRelations, string strShapes)
        {
            visiomap.Group       = string.IsNullOrEmpty(visiomap.Group) ? null : visiomap.Group.Trim();
            visiomap.Title       = string.IsNullOrEmpty(visiomap.Title) ? null : visiomap.Title.Trim();
            visiomap.Default     = string.IsNullOrEmpty(visiomap.Default) || visiomap.Group != "INTERFACE" ? null : visiomap.Default.Trim();
            visiomap.EnableLayer = string.IsNullOrEmpty(visiomap.EnableLayer) ? null : visiomap.EnableLayer.Trim();
            visiomap.Date        = DateTime.Now;
            visiomap.User        = User.Identity.Name;

            db.Add(visiomap);


            #region Shapes
            if (!string.IsNullOrEmpty(strShapes))
            {
                foreach (string strShape in JArray.Parse(strShapes))
                {
                    string[] arrVal  = strShape.Split(',');
                    string   type    = arrVal[0];
                    string   name    = arrVal[1];
                    string   text    = arrVal[2];
                    string   reShape = arrVal[3];


                    Shape shape = new Shape
                    {
                        VisioMapId = visiomap.Id,
                        Type       = string.IsNullOrEmpty(type) ? null : type,
                        Name       = string.IsNullOrEmpty(name) ? null : name,
                        Text       = string.IsNullOrEmpty(text) ? null : text,
                        Date       = DateTime.Now,
                        User       = User.Identity.Name
                    };

                    visiomap.Shapes.Add(shape);
                    db.SaveChanges();


                    if (!string.IsNullOrEmpty(reShape))
                    {
                        RelationShape newReShape = new RelationShape
                        {
                            ShapeId   = shape.Id,
                            ReShapeId = int.Parse(reShape)
                        };

                        shape.RelationShapes.Add(newReShape);
                    }
                }

                db.SaveChanges();
            }
            #endregion


            #region Relation
            if (!string.IsNullOrEmpty(strRelations))
            {
                foreach (var strRelation in JArray.Parse(strRelations))
                {
                    string method         = (string)strRelation["Method"];
                    string value          = (string)strRelation["Value"];
                    string variantIds     = (string)strRelation["VariantIds"];
                    int?   intEquipmentId = (int?)strRelation["IntEquipmentId"];
                    int?   intProductId   = (int?)strRelation["IntProductId"];
                    int?   reLayerId      = (int?)strRelation["ReLayerId"];
                    string reLayerValue   = (string)strRelation["ReLayerValue"];

                    RelationVisiomap relation = new RelationVisiomap
                    {
                        VisiomapId     = visiomap.Id,
                        Method         = string.IsNullOrEmpty(method) ? null : method.Trim(),
                        Value          = string.IsNullOrEmpty(value) ? null : value.Trim(),
                        VariantIds     = string.IsNullOrEmpty(variantIds) ? null : value.Trim(),
                        IntEquipmentId = intEquipmentId,
                        IntProductId   = intProductId,
                        ReLayerId      = reLayerId,
                        ReLayerValue   = string.IsNullOrEmpty(reLayerValue) ? null : reLayerValue.Trim()
                    };
                    db.RelationVisiomaps.Add(relation);
                }

                db.SaveChanges();
            }
            #endregion
        }
示例#5
0
        public async Task <JObject> LoadVisioMapItem(int?visioId)
        {
            JObject json = new JObject();

            VisioMap visiomap = await db.VisioMaps
                                .Include(e => e.Product)
                                .ThenInclude(e => e.Equipment)
                                .Include(e => e.Shapes)
                                .ThenInclude(e => e.RelationShapes)
                                .Include(e => e.Relations)
                                .AsNoTracking()
                                .FirstOrDefaultAsync(e => e.Id == visioId);


            #region Information
            JObject info = new JObject();
            json.Add("ItemInfo", info);

            info.Add("Id", visioId);
            info.Add("ProductNumber", visiomap.Product.Model);
            info.Add("ProductId", visiomap.Product.Id);

            info.Add("EquipmentId", visiomap.Product.EquipmentId);
            info.Add("EquipmentGroup", visiomap.Product.Equipment.Group);

            info.Add("WordMapId", visiomap.WordMapId);
            info.Add("Group", visiomap.Group);
            info.Add("Title", visiomap.Title);
            info.Add("Default", visiomap.Default);
            info.Add("EnableLayer", visiomap.EnableLayer);
            #endregion


            #region Shapes
            JArray arrShape = new JArray();
            json.Add("Shapes", arrShape);

            foreach (Shape shape in visiomap.Shapes)
            {
                JObject obShape = new JObject();
                arrShape.Add(obShape);

                obShape.Add("VisioMapId", shape.Id);
                obShape.Add("Type", shape.Type);
                obShape.Add("Name", shape.Name);
                obShape.Add("Text", shape.Text);

                JArray arrReShape = new JArray();
                obShape.Add("ReShape", arrReShape);


                if (shape.RelationShapes.Count() > 0)
                {
                    foreach (RelationShape reShape in shape.RelationShapes)
                    {
                        JObject obReShape = new JObject();
                        arrReShape.Add(obReShape);

                        obReShape.Add("ReShapeId", reShape.Id);
                        obReShape.Add("ReProduct", reShape.ReShape.VisioMap.ProductId);
                        obReShape.Add("ReLayer", reShape.ReShape.VisioMapId);
                        obReShape.Add("ReShape", reShape.ReShapeId);
                        obReShape.Add("Method", reShape.Method);
                        obReShape.Add("Value", reShape.Value);
                    }
                }
            }
            #endregion


            #region Relations
            JArray arrRelation = new JArray();
            json.Add("Relations", arrRelation);

            foreach (RelationVisiomap relation in visiomap.Relations)
            {
                arrRelation.Add(relation.Id);
                //JObject obRelation = new JObject();
                //arrRelation.Add(obRelation);

                //obRelation.Add("Id", relation.Id);
                //obRelation.Add("VisiomapId", relation.VisiomapId);
                //obRelation.Add("RelationType", relation.RelationType);
                //obRelation.Add("Method", relation.Method);

                //obRelation.Add("IntEquipmentId", relation.IntEquipmentId);
                //obRelation.Add("IntProductId", relation.IntProductId);
                //obRelation.Add("ReLayerId", relation.ReLayerId);
            }
            #endregion

            return(json);
        }
示例#6
0
        // Delete
        public async Task <string> DeleteProduct(string json)
        {
            JArray arrItems = JArray.Parse(json);

            foreach (int id in arrItems)
            {
                Product product = await db.Products
                                  .Include(e => e.WordMaps)
                                  .Include(e => e.Children)
                                  .Include(e => e.VisioMaps)
                                  .ThenInclude(e => e.Shapes)
                                  .ThenInclude(e => e.RelationShapes)
                                  .Include(e => e.VisioMaps)
                                  .ThenInclude(e => e.Relations)
                                  .FirstOrDefaultAsync(e => e.Id == id);

                if (product.Completion == "GOODS")
                {
                    foreach (VisioMap visiomap in product.VisioMaps.Reverse())
                    {
                        foreach (Shape shape in visiomap.Shapes.Reverse())
                        {
                            foreach (RelationShape reShape in shape.RelationShapes.Reverse())
                            {
                                db.Remove(reShape);
                            }

                            db.Remove(shape);
                        }

                        foreach (RelationVisiomap reVisiomap in visiomap.Relations.Reverse())
                        {
                            db.Remove(reVisiomap);
                        }

                        db.Remove(visiomap);
                    }

                    foreach (var wdmap in product.WordMaps.Reverse())
                    {
                        db.Remove(wdmap);
                    }

                    foreach (Variant variant in product.Children.Reverse())
                    {
                        db.Remove(variant);
                    }
                }
                else
                {
                    IEnumerable <Variant> variants = db.Variants.Where(e => e.ProductId == product.Id);

                    foreach (Variant variant in variants.Reverse())
                    {
                        var reVisios = db.RelationVisiomaps.Where(e => e.VariantIds.Contains(variant.Id.ToString()));

                        foreach (RelationVisiomap reVisio in reVisios.Reverse())
                        {
                            if (reVisio.VariantIds.Contains(','))
                            {
                                string[] oIds = reVisio.VariantIds.Split(',');
                                string   nIds = null;

                                for (int i = 0; i < oIds.Length; i++)
                                {
                                    if (oIds[i] != variant.Id.ToString())
                                    {
                                        if (i == 0)
                                        {
                                            nIds = oIds[i];
                                        }
                                        else
                                        {
                                            nIds += "," + oIds[i];
                                        }
                                    }
                                }

                                reVisio.VariantIds = nIds;
                                db.Update(reVisio);
                            }
                            else
                            {
                                //VisioMap visiomap = reVisio.VisioMap;
                                VisioMap visiomap = await db.VisioMaps
                                                    .Include(e => e.Shapes)
                                                    .Include(e => e.Relations)
                                                    .FirstOrDefaultAsync(e => e.Id == reVisio.VisiomapId);

                                foreach (Diagram diagram in db.Diagrams.Where(e => e.VisioMapId == visiomap.Id).Reverse())
                                {
                                    db.Remove(diagram);
                                }

                                foreach (Shape shape in visiomap.Shapes.Reverse())
                                {
                                    db.Remove(shape);
                                }

                                db.Remove(reVisio);

                                if (visiomap.Relations.Count() == 0)
                                {
                                    db.Remove(visiomap);
                                }
                            }
                        }
                        db.Remove(variant);
                    }
                }
                db.SaveChanges();


                Log log = new Log
                {
                    RefId      = id,
                    DataType   = "Product",
                    Date       = DateTime.Now,
                    User       = User.Identity.Name,
                    ActionType = "DeleteProduct"
                };
                db.Add(log);

                // Product 삭제
                db.Remove(product);
                db.SaveChanges();
            }
            return("Success");
        }