﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Setting
{
	/// <summary>
	/// Summary description for LogicSet.
	/// </summary>
	public class LogicSet : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Button btnReturn;
		private System.Windows.Forms.CheckBox chkOut3;
		private System.Windows.Forms.CheckBox chkOut2;
		private System.Windows.Forms.CheckBox chkOut1;
		private System.Windows.Forms.CheckBox chkLim;
		private System.Windows.Forms.CheckBox chkIn7;
		private System.Windows.Forms.CheckBox chkIn6;
		private System.Windows.Forms.CheckBox chkIn5;
		private System.Windows.Forms.CheckBox chkIn4;
		private System.Windows.Forms.CheckBox chkIn3;
		private System.Windows.Forms.CheckBox chkIn2;
		private System.Windows.Forms.CheckBox chkIn1;
		private System.Windows.Forms.Label lblOut1;
		private System.Windows.Forms.Label lblOut2;
		private System.Windows.Forms.Label lblOut3;
		private System.Windows.Forms.Label lblLim;
		private System.Windows.Forms.Label lblIn1;
		private System.Windows.Forms.Label lblIn2;
		private System.Windows.Forms.Label lblIn3;
		private System.Windows.Forms.Label lblIn4;
		private System.Windows.Forms.Label lblIn5;
		private System.Windows.Forms.Label lblIn6;
		private System.Windows.Forms.Label lblIn7;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public LogicSet()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.lblOut3 = new System.Windows.Forms.Label();
			this.lblOut2 = new System.Windows.Forms.Label();
			this.lblOut1 = new System.Windows.Forms.Label();
			this.chkOut3 = new System.Windows.Forms.CheckBox();
			this.chkOut2 = new System.Windows.Forms.CheckBox();
			this.chkOut1 = new System.Windows.Forms.CheckBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.lblLim = new System.Windows.Forms.Label();
			this.chkLim = new System.Windows.Forms.CheckBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.lblIn7 = new System.Windows.Forms.Label();
			this.lblIn6 = new System.Windows.Forms.Label();
			this.lblIn5 = new System.Windows.Forms.Label();
			this.lblIn4 = new System.Windows.Forms.Label();
			this.lblIn3 = new System.Windows.Forms.Label();
			this.lblIn2 = new System.Windows.Forms.Label();
			this.lblIn1 = new System.Windows.Forms.Label();
			this.chkIn7 = new System.Windows.Forms.CheckBox();
			this.chkIn6 = new System.Windows.Forms.CheckBox();
			this.chkIn5 = new System.Windows.Forms.CheckBox();
			this.chkIn4 = new System.Windows.Forms.CheckBox();
			this.chkIn3 = new System.Windows.Forms.CheckBox();
			this.chkIn2 = new System.Windows.Forms.CheckBox();
			this.chkIn1 = new System.Windows.Forms.CheckBox();
			this.btnReturn = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.lblOut3,
																					this.lblOut2,
																					this.lblOut1,
																					this.chkOut3,
																					this.chkOut2,
																					this.chkOut1});
			this.groupBox1.Location = new System.Drawing.Point(16, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(232, 160);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Out Logic";
			// 
			// lblOut3
			// 
			this.lblOut3.Location = new System.Drawing.Point(112, 114);
			this.lblOut3.Name = "lblOut3";
			this.lblOut3.Size = new System.Drawing.Size(112, 20);
			this.lblOut3.TabIndex = 10;
			this.lblOut3.Text = "High Active";
			// 
			// lblOut2
			// 
			this.lblOut2.Location = new System.Drawing.Point(112, 74);
			this.lblOut2.Name = "lblOut2";
			this.lblOut2.Size = new System.Drawing.Size(112, 20);
			this.lblOut2.TabIndex = 9;
			this.lblOut2.Text = "High Active";
			// 
			// lblOut1
			// 
			this.lblOut1.Location = new System.Drawing.Point(112, 34);
			this.lblOut1.Name = "lblOut1";
			this.lblOut1.Size = new System.Drawing.Size(112, 20);
			this.lblOut1.TabIndex = 8;
			this.lblOut1.Text = "High Active";
			// 
			// chkOut3
			// 
			this.chkOut3.Location = new System.Drawing.Point(10, 112);
			this.chkOut3.Name = "chkOut3";
			this.chkOut3.Size = new System.Drawing.Size(80, 24);
			this.chkOut3.TabIndex = 4;
			this.chkOut3.Text = "OUT 3";
			this.chkOut3.CheckedChanged += new System.EventHandler(this.chkOut3_CheckedChanged);
			// 
			// chkOut2
			// 
			this.chkOut2.Location = new System.Drawing.Point(10, 72);
			this.chkOut2.Name = "chkOut2";
			this.chkOut2.Size = new System.Drawing.Size(80, 24);
			this.chkOut2.TabIndex = 3;
			this.chkOut2.Text = "OUT 2";
			this.chkOut2.CheckedChanged += new System.EventHandler(this.chkOut2_CheckedChanged);
			// 
			// chkOut1
			// 
			this.chkOut1.Location = new System.Drawing.Point(10, 32);
			this.chkOut1.Name = "chkOut1";
			this.chkOut1.Size = new System.Drawing.Size(80, 24);
			this.chkOut1.TabIndex = 2;
			this.chkOut1.Text = "OUT 1";
			this.chkOut1.CheckedChanged += new System.EventHandler(this.chkOut1_CheckedChanged);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.lblLim,
																					this.chkLim});
			this.groupBox2.Location = new System.Drawing.Point(16, 184);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(232, 96);
			this.groupBox2.TabIndex = 3;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Limit Logic";
			// 
			// lblLim
			// 
			this.lblLim.Location = new System.Drawing.Point(112, 50);
			this.lblLim.Name = "lblLim";
			this.lblLim.Size = new System.Drawing.Size(112, 20);
			this.lblLim.TabIndex = 11;
			this.lblLim.Text = "High Active";
			// 
			// chkLim
			// 
			this.chkLim.Location = new System.Drawing.Point(10, 48);
			this.chkLim.Name = "chkLim";
			this.chkLim.Size = new System.Drawing.Size(80, 24);
			this.chkLim.TabIndex = 8;
			this.chkLim.Text = "Limit";
			this.chkLim.CheckedChanged += new System.EventHandler(this.chkLim_CheckedChanged);
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.lblIn7,
																					this.lblIn6,
																					this.lblIn5,
																					this.lblIn4,
																					this.lblIn3,
																					this.lblIn2,
																					this.lblIn1,
																					this.chkIn7,
																					this.chkIn6,
																					this.chkIn5,
																					this.chkIn4,
																					this.chkIn3,
																					this.chkIn2,
																					this.chkIn1});
			this.groupBox3.Location = new System.Drawing.Point(264, 8);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(232, 272);
			this.groupBox3.TabIndex = 4;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "In Logic";
			// 
			// lblIn7
			// 
			this.lblIn7.Location = new System.Drawing.Point(112, 232);
			this.lblIn7.Name = "lblIn7";
			this.lblIn7.Size = new System.Drawing.Size(112, 20);
			this.lblIn7.TabIndex = 30;
			this.lblIn7.Text = "High Active";
			// 
			// lblIn6
			// 
			this.lblIn6.Location = new System.Drawing.Point(112, 199);
			this.lblIn6.Name = "lblIn6";
			this.lblIn6.Size = new System.Drawing.Size(112, 20);
			this.lblIn6.TabIndex = 29;
			this.lblIn6.Text = "High Active";
			// 
			// lblIn5
			// 
			this.lblIn5.Location = new System.Drawing.Point(112, 166);
			this.lblIn5.Name = "lblIn5";
			this.lblIn5.Size = new System.Drawing.Size(112, 20);
			this.lblIn5.TabIndex = 28;
			this.lblIn5.Text = "High Active";
			// 
			// lblIn4
			// 
			this.lblIn4.Location = new System.Drawing.Point(112, 133);
			this.lblIn4.Name = "lblIn4";
			this.lblIn4.Size = new System.Drawing.Size(112, 20);
			this.lblIn4.TabIndex = 27;
			this.lblIn4.Text = "High Active";
			// 
			// lblIn3
			// 
			this.lblIn3.Location = new System.Drawing.Point(112, 100);
			this.lblIn3.Name = "lblIn3";
			this.lblIn3.Size = new System.Drawing.Size(112, 20);
			this.lblIn3.TabIndex = 26;
			this.lblIn3.Text = "High Active";
			// 
			// lblIn2
			// 
			this.lblIn2.Location = new System.Drawing.Point(112, 67);
			this.lblIn2.Name = "lblIn2";
			this.lblIn2.Size = new System.Drawing.Size(112, 20);
			this.lblIn2.TabIndex = 25;
			this.lblIn2.Text = "High Active";
			// 
			// lblIn1
			// 
			this.lblIn1.Location = new System.Drawing.Point(112, 34);
			this.lblIn1.Name = "lblIn1";
			this.lblIn1.Size = new System.Drawing.Size(112, 20);
			this.lblIn1.TabIndex = 24;
			this.lblIn1.Text = "High Active";
			// 
			// chkIn7
			// 
			this.chkIn7.Location = new System.Drawing.Point(10, 230);
			this.chkIn7.Name = "chkIn7";
			this.chkIn7.Size = new System.Drawing.Size(80, 24);
			this.chkIn7.TabIndex = 16;
			this.chkIn7.Text = "IN 7";
			this.chkIn7.CheckedChanged += new System.EventHandler(this.chkIn7_CheckedChanged);
			// 
			// chkIn6
			// 
			this.chkIn6.Location = new System.Drawing.Point(10, 197);
			this.chkIn6.Name = "chkIn6";
			this.chkIn6.Size = new System.Drawing.Size(80, 24);
			this.chkIn6.TabIndex = 15;
			this.chkIn6.Text = "IN 6";
			this.chkIn6.CheckedChanged += new System.EventHandler(this.chkIn6_CheckedChanged);
			// 
			// chkIn5
			// 
			this.chkIn5.Location = new System.Drawing.Point(10, 164);
			this.chkIn5.Name = "chkIn5";
			this.chkIn5.Size = new System.Drawing.Size(80, 24);
			this.chkIn5.TabIndex = 14;
			this.chkIn5.Text = "IN 5";
			this.chkIn5.CheckedChanged += new System.EventHandler(this.chkIn5_CheckedChanged);
			// 
			// chkIn4
			// 
			this.chkIn4.Location = new System.Drawing.Point(10, 131);
			this.chkIn4.Name = "chkIn4";
			this.chkIn4.Size = new System.Drawing.Size(80, 24);
			this.chkIn4.TabIndex = 13;
			this.chkIn4.Text = "IN 4";
			this.chkIn4.CheckedChanged += new System.EventHandler(this.chkIn4_CheckedChanged);
			// 
			// chkIn3
			// 
			this.chkIn3.Location = new System.Drawing.Point(10, 98);
			this.chkIn3.Name = "chkIn3";
			this.chkIn3.Size = new System.Drawing.Size(80, 24);
			this.chkIn3.TabIndex = 12;
			this.chkIn3.Text = "IN 3";
			this.chkIn3.CheckedChanged += new System.EventHandler(this.chkIn3_CheckedChanged);
			// 
			// chkIn2
			// 
			this.chkIn2.Location = new System.Drawing.Point(10, 65);
			this.chkIn2.Name = "chkIn2";
			this.chkIn2.Size = new System.Drawing.Size(80, 24);
			this.chkIn2.TabIndex = 11;
			this.chkIn2.Text = "IN 2";
			this.chkIn2.CheckedChanged += new System.EventHandler(this.chkIn2_CheckedChanged);
			// 
			// chkIn1
			// 
			this.chkIn1.Location = new System.Drawing.Point(10, 32);
			this.chkIn1.Name = "chkIn1";
			this.chkIn1.Size = new System.Drawing.Size(80, 24);
			this.chkIn1.TabIndex = 10;
			this.chkIn1.Text = "IN 1";
			this.chkIn1.CheckedChanged += new System.EventHandler(this.chkIn1_CheckedChanged);
			// 
			// btnReturn
			// 
			this.btnReturn.Location = new System.Drawing.Point(368, 296);
			this.btnReturn.Name = "btnReturn";
			this.btnReturn.Size = new System.Drawing.Size(128, 32);
			this.btnReturn.TabIndex = 1;
			this.btnReturn.Text = "Return";
			this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
			// 
			// LogicSet
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(512, 336);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnReturn,
																		  this.groupBox3,
																		  this.groupBox2,
																		  this.groupBox1});
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "LogicSet";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Logic Setting";
			this.Load += new System.EventHandler(this.LogicSet_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnReturn_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void ChkDisp(Label cText, int flg)
		{
			if( flg == 0 )
			{
				cText.Text = "Low Active";
			}
			else
			{
				cText.Text = "High Active";
			}
		}

		private void ChkAndDisp(CheckBox cChk, Label cText, int flg)
		{
			ChkDisp(cText, flg);
			if( flg == 0 )
			{
				cChk.Checked = true;
			}
			else
			{
				cChk.Checked = false;
			}
		}

		private void LogicSet_Load(object sender, System.EventArgs e)
		{
			ChkAndDisp(chkIn1, lblIn1, Setting.CtrlInOutLog & 0x1);
			ChkAndDisp(chkIn2, lblIn2, Setting.CtrlInOutLog & 0x2);
			ChkAndDisp(chkIn3, lblIn3, Setting.CtrlInOutLog & 0x4);
			ChkAndDisp(chkIn4, lblIn4, Setting.CtrlInOutLog & 0x8);
			ChkAndDisp(chkIn5, lblIn5, Setting.CtrlInOutLog & 0x10);
			ChkAndDisp(chkIn6, lblIn6, Setting.CtrlInOutLog & 0x20);
			ChkAndDisp(chkIn7, lblIn7, Setting.CtrlInOutLog & 0x40);
			ChkAndDisp(chkLim, lblLim, Setting.CtrlInOutLog & 0x80);
			ChkAndDisp(chkOut1, lblOut1, Setting.CtrlInOutLog & 0x100);
			ChkAndDisp(chkOut2, lblOut2, Setting.CtrlInOutLog & 0x200);
			ChkAndDisp(chkOut3, lblOut3, Setting.CtrlInOutLog & 0x400);
		}

		private void chkIn1_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x1;
			int	tmp = Setting.CtrlInOutLog;
			if( chkIn1.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit ;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblIn1, Setting.CtrlInOutLog & bit);
		}

		private void chkIn2_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x2;
			int	tmp = Setting.CtrlInOutLog;
			if( chkIn2.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit ;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblIn2, Setting.CtrlInOutLog & bit);
		}

		private void chkIn3_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x4;
			int	tmp = Setting.CtrlInOutLog;
			if( chkIn3.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit ;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblIn3, Setting.CtrlInOutLog & bit);
		}

		private void chkIn4_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x8;
			int	tmp = Setting.CtrlInOutLog;
			if( chkIn4.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit ;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblIn4, Setting.CtrlInOutLog & bit);
		}

		private void chkIn5_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x10;
			int	tmp = Setting.CtrlInOutLog;
			if( chkIn5.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit ;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblIn5, Setting.CtrlInOutLog & bit);
		}

		private void chkIn6_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x20;
			int	tmp = Setting.CtrlInOutLog;
			if( chkIn6.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit ;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblIn6, Setting.CtrlInOutLog & bit);
		}

		private void chkIn7_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x40;
			int	tmp = Setting.CtrlInOutLog;
			if( chkIn7.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblIn7, Setting.CtrlInOutLog & bit);
		}

		private void chkLim_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x80;
			int	tmp = Setting.CtrlInOutLog;
			if( chkLim.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblLim, Setting.CtrlInOutLog & bit);
		}

		private void chkOut1_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x100;
			int	tmp = Setting.CtrlInOutLog;
			if( chkOut1.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblOut1, Setting.CtrlInOutLog & bit);
		}

		private void chkOut2_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x200;
			int	tmp = Setting.CtrlInOutLog;
			if( chkOut2.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblOut2, Setting.CtrlInOutLog & bit);
		}

		private void chkOut3_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x400;
			int	tmp = Setting.CtrlInOutLog;
			if( chkOut3.Checked == true )
			{
				tmp = tmp & (~ bit );
				Setting.CtrlInOutLog = (short)tmp;
			}
			else
			{
				tmp = tmp | bit;
				Setting.CtrlInOutLog = (short)tmp;
			}
			ChkDisp(lblOut3, Setting.CtrlInOutLog & bit);
		}
	}
}
