• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

vbshell函数在c#的转换

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
(转)C#:正则表达式30分钟入门教程发布时间:2022-07-14
下一篇:
C#创建和初始化集合对象发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap