Exemplo n.º 1
0
        public getCustomerVehiclesResponse getCustomerVehicles(getCustomerVehiclesRequest request)
        {
            Int32 kontonr;
            Int32 fahrzeugid;
            string fahrgestellnr = "";
            string zulassungskz = "";
            string marke = "";
            string verkaufstyp = "";
            string bezeichnung = "";
            string motorseriennr = "";
            DateTime datumerstzulassung;
            string datErstzulassung = "";
            Int32 kilometerstand;
            string farbe = "";
            string innenausstattung = "";
            Int32 kw;
            DateTime datumbesuch;
            string datBesuch = "";
            DateTime creationdate;
            string creationuser = "";
            DateTime modifieddate;
            string modifieduser = "";
            DateTime datumzulassungkunde;
            string datZulassungkunde = "";
            DateTime datumhu;
            string datHU = "";
            DateTime datumau;
            string datAU = "";
            string zuendschluesselnr = "";
            string tuerschluesselnr = "";
            string radiocode = "";
            Int32 hubraum;
            string kbahsnr = "";
            string kbatsnr = "";
            string motortyp = "";
            string kfzbriefnr = "";
            string treibstoff = "";
            string info = "";
            string kfzversicherung = "";
            Int32 modelljahr;
            bool aktiv = false;
            string strVerkaeufer = "";
            string strKW = "";
            string strHubraum = "";
            string strModelljahr = "";
            string strKilometerstand = "";

            DateTime dtDefaultDB;
            dtDefaultDB = Convert.ToDateTime("01.01.1900");
            creationdate = dtDefaultDB;
            modifieddate = dtDefaultDB;
            datumzulassungkunde = dtDefaultDB;
            datumhu = dtDefaultDB;
            datumau = dtDefaultDB;
            datumbesuch = dtDefaultDB;
            datumerstzulassung = dtDefaultDB;

            getCustomerVehiclesResponse res = new getCustomerVehiclesResponse();

            interfaceData iData = new interfaceData();
            customerVehicleType cV;

            System.Collections.ArrayList aFahrzeuge = new System.Collections.ArrayList();

            salesmanType sT = new salesmanType();
            sT.identifier = "fmad";
            sT.name = "Fmade";

            using (DBConnect myConnect = new DBConnect())
            {
                String sqlCommand;
                //Limitierung auf 100 Adressdatensätzen pro Abruf
                sqlCommand = "SELECT TOP 100 START AT " + request.Body.arg0.ToString() + " a.kontonr, b.fahrzeugid, b.fahrgestellnr, b.zulassungskz, b.marke, b.verkaufstyp, b.bezeichnung, ";
                //sqlCommand = "SELECT  a.kontonr, b.fahrzeugid, b.fahrgestellnr, b.zulassungskz, b.marke, b.verkaufstyp, b.bezeichnung, ";
                sqlCommand += "b.motorseriennr, b.datumerstzulassung, b.kilometerstand, b.farbe, b.innenausstattung, b.kw, b.verkaeufer, b.datumbesuch, b.creationdate, b.creationuser, b.modifieddate, b.modifieduser, ";
                sqlCommand += "b.datumzulassungkunde, b.datumhu, b.datumau, b.zuendschluesselnr, b.tuerschluesselnr, b.radiocode, b.hubraum, b.kbahsnr, b.motortyp, b.kfzbriefnr, b.treibstoff, b.info, b.kfzversicherung, b.modelljahr, ";
                sqlCommand += " b.aktiv, b.kbatsnr";
                sqlCommand += " FROM bungert.adresse a, bungert.fahrzeug b";
                sqlCommand += " WHERE  a.adressid = b.kundenadrid";
                //sqlCommand += " AND b.zulassungskz = 'B-AR 6700'";
                sqlCommand += " ORDER BY b.fahrzeugid";
                OdbcCommand cmd = new OdbcCommand(sqlCommand, myConnect.conn);
                //cmd.Parameters.Add(":fahrgestellnr", OdbcType.VarChar, 17).Value = vin;

                myConnect.Connect();

                OdbcDataReader reader;
                //DataReader Objekt wird initialisiert

                using (reader = cmd.ExecuteReader())
                {

                    if (reader.HasRows)
                    {

                        while (reader.Read())
                        {
                            cV = new customerVehicleType();

                            kontonr = 0;

                            kontonr = reader.GetInt32(0);
                            fahrzeugid = reader.GetInt32(1);
                            fahrgestellnr = reader.GetValue(2).ToString();
                            zulassungskz = reader.GetValue(3).ToString();
                            marke = reader.GetValue(4).ToString();
                            verkaufstyp = reader.GetValue(5).ToString();
                            bezeichnung = reader.GetValue(6).ToString();
                            motorseriennr = reader.GetValue(7).ToString();
                            datErstzulassung = reader.GetValue(8).ToString();
                            strKilometerstand = reader.GetValue(9).ToString();
                            farbe = reader.GetValue(10).ToString();
                            innenausstattung = reader.GetValue(11).ToString();
                            strKW = reader.GetValue(12).ToString();
                            strVerkaeufer = reader.GetValue(13).ToString();
                            datBesuch = reader.GetValue(14).ToString();
                            creationdate = reader.GetDateTime(15);
                            creationuser = reader.GetValue(16).ToString();
                            modifieddate = reader.GetDateTime(17);
                            modifieduser = reader.GetValue(18).ToString();
                            datZulassungkunde = reader.GetValue(19).ToString();
                            datHU = reader.GetValue(20).ToString();
                            datAU = reader.GetValue(21).ToString();
                            zuendschluesselnr = reader.GetValue(22).ToString();
                            tuerschluesselnr = reader.GetValue(23).ToString();
                            radiocode = reader.GetValue(24).ToString();
                            strHubraum = reader.GetValue(25).ToString();
                            kbahsnr = reader.GetValue(26).ToString();
                            motortyp = reader.GetValue(27).ToString();
                            kfzbriefnr = reader.GetValue(28).ToString();
                            treibstoff = reader.GetValue(29).ToString();
                            info = reader.GetValue(30).ToString();
                            kfzversicherung = reader.GetValue(31).ToString();
                            strModelljahr = reader.GetValue(32).ToString();
                            aktiv = reader.GetBoolean(33);
                            kbatsnr = reader.GetValue(34).ToString();

                            //Datum Erstzulassung
                            if (String.IsNullOrWhiteSpace(datErstzulassung))
                            {
                                datumerstzulassung = dtDefaultDB;
                            }
                            else
                            {
                                datumerstzulassung = Convert.ToDateTime(datErstzulassung);
                            }

                            //Datum Besuch
                            if (String.IsNullOrWhiteSpace(datBesuch))
                            {
                                datumbesuch = dtDefaultDB;
                            }
                            else
                            {
                                datumbesuch = Convert.ToDateTime(datBesuch);
                            }

                            //Datum Zulassungkunde
                            if (String.IsNullOrWhiteSpace(datZulassungkunde))
                            {
                                datumzulassungkunde = dtDefaultDB;
                            }
                            else
                            {
                                datumzulassungkunde = Convert.ToDateTime(datZulassungkunde);
                            }

                            //Datum HU
                            if (String.IsNullOrWhiteSpace(datHU))
                            {
                                datumhu = dtDefaultDB;
                            }
                            else
                            {
                                datumhu = Convert.ToDateTime(datHU);
                            }

                            //Datum AU
                            if (String.IsNullOrWhiteSpace(datAU))
                            {
                                datumau = dtDefaultDB;
                            }
                            else
                            {
                                datumau = Convert.ToDateTime(datAU);
                            }

                            customerIdentificationType custID = new customerIdentificationType();
                            custID.number = kontonr;

                            //US 10.02.2014
                            //Standort muss zum Verkaeufer passen - standardmäßig "location=1"
                            custID.location = 1;

                            cV.customerNumber = custID;
                            cV.vehicleNumber = fahrzeugid;
                            cV.vin = fahrgestellnr;

                            if (aktiv)
                            {
                                cV.deleted = false;
                            }
                            else
                            {
                                cV.deleted = true;
                            }

                            cV.licensePlate = zulassungskz;
                            cV.brand = marke;
                            cV.typeCode = verkaufstyp;
                            cV.type = bezeichnung;

                            if (String.IsNullOrWhiteSpace(strModelljahr))
                            {
                                modelljahr = 0;
                            }
                            else
                            {
                                modelljahr = Convert.ToInt32(strModelljahr);
                            }

                            cV.modelYear = Convert.ToDateTime("01.01." + modelljahr.ToString());
                            cV.modelYearSpecified = true;
                            cV.motorNumber = motorseriennr;
                            cV.firstRegistration = datumerstzulassung;
                            cV.firstRegistrationSpecified = true;

                            if (String.IsNullOrWhiteSpace(strKilometerstand))
                            {
                                kilometerstand = 0;
                            }
                            else
                            {
                                kilometerstand = Convert.ToInt32(strKilometerstand);
                            }

                            cV.milage = kilometerstand;
                            cV.milageSpecified = true;
                            cV.exteriorColor = farbe;
                            cV.interiorColor = innenausstattung;

                            if (String.IsNullOrWhiteSpace(strKW))
                            {
                                kw = 0;
                            }
                            else
                            {
                                kw = Convert.ToInt32(strKW);
                            }

                            cV.kw = kw;

                            customerVehicleTypeLastInvoice custLI = new customerVehicleTypeLastInvoice();
                            custLI.date = datumbesuch;
                            custLI.dateSpecified = true;
                            cV.lastInvoice = custLI;

                            customerVehicleTypeCreation custCreate = new customerVehicleTypeCreation();
                            custCreate.date = creationdate;
                            custCreate.dateSpecified = true;

                            cV.creation = custCreate;

                            salesmanType custST = new salesmanType();
                            custST.identifier = creationuser;
                            custST.name = creationuser;

                            custCreate.salesman = custST;

                            customerVehicleTypeLastChange custLS = new customerVehicleTypeLastChange();
                            custLS.date = modifieddate;
                            custLS.dateSpecified = true;

                            custST = new salesmanType();
                            custST.identifier = modifieduser;
                            custST.name = modifieduser;

                            custLS.salesman = custST;

                            cV.lastChange = custLS;

                            //Datum Zulassungkunde
                            cV.lastRegistrationSpecified = false;

                            if (datumzulassungkunde.Date > dtDefaultDB.Date)
                            {
                                cV.lastRegistration = datumzulassungkunde;
                                cV.lastRegistrationSpecified = true;
                            }

                            //Datum HU
                            cV.testDate1Specified = false;

                            if (datumhu.Date > dtDefaultDB.Date)
                            {
                                cV.testDate1 = datumhu;
                                cV.testDate1Specified = true;
                            }

                            //Datum AU
                            cV.testDate2Specified = false;

                            if (datumau.Date > dtDefaultDB.Date)
                            {
                                cV.testDate2 = datumau;
                                cV.testDate2Specified = true;
                            }

                            cV.keyCode1 = zuendschluesselnr;
                            cV.keyCode2 = tuerschluesselnr;
                            cV.radioCode = radiocode;

                            if (String.IsNullOrWhiteSpace(strHubraum))
                            {
                                hubraum = 0;
                            }
                            else
                            {
                                hubraum = Convert.ToInt32(strHubraum);
                            }

                            if (String.IsNullOrWhiteSpace(kbahsnr)) kbahsnr = "";
                            if (String.IsNullOrWhiteSpace(kbatsnr)) kbatsnr = "";
                            cV.kbaNumber = kbahsnr + "/" + kbatsnr;
                            cV.capacity = hubraum;
                            cV.capacitySpecified = true;
                            cV.motorCode = motortyp;
                            cV.carsLetter = kfzbriefnr;
                            cV.fuelDescription = treibstoff;
                            cV.remark = info;

                            customerVehicleTypeInsurance custInsurance = new customerVehicleTypeInsurance();
                            custInsurance.policyNumber = kfzversicherung;

                            cV.insurance = custInsurance;

                            aFahrzeuge.Add(cV);

                        }

                    }
                    reader.Close();
                }
            }

            customerVehicleType[] aCustVehicle = new customerVehicleType[aFahrzeuge.Count];
            //List<customerVehicleType> aCustVehicle = new List<customerVehicleType>();
            for (int i = 0; i < aFahrzeuge.Count; i++)
            {
                customerVehicleType custV = (customerVehicleType)aFahrzeuge[i];
                aCustVehicle[i] = custV;
            }

            iData.customerVehicle = aCustVehicle;
            iData.interfaceVersion = 1;
            iData.dataProvider = "STANDARD_INTERFACE";

            iData.callingUser = sT;
            iData.transmissionReason = "";

            System.IO.StringWriter stringWriter = new System.IO.StringWriter();

            var serializer = new XmlSerializer(typeof(interfaceData));
            using (var xw = XmlWriter.Create(stringWriter, new XmlWriterSettings { Encoding = new UTF8Encoding() }))
            {
                serializer.Serialize(xw, iData);

            }

            #region xml encoding
            //string result;
            //using (MemoryStream memoryStream = new MemoryStream())
            //{
            //    XmlSerializer xs = new XmlSerializer(typeof(interfaceData));
            //    XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
            //    xs.Serialize(xmlTextWriter, iData);
            //    result = Encoding.UTF8.GetString(memoryStream.ToArray());
            //}
            //if (String.IsNullOrEmpty(result))
            //    result = "";
            #endregion

            getCustomerVehiclesResponseBody resBody = new getCustomerVehiclesResponseBody();

            resBody.@return = stringWriter.ToString();

            res.Body = resBody;

            SmitConfig sc = new SmitConfig();
            sc = ReadXML();
            sc.changedCustomerVehicleDate = DateTime.Now.ToString("yyyy-MM-dd");

            WriteXML(sc);

            return res;
        }
