Files
fl-knowledge/LP/Form7_GuZhangFuXian.cs

576 lines
18 KiB
C#

using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace LP;
public class Form7_GuZhangFuXian : Form
{
private delegate void delegateFormHide(Form form);
private delegate void dltFormSetVisiable(Form form, bool value);
private delegate void delegateFormSetTitle(Form form, string value);
private delegate void delegateComboBoxItemsClear(ComboBox comboBox);
private delegate void delegateComboBoxAdd(ComboBox comboBox, string value);
private delegate void delegateComboBoxSetSelectedIndex(ComboBox comboBox, int value);
private delegate void delegateListBoxItemsClear(ListBox listBox);
private delegate void delegateListBoxAdd(ListBox listBox, string value);
private delegate void delegateListBoxSelectedIndex(ListBox listBox, int value);
private delegate void delegateTextBoxSetText(TextBox textBox, string value);
private delegate void delegateButtonEnabled(Button button, bool value);
public FormDesktop desktop = null;
private bool mAfterInit = false;
public string mTitle = "";
public int mIndex_CurrentCurve = -1;
public int mCurrentCurve = 0;
public int mIndex_0FanJi_1RaoJi = -1;
public int m0FanJi_1RaoJi = -1;
public double mNaiLeiShuiPing = 0.0;
public string mBaseFileName = "";
private readonly string mSubPath_FuXian = "FuXian";
private IContainer components = null;
private ComboBox comboBox_CurrentCurve;
private Label label2;
private Button buttonCancel;
private Button buttonOK;
private Label label1;
private ComboBox comboBox_0FanJi_1RaoJi;
private Label label3;
private TextBox textBox_NaiLeiShuiPing;
private Button buttonGuZhangFuXian;
private TextBox textBox_Show;
private Button buttonBase;
public Form7_GuZhangFuXian()
{
InitializeComponent();
string path = Application.StartupPath + "\\" + mSubPath_FuXian;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
private void Form7_GuZhangFuXian_Load(object sender, EventArgs e)
{
mAfterInit = false;
MyInput_ComboBox();
mAfterInit = true;
}
private void Form7_GuZhangFuXian_FormClosing(object sender, FormClosingEventArgs e)
{
}
public void MyInput_ComboBox()
{
MyComboBoxItemsClear(comboBox_CurrentCurve);
MyComboBoxAdd(comboBox_CurrentCurve, "Heidler");
MyComboBoxAdd(comboBox_CurrentCurve, "双斜角");
MyComboBoxAdd(comboBox_CurrentCurve, "双指数");
if (mIndex_CurrentCurve < 0)
{
mIndex_CurrentCurve = 0;
}
if (mIndex_CurrentCurve >= 0 && mIndex_CurrentCurve < comboBox_CurrentCurve.Items.Count)
{
MyComboBoxSetSelectedIndex(comboBox_CurrentCurve, mIndex_CurrentCurve);
mCurrentCurve = comboBox_CurrentCurve.SelectedIndex + 1;
}
else
{
mCurrentCurve = 0;
}
MyComboBoxItemsClear(comboBox_0FanJi_1RaoJi);
MyComboBoxAdd(comboBox_0FanJi_1RaoJi, "反击");
MyComboBoxAdd(comboBox_0FanJi_1RaoJi, "绕击");
if (mIndex_0FanJi_1RaoJi < 0)
{
mIndex_0FanJi_1RaoJi = 0;
}
if (mIndex_0FanJi_1RaoJi >= 0 && mIndex_0FanJi_1RaoJi < comboBox_0FanJi_1RaoJi.Items.Count)
{
MyComboBoxSetSelectedIndex(comboBox_0FanJi_1RaoJi, mIndex_0FanJi_1RaoJi);
m0FanJi_1RaoJi = comboBox_0FanJi_1RaoJi.SelectedIndex;
}
else
{
m0FanJi_1RaoJi = 0;
}
MyTextBoxSetText(textBox_NaiLeiShuiPing, $"{mNaiLeiShuiPing}");
}
public void Destroy()
{
}
private void buttonOK_Click(object sender, EventArgs e)
{
if (mAfterInit)
{
base.DialogResult = DialogResult.OK;
Close();
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
if (mAfterInit)
{
base.DialogResult = DialogResult.Cancel;
Close();
}
}
private void buttonGuZhangFuXian_Click(object sender, EventArgs e)
{
if (!mAfterInit)
{
return;
}
string value = "";
MyFormSetTitle(this, value);
MyTextBoxSetText(textBox_Show, value);
if (mCurrentCurve < 1 || mCurrentCurve > 3)
{
value = $"波形数值({mCurrentCurve})越界. 有效值范围[1,3].";
MyFormSetTitle(this, value + "请选定波形,然后点击“" + buttonGuZhangFuXian.Text + "”。");
comboBox_CurrentCurve.Focus();
return;
}
if (m0FanJi_1RaoJi != 0 && m0FanJi_1RaoJi != 1)
{
value = $"类型数值({m0FanJi_1RaoJi})越界. ";
MyFormSetTitle(this, value + "请选定类型,然后点击“" + buttonGuZhangFuXian.Text + "”。");
comboBox_0FanJi_1RaoJi.Focus();
return;
}
if (mNaiLeiShuiPing <= 0.0)
{
value = $"雷电流数值({mNaiLeiShuiPing})越界. 有效值大于零.";
MyFormSetTitle(this, value + "请重新输入雷电流,然后点击“" + buttonGuZhangFuXian.Text + "”。");
textBox_NaiLeiShuiPing.Focus();
return;
}
desktop.mFuXian.mFName_file = $"{mSubPath_FuXian}\\file_{mCurrentCurve}.txt";
desktop.mFuXian.mFName_data = $"{mSubPath_FuXian}\\data_{mCurrentCurve}.txt";
desktop.mFuXian.mFName_out = mSubPath_FuXian + "\\data-out.txt";
if (!File.Exists(desktop.mFuXian.mFName_file))
{
value = "基础数据文件(" + desktop.mFuXian.mFName_file + ")未找到。";
MyFormSetTitle(this, value + " 请点击“" + buttonBase.Text + "”.");
buttonBase.Focus();
return;
}
if (!File.Exists(desktop.mFuXian.mFName_data))
{
value = "基础数据文件(" + desktop.mFuXian.mFName_data + ")未找到。";
MyFormSetTitle(this, value + " 请点击“" + buttonBase.Text + "”.");
buttonBase.Focus();
return;
}
string text = "";
text = desktop.mFuXian.ReadFileData();
if (!text.Equals("OK"))
{
value = text;
MyFormSetTitle(this, value + " 请点击“" + buttonBase.Text + "”.");
buttonBase.Focus();
}
else
{
desktop.mFuXian.mCurveNo = mCurrentCurve;
desktop.mFuXian.m0FanJi_1RaoJi = m0FanJi_1RaoJi;
desktop.mFuXian.mShuiPing = mNaiLeiShuiPing;
text = desktop.mFuXian.LeiDianFuXian2();
MyTextBoxSetText(textBox_Show, text);
}
}
private void buttonBase_Click(object sender, EventArgs e)
{
if (mAfterInit)
{
MyFormSetTitle(this, "");
MyTextBoxSetText(textBox_Show, "");
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Application.StartupPath;
openFileDialog.Filter = "所有文件*.*|*.*|Excel文件(*.csv)|*.csv|Txt文件(*.txt)|*.txt";
openFileDialog.FilterIndex = 3;
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
mBaseFileName = openFileDialog.FileName;
desktop.mFuXian.mFName_file = $"{mSubPath_FuXian}\\file_{mCurrentCurve}.txt";
desktop.mFuXian.mFName_data = $"{mSubPath_FuXian}\\data_{mCurrentCurve}.txt";
desktop.mFuXian.mCurveNo = mCurrentCurve;
desktop.mFuXian.m0FanJi_1RaoJi = m0FanJi_1RaoJi;
desktop.mFuXian.mShuiPing = mNaiLeiShuiPing;
Thread thread = new Thread(MyLoad_Base);
thread.Start();
}
}
}
private void MyLoad_Base()
{
string text = "";
text = desktop.mFuXian.MyLoad_BaseData(mBaseFileName);
if (text.Equals("OK"))
{
text = $"基础数据{desktop.mFuXian.arrHead.Count}条。";
}
MyTextBoxSetText(textBox_Show, text);
}
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (mAfterInit)
{
int selectedIndex = ((ComboBox)sender).SelectedIndex;
string text = ((ComboBox)sender).SelectedItem.ToString().Trim();
if (sender == comboBox_CurrentCurve)
{
mIndex_CurrentCurve = selectedIndex;
mCurrentCurve = selectedIndex + 1;
}
else if (sender == comboBox_0FanJi_1RaoJi)
{
mIndex_0FanJi_1RaoJi = selectedIndex;
m0FanJi_1RaoJi = selectedIndex;
}
}
}
private void textBox_TextChanged(object sender, EventArgs e)
{
if (mAfterInit)
{
string value = ((TextBox)sender).Text.Trim();
double num = -1.0;
try
{
num = Convert.ToDouble(value);
}
catch (Exception)
{
num = -1.0;
}
if (sender == textBox_NaiLeiShuiPing)
{
mNaiLeiShuiPing = num;
}
}
}
public void MyFormHide(Form form)
{
try
{
if (form.InvokeRequired)
{
delegateFormHide method = MyFormHide;
form.Invoke(method, form);
}
else
{
form.Hide();
}
}
catch (Exception)
{
}
}
public void MyFormSetVisiable(Form form, bool value)
{
if (form.InvokeRequired)
{
dltFormSetVisiable method = MyFormSetVisiable;
form.Invoke(method, form, value);
}
else
{
form.Visible = value;
}
}
public void MyFormSetTitle(Form form, string value)
{
if (form.InvokeRequired)
{
delegateFormSetTitle method = MyFormSetTitle;
form.Invoke(method, form, value);
return;
}
if (string.IsNullOrEmpty(value))
{
form.Text = mTitle;
}
if (!string.IsNullOrEmpty(value))
{
form.Text = mTitle + " " + value;
}
}
public void MyComboBoxItemsClear(ComboBox comboBox)
{
if (comboBox.InvokeRequired)
{
delegateComboBoxItemsClear method = MyComboBoxItemsClear;
comboBox.Invoke(method, comboBox);
}
else
{
comboBox.Items.Clear();
}
}
public void MyComboBoxAdd(ComboBox comboBox, string value)
{
if (comboBox.InvokeRequired)
{
delegateComboBoxAdd method = MyComboBoxAdd;
comboBox.Invoke(method, comboBox, value);
}
else if (!string.IsNullOrEmpty(value))
{
comboBox.Items.Add(value);
}
}
public void MyComboBoxSetSelectedIndex(ComboBox comboBox, int value)
{
if (comboBox.InvokeRequired)
{
delegateComboBoxSetSelectedIndex method = MyComboBoxSetSelectedIndex;
comboBox.Invoke(method, comboBox, value);
}
else if (value >= 0 && value < comboBox.Items.Count)
{
comboBox.SelectedIndex = value;
}
}
public void MyListBoxItemsClear(ListBox listBox)
{
if (listBox.InvokeRequired)
{
delegateListBoxItemsClear method = MyListBoxItemsClear;
listBox.Invoke(method, listBox);
}
else
{
listBox.Items.Clear();
}
}
public void MyListBoxAdd(ListBox listBox, string value)
{
if (listBox.InvokeRequired)
{
delegateListBoxAdd method = MyListBoxAdd;
listBox.Invoke(method, listBox, value);
}
else if (!string.IsNullOrEmpty(value))
{
listBox.Items.Add(value);
}
}
public void MyListBoxSelectedIndex(ListBox listBox, int value)
{
if (listBox.InvokeRequired)
{
delegateListBoxSelectedIndex method = MyListBoxSelectedIndex;
listBox.Invoke(method, listBox, value);
}
else if (value >= 0 && value < listBox.Items.Count)
{
listBox.SelectedIndex = value;
}
}
public void MyTextBoxSetText(TextBox textBox, string value)
{
if (textBox.InvokeRequired)
{
delegateTextBoxSetText method = MyTextBoxSetText;
textBox.Invoke(method, textBox, value);
}
else
{
textBox.Text = value;
}
}
public void MyButtonEnabled(Button button, bool value)
{
if (button.InvokeRequired)
{
delegateButtonEnabled method = MyButtonEnabled;
button.Invoke(method, button, value);
}
else
{
button.Enabled = value;
}
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.comboBox_CurrentCurve = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.comboBox_0FanJi_1RaoJi = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox_NaiLeiShuiPing = new System.Windows.Forms.TextBox();
this.buttonGuZhangFuXian = new System.Windows.Forms.Button();
this.textBox_Show = new System.Windows.Forms.TextBox();
this.buttonBase = new System.Windows.Forms.Button();
base.SuspendLayout();
this.comboBox_CurrentCurve.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox_CurrentCurve.Font = new System.Drawing.Font("宋体", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
this.comboBox_CurrentCurve.FormattingEnabled = true;
this.comboBox_CurrentCurve.Location = new System.Drawing.Point(64, 45);
this.comboBox_CurrentCurve.Name = "comboBox_CurrentCurve";
this.comboBox_CurrentCurve.Size = new System.Drawing.Size(388, 20);
this.comboBox_CurrentCurve.TabIndex = 61;
this.comboBox_CurrentCurve.SelectedIndexChanged += new System.EventHandler(comboBox_SelectedIndexChanged);
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
this.label2.Location = new System.Drawing.Point(64, 28);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(77, 14);
this.label2.TabIndex = 62;
this.label2.Text = "雷电流波形";
this.buttonCancel.Location = new System.Drawing.Point(366, 358);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(86, 28);
this.buttonCancel.TabIndex = 64;
this.buttonCancel.Text = "取消";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(buttonCancel_Click);
this.buttonOK.Location = new System.Drawing.Point(258, 358);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(86, 28);
this.buttonOK.TabIndex = 63;
this.buttonOK.Text = "确定";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(buttonOK_Click);
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
this.label1.Location = new System.Drawing.Point(61, 88);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 14);
this.label1.TabIndex = 62;
this.label1.Text = "类型";
this.comboBox_0FanJi_1RaoJi.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox_0FanJi_1RaoJi.Font = new System.Drawing.Font("宋体", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
this.comboBox_0FanJi_1RaoJi.FormattingEnabled = true;
this.comboBox_0FanJi_1RaoJi.Location = new System.Drawing.Point(64, 105);
this.comboBox_0FanJi_1RaoJi.Name = "comboBox_0FanJi_1RaoJi";
this.comboBox_0FanJi_1RaoJi.Size = new System.Drawing.Size(388, 20);
this.comboBox_0FanJi_1RaoJi.TabIndex = 61;
this.comboBox_0FanJi_1RaoJi.SelectedIndexChanged += new System.EventHandler(comboBox_SelectedIndexChanged);
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
this.label3.Location = new System.Drawing.Point(61, 152);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(77, 14);
this.label3.TabIndex = 62;
this.label3.Text = "雷电流数值";
this.textBox_NaiLeiShuiPing.Location = new System.Drawing.Point(144, 151);
this.textBox_NaiLeiShuiPing.Name = "textBox_NaiLeiShuiPing";
this.textBox_NaiLeiShuiPing.Size = new System.Drawing.Size(167, 21);
this.textBox_NaiLeiShuiPing.TabIndex = 65;
this.textBox_NaiLeiShuiPing.TextChanged += new System.EventHandler(textBox_TextChanged);
this.buttonGuZhangFuXian.Location = new System.Drawing.Point(63, 186);
this.buttonGuZhangFuXian.Name = "buttonGuZhangFuXian";
this.buttonGuZhangFuXian.Size = new System.Drawing.Size(86, 28);
this.buttonGuZhangFuXian.TabIndex = 66;
this.buttonGuZhangFuXian.Text = "故障复现";
this.buttonGuZhangFuXian.UseVisualStyleBackColor = true;
this.buttonGuZhangFuXian.Click += new System.EventHandler(buttonGuZhangFuXian_Click);
this.textBox_Show.Enabled = false;
this.textBox_Show.Location = new System.Drawing.Point(63, 220);
this.textBox_Show.Multiline = true;
this.textBox_Show.Name = "textBox_Show";
this.textBox_Show.Size = new System.Drawing.Size(389, 91);
this.textBox_Show.TabIndex = 65;
this.textBox_Show.TextChanged += new System.EventHandler(textBox_TextChanged);
this.buttonBase.Location = new System.Drawing.Point(225, 186);
this.buttonBase.Name = "buttonBase";
this.buttonBase.Size = new System.Drawing.Size(86, 28);
this.buttonBase.TabIndex = 66;
this.buttonBase.Text = "指定基础数据";
this.buttonBase.UseVisualStyleBackColor = true;
this.buttonBase.Click += new System.EventHandler(buttonBase_Click);
base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
base.ClientSize = new System.Drawing.Size(508, 398);
base.Controls.Add(this.buttonBase);
base.Controls.Add(this.buttonGuZhangFuXian);
base.Controls.Add(this.textBox_Show);
base.Controls.Add(this.textBox_NaiLeiShuiPing);
base.Controls.Add(this.buttonCancel);
base.Controls.Add(this.buttonOK);
base.Controls.Add(this.comboBox_0FanJi_1RaoJi);
base.Controls.Add(this.comboBox_CurrentCurve);
base.Controls.Add(this.label1);
base.Controls.Add(this.label3);
base.Controls.Add(this.label2);
base.Name = "Form7_GuZhangFuXian";
base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Form7_GuZhangFuXian";
base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(Form7_GuZhangFuXian_FormClosing);
base.Load += new System.EventHandler(Form7_GuZhangFuXian_Load);
base.ResumeLayout(false);
base.PerformLayout();
}
}