public virtual string Data2DB(IDictionary <string, string> ps, IList <string> paramNeeded, DbConnection connection, string pch) { string webServiceData = GetWebServiceData(ps, paramNeeded);//获取webservice数据 BDC bdc = XMLParsing(webServiceData); return(PushData2DB(bdc, connection, pch)); }
protected override string PushData2DB(BDC bdc, DbConnection conn, string pch) { //return base.PushData2DB(bdc, conn, pch); if (bdc == null || bdc.data == null) { return(pch); } DataTable dt = bdc.data.dt; if (dt != null && dt.Rows.Count > 0) { if (this._excuteCode == "0000")//如果是测管系统取数据,且有数据返回.用LPBH和XMMC去匹配,尽量用数据库中原有的ID。 { for (int i = 0; i < dt.Rows.Count; i++) { //dt.Rows[i]["ZID"] = GuidChange.Change2With_(dt.Rows[i]["ZID"].ToString());//GZid.ToString("D"); if (dt.Columns.Contains("LPBH")) { string tm = LPBHFindExist(dt.Rows[i]["LPBH"].ToString(), dt.Rows[i]["XMMC"].ToString());//尽可能返回不动产的id if (!string.IsNullOrEmpty(tm)) { insertFC_ZIDGL(tm, dt.Rows[i]["ZID"].ToString()); dt.Rows[i]["ZID"] = tm; } else { dt.Rows[i]["ZID"] = GuidChange.Change2With_(dt.Rows[i]["ZID"].ToString());//GZid.ToString("D"); } } } } } return(base.PushData2DB(bdc, conn, pch)); }
protected virtual string PushData2DB(BDC bdc, DbConnection conn, string pch) { if (bdc.head.flag == 0) { //取数据失败 //if (conn.State == ConnectionState.Open) conn.Close(); return(string.Empty); } else { if (bdc.data != null && bdc.data.dt != null && bdc.data.dt.Rows.Count > 0) { //string insertSql = InsertSql(pch, bdc.data.dt, _TabelName); //IList<DbCommand> commands = new List<DbCommand>(); //if (conn == null || conn.State == ConnectionState.Closed) //{ // conn = DBHelper.Connection; //} DbTransaction Tran = conn.BeginTransaction(); DbCommand command = conn.CreateCommand(); command.Transaction = Tran; try { for (int i = 0; i < bdc.data.dt.Rows.Count; i++) { command.CommandType = CommandType.Text; command.Parameters.Clear(); CreateParameters(command, bdc.data.dt, i); if (string.IsNullOrEmpty(command.CommandText)) { command.CommandText = InsertSql(pch, command.Parameters, _TabelName); } command.ExecuteNonQuery(); } Tran.Commit(); } catch (Exception ex) { Tran.Rollback(); throw new Exception(ex.Message + "在从webservice中取出数据再插入临时表时出错。pch:" + pch); #if DEBUG #else ILog log = new ErrorLog(typeof(WebServiceDataBase)); log.WriteLog(ex); throw new Exception(ex.Message + "在从webservice中取出数据再插入临时表时出错。pch:" + pch); #endif } finally { //conn.Close(); } return(pch); } else { //if (conn.State == ConnectionState.Open) conn.Close(); return(string.Empty); } } }
protected override IDictionary <string, string> GetReturnId(BDC bdc) { //return base.GetReturnId(bdc); IDictionary <string, string> ret = new Dictionary <string, string>(); if (bdc.head.flag != 1) { return(ret); } if (bdc.data != null && bdc.data.dt != null && bdc.data.dt.Rows.Count > 0) { DataTable dt = bdc.data.dt; string zid = dt.Rows[0]["ZID"].ToString(); ret.Add("ZID", zid); } return(ret); }
/// <summary> /// 解析返回来的XML /// </summary> /// <param name="xml"></param> /// <returns></returns> public virtual BDC XMLParsing(string xml) { //xml = File.ReadAllText(@"C:\Users\Administrator\Desktop\1.xml"); xml = xml.Replace("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body>", ""); xml = xml.Replace("</soap:Body></soap:Envelope>", ""); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); XmlElement root = xmlDoc.DocumentElement; root.Attributes.RemoveAll(); XmlNode bodyNode = xmlDoc.ChildNodes[1].FirstChild; xml = string.Format("<BDC>{0}</BDC>", bodyNode.InnerXml); using (StringReader sr = new StringReader(xml)) { XmlSerializer serializer = new XmlSerializer(typeof(BDC)); BDC bdc = (BDC)serializer.Deserialize(sr); return(bdc); } }
protected override IDictionary <string, string> GetReturnId(BDC bdc) { //return base.GetReturnId(bdc); IDictionary <string, string> ret = new Dictionary <string, string>(); if (bdc.head.flag != 1) { return(ret); } if (bdc.data != null && bdc.data.dt != null && bdc.data.dt.Rows.Count > 0) { DataTable dt = bdc.data.dt; //Guid GZid = Guid.Parse(dt.Rows[0]["ZID"].ToString()); //string zid = GZid.ToString("N");//GetZidTemp(dt, 0); string zid = dt.Rows[0]["ZID"].ToString(); ret.Add("ZID", zid); //Guid GHid = Guid.Parse(dt.Rows[0]["HID"].ToString()); //string hid = GHid.ToString("N");//GetZidTemp(dt, 0); string hid = dt.Rows[0]["HID"].ToString(); ret.Add("HID", hid); string htid = dt.Rows[0]["HTID"].ToString().Trim(); ret.Add("HTID", htid); string htbahid = dt.Rows[0]["SPFHTBAH"].ToString(); ret.Add("HTBAH", htbahid); if (dt.Columns.Contains("LPBH")) { string lpbh = dt.Rows[0]["LPBH"].ToString(); ret.Add("LPBH", lpbh); } if (dt.Columns.Contains("FJBM")) { string fjbm = dt.Rows[0]["FJBM"].ToString(); ret.Add("FJBM", fjbm); } } return(ret); }
public override string Data2DB(IDictionary <string, string> ps, IList <string> paramNeeded, DbConnection connection, string pch) { //return base.Data2DB(ps, paramNeeded, connection, pch); //先看看zid在数据库中有无对应关系 if (ps.ContainsKey("ZID")) { string idInCG = GetCGZID(ps["ZID"]); if (!string.IsNullOrEmpty(idInCG)) { ps["ZID"] = GuidChange.Change2Without_(idInCG);// } } BDC bdc = null; try { string webServiceData = GetWebServiceData(ps, paramNeeded);//获取webservice数据 bdc = XMLParsing(webServiceData); } catch (Exception ex) { bdc = new BDC(); bdc.head = new Head { flag = 0, msg = ex.Message }; } if (_excuteCode != "0000" && ps.ContainsKey("ZID") && bdc.data != null && bdc.data.dt != null && bdc.data.dt.Rows.Count > 0) { //存量房和网备可能使用LPBH去获取,导致ZID不一致 string CGZID = bdc.data.dt.Rows[0]["ZID"].ToString(); if (!CGZID.Equals(ps["ZID"])) //如果返回的zid和参数里面的zid不一致。将zid对应关系保存,并修改返回的数据 { insertFC_ZIDGL(ps["ZID"], GuidChange.Change2With_(CGZID)); bdc.data.dt.Rows[0]["ZID"] = GuidChange.Change2With_(ps["ZID"]); } } return(PushData2DB(bdc, connection, pch)); }
/// <summary> /// 返回需要继续查询的ID,变态 /// </summary> /// <param name="bdc"></param> /// <returns></returns> protected virtual IDictionary <string, string> GetReturnId(BDC bdc) { return(null); }