我们有一个标签打印机A4 +,我们使用它们为我们的仓库打印大量标签,因为我们想要打印标签,每个标签都与另一个不同我们决定为每个打印作业制作一个DBF文件,因此,每当DBF文件包含多个不同记录时,我们的Web服务向A4 +打印机发出ftp请求并将DBF文件ftp到打印机,然后将打印命令发送到打印机并打印DBF文件。大部分时间所有步骤都成功完成但有时候打印机上的DBF文件与在web服务上创建的dbf文件差别不大,并且差异在文件头上,这种差异导致问题所以打印机打印标签但不打印到DBF文件的末尾,例如,如果DBF文件包含500条记录,打印机打印只有300条记录或不同的数字,然后它继续打印但标签不包含数据,这意味着300打印机后不要读取dbf文件,标签非常原始,但由于打印命令为500(DBF文件也包含500条记录),它继续将标签送到500.
我们比较托管Web服务的服务器上的DBF文件(这是我们创建dbf文件的地方)和打印机上的ftp文件,它们是相同的,只是文件头上的一点是diiffrent它就是这个问题。我包含了我们制作DBF文件的代码以及我们用来将此文件ftp到打印机的代码,还附加了两个DBF文件以供样本使用。
我们的团队致力于项目,我们在您的网站上研究帮助,但此时我们可以看到一切正常,我们无法调试此案例,也许您可以帮助我们解决这个问题。
------------------------创建DBF文件-------------------- ----------------------------------
private bool EportDBF(string filePath, List<BarcodeData> list)
{
string tableName = string.Empty;
string folderPath = string.Empty;
GetFileNameAndPath(filePath, ref tableName, ref folderPath);
string connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + folderPath + "; Extended Properties=DBASE IV;";
string createStatement = "Create Table " + tableName + " ( ";
string insertStatement = "Insert Into " + tableName + " Values ( ";
string insertTemp = string.Empty;
OleDbConnection conn = new OleDbConnection(connString);
try
{
createStatement += "[RW] varchar(4), ";
createStatement += "[CODE] varchar(16), ";
createStatement += "[DESC] varchar(16), ";
createStatement += "[WEIGHT] varchar(16), ";
createStatement += "[DATE] varchar(32), ";
createStatement += "[RCODE] varchar(16), ";
createStatement += "[BCODE] varchar(16) )";
conn.Open();
DataSet dsFill = new DataSet();
OleDbDataAdapter daInsertTable = new OleDbDataAdapter(createStatement, conn);
daInsertTable.Fill(dsFill);
int row = 1001;
foreach (var item in list)
{
insertTemp = insertStatement;
insertTemp += "'" + row++ + "' , ";
insertTemp += "'" + item.ItemCode + "' , ";
insertTemp += "'0' , ";
insertTemp += "'" + item.Weight + "' , ";
insertTemp += "'" + item.DateTime + "' , ";
insertTemp += "'" + item.ReferenceCode + "' , ";
insertTemp += "'" + item.Barcode.ToString() + "' ) ;";
daInsertTable = new OleDbDataAdapter(insertTemp, conn);
daInsertTable.Fill(dsFill);
}
conn.Close();
conn.Dispose();
}
catch (Exception ex)
{
conn.Close();
conn.Dispose();
return false;
}
return true;
}
------------------------ FTP DBF文件到打印机------------------ -------------------------
private bool UpLoadDBF(List<BarcodeData> barcodeDatas, string path)
{
try
{
EportDBF(path, barcodeDatas);
FtpWebRequest request;
FtpWebResponse response;
Stream sourceStream = new MemoryStream();
Stream requestStream = sourceStream;
StreamReader reader = new StreamReader(path);
try
{
request = (FtpWebRequest)WebRequest.Create("ftp://" + printerIP + "/card/barcodes.dbf");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.KeepAlive = false;
request.Credentials = new NetworkCredential(user, password);
byte[] byteArray = Encoding.Default.GetBytes(reader.ReadToEnd());
sourceStream = new MemoryStream(byteArray);
try
{
requestStream = request.GetRequestStream();
}
finally
{
request.ContentLength = sourceStream.Length;
byte[] buffer = new byte[sourceStream.Length];
int count = 2048;
if (sourceStream.Length < count)
count = (int) sourceStream.Length;
int bytesRead = sourceStream.Read(buffer, 0, count);
do
{
requestStream.Write(buffer, 0, bytesRead);
bytesRead = sourceStream.Read(buffer, 0, count);
} while (bytesRead > 0);
sourceStream.Close();
requestStream.Close();
}
}
catch (Exception ex)
{
}
finally
{
request = null;
sourceStream.Close();
sourceStream.Dispose();
reader.Close();
reader.Dispose();
requestStream.Close();
requestStream.Dispose();
}
}
catch (Exception ex)
{
return false;
}
return true;
}
非常感谢inadvance
答案 0 :(得分:0)
我不知道为什么你使用Encoding.Default.GetBytes来读取字节。而不是使用FileStream的Read方法来读取字节。希望这会有所帮助。