Beispiel #1
0
 /// <summary>
 /// getDoc(name) - get Document name - when nor read yet - from the file. If necessary - Create new Sheet
 /// </summary>
 /// <param name="name">Document name</param>
 /// <param name="fatal">FATAL if this flag = true; else - return null if Document doesnt exists</param>
 /// <returns>Document or null</returns>
 /// <returns>Document</returns>
 /// <history> 25.12.2013 отлажено
 /// 25.12.2013 - чтение из файла, формирование Range Body
 /// 28.12.13 - теперь doc.Sheet и doc.Wb храним в структуре Документа
 /// 5.4.14  - инициализируем docDic, то есть подготавливаем набор данных для Fetch
 /// 22.12.15 - getDoc для нового документа - в Штампе он помечен N
 /// 6.1.16 - NOP если FiliDirectory содержит # - каталог Документа еще будет разворачиваться позже
 ///  5.3.16 - null if Document not found or exist
 /// 30.3.16 - get #template Path from Bootstrap.Template; try-catch rewritten
 ///  5.4.16 - bug fix - SheetReset for "N" Document
 /// 19.4.16 - use Templ.getPath in getDoc()
 /// 27.4.16 - optional flag load - if false -> don't load contents from the file
 /// </history>
 public static Document getDoc(string name = Decl.DOC_TOC, bool fatal = true, bool load = true)
 {
     Log.set("getDoc(" + name + ")");
     Document doc = null;
     string err = "Err getDoc: ", ex= "";
     try { doc = Documents[name]; }
     catch (Exception e) { err += "doc not in TOC"; ex = e.Message; doc = null; }
     if (doc != null && !doc.isOpen)
     {
         if (load)
         {
             if (doc.FileDirectory.Contains("#")) // #Template substitute with Path in Dictionary
                 doc.FileDirectory = Templates[doc.FileDirectory];
             //-------- Load Document from the file or create it ------------
             bool create = !string.IsNullOrEmpty(doc.type) && doc.type[0] == 'N' ? true : false;
             doc.Wb = FileOp.fileOpen(doc.FileDirectory, doc.FileName, create);
             try
             {
                 if (doc.type == Decl.DOC_TYPE_N) FileOp.SheetReset(doc.Wb, doc.SheetN);
                 doc.Sheet = doc.Wb.Worksheets[doc.SheetN];
             }
             catch (Exception e) { err += "no SheetN"; ex = doc.SheetN; doc = null; }
             if (create && doc != null) doc.Reset();
             else if (doc != null) doc.Body = FileOp.getSheetValue(doc.Sheet);
         }
     } // end if(!doc.isOpen)
     if(doc == null && fatal) Msg.F(err, ex, name);
     if(doc != null && doc.Body != null) doc.isOpen = true;
     Log.exit();
     return doc;
 }
Beispiel #2
0
        /// <summary>
        /// CopyFile(FrDir, FileName, ToDir [,overwrite]) - copy FileName from FrDir to ToDir
        /// </summary>
        /// <param name="FrDir">copy from FrDir Directory</param>
        /// <param name="FileName">file to copy</param>
        /// <param name="ToDir">destination Directory</param>
        /// <param name="overwrite">obligatory flag - true - allow overwrite</param>
        /// <returns>bool result -- true if copy was succesful</returns>
        /// <history>20.3.2016 PKh</history>
        public static bool CopyFile(string FrDir, string FileName, string ToDir, bool overwrite = false)
        {
            bool result = false;

            if (!isFileExist(FrDir, FileName))
            {
                Msg.F("ERR_02.2_COPY_NOFILEFROM", FrDir, FileName);
            }
            string From = FrDir + "\\" + FileName;
            string To   = ToDir + "\\" + FileName;

            if (isFileExist(ToDir, FileName))
            {
                string sav = "SAVED_" + FileName;
                if (isFileExist(ToDir, sav))
                {
                    Delete(ToDir, sav);
                }
                File.Move(To, ToDir + "\\" + sav);
            }
            try
            {
                File.Copy(From, To, overwrite);
                result = true;
            }
            catch (Exception e) { Msg.F("ERR_02.3_FILENOTCOPIED", e, From, To); }
            return(result);
        }
Beispiel #3
0
            internal static Form getFormByName(Document doc, string name)
            {

                if (!isFormExist(doc.forms, name)) Msg.F("Document.wrDoc no form", name, doc.name);
                name = Lang(name);
                return doc.forms.Find(x => x.name == name);
            }
