Esempio n. 1
0
        public void enumarateFirstAttr(string attr, string value)
        {
            lastEnumeratedNode = null;
            List <XmlElement> list = new List <XmlElement>();

            foreach (XmlNode nodeRoot in xmlNodes)
            {
                foreach (XmlNode node in nodeRoot)
                {
                    if (ToolXml.getAttribValue(node, attr, null) == value)
                    {
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            list.Add((XmlElement)node);
                            break;
                        }
                    }
                }
            }
            if (list.Count > 0)
            {
                lastEnumeratedNode = list[0];
            }
            enumeration = list.GetEnumerator();
        }
Esempio n. 2
0
        private void exeCmdGroup(StringBuilder pBuilder, XmlNode pNode, DataSet pDataSet)
        {
            string    tabName = pNode.Attributes[_constAttrTable].Value;
            string    filter  = ToolXml.getAttribValue(pNode, _constAttrFilter, string.Empty);
            DataTable table   = pDataSet.Tables[tabName];

            table.DefaultView.RowFilter = filter;
            string[] colsArr = ToolString.explodeList(pNode.Attributes[_constAttrList].Value);


            DataTable[] grpTabs = ToolTable.explodeForGroups(table, colsArr);
            foreach (DataTable curTab in grpTabs)
            {
                if (curTab.DefaultView.Count > 0)
                {
                    pDataSet.Tables.Remove(tabName);
                    pDataSet.Tables.Add(curTab);
                    setVars(curTab.DefaultView[0].Row);
                    eval(pNode, pDataSet, pBuilder);
                }
            }


            pDataSet.Tables.Remove(tabName);
            pDataSet.Tables.Add(table);
        }
        void refresh()
        {
            try
            {
                //ToolMsg.progressStart(null, "T_LOAD");
                var agent = _environment.getServerAgent();

                if (agent == null)
                {
                    throw new Exception("Connection agent is null");
                }

                var res = agent.sendText(string.Format(@"
<CMD>
<arr cmd='REPSERVER' arg='{0}' />
</CMD>

", WebUtility.HtmlEncode(_cmd)));

                string err = null;
                string rep = null;

                if (res != null)
                {
                    var docXml = new XmlDocument();
                    docXml.LoadXml(res);

                    var nodeRoot = docXml["CMD"];

                    var nodeRep = nodeRoot.FirstChild;

                    rep = ToolXml.getAttribValue(nodeRep, "value", "");

                    err = ToolXml.getAttribValue(nodeRep, "err", "");
                }
                else
                {
                    throw new Exception("T_MSG_ERROR_CONNECTION");
                }


                var hasErr = err != "";

                if (hasErr)
                {
                    throw new Exception(err);
                }

                //if (!string.IsNullOrEmpty(rep))
                //    ToolMobile.writeFileText(_file, rep);

                content = rep;
            }
            finally
            {
                //ToolMsg.progressStop( );
            }
        }
Esempio n. 4
0
        bool isSameData(XmlDocument doc, ISettings oldSysSettings)
        {
            string newId = ToolXml.getAttribValue(doc.DocumentElement, "guid", string.Empty);
            string oldId = oldSysSettings.getString(SettingsSysMob.MOB_USR_DATA_ID, string.Empty);

            if (newId != string.Empty)
            {
                return(newId == oldId);
            }

            return(true);
        }
Esempio n. 5
0
        static void initLang()
        {
            if (cache != null)
            {
                return;
            }

            try
            {
                var cache_tmp = new Dictionary <string, SortedDictionary <string, string> >();
                var xmlDoc    = new XmlDocument();

                var lang_xml = ToolMobile.getFsOrResourceText("config/sys", "lang.xml");

                xmlDoc.LoadXml(
                    lang_xml
                    );


                var root = xmlDoc["settings"];


                foreach (var lang in langs)
                {
                    var langCache = new SortedDictionary <string, string>();

                    foreach (var node in root.ChildNodes)
                    {
                        var el = node as XmlElement;
                        if (el != null)
                        {
                            var from = el.Name;
                            var to   = ToolXml.getAttribValue(el, lang, el.Name);
                            langCache[from] = to;
                        }
                    }


                    cache_tmp[lang] = langCache;
                }
                cache = cache_tmp;
            }
            catch (Exception exc)
            {
                ToolMobile.setExceptionInner(exc);
            }
        }
Esempio n. 6
0
        public ImplXmlReport(string pFile, IEnvironment pEnv)
        {
            _environment = pEnv;
            _script      = new SimpleScript(_environment);

            // var fileContent = ToolMobile.readFileTextByCache(pFile);
            var fileContent = ToolMobile.getFsOrResourceText(Path.GetDirectoryName(pFile), Path.GetFileName(pFile));

            _doc.LoadXml(fileContent);
            //
            _rendInfo.count    = XmlFormating.helper.parseInt(ToolXml.getAttribValue(_doc.DocumentElement, _constAttrCount, XmlFormating.helper.format(_rendInfo.count)));
            _rendInfo.isDirect = XmlFormating.helper.parseBool(ToolXml.getAttribValue(_doc.DocumentElement, _constAttrDirect, XmlFormating.helper.format(_rendInfo.isDirect)));
            _rendInfo.encoding = XmlFormating.helper.parseString(ToolXml.getAttribValue(_doc.DocumentElement, _constAttrEnc, XmlFormating.helper.format(_rendInfo.encoding)));
            _rendInfo.replace  = XmlFormating.helper.parseString(ToolXml.getAttribValue(_doc.DocumentElement, _constAttrReplace, XmlFormating.helper.format(_rendInfo.replace)));

            //
        }
Esempio n. 7
0
        private void exeCmdTable(StringBuilder pBuilder, XmlNode pNode, DataTable pTable, int pMaxCount)
        {
            try
            {
                pTable.DefaultView.RowFilter = ToolXml.getAttribValue(pNode, _constAttrFilter, string.Empty);
                pTable.DefaultView.Sort      = ToolXml.getAttribValue(pNode, _constAttrSort, string.Empty);

                var repeatCol_ = ToolXml.getAttribValue(pNode, _constAttrLineRepeat, string.Empty);


                int counter = 0;
                foreach (DataRowView rowView in pTable.DefaultView)
                {
                    ++counter;
                    if (counter > pMaxCount)
                    {
                        break;
                    }


                    var repeat_ = 1;
                    if (!string.IsNullOrEmpty(repeatCol_))
                    {
                        repeat_ = Convert.ToInt16(Convert.ToDouble(rowView[repeatCol_]));
                        repeat_ = Math.Max(repeat_, 1);
                    }



                    for (int i = 1; i <= repeat_; ++i)
                    {
                        setVars(rowView.Row);
                        string newData = _script.eval(pNode.InnerText);
                        pBuilder.Append(newData);
                    }
                }
            }
            finally
            {
                if (pTable != null)
                {
                    pTable.DefaultView.Sort = pTable.DefaultView.RowFilter = string.Empty;
                }
            }
        }
Esempio n. 8
0
        private void exeCmdAggr(XmlNode pNode, DataSet pDataSet)
        {
            string    name      = pNode.Attributes[_constAttrName].Value;
            DataTable table     = pDataSet.Tables[pNode.Attributes[_constAttrTable].Value];
            string    exp       = pNode.Attributes[_constAttrExp].Value;
            string    filter    = ToolXml.getAttribValue(pNode, _constAttrFilter, string.Empty);
            string    col       = ToolXml.getAttribValue(pNode, _constAttrCol, string.Empty);;
            string    sort      = ToolXml.getAttribValue(pNode, _constAttrSort, string.Empty);
            string    lineCount = ToolXml.getAttribValue(pNode, _constAttrLineRepeat, string.Empty);

            DataRow[] rows = table.Select(filter, sort);


            switch (exp.ToLower())
            {
            case "sum":
                double res = 0;
                foreach (DataRow row in rows)
                {
                    res += Convert.ToDouble(row[col]);
                }
                setVar(name, res);
                break;

            case "count":
                setVar(name, rows.Length);
                break;

            case "distinct":
                List <object> list = new List <object>();
                foreach (DataRow row in rows)
                {
                    if (!list.Contains(row[col]))
                    {
                        list.Add(row[col]);
                    }
                }
                setVar(name, list.Count);
                break;
            }
        }
Esempio n. 9
0
        void doneAsync()
        {
            lock (environment)
            {
                ISettings oldSysSettings = environment.getSysSettings();

                try
                {
                    //
                    bool localDebugImport = false;

#if DEBUG
                    localDebugImport = false;
#endif


                    log.set(MessageCollection.T_MSG_OPERATION_STARTING);
                    //

                    ToolMobile.setRuntimeMsg("Data import starting");

                    if (!localDebugImport)
                    {
                        checkDataSource();
                    }

                    //
                    string fileWorkDir = Path.Combine(ToolMobile.curDir(), "data");
                    ToolMobile.createDir(fileWorkDir);
                    string fileInputZip = Path.Combine(fileWorkDir, "fromava.zip");
                    string fileInputXml = Path.Combine(fileWorkDir, "fromava.xml");
                    // bool state = false;
                    //Source
                    if (localDebugImport)//CurrentVersion.ENV.isLocalExim()
                    {
                        //!!//
                    }
                    else
                    {
                        {
                            //
                            log.set(MessageCollection.T_MSG_DATA_RECEIVING);
                            //
                            AgentData    ad = new AgentData(environment);
                            ServerResult sr;
                            ad.chackOperationResult(sr = ad.resiveData());
                            byte[] data = sr.data;
                            //
                            log.set(MessageCollection.T_MSG_DATA_WRITING);
                            //
                            ToolMobile.writeFileData(fileInputZip, data);
                            ToolZip.decompress(fileInputZip, Path.GetDirectoryName(fileInputZip));
                        }
                    }

                    //Get
                    log.set(MessageCollection.T_MSG_DATA_READING);
                    //
                    XmlDocument doc = new XmlDocument();
                    doc.Load(fileInputXml);
                    //
                    if (isSameData(doc, oldSysSettings))
                    {
                        throw new Exception(MessageCollection.T_MSG_DATA_OLD);
                    }
                    //
                    var commited = false;
                    try
                    {
                        environment.beginBatch();
                        //
                        #region delete firm prm


                        log.set(MessageCollection.T_MSG_DATA_DELETING);
                        //
                        {
                            string[] arrTables = new string[]
                            {
                                TableFIRMPARAMS.TABLE_FULL_NAME
                            };
                            string[] arrDesc = new string[]
                            {
                                environment.translate(WordCollection.T_ADDITIONAL)
                            };
                            deleteTables(arrTables, arrDesc);
                        }
                        //
                        //
                        #endregion
                        //
                        #region import firm prm

                        //
                        log.set(MessageCollection.T_MSG_DATA_IMPORT);
                        //
                        {
                            AdapterUserRecords[] arrAdapters = new AdapterUserRecords[]
                            {
                                new AdapterUserFirmParams(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetFirmParams(environment)))
                            };
                            string[] arrDesc = new string[]
                            {
                                environment.translate(WordCollection.T_ADDITIONAL)
                            };
                            importRecords(doc, arrAdapters, arrDesc);
                        }
                        #endregion
                        //
                        #region sys settings
                        environment.setSysSettings(getSysSettings());
                        //environment.getSysSettings().set(SettingsSysMob.MOB_SYS_LAST_IMPORT, DateTime.Now);
                        #endregion
                        //
                        #region delete rec


                        log.set(MessageCollection.T_MSG_DATA_DELETING);
                        //
                        {
                            string[] arrTables = new string[]
                            {
                                TableCLCARD.TABLE_FULL_NAME,
                                TableITEMS.TABLE_FULL_NAME,
                                TableWHOUSE.TABLE_FULL_NAME,
                                TableINFOFIRM.TABLE_FULL_NAME,
                                TableINFOPERIOD.TABLE_FULL_NAME,
                                TableINFODOCSAVE.TABLE_FULL_NAME
                            };
                            string[] arrDesc = new string[]
                            {
                                environment.translate(WordCollection.T_CLIENT),
                                environment.translate(WordCollection.T_MATERIAL),
                                environment.translate(WordCollection.T_WAREHOUSE),
                                environment.translate(WordCollection.T_INFO),
                                environment.translate(WordCollection.T_INFO),
                                environment.translate(WordCollection.T_INFO)
                            };
                            deleteTables(arrTables, arrDesc);
                        }
                        //
                        //
                        #endregion
                        //
                        #region docs
                        log.set(MessageCollection.T_MSG_DOCS_DELETING);
                        //
                        DateTime limDate = environment.getSysSettings().getDateTime(SettingsSysMob.MOB_SYS_CMD_DELETE_DOCS_BEFORE, new DateTime(DateTime.Now.Year, 1, 1));
                        {
                            string[][] arrTablesGroup = new string[][]
                            {
                                new string[] { TableINVOICE.TABLE_FULL_NAME, TableSTLINE.TABLE_LONG },
                                new string[] { TableORFICHE.TABLE_FULL_NAME, TableORFLINE.TABLE_LONG },
                                new string[] { TableKSLINES.TABLE_FULL_NAME }
                            };
                            string[] arrDesc = new string[]
                            {
                                environment.translate(WordCollection.T_DOC_STOCK_TRANS),
                                environment.translate(WordCollection.T_DOC_STOCK_ORDERS),
                                environment.translate(WordCollection.T_DOC_FINANCE)
                            };
                            deleteDocTables(arrTablesGroup, arrDesc, limDate);
                        }
                        #endregion
                        //
                        #region import

                        //
                        log.set(MessageCollection.T_MSG_DATA_IMPORT);
                        //
                        {
                            AdapterUserRecords[] arrAdapters = new AdapterUserRecords[]
                            {
                                new AdapterUserClient(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetClient(environment))),
                                new AdapterUserMaterial(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetMaterial(environment))),
                                new AdapterUserWarehouse(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetWarehouse(environment))),

                                new AdapterUserInfoFirm(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetInfoFirm(environment))),
                                new AdapterUserInfoPeriod(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetInfoPeriod(environment))),
                                new AdapterUserInfoDocSave(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetInfoDocSave(environment)))
                            };
                            string[] arrDesc = new string[]
                            {
                                environment.translate(WordCollection.T_CLIENT),
                                environment.translate(WordCollection.T_MATERIAL),
                                environment.translate(WordCollection.T_WAREHOUSE),
                                environment.translate(WordCollection.T_INFO),
                                environment.translate(WordCollection.T_INFO),
                                environment.translate(WordCollection.T_INFO)
                            };
                            importRecords(doc, arrAdapters, arrDesc);
                        }
                        #endregion
                        //clear



                        //
                        environment.clearStateData();
                        //

                        //ToolMobile.setRuntimeMsg("Data importded, commit started");

                        environment.commitBatch();
                        // state = true;
                        commited = true;

                        // ToolMobile.setRuntimeMsg("Data importded, commited");



                        #region files
                        {
                            try
                            {
                                var files = doc.SelectSingleNode("DATA/ITEM[@ei_code='ADP_FILES']");

                                if (files != null)
                                {
                                    foreach (var file in files)
                                    {
                                        var el = file as XmlElement;
                                        if (el != null)
                                        {
                                            var dir    = ToolXml.getAttribValue(el, "dir", null);
                                            var name   = ToolXml.getAttribValue(el, "name", null);
                                            var value_ = ToolXml.getAttribValue(el, "value", null);

                                            if (dir != null && name != null && value_ != null)
                                            {
                                                if (Path.IsPathRooted(dir))
                                                {
                                                    log.error(WordCollection.T_FILE + ": Path rooted: " + dir);
                                                }
                                                else
                                                {
                                                    if (!ToolMobile.existsDir(dir))
                                                    {
                                                        ToolMobile.createDir(dir);
                                                    }

                                                    var path = Path.Combine(dir, name);

                                                    log.set(WordCollection.T_FILE + ": " + path);

                                                    var data = Convert.FromBase64String(value_);

                                                    ToolMobile.writeFileData(path, data);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception exc)
                            {
                                ToolMobile.setExceptionInner(exc);


                                log.error("Files import error");

                                ToolMobile.setException(exc);
                            }
                        }
                        #endregion
                    }
                    catch (Exception exc)
                    {
                        try
                        {
                            ToolMobile.setExceptionInner(exc);
                        }
                        catch { }


                        try
                        {
                            if (!commited)
                            {
                                ToolMobile.setRuntimeMsg("Data import error, rollback started");

                                environment.rollbackBatch();

                                ToolMobile.setRuntimeMsg("Data import error, rollback ended");
                            }
                        }
                        catch { }


                        environment.setSysSettings(oldSysSettings);

                        throw new Exception(exc.Message, exc);
                    }

                    //if (commited)
                    //{
                    //    var dir = "cache";
                    //    if (ToolMobile.existsDir(dir))
                    //        ToolMobile.deleteDir(dir);
                    //}
                }
                catch (Exception exc)
                {
                    ToolMobile.setExceptionInner(exc);


                    var err = ToolException.unwrap(exc);


                    ToolMobile.setRuntimeMsg(err);



                    ToolMobile.getContextLast().RunOnUiThread(() =>
                    {
                        try
                        {
                            Android.Widget.Toast.MakeText(Android.App.Application.Context, err, Android.Widget.ToastLength.Long).Show();
                        }
                        catch { }
                    });

                    // ActivityExt.errMessageOnResume = err;


                    log.error(ToolException.unwrap(exc));
                    environment.getExceptionHandler().setException(exc);
                }
                finally
                {
                    log.set(MessageCollection.T_MSG_OPERATION_FINISHING);

                    Thread.Sleep(1000);
                    log.hide();
                }
            }
        }