vb shell:

Private Sub AddBarcodeImages(ByVal DTab As DataTable)
        If Not DTab Is Nothing Then

            DTab.Columns.Add("BCIMAGE", Type.GetType("System.Byte[]"))

            Dim r As DataRow
            For Each r In DTab.Rows

                Try
                    Dim BatchNo As String = CStr(r.Item("Operator2")).Trim
                    Dim sFileName As String = "C:\TEMP\" & BatchNo & ".jpg"

                    Shell("Barcode.exe " & BatchNo & " 36", AppWinStyle.NormalFocus, True)

                    Dim fs As IO.FileStream = New IO.FileStream(sFileName, IO.FileMode.Open)
                    Dim fi As IO.FileInfo = New IO.FileInfo(sFileName)
                    Dim fl As Long = fi.Length
                    Dim lung As Integer = Convert.ToInt32(fl)
                    Dim imgBytes As Byte() = New Byte(lung - 1) {}
                    fs.Read(imgBytes, 0, lung)
                    fs.Close()
                    r.Item("BCIMAGE") = imgBytes

                    Dim f As IO.File
                    Try
                        f.Delete(sFileName)
                    Catch ex As Exception
                        Console.WriteLine(ex.ToString)
                    End Try

                Catch ex As Exception
                    'MessageBox.Show(ex.ToString)
                End Try
            Next
        End If
    End Sub

c# Process线程:

private DataTable getReportData()
        {
            DataTable tb = new DataTable();
            tb.Columns.Add("Operator", Type.GetType("System.String"));
            tb.Columns.Add("OperName", Type.GetType("System.String"));
            tb.Columns.Add("Line_No", Type.GetType("System.String"));
            tb.Columns.Add("SessionID", Type.GetType("System.String"));
            tb.Columns.Add("IsActive", Type.GetType("System.String"));
            tb.Columns.Add("IsLine", Type.GetType("System.String"));
            tb.Columns.Add("logo", Type.GetType("System.Byte[]"));

            DataRow row;
            foreach (DataRow r in ds.Tables["empd10"].Rows)
            {
                if (r["s_select"].ToString() == "F") continue;
                if (r["ticketstatus"].ToString() != "Y") continue;
                try
                {
                    row = tb.NewRow();
                    row.BeginEdit();
                    row["Operator"] = r["empno"];
                    row["OperName"] = r["empname"].ToString() + r["eng_name"].ToString();
                    row["Line_No"] = r["teamno"];
                    row["SessionID"] = "";
                    row["IsActive"] = "";
                    row["IsLine"] = "";
                    //--------------------------------------------------条码-------------------------------------------
                    string BatchNo = row["Operator"].ToString().Trim();
                    string sFileName = @"C:\TEMP\" + BatchNo + ".jpg";

                    //------------------shell函数在c#的转换--------------------
                    Process process = new Process();
                    ProcessStartInfo startInfo = new ProcessStartInfo("Barcode.exe", BatchNo + " 36");
                    startInfo.WorkingDirectory = Application.StartupPath;
                    process.StartInfo = startInfo;
                    process.Start();
                    process.WaitForExit();//必不可少否则出现条码生成不成功的情况
                    //------------------shell函数在c#的转换--------------------
                    

                    System.IO.FileStream fs = new System.IO.FileStream(sFileName, System.IO.FileMode.Open);
                    System.IO.FileInfo fi = new System.IO.FileInfo(sFileName);
                    long f1 = fi.Length;
                    int lung = Convert.ToInt32(f1);
                    Byte[] imgBytes = new Byte[lung];
                    fs.Read(imgBytes, 0, lung);
                    fs.Close();
                    row["logo"] = imgBytes;

                    try
                    {
                        System.IO.File.Delete(sFileName);
                    }
                    catch (Exception ex) 
                    {
                        Console.WriteLine(ex.ToString());
                    }
                    //--------------------------------------------------条码-------------------------------------------
                    row.EndEdit();
                    tb.Rows.Add(row);
                }
                catch (Exception ex) 
                {
                    //return null;
                }
            }
            tb.TableName = "OM";
            tb.AcceptChanges();
            return tb;
        }

 

posted on 2013-11-06 17:16  vinsonLu  阅读(699)  评论(0编辑  收藏  举报