Beispiel #4
0
            internal static bool checkResource(List <Resource> Resources, R_name name, string arg = "")
            {
                bool ok = false;

                switch (name)
                {
                case R_name.Tekla:
                    ok = TS.isTeklaActive();
                    break;

                case R_name.TSmatch:
                    string TOCdir = arg;
                    if (String.IsNullOrEmpty(TOCdir))
                    {
                        Msg.F(
                            "\n\r\n\r================================================"
                            + "\n\rTSmatch application is not initiated properly:"
                            + "\n\rTSmatch.xlsx not available, because TOCdir=null."
                            + "\n\r================================================\n\r");
                    }
                    ok = FileOp.isFileExist(TOCdir, Decl.F_MATCH);
                    Resource r = Resources.Find(x => x.name == Decl.TSMATCH);

                    //////                     if (!ok) Recover(Decl.RESOURCE_FAULT_REASON.NoFile);
                    //////                     if (!checkTOCdate(TOCdir, this)) Recover(Decl.RESOURCE_FAULT_REASON.Obsolete);
                    break;
                }
                return(ok);

                throw new NotImplementedException();
            }
Beispiel #5
0
 private void getSavedGroups()
 {
     Docs docRaw = Docs.getDoc(Decl.TSMATCHINFO_RAW, create_if_notexist: false);
     elements.Clear();
     int cnt = docRaw.Body.iEOL();
     for (int i = docRaw.i0; i <= cnt; i++)
     {
         string guid = docRaw.Body.Strng(i, 1);
         string mat = docRaw.Body.Strng(i, 2);
         string mat_type = docRaw.Body.Strng(i, 3);
         string prf = docRaw.Body.Strng(i, 4);
         double lng = docRaw.Body.Double(i, 5);
         double weight = docRaw.Body.Double(i, 6);
         double vol = docRaw.Body.Double(i, 7);
         Elm elm = new Elm(guid, mat, mat_type, prf, lng, weight, vol);
         elements.Add(elm);
     }
     if (elements.Count != elementsCount)
     {
         Msg.F("TSmatchINFO.xlsx inconsystent", name, elementsCount, elements.Count);
         //11/4                GetSavedReport(doRead: true);
     }
     docReport = Docs.getDoc(Decl.TSMATCHINFO_REPORT);
     getGroups();
     int gr_n = docReport.i0;
     foreach (var gr in elmGroups)
     {
         string grPrice = docReport.Body.Strng(gr_n, Decl.REPORT_SUPL_PRICE);
         gr.totalPrice = Lib.ToDouble(grPrice);
         gr.SupplierName = docReport.Body.Strng(gr_n, Decl.REPORT_SUPPLIER);
         gr.CompSetName = docReport.Body.Strng(gr_n, Decl.REPORT_COMPSET);
         gr_n++;
     }
 }
Beispiel #6
0
        public void getGroups(List<Elm> elements)
        {
            elmMgroups.Clear();
            elmGroups.Clear();
            Dictionary<string, ElmAttSet.ElmAttSet> Elements = new Dictionary<string, ElmAttSet.ElmAttSet>();
            try { Elements = elements.ToDictionary(elm => elm.guid); }
            catch { Msg.F("Model.getGroups inconsystent elements "); }

            //-- группы по Материалам elm.mat
            var matGroups = from elm in elements group elm by elm.mat;
            foreach (var matGr in matGroups)
            {
                List<string> guids = new List<string>();
                foreach (ElmAttSet.ElmAttSet element in matGr)
                {
                    //                      log.Info("mgr.mat=" + matGr.Key + " mgr.element.guid=" + element.guid);
                    guids.Add(element.guid);
                }
                ElmAttSet.Mgroup Mgr = new ElmAttSet.Mgroup(elements, matGr.Key, guids);
                elmMgroups.Add(Mgr);
            }
            log.Info("----- Material Groups Count = " + elmMgroups.Count + "\tfrom " + elements.Count + " elements ----");
            foreach (var mtGr in elmMgroups)
                log.Info("material= " + mtGr.mat + "\tCount= " + mtGr.guids.Count + "\tвес=" + mtGr.totalWeight + "\tобъем=" + mtGr.totalVolume);

            //-- группы по Материалу и Профилю elm.mat && elm.prf
            foreach (var Mgr in elmMgroups)
            {
                string curMat = Mgr.mat;
                //7/6                string curPrf = Lib.ToLat(Elements[Mgr.guids[0]].prf.ToLower());
                string curPrf = Elements[Mgr.guids[0]].prf;
                List<string> guids = new List<string>();
                foreach (var g in Mgr.guids)
                {
                    ElmAttSet.ElmAttSet elm = Elements[g];
                    if (elm.prf == curPrf) guids.Add(g);
                    else
                    {
                        elmGroups.Add(new ElmGr(Elements, curMat, curPrf, guids));
                        curPrf = elm.prf;
                        guids = new List<string>();
                        guids.Add(g);
                    }
                }
                if (guids.Count != 0) elmGroups.Add(new ElmGr(Elements, curMat, curPrf, guids));
            }

            elmGroups = PrfUpdate(elmGroups);
//26/6            PrfUpdate();

            log.Info("----- <Material, Profile> Groups Count = " + this.elmGroups.Count);
            int chkSum = 0;
            foreach (var gr in this.elmGroups)
            {
                log.Info("material= " + gr.mat + "\tprofile= " + gr.prf + "\tCount= " + gr.guids.Count);
                chkSum += gr.guids.Count;
            }
            log.Info("-------------- CheckSum: total elements count in all groups = " + chkSum);
        }
