微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试使用C#在Tally中插入xml数据度量单位

如何解决尝试使用C#在Tally中插入xml数据度量单位

尝试使用C#在Tally中插入xml数据(度量单位) 我有一个转换后的值,将其转换为xml格式,并尝试将xml数据插入到具有http:// localhost:9000的Tally中。我将数据插入Tally进行分类账创建,但因库存信息中的计量单位而失败

Xml数据:

String xmlstc = "";
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>All Masters</REPORTNAME>\r\n";
xmlstc = xmlstc + "<STATICVARIABLES><SVCURRENTCOMPANY>Siddharth</SVCURRENTCOMPANY></STATICVARIABLES>\r\n";
xmlstc = xmlstc + "</REQUESTDESC>\r\n";
xmlstc = xmlstc + "<REQUESTDATA>\r\n";
xmlstc = xmlstc + "<TALLYMESSAGE xmlns:UDF=" + "\"" + "TallyUDF" + "\">\r\n";
xmlstc = xmlstc + "<UNIT NAME=" + "\"" + "Kg" + "\" Action =" + "\"" + "Create" + "\">\r\n";
xmlstc = xmlstc + "<NAME>" + "Kg" + "</NAME>\r\n";               
xmlstc = xmlstc + "<ORIGINALNAME>" + "Kilogram" + "</ORIGINALNAME>\r\n";           
xmlstc = xmlstc + "<ISUPDATINGTARGETID>" + "No" + "</ISUPDATINGTARGETID>\r\n";
xmlstc = xmlstc + "<ASORIGINAL>" + "Yes" + "</ASORIGINAL>\r\n";
xmlstc = xmlstc + "<ISGSTEXCLUDED>" + "No" + "</ISGSTEXCLUDED>\r\n";
xmlstc = xmlstc + "<ISSIMPLEUNIT>" + "Yes" + "</ISSIMPLEUNIT>\r\n";
xmlstc = xmlstc + "<ALTERID>" + "1326" + "</ALTERID>\r\n";
xmlstc = xmlstc + "<DECIMALPLACES>" + "1" + "</DECIMALPLACES>\r\n";
xmlstc = xmlstc + "</UNIT>\r\n";
xmlstc = xmlstc + "</TALLYMESSAGE>\r\n";
xmlstc = xmlstc + "</REQUESTDATA>\r\n";
xmlstc = xmlstc + "</IMPORTDATA>\r\n";
xmlstc = xmlstc + "</BODY>";
xmlstc = xmlstc + "</ENVELOPE>";

以Tally格式发送数据的代码(库存信息=>计量单位)

String lTallyLocalHost = "http://localhost:9000";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(lTallyLocalHost);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = (long)xmlstc.Length;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
StreamWriter lStrmWritr = new StreamWriter(httpWebRequest.GetRequestStream());
lStrmWritr.Write(xmlstc);
lStrmWritr.Close();
HttpWebResponse lhttpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream lreceiveStream = lhttpResponse.GetResponseStream();
StreamReader lStreamReader = new StreamReader(lreceiveStream,Encoding.UTF8);
lResponseStr = lStreamReader.ReadToEnd();
lhttpResponse.Close();
lStreamReader.Close();

解决方法

下载 Tally connector Library 并添加对您项目的引用 现在您无需在代码中使用 XML 即可与 Tally 交互

要在 Tally 中创建单位,请使用以下代码

Using TallyConnector //Importing TallyConnector Library
using TallyConnector.Models;

Ctally = new Tally();

Unit NewUnit = new Unit();
NewUnit.Name = "Kg";
NewUnit.OriginalName = "Kg";
NewUnit.DecimalPlaces= 1;

await Ctally.PostUnit(NewUnit);// Creates Unit in Tally

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。