Beispiel #1
0
        public static TreeNode CreateNew(PLMPackEntities db, string grpId
                                         , string parentNodeId
                                         , string name, string description
                                         , int thumbId)
        {
            if (!string.IsNullOrEmpty(parentNodeId))
            {
                TreeNode tnParent = TreeNode.GetById(db, new Guid(parentNodeId));
                if (null != tnParent)
                {
                    if (tnParent.HasChildWithName(name))
                    {
                        throw new ModelException(string.Format("Node {0} ({1}) already has child named {1}", parentNodeId, tnParent.Name, name));
                    }
                }
            }

            TreeNode tn = new TreeNode();

            tn.Id           = Guid.NewGuid().ToString();
            tn.GroupId      = grpId;
            tn.ParentNodeId = parentNodeId;
            tn.Name         = name;
            tn.Description  = description;
            tn.ThumbnailId  = thumbId;
            db.TreeNodes.Add(tn);
            db.SaveChanges();

            return(db.TreeNodes.Single(n => n.Id == tn.Id));
        }
Beispiel #2
0
        public Dictionary <string, double> GetParamDefaultValues(PLMPackEntities db, string grpId)
        {
            if (db.ParamDefaultComponents.Count(pdc => (pdc.GroupId == grpId) && (pdc.ComponentGuid == this.Guid)) == 0)
            {
                // get component group
                string compGrpId = this.Document.Group.Id;
                // get param default components
                var paramDefaults1 = db.ParamDefaultComponents.Where(pdc => (pdc.GroupId == grpId) && (pdc.ComponentGuid == this.Guid));
                foreach (ParamDefaultComponent pdc in paramDefaults1)
                {
                    db.ParamDefaultComponents.Add(
                        new ParamDefaultComponent()
                    {
                        ComponentGuid = this.Guid,
                        GroupId       = pdc.GroupId,
                        Name          = pdc.Name,
                        Value         = pdc.Value
                    }
                        );
                }
                db.SaveChanges();
            }
            Dictionary <string, double> defaultParamValues = new Dictionary <string, double>();
            var paramDefaults2 = this.ParamDefaultComponents.Where(
                pdc => (pdc.GroupId == grpId) && (pdc.ComponentGuid == this.Guid)
                );

            foreach (ParamDefaultComponent pdc in paramDefaults2)
            {
                defaultParamValues.Add(pdc.Name, pdc.Value);
            }
            return(defaultParamValues);
        }
Beispiel #3
0
 public void Delete(PLMPackEntities db)
 {
     // remove all cardboard qualities that use this cardboard
     db.CardboardQualities.RemoveRange(CardboardQualities);
     // remove cardboard profile itself
     db.CardboardProfiles.Remove(this);
     db.SaveChanges();
 }
Beispiel #4
0
 public void RemoveGroupOfInterest(PLMPackEntities db, Group gp)
 {
     if (HasGroupOfInterest(gp))
     {
         GroupsOfInterest.Remove(gp);
         db.SaveChanges();
     }
 }
Beispiel #5
0
 public void AddGroupOfInterest(PLMPackEntities db, Group gp)
 {
     if (!HasGroupOfInterest(gp))
     {
         GroupsOfInterest.Add(gp);
         db.SaveChanges();
     }
 }
Beispiel #6
0
        public void Disconnect(PLMPackEntities db)
        {
            UserConnection uConnect = db.UserConnections.Where(uc => uc.UserId == Id)
                                      .OrderByDescending(uc => uc.DateConnectIN)
                                      .FirstOrDefault();

            uConnect.DateConnectOUT = DateTime.Now;
            db.SaveChanges();
        }
Beispiel #7
0
        public void Delete(PLMPackEntities db)
        {
            // remove tree node documents
            var tnDocs = db.TreeNodeDocuments.Where(tnd => tnd.DocumentId == this.Id);

            foreach (TreeNodeDocument tnd in tnDocs)
            {
                db.TreeNodeDocuments.Remove(tnd);
                db.TreeNodes.Remove(db.TreeNodes.Single(tn => tn.Id == tnd.TreeNodeId));
                db.SaveChanges();
            }
            Guid fGuid = Guid.Parse(FileGuid);

            // actually remove document
            db.Documents.Remove(this);
            db.SaveChanges();
            // remove file
            File f = File.GetById(db, fGuid);

            f.Delete(db);
        }
