public void Should_convert_cost_center_to_cost_center_response()
        {
            var costCenter         = _costCenterInterface.GetByName("00000");
            var costCenterResponse = _costCenterConverter.ConvertCostCenter(costCenter[0]);

            Assert.IsNotNull(costCenterResponse);
        }
示例#2
0
        public void ConvertData <T>(T item) where T : class
        {
            var  resultType = typeof(T);
            var  xml        = string.Empty;
            var  json       = string.Empty;
            var  code       = string.Empty;
            bool art        = false;

            if (resultType == typeof(Customer))
            {
                var x = item as Customer;
                var r = _customerConverter.ConvertCustomer(x);
                code = r.Code;
                var customer = (new ResponseClassToXmlClass()).ConvertCustomer(r);
                if (_form.XmlCheckBox.Checked)
                {
                    xml = (new Xml.ClassToXml <XmlCustomer>()).WriteXml(customer);
                }

                if (_form.JsonCheckBox.Checked)
                {
                    json = (new ClassToJson <XmlCustomer>()).WriteJson(customer);
                }
            }

            if (resultType == typeof(Supplier))
            {
                var x  = item as Supplier;
                var rs = _supplierConverter.ConvertSupplier(x);
                code = rs.Code;
                var supplier = (new ResponseClassToXmlClass()).ConvertSupplier(rs);
                if (_form.XmlCheckBox.Checked)
                {
                    xml = (new Xml.ClassToXml <XmlSupplier>()).WriteXml(supplier);
                }

                if (_form.JsonCheckBox.Checked)
                {
                    json = (new ClassToJson <XmlSupplier>()).WriteJson(supplier);
                }
            }

            if (resultType == typeof(Article))
            {
                art = true;
                var x       = item as Article;
                var ar      = _articleConverter.ConvertArticle(x);
                var product = (new ResponseClassToXmlClass()).ConvertProducts(ar);
                if (_form.XmlCheckBox.Checked)
                {
                    xml = (new Xml.ClassToXml <XmlProducts>()).WriteXml(product);
                }

                if (_form.JsonCheckBox.Checked)
                {
                    json = (new ClassToJson <XmlProducts>()).WriteJson(product);
                }
                _form.LogBox.AppendText("\r\nData ");
                for (int i = 0; i < ar.Count; i++)
                {
                    if (i == 0)
                    {
                        _form.LogBox.AppendText(ar[i].Code);
                    }
                    else
                    {
                        _form.LogBox.AppendText(", " + ar[i].Code);
                    }
                }
                _form.LogBox.AppendText(" created in middleware");
            }

            if (resultType == typeof(SalesInvoice))
            {
                var x   = item as SalesInvoice;
                var sir = _salesInvoiceConverter.ConvertSalesInvoice(x);
                code = sir.OrderNummer;
                var salesInvoice = (new ResponseClassToXmlClass()).ConvertSalesInvoice(sir);
                if (_form.XmlCheckBox.Checked)
                {
                    xml = (new Xml.ClassToXml <XmlSalesInvoice>()).WriteXml(salesInvoice);
                }

                if (_form.JsonCheckBox.Checked)
                {
                    json = (new ClassToJson <XmlSalesInvoice>()).WriteJson(salesInvoice);
                }
                _form.LogBox.AppendText("\r\nSales invoice " + sir.OrderNummer + " created in middleware");
            }

            if (resultType == typeof(BalanceSheet))
            {
                var x   = item as BalanceSheet;
                var glr = _generalLedgerConverter.ConvertBalanceSheet(x);
                code = glr.Code;
                var balanceSheet = (new ResponseClassToXmlClass()).ConvertGeneralLedger(glr);
                if (_form.XmlCheckBox.Checked)
                {
                    xml = (new Xml.ClassToXml <XmlGeneralLedger>()).WriteXml(balanceSheet);
                }

                if (_form.JsonCheckBox.Checked)
                {
                    json = (new ClassToJson <XmlGeneralLedger>()).WriteJson(balanceSheet);
                }
            }

            if (resultType == typeof(ProfitLoss))
            {
                var x   = item as ProfitLoss;
                var glr = _generalLedgerConverter.ConvertProfitLoss(x);
                code = glr.Code;
                var profitLoss = (new ResponseClassToXmlClass()).ConvertGeneralLedger(glr);
                if (_form.XmlCheckBox.Checked)
                {
                    xml = (new Xml.ClassToXml <XmlGeneralLedger>()).WriteXml(profitLoss);
                }

                if (_form.JsonCheckBox.Checked)
                {
                    json = (new ClassToJson <XmlGeneralLedger>()).WriteJson(profitLoss);
                }
            }

            if (resultType == typeof(CostCenter))
            {
                var x   = item as CostCenter;
                var ccr = _costCenterConverter.ConvertCostCenter(x);
                code = ccr.Code;
                var costcenter = (new ResponseClassToXmlClass()).ConvertCostCenter(ccr);
                if (_form.XmlCheckBox.Checked)
                {
                    xml = (new Xml.ClassToXml <XmlCostCenter>()).WriteXml(costcenter);
                }

                if (_form.JsonCheckBox.Checked)
                {
                    json = (new ClassToJson <XmlCostCenter>()).WriteJson(costcenter);
                }
            }

            if (!art)
            {
                _form.LogBox.AppendText("\r\nData " + code + " created in middleware");
            }


            if (_form.XmlCheckBox.Checked)
            {
                _form.LogBox.AppendText("\r\nXml file '" + xml + "' created");
            }

            if (_form.JsonCheckBox.Checked)
            {
                _form.LogBox.AppendText("\r\nJson file '" + json + "' created");
            }

            _form.LogBox.SelectionColor = Color.Black;
            Cursor.Current            = Cursors.Arrow;
            _form.resultBar.BackColor = Color.Chartreuse;
            _form.LogBox.ScrollToCaret();
        }