如何使用 C# 在计数中创建新账本

本文关键字:创建 新账本 何使用 | 更新日期: 2023-09-27 18:33:27

我想编写 C# 代码以在 Tally 数据库中创建新的账本。我正在使用 ASP.Net MVC开发ERP。我想将应用程序与 Tally 集成。以便账本数据以 XML 格式传输到计数。怎么做?我需要你所有有价值的贡献。这是我的代码

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();
                }

我在每个地方都遇到错误

如何使用 C# 在计数中创建新账本

亲爱的你还没有初始化字符串.将XML字符串声明为字符串.此外,您可以将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();
                }