#region Using using System; using System.Windows.Forms; using ORiN2.interop.CAO; #endregion Using namespace FL_netCaoTester { public partial class Form3 : Form { #region Fields private CaoVariable Variable; #endregion Fields #region Constructor public Form3(string Name, CaoVariable val) { InitializeComponent(); this.Text += Name; this.Variable = val; } #endregion Constructor #region Load/Closed private void Form3_Load(object sender, EventArgs e) { } private void Form3_FormClosed(object sender, FormClosedEventArgs e) { try { // RemoveVariable if(this.Owner.ToString().IndexOf("Form4") >= 0) { ((Form4)this.Owner).Extension.Variables.Remove(this.Variable.Index); } else { ((Form1)(((Form2)this.Owner).Owner)).caoCtrl.Variables.Remove(this.Variable.Index); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion Load/Closed #region Button private void button_Name_Click(object sender, EventArgs e) { try { this.textBox_Name.Text = this.Variable.Name; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void buttonValue_Put_Click(object sender, EventArgs e) { this.button_Value_Put.Enabled = false; try { string[] ValArray = this.textBox_Value_Put.Text.Split(','); if (!this.checkBox_Array.Checked && (ValArray.Length > 1)) { throw new System.ArgumentException("Arrayチェックなし複数要素指定"); } this.PutValue(ValArray, this.checkBox_Array.Checked); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.button_Value_Put.Enabled = true; } private void button_Value_Get_Click(object sender, EventArgs e) { this.button_Value_Get.Enabled = false; try { this.textBox_Value_Get.Text = ""; object Value = this.Variable.Value; bool bChecked = this.checkBox_Array.Checked; int iSelectedIndex = this.comboBox_Type.SelectedIndex; Common cm = new Common(); this.textBox_Value_Get.Text = cm.ConvertVariantToString(Value, ref bChecked, ref iSelectedIndex); this.checkBox_Array.Checked = bChecked; this.comboBox_Type.SelectedIndex = iSelectedIndex; } catch (Exception ex) { MessageBox.Show(ex.Message); } this.button_Value_Get.Enabled = true; } private void button_Attribute_Click(object sender, EventArgs e) { try { this.textBox_Attribute.Text = this.Variable.Attribute.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button_Help_Click(object sender, EventArgs e) { try { this.textBox_Help.Text = this.Variable.Help; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button_DateTime_Click(object sender, EventArgs e) { try { DateTime dt = (DateTime)this.Variable.DateTime; this.textBox_DateTime.Text = dt.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button_MicroSec_Click(object sender, EventArgs e) { try { this.textBoxMicroSec.Text = this.Variable.Microsecond.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button_Tag_Put_Click(object sender, EventArgs e) { try { // TODO: dynamic型への変換 //this.Variable.Tag } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button_Tag_Get_Click(object sender, EventArgs e) { try { // TODO: dynamic型からの変換 //this.Variable.Tag } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button_ID_Put_Click(object sender, EventArgs e) { try { this.Variable.ID = int.Parse(this.textBox_ID_Put.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button_ID_Get_Click(object sender, EventArgs e) { try { int id = (int)this.Variable.ID; this.textBox_ID_Get.Text = id.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion Button #region PutValue private void PutValue(string[] ValArray, bool bArryEnabled) { switch (this.comboBox_Type.SelectedIndex) { case 0: // VT_BOOL { //if (ValArray.Length > 1) if (bArryEnabled) { Boolean[] Array = new Boolean[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = Boolean.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = Boolean.Parse(str); } } break; case 1: // VT_I1 { //if (ValArray.Length > 1) if (bArryEnabled) { SByte[] Array = new SByte[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = SByte.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = SByte.Parse(str); } } break; case 2: // VT_I2 { //if (ValArray.Length > 1) if (bArryEnabled) { Int16[] Array = new Int16[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = Int16.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = Int16.Parse(str); } } break; case 3: // VT_I4 { //if (ValArray.Length > 1) if (bArryEnabled) { Int32[] Array = new Int32[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = Int32.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = Int32.Parse(str); } } break; case 4: // VT_I8 { //if (ValArray.Length > 1) if (bArryEnabled) { Int64[] Array = new Int64[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = Int64.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = Int64.Parse(str); } } break; case 5: // VT_UI1 { //if (ValArray.Length > 1) if (bArryEnabled) { Byte[] Array = new Byte[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = Byte.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = Byte.Parse(str); } } break; case 6: // VT_UI2 { //if (ValArray.Length > 1) if (bArryEnabled) { UInt16[] Array = new UInt16[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = UInt16.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = UInt16.Parse(str); } } break; case 7: // VT_UI4 { //if (ValArray.Length > 1) if (bArryEnabled) { UInt32[] Array = new UInt32[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = UInt32.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = UInt32.Parse(str); } } break; case 8: // VT_UI8 { //if (ValArray.Length > 1) if (bArryEnabled) { UInt64[] Array = new UInt64[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = UInt64.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = UInt64.Parse(str); } } break; case 9: // VT_R4 { //if (ValArray.Length > 1) if (bArryEnabled) { Single[] Array = new Single[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = Single.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = Single.Parse(str); } } break; case 10: // VT_R8 { //if (ValArray.Length > 1) if (bArryEnabled) { Double[] Array = new Double[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = Double.Parse(str); } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = Double.Parse(str); } } break; case 11: // VT_BSTR { //if (ValArray.Length > 1) if (bArryEnabled) { string[] Array = new string[ValArray.Length]; for (int i = 0; i < ValArray.Length; i++) { string str = ValArray[i]; str = str.TrimStart(); str = str.TrimEnd(); Array[i] = str; } this.Variable.Value = Array; } else { string str = ValArray[0]; str = str.TrimStart(); str = str.TrimEnd(); this.Variable.Value = str; } } break; case 12: // TODO: VT_VARIANT対応(object配列にして渡す) throw new System.ArgumentException("VT_VARIANT型は未対応"); default: throw new System.ArgumentException("未対応型"); } } #endregion PutValue } }