using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using System.Text; using System.IO; using System.Collections; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { //public Service () { // //如果使用设计的组件,请取消注释以下行 // //InitializeComponent(); //} [System.Web.Services.WebMethod(Description = "职工信息接口")] public String zget_staff_info(String reqInfo) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<zget_staff_info_response>" + "</zget_staff_info_response>"); XmlNode root = doc.DocumentElement; XmlElement elem0 = doc.CreateElement("Staff"); root.AppendChild(elem0); String ConnectionString = GetConnectString(); SqlConnection connection = new SqlConnection(ConnectionString); String QueryString = "select pk_hr_hi_person as unique_id,cPsn_Num as staff_no, cPsn_Name as staff_name,cDept_num as staff_department,00000000 as staff_company ,0 as block from hr_hi_person "; try { connection.Open(); SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = QueryString; SqlDataReader sr = command.ExecuteReader(); while (sr.Read()) { XmlElement elem2 = doc.CreateElement("item"); elem0.AppendChild(elem2); String id = sr.GetGuid(0).ToString(); XmlElement elem3 = doc.CreateElement("unique_id"); elem3.InnerText = id; elem2.AppendChild(elem3); String name = sr.GetSqlString(2).ToString(); XmlElement elem4 = doc.CreateElement("staff_name"); elem4.InnerText = name; elem2.AppendChild(elem4); String no = sr.GetSqlString(1).ToString(); XmlElement elem5 = doc.CreateElement("staff_no"); elem5.InnerText = no; elem2.AppendChild(elem5); String department = sr.GetSqlString(3).ToString(); XmlElement elem6 = doc.CreateElement("staff_department"); elem6.InnerText = department; elem2.AppendChild(elem6); String company = sr.GetInt32(4).ToString(); XmlElement elem7 = doc.CreateElement("staff_company"); elem7.InnerText = company; elem2.AppendChild(elem7); XmlElement elem8 = doc.CreateElement("staff_type"); elem2.AppendChild(elem8); XmlElement elem9 = doc.CreateElement("staff_loginer"); elem9.InnerText = ""; elem2.AppendChild(elem9); String block = sr.GetInt32(5).ToString(); XmlElement elem10 = doc.CreateElement("block"); elem10.InnerText = block; elem2.AppendChild(elem10); XmlElement elem11 = doc.CreateElement("sign"); elem11.InnerText = ""; elem2.AppendChild(elem11); } sr.Close(); XmlElement elem1 = doc.CreateElement("result"); elem1.InnerText = ""; root.AppendChild(elem1); } catch (Exception ex) { XmlElement elem1 = doc.CreateElement("result"); elem1.InnerText = ex.ToString(); root.AppendChild(elem1); } doc.Save(@"D:/Web Services/职工信息接口.xml"); return doc.OuterXml; } [System.Web.Services.WebMethod(Description = "往来单位信息接口")] public string zget_currentunit_info(String req_system, String req_date, String req_method) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<zget_currentunit_info_response>" + "</zget_currentunit_info_response>"); XmlNode root = doc.DocumentElement; XmlElement elem0 = doc.CreateElement("currentunit"); root.AppendChild(elem0); String connectionString = GetConnectString(); SqlConnection connect = new SqlConnection(connectionString); String QueryString = "Select cVenName as unit_name ,'0'+cVenCode as unit_code ,'0'+cVenCode as unique_id , '0'+cVenHeadCode as unit_company, 0 as block from Vendor Union All Select cCusName as unit_name,'1'+cCusCode as unit_code ,'1'+cCusCode as unique_id , '0'+cCusHeadCode as unit_company, 0 as block from Customer"; try { connect.Open(); SqlCommand command = new SqlCommand(); command.Connection = connect; command.CommandText = QueryString; SqlDataReader sr = command.ExecuteReader(); while (sr.Read()) { XmlElement elem2 = doc.CreateElement("Item"); elem0.AppendChild(elem2); String name = sr.GetSqlString(0).ToString(); XmlElement elem3 = doc.CreateElement("unit_name"); elem3.InnerText = name; elem2.AppendChild(elem3); String code = sr.GetSqlString(1).ToString(); XmlElement elem4 = doc.CreateElement("unit_code"); elem4.InnerText = code; elem2.AppendChild(elem4); String id = sr.GetSqlString(2).ToString(); XmlElement elem5 = doc.CreateElement("unique_id"); elem5.InnerText = id; elem2.AppendChild(elem5); String company = sr.GetSqlString(3).ToString(); XmlElement elem6 = doc.CreateElement("unit_company"); elem6.InnerText = company; elem2.AppendChild(elem6); XmlElement elem7 = doc.CreateElement("unit_countervail"); //elem7.InnerText = ""; elem2.AppendChild(elem7); XmlElement elem8 = doc.CreateElement("unit_type"); //elem8.InnerText = ""; elem2.AppendChild(elem8); XmlElement elem9 = doc.CreateElement("unit_nature"); //elem9.InnerText = ""; elem2.AppendChild(elem9); String block = sr.GetInt32(4).ToString(); XmlElement elem10 = doc.CreateElement("block"); elem10.InnerText = block; elem2.AppendChild(elem10); XmlElement elem11 = doc.CreateElement("sign"); //elem11.InnerText = ""; elem2.AppendChild(elem11); } sr.Close(); XmlElement elem1 = doc.CreateElement("result"); elem1.InnerText = ""; root.AppendChild(elem1); } catch (Exception e) { String errorinfomation = e.Message; XmlElement elem1 = doc.CreateElement("result"); elem1.InnerText = errorinfomation; root.AppendChild(elem1); } doc.Save(@"D:/Web Services/往来单位信息接口.xml"); return doc.DocumentElement.OuterXml; } [System.Web.Services.WebMethod(Description = "财务系统凭证核算信息接口")] public String zget_accountingvoucher_info(String req_system, String req_date, String req_method, String accounting_unit, String basic_unit, String year, String period, String documenttype, String doc_date_from, String doc_date_to, String post_date_from, String post_date_to, String doc_no_from, String doc_no_to) { string error = ""; if (doc_date_from == "") doc_date_from = DateTime.MinValue.ToString(); if (doc_date_to == "") doc_date_to = DateTime.MaxValue.ToString(); if (post_date_from == "") post_date_from = DateTime.MinValue.ToString(); if (post_date_to == "") post_date_to = DateTime.MaxValue.ToString(); if (doc_no_from == "") doc_no_from = int.MinValue.ToString(); if (doc_no_to == "") doc_no_to = int.MaxValue.ToString(); if (doc_date_from.CompareTo(doc_date_to) > 0) error = "输入日期从与输入日期至不正确!" + error; if(post_date_from.CompareTo(post_date_to) > 0) error = "过账日期从与过账日期至不正确!" + error; if (doc_no_from.CompareTo(doc_no_to) > 0) error = "凭证编号从与凭证编号至不正确!" + error; XmlDocument doc = new XmlDocument(); doc.LoadXml("<zget_accountingvoucher_info>" + "</zget_accountingvoucher_info>"); XmlNode root = doc.DocumentElement; XmlElement elem0 = doc.CreateElement("Voucher"); root.AppendChild(elem0); String errorinfo = ""; String connectString = GetConnectString(); SqlConnection connect = new SqlConnection(connectString); String QueryString0 = "SELECT max( i_id) as i_id ,(Csign+cast(ino_id as nvarchar(8)))as summary,cast(dbill_date as nvarchar(10))as year,cast( iperiod as nvarchar(32)) as period,cast(ino_id as nvarchar(8)) as docid,cbill as creator,ccheck as checker,cbook as book_keeper,CONVERT(nvarchar(8),dbill_date,112) as document_date,CONVERT(nvarchar(8),dbill_date,112) as posting_date ,daudit_date as period_date,csign as document_type,cast(idoc as nvarchar(8)) as reference ,cast(iperiod as nvarchar(16))as check1,cast(csign as nvarchar(16))as check2,cast(ino_ID as nvarchar(16)) check3,inid as Id ,cdigest as summary2,md,mc,ccode as account ,cexch_name as eate,cperson_id as employee,csup_id as vendor,ccus_id as customer FROM GL_accvouch where dbill_date > '" + doc_date_from + "'and dbill_date < '" + doc_date_to + "'and daudit_date>'" + post_date_from + "'and daudit_date <'" + post_date_to + "' and ino_id >'" + doc_no_from + "' and ino_id <'" + doc_no_to + "' GROUP BY dbill_date,iperiod , csign , ino_id,cbill,ccheck,cbook,daudit_date,idoc,inid,cdigest,md,mc,ccode,cexch_name,cperson_id,csup_id,ccus_id "; //String QueryString0 = "SELECT max( i_id) as i_id ,(Csign+cast(ino_id as nvarchar(8)))as summary,cast(dbill_date as nvarchar(10))as year,cast( iperiod as nvarchar(32)) as period,cast(ino_id as nvarchar(8)) as docid,cbill as creator,ccheck as checker,cbook as book_keeper,CONVERT(nvarchar(8),dbill_date,112) as document_date,CONVERT(nvarchar(8),dbill_date,112) as posting_date ,daudit_date as period_date,csign as document_type,cast(idoc as nvarchar(8)) as reference ,cast(iperiod as nvarchar(16))as check1,cast(csign as nvarchar(16))as check2,cast(ino_ID as nvarchar(16)) check3,inid as Id ,cdigest as summary2,md,mc,ccode as account ,cexch_name as eate,cperson_id as employee,csup_id as vendor,ccus_id as customer FROM GL_accvouch where iNo_id > '5' and iNo_id < '10' GROUP BY dbill_date,iperiod , csign , ino_id,cbill,ccheck,cbook,daudit_date,idoc,inid,cdigest,md,mc,ccode,cexch_name,cperson_id,csup_id,ccus_id"; try { connect.Open(); SqlCommand command0 = new SqlCommand(); command0.Connection = connect; command0.CommandText = QueryString0; SqlDataReader reader0 = command0.ExecuteReader(); while (reader0.Read()) { XmlElement elem2 = doc.CreateElement("item"); elem0.AppendChild(elem2); String dbdata3 = reader0.GetSqlString(1).ToString(); XmlElement elem3 = doc.CreateElement("summary"); elem3.InnerText = dbdata3; elem2.AppendChild(elem3); XmlElement elem4 = doc.CreateElement("accounting_unit"); elem4.InnerText = "00000000"; elem2.AppendChild(elem4); XmlElement elem5 = doc.CreateElement("basic_unit"); elem5.InnerText = "1001"; elem2.AppendChild(elem5); XmlElement elem6 = doc.CreateElement("year"); String dbdata6temp = reader0.GetSqlString(2).ToString(); String dbdata6 = dbdata6temp.Substring(5); elem6.InnerText = dbdata6; elem2.AppendChild(elem6); XmlElement elem7 = doc.CreateElement("period"); String dbdata7 = ""; if (!reader0.IsDBNull(3)) { dbdata7 = reader0.GetSqlString(3).ToString(); } elem5.InnerText = dbdata7; elem2.AppendChild(elem7); XmlElement elem8 = doc.CreateElement("docid"); String dbdata8 = reader0.GetSqlString(4).ToString(); elem8.InnerText = dbdata8; elem2.AppendChild(elem8); XmlElement elem9 = doc.CreateElement("creator"); String dbdata9 = reader0.GetSqlString(5).ToString(); elem9.InnerText = dbdata9; elem2.AppendChild(elem9); XmlElement elem10 = doc.CreateElement("checker"); String dbdata10 = reader0.GetSqlString(6).ToString(); elem10.InnerText = dbdata10; elem2.AppendChild(elem10); XmlElement elem11 = doc.CreateElement("book_keeper"); String dbdata11 = reader0.GetSqlString(7).ToString(); elem11.InnerText = dbdata11; elem2.AppendChild(elem11); XmlElement elem12 = doc.CreateElement("document_date"); String dbdata12 = reader0.GetSqlString(8).ToString(); elem12.InnerText = dbdata12; elem2.AppendChild(elem12); XmlElement elem13 = doc.CreateElement("posting_date"); String dbdata13 = ""; if (!reader0.IsDBNull(9)) { dbdata13 = reader0.GetSqlString(9).ToString(); } elem13.InnerText = dbdata13; elem2.AppendChild(elem13); XmlElement elem14 = doc.CreateElement("period_date"); DateTime dbdata14temp = DateTime.MinValue; if (!reader0.IsDBNull(10)) { dbdata14temp = reader0.GetDateTime(10); } String dbdata14 = dbdata14temp.Month.ToString(); elem14.InnerText = dbdata14; elem2.AppendChild(elem14); XmlElement elem15 = doc.CreateElement("document_type"); String dbdata15 = reader0.GetSqlString(11).ToString(); elem15.InnerText = dbdata15; elem2.AppendChild(elem15); XmlElement elem16 = doc.CreateElement("reference"); String dbdata16 = reader0.GetSqlString(12).ToString(); elem16.InnerText = dbdata16; elem2.AppendChild(elem16); String checkiperiod = reader0.GetSqlString(13).ToString(); String checkcsign = reader0.GetSqlString(14).ToString(); String checkino_ID = reader0.GetSqlString(15).ToString(); XmlElement elem17 = doc.CreateElement("item"); elem2.AppendChild(elem17); String connectString1 = GetConnectString(); SqlConnection connect1 = new SqlConnection(connectString1); //String QueryString1 = "select cast(inid as nvarchar(8)) as Id ,cdigest as summary2,md,mc,ccode as account ,cexch_name as currency,cast(nfrat as nvarchar(16))as eate,cperson_id as employee,csup_id as vendor,ccus_id as customer ,csign,cast(iperiod as nvarchar(8))as iperiod ,cast(ino_ID as nvarchar(8)) as ino_id ,cast(iSignSeq as varchar(8)) as iSignSeq ,cast(inid as nvarchar(8)) as inid from GL_accvouch where iperiod = '" + checkiperiod + "' and csign = '" + checkcsign + "' and ino_id = '" + checkino_ID + "'" ; String QueryString1 = "select cast(inid as nvarchar(8)) as Id ,cdigest as summary2,md,mc,ccode as account ,cexch_name as currency,cast(nfrat as nvarchar(16))as eate,cperson_id as employee,csup_id as vendor,ccus_id as customer ,csign,cast(iperiod as nvarchar(8))as iperiod ,cast(ino_ID as nvarchar(8)) as ino_id ,cast(iSignSeq as varchar(8)) as iSignSeq ,cast(inid as nvarchar(8)) as inid from GL_accvouch where iperiod = '8' and csign = '现' and ino_id = '5'"; connect1.Open(); SqlCommand command1 = new SqlCommand(); command1.Connection = connect1; command1.CommandText = QueryString1; SqlDataReader reader1 = command1.ExecuteReader(); while (reader1.Read()) { XmlElement substr0 = doc.CreateElement("item"); elem17.AppendChild(substr0); XmlElement substr1 = doc.CreateElement("Id"); String data1 = reader1.GetSqlString(0).ToString(); substr1.InnerText = data1; substr0.AppendChild(substr1); XmlElement substr2 = doc.CreateElement("summary"); String data2 = reader1.GetSqlString(1).ToString(); substr2.InnerText = data2; substr0.AppendChild(substr2); Decimal mc = Convert.ToDecimal(reader1[2]); Decimal md = Convert.ToDecimal(reader1[3]); String data3 = ""; if (mc > 0) { data3 = "cr"; } else if (md > 0) { data3 = "De"; } else { errorinfo = errorinfo + "+ crde输入时借贷金额错误+"; } XmlElement substr3 = doc.CreateElement("crde"); substr3.InnerText = data3; substr0.AppendChild(substr3); XmlElement substr4 = doc.CreateElement("account"); String data4 = reader1.GetSqlString(4).ToString(); substr4.InnerText = data4; substr0.AppendChild(substr4); String data105 = ""; if (mc > 0) { data105 = mc.ToString(); } else if (md > 0) { data105 = md.ToString(); } else { errorinfo = errorinfo + "+ amount输入时借贷金额错误+"; } XmlElement substr105 = doc.CreateElement("amount"); substr105.InnerText = data105; substr0.AppendChild(substr105); XmlElement substr5 = doc.CreateElement("currency"); String data5 = reader1.GetSqlString(5).ToString(); if (data5.ToLower() == "null") { substr5.InnerText = ""; } else { substr5.InnerText = data5; } substr0.AppendChild(substr5); XmlElement substr6 = doc.CreateElement("eate"); String data6 = reader1.GetSqlString(6).ToString(); substr6.InnerText = data6; substr0.AppendChild(substr6); XmlElement substr7 = doc.CreateElement("negposting"); substr0.AppendChild(substr7); String checkcashiperiod = reader1.GetString(11).ToString(); String checkcashIno_id = reader1.GetString(12).ToString(); String checkcashisignseq = reader1.GetString(13).ToString(); String checkcashinid = reader1.GetString(14).ToString(); String connectString2 = GetConnectString(); SqlConnection connect2 = new SqlConnection(connectString2); String QueryString2 = "select cCashItem as reason_code from GL_QcashSumTable where iNo_id ='" + checkcashIno_id + "' and iSignSeq ='" + checkcashisignseq + "' and inid ='" + checkcashinid + "' and iperiod ='" + checkcashiperiod + "'"; connect2.Open(); SqlCommand command2 = new SqlCommand(); command2.Connection = connect2; command2.CommandText = QueryString2; SqlDataReader reader2 = command2.ExecuteReader(); XmlElement substr8 = doc.CreateElement("reason_code"); String data8 = ""; try { String datatemp8 = reader2.GetSqlString(0).ToString(); data8 = datatemp8; } catch (Exception ereason_code) { data8 = ""; String error1 = ereason_code.Message; errorinfo = errorinfo + error1; } substr8.InnerText = data8; substr0.AppendChild(substr8); XmlElement substr9 = doc.CreateElement("bank_account"); substr0.AppendChild(substr9); XmlElement substr10 = doc.CreateElement("bank"); substr0.AppendChild(substr10); XmlElement substr11 = doc.CreateElement("employee"); String data11 = reader1.GetSqlString(7).ToString(); if (data11.ToLower() == "null") { substr11.InnerText = ""; } else { substr11.InnerText = data11; } substr0.AppendChild(substr11); XmlElement substr12 = doc.CreateElement("cost_center"); substr0.AppendChild(substr12); XmlElement substr14 = doc.CreateElement("vendor"); String data14 = reader1.GetSqlString(8).ToString(); if (data14.ToLower() == "null") {substr14.InnerText = "";} else { substr14.InnerText = data14; } substr0.AppendChild(substr14); XmlElement substr15 = doc.CreateElement("customer"); String data15 = reader1.GetSqlString(9).ToString(); if (data15.ToLower() == "null") {substr15.InnerText = "";} else { substr15.InnerText = data15; } substr0.AppendChild(substr15); XmlElement substr16 = doc.CreateElement("project_jj"); substr0.AppendChild(substr16); XmlElement substr17 = doc.CreateElement("project_jg"); substr0.AppendChild(substr17); XmlElement substr18 = doc.CreateElement("project_dx"); substr0.AppendChild(substr18); XmlElement substr19 = doc.CreateElement("project_contract"); substr0.AppendChild(substr19); XmlElement substr20 = doc.CreateElement("shortterm_contract"); substr0.AppendChild(substr20); XmlElement substr21 = doc.CreateElement("longterm_contract"); substr0.AppendChild(substr21); XmlElement substr22 = doc.CreateElement("financing_contract"); substr0.AppendChild(substr22); XmlElement substr23 = doc.CreateElement("currency_contract"); substr0.AppendChild(substr23); XmlElement substr24 = doc.CreateElement("entrust_contract"); substr0.AppendChild(substr24); XmlElement substr25 = doc.CreateElement("invisible_assets"); substr0.AppendChild(substr25); XmlElement substr26 = doc.CreateElement("real_estate"); substr0.AppendChild(substr26); XmlElement substr27 = doc.CreateElement("credit_source"); substr0.AppendChild(substr27); XmlElement substr28 = doc.CreateElement("credit_project"); substr0.AppendChild(substr28); XmlElement substr29 = doc.CreateElement("bond"); substr0.AppendChild(substr29); XmlElement substr30 = doc.CreateElement("stocks"); substr0.AppendChild(substr30); XmlElement substr31 = doc.CreateElement("fund"); substr0.AppendChild(substr31); XmlElement substr32 = doc.CreateElement("other_investment"); substr0.AppendChild(substr32); XmlElement substr33 = doc.CreateElement("bond_payable"); substr0.AppendChild(substr33); XmlElement substr34 = doc.CreateElement("number"); substr0.AppendChild(substr34); XmlElement substr35 = doc.CreateElement("price"); substr0.AppendChild(substr35); reader2.Close(); } reader1.Close(); } reader0.Close(); XmlElement elem1 = doc.CreateElement("result"); elem1.InnerText = ""; root.AppendChild(elem1); } catch (Exception ex) { String catcherror = ex.Message; errorinfo = errorinfo + catcherror; XmlElement elem1 = doc.CreateElement("result"); elem1.InnerText = error + errorinfo; root.AppendChild(elem1); } doc.Save(@"D:/Web Services/财务系统凭证核算信息接口.xml"); return doc.OuterXml; } public String GetConnectString() { return "Data Source = 127.0.0.1;Initial Catalog=UFDATA_001_2010;User ID=sa;Password=;" + "Integrated Security=true"; } }