Beispiel #7
0
 public void init(string _schemaName)
 {
     schemaName = _schemaName;
     if (string.IsNullOrEmpty(schemaName))
     {
         Msg.F("IFC.init: No schema");
     }
 }
Beispiel #8
0
        public static List <ElmAttributes.ElmAttSet> Read(string ifcFileName)
        {
            var manager = new IfcManager.Core.IfcManager();

            if (!FileOp.isFileExist(ifcFileName))
            {
                Msg.F("IFC.Read: no file", ifcFileName);
            }

            log.Info("TRACE: Read(\"" + ifcFileName + "\"");

            manager.init(ifcFileName, schemaName);

            List <IfcManager.Core.IfcManager.IfcElement> elements = new List <IfcManager.Core.IfcManager.IfcElement>();

            elements = manager.getElementsByProperty("NetVolume");
            IFC.MergeIfcToElmAttSet(elements);

            elements.Clear();
            elements = manager.getElementsByProperty("Weight");
            IFC.MergeIfcToElmAttSet(elements);

            elements.Clear();
            elements = manager.getElementsByMaterials();
            IFC.MergeIfcToElmAttSet(elements);

            elements.Clear();
            elements = manager.getElementsByProperty("Profile");
            IFC.MergeIfcToElmAttSet(elements);

            List <ElmAttributes.ElmAttSet> result = new List <ElmAttributes.ElmAttSet>();

            result = ElmAttributes.ElmAttSet.Elements.Values.ToList();
            foreach (var elm in result)
            {
                string[] matToSplit = elm.mat.Split('/');
                switch (matToSplit.Count())
                {
                case 2:
                    elm.mat_type = matToSplit[0];
                    elm.mat      = matToSplit[1];
                    break;

                case 1:
                    elm.mat_type = "STEEL";
                    elm.prf      = elm.mat; // А400 - это арматура; почемуто ее марку указывают как материал
                                            //..здесь еще надо разобраться с ГОСТ-5781
                                            //..и присвоить значения элемента mat, prf и др
                    break;

                default: Msg.F("IFC error Material Parse", elm.mat);
                    break;
                }
            }
            result.Sort();
            return(result);
        }
Beispiel #9
0
 /// <summary>
 /// getGroups() - groupping of elements of Model by Material and Profile
 /// </summary>
 /// <ToDo>30.9.2016 - попробовать перенести этот метод в ElmAttSet.Groups или вообще выделить Groups в отдельный класс</ToDo>
 /// <history> 
 /// 2016.09.29 created
 /// 2017.05.8  перенес в модуль ModHandling, добавил аргумент elements
 /// 2017.06.27 переписано
 /// </history>
 public List<ElmGr> getGrps(List<Elm> elements)
 {
     List <ElmGr> groups = new List<ElmGr>();
     var grps = elements.GroupBy(x => x.prf);
     foreach (var gr in grps) groups.Add(new ElmGr(gr));
     if (elements.Count != groups.Sum(x => x.guids.Count)) Msg.F("getGrps internal error");
     var v = new ProfileUpdate.ProfileUpdate(ref groups);
     return groups;
 }
Beispiel #10
0
        Form form;  // form set in wrDocSet
        internal void wrDocSetForm(string formName, int nStrBody = -1, bool AutoFit = false)
        {
            Log.set("wrDocSetForm");
            if (!Form.isFormExist(forms, formName)) Msg.F("Document.wrDoc no form", formName, this.name);
            form = Form.getFormByName(this, formName);
            form.AutoFit = AutoFit;
            Form.last_name = "";
            Form.nStr = nStrBody == -1 ? Body.iEOL()+1: nStrBody; // defualt nStr = Body.iEOL()+1
///            Form.getFormByName(this, formName).AutoFit = AutoFit;
            Log.exit();
        }
Beispiel #11
0
 private string strExclude(string str, List <string> syns)
 {
     foreach (string s in syns)
     {
         if (!str.Contains(s))
         {
             continue;
         }
         return(str.Substring(s.Length));
     }
     Msg.F("Rule.strExclude error", str, syns);
     return(null);
 }
