Beispiel #1
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();
                }
            }
        }