新框架PC前端标准版(祈禧6月初版本)
lg
2025-11-20 fbe33a615f1c4e798a0f8e58163e68c3ce789614
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using CefSharp.WinForms;
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Windows.Forms;
 
namespace Gs.DevApp.UserControl
{
    public partial class ShowFile : DevExpress.XtraEditors.XtraForm
    {
        string strConn = "Data Source=192.168.1.146,12468;Initial Catalog=GS_MES;User ID=mesUser;Password =qixi1qaz@WSXmes";
        private static readonly string WebApiUrl =
        ConfigurationManager.AppSettings["WebApiUrl"];
        private ChromiumWebBrowser chromeBrowser;
        string urlPath;
        public ShowFile(string _urlPath)
        {
            InitializeComponent();
            this.urlPath = _urlPath;
            this.Load += ShowFile_Load;
            this.FormClosed += ShowFile_FormClosed;
        }
 
        private void ShowFile_FormClosed(object sender, FormClosedEventArgs e)
        {
            chromeBrowser.Dispose();
        }
 
        private void ShowFile_Load(object sender, EventArgs e)
        {
            string fileType = GetFileType(urlPath);
            string filePath = "";
            //这是guid,不是路径,根据guid 读取到它的路径
            if (urlPath.Length == 36)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder(" select top 1 url_Path from [dbo].[MES_FILE] where parent_Guid='" + urlPath + "'");
                object obj = GetSingle(sb.ToString());
                if (obj != null)
                {
                    filePath = System.Uri.EscapeUriString(obj.ToString());
                    fileType = GetFileType(filePath);
                }
                else
                    filePath = System.Uri.EscapeUriString(urlPath);
            }
            else
                filePath = System.Uri.EscapeUriString(urlPath);
            string _url = WebApiUrl + "upload/h5/site.html?fileType=" + fileType + "&filePath=" + filePath + "&mid=" + Guid.NewGuid().ToString();
            chromeBrowser = new ChromiumWebBrowser(_url);
            this.pane1.Controls.Add(chromeBrowser);
            chromeBrowser.Dock = DockStyle.Fill;
            txtUrl.Text = _url;
            txtUrl.ReadOnly = true;
        }
 
        public static string GetFileType(string fileName)
        {
            // 获取文件扩展名
            string extension = Path.GetExtension(fileName);
            // 根据扩展名判断文件类型
            switch (extension.ToLowerInvariant())
            {
                case ".jpg":
                case ".jpeg":
                case ".png":
                    return "img";
                case ".pdf":
                    return "pdf";
                case ".mp4":
                    return "mp4";
                default:
                    return "other";
            }
        }
 
 
        /// <summary>
        ///     执行一条计算查询结果语句,返回查询结果(object)。
        /// </summary>
        /// <param name="SQLString">计算查询结果语句</param>
        /// <returns>查询结果(object)</returns>
        private object GetSingle(string SQLString)
        {
            using (var connection = new SqlConnection(strConn))
            {
                using (var cmd = new SqlCommand(SQLString, connection))
                {
                    try
                    {
                        connection.Open();
                        var obj = cmd.ExecuteScalar();
                        if (Equals(obj, null) || Equals(obj, DBNull.Value))
                            return null;
                        return obj;
                    }
                    catch (SqlException e)
                    {
                        connection.Close();
                        throw new Exception(e.Message);
                    }
                }
            }
        }
    }
}