Exemple #1
0
        /// <summary>
        /// Take a dictionary, inspect the inner types of the resultant anonymous object, and make a DataTable object.
        /// </summary>
        /// <param name="d">A Dictionary<string, Part> of Part values, with their name as keys.</param>
        /// <param name="cd">An active CutlistData object.</param>
        /// <returns>A DataTable object.</returns>
        private static DataTable DictToPartList(Dictionary <string, Part> d, CutlistData cd)
        {
            List <object> lp = new List <object>();
            DataTable     dt = new DataTable();

            foreach (KeyValuePair <string, Part> p in d)
            {
                Part i = p.Value;
                var  o = new {
                    Part        = i.PartNumber,
                    Description = i.Description,
                    Qty         = i.Qty,
                    Material    = cd.GetMaterialByID(i.MaterialID.ToString()),
                    L           = i.Length,
                    W           = i.Width,
                    T           = i.Thickness,
                    BlankQty    = i.BlankQty,
                    OverL       = i.OverL,
                    OverW       = i.OverW,
                    CNC1        = i.CNC1,
                    CNC2        = i.CNC2,
                    Op1         = cd.GetOpAbbreviationByID(i.get_OpID(0).ToString()),
                    Op2         = cd.GetOpAbbreviationByID(i.get_OpID(1).ToString()),
                    Op3         = cd.GetOpAbbreviationByID(i.get_OpID(2).ToString()),
                    Op4         = cd.GetOpAbbreviationByID(i.get_OpID(3).ToString()),
                    Op5         = cd.GetOpAbbreviationByID(i.get_OpID(4).ToString()),
                    EdgeFront   = cd.GetEdgeByID(i.EdgeFrontID.ToString()),
                    EdgeBack    = cd.GetEdgeByID(i.EdgeBackID.ToString()),
                    EdgeLeft    = cd.GetEdgeByID(i.EdgeLeftID.ToString()),
                    EdgeRight   = cd.GetEdgeByID(i.EdgeRightID.ToString()),
                    Comment     = i.Comment,
                    Deptartment = cd.GetDeptByID((int)i.DepartmentID),
                    Update      = i.UpdateCNC ? "Yes" : "No"
                };
                lp.Add(o);
            }

            // Wow, reflection! Fancy! C++ can't do this (yet).
            System.Reflection.PropertyInfo[] props = lp[0].GetType().GetProperties();
            foreach (var prop in props)
            {
                dt.Columns.Add(prop.Name);
            }

            foreach (var item in lp)
            {
                var values = new object[props.Length];
                for (var i = 0; i < props.Length; i++)
                {
                    values[i] = props[i].GetValue(item, null);
                }
                dt.Rows.Add(values);
            }

            return(dt);
        }
        /// <summary>
        /// Directly draws from SW, assinging SwApp. Why do I have all these?
        /// </summary>
        /// <param name="md">A ModelDoc2.</param>
        /// <param name="cd">The Cutlist handler.</param>
        public void Get2(ModelDoc2 md, CutlistData cd)
        {
            Configuration cf = md.ConfigurationManager.ActiveConfiguration;

              CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
              CustomPropertyManager scpm;

              bool wasResolved;
              bool useCached = false;
              string tempval = string.Empty;
              string tempresval = string.Empty;

              if (cf != null) {
            scpm = md.Extension.get_CustomPropertyManager(cf.Name);
              } else {
            scpm = md.Extension.get_CustomPropertyManager(string.Empty);
              }
              int res;

              if (this.Global) {
            res = gcpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
            if (res == (int)swCustomInfoGetResult_e.swCustomInfoGetResult_NotPresent) {
              Value = tempval;
              ResValue = tempresval;
              Type = (swCustomInfoType_e)gcpm.GetType2(this.Name);
            } else { // check in wrong place; sometimes it's there.
              res = scpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
              if (wasResolved) {
            Value = tempval;
            ResValue = tempresval;
            Type = (swCustomInfoType_e)gcpm.GetType2(this.Name);
              }
            }

            if (Type == swCustomInfoType_e.swCustomInfoNumber && Name.ToUpper().Contains("OVER"))
              Type = swCustomInfoType_e.swCustomInfoDouble;

            if (this.Name.Contains("OP")) {
              int tp = 0;

              if (int.TryParse(this._value, out tp)) {
            ID = _resValue;
            _descr = cd.GetOpAbbreviationByID(_resValue);
              } else {
            ID = cd.GetOpIDByName(_resValue).ToString();
              }
            }
              } else {
            res = scpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
            if (wasResolved) {
              Value = tempval;
              ResValue = tempresval;
              Type = (swCustomInfoType_e)scpm.GetType2(this.Name);
            }
            if (Name.ToUpper().Contains("CUTLIST MATERIAL")) {
              int tp = 0;
              if (int.TryParse(_value, out tp)) {
            ID = _resValue;
            _value = cd.GetMaterialByID(_resValue);
              } else {
            ID = cd.GetMaterialID(_value).ToString();
              }
            }

            if (Name.ToUpper().Contains("EDGE")) {
              int tp = 0;
              if (int.TryParse(_value, out tp)) {
            ID = _resValue;
            _value = cd.GetEdgeByID(_resValue);
              } else {
            ID = cd.GetEdgeID(_value).ToString();
              }
            }
              }
        }
        /// <summary>
        /// Directly draws from SW, assinging SwApp. Why do I have all these?
        /// </summary>
        /// <param name="md">A ModelDoc2.</param>
        /// <param name="cd">The Cutlist handler.</param>
        public void Get(ModelDoc2 md, CutlistData cd)
        {
            Configuration cf = md.ConfigurationManager.ActiveConfiguration;

              CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
              CustomPropertyManager scpm;

              bool wasResolved;
              bool useCached = false;
              string tempval = string.Empty;
              string tempresval = string.Empty;

              if (cf != null) {
            scpm = md.Extension.get_CustomPropertyManager(cf.Name);
              } else {
            scpm = md.Extension.get_CustomPropertyManager(string.Empty);
              }

              if (SWCustPropMgr != null) {
            scpm = SWCustPropMgr;
              }

              int res;

              res = scpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);

              if (res == (int)swCustomInfoGetResult_e.swCustomInfoGetResult_NotPresent ||
            tempval == string.Empty) {
            res = gcpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
            if (tempval != string.Empty) {
              Value = tempval;
              ResValue = tempresval;
            }
              } else {
            Value = tempval;
            ResValue = tempresval;
              }

              if (Name.ToUpper().Contains("CUTLIST MATERIAL") || Name.ToUpper().Contains("CLID")) {
            int tp = 0;
            if (int.TryParse(Value, out tp)) {
              ID = Value;
              Descr = cd.GetMaterialByID(Value);
              Value = ID;
            } else {
              ID = cd.GetMaterialID(Value).ToString();
              Descr = Value;
            }
              }

              if (Name.Contains("OP")) {
            int tp = 0;
            if (int.TryParse(Value, out tp)) {
              ID = Value;
              Descr = cd.GetOpAbbreviationByID(Value);
            } else {
              ID = cd.GetOpIDByName(Value).ToString();
              Descr = Value;
            }
              }

              if (Name.ToUpper().Contains("EDGE") || (Name.ToUpper().StartsWith("E") && Name.ToUpper().EndsWith("ID"))) {
            int tp = 0;
            if (int.TryParse(Value, out tp)) {
              ID = Value;
              Descr = cd.GetEdgeByID(Value);
            } else {
              ID = cd.GetEdgeID(Value).ToString();
              Descr = Value;
            }
              }
        }
        /// <summary>
        /// Directly draws from SW, assinging SwApp. Why do I have all these?
        /// </summary>
        /// <param name="md">A ModelDoc2.</param>
        /// <param name="cd">The Cutlist handler.</param>
        public void Get2(ModelDoc2 md, CutlistData cd)
        {
            Configuration cf = md.ConfigurationManager.ActiveConfiguration;

            CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
            CustomPropertyManager scpm;

            bool   wasResolved;
            bool   useCached  = false;
            string tempval    = string.Empty;
            string tempresval = string.Empty;

            if (cf != null)
            {
                scpm = md.Extension.get_CustomPropertyManager(cf.Name);
            }
            else
            {
                scpm = md.Extension.get_CustomPropertyManager(string.Empty);
            }
            int res;

            if (this.Global)
            {
                res = gcpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
                if (res == (int)swCustomInfoGetResult_e.swCustomInfoGetResult_NotPresent)
                {
                    Value    = tempval;
                    ResValue = tempresval;
                    Type     = (swCustomInfoType_e)gcpm.GetType2(this.Name);
                }
                else // check in wrong place; sometimes it's there.
                {
                    res = scpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
                    if (wasResolved)
                    {
                        Value    = tempval;
                        ResValue = tempresval;
                        Type     = (swCustomInfoType_e)gcpm.GetType2(this.Name);
                    }
                }

                if (Type == swCustomInfoType_e.swCustomInfoNumber && Name.ToUpper().Contains("OVER"))
                {
                    Type = swCustomInfoType_e.swCustomInfoDouble;
                }

                if (this.Name.Contains("OP"))
                {
                    int tp = 0;

                    if (int.TryParse(this._value, out tp))
                    {
                        ID     = _resValue;
                        _descr = cd.GetOpAbbreviationByID(_resValue);
                    }
                    else
                    {
                        ID = cd.GetOpIDByName(_resValue).ToString();
                    }
                }
            }
            else
            {
                res = scpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
                if (wasResolved)
                {
                    Value    = tempval;
                    ResValue = tempresval;
                    Type     = (swCustomInfoType_e)scpm.GetType2(this.Name);
                }
                if (Name.ToUpper().Contains("CUTLIST MATERIAL"))
                {
                    int tp = 0;
                    if (int.TryParse(_value, out tp))
                    {
                        ID     = _resValue;
                        _value = cd.GetMaterialByID(_resValue);
                    }
                    else
                    {
                        ID = cd.GetMaterialID(_value).ToString();
                    }
                }

                if (Name.ToUpper().Contains("EDGE"))
                {
                    int tp = 0;
                    if (int.TryParse(_value, out tp))
                    {
                        ID     = _resValue;
                        _value = cd.GetEdgeByID(_resValue);
                    }
                    else
                    {
                        ID = cd.GetEdgeID(_value).ToString();
                    }
                }
            }
        }
        /// <summary>
        /// Directly draws from SW, assinging SwApp. Why do I have all these?
        /// </summary>
        /// <param name="md">A ModelDoc2.</param>
        /// <param name="cd">The Cutlist handler.</param>
        public virtual void Get(ModelDoc2 md, CutlistData cd)
        {
            Configuration cf = md.ConfigurationManager.ActiveConfiguration;

            CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
            CustomPropertyManager scpm;

            bool   wasResolved;
            bool   useCached  = false;
            string tempval    = string.Empty;
            string tempresval = string.Empty;

            if (cf != null)
            {
                scpm = md.Extension.get_CustomPropertyManager(cf.Name);
            }
            else
            {
                scpm = md.Extension.get_CustomPropertyManager(string.Empty);
            }

            if (SWCustPropMgr != null)
            {
                scpm = SWCustPropMgr;
            }

            int res;

            res = scpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);

            if (res == (int)swCustomInfoGetResult_e.swCustomInfoGetResult_NotPresent ||
                tempval == string.Empty)
            {
                res = gcpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
                if (tempval != string.Empty)
                {
                    Value    = tempval;
                    ResValue = tempresval;
                }
            }
            else
            {
                Value    = tempval;
                ResValue = tempresval;
            }

            if (Name.ToUpper().Contains("CUTLIST MATERIAL") || Name.ToUpper().Contains("CLID"))
            {
                int tp = 0;
                if (int.TryParse(Value, out tp))
                {
                    ID    = Value;
                    Descr = cd.GetMaterialByID(Value);
                    Value = ID;
                }
                else
                {
                    ID    = cd.GetMaterialID(Value).ToString();
                    Descr = Value;
                }
            }

            if (Name.Contains("OP"))
            {
                int tp = 0;
                if (int.TryParse(Value, out tp))
                {
                    ID    = Value;
                    Descr = cd.GetOpAbbreviationByID(Value);
                }
                else
                {
                    ID    = cd.GetOpIDByName(Value).ToString();
                    Descr = Value;
                }
            }

            if (Name.ToUpper().Contains("EDGE") || (Name.ToUpper().StartsWith("E") && Name.ToUpper().EndsWith("ID")))
            {
                int tp = 0;
                if (int.TryParse(Value, out tp))
                {
                    ID    = Value;
                    Descr = cd.GetEdgeByID(Value);
                }
                else
                {
                    ID    = cd.GetEdgeID(Value).ToString();
                    Descr = Value;
                }
            }
        }
        /// <summary>
        /// Take a dictionary, inspect the inner types of the resultant anonymous object, and make a DataTable object.
        /// </summary>
        /// <param name="d">A Dictionary<string, Part> of Part values, with their name as keys.</param>
        /// <param name="cd">An active CutlistData object.</param>
        /// <returns>A DataTable object.</returns>
        private static DataTable DictToPartList(Dictionary<string, Part> d, CutlistData cd)
        {
            List<object> lp = new List<object>();
              DataTable dt = new DataTable();
              foreach (KeyValuePair<string, Part> p in d) {
            Part i = p.Value;
            var o = new {
              Part = i.PartNumber,
              Description = i.Description,
              Qty = i.Qty,
              Material = cd.GetMaterialByID(i.MaterialID.ToString()),
              L = i.Length,
              W = i.Width,
              T = i.Thickness,
              BlankQty = i.BlankQty,
              OverL = i.OverL,
              OverW = i.OverW,
              CNC1 = i.CNC1,
              CNC2 = i.CNC2,
              Op1 = cd.GetOpAbbreviationByID(i.get_OpID(0).ToString()),
              Op2 = cd.GetOpAbbreviationByID(i.get_OpID(1).ToString()),
              Op3 = cd.GetOpAbbreviationByID(i.get_OpID(2).ToString()),
              Op4 = cd.GetOpAbbreviationByID(i.get_OpID(3).ToString()),
              Op5 = cd.GetOpAbbreviationByID(i.get_OpID(4).ToString()),
              EdgeFront = cd.GetEdgeByID(i.EdgeFrontID.ToString()),
              EdgeBack = cd.GetEdgeByID(i.EdgeBackID.ToString()),
              EdgeLeft = cd.GetEdgeByID(i.EdgeLeftID.ToString()),
              EdgeRight = cd.GetEdgeByID(i.EdgeRightID.ToString()),
              Comment = i.Comment,
              Deptartment = cd.GetDeptByID((int)i.DepartmentID),
              Update = i.UpdateCNC ? "Yes" : "No"
            };
            lp.Add(o);
              }

              // Wow, reflection! Fancy! C++ can't do this (yet).
              System.Reflection.PropertyInfo[] props = lp[0].GetType().GetProperties();
              foreach (var prop in props) {
            dt.Columns.Add(prop.Name);
              }

              foreach (var item in lp) {
            var values = new object[props.Length];
            for (var i = 0; i < props.Length; i++) {
              values[i] = props[i].GetValue(item, null);
            }
            dt.Rows.Add(values);
              }

              return dt;
        }