Beispiel #1
0
        internal static bool RemoveTool(Tools form, ToolObjectList toolObjectList)
        {
            TreeView toolTreeView         = form.toolTreeView;
            TextBox  descriptionTextBox   = form.descriptionTextBox;
            TextBox  commandLineTextBox   = form.commandLineTextBox;
            TextBox  workingFolderTextBox = form.workingFolderTextBox;
            ComboBox runComboBox          = form.runComboBox;
            Button   removeButton         = form.removeButton;

            int indexNodeToRemove  = toolTreeView.SelectedNode.Index;
            int toolPositionInList = GetToolPositionInList(toolObjectList, descriptionTextBox.Text);

            if (toolPositionInList == -1)
            {
                String        error     = LanguageUtil.GetCurrentLanguageString("ErrorRemoving", className);
                ToolException exception = new ToolException(error);
                WindowManager.ShowErrorBox(form, error, exception);
                return(false);
            }
            toolObjectList.RemoveAt(toolPositionInList);

            toolTreeView.Focus();
            toolTreeView.Nodes.Remove(toolTreeView.SelectedNode);

            if (toolTreeView.Nodes.Count == 0)
            {
                descriptionTextBox.Text   = String.Empty;
                commandLineTextBox.Text   = String.Empty;
                workingFolderTextBox.Text = String.Empty;
                runComboBox.SelectedIndex = 0;

                descriptionTextBox.Enabled   = false;
                commandLineTextBox.Enabled   = false;
                workingFolderTextBox.Enabled = false;
                runComboBox.Enabled          = false;
                removeButton.Enabled         = false;
            }
            else if (toolTreeView.Nodes.Count > indexNodeToRemove)
            {
                toolTreeView.SelectedNode = toolTreeView.Nodes[indexNodeToRemove];

                descriptionTextBox.Enabled   = true;
                commandLineTextBox.Enabled   = true;
                workingFolderTextBox.Enabled = true;
                runComboBox.Enabled          = true;
                removeButton.Enabled         = true;
            }
            else
            {
                toolTreeView.SelectedNode = toolTreeView.Nodes[indexNodeToRemove - 1];

                descriptionTextBox.Enabled   = true;
                commandLineTextBox.Enabled   = true;
                workingFolderTextBox.Enabled = true;
                runComboBox.Enabled          = true;
                removeButton.Enabled         = true;
            }

            return(true);
        }
Beispiel #2
0
        internal static bool SaveDescription(Tools form, ToolObjectList toolObjectList)
        {
            TreeView toolTreeView       = form.toolTreeView;
            TextBox  descriptionTextBox = form.descriptionTextBox;

            if (String.IsNullOrEmpty(descriptionTextBox.Text))
            {
                WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("NameNotEmpty", className));
                descriptionTextBox.Focus();
                return(true);
            }

            ToolObject selectedToolObject = null;

            foreach (ToolObject toolObject in toolObjectList)
            {
                if (toolObject.Description != toolTreeView.SelectedNode.Text && toolObject.Description == descriptionTextBox.Text)
                {
                    WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("AlreadyExists", className));
                    descriptionTextBox.Focus();
                    return(true);
                }

                if (toolObject.Description == toolTreeView.SelectedNode.Text)
                {
                    selectedToolObject = toolObject;
                }
            }

            if (selectedToolObject == null)
            {
                String        error     = LanguageUtil.GetCurrentLanguageString("ErrorSaving", className);
                ToolException exception = new ToolException(error);
                WindowManager.ShowErrorBox(form, error, exception);
                return(false);
            }

            selectedToolObject.Description = descriptionTextBox.Text;
            toolTreeView.SelectedNode.Text = selectedToolObject.Description;

            return(true);
        }
Beispiel #3
0
        internal void ShouldCreateConfiguration(
            string[] args,
            bool success,
            string userName,
            string password,
            IEnumerable <string> runAsArguments,
            IEnumerable <string> commandArguments)
        {
            // Given
            var environment = new Mock <IEnvironment>();

            environment.SetupGet(i => i.Args).Returns(args);
            var           configurationFactory = new ConfigurationFactory(environment.Object);
            Configuration configuration        = null;
            ToolException exception            = null;

            // When
            try
            {
                configuration = configurationFactory.Create();
            }
            catch (ToolException ex)
            {
                exception = ex;
            }

            // Then
            if (success)
            {
                configuration.ShouldNotBeNull();
                configuration.UserName.ShouldBe(userName);
                configuration.Password.ShouldBe(password);
                configuration.RunAsArguments.ShouldBe(runAsArguments);
                configuration.CommandArguments.ShouldBe(commandArguments);
            }
            else
            {
                exception.ShouldNotBeNull();
            }
        }