Beispiel #8
0
        public void Connect(PLMPackEntities db)
        {
            // initialize user
            InitializeUser(db);
            // create user connection
            UserConnection uConnect = new UserConnection();

            uConnect.UserId         = Id;
            uConnect.DateConnectIN  = DateTime.Now;
            uConnect.DateConnectOUT = null;
            db.UserConnections.Add(uConnect);
            db.SaveChanges();
        }
Beispiel #9
0
        public static File CreateNew(PLMPackEntities db, Guid g, string extension)
        {
            string sGuid = g.ToString();
            // create file
            File fn = new File();

            fn.Guid        = sGuid;
            fn.Extension   = extension;
            fn.DateCreated = DateTime.Now;
            db.Files.Add(fn);
            db.SaveChanges();
            // return file
            return(db.Files.Single(f => f.Guid == sGuid));
        }
Beispiel #10
0
 public static void DeleteIfNotRefered(PLMPackEntities db, int id)
 {
     if (0 == db.TreeNodes.Count(tn => tn.ThumbnailId == id))
     {
         Thumbnail thumb = db.Thumbnails.Single(tb => tb.Id == id);
         // delete thumbnail
         string fileGuid = thumb.FileGuid;
         db.Thumbnails.Remove(thumb);
         db.SaveChanges();
         // delete file
         File f = File.GetById(db, Guid.Parse(fileGuid));
         f.Delete(db);
     }
 }
Beispiel #11
0
        public static Thumbnail CreateNew(PLMPackEntities db, Guid fileGuid)
        {
            File      f  = File.GetById(db, fileGuid);
            Thumbnail tb = new Thumbnail()
            {
                Width = 150, Height = 150, FileGuid = fileGuid.ToString(), MimeType = Ext2MimeType(f.Extension)
            };

            db.Thumbnails.Add(tb);
            db.SaveChanges();

            int tid = tb.Id;

            return(db.Thumbnails.Single(t => t.Id == tid));
        }
Beispiel #12
0
        public void Delete(PLMPackEntities db)
        {
            string documentId = this.DocumentId;

            // remove TreeNodeDocuments
            db.TreeNodeDocuments.Remove(this);
            db.SaveChanges();
            // delete document
            Document doc = Document.GetByID(db, documentId);

            if (null != doc)
            {
                doc.Delete(db);
            }
        }
Beispiel #13
0
        public static Component CreateNew(PLMPackEntities db, string grpId
                                          , string name, string description
                                          , Guid fileGuid, Guid compGuid)
        {
            Document  doc = Document.CreateNew(db, grpId, "DT_COMPONENT", name, description, fileGuid, "dll");
            Component cp  = new Component()
            {
                DocumentId = doc.Id, Guid = compGuid.ToString()
            };

            db.Components.Add(cp);
            db.SaveChanges();

            return(GetByGuid(db, compGuid));
        }
Beispiel #14
0
        public static Thumbnail CreateNew(PLMPackEntities db, Guid g, string ext)
        {
            // create thumbnail
            Thumbnail tb = new Thumbnail();

            tb.File     = File.CreateNew(db, g, ext);
            tb.Width    = 150;
            tb.Height   = 150;
            tb.MimeType = Ext2MimeType(ext);
            db.Thumbnails.Add(tb);
            db.SaveChanges();

            int tid = tb.Id;

            return(db.Thumbnails.Single(t => t.Id == tid));
        }
Beispiel #15
0
        public void Share(PLMPackEntities db, AspNetUser user, Group gp)
        {
            if (Group != user.CurrentGroup(db))
            {
                return;                                 // -> user not allowed to share
            }
            if (IsShared(gp))
            {
                return;                 // already shared with this group
            }
            TreeNodeGroupShare tngs = new PLMPackModel.TreeNodeGroupShare();

            tngs.TreeNodeId = Id;
            tngs.GroupId    = gp.Id;
            db.TreeNodeGroupShares.Add(tngs);
            db.SaveChanges();
        }