Exemplo n.º 2
0
        public getNewInvoiceResponse getNewInvoices(getNewInvoiceRequest request)
        {
            Int32 rechnungsNr;
            Int32 kontoNr;
            string strKontoNr = "";
            string kundenName1 = "";
            string kundenName2 = "";
            string kundenName3 = "";
            string kundenVorname = "";
            string kundenStrasse = "";
            string kundenPLZ = "";
            string kundenOrt = "";
            string kundenLand = "";
            Int32 rechnungsAdrID;
            string strRechnungsAdrID = "";
            string rechnungName1 = "";
            string rechnungName2 = "";
            string rechnungName3 = "";
            string rechnungVorname = "";
            string rechnungStrasse = "";
            string rechnungPLZ = "";
            string rechnungOrt = "";
            string rechnungLand = "";
            Int32 fahrzeugID;
            string fahrgestellNr = "";
            string marke = "";
            string bezeichnung = "";
            string zulassungsKZ = "";
            Int32 kilometerstand;
            string strKilometerstand = "";
            string motorserienNr = "";
            DateTime rechnungsDatum;
            string strRechnungsDatum = "";
            string strRechnungsNr = "";
            DateTime datumAuftrag;
            string strDatumAuftrag = "";
            string auftragNr = "";
            Int32 annehmer;
            string strAnnehmer = "";
            decimal sumVkGesamt;
            string strSumVkGesamt = "";
            decimal sumMwst;
            string strSumMwst = "";
            decimal posAnzahl;
            string strPosAnzahl = "";
            decimal posVkGesamt;
            string strPosVkGesamt = "";
            decimal posRabattBetrag;
            string strPosRabattBetrag = "";
            Int32 mwstCode;
            string kundenAnrede = "";
            string rechnungAnrede = "";

            DateTime dtDefaultDB;
            dtDefaultDB = Convert.ToDateTime("01.01.1900");

            rechnungsDatum = dtDefaultDB;
            datumAuftrag = dtDefaultDB;

            getNewInvoiceResponse res = new getNewInvoiceResponse();

            interfaceData iData = new interfaceData();

            invoiceType iT;
            invoiceTypeHeader iTH;
            invoiceCustomerTypeName[] aICTN;
            //List<invoiceCustomerTypeName> aICTN;
            invoiceCustomerTypeAddress iCTA;
            invoiceTypeHeaderVehicle iTHV;
            customerIdentificationType cIT;

            System.Collections.ArrayList aRechnungen = new System.Collections.ArrayList();

            salesmanType sT = new salesmanType();
            sT.identifier = "fmad";
            sT.name = "Fmade";

            SmitConfig sc = new SmitConfig();
            sc = ReadXML();

            using (DBConnect myConnect = new DBConnect())
            {

                String sqlCommand;
                //Limitierung auf 100 Auftragdatensätzen pro Abruf
                sqlCommand = "SELECT TOP 100 START AT " + request.Body.arg0.ToString() + " rechnungsnr, kontonr, kundenname1, kundenname2, kundenname3, kundenvorname, kundenstrasse, kundenplz, kundenort, kundenland, ";
                sqlCommand += " rechnungadrid, rechnungname1, rechnungname2, rechnungname3, rechnungvorname, rechnungstrasse, rechnungplz, rechnungort, rechnungland,";
                sqlCommand += " a.fahrzeugid, c.fahrgestellnr, c.marke, c.bezeichnung, c.zulassungskz, c.kilometerstand, c.motorseriennr, rechnungsdatum, rechnungsnr, datumauftrag, auftragnr, annehmer, sumvkgesamt, ";
                sqlCommand += " ifnull(summwst1, 0, summwst1) + ifnull(summwst2,0,summwst2) + ifnull(summwstat, 0, summwstat)  , kundenanrede, rechnunganrede ";
                sqlCommand += " FROM bungert.auftrag a, bungert.fahrzeug c";
                sqlCommand += " WHERE a.fahrzeugid = c.fahrzeugid and a.rechnungsnr is not null and a.rechnungsnr <> 0";
                sqlCommand += " AND a.auftragnr > " + (String.IsNullOrWhiteSpace(sc.lastOrderNumber) ? Int32.MaxValue.ToString() : sc.lastOrderNumber);
                sqlCommand += " ORDER BY a.auftragnr";
                OdbcCommand cmd = new OdbcCommand(sqlCommand, myConnect.conn);

                myConnect.Connect();

                OdbcDataReader reader;
                //DataReader Objekt wird initialisiert

                using (reader = cmd.ExecuteReader())
                {

                    if (reader.HasRows)
                    {

                        while (reader.Read())
                        {
                            iT = new invoiceType();
                            iTH = new invoiceTypeHeader();

                            rechnungsNr = reader.GetInt32(0);
                            strKontoNr = reader.GetValue(1).ToString();
                            kundenName1 = reader.GetValue(2).ToString();
                            kundenName2 = reader.GetValue(3).ToString();
                            kundenName3 = reader.GetValue(4).ToString();
                            kundenVorname = reader.GetValue(5).ToString();
                            kundenStrasse = reader.GetValue(6).ToString();
                            kundenPLZ = reader.GetValue(7).ToString();
                            kundenOrt = reader.GetValue(8).ToString();
                            kundenLand = reader.GetValue(9).ToString();
                            strRechnungsAdrID = reader.GetValue(10).ToString();
                            rechnungName1 = reader.GetValue(11).ToString();
                            rechnungName2 = reader.GetValue(12).ToString();
                            rechnungName3 = reader.GetValue(13).ToString();
                            rechnungVorname = reader.GetValue(14).ToString();
                            rechnungStrasse = reader.GetValue(15).ToString();
                            rechnungPLZ = reader.GetValue(16).ToString();
                            rechnungOrt = reader.GetValue(17).ToString();
                            rechnungLand = reader.GetValue(18).ToString();
                            fahrzeugID = reader.GetInt32(19);
                            fahrgestellNr = reader.GetValue(20).ToString();
                            marke = reader.GetValue(21).ToString();
                            bezeichnung = reader.GetValue(22).ToString();
                            zulassungsKZ = reader.GetValue(23).ToString();
                            strKilometerstand = reader.GetValue(24).ToString();
                            motorserienNr = reader.GetValue(25).ToString();
                            strRechnungsDatum = reader.GetValue(26).ToString();
                            strDatumAuftrag = reader.GetValue(28).ToString();
                            auftragNr = reader.GetValue(29).ToString();
                            strAnnehmer = reader.GetValue(30).ToString();
                            strSumVkGesamt = reader.GetValue(31).ToString();
                            strSumMwst = reader.GetValue(32).ToString();
                            kundenAnrede = reader.GetValue(33).ToString();
                            rechnungAnrede = reader.GetValue(34).ToString();

                            Decimal.TryParse(strSumVkGesamt, out sumVkGesamt);
                            Decimal.TryParse(strSumMwst, out sumMwst);
                            Decimal.TryParse(strPosAnzahl, out posAnzahl);
                            Decimal.TryParse(strPosRabattBetrag, out posRabattBetrag);
                            Decimal.TryParse(strPosVkGesamt, out posVkGesamt);

                            iT.invoiceID = rechnungsNr;

                            iTH.location = 1;
                            iTH.kindOfInvoice = invoiceTypeHeaderKindOfInvoice.workshop;

                            //Kunde
                            //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                            invoiceCustomerType iCT = new invoiceCustomerType();

                            // Salutatuon 1 = Herr / 2 = Frau
                            if (kundenAnrede.ToLower().Contains("herr"))
                            {
                                iCT.salutation = 1;
                            }
                            else if (kundenAnrede.ToLower().Contains("frau"))
                            {
                                iCT.salutation = 2;
                            }
                            else if (kundenAnrede.ToLower().Contains("firma"))
                            {
                                iCT.salutation = 9;
                            }

                            aICTN = new invoiceCustomerTypeName[4];
                            //aICTN = new List<invoiceCustomerTypeName>();
                            invoiceCustomerTypeName iCTN;

                            if (iCT.salutation == 1 || iCT.salutation == 2)
                            {
                                kundenName1 = kundenVorname + " " + kundenName1;
                                kundenVorname = "";
                            }

                            iCTN = new invoiceCustomerTypeName();
                            iCTN.name = kundenName1;
                            iCTN.sequence = 1;
                            aICTN[0] = iCTN;

                            iCTN = new invoiceCustomerTypeName();
                            iCTN.name = kundenName2;
                            iCTN.sequence = 2;
                            aICTN[1] = iCTN;

                            iCTN = new invoiceCustomerTypeName();
                            iCTN.name = kundenName3;
                            iCTN.sequence = 3;
                            aICTN[2] = iCTN;

                            iCTN = new invoiceCustomerTypeName();
                            iCTN.name = kundenVorname;
                            iCTN.sequence = 4;
                            aICTN[3] = iCTN;

                            iCTA = new invoiceCustomerTypeAddress();

                            iCTA.city = kundenOrt;
                            iCTA.country = kundenLand;
                            iCTA.street = kundenStrasse;
                            iCTA.zip = kundenPLZ;

                            iCT.address = iCTA;

                            //KontoNr
                            if (String.IsNullOrWhiteSpace(strKontoNr))
                            {
                                kontoNr = 0;
                            }
                            else
                            {
                                kontoNr = Convert.ToInt32(strKontoNr);
                            }

                            //RechnungsAdrID
                            if (String.IsNullOrWhiteSpace(strRechnungsAdrID))
                            {
                                rechnungsAdrID = 0;
                            }
                            else
                            {
                                rechnungsAdrID = Convert.ToInt32(strRechnungsAdrID);
                            }

                            cIT = new customerIdentificationType();
                            cIT.location = 1;
                            cIT.number = kontoNr;

                            iCT.customerNumber = cIT;

                            iCT.name = aICTN;

                            iTH.customer = iCT;
                            //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                            //Abweichender Rechnungsempfänger
                            //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                            iCT = new invoiceCustomerType();

                            // Salutatuon 1 = Herr / 2 = Frau
                            if (rechnungAnrede.ToLower().Contains("herr"))
                            {
                                iCT.salutation = 1;
                            }
                            else if (rechnungAnrede.ToLower().Contains("frau"))
                            {
                                iCT.salutation = 2;
                            }
                            else if (rechnungAnrede.ToLower().Contains("firma"))
                            {
                                iCT.salutation = 9;
                            }

                            aICTN = new invoiceCustomerTypeName[4];
                            //aICTN = new List<invoiceCustomerTypeName>();

                            if (iCT.salutation == 1 || iCT.salutation == 2)
                            {
                                rechnungName1 = rechnungVorname + " " + rechnungName1;
                                rechnungVorname = "";
                            }

                            iCTN = new invoiceCustomerTypeName();
                            iCTN.name = rechnungName1;
                            iCTN.sequence = 1;
                            aICTN[0] = iCTN;

                            iCTN = new invoiceCustomerTypeName();
                            iCTN.name = rechnungName2;
                            iCTN.sequence = 2;
                            aICTN[1] = iCTN;

                            iCTN = new invoiceCustomerTypeName();
                            iCTN.name = rechnungName3;
                            iCTN.sequence = 3;
                            aICTN[2] = iCTN;

                            iCTN = new invoiceCustomerTypeName();
                            iCTN.name = rechnungVorname;
                            iCTN.sequence = 4;
                            aICTN[3] = iCTN;

                            iCTA = new invoiceCustomerTypeAddress();

                            iCTA.city = rechnungOrt;
                            iCTA.country = rechnungLand;
                            iCTA.street = rechnungStrasse;
                            iCTA.zip = rechnungPLZ;

                            iCT.address = iCTA;

                            //RechnungsAdrID
                            if (String.IsNullOrWhiteSpace(strRechnungsAdrID))
                            {
                                rechnungsAdrID = 0;
                            }
                            else
                            {
                                rechnungsAdrID = Convert.ToInt32(strRechnungsAdrID);
                            }

                            cIT = new customerIdentificationType();
                            cIT.location = 1;
                            cIT.number = getKontNr(rechnungsAdrID, myConnect);

                            iCT.customerNumber = cIT;

                            iCT.name = aICTN;

                            iTH.differentInvoiceReceiver = iCT;
                            //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                            iTHV = new invoiceTypeHeaderVehicle();

                            iTHV.brand = marke;
                            iTHV.licensePlate = zulassungsKZ;

                            //Kilometerstand
                            if (String.IsNullOrWhiteSpace(strKilometerstand))
                            {
                                kilometerstand = 0;
                            }
                            else
                            {
                                kilometerstand = Convert.ToInt32(strKilometerstand);
                            }

                            iTHV.milage = kilometerstand;
                            iTHV.motorNumber = motorserienNr;
                            iTHV.type = bezeichnung;
                            iTHV.vehicleNumber = fahrzeugID;
                            //iTHV.vehicleType =
                            iTHV.vin = fahrgestellNr;

                            iTH.vehicle = iTHV;

                            //Rechnungsdatum
                            if (String.IsNullOrWhiteSpace(strRechnungsDatum))
                            {
                                rechnungsDatum = dtDefaultDB;
                            }
                            else
                            {
                                rechnungsDatum = Convert.ToDateTime(strRechnungsDatum);
                            }

                            iTH.invoiceDate = rechnungsDatum;
                            iTH.invoiceNumber = rechnungsNr.ToString();
                            //iTH.kindOfInvoice =

                            //Datum Auftrag
                            if (String.IsNullOrWhiteSpace(strDatumAuftrag))
                            {
                                datumAuftrag = dtDefaultDB;
                            }
                            else
                            {
                                datumAuftrag = Convert.ToDateTime(strDatumAuftrag);
                            }

                            iTH.orderDate = datumAuftrag;
                            iTH.orderNumber = auftragNr.ToString();

                            //Annehmer
                            if (String.IsNullOrWhiteSpace(strAnnehmer))
                            {
                                annehmer = 0;
                            }
                            else
                            {
                                annehmer = Convert.ToInt32(strAnnehmer);
                            }

                            iTH.acceptor = getSalesman(annehmer, myConnect);

                            iTH.sumGross = Convert.ToDouble(sumVkGesamt);
                            iTH.sumNet = Convert.ToDouble(sumVkGesamt - sumMwst);

                            //iTH.vat = mw

                            iT.positions = getPostionen(auftragNr, myConnect);

                            iT.header = iTH;

                            //salesVehicleTypeDetailsPricesEfforts efforts = new salesVehicleTypeDetailsPricesEfforts();
                            //efforts.internEffort1Specified = (efforts.internEffort1 = Convert.ToDouble(aufbereitungek)) > 0;

                            if(!String.IsNullOrWhiteSpace(auftragNr))
                                aRechnungen.Add(iT);

                        }

                    }
                    reader.Close();
                }
            }

            invoiceType[] aInvoice = new invoiceType[aRechnungen.Count];
            //List<invoiceType> aInvoice = new List<invoiceType>();
            for (int i = 0; i < aRechnungen.Count; i++)
            {
                invoiceType iType = (invoiceType)aRechnungen[i];
                aInvoice[i] = iType;
            }

            iData.invoice = aInvoice;
            iData.interfaceVersion = 1;
            iData.dataProvider = "STANDARD_INTERFACE";

            iData.callingUser = sT;
            iData.transmissionReason = "";

            System.IO.StringWriter stringWriter = new System.IO.StringWriter();

            var serializer = new XmlSerializer(typeof(interfaceData));
            using (var xw = XmlWriter.Create(stringWriter, new XmlWriterSettings { Encoding = new UTF8Encoding() }))
            {
                serializer.Serialize(xw, iData);
            }

            if (!String.IsNullOrWhiteSpace(auftragNr))
            {
                sc.lastOrderNumber = auftragNr;
                WriteXML(sc);
            }

            getNewInvoiceResponseBody resBody = new getNewInvoiceResponseBody();

            resBody.@return = stringWriter.ToString();

            res.Body = resBody;

            return res;
        }