Beispiel #12
0
        public void openModel(string name = RECENT_MODEL)
        {
            Log.set("openModel(\"" + name + "\")");
            Model mod = null;
            bool ok = false;
            if (TS.isTeklaActive())
            {
                //!! here we could upload over API in Tekla another model it differ from requested name
                //!! if (TS.isTeklaModel(mod.name))
                //!! implement it later on 23/6/2016
                UpdateFrTekla();
            }
            if (name == RECENT_MODEL) mod = RecentModel();
                                 else mod = getModel(name);

            string dir = mod.dir;
            string FileName = "TSmatchINFO.xlsx";
            if (mod.Made == "IFC") FileName = "out.ifc";
            if (mod != null) ok = FileOp.isFileExist(dir, FileName);

            if (!ok)
            {           //-- Folder or File Browth dialog
                FolderBrowserDialog ffd = new FolderBrowserDialog();
                dir = ffd.SelectedPath = mod.dir;
                DialogResult result = ffd.ShowDialog();
                if (result == DialogResult.OK) dir = ffd.SelectedPath;
                do
                {
                    if (!FileOp.isFileExist(dir, FileName))
                    {
                        Msg.W("W20.4_opMod_NO_TSmINFO", dir);
                        OpenFileDialog ofd = new OpenFileDialog();
                        ofd.InitialDirectory = dir;
                        if (ofd.ShowDialog() == DialogResult.OK)
                        {
                            FileName = ofd.FileName;
                            // !!!!!!                       dir = ofd.Sel
                        }
                    }
                    ok = readModel(dir, FileName);
                    //!!!                if(!ok) Msg.Ask(Еще раз?) break;
                } while (!ok);
            }
            else
            {
                string ext = Path.GetExtension(FileName);
                if ( ext == ".ifc") Ifc.Read(dir, FileName); //!!
                if (ext == ".xlsx") dir= "";//!! readModel();
            }
            Log.exit();
        }
Beispiel #13
0
        private void OnSupplier_changed(object sender, SelectionChangedEventArgs e)
        {
            string curSN        = MainWindow.SuplName;
            Supl   selectedSupl = (Supl)Suppliers.SelectedItem;
            string selSN        = selectedSupl.Name;

            if (!Msg.AskYN("Вы действительно хотите заменить \"{0}\" на \"{1}\"?", curSN, selSN))
            {
                return;
            }
            MainWindow.SuplName = selSN;
            MainWindow.RePricing();
            Close();
        }
Beispiel #14
0
 /// <summary>
 /// getModJournal(name, dir) - get model from Model Journal in TSmatch.xlsx
 /// </summary>
 /// <param name="name">name of model in Journal. If empty - most recent</param>
 /// <param name="dir">directory of model in Journal. If empty - by name</param>
 /// <returns>line number in TSmatch.xlsx/Models</returns>
 /// <ToDo>10.4.17 реализовать default name и dir </ToDo>
 public int getModJournal(string name = "", string dir = "")
 {
     Docs doc = Docs.getDoc(Decl.MODELS);
     if (name == "") throw new NotImplementedException();
     for (int i = doc.i0; i <= doc.il; i++)
     {
         if (dir != "" && dir != doc.Body.Strng(i, Decl.MODEL_DIR)) continue;
         if (name != doc.Body.Strng(i, Decl.MODEL_NAME)) continue;
         return i;
     }
     throw new NotFiniteNumberException();
     // тут надо записывать в Журнал Моделей
     Msg.I("new record in Model Journul", name, dir);
     return -1;
 }
Beispiel #15
0
        internal static Model getModelFrTekla()
        {
            string modName = TS.getModInfo();
            Docs   doc     = Docs.getDoc(Decl.MODELS);

            for (int i = doc.i0; i <= doc.il; i++)
            {
                if (doc.Body.Strng(i, Decl.MODEL_NAME) != modName)
                {
                    continue;
                }
                return(new TSmatch.Model.Model(i));
            }
            Msg.F("TEMPORARY: New model in Tekla! Put it in Model Jornal manually");
            return(null);
        }
Beispiel #16
0
 public Mgroup(List <ElmAttSet> elements, string material, List <string> guids)
 {
     this.mat    = material;
     this.guids  = guids;
     totalWeight = totalVolume = totalPrice = 0.0;
     foreach (string id in guids)
     {
         ElmAttSet elm = elements.Find(x => x.guid == id);
         if (elm == null)
         {
             Msg.F("ElmAttSet: Mgroup(wrong guid)", id);
         }
         totalWeight += elm.weight;
         totalVolume += elm.volume;
         totalPrice  += elm.price;
     }
 }
Beispiel #17
0
 /// <summary>
 /// Reset() - "Reset" of the Document. All contents of hes Excel Sheet erased, write Header form
 /// Reset("Now") - write DataTime.Now string in Cell [1,1]
 /// </summary>
 /// <history>9.1.2014
 /// 17.1.16 - полностью переписано с записью Шапки
 /// 16.3.16 - header name get from doc.forms[0]
 /// 26.3.16 - Reset("Now")
 /// 27.3.16 - bug fixed. Issue was: Reset named as a doc.name instead SheetN
 /// </history>
 public void Reset(string str = "")
 {
     Log.set("Reset(" + this.name + ")");
     Document toc = getDoc();
     this.Sheet = FileOp.SheetReset(this.Wb, this.SheetN);
     Excel.Range rng = FileOp.setRange(this.Sheet);
     if (this.forms.Count == 0) Msg.F("Document.Reset no HDR form", this.name);
     string myHDR_name = this.forms[0].name;
     FileOp.CopyRng(toc.Wb, myHDR_name, rng);
     this.Body = FileOp.getSheetValue(this.Sheet);
     if (str == "Now")
     {
         Body[1, 1] = Lib.timeStr();
         FileOp.setRange(this.Sheet);
         FileOp.saveRngValue(Body);
     }
     Log.exit();
 }