Beispiel #16
0
        public TreeNode InsertComponent(PLMPackEntities db, string grpId
                                        , string name, string description
                                        , Guid fileGuid, Guid compGuid
                                        , Thumbnail thumb)
        {
            // create TreeNode
            TreeNode tn = InsertBranch(db, grpId, name, description, thumb);
            // create component
            Component cp = Component.CreateNew(db, grpId, name, description, fileGuid, compGuid);

            // create treeNode document
            db.TreeNodeDocuments.Add(new TreeNodeDocument()
            {
                TreeNodeId = tn.Id, DocumentId = cp.DocumentId
            });
            db.SaveChanges();

            return(TreeNode.GetById(db, Guid.Parse(tn.Id)));
        }
Beispiel #17
0
        public static Document CreateNew(PLMPackEntities db, string groupId
                                         , string docType, string name, string description
                                         , Guid fileGuid, string fileExt)
        {
            // create document
            Document doc = new Document()
            {
                Id           = Guid.NewGuid().ToString(),
                Name         = name,
                Description  = description,
                DocumentType = docType,
                FileGuid     = fileGuid.ToString(),
                GroupId      = groupId
            };

            db.Documents.Add(doc);
            db.SaveChanges();
            return(doc);
        }
Beispiel #18
0
        public static CardboardFormat CreateNew(
            PLMPackEntities db, Group gp
            , string name, string description
            , double length, double width)
        {
            if (CardboardFormat.Exists(db, gp, name))
            {
                throw new ModelException(string.Format("Cardboad format {0} already exists.", name));
            }
            CardboardFormat cardboardFormat = new CardboardFormat();

            cardboardFormat.Group       = gp;
            cardboardFormat.Name        = name;
            cardboardFormat.Description = description;
            cardboardFormat.Length      = length;
            cardboardFormat.Width       = width;
            db.CardboardFormats.Add(cardboardFormat);
            db.SaveChanges();
            return(cardboardFormat);
        }
Beispiel #19
0
        public static CardboardProfile CreateNew(
            PLMPackEntities db, Group gp
            , string name, string description
            , string code, double thickness)
        {
            if (CardboardProfile.Exists(db, gp, name))
            {
                throw new ModelException(string.Format("Cardboard profile \'{0}\' already exist.", name));
            }
            CardboardProfile cp = new CardboardProfile();

            cp.Group       = gp;
            cp.Name        = name;
            cp.Description = description;
            cp.Code        = code;
            cp.Thickness   = thickness;
            db.CardboardProfiles.Add(cp);
            db.SaveChanges();
            return(cp);
        }
Beispiel #20
0
        private void InitializeUser(PLMPackEntities db)
        {
            if (string.IsNullOrEmpty(GroupId))
            {
                string userName = UserName;
                // create group using user name
                Group grp = Group.CreateNew(db
                                            , string.Format("{0}_grp", userName)                   // group name
                                            , string.Format("Default group of user {0}", userName) // group description
                                            , this                                                 // owner
                                            );
                // set as current group
                this.GroupId = grp.Id;
                db.SaveChanges();
                // add group of interest treeDiM
                Group grp_treeDiM = Group.GetByName(db, "treeDiM");
                if (null != grp_treeDiM)
                {
                    AddGroupOfInterest(db, grp_treeDiM);
                }
                // share user root node
                TreeNode tn = TreeNode.GetUserRootNode(db, this);
                tn.Share(db, this, Group.Everyone(db));

                if (null != grp_treeDiM)
                {
                    // copy cardboard formats from treeDiM group
                    CardboardFormat[] cardboardFormats = CardboardFormat.GetAll(db, grp_treeDiM);
                    foreach (CardboardFormat cf in cardboardFormats)
                    {
                        CardboardFormat.CreateNew(db, grp, cf.Name, cf.Description, cf.Length, cf.Width);
                    }
                    // copy cardboard profile from treeDiM group
                    CardboardProfile[] cardboardProfiles = CardboardProfile.GetAll(db, grp_treeDiM);
                    foreach (CardboardProfile cp in cardboardProfiles)
                    {
                        CardboardProfile.CreateNew(db, grp, cp.Name, cp.Description, cp.Code, cp.Thickness);
                    }
                }
            }
        }
