From 6e3bf2551088f0006eef11c2a2e607863a3f5536 Mon Sep 17 00:00:00 2001 From: keke Date: Tue, 15 Aug 2023 17:59:17 +0800 Subject: [PATCH] =?UTF-8?q?[WinAPP]=20keke=20test=20=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E7=84=A1=E9=97=9C=E7=B7=8A=E8=A6=81=E7=9A=84?= =?UTF-8?q?=E6=9D=B1=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- z01_WinAPP/Program.cs | 3 +- z01_WinAPP/Service/webRequestSvc.cs | 77 ++++++++++++++++- z01_WinAPP/fmCheckTagName.cs | 2 - z01_WinAPP/fmCheckTagName.resx | 62 +++++++++++++- z01_WinAPP/fmKeke.Designer.cs | 117 ++++++++++++++++++++++++++ z01_WinAPP/fmKeke.cs | 77 +++++++++++++++++ z01_WinAPP/fmKeke.resx | 123 ++++++++++++++++++++++++++++ 7 files changed, 454 insertions(+), 7 deletions(-) create mode 100644 z01_WinAPP/fmKeke.Designer.cs create mode 100644 z01_WinAPP/fmKeke.cs create mode 100644 z01_WinAPP/fmKeke.resx diff --git a/z01_WinAPP/Program.cs b/z01_WinAPP/Program.cs index ef35d3a..d96e59b 100644 --- a/z01_WinAPP/Program.cs +++ b/z01_WinAPP/Program.cs @@ -18,7 +18,8 @@ namespace tpDomeWinAPP Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new fmCheckTagName()); + //Application.Run(new fmCheckTagName()); + Application.Run(new fmKeke()); //Application.Run(new fmDecrypt()); } } diff --git a/z01_WinAPP/Service/webRequestSvc.cs b/z01_WinAPP/Service/webRequestSvc.cs index 6d31260..517c6fd 100644 --- a/z01_WinAPP/Service/webRequestSvc.cs +++ b/z01_WinAPP/Service/webRequestSvc.cs @@ -145,9 +145,10 @@ namespace tpDomeWinAPP.Service { List result = new List(); //String username = "obixUser"; - //String password = "Admin123456"; - String username = "stanGG"; - String password = "St12345678"; + String username = "admin"; + String password = "Admin123456"; + //String username = "stanGG"; + //String password = "St12345678"; String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); String API_Url = urlString; @@ -234,5 +235,75 @@ namespace tpDomeWinAPP.Service } return result; } + public List obixQuery_keke(string urlString, string post_xml) + { + //var handler = new HttpClientHandler(); + //handler.ClientCertificateOptions = ClientCertificateOption.Manual; + //handler.ServerCertificateCustomValidationCallback = + // (httpRequestMessage, cert, cetChain, policyErrors) => + // { + // return true; + // }; + //var client = new HttpClient(handler); + + List result = new List(); + String username = "admin"; + String password = "Admin123456"; + String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); + String API_Url = urlString; + + HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create(API_Url); + Postrequest.Method = "POST"; + Postrequest.Headers.Add("Authorization", "Basic " + encoded); + Postrequest.PreAuthenticate = true; + + using (var streamWriter = new StreamWriter(Postrequest.GetRequestStream())) + { + streamWriter.Write(post_xml); + } + + HttpWebResponse response = (HttpWebResponse)Postrequest.GetResponse(); + var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); + + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(responseString); + //xmlDoc.Load("N4v1021.xml");//N4v1021 + + //xmlDoc.Save("N4.xml"); + + + string jsonText = JsonConvert.SerializeXmlNode(xmlDoc); + // JObject resultVal = (JObject)JsonConvert.DeserializeObject(jsonText); + var data = Welcome.FromJson(jsonText); + + foreach (var item in data.Obj.Str) + { + device_value2 row = new device_value2(); + row.value = item.Val; + string[] s1 = item.Val.Split(','); + string[] s2 = s1[0].Split('/'); + row.tag_name = ""; + + for (int i = 0; i < s2.Length; i++) + { + if (i == s2.Length - 2) + { + row.point_name = s2[i]; + } + else if (i == 1) + { + row.tag_name += s2[i]; + } + else if (i > 1 && i < s2.Length - 2) + { + row.tag_name += "_" + s2[i].Replace("$3", ""); + } + } + + result.Add(row); + + } + return result; + } } } diff --git a/z01_WinAPP/fmCheckTagName.cs b/z01_WinAPP/fmCheckTagName.cs index fcd70ef..1e3a40f 100644 --- a/z01_WinAPP/fmCheckTagName.cs +++ b/z01_WinAPP/fmCheckTagName.cs @@ -120,8 +120,6 @@ namespace tpDomeWinAPP index++; } } - - private void rb100_CheckedChanged(object sender, EventArgs e) { RadioButton rb = (sender as RadioButton); diff --git a/z01_WinAPP/fmCheckTagName.resx b/z01_WinAPP/fmCheckTagName.resx index f298a7b..a395bff 100644 --- a/z01_WinAPP/fmCheckTagName.resx +++ b/z01_WinAPP/fmCheckTagName.resx @@ -1,4 +1,64 @@ - + + + diff --git a/z01_WinAPP/fmKeke.Designer.cs b/z01_WinAPP/fmKeke.Designer.cs new file mode 100644 index 0000000..8181991 --- /dev/null +++ b/z01_WinAPP/fmKeke.Designer.cs @@ -0,0 +1,117 @@ +namespace z01_WinAPP +{ + partial class fmKeke + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + splitContainer1 = new System.Windows.Forms.SplitContainer(); + lbMsg = new System.Windows.Forms.Label(); + loadData = new System.Windows.Forms.Button(); + dataGridView1 = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + splitContainer1.Location = new System.Drawing.Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(lbMsg); + splitContainer1.Panel1.Controls.Add(loadData); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dataGridView1); + splitContainer1.Size = new System.Drawing.Size(1169, 658); + splitContainer1.SplitterDistance = 121; + splitContainer1.TabIndex = 0; + // + // lbMsg + // + lbMsg.AutoSize = true; + lbMsg.Location = new System.Drawing.Point(474, 76); + lbMsg.Name = "lbMsg"; + lbMsg.Size = new System.Drawing.Size(219, 19); + lbMsg.TabIndex = 0; + lbMsg.Text = "Please Click \"loadData\" button"; + // + // loadData + // + loadData.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + loadData.Location = new System.Drawing.Point(463, 12); + loadData.Name = "loadData"; + loadData.Size = new System.Drawing.Size(236, 42); + loadData.TabIndex = 0; + loadData.Text = "loadData"; + loadData.UseVisualStyleBackColor = true; + loadData.Click += button1_Click; + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new System.Drawing.Point(177, 13); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowHeadersWidth = 51; + dataGridView1.RowTemplate.Height = 29; + dataGridView1.Size = new System.Drawing.Size(819, 508); + dataGridView1.TabIndex = 0; + dataGridView1.CellContentClick += dataGridView1_CellContentClick; + // + // fmKeke + // + AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(1169, 658); + Controls.Add(splitContainer1); + Name = "fmKeke"; + Text = "fmKeke"; + Load += fmKeke_Load; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.Button loadData; + private System.Windows.Forms.Label lbMsg; + private System.Windows.Forms.DataGridView dataGridView1; + } +} \ No newline at end of file diff --git a/z01_WinAPP/fmKeke.cs b/z01_WinAPP/fmKeke.cs new file mode 100644 index 0000000..21cdfac --- /dev/null +++ b/z01_WinAPP/fmKeke.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Security.Cryptography; +using System.Text; +using System.Windows.Forms; +using tpDomeWinAPP.Service; +using tpDomeWinAPP.Models; +using System.Linq; +using System.Collections; +using NPOI.SS.Formula.Functions; + +namespace z01_WinAPP +{ + public partial class fmKeke : Form + { + List ds; + public fmKeke() + { + InitializeComponent(); + } + + private void fmKeke_Load(object sender, EventArgs e) + { + + } + + private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e) + { + + } + + private void button1_Click(object sender, EventArgs e) + { + + loadData_fic(); + } + + private void loadData_fic() + { + lbMsg.Text = "Loading ..."; + + // https://green.fic.com.tw:8443/obix/config/ + // ObixUser + // Admin123456 + + webRequestSvc svc = new webRequestSvc(); + + //local:|foxs:|history:/S02102000101/Inv|view:history:HistoryTable + + string url_slot = "history:/S02102000101/Inv|"; + string bql = url_slot + "bql:select *"; + string obix_url = "https://green.fic.com.tw:8443/obix/histories/S03203000101/Inv/~historyQuery/"; + + string post_xml = ""; + + ds = svc.obixQuery_keke(obix_url, post_xml); + + //ds = svc.obixQuery("http://60.251.164.125:8080/obix/config/Arena/Program/ObixQuery/query/", bql); + //ds = svc.obixQuery("http://60.251.164.125:8080/obix/config/Program/ObixQuery/query/", bql);//三菱 + //ds = svc.obixQuery("http://192.168.0.136:8081/obix/config/Program/ObixQuery/query/", bql);//wsp + //ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql); + //dataGridView1.DataSource = ds; + dataGridView1.Columns[0].Visible = false; + dataGridView1.Columns[1].Width = 400; + dataGridView1.Columns[2].Width = 200; + //lbMsg.Text = "共 " + ds.Count.ToString() + " 筆資料 " + Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + } + + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + } +} diff --git a/z01_WinAPP/fmKeke.resx b/z01_WinAPP/fmKeke.resx new file mode 100644 index 0000000..49ea9be --- /dev/null +++ b/z01_WinAPP/fmKeke.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file