Beispiel #18
0
 public int Int(int parNumber = 0)
 {
     if (parNumber < 0 || parNumber >= pars.Count)
         Msg.F("FP.Int() Not supported pars.Count", pars.Count);
     if(pars[parNumber].GetType() == typeof(string))
     {
         string str = (string)pars[parNumber].par;
         int result =  Lib.ToInt(str);
         if (result == -1) Msg.F("FP TMP not recognized Int", str);
         return result;
     }
     if (pars[parNumber].par.GetType() == typeof(int))
         return (int)pars[parNumber].par;
     if (pars[parNumber].par.GetType() == typeof(string))
         return Lib.ToInt((string)pars[parNumber].par);
     Msg.F("ErrFP string or integer parametr exected");
     return -1;
 }
Beispiel #19
0
 public bool isSectionMatch(string template)
 {
     if (!SectionTab.Any())
     {
         Msg.F("SectionTab is empty");
     }
     string[] sections = Lib.ToLat(template).ToLower().Replace(" ", "").Split(';');
     foreach (string str in sections)
     {
         if (SecType(str) != type)
         {
             continue;
         }
         string templ = SecBody(str).Replace("*", "(.*?)");
         return(Regex.IsMatch(body, templ));
     }
     return(false);
 }
Beispiel #20
0
        public static bool isNamedRangeExist(Excel.Workbook Wb, string name)
        {
            bool result = true;

            try
            {
                result = Wb.Names.Item(name) != null;
            }
            catch (Exception e)
            {
                if (Msg.Trace)
                {
                    Msg.I("TRACE_33.1_IsNameRangeExist", e, name);
                }
                result = false;
            }
            return(result);
        }
Beispiel #21
0
        //internal void wrDoсForm(string dir, string v, DateTime date, string mD5, int count, string strListRules)
        //{
        //    throw new NotImplementedException();
        //}

        /// <summary>
        /// wrDoc(str, obect[] obj) -- write data from array of objects to the Document in Excel
        /// </summary>
        /// <param name="str">form name; "str_F" format is also accounted</param>
        /// <param name="obg">data array to be written</param>
        /// <history>16.3.2016
        /// 26.3.2016 - output HDR_ form with time.Now in [1,1]
        ///  3.4.2016 - multiple line output support with last_name
        /// 13.4.2016 - Internal error message, when form not found
        /// 22.8.2016 - auditted: if(obj is Array); i0+1
        /// </history>
        public void wrDoc(string formName, params object[] obj)
        {
            Log.set("wrDoc(" + formName + ", obj[])");

            if(obj is Array)
            {
                int objLng = obj.Length;
                object[] _obj = obj;
                //--------------- not implemented yet
                if ( obj[0] is Array)
                {

                }
            }
 //           Type ob = typeof(obj);  //.IsAssignableFrom(type); 

            Form frm = forms.Find(x => x.name == formName);
            if (frm == null) Msg.F("Document.wrDoc no form", formName, this.name);
            if (frm.name == Form.last_name)
            {
                Body.AddRow(obj);
            }
            else
            {
                saveDoc();
                int lineInBodyToWrite = Form.nStr < 1 ? Body.iEOL() : Form.nStr;
                Excel.Range rng = FileOp.setRange(Sheet, lineInBodyToWrite);
                Document toc = getDoc();
                FileOp.CopyRng(toc.Wb, formName, rng);
                Body = FileOp.getSheetValue(Sheet);
                FileOp.saveRngValue(Body);
                int i = 0;
                foreach (var v in obj)
                {
                    int r = frm.row[i] + lineInBodyToWrite - 1;
                    int c = frm.col[i++];
                    Body[r, c] = v;
                }
                FileOp.saveRngValue(Body, 1, AutoFit: frm.AutoFit);
                Form.last_name = frm.name;
            }
            Log.exit();
        }
