using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; using System.Xml.Linq; using EntityDataSet; using IntelligentControlForsx.ChildForms; using IntelligentControlForsx.MyControls; using IntelligentControlForsx.MyControls.windturbine; using IntelligentControlForsx.Service.HomeFormInfo; using IntelligentControlForsx.Service.HomeFormInfo.Domain; using IntelligentControlForsx.Service.ParameterFormInfo; using IntelligentControlForsx.Service.WindturbineControl.Domain; using IntelligentControlForsx.Service.WindturbineControl.FormInfoSvc; using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc; using IntelligentControlForsx.Service.WindturbineInfo; using Golden.DotNetSDK.Common; using Gyee_Control.Svc.Cache; using Gyee_Control.View; using WisdomClient; using WisdomClient.data; namespace IntelligentControlForsx.Test { public partial class Test : Form { public Test() { InitializeComponent(); } private void btnMySql_Click(object sender, EventArgs e) { wisdom_cs_entity entity = new wisdom_cs_entity(); IQueryable result = entity.project.Select(s => s); foreach (project item in result) { Console.WriteLine(item.NAME); } } private void btnDateToLong_Click(object sender, EventArgs e) { DateTime time = DateTime.Now; DateTime FirstTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); long timeStamp = (long)(DateTime.Now - FirstTime).TotalMilliseconds; MessageBox.Show(timeStamp.ToString()); } private void btnGetHomeInfo_Click(object sender, EventArgs e) { HomeFormInfoSvc svc = HomeFormInfoSvc.Instance; LeftInfo leftInfo = svc.GetLeftInfo(); CenterInfo centerInfo = svc.GetCenterInfo(); RightInfo rightInfo = svc.GetRightInfo(); } private void btnConvert_Click(object sender, EventArgs e) { string s = "6.68229675292969"; double ss = Double.Parse(s); MessageBox.Show(ss.ToString()); } private void btnRef_Click(object sender, EventArgs e) { IList list1 = new List(); RefTest(ref list1); for (int i = 0; i < list1.Count; i++) { MessageBox.Show(list1[i]); } } private void RefTest(ref IList list) { list.Add("123"); list.Add("456"); } private void btnForeach_Click(object sender, EventArgs e) { IList list = new List(); MyClass c1 = new MyClass() { id = 1, name = "name1" }; MyClass c2 = new MyClass() { id = 2, name = "name2" }; list.Add(c1); list.Add(c1); for (int i = 1; i < 3; i++) { var data = list.Where(s => s.id == i).FirstOrDefault(); if (data != null) data.name = "wanghs"; } Console.WriteLine(list[0].name); } public class MyClass { public int id { set; get; } public string name { set; get; } } private void btnGetSnap_Click(object sender, EventArgs e) { DateTime FirstTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); DateTime startDateTime = DateTime.Now.AddHours(-12); long startTimeStamp = (long)(startDateTime - FirstTime).TotalMilliseconds; long endTimeStamp = (long)(DateTime.Now - FirstTime).TotalMilliseconds; List powerList = RestfulClient.findHistorySnapByThingCodes("station", "0", Point.SSZGL, startTimeStamp, endTimeStamp, 3600); List speedList = RestfulClient.findHistorySnapByThingCodes("station", "-1", "SSFS", startTimeStamp, endTimeStamp, 3600); MessageBox.Show(powerList.Count.ToString()); MessageBox.Show(speedList.Count.ToString()); } private void btnParameter_Click(object sender, EventArgs e) { ParameterFormInfoSvc svc = ParameterFormInfoSvc.Instance; //svc.BuilDicUnifromCodeList(); svc.RefreshDataList("XS_FDC"); } private void btnGolden_Click(object sender, EventArgs e) { string goldenConfig = ConfigurationManager.AppSettings["GoldenConnectPath"]; RTDBConnection conData = new RTDBConnection(goldenConfig); conData.Open(); } private void btnWindturbine_TagName_Click(object sender, EventArgs e) { } private void btnThread_Click(object sender, EventArgs e) { Thread t = new Thread(Th); t.Start(); Console.WriteLine("方法执行完成"); } public void Th() { for (int i = 0; i < 100; i++) { Thread.Sleep(100); Console.WriteLine(i); } } private void btnSubString_Click(object sender, EventArgs e) { IList list = new List(); WindturbinePointData data1 = new WindturbinePointData(); data1.WindturbineName = "SG01-01"; data1.Power = 23.22; WindturbinePointData data2 = new WindturbinePointData(); data2.WindturbineName = "SG01-02"; data2.Power = 23.22; WindturbinePointData data3 = new WindturbinePointData(); data3.WindturbineName = "SG01-110"; data3.Power = 23.22; WindturbinePointData data4 = new WindturbinePointData(); data4.WindturbineName = "SG01-111"; data4.Power = 23.22; WindturbinePointData data5 = new WindturbinePointData(); data5.WindturbineName = "SG01-09"; data5.Power = 23.22; WindturbinePointData data6 = new WindturbinePointData(); data6.WindturbineName = "SG01-10"; data6.Power = 23.22; list.Add(data2); list.Add(data1); list.Add(data4); list.Add(data3); list.Add(data5); list.Add(data6); MessageBox.Show(list[3].WindturbineName.Substring(5, list[3].WindturbineName.Length - 5)); MessageBox.Show(list[2].WindturbineName.Substring(5, list[2].WindturbineName.Length - 5)); MessageBox.Show(list[0].WindturbineName.Substring(5, list[0].WindturbineName.Length - 5)); MessageBox.Show(list[0].WindturbineName.Split('-').ToList()[1].ToString()); MessageBox.Show(list[3].WindturbineName.Split('-').ToList()[1].ToString()); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i].WindturbineName); } Console.WriteLine("========================================================="); IList list2 = list.OrderBy(s => s.WindturbineName.Split('-').ToList()[1]).ToList(); for (int i = 0; i < list2.Count; i++) { Console.WriteLine(list2[i].WindturbineName); } } private void btnOutMethod_Click(object sender, EventArgs e) { IList numList = new List(); for (int i = 0; i < 30; i++) { numList.Add(i); } IList list = new List(); bool t = OutMethodTest(numList, out list); } public bool OutMethodTest(IList numList, out IList oList) { oList = new List(); bool b = OutMetodTest2(numList, out oList); return b; } public bool OutMetodTest2(IList numList, out IList oddList) { oddList = new List(); for (int i = 0; i < numList.Count; i++) { if (numList[i] % 3 == 0) oddList.Add(numList[i]); } if (oddList.Count > 9) return true; else return false; } private void btnConnect_Click(object sender, EventArgs e) { ControlIntPtr svc = ControlIntPtr.GetControlIntPtr(); svc.init(); MessageBox.Show("通道建立成功"); } private void btnSendCmd_Click(object sender, EventArgs e) { IntPtr ptr = ControlIntPtr.dic[""]; byte[] types = new byte[] { CmdSendService.GYCP_TYPE_YT, CmdSendService.GYCP_TYPE_YT, CmdSendService.GYCP_TYPE_YK, CmdSendService.GYCP_TYPE_YK }; uint[] addrs = new uint[] { 1999, 2001, 2002, 2003, 998 }; float[] values = new float[] { 1, 1, 1, 1, 1 }; uint length = 5; int count = CmdSendService.gycp_control(ptr, types, addrs, values, length); } private void btnForeachBreak_Click(object sender, EventArgs e) { IList list = new List() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; foreach (int i in list) { if (i == 5) break; Console.WriteLine(i); } } private void btnPic_Click(object sender, EventArgs e) { } private void btnGroupBy_Click(object sender, EventArgs e) { IList list = new List(); list.Add(new MyTest() { Name = "wanghs0", Id = 1 }); list.Add(new MyTest() { Name = "wanghs1", Id = 1 }); list.Add(new MyTest() { Name = "wanghs2", Id = 2 }); list.Add(new MyTest() { Name = "wanghs3", Id = 2 }); list.Add(new MyTest() { Name = "wanghs4", Id = 3 }); var result = list.GroupBy(s => s.Id); foreach (IGrouping info in result) { List sl = info.ToList(); for (int i = 0; i < sl.Count; i++) { Console.WriteLine(sl[i].Name); } Console.WriteLine("----------"); } } private void btnUniformCodeTest_Click(object sender, EventArgs e) { DateTime t1 = DateTime.Now; CacheInfo.StationChange("SBQ_FDC"); DateTime t2 = DateTime.Now; TimeSpan ts = t2 - t1; MessageBox.Show(ts.Minutes.ToString() + "分" + ts.Seconds.ToString() + "秒"); } private void btnFingerCheck_Click(object sender, EventArgs e) { user u = null; FingerCheck check = new FingerCheck(); check.ShowDialog(); u = FingerCheck.checkSuccessUser; if (u != null) Console.WriteLine("获取到用户"); else Console.WriteLine("未获取到用户"); // MessageBox.Show(u.name); } private void btnGetPath_Click(object sender, EventArgs e) { DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); long tt = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 WindturbineInfoSvc svc = WindturbineInfoSvc.Instance; svc.RefreshPointValue("SBQ_FDC", "SG01_01", "UP82_2", "BasicInfo"); IList list = svc.GetPointData(); long ee = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 long re = ee - tt; MessageBox.Show("时间差:" + re); foreach (var item in list) { Console.WriteLine(item.Index + "_" + item.Name + ":" + item.PointValue); } } private void btnRegister_Click(object sender, EventArgs e) { FingerCheck check = new FingerCheck(); check.ShowDialog(); user adminUser = FingerCheck.checkSuccessUser; if (adminUser != null && adminUser.user_name == "admin") { // Register register = new Register(); // register.ShowDialog(); } else { MessageBox.Show("管理员验证失败"); } } private void btnGetWindturbine_Click(object sender, EventArgs e) { using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { IList list = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == "SBQ_FDC" && s.PROJECTID == "SBQ02_GC").ToList(); string str = ""; for (int i = 0; i < list.Count; i++) { str = str + "'" + list[i].ID + "'" + ","; } Console.WriteLine(str); } } private void btnDic_Click(object sender, EventArgs e) { ParameterFormInfoSvc svc = ParameterFormInfoSvc.Instance; Console.WriteLine("获取成功"); } private void btnArrSub_Click(object sender, EventArgs e) { int[] arr = new int[22]; for (int i = 0; i < 22; i++) { arr[i] = i; } int selectCount = arr.Length / 5; int remainder = arr.Length % 5; if (remainder == 0)//如果被整除 { for (int i = 0; i < selectCount; i++) { int[] subTagName = arr.Skip(5 * i).Take(5 * (i + 1)).ToArray(); for (int j = 0; j < subTagName.Length; j++) { Console.WriteLine(subTagName[j]); } } } else//tagNames长度无法被1000整除 { for (int i = 0; i < selectCount; i++) { int[] subTagName = arr.Skip(5 * i).Take(5 * (i + 1)).ToArray(); for (int j = 0; j < subTagName.Length; j++) { Console.WriteLine(subTagName[j]); } } //将数组剩余元素进行查询 int[] lastTagName = arr.Skip(5 * selectCount).Take(remainder).ToArray(); ; for (int j = 0; j < lastTagName.Length; j++) { Console.WriteLine(lastTagName[j]); } } } private void btnControlFull_Click(object sender, EventArgs e) { this.plInfo.Controls.Clear(); for (int i = 0; i < 2; i++) { ControlLine line = new ControlLine(); line.Name = "line" + i; line.WindturbineId = "SG01_0" + i; line.Dock = DockStyle.Top; this.plInfo.Controls.Add(line); } label1.BackColor = Color.OrangeRed; label1.ForeColor = Color.White; } private void btnChange_Click(object sender, EventArgs e) { Control[] lineArr = this.Controls.Find("line0", true); if (lineArr.Length > 0) { ControlLine controlLine = (ControlLine)lineArr[0]; controlLine.WindturbineId = "SG01_111"; } } private void btnToOtherPage_Click(object sender, EventArgs e) { MainTest t = new MainTest(); t.Show(); } private void btnIndexTest_Click(object sender, EventArgs e) { CacheInfo.StationChange("SBQ_FDC"); } private void btnRestFul_Click(object sender, EventArgs e) { IList dataList = new List(); System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); long tt = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { IList list = ctx.windturbine_uniform_code.Where(s => s.station_id == "SBQ_FDC").ToList(); for (int i = 0; i < list.Count; i++) { WindturbinePointData data = new WindturbinePointData(); data.WindturbineName = list[i].windturbine_id; data.StationId = list[i].station_id; Dictionary dic = null; string[] arr = new[] { list[i].status_uniform_code, list[i].wind_speed_uniform_code, list[i].power_uniform_code, list[i].alternator_speed_uniform_code, list[i].lamina_speed_uniform_code, list[i].lamina_angle1_uniform_code, list[i].lamina_angle2_uniform_code, list[i].lamina_angle3_uniform_code, list[i].wind_angle_uniform_code, list[i].yaw_position_uniform_code, }; dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].windturbine_id, arr); foreach (var tsData in dic) { //int statusValue = Convert.ToInt32(tsData.Value.getValue()); //switch (statusValue) //{ // case 0: // data.Status = WindturbineStatus.Standby; // break; // case 1: // data.Status = WindturbineStatus.BuildPower; // break; // case 2: // data.Status = WindturbineStatus.FaultStop; // break; // case 3: // data.Status = WindturbineStatus.Offline; // break; // case 4: // data.Status = WindturbineStatus.Maintain; // break; //} data.WindSpeed = Convert.ToDouble(tsData.Value.getValue()); dataList.Add(data); } } long ee = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 long re = ee - tt; MessageBox.Show("时间差:" + re); } } private void btnAdapter_Click(object sender, EventArgs e) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); long tt = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 WindturbinePointDataSvc.UpdatePointData("SBQ_FDC"); long ee = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 long re = ee - tt; MessageBox.Show("时间差:" + re); } private void btnAdapterSnap_Click(object sender, EventArgs e) { System.DateTime theTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime startTime = new System.DateTime(2018, 10, 17); long startTimeLong = (startTime.Ticks - theTime.Ticks) / 10000; //除10000调整为13位 DateTime endTime = new System.DateTime(2018, 10, 18); long endTimeLong = (endTime.Ticks - theTime.Ticks) / 10000; //除10000调整为13位 IList list = RestfulClient.findHistorySnapByTagName("SBQFJ.NX_GD_SBQF_FJ_P1_L1_001_AI0005", startTimeLong, endTimeLong, 3600); for (int i = 0; i < list.Count; i++) { string dataValue = list[i].getValue(); DateTime dt = theTime.AddMilliseconds(list[i].ts); string dateTime = dt.ToString("yyyy/MM/dd HH:mm:ss:ffff"); Console.WriteLine(dataValue + "=======" + dateTime); } for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i].getValue() + "+++" + list[i].ts); } } private void btnGoldenWirte_Click(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { Label l = (Label)sender; MessageBox.Show(l.Name + l.Text); } private void btnControlTest_Click(object sender, EventArgs e) { UniformCodeInfo info1 = new UniformCodeInfo(); info1.PointValue = "201811"; info1.Unit = "Kw"; info1.Name = "功率"; pointValueAI1.BindData(info1); UniformCodeInfo info2 = new UniformCodeInfo(); info2.PointValue = "1"; info2.Unit = ""; info2.Name = "故障"; pointValueDI1.BindData(info2); } private void btnGetClassName_Click(object sender, EventArgs e) { MessageBox.Show(this.GetType().Name); } private void btnGetControl_Click(object sender, EventArgs e) { object obj = this.GetType().GetField("pointValueAI1", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this); if (obj is Label) { Label l = (Label)obj; } else if (obj is PointValueAI) { PointValueAI p = (PointValueAI)obj; MessageBox.Show(obj.GetType().Name); MessageBox.Show(p.Name + p.NameString); } } private void btnNumConvert_Click(object sender, EventArgs e) { string s = "0.00"; int n = Convert.ToInt32(s); MessageBox.Show(n.ToString()); } private bool ConvertNum(string s) { double num = 0.0; try { num = Convert.ToDouble(s); return true; } catch (Exception) { return false; } } private void timer1_Tick(object sender, EventArgs e) { DateTime time = DateTime.Now; string timeString = time.ToString("yyyy-MM-dd hh:mm:ss"); lblTime.Text = timeString; } private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 3; i++) { OutInLine ln = new OutInLine(); ln.Name = "叶轮装置" + i; ln.PointName = "叶轮装置" + i; ln.Dock = DockStyle.Top; panel2.Controls.Add(ln); } } private void btnXmlRead_Click(object sender, EventArgs e) { OutInInfo info = new OutInInfo(); } private void button2_Click(object sender, EventArgs e) { int num1 = Convert.ToInt32(textBox1.Text.Trim()); int num2 = Convert.ToInt32(textBox2.Text.Trim()); string mark = textBox3.Text.Trim(); string markName = ""; int result = 0; if (mark == "+") { result = num1 + num2; markName = "加法"; } if (mark == "-") result = num1 - num2; if (mark == "*") result = num1 * num2; if (mark == "/") result = num1 / num2; for (int i = 0; i < 10; i++) { MessageBox.Show("做" + markName + "运算,运算数1:" + num1 + ",加数2:" + num2 + "计算结果为:" + result+"|||循环次数为第"+i); } } private void button3_Click(object sender, EventArgs e) { textBox1.Text = "测试"; } private void textBox2_TextChanged(object sender, EventArgs e) { } /* public void Send() { ControlDao.GycpReceive receive = Back; IntPtr ptr = ControlDao.gycp_create("127.0.0.1", (ushort)9901, 30, 30, 20, Back, new IntPtr()); byte[] types = new byte[] { ControlDao.GYCP_TYPE_YK }; uint[] addrs = new uint[] { 2001 }; float[] values = new float[] { 1 }; uint length = 1; ControlDao.gycp_control(ptr, types, addrs, values, length); } public void Back(IntPtr types, IntPtr addrs, IntPtr errors, uint length, IntPtr arg) { Console.WriteLine("============================="); try { if (addrs != null && errors != null && length != 0) { byte[] tmp_types = new byte[length]; int[] tmp_addrs = new int[length]; int[] tmp_errs = new int[length]; Marshal.Copy(types, tmp_types, 0, tmp_types.Length); Marshal.Copy(addrs, tmp_addrs, 0, tmp_addrs.Length); Marshal.Copy(errors, tmp_errs, 0, tmp_errs.Length); Console.WriteLine("回调成功" + tmp_addrs + "||" + tmp_errs + "||" + tmp_errs); } } catch (Exception e) { Console.WriteLine("回调异常"); } }*/ } public class MyTest { public string Name { set; get; } public int Id { set; get; } } }