Beispiel #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                LayoutInflater.Factory = CustomViewFactory.getInstance();

                base.OnCreate(savedInstanceState);


                initForm();
            }
            catch (Exception exc)
            {
                ToolMobile.setExceptionInner(exc);

                var err = ToolException.unwrap(exc);

                Close();


                Android.Widget.Toast.MakeText(this.ApplicationContext, err, Android.Widget.ToastLength.Long).Show();
            }
        }
Beispiel #5
0
        void doneAsync()
        {
            lock (environment)
            {
                bool ok = false;
                try
                {
                    //

                    log.set(MessageCollection.T_MSG_OPERATION_STARTING);
                    //
                    makeDbReadonly();

                    //
                    string fileWorkDir = ToolMobile.getFullPath("data");
                    ToolMobile.createDir(fileWorkDir);
                    string fileOutputZip = Path.Combine(fileWorkDir, "toava.zip");
                    string fileOutputXml = Path.Combine(fileWorkDir, "toava.xml");
                    // bool res = false;

                    //Source
                    //if (environment.getAppSettings().getBool(AvaExt.Settings.SettingsAvaAgent.MOB_USE_LOCAL_EXPIMP_B))
                    //{
                    //    //SaveFileDialog sfd = new SaveFileDialog();
                    //    //if (sfd.ShowDialog() == DialogResult.OK)
                    //    //    fileOutputXml = sfd.FileName;
                    //    //else
                    //    //    throw new Exception(string.Empty);
                    //}

                    //
                    log.set(MessageCollection.T_MSG_DATA_READING);
                    //
                    XmlDocument doc = new XmlDocument();

                    string docID = "LOGICALREF";

                    AdapterUserDocument[] adapters = new AdapterUserDocument[]
                    {
                        new AdapterUserWholesaleSlip(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetWholesaleSlip(environment))),
                        new AdapterUserWholesaleOrder(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetWholesaleOrder(environment))),
                        new AdapterUserCashClient(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetCashClient(environment)))
                    };
                    IPagedSource[] sources = new IPagedSource[]
                    {
                        new PagedSourceSlip(environment),
                        new PagedSourceOrder(environment),
                        new PagedSourceCashTrans(environment)
                    };
                    string[] arrDesc = new string[]
                    {
                        environment.translate(WordCollection.T_DOC_STOCK_TRANS),
                        environment.translate(WordCollection.T_DOC_STOCK_ORDERS),
                        environment.translate(WordCollection.T_DOC_FINANCE)
                    };
                    bool hasData = false;
                    for (int i = 0; i < sources.Length; ++i)
                    {
                        IPagedSource source = sources[i];
                        source.getBuilder().addParameterValue(TableDUMMY.CANCELLED, ConstBool.not);
                        AdapterUserDocument adapter = adapters[i];
                        log.set(MessageCollection.T_MSG_DATA_READING, new object[] { arrDesc[i] });
                        DataTable table = source.getAll();
                        log.set(MessageCollection.T_MSG_DATA_EXPORT, new object[] { arrDesc[i] });
                        foreach (DataRow row in table.Rows)
                        {
                            hasData = true;
                            adapter.edit(row[docID]);
                            adapter.export(doc);
                        }
                    }

                    if (!hasData)
                    {
                        throw new Exception(MessageCollection.T_MSG_ERROR_NO_DATA);
                    }
                    //
                    string[] expSettings = environment.getSysSettings().getAllSettings();
                    foreach (string settingsName in expSettings)
                    {
                        if (settingsName.StartsWith("MOB_SYS_"))
                        {
                            XmlAttribute attr = doc.CreateAttribute(settingsName);
                            attr.Value = environment.getSysSettings().getString(settingsName);
                            doc.DocumentElement.Attributes.Append(attr);
                        }
                    }


                    //
                    log.set(MessageCollection.T_MSG_DATA_WRITING);
                    //
                    doc.Save(fileOutputXml);
                    ToolZip.compress(fileOutputZip, fileOutputXml);
                    // if (!environment.getAppSettings().getBool(AvaExt.Settings.SettingsAvaAgent.MOB_USE_LOCAL_EXPIMP_B))
                    //  {
                    if (ToolMobile.existsFile(fileOutputZip))
                    {
                        //
                        log.set(MessageCollection.T_MSG_DATA_SENDING);
                        //
                        AgentData ad = new AgentData(environment);
                        ad.chackOperationResult(ad.sendData(ToolMobile.readFileData(fileOutputZip)));
                    }
                    // }
                    ok = true;
                }
                catch (Exception exc)
                {
                    log.error(ToolException.unwrap(exc));
                    environment.getExceptionHandler().setException(exc);
                }
                finally
                {
                    log.set(MessageCollection.T_MSG_OPERATION_FINISHING);

                    Thread.Sleep(1000);
                    log.hide();
                }
            }
        }
Beispiel #6
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();
                }
            }
        }