Beispiel #22
0
        ////////////////Docs doc = Docs.getDoc(Decl.SUPPLIERS);
        ////////////////this.date = Lib.getDateTime(doc.Body[n, Decl.SUPL_DATE]);
        ////////////////this.name = (string)doc.Body[n, Decl.SUPL_NAME];
        ////////////////this.Url = (string)doc.Body[n, Decl.SUPL_URL];
        ////////////////this.City = (string)doc.Body[n, Decl.SUPL_CITY];
        ////////////////this.street = (string)doc.Body[n, Decl.SUPL_STREET];
        ////////////////this.index = (string)doc.Body[n, Decl.SUPL_INDEX];
        ////////////////this.telephone = (string)doc.Body[n, Decl.SUPL_TEL];
        ////////////////    // get doc_names list from TOC
        ////////////////Docs toc = Docs.getDoc(Decl.DOC_TOC);
        ////////////////for(int i= toc.i0; i < toc.il; i++)
        ////////////////{
        ////////////////    string str = toc.Body.Strng(i, Decl.DOC_SUPPLIER);
        ////////////////    if (name != str) continue;
        ////////////////    string cs_name = toc.Body.Strng(i, Decl.DOC_SHEET);
        ////////////////    string doc_name = toc.Body.Strng(i, Decl.DOC_NAME);
        ////////////////    CmpSet cs = CmpSet.setCompSet(cs_name, doc_name, this);
        ////////////////    this.CompSets.Add(cs);
        ////////////////}

        public Supplier(string _name)
        {
            Docs docSupl = Docs.getDoc(Decl.SUPPLIERS);

            for (int i = docSupl.i0; i <= docSupl.il; i++)
            {
                string suplName = docSupl.Body.Strng(i, Decl.SUPL_NAME);
                if (suplName != _name)
                {
                    continue;
                }
                getSupplier(i);
                break;
            }
            if (this.name == "")
            {
                Msg.F("No Supplier(" + _name + ")");
            }
        }
Beispiel #23
0
 /// <summary>
 /// saveDoc(doc [,BodySave, string MD5]) - сохраняет Документ в Excel файл, если он изменялся
 /// </summary>
 /// <param name="name">имя документа</param>
 /// <param name="BodySave>true - doc.Body нужно сохранить, false - уже в Excel</param>
 /// <param name="MD5">MD5 документа. Если BodySave = false - обязательно</param>
 /// <history>10.1.2016
 /// 18.1.16 - аккуратная обработка BodySave=false и MD5
 /// 20.1.16 - fix bug: not write EOLinTOC for TSmatch type Documents
 /// 1.04.16 - overlay saveDoc(..)
 /// </history>
 public static void saveDoc(Document doc, bool BodySave = true, string MD5 = "", int EOL = 0)
 {
     Log.set("saveDoc(\"" + doc.name + "\")");
     try
     {
         Document toc = Documents[Decl.DOC_TOC];
         if (doc.type == Decl.DOC_TYPE_N) doc.isChanged = true;
         if (doc.isChanged)
         {
             int EOLinTOC = EOL;
             if (BodySave)
             {
                 FileOp.setRange(doc.Sheet);
                 FileOp.saveRngValue(doc.Body);
                 doc.chkSum = doc.Body.ComputeMD5();
                 doc.EOLinTOC = doc.Body.iEOL();
                 FileOp.fileSave(doc.Wb);
                 doc.isChanged = false;
             }
             else
             {
                 if (MD5.Length < 20 || EOL == 0) Msg.F("ERR_05.8_saveDoc_NOMD5");
                 else { doc.chkSum = MD5; doc.EOLinTOC = EOLinTOC; }
             }
             Mtr tmp = FileOp.getSheetValue(toc.Sheet);
             for (int n = toc.i0; n <= toc.il; n++)
             {   // находим и меняем строку документа doc TOC
                 if ((string)toc.Body[n, Decl.DOC_NAME] != doc.name) continue;
                 tmp[1, 1] = Lib.timeStr();
                 tmp[n, Decl.DOC_TIME] = Lib.timeStr();
                 tmp[n, Decl.DOC_MD5] = doc.chkSum;
                 if (doc.type == "N") tmp[n, Decl.DOC_CREATED] = Lib.timeStr();
                 if (doc.type != Decl.TSMATCH_TYPE) tmp[n, Decl.DOC_EOL] = doc.EOLinTOC;
                 FileOp.setRange(toc.Sheet);
                 FileOp.saveRngValue(tmp, AutoFit: false);  //======= save TОC in TSmatch.xlsx
                 break;
             }
         }
     }
     catch (Exception e) { Log.FATAL("Ошибка \"" + e.Message + "\" сохранения файла \"" + doc.name + "\""); }
     Log.exit();
 }
Beispiel #24
0
        public void SavModJournal()
        {
            if (models == null || models.Count < 1)
            {
                Msg.F("ModJournal internal error");
            }
            models.Sort();
            Docs doc = Docs.getDoc(Decl.MODELS);

            doc.Reset("Now");
            doc.wrDocSetForm("FORM_Models_in_TSmatch.xlsx");
            foreach (var mod in models)
            {
                string dt     = mod.date.ToString("d.MM.yy H:mm");
                string sPhase = "'" + mod.phase;
                doc.wrDocForm(dt, mod.name, mod.dir, ifcPath,
                              mod.made, sPhase, mod.MD5, mod.strListRules);
            }
            doc.isChanged = true;
            doc.saveDoc();
        }
