Ejemplo n.º 1
0
        public static bool SaveChanges(this MDPart part, EplPartProperties eplPartProperties)
        {
            try
            {
                part.GenericProductGroup = MDPartsDatabaseItem.Enums.ProductTopGroup.Electric;
                part.ProductGroup        = MDPartsDatabaseItem.Enums.ProductGroup.Common;
                part.ProductSubGroup     = MDPartsDatabaseItem.Enums.ProductSubGroup.Common;

                part.Properties.ARTICLE_SUPPLIER          = eplPartProperties.Supplier;
                part.Properties.ARTICLE_NOTE              = eplPartProperties.Description;
                part.Properties.ARTICLE_MANUFACTURER      = eplPartProperties.Manufacturer;
                part.Properties.ARTICLE_ORDERNR           = eplPartProperties.OrderNumber;
                part.Properties.ARTICLE_QUANTITYUNIT      = eplPartProperties.Unit;
                part.Properties.ARTICLE_PACKAGINGQUANTITY = eplPartProperties.Quantity;
                part.Properties.ARTICLE_MACRO             = eplPartProperties.Macro;

                if (eplPartProperties.PartFreeProperties != null)
                {
                    for (int i = 0; i < eplPartProperties.PartFreeProperties.Count; i++)
                    {
                        part.Properties.ARTICLE_FREE_DATA_DESCRIPTION[i + 1] = eplPartProperties.PartFreeProperties[i].Description;
                        part.Properties.ARTICLE_FREE_DATA_VALUE[i + 1]       = eplPartProperties.PartFreeProperties[i].Value;
                        part.Properties.ARTICLE_FREE_DATA_UNIT[i + 1]        = eplPartProperties.PartFreeProperties[i].Unit;
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Save part", ex);
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void panel_Symbol_Paint(object sender, PaintEventArgs e)
        {
            if (this.MvProject.Project == null)
            {
                return;
            }
            if (dataGridView2.CurrentRow == null || dataGridView2.CurrentRow.Cells["PartNr"].Value == null)
            {
                return;
            }

            string          partNr = dataGridView2.CurrentRow.Cells["PartNr"].Value.ToString();
            MDPartsDatabase mdb    = Util.eplan.GetPartMaster();
            MDPart          part   = mdb.GetPart(partNr);

            if (part == null)
            {
                return;
            }

            string filePath = PathMap.SubstitutePath(part.Properties.ARTICLE_GROUPSYMBOLMACRO.ToString());

            if (!File.Exists(filePath))
            {
                return;
            }

            int variant = 0;

            if (panel_Symbol.Tag != null)
            {
                variant = (int)panel_Symbol.Tag;
            }

            try
            {
                WindowMacro wm = new WindowMacro();
                wm.Open(filePath, this.MvProject.Project);
                wm.RepresentationType = WindowMacro.Enums.RepresentationType.SingleLine;

                if (wm.ExistVariant(WindowMacro.Enums.RepresentationType.SingleLine, variant))
                {
                    wm.Variant = variant;
                }
                else
                {
                    panel_Symbol.Tag = wm.Variant = 0;
                }

                DrawingService ds = new DrawingService();
                ds.MacroPreview = false;
                ds.CenterView   = true;
                ds.CreateDisplayList(wm);
                ds.DrawDisplayList(e);
            }
            catch
            {
                //MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }
Ejemplo n.º 3
0
        public static MDPart SelectPartWithGui()
        {
            EplApplication    eplanApplication = new EplApplication();
            MDPartsManagement partsManagement  = new MDPartsManagement();
            string            partnNumber      = string.Empty;
            string            partVariant      = string.Empty;

            eplanApplication.ShowPartSelectionDialog(ref partnNumber, ref partVariant);
            MDPartsDatabase partsDatabase = partsManagement.OpenDatabase();
            MDPart          part          = partsDatabase.GetPart(partnNumber, partVariant);

            return(part);
        }
Ejemplo n.º 4
0
        public static MDPart CreatePart(ArticleReference articleReference)
        {
            // Need to lock project
            var project = articleReference.Project;

            project.SmartLock();
            if (articleReference.ParentObject != null)
            {
                articleReference.ParentObject.SmartLock();
            }
            articleReference.SmartLock();

            // Init
            var partsDatabase = new MDPartsManagement().OpenDatabase();

            articleReference.SmartLock();
            var    partNr      = articleReference.PartNr;
            var    partVariant = articleReference.VariantNr;
            MDPart part        = partsDatabase.GetPart(partNr, partVariant);

            // Create new part
            if (part == null)
            {
                articleReference.SmartLock();
                // ReSharper disable once RedundantAssignment
                part = partsDatabase.AddPart(partNr, partVariant);
                using (new LockingUtility.SeplaLockingVector())
                {
                    new EplApplication().ShowPartSelectionDialog(ref partNr, ref partVariant);
                }
                partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part
                part          = partsDatabase.GetPart(partNr, partVariant);
            }

            // Load data
            var article = project.Articles
                          .FirstOrDefault(obj =>
                                          obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant)
                                          );

            if (article != null)
            {
                article.SmartLock();
                article.LoadFromMasterdata();
            }

            return(part);
        }
Ejemplo n.º 5
0
        public static MDPart CreatePart(ArticleReference articleReference)
        {
            // Need to lock project
            var project = articleReference.Project;

            project.SmartLock();
            if (articleReference.ParentObject != null)
            {
                articleReference.ParentObject.SmartLock();
            }
            articleReference.SmartLock();

            // Init
            var partsDatabase = new MDPartsManagement().OpenDatabase();

            //var articleReference = function.ArticleReferences.First();
            articleReference.SmartLock();
            var    partNr      = articleReference.PartNr;
            var    partVariant = articleReference.VariantNr;
            MDPart part        = partsDatabase.GetPart(partNr, partVariant);

            // Create new part
            if (part == null)
            {
                part = partsDatabase.AddPart(partNr, partVariant);

                // PartSelection to edit data
                new EplApplication().ShowPartSelectionDialog(ref partNr, ref partVariant);

                //partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part
                //part = partsDatabase.GetPart(partNr, partVariant);
            }

            // Load data
            var article = project.Articles
                          .FirstOrDefault(obj =>
                                          obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant)
                                          );

            if (article != null)
            {
                article.SmartLock();
                article.LoadFromMasterdata();
            }

            return(part);
        }
Ejemplo n.º 6
0
        public void AddAttribite(MDPart part, string category, string subCategory)
        {
            try
            {
                using (OleDbConnection connection = new OleDbConnection(this.ConnectionString))
                {
                    connection.Open();
                    category    = category.Replace("\'", "\'\'");
                    subCategory = subCategory.Replace("\'", "\'\'");

                    string selectQuery = "SELECT id, partnr, description1, manufacturer, graphicmacro, groupsymbolmacro FROM tblPart "
                                         + "WHERE partnr ='" + part.PartNr + "'";

                    OleDbCommand    command = new OleDbCommand(selectQuery, connection);
                    OleDbDataReader reader  = command.ExecuteReader();
                    if (!reader.Read())
                    {
                        MessageBox.Show(part.PartNr + " 부품을 찾을 수 없습니다.");
                        return;
                    }

                    string id = reader[0].ToString();

                    command = new OleDbCommand(selectQuery, connection);
                    string insertQuery = "INSERT INTO tblAttribute VALUES(1, " + id + ", 11, '" + category + "')";
                    command.CommandText = insertQuery;
                    command.ExecuteNonQuery();

                    insertQuery         = "INSERT INTO tblAttribute VALUES(1, " + id + ", 12, '" + subCategory + "')";
                    command.CommandText = insertQuery;
                    command.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }
Ejemplo n.º 7
0
        public static MDPart CreateOrUpdatePart(ArticleReference articleReference, bool updateFunctionTemplate)
        {
            // Need to lock project
            var project = articleReference.Project;

            project.SmartLock();
            //if (articleReference.ParentObject != null) articleReference.ParentObject.SmartLock();
            articleReference.SmartLock();

            // Init
            var partsDatabase = new MDPartsManagement().OpenDatabase();

            //var articleReference = function.ArticleReferences.First();
            articleReference.SmartLock();
            var    partNr      = articleReference.PartNr;
            var    partVariant = articleReference.VariantNr;
            MDPart part        = partsDatabase.GetPart(partNr, partVariant);

            // Check if article is in project and remove, because the eplan action to create is not possible
            var existingArticle = project.Articles
                                  .FirstOrDefault(obj =>
                                                  obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant)
                                                  );

            if (existingArticle != null)
            {
                existingArticle.SmartLock();
                existingArticle.Remove();
            }

            // Need to focus again if its lost
            if (articleReference.ParentObject is Placement placementToBringInFront)
            {
                new Edit().BringToFront(placementToBringInFront);
            }

            // Create new part
            if (part == null)
            {
                // LockingVector is needed because of locking exception from EPLAN action (no catch possible)
                using (new LockingUtility.SeplaLockingVector())
                {
                    new CommandLineInterpreter().Execute("XPameCreateType");
                }

                partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part
                part          = partsDatabase.GetPart(partNr, partVariant);
            }
            // Existing part
            else
            {
                // Check if pro panel, because there is no update possible
                bool isProPanel = articleReference.ParentObject is Component;

                string partNrTemp = partNr;
                if (!isProPanel)
                {
                    // Rename part
                    string suffix = "_temp";
                    partNrTemp = part.PartNr + suffix;
                    try
                    {
                        articleReference.PartNr = partNrTemp;
                        articleReference.ParentObject.SmartLock();
                        articleReference.StoreToObject();

                        // Quiet create temp part
                        var application = new EplApplication();
                        var quiteMode   = application.QuietMode;
                        application.QuietMode = EplApplication.QuietModes.ShowNoDialogs;
                        using (new LockingUtility.SeplaLockingVector())
                        {
                            new CommandLineInterpreter().Execute("XPameCreateType");
                        }
                        application.QuietMode = quiteMode;
                    }
                    finally
                    {
                        // Rename back
                        articleReference.PartNr = partNr;
                        articleReference.StoreToObject();
                    }

                    // Copy FunctionTemplate
                    if (updateFunctionTemplate)
                    {
                        partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part
                        MDPart partDuplicate = partsDatabase.GetPart(partNrTemp, partVariant);
                        foreach (var partFunctionTemplatePosition in part.FunctionTemplatePositions)
                        {
                            part.RemoveFunctionTemplatePosition(partFunctionTemplatePosition);
                        }
                        foreach (var partDuplicateFunctionTemplatePosition in partDuplicate.FunctionTemplatePositions)
                        {
                            part.AddFunctionTemplatePosition(partDuplicateFunctionTemplatePosition);
                        }
                        partsDatabase.RemovePart(partDuplicate);
                    }
                }


                // Check if article is in project
                var existingTempArticle = project.Articles
                                          .FirstOrDefault(obj =>
                                                          obj.PartNr.Equals(partNrTemp) && obj.VariantNr.Equals(partVariant)
                                                          );
                if (existingTempArticle != null)
                {
                    existingTempArticle.SmartLock();
                    existingTempArticle.Remove();
                }
            }

            // Load data
            var article = project.Articles
                          .FirstOrDefault(obj =>
                                          obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant)
                                          );

            if (article != null)
            {
                article.SmartLock();
                article.LoadFromMasterdata();
            }

            return(part);
        }
Ejemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!this.IsValidPartNr())
            {
                MessageBox.Show("부품 종류와 부품 번호를 입력해야 합니다.");
                return;
            }

            string partNr           = comboBox4.Text;
            string category         = comboBox1.Text;
            string subCategory      = comboBox2.Text;
            string maker            = comboBox3.Text;
            string description1     = comboBox5.Text;
            string note             = textBox1.Text;
            string groupSymbolMacro = textBox2.Text;

            MDPartsManagement pm       = new MDPartsManagement();
            MDPartsDatabase   database = pm.OpenDatabase();
            MDPart            mdPart   = database.GetPart(partNr);

            if (mdPart != null)
            {
                MessageBox.Show(partNr + " 부품이 있습니다.");
                return;
            }

            DialogResult dr = MessageBox.Show(partNr + " 부품을 생성합니다.", "부품 생성 확인", MessageBoxButtons.OKCancel);

            if (DialogResult.OK != dr)
            {
                return;
            }


            Data.Mdb mdb        = Data.MdbFactory.GetUniqueInstance;
            string[] attributes = mdb.GetAttribute(comboBox1.Text, comboBox2.Text);


            mdPart = database.AddPart(partNr);
            if (mdPart == null)
            {
                MessageBox.Show(mdPart.PartNr + " 부품이 생성이 실패했습니다.");
                return;
            }

            mdPart.Variant = "0";
            mdPart.Properties.ARTICLE_PRODUCTGROUP     = attributes[0];
            mdPart.Properties.ARTICLE_PRODUCTSUBGROUP  = attributes[1];
            mdPart.Properties.ARTICLE_PRODUCTTOPGROUP  = attributes[2];
            mdPart.Properties.ARTICLE_MANUFACTURER     = maker.Trim().Length == 0 ? " " : maker;
            mdPart.Properties.ARTICLE_TYPENR           = partNr;
            mdPart.Properties.ARTICLE_NOTE             = note;
            mdPart.Properties.ARTICLE_GROUPSYMBOLMACRO = groupSymbolMacro;

            MultiLangString mls = new MultiLangString();

            mls.AddString(ISOCode.Language.L___, description1);
            mdPart.Properties.ARTICLE_DESCR1 = mls;

            mdb.AddAttribite(mdPart, category, subCategory);

            MessageBox.Show(mdPart.PartNr + " 부품이 생성되었습니다.");
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Project"></param>
        /// <param name="eplPartProperties"></param>
        /// <returns>true if successed</returns>
        public bool InsertPart(EplPartProperties eplPartProperties, PartAction action)
        {
            try
            {
                MDPart part = GetPart(eplPartProperties.PartNumber);

                if (part != null)
                {
                    switch (action)
                    {
                    case PartAction.OVERRIDE:
                        PartsDataBase.RemovePart(part);
                        part = AddPart(eplPartProperties.PartNumber);
                        break;

                    case PartAction.UPDATE:
                        break;

                    case PartAction.SKIP:
                        return(true);
                    }
                }
                else
                {
                    part = AddPart(eplPartProperties.PartNumber);
                }

                if (part == null)
                {
                    Logger.WriteLine("Add new part failed.");
                    return(false);
                }

                part.GenericProductGroup = MDPartsDatabaseItem.Enums.ProductTopGroup.Electric;
                part.ProductGroup        = MDPartsDatabaseItem.Enums.ProductGroup.Common;
                part.ProductSubGroup     = MDPartsDatabaseItem.Enums.ProductSubGroup.Common;

                part.Properties.ARTICLE_SUPPLIER          = eplPartProperties.Supplier;
                part.Properties.ARTICLE_NOTE              = eplPartProperties.Description;
                part.Properties.ARTICLE_MANUFACTURER      = eplPartProperties.Manufacturer;
                part.Properties.ARTICLE_ORDERNR           = eplPartProperties.OrderNumber;
                part.Properties.ARTICLE_QUANTITYUNIT      = eplPartProperties.Unit;
                part.Properties.ARTICLE_PACKAGINGQUANTITY = eplPartProperties.Quantity;
                part.Properties.ARTICLE_MACRO             = eplPartProperties.Macro;
                part.Properties.ARTICLE_CHARACTERISTICS   = eplPartProperties.Characteristic;
                part.Properties.ARTICLE_PACKAGINGPRICE_1  = eplPartProperties.Price;
                part.Properties.ARTICLE_REPORT_SYMBOL[1]  = eplPartProperties.Symbol;
                part.Properties.ARTICLE_GROUPNUMBER       = eplPartProperties.PartGroup;

                part.Properties.ARTICLE_VOLTAGE                = eplPartProperties.Voltage;
                part.Properties.ARTICLE_VOLTAGETYPE            = eplPartProperties.VoltageType;
                part.Properties.ARTICLE_ELECTRICALCURRENT      = eplPartProperties.Current;
                part.Properties.ARTICLE_TRIGGERCURRENT         = eplPartProperties.TrippingCurrent;
                part.Properties.ARTICLE_CONNECTIONCROSSSECTION = eplPartProperties.ConnectionPointCrossSection;
                part.Properties.ARTICLE_ELECTRICALPOWER        = eplPartProperties.SwitchingCapacity;
                part.Properties.ARTICLE_POWERDISSIPATION       = eplPartProperties.MaxPowerDissipation;

                if (eplPartProperties.PartFreeProperties != null)
                {
                    for (int i = 0; i < eplPartProperties.PartFreeProperties.Count; i++)
                    {
                        part.Properties.ARTICLE_FREE_DATA_DESCRIPTION[i + 1] = eplPartProperties.PartFreeProperties[i].Description;
                        part.Properties.ARTICLE_FREE_DATA_VALUE[i + 1]       = eplPartProperties.PartFreeProperties[i].Value;
                        part.Properties.ARTICLE_FREE_DATA_UNIT[i + 1]        = eplPartProperties.PartFreeProperties[i].Unit;
                    }
                }

                Logger.WriteLine($"Create part: {eplPartProperties.PartNumber} successfully.");
                return(true);
            }
            catch (Exception e)
            {
                OnExceptionThrown?.Invoke($"Insert Part {eplPartProperties.PartNumber} error.");
                Logger.WriteLine("InsertPart error.", e);
                return(false);
            }
        }