static Utils() { dbhandler = new DatabaseHandler(ConfigurationManager.AppSettings["db"]); metadata = new EYouBaoMetadata(); metadata.Server = ConfigurationManager.AppSettings["ems_server"]; metadata.Port = ConfigurationManager.AppSettings["ems_port"]; metadata.Version = ConfigurationManager.AppSettings["ems_version"]; metadata.Authenticate = ConfigurationManager.AppSettings["ems_authenticate"]; metadata.ShipURI = ConfigurationManager.AppSettings["ems_ship_uri"]; }
private void ShipPlatformOrder(PlatformOrder order, SystemOrder systemOrder) { EYouBaoMetadata metadata = Utils.EYouBaoMetadata(); string requestURL = String.Format("http://{0}:{1}{2}", metadata.Server, metadata.Port, metadata.ShipURI); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestURL); request.Headers.Set("version", metadata.Version); request.Headers.Set("authenticate", metadata.Authenticate); request.Method = "POST"; request.ContentType = "application/xml;charset=UTF-8"; Encoding encoding = Encoding.GetEncoding("utf-8"); byte[] postdata = encoding.GetBytes(Utils.GetXmlString(order)); request.ContentLength = postdata.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(postdata, 0, postdata.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); XPathDocument doc = new XPathDocument(reader); XPathNavigator nav = doc.CreateNavigator(); XPathNavigator node = nav.SelectSingleNode("/order/mailnum"); if (null != node) { string mailnum = node.InnerXml; try { DatabaseHandler handler = Utils.DatabaseHandler(); string sql = String.Format("UPDATE COPTD SET {0} = '{1}' WHERE {2} = '{3}' AND {4} = '{5}' AND {6} = '{7}' AND TD016='N' AND TD008<>0 AND (UDF04 IS NULL OR UDF04 = '') ", COL_MAIL_NUM, mailnum, COL_SORDER_TYPE, systemOrder.OrderType, COL_SORDER_NO, systemOrder.OrderNo, COL_PORDER_NO, order.OrderCode); int count = handler.Execute(sql); } catch (SqlException e) { MessageBox.Show(String.Format("运单号入库失败,单别:{0},单号:{1},平台单号:{2},生成的运单号:{3},具体错误信息:\r\n{4}", systemOrder.OrderType, systemOrder.OrderNo, order.OrderCode, mailnum, e.Message), "错误"); } } else { // 生成订单失败,数据错误 node = nav.SelectSingleNode("/response/description"); string error = node == null ? "生成运单失败。" : node.InnerXml; throw new EYouBaoAccessException(error); } }