Beispiel #25
0
        public void GetModelInfo()
        {
            if (TS.isTeklaActive())
            {
                name = Path.GetFileNameWithoutExtension(TS.ModInfo.ModelName);
                dir = TS.ModInfo.ModelPath;
                elementsCount = ts.elementsCount();
                // getModInfo from Journal by name and dir
                iModJounal = getModJournal(name, dir);
                date = DateTime.Parse(modJournal(iModJounal, Decl.MODEL_DATE));
                getSavedGroups();
//12/4                getSavedRules();
            }
            else //if no Tekla active get name and dir from IFC or from INFO file if exists
            {
                if (!GetSavedReport()) Msg.F("No Tekla no saved TSmatchINFO");
            }
            // 12/4 //Docs doc = Docs.getDoc(Decl.TSMATCHINFO_MODELINFO);
            //////////doc.Close();
           var  doc = Docs.getDoc();
            doc.Close();
        }
Beispiel #26
0
        //-- get cs doc from TOC by cs_name and Supplier in TSmatch.xlsx/Rule
        private Docs getCSdoc(Supl supplier, string _name)
        {
            string docName = string.Empty;
            Docs   toc     = Docs.getDoc();

            for (int i = toc.i0; i <= toc.il; i++)
            {
                string suplName = toc.Body.Strng(i, Decl.DOC_SUPPLIER);
                string csSheet  = toc.Body.Strng(i, Decl.DOC_SHEET);
                if (suplName != Supplier.name || csSheet != name)
                {
                    continue;
                }
                docName = toc.Body.Strng(i, Decl.DOC_NAME);
                break;
            }
            if (string.IsNullOrEmpty(docName))
            {
                Msg.F("CompSet not found price list");
            }
            return(Docs.getDoc(docName));
        }
Beispiel #27
0
 /// <summary>
 /// IsTeklaActice() - return true if TeklaStructures Process exists in Windows, and model is available 
 /// </summary>
 /// <returns>true if Tekla is up and running</returns>
 public static bool isTeklaActive()
 {
     Log.set("isTeklaActive()");
     bool ok = false;
     const string Tekla = "TeklaStructures";
     foreach (Process clsProcess in Process.GetProcesses())
     {
         if (clsProcess.ProcessName.ToLower().Contains(Tekla.ToLower()))
         {
             TSM.Model model = new TSM.Model();
             if (!model.GetConnectionStatus()) Msg.W("===== No Tekla active =========");
             try
             {
                 ModInfo = model.GetInfo();
                 ok = model.GetConnectionStatus() && ModInfo.ModelName != "";
             }
             catch { Msg.W("isTeklaActive no model Connection"); }
             break;
         }
     }
     Log.exit();
     return ok;
 }
Beispiel #28
0
 public int Col(int parNumber = 0)
 {
     int result = Int(parNumber);
     if (result < 1) Msg.F("FP.Col wrong parametr", result);
     return result;
 }
Beispiel #29
0
        string PrfNormStr(string str, string mark, List<int> pars)
        {
            switch (mark)
            {
                case "I":
                    mark += pars[0];
                    if (str.Contains("b1")) { mark += "Б1"; break; }
                    if (str.Contains("b2")) { mark += "Б2"; break; }
                    if (str.Contains("b3")) { mark += "Б3"; break; }
                    if (pars.Count != 1) Msg.F("Internal error");
                    break;
                case "[":
                    mark += pars[0];
                    if (str.Contains("ap")) { mark += "аП"; break; }
                    if (str.Contains("p"))  { mark += "П";  break; }
                    if (str.Contains("ay")) { mark += "аУ"; break; }
                    if (str.Contains("y"))  { mark += "У";  break; }
                    if (str.Contains("e"))  { mark += "Э";  break; }
                    if (str.Contains("l"))  { mark += "Л";  break; }
                    if (str.Contains("ca")) { mark += "Cа"; break; }
                    if (str.Contains("cb")) { mark += "Cб"; break; }
                    if (str.Contains("c"))  { mark += "C";  break; }
                    if (pars.Count != 1) Msg.F("Internal error");
                    break;
                
                case "Гн.[]":
                    break;
                case "Гн.":
                    break;
            }


            //////////switch (pars.Count)
            //////////{
            //////////    case 1:
            //////////        if (mark == "[")
            //////////        {
            //////////            mark += pars[0];
            //////////            if (str.Contains("ap")) { mark += "аП"; break; }
            //////////            if (str.Contains("p"))  { mark += "П";  break; }
            //////////            if (str.Contains("ay")) { mark += "аУ"; break; }
            //////////            if (str.Contains("y"))  { mark += "У";  break; }
            //////////            if (str.Contains("e"))  { mark += "Э";  break; }
            //////////            if (str.Contains("l"))  { mark += "Л";  break; }
            //////////            if (str.Contains("ca")) { mark += "Cа"; break; }
            //////////            if (str.Contains("cb")) { mark += "Cб"; break; }
            //////////            if (str.Contains("c"))  { mark += "C";  break; }
            //////////            break;
            //////////        }
            //////////        if (mark == "I")
            //////////        {
            //////////            mark += pars[0];
            //////////            if (str.Contains("b1")) { mark += "Б1"; break; }
            //////////            if (str.Contains("b2")) { mark += "Б2"; break; }
            //////////            if (str.Contains("b3")) { mark += "Б3"; break; }
            //////////            break;
            //////////        }
            //////////        if (mark == "—") mark += pars[0];
            //////////        break;
            //////////    case 2:
            //////////        if (mark == "I")
            //////////        {
            //////////            mark += pars[0];
            //////////            if (str.Contains("b")) { mark += "Б" + pars[1]; break; }
            //////////            if (str.Contains("k"))
            //////////            {
            //////////                mark += "К" + pars[1];
            //////////                if (str.Contains("a")) mark += "A";
            //////////                break;
            //////////            }
            //////////        }
            //////////        if (mark == "Гн.") { mark += pars[0] + "x" + pars[1]; break; }
            //////////        mark += pars.Min() + "x" + pars.Max();
            //////////        break;
            //////////    case 3:
            //////////        if (md == PrfOpMode.Mark)
            //////////        {
            //////////            mark += pars[0] + 'x' + pars[1] + 'x' + pars[2];
            //////////            break;
            //////////        }
            //////////        if (mark == "Гн.[]")
            //////////        {
            //////////            if (pars[0] == pars[1]) return "Гн." + pars.Max() + "x" + pars.Min();
            //////////            mark += pars[0] + "x" + pars[1] + "x" + pars[2];
            //////////            break;
            //////////        }
            //////////        int p1 = pars.Min();
            //////////        pars.Remove(p1);
            //////////        int p3 = pars.Max();
            //////////        pars.Remove(p3);
            //////////        mark += p1 + "x" + pars[0] + "x" + p3;
            //////////        break;
            //////////    default: Msg.F("ModHandler.grPrfPars not recognized Profile"); break;
            //////////}
            return mark;
        }