Beispiel #21
0
 public void InsertParamDefaultValue(PLMPackEntities db, string grpId, string name, double value)
 {
     if (db.ParamDefaultComponents.Count(
             pdc => (pdc.ComponentGuid == Guid) && (pdc.GroupId == grpId) && (pdc.Name == name)) > 0)
     {
         ParamDefaultComponent paramDefValue = db.ParamDefaultComponents.Single(
             pdc => (pdc.ComponentGuid == Guid) && (pdc.GroupId == grpId) && (pdc.Name == name));
         paramDefValue.Value = value;
     }
     else
     {
         db.ParamDefaultComponents.Add(new ParamDefaultComponent()
         {
             ComponentGuid = Guid,
             GroupId       = grpId,
             Name          = name,
             Value         = value
         }
                                       );
     }
     db.SaveChanges();
 }
Beispiel #22
0
        public TreeNode InsertDocument(PLMPackEntities db, string grpId
                                       , string name, string description
                                       , string docType, Guid docGuid, string docExt
                                       , Thumbnail thumb)
        {
            // create TreeNode
            TreeNode tn = InsertBranch(db, grpId, name, description, thumb);
            // create document
            Document doc = Document.CreateNew(db, grpId
                                              , docType
                                              , name, description
                                              , docGuid, docExt);
            // create treeNode document
            TreeNodeDocument tnd = new TreeNodeDocument();

            tnd.TreeNodeId = tn.Id;
            tnd.DocumentId = doc.Id;
            db.TreeNodeDocuments.Add(tnd);
            db.SaveChanges();

            return(TreeNode.GetById(db, Guid.Parse(tn.Id)));
        }
Beispiel #23
0
        public static CardboardQuality CreateNew(PLMPackEntities db, Group gp
                                                 , string name, string description
                                                 , int profileId
                                                 , double surfacicMass, double rigidityX, double rigidityY
                                                 , double youngModulus, double ect)
        {
            if (CardboardQuality.Exists(db, gp, name))
            {
                throw new ModelException(string.Format("Cardboard quality \'{0}\' already exist.", name));
            }
            CardboardQuality cq = new CardboardQuality();

            cq.Name               = name;
            cq.Description        = description;
            cq.CardboardProfileId = profileId;
            cq.SurfacicMass       = surfacicMass;
            cq.RigidityX          = rigidityX;
            cq.RigidityY          = rigidityY;
            cq.YoungModulus       = youngModulus;
            cq.ECT = ect;
            db.CardboardQualities.Add(cq);
            db.SaveChanges();
            return(cq);
        }
Beispiel #24
0
 public DCCardboardProfile UpdateCardboardProfile(DCCardboardProfile cbProfile)
 {
     PLMPackEntities db = new PLMPackEntities();
     CardboardProfile cp = CardboardProfile.GetByID(db, cbProfile.ID);
     cp.Name = cbProfile.Name;
     cp.Description = cbProfile.Description;
     cp.Code = cbProfile.Code;
     cp.Thickness = cbProfile.Thickness;
     db.SaveChanges();
     return cbProfile;
 }
Beispiel #25
0
 public DCCardboadFormat UpdateCardboardFormat(DCCardboadFormat cbFormat)
 {
     PLMPackEntities db = new PLMPackEntities();
     CardboardFormat cf = CardboardFormat.GetById(db, cbFormat.ID);
     cf.Name = cbFormat.Name;
     cf.Description = cbFormat.Description;
     cf.Length = cbFormat.Length;
     cf.Width = cbFormat.Width;
     db.SaveChanges();
     return cbFormat;
 }