Exemplo n.º 3
0
        //US 22.01.2014
        //Daten für die Kommunikation werden alle aus der Tabelle "marketingkontakt" abgefragt, da eine Zustimmung des Kunden vorliegen muss (RB 22.01.2014)
        public getCustomersResponse getCustomers(getCustomersRequest request)
        {
            Int32 kontonr;
            string anrede = "";
            string vorname = "";
            string name1 = "";
            string name2 = "";
            string name3 = "";
            string suchname = "";
            string strasse = "";
            string plz = "";
            string ort = "";
            string land = "";
            string telefonp = "";
            string mobilp = "";
            string emailp = "";
            string telefond = "";
            string mobild = "";
            string emaild = "";
            bool ok1marketing = false;
            bool ok1post = false;
            bool ok1telefonp = false;
            bool ok1mobilp = false;
            bool ok1emailp = false;
            bool ok1telefond = false;
            bool ok1mobild = false;
            bool ok1emaild = false;
            DateTime creationdate;
            string creationuser = "";
            DateTime modifieddate;
            string modifieduser = "";
            string gebDat = "";
            DateTime geburtsdatum;
            DateTime dtDefaultDB;
            dtDefaultDB = Convert.ToDateTime("01.01.1900");
            creationdate = dtDefaultDB;
            modifieddate = dtDefaultDB;
            bool privatPerson = false;
            string steuernummer = "";
            string ustidnr = "";
            string datWerkstatt = "";
            DateTime datumWerkstatt;
            string datTheke = "";
            DateTime datumTheke;
            string art = "";
            string gebiet = "";

            getCustomersResponse res = new getCustomersResponse();

            interfaceData iData = new interfaceData();
            customerType cust;
            customerTypeAddress custAdr;
            customerTypeName custName;
            customerTypePhoneMobil mobile;
            customerTypeEmail email;

            System.Collections.ArrayList aAdressen = new System.Collections.ArrayList();

            salesmanType sT = new salesmanType();
            sT.identifier = "fmad";
            sT.name = "Fmade";

            try
            {

                using (DBConnect myConnect = new DBConnect())
                {
                    String sqlCommand;
                    //Limitierung auf 100 Adressdatensätzen pro Abruf

                    sqlCommand = "SELECT TOP 100 START AT " + request.Body.arg0.ToString() + " a.kontonr, a.anrede, a.vorname, a.name1, a.name2, a.name3, a.suchname, a.strasse, a.plz, a.ort, a.land, ";
                    sqlCommand += " b.telefonp, b.mobilp, b.emailp, b.telefond, b.mobild, b.emaild,";
                    sqlCommand += " b.ok1marketing, b.ok1post, b.ok1telefonp, b.ok1mobilp, b.ok1emailp, b.ok1telefond, b.ok1mobild, b.ok1emaild,";
                    sqlCommand += " a.creationdate, a.creationuser, a.modifieddate, a.modifieduser, a.geburtsdatum, a.steuernummer, a.ustidnr, a.art, a.datumwerkstatt, a.datumtheke, a.gebiet";
                    sqlCommand += " FROM bungert.adresse a LEFT OUTER JOIN bungert.marketingkontakt b";
                    sqlCommand += " ON a.adressid = b.adressid WHERE aktiv = 1";
                    sqlCommand += " ORDER BY a.adressid";

                    OdbcCommand cmd = new OdbcCommand(sqlCommand, myConnect.conn);

                    myConnect.Connect();

                    OdbcDataReader reader;
                    //DataReader Objekt wird initialisiert

                    using (reader = cmd.ExecuteReader())
                    {

                        if (reader.HasRows)
                        {

                            while (reader.Read())
                            {
                                cust = new customerType();
                                custAdr = new customerTypeAddress();
                                privatPerson = false;

                                kontonr = 0;

                                kontonr = reader.GetInt32(0);
                                anrede = reader.GetValue(1).ToString();
                                vorname = reader.GetValue(2).ToString();
                                name1 = reader.GetValue(3).ToString();
                                name2 = reader.GetValue(4).ToString();
                                name3 = reader.GetValue(5).ToString();
                                suchname = reader.GetValue(6).ToString();
                                strasse = reader.GetValue(7).ToString();
                                plz = reader.GetValue(8).ToString();
                                ort = reader.GetValue(9).ToString();
                                land = reader.GetValue(10).ToString();

                                telefonp = reader.GetValue(11).ToString();
                                mobilp = reader.GetValue(12).ToString();
                                emailp = reader.GetValue(13).ToString();
                                telefond = reader.GetValue(14).ToString();
                                mobild = reader.GetValue(15).ToString();
                                emaild = reader.GetValue(16).ToString();

                                ok1marketing = (String.IsNullOrWhiteSpace(reader.GetValue(17).ToString()) ? false : reader.GetBoolean(17));
                                ok1post = (String.IsNullOrWhiteSpace(reader.GetValue(18).ToString()) ? false : reader.GetBoolean(18));
                                ok1telefonp = (String.IsNullOrWhiteSpace(reader.GetValue(19).ToString()) ? false : reader.GetBoolean(19));
                                ok1mobilp = (String.IsNullOrWhiteSpace(reader.GetValue(20).ToString()) ? false : reader.GetBoolean(20));
                                ok1emailp = (String.IsNullOrWhiteSpace(reader.GetValue(21).ToString()) ? false : reader.GetBoolean(21));
                                ok1telefond = (String.IsNullOrWhiteSpace(reader.GetValue(22).ToString()) ? false : reader.GetBoolean(22));
                                ok1mobild = (String.IsNullOrWhiteSpace(reader.GetValue(23).ToString()) ? false : reader.GetBoolean(23));
                                ok1emaild = (String.IsNullOrWhiteSpace(reader.GetValue(24).ToString()) ? false : reader.GetBoolean(24));

                                creationdate = reader.GetDateTime(25);
                                creationuser = reader.GetValue(26).ToString();
                                modifieddate = reader.GetDateTime(27);
                                modifieduser = reader.GetValue(28).ToString();
                                gebDat = reader.GetValue(29).ToString();
                                steuernummer = reader.GetValue(30).ToString();
                                ustidnr = reader.GetValue(31).ToString();
                                art = reader.GetValue(32).ToString();
                                datWerkstatt = reader.GetValue(33).ToString();
                                datTheke = reader.GetValue(34).ToString();
                                gebiet = reader.GetValue(35).ToString(); //Verkäufer

                                if (String.IsNullOrWhiteSpace(gebDat))
                                {
                                    geburtsdatum = dtDefaultDB;
                                }
                                else
                                {
                                    geburtsdatum = Convert.ToDateTime(gebDat);
                                }

                                if (String.IsNullOrWhiteSpace(steuernummer))
                                {
                                    steuernummer = "";
                                }

                                if (String.IsNullOrWhiteSpace(ustidnr))
                                {
                                    ustidnr = "";
                                }

                                if (String.IsNullOrWhiteSpace(datWerkstatt))
                                {
                                    datumWerkstatt = dtDefaultDB;
                                }
                                else
                                {
                                    datumWerkstatt = Convert.ToDateTime(datWerkstatt);
                                }

                                if (String.IsNullOrWhiteSpace(datTheke))
                                {
                                    datumTheke = dtDefaultDB;
                                }
                                else
                                {
                                    datumTheke = Convert.ToDateTime(datTheke);
                                }

                                if (!String.IsNullOrWhiteSpace(gebiet))
                                {
                                    salesmanType salesman = new salesmanType();
                                    salesman.name = gebiet;
                                    salesman.identifier = gebiet;
                                    cust.salesman = salesman;
                                }

                                custAdr.city = ort;
                                custAdr.country = land;
                                custAdr.street = strasse;
                                custAdr.zip = plz;

                                cust.address = custAdr;

                                salesmanType sMT = new salesmanType();

                                sMT.identifier = creationuser;
                                sMT.name = creationuser;

                                customerTypeCreation custCr = new customerTypeCreation();
                                custCr.date = creationdate;
                                custCr.dateSpecified = true;
                                custCr.location = 1;
                                custCr.locationSpecified = true;
                                custCr.salesman = sMT;

                                cust.creation = custCr;

                                sMT = new salesmanType();
                                sMT.identifier = modifieduser;
                                sMT.name = modifieduser;

                                customerTypeLastChange custLC = new customerTypeLastChange();
                                custLC.date = modifieddate;
                                custLC.dateSpecified = true;
                                custLC.location = 1;
                                custLC.locationSpecified = true;
                                custLC.salesman = sMT;

                                cust.lastChange = custLC;

                                customerIdentificationType custID = new customerIdentificationType();

                                //Testdaten "location" muss noch mit fmade geklärt werden
                                custID.location = 1;
                                custID.number = kontonr;

                                cust.customerNumber = custID;

                                cust.matchcode = String.IsNullOrWhiteSpace(suchname) ? "" : suchname;
                                cust.firstName = String.IsNullOrWhiteSpace(vorname) ? "" : vorname;

                                //cust.fsalesNumber = 2;

                                cust.salutationTypeSpecified = false;

                                // Salutatuon 1 = Herr / 2 = Frau
                                if (anrede.ToLower().Contains("herr"))
                                {
                                    cust.salutation = 1;
                                    cust.salutationSpecified = true;
                                    customerTypeSalutationLetter custSL = new customerTypeSalutationLetter();
                                    custSL.id = 1;
                                    custSL.description = String.IsNullOrWhiteSpace(name1) ? "" : name1;
                                    custSL.idSpecified = true;
                                    cust.salutationLetter = custSL;
                                    privatPerson = true;
                                }
                                else if (anrede.ToLower().Contains("frau"))
                                {
                                    cust.salutation = 2;
                                    cust.salutationSpecified = true;
                                    customerTypeSalutationLetter custSL = new customerTypeSalutationLetter();
                                    custSL.id = 2;
                                    custSL.description = String.IsNullOrWhiteSpace(name1) ? "" : name1;
                                    custSL.idSpecified = true;
                                    cust.salutationLetter = custSL;
                                    privatPerson = true;
                                }
                                else if (anrede.ToLower().Contains("firma"))
                                {
                                    cust.salutation = 9;
                                    cust.salutationSpecified = true;
                                    customerTypeSalutationLetter custSL = new customerTypeSalutationLetter();
                                    custSL.id = 9;
                                    custSL.idSpecified = true;
                                    cust.salutationLetter = custSL;
                                    privatPerson = false;
                                }
                                else //keine Anrede vorhanden
                                {
                                    cust.salutation = 0;
                                    cust.salutationSpecified = true;
                                    customerTypeSalutationLetter custSL = new customerTypeSalutationLetter();
                                    custSL.id = 0;
                                    custSL.idSpecified = true;
                                    cust.salutationLetter = custSL;
                                    privatPerson = true;
                                }

                                customerTypeName[] custNames = new customerTypeName[3];
                                //List<customerTypeName> custNames = new List<customerTypeName>();

                                custName = new customerTypeName();
                                custName.sequence = 1;

                                if (privatPerson)
                                {
                                    cust.lastName = name1;
                                    name1 = vorname + " " + name1;
                                }

                                custName.name = name1;
                                custNames[0] = custName;

                                custName = new customerTypeName();
                                custName.sequence = 2;
                                custName.name = name2;
                                custNames[1] = custName;

                                custName = new customerTypeName();
                                custName.sequence = 3;
                                custName.name = name3;
                                custNames[2] = custName;

                                cust.name = custNames;

                                cust.birthDateSpecified = false;

                                if (geburtsdatum.Date > dtDefaultDB.Date)
                                {
                                    cust.birthDate = geburtsdatum;
                                    cust.birthDateSpecified = true;
                                }

                                customerTypeInvoice inv = new customerTypeInvoice();

                                customerTypeInvoiceLastPart lastPart = new customerTypeInvoiceLastPart();
                                customerTypeInvoiceLastWokshop lastWorkShop = new customerTypeInvoiceLastWokshop();

                                lastPart.dateSpecified = false;
                                lastWorkShop.dateSpecified = false;

                                if (datumWerkstatt.Date > dtDefaultDB)
                                {
                                    lastWorkShop.date = datumWerkstatt;
                                    lastWorkShop.dateSpecified = true;
                                }

                                if (datumTheke.Date > dtDefaultDB)
                                {
                                    lastPart.date = datumTheke;
                                    lastPart.dateSpecified = true;
                                }

                                inv.lastPart = lastPart;
                                inv.lastWokshop = lastWorkShop;

                                cust.invoice = inv;

                                if (art.ToLower().Trim() == "k")
                                {
                                    cust.customerType1 = customerTypeCustomerType.customer; //Kunde
                                    cust.customerType1Specified = true;
                                }
                                else if (art.ToLower().Trim() == "i")
                                {
                                    cust.customerType1 = customerTypeCustomerType.prospect; //Interessent
                                    cust.customerType1Specified = true;
                                }

                                customerTypeMarketing custMarketing = new customerTypeMarketing();
                                custMarketing.postWanted = ok1post;
                                custMarketing.postWantedSpecified = true;
                                custMarketing.emailWanted = ok1emailp;
                                custMarketing.emailWantedSpecified = true;
                                custMarketing.phoneWanted = ok1telefonp;
                                custMarketing.phoneWantedSpecified = true;
                                custMarketing.useData = ok1marketing;
                                custMarketing.useDataSpecified = true;
                                custMarketing.smsWanted = ok1mobilp;
                                custMarketing.smsWantedSpecified = true;
                                custMarketing.useData = ok1marketing;
                                custMarketing.useDataSpecified = true;

                                customerTypePhone custPhone = new customerTypePhone();
                                custPhone.@private = telefonp;
                                custPhone.business = telefond;

                                customerTypePhoneMobil[] mobiles = new customerTypePhoneMobil[2];
                                //List<customerTypePhoneMobil> mobiles = new List<customerTypePhoneMobil>();

                                mobile = new customerTypePhoneMobil();
                                mobile.number = mobilp;
                                mobile.sequence = 1;

                                mobiles[0] = mobile;

                                mobile = new customerTypePhoneMobil();
                                mobile.sequence = 2;
                                mobile.number = mobild;

                                mobiles[1] = mobile;

                                custPhone.mobil = mobiles;
                                cust.phone = custPhone;

                                customerTypeEmail[] emails = new customerTypeEmail[2];
                                //List<customerTypeEmail> emails = new List<customerTypeEmail>();

                                email = new customerTypeEmail();
                                email.address = emailp;
                                email.sequence = 1;

                                emails[0] = email;

                                email = new customerTypeEmail();
                                email.address = emaild;
                                email.sequence = 2;

                                emails[1] = email;

                                cust.email = emails;

                                cust.marketing = custMarketing;

                                customerTypeNumbers cTN = new customerTypeNumbers();
                                cTN.vatNumber = ustidnr;
                                cTN.taxNumber = steuernummer;

                                cust.numbers = cTN;

                                aAdressen.Add(cust);

                            }

                        }
                        reader.Close();
                    }
                }

                #region testdaten
                //custAdr.city = "Linz";
                //custAdr.country = "AT";
                //custAdr.street = "Teststraße";
                //custAdr.zip = "4020";

                //cust.address = custAdr;

                //salesmanType sT = new salesmanType();
                //sT.identifier = "fmad";
                //sT.name = "Fmade";

                //customerTypeCreation custCr = new customerTypeCreation();
                //custCr.date = DateTime.Today;
                //custCr.dateSpecified = true;
                //custCr.location = 1;
                //custCr.locationSpecified = true;
                //custCr.salesman = sT;

                //cust.creation = custCr;

                //customerTypeLastChange custLC = new customerTypeLastChange();
                //custLC.date = DateTime.Today;
                //custLC.dateSpecified = true;
                //custLC.location = 1;
                //custLC.locationSpecified = true;

                //custLC.salesman = sT;

                //cust.lastChange = custLC;

                //customerIdentificationType custID = new customerIdentificationType();
                //custID.location = 1;
                //custID.number = 2;

                //cust.customerNumber = custID;

                //cust.firstName = "Uwe";
                //cust.fsalesNumber = 2;
                //cust.lastName = "Schwan";

                //customerTypeName[] custNames = new customerTypeName[1];
                //customerTypeName custName = new customerTypeName();

                //custName.sequence = 1;
                //custName.name = "Uwe Schwan";

                //custNames[0] = custName;

                //cust.name = custNames;

                //customerTypeMarketing custMarketing = new customerTypeMarketing();
                //custMarketing.emailWanted = true;
                //custMarketing.emailWantedSpecified = true;
                //custMarketing.phoneWanted = true;
                //custMarketing.phoneWantedSpecified = true;
                //custMarketing.useData = true;
                //custMarketing.useDataSpecified = true;

                //cust.marketing = custMarketing;

                //cust.salutation = 1;
                //cust.salutationSpecified = true;

                //customer[0] = cust;
                #endregion

                customerType[] aCustomers = new customerType[aAdressen.Count];
                //List<customerType> aCustomers = new List<customerType>();
                for (int i = 0; i < aAdressen.Count; i++)
                {
                    customerType customer = (customerType)aAdressen[i];
                    aCustomers[i] = customer;
                }

                iData.customer = aCustomers;
                iData.interfaceVersion = 1;
                iData.dataProvider = "STANDARD_INTERFACE";

                iData.callingUser = sT;
                iData.transmissionReason = "";

                System.IO.StringWriter stringWriter = new System.IO.StringWriter();

                var serializer = new XmlSerializer(typeof(interfaceData));
                using (var xw = XmlWriter.Create(stringWriter, new XmlWriterSettings { Encoding = new UTF8Encoding() }))
                {
                    serializer.Serialize(xw, iData);

                }

                #region xml encoding
                //string result;
                //using (MemoryStream memoryStream = new MemoryStream())
                //{
                //    XmlSerializer xs = new XmlSerializer(typeof(interfaceData));
                //    XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
                //    xs.Serialize(xmlTextWriter, iData);
                //    result = Encoding.UTF8.GetString(memoryStream.ToArray());
                //}
                //if (String.IsNullOrEmpty(result))
                //    result = "";
                #endregion

                getCustomersResponseBody resBody = new getCustomersResponseBody();

                resBody.@return = stringWriter.ToString();
                res.Body = resBody;

                SmitConfig sc = new SmitConfig();
                sc = ReadXML();
                sc.changedCustomerDate = DateTime.Now.ToString("yyyy-MM-dd");

                WriteXML(sc);
            }
            catch (System.Exception ex)
            {
                Trace.WriteLine(DateTime.Now.ToString() + " - " + ex.Message, "SmitService");
                res.Body.@return = "-1";
            }

            return res;
        }