Exemple #1
0
        static void Main(string[] args)
        {
            // xmlTest();

            // postTest();
            //  getTest();
            // putTest();

            X3WebAPI webAPI = new X3WebAPI();

            CAdxResultXml resultXML = webAPI.operation("read", "ECMSOH", "SOHNUM=SONZA0120015", null);

            Console.WriteLine(resultXML.resultXml);
            StreamWriter sw = new StreamWriter(@"c:\temp\xml.txt");

            sw.WriteLine(resultXML.resultXml);
            sw.Close();
            if (resultXML.status != 0)
            {
                XDocument xdoc  = XDocument.Parse(resultXML.resultXml);
                var       query = "RESULT/GRP[@ID=\"SOH0_1\"]/FLD[@NAME=\"SOHNUM\"]";

                var dbElement = xdoc.XPathSelectElement(query);
                if (dbElement != null)
                {
                    Console.WriteLine(dbElement.Value);
                }
            }

            Console.ReadLine();
        }
Exemple #2
0
        static void orderImport()
        {
            const string strConnection = "Data Source=192.168.0.21\\X3;Initial Catalog=B2B_Staging;Persist Security Info=False;User ID=hubsoft;Pwd=qiawfesacojdpvpd;MultipleActiveResultSets=True";

            string SQL = "";

            SqlConnection conn      = new SqlConnection(strConnection);
            SqlCommand    cmdOrdHdr = new SqlCommand();
            SqlCommand    cmdOrdDtl = new SqlCommand();
            SqlCommand    cmdUpdate = new SqlCommand();
            SqlDataReader rdrOrdHdr;
            SqlDataReader rdrOrdDtl;

            double discRate = 0;

            conn.Open();
            // run update to update all ProcessStatus to 1 when ProcessStatus = 0
            SQL       = "update StgSalesOrder SET ProcessStatus = 1 where ProcessStatus = 0";
            cmdUpdate = new SqlCommand(SQL, conn);
            cmdUpdate.ExecuteNonQuery();


            SQL = "select * from StgSalesOrder where ProcessStatus = 1";

            cmdOrdHdr = new SqlCommand(SQL, conn);


            rdrOrdHdr = cmdOrdHdr.ExecuteReader();
            while (rdrOrdHdr.Read())
            {
                X3WSFieldGroups f = new X3WSFieldGroups();
                f.AddData("SOH0_1", "SALFCY", rdrOrdHdr["SALFCY_0"].ToString());
                f.AddData("SOH0_1", "SOHTYP", rdrOrdHdr["SOHTYP_0"].ToString());
                f.AddData("SOH0_1", "CUSORDREF", rdrOrdHdr["CUSORDREF_0"].ToString());
                f.AddData("SOH0_1", "CUR", rdrOrdHdr["CUR_0"].ToString());
                f.AddData("SOH0_1", "BPCORD", rdrOrdHdr["BPCORD_0"].ToString());

                f.AddData("SOH1_1", "BPAADD", rdrOrdHdr["BPAADD_0"].ToString());


                f.AddData("SOH1_4", "CUR", rdrOrdHdr["CUR_0"].ToString());
                f.AddData("SOH1_4", "YHUBSFT", rdrOrdHdr["HUBSOFT_TRANID"].ToString());

                f.AddData("SOH2_1", "STOFCY", rdrOrdHdr["SALFCY_0"].ToString());
                f.AddData("SOH2_2", "DEMDLVDAT", Convert.ToDateTime(rdrOrdHdr["SHIDAT_0"]).ToString("yyyyMMdd"));
                //f.AddData("SOH2_2", "SHIDAT", Convert.ToDateTime(rdrOrdHdr["SHIDAT_0"]).ToString("yyyyMMdd"));
                f.AddData("SOH3_3", "PTE", rdrOrdHdr["PTE_0"].ToString());

                /*   if (Convert.ToDouble(rdrOrdHdr["DISCRGVAL1_0"]) > 0)
                 * {
                 *     discRate = Convert.ToDouble(rdrOrdHdr["DISCRGVAL1_0"]);
                 * }
                 * else if (Convert.ToDouble(rdrOrdHdr["totalMerchAmount"]) < Convert.ToDouble(rdrOrdHdr["totalOrderAmount"]))
                 * {
                 *     discRate = (1 - (Convert.ToDouble(rdrOrdHdr["totalMerchAmount"]) / Convert.ToDouble(rdrOrdHdr["totalOrderAmount"]))) * 100;
                 * }
                 */

                X3WSTables t  = new X3WSTables();
                int        ct = 0;


                SQL       = string.Format("select * from StgSOLine where HUBSOFT_TRANID = '{0}' and SessionKey = {1}", rdrOrdHdr["HUBSOFT_TRANID"], rdrOrdHdr["SessionKey"]);
                cmdOrdDtl = new SqlCommand(SQL, conn);
                rdrOrdDtl = cmdOrdDtl.ExecuteReader();

                while (rdrOrdDtl.Read())
                {
                    discRate = (1 - (Convert.ToDouble(rdrOrdDtl["NETPRI_0"]) / Convert.ToDouble(rdrOrdDtl["GROPRI_0"]))) * 100;
                    discRate = Math.Round(discRate, 0);
                    t.AddData("SOH4_1", ct.ToString(), "NUMLIG", ct.ToString());
                    t.AddData("SOH4_1", ct.ToString(), "ITMREF", rdrOrdDtl["ITMREF_0"].ToString());
                    t.AddData("SOH4_1", ct.ToString(), "ITMDES1", rdrOrdDtl["ITMDES1_0"].ToString());

                    t.AddData("SOH4_1", ct.ToString(), "DSTOFCY", rdrOrdDtl["STOFCY_0"].ToString());

                    t.AddData("SOH4_1", ct.ToString(), "QTY", rdrOrdDtl["QTY_0"].ToString());
                    t.AddData("SOH4_1", ct.ToString(), "GROPRI", rdrOrdDtl["GROPRI_0"].ToString());
                    t.AddData("SOH4_1", ct.ToString(), "DISCRGVAL1", discRate.ToString());
                    ct++;
                }
                rdrOrdDtl.Close();

                X3WSParameter para = new X3WSParameter();
                para.AddGroup(f);
                para.AddTable(t);

                string query = para.XML();
                Console.WriteLine(query);

                X3WebAPI webAPI = new X3WebAPI();

                CAdxResultXml resultXML = webAPI.operation("save", "YSOH", null, query);

                if (resultXML.resultXml == null)
                {
                    Console.WriteLine("Something went wrong........");
                }
                // set processstatus = 2
                SQL       = String.Format("update StgSalesOrder SET ProcessStatus = 2 where ProcessStatus = 1 and HUBSOFT_TRANID = '{0}'", rdrOrdHdr["HUBSOFT_TRANID"]);
                cmdUpdate = new SqlCommand(SQL, conn);
                cmdUpdate.ExecuteNonQuery();
            }
            rdrOrdHdr.Close();
            conn.Close();

            // Console.ReadLine();
        }