Beispiel #26
0
        public Dictionary <string, double> GetMajorationSet(PLMPackEntities db, CardboardProfile cp)
        {
            if (db.MajorationSets.Count(
                    mjs => (mjs.ComponentGuid == Guid) && (mjs.CardboardProfile.GroupId == cp.GroupId)) == 0)
            {
                try
                {
                    // dict majo
                    db.MajorationSets.Add(new MajorationSet()
                    {
                        ComponentGuid      = Guid,
                        CardboardProfileId = cp.Id
                    }
                                          );
                    db.SaveChanges();
                    // build list of majo
                    var           majoSets = db.MajorationSets.Where(mjs => (mjs.ComponentGuid == this.Guid) && (mjs.CardboardProfile.GroupId == this.Document.GroupId));
                    MajorationSet mjsNearest = null; double diffMax = double.MaxValue;
                    foreach (MajorationSet mjset in majoSets)
                    {
                        double thickness = mjset.CardboardProfile.Thickness;
                        if (Math.Abs(thickness - cp.Thickness) < diffMax)
                        {
                            mjsNearest = mjset;
                            diffMax    = Math.Abs(thickness - cp.Thickness);
                        }
                    }
                    MajorationSet mjsCurrent       = MajorationSet.Single(mjs => (mjs.ComponentGuid == this.Guid) && (mjs.CardboardProfileId == cp.Id));
                    double        thicknessNearest = mjsNearest.CardboardProfile.Thickness;
                    foreach (Majoration mj in mjsNearest.Majorations)
                    {
                        db.Majorations.Add(
                            new Majoration()
                        {
                            MajorationSetId = mjsCurrent.Id,
                            Name            = mj.Name,
                            Value           = mj.Value * cp.Thickness / thicknessNearest
                        }
                            );
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            var majorationSets = db.MajorationSets.Where(mjs => (mjs.ComponentGuid == this.Guid) && (mjs.CardboardProfile.GroupId == this.Document.GroupId));

            // find nearest set
            MajorationSet nearestSet = null;

            foreach (MajorationSet majoSet in majorationSets)
            {
                if (null == nearestSet ||
                    (Math.Abs(majoSet.CardboardProfile.Thickness - cp.Thickness) < Math.Abs(nearestSet.CardboardProfile.Thickness - cp.Thickness))
                    )
                {
                    nearestSet = majoSet;
                }
            }

            // build dictionnary
            Dictionary <string, double> dictMajo = new Dictionary <string, double>();

            if (null != nearestSet)
            {
                double coef = (double)(cp.Thickness / nearestSet.CardboardProfile.Thickness);
                dictMajo.Add("th1", cp.Thickness);
                dictMajo.Add("ep1", cp.Thickness);
                foreach (Majoration maj in nearestSet.Majorations)
                {
                    double valueMaj = maj.Value * coef;
                    if (Math.Abs(coef - 1.0) > 1.0e-3)
                    {
                        MajoRounding rounding = MajoRounding.ROUDING_FIRSTDECIMALNEAREST;
                        switch (rounding)
                        {
                        case MajoRounding.ROUDING_FIRSTDECIMALNEAREST:
                            valueMaj = Math.Round(valueMaj * 10) / 10.0;
                            break;

                        case MajoRounding.ROUNDING_HALFNEAREST:
                            valueMaj = Math.Round(valueMaj * 2) / 2.0;
                            break;

                        case MajoRounding.ROUNDING_HALFTOP:
                            valueMaj = Math.Ceiling(valueMaj * 2) / 2;
                            break;

                        case MajoRounding.ROUDING_INT:
                            valueMaj = Math.Round(valueMaj);
                            break;

                        default:
                            break;     // no rounding
                        }
                    }
                    dictMajo.Add(maj.Name, valueMaj);
                }
            }
            return(dictMajo);
        }
Beispiel #27
0
 public void Delete(PLMPackEntities db)
 {
     db.CardboardFormats.Remove(this);
     db.SaveChanges();
 }
Beispiel #28
0
 public void Delete(PLMPackEntities db)
 {
     // remove all cardboard quality
     db.CardboardQualities.Remove(this);
     db.SaveChanges();
 }
Beispiel #29
0
 public void SetCurrentGroup(PLMPackEntities db, Group gp)
 {
     GroupId = gp.Id;
     db.SaveChanges();
 }