Beispiel #30
0
        public Tekla() { } // конструктор класса Tekla - пока пустой 6.4.17

        public List<Elm> Read(string dir = "", string name = "")
        {
            Log.set("TS_OpenAPI.Read");
            List<Elm> elements = new List<Elm>();
            // 6.4.17 //TSM.Model model = new TSM.Model();
            ////////////List<Part> parts = new List<Part>();
            ModInfo = model.GetInfo();
            if (dir != "" && ModInfo.ModelPath != dir
                || name != "" && ModInfo.ModelName != String.Concat(name, ".db1")) Msg.F("Tekla.Read: Another model loaded, not", name);
            ModInfo.ModelName = ModInfo.ModelName.Replace(".db1", "");
            TSM.ModelObjectSelector selector = model.GetModelObjectSelector();
            System.Type[] Types = new System.Type[1];
            Types.SetValue(typeof(Part), 0);

            TSM.ModelObjectEnumerator objectList = selector.GetAllObjectsWithType(Types);
            int totalCnt = objectList.GetSize();
            var progress = new TSM.Operations.Operation.ProgressBar();
            bool displayResult = progress.Display(100, "TSmatch", "Reading model. Pass component records:", "Cancel", " ");
            int ii = 0;
            while (objectList.MoveNext())
            {
                TSM.Part myPart = objectList.Current as TSM.Part;
                if (myPart != null)
                {
                    ii++;
                    double lng = 0.0;
                    double weight = 0.0;
                    double vol = 0.0;
                    string guid = "";
                    string mat_type = "";
                    double price = 0.0;

                    myPart.GetReportProperty("GUID", ref guid);
                    myPart.GetReportProperty("LENGTH", ref lng);
                    myPart.GetReportProperty("WEIGHT", ref weight);
                    myPart.GetReportProperty("VOLUME", ref vol);
                    myPart.GetReportProperty("MATERIAL_TYPE", ref mat_type);

                    lng = Math.Round(lng, 0);
                    //string cut = "";
                    //myPart.GetReportProperty("CAST_UNIT_TYPE", ref cut);
                    //ModAtr.Add(new AttSet(myPart.Material.MaterialString,
                    //                      profile, lng, weight, vol));
                    //21/6/2016 в отладке                    Elm.Elements.Add(new Elm());
                    elements.Add(new Elm(guid, myPart.Material.MaterialString,
                        mat_type,
                        myPart.Profile.ProfileString,
                        lng, weight, vol, price));
 // !!                  if (ii % 500 == 0) // progress update every 500th items
                    {
                        if (progress.Canceled())
                        {
//                            new Log("\n\n======= TSmatch pass model CANCEL!! =======  ii=" + ii);
//                            TSD.Show()
                            break;
                        }
                        progress.SetProgress(ii.ToString(), 100 * ii / totalCnt);
                    }
                }
            } //while
            progress.Close();
            Scale(elements);
            elements.Sort();
            Log.exit();
            return elements;
        } // Read