如何使用C#在计数器中创建新的分类帐

时间:2014-12-08 12:09:05

标签: c# asp.net-mvc erp

我想编写C#代码以在Tally数据库中创建新的分类帐。我正在使用ASP.Net MVC开发ERP。我想将应用程序与Tally集成。这样Ledger数据将作为XML格式传输到Tally。这该怎么做?我需要你所有的宝贵贡献。我的代码是

string strGRNDate = "2/02/2014";
                string strVoucherNo = "3";
                string strGRNNo = "2";
                string strSupplierName = "Abhinav Sharma";
                string strPurchaseOrder = "2";
                string strGRN = "1";
                string strGRNValueNtv = "2";


                xmlstc = "<ENVELOPE>" + "\r\n";
                xmlstc = xmlstc + "<HEADER>" + "\r\n";
                xmlstc = xmlstc + "<TALLYREQUEST>Import Data</TALLYREQUEST>" + "\r\n";
                xmlstc = xmlstc + "</HEADER>" + "\r\n";
                xmlstc = xmlstc + "<BODY>" + "\r\n";
                xmlstc = xmlstc + "<IMPORTDATA>" + "\r\n";
                xmlstc = xmlstc + "<REQUESTDESC>" + "\r\n";
                xmlstc = xmlstc + "<REPORTNAME>Vouchers</REPORTNAME>" + "\r\n";
                xmlstc = xmlstc + "<STATICVARIABLES>" + "\r\n";
                xmlstc = xmlstc + "<SVCURRENTCOMPANY>##SVCURRENTCOMPANY</SVCURRENTCOMPANY>" + "\r\n";
                xmlstc = xmlstc + "</STATICVARIABLES>" + "\r\n";
                xmlstc = xmlstc + "</REQUESTDESC>" + "\r\n";
                xmlstc = xmlstc + "<REQUESTDATA>" + "\r\n";
                xmlstc = xmlstc + "<TALLYMESSAGE xmlns:UDF=" + "\"" + "TallyUDF" + "\" >" + "\r\n";
                xmlstc = xmlstc + "<VOUCHER VCHTYPE=" + "\"" + "Purchase" + "\" >" + "\r\n";
                xmlstc = xmlstc + "<DATE>" + strGRNDate + "</DATE>" + "\r\n";
                xmlstc = xmlstc + "<VOUCHERTYPENAME>Purchase</VOUCHERTYPENAME>" + "\r\n";
                xmlstc = xmlstc + "<VOUCHERNUMBER>" + strVoucherNo + "</VOUCHERNUMBER>" + "\r\n";
                xmlstc = xmlstc + "<REFERENCE>" + strGRNNo + "</REFERENCE>" + "\r\n";
                xmlstc = xmlstc + "<PARTYLEDGERNAME>" + strSupplierName + "</PARTYLEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<PARTYNAME>" + strSupplierName + "</PARTYNAME>" + "\r\n";
                xmlstc = xmlstc + "<EFFECTIVEDATE>" + strGRNDate + "</EFFECTIVEDATE>" + "\r\n";
                xmlstc = xmlstc + "<ISINVOICE>Yes</ISINVOICE>" + "\r\n";
                xmlstc = xmlstc + "<INVOICEORDERLIST.LIST>" + "\r\n";
                xmlstc = xmlstc + "<BASICORDERDATE>" + strGRNDate + "</BASICORDERDATE>" + "\r\n";
                xmlstc = xmlstc + "<BASICPURCHASEORDERNO>" + strPurchaseOrder + "</BASICPURCHASEORDERNO>" + "\r\n";
                xmlstc = xmlstc + "</INVOICEORDERLIST.LIST>" + "\r\n";
                xmlstc = xmlstc + "<ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERNAME>" + strSupplierName + "</LEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<GSTCLASS/>" + "\r\n";
                xmlstc = xmlstc + "<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERFROMITEM>No</LEDGERFROMITEM>" + "\r\n";
                xmlstc = xmlstc + "<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>" + "\r\n";
                xmlstc = xmlstc + "<ISPARTYLEDGER>Yes</ISPARTYLEDGER>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRN + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "<BILLALLOCATIONS.LIST>" + "\r\n";
                xmlstc = xmlstc + "<NAME>" + strGRNNo + "</NAME>" + "\r\n";
                xmlstc = xmlstc + "<BILLCREDITPERIOD>30 Days</BILLCREDITPERIOD>" + "\r\n";
                xmlstc = xmlstc + "<BILLTYPE>New Ref</BILLTYPE>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRN + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "</BILLALLOCATIONS.LIST>" + "\r\n";
                xmlstc = xmlstc + "</ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERNAME>Abhinav Sharma</LEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<GSTCLASS/>" + "\r\n";
                xmlstc = xmlstc + "<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERFROMITEM>No</LEDGERFROMITEM>" + "\r\n";
                xmlstc = xmlstc + "<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>" + "\r\n";
                xmlstc = xmlstc + "<ISPARTYLEDGER>No</ISPARTYLEDGER>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRNValueNtv + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "</ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "</VOUCHER>" + "\r\n";
                xmlstc = xmlstc + "</TALLYMESSAGE>" + "\r\n";
                xmlstc = xmlstc + "</REQUESTDATA>" + "\r\n";
                xmlstc = xmlstc + "</IMPORTDATA>" + "\r\n";
                xmlstc = xmlstc + "</BODY>" + "\r\n";
                xmlstc = xmlstc + "</ENVELOPE>" + "\r\n";

                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:" + Connection.TallyPort);
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentLength = xmlstc.Length;
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
                streamWriter.Write(xmlstc);
                streamWriter.Close();
                string result;
                HttpWebResponse objResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    sr.Close();
                }

