我们有一些标签打印机 A4+,我们用它们为我们的仓库打印大量标签,因为我们想打印每个标签都不同的标签,我们决定为每个打印作业制作一个 DBF 文件,所以每次DBF 文件包含不同记录的数量,然后我们的 Web 服务向 A4+ 打印机发出 ftp 请求并将 DBF 文件 ftp 到打印机,然后将打印命令发送到打印机并打印 DBF 文件。大多数情况下,所有步骤都成功发生,但有时打印机上的 DBF 文件与 Web 服务上生成的 dbf 文件几乎没有区别,并且差异在文件的标题上,这种差异导致了问题,所以打印机打印标签但不打印到 DBF 文件的末尾,例如,如果 DBF 文件包含 500 条记录,
我们比较了托管 Web 服务的服务器上的 DBF 文件(这是我们创建 dbf 文件的地方)和打印机上 ftp 的文件,它们是相同的,只是文件头有点不同,它使这个问题。
我包括我们制作 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;
}
所以提前谢谢