我在每个地方都遇到错误

1 个答案:

答案 0 :(得分:2)

亲爱的,你没有初始化字符串.declare xml string as string。而且你可以将connection.tally端口改为9000。这是最终的代码。

 string strGRNDate = "2/02/2014";
                string strVoucherNo = "3";
                string strGRNNo = "2";
                string strSupplierName = "Abhinav Sharma";
                string strPurchaseOrder = "2";
                string strGRN = "1";
                string strGRNValueNtv = "2";


                string xmlstc = "<ENVELOPE>" + "\r\n";
                xmlstc = xmlstc + "<HEADER>" + "\r\n";
                xmlstc = xmlstc + "<TALLYREQUEST>Import Data</TALLYREQUEST>" + "\r\n";
                xmlstc = xmlstc + "</HEADER>" + "\r\n";
                xmlstc = xmlstc + "<BODY>" + "\r\n";
                xmlstc = xmlstc + "<IMPORTDATA>" + "\r\n";
                xmlstc = xmlstc + "<REQUESTDESC>" + "\r\n";
                xmlstc = xmlstc + "<REPORTNAME>Vouchers</REPORTNAME>" + "\r\n";
                xmlstc = xmlstc + "<STATICVARIABLES>" + "\r\n";
                xmlstc = xmlstc + "<SVCURRENTCOMPANY>##SVCURRENTCOMPANY</SVCURRENTCOMPANY>" + "\r\n";
                xmlstc = xmlstc + "</STATICVARIABLES>" + "\r\n";
                xmlstc = xmlstc + "</REQUESTDESC>" + "\r\n";
                xmlstc = xmlstc + "<REQUESTDATA>" + "\r\n";
                xmlstc = xmlstc + "<TALLYMESSAGE xmlns:UDF=" + "\"" + "TallyUDF" + "\" >" + "\r\n";
                xmlstc = xmlstc + "<VOUCHER VCHTYPE=" + "\"" + "Purchase" + "\" >" + "\r\n";
                xmlstc = xmlstc + "<DATE>" + strGRNDate + "</DATE>" + "\r\n";
                xmlstc = xmlstc + "<VOUCHERTYPENAME>Purchase</VOUCHERTYPENAME>" + "\r\n";
                xmlstc = xmlstc + "<VOUCHERNUMBER>" + strVoucherNo + "</VOUCHERNUMBER>" + "\r\n";
                xmlstc = xmlstc + "<REFERENCE>" + strGRNNo + "</REFERENCE>" + "\r\n";
                xmlstc = xmlstc + "<PARTYLEDGERNAME>" + strSupplierName + "</PARTYLEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<PARTYNAME>" + strSupplierName + "</PARTYNAME>" + "\r\n";
                xmlstc = xmlstc + "<EFFECTIVEDATE>" + strGRNDate + "</EFFECTIVEDATE>" + "\r\n";
                xmlstc = xmlstc + "<ISINVOICE>Yes</ISINVOICE>" + "\r\n";
                xmlstc = xmlstc + "<INVOICEORDERLIST.LIST>" + "\r\n";
                xmlstc = xmlstc + "<BASICORDERDATE>" + strGRNDate + "</BASICORDERDATE>" + "\r\n";
                xmlstc = xmlstc + "<BASICPURCHASEORDERNO>" + strPurchaseOrder + "</BASICPURCHASEORDERNO>" + "\r\n";
                xmlstc = xmlstc + "</INVOICEORDERLIST.LIST>" + "\r\n";
                xmlstc = xmlstc + "<ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERNAME>" + strSupplierName + "</LEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<GSTCLASS/>" + "\r\n";
                xmlstc = xmlstc + "<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERFROMITEM>No</LEDGERFROMITEM>" + "\r\n";
                xmlstc = xmlstc + "<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>" + "\r\n";
                xmlstc = xmlstc + "<ISPARTYLEDGER>Yes</ISPARTYLEDGER>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRN + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "<BILLALLOCATIONS.LIST>" + "\r\n";
                xmlstc = xmlstc + "<NAME>" + strGRNNo + "</NAME>" + "\r\n";
                xmlstc = xmlstc + "<BILLCREDITPERIOD>30 Days</BILLCREDITPERIOD>" + "\r\n";
                xmlstc = xmlstc + "<BILLTYPE>New Ref</BILLTYPE>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRN + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "</BILLALLOCATIONS.LIST>" + "\r\n";
                xmlstc = xmlstc + "</ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERNAME>Abhinav Sharma</LEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<GSTCLASS/>" + "\r\n";
                xmlstc = xmlstc + "<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERFROMITEM>No</LEDGERFROMITEM>" + "\r\n";
                xmlstc = xmlstc + "<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>" + "\r\n";
                xmlstc = xmlstc + "<ISPARTYLEDGER>No</ISPARTYLEDGER>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRNValueNtv + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "</ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "</VOUCHER>" + "\r\n";
                xmlstc = xmlstc + "</TALLYMESSAGE>" + "\r\n";
                xmlstc = xmlstc + "</REQUESTDATA>" + "\r\n";
                xmlstc = xmlstc + "</IMPORTDATA>" + "\r\n";
                xmlstc = xmlstc + "</BODY>" + "\r\n";
                xmlstc = xmlstc + "</ENVELOPE>" + "\r\n";

                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:" + 9000);
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentLength = xmlstc.Length;
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
                streamWriter.Write(xmlstc);
                streamWriter.Close();
                string result;
                HttpWebResponse objResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    sr.Close();
                }