//AutoSizeFormClass asc = new AutoSizeFormClass();
        public Form_WaitRun(MainForm f, List <int> L, int t, int b)
        {
            this.f = f;
            if (L == null)
            {
                RunLoop = false;
            }
            else
            {
                this.L = L;
            }
            this.Time_done = t;//设置的轮巡时间
            this.b         = b;
            InitializeComponent();
            languageFile = new IniFiles(Application.StartupPath + "\\LanguagePack" + f.package);
            //Init_FormString();

            if (f.Chinese_English == 1)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                ApplyResource();
            }
            else if (f.Chinese_English == 0)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
                ApplyResource();
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHT");
                ApplyResource();
            }

            label4.Text     = Time_done.ToString();
            timer1.Interval = 1000;
            timer1.Enabled  = true;
            timer1.Start();
        }
        //public static bool do_Attime = false;
        //public static bool do_Athex = true;
        //private bool connecte = false;
        //public static byte Leng = 0;
        //public static string str = "";
        //private byte[] Buf = new byte[128];
        //AutoSizeFormClass asc = new AutoSizeFormClass();
        public SerialSetForm(MainForm f)
        {
            this.f = f;
            InitializeComponent();

            languageFile = new IniFiles(Application.StartupPath + "\\LanguagePack" + f.package);

            Init_FormString();

            if (f.Chinese_English == 1)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                ApplyResource();
            }
            else if (f.Chinese_English == 0)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
                ApplyResource();
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHT");
                ApplyResource();
            }
            initSerialPort();
            if (f.Motherboard_flag == 1)
            {
                checkBox1.Checked = true;
                groupBox2.Enabled = false;
                checkBox2.Enabled = false;
            }
            else
            {
                groupBox2.Enabled = true;
                checkBox2.Enabled = true;
            }
        }
Beispiel #3
0
        //AutoSizeFormClass asc = new AutoSizeFormClass();
        public Form_Auto(MainForm f, int count)
        {
            this.f     = f;
            this.count = count;
            InitializeComponent();
            settingFile       = new IniFiles(Application.StartupPath + "\\setting.ini");
            languageFile      = new IniFiles(Application.StartupPath + "\\LanguagePack" + f.package);
            this.Text         = languageFile.ReadString("AUTOFORM", "TITLE", "预案场景");
            this.label1.Text  = languageFile.ReadString("AUTOFORM", "T_I", "间隔时间(30s~24h)");
            this.button1.Text = languageFile.ReadString("AUTOFORM", "START", "开始");
            string sl = languageFile.ReadString("AUTOFORM", "SCENES", "场景");

            if (f.Chinese_English == 1)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                ApplyResource();
            }
            else if (f.Chinese_English == 0)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
                ApplyResource();
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHT");
                ApplyResource();
            }

            foreach (Control var in this.Controls)
            {
                if (var is System.Windows.Forms.CheckBox)
                { //如果是CheckBox
                    //Console.WriteLine(var.Name);
                    var.Text = var.Name.Replace("checkBox", sl);
                    string s = var.Name;
                    //if (f.Chinese_English)
                    {
                        if (int.Parse(s.Substring(8, s.Length - 8)) > count)
                        {
                            var.Enabled = false;
                        }
                    }
                }
            }
            string str = settingFile.ReadString("SCREEN", "NUM", "");

            if (str != "")
            {
                string[] s;
                s = str.Split(new char[] { ',' });
                int k = s.Length;
                if (k > 0)
                {
                    for (int i = 0; i < k; i++)
                    {
                        //Console.WriteLine(s[i]);
                        switch (s[i])
                        {
                        case "1":
                            checkBox1.Checked = true;
                            continue;

                        case "2":
                            checkBox2.Checked = true;
                            continue;

                        case "3":
                            checkBox3.Checked = true;
                            continue;

                        case "4":
                            checkBox4.Checked = true;
                            continue;

                        case "5":
                            checkBox5.Checked = true;
                            continue;

                        case "6":
                            checkBox6.Checked = true;
                            continue;

                        case "7":
                            checkBox7.Checked = true;
                            continue;

                        case "8":
                            checkBox8.Checked = true;
                            continue;

                        case "9":
                            checkBox9.Checked = true;
                            continue;

                        case "10":
                            checkBox10.Checked = true;
                            continue;

                        case "11":
                            checkBox11.Checked = true;
                            continue;

                        case "12":
                            checkBox12.Checked = true;
                            continue;

                        default:
                            continue;
                        }
                    }
                }
            }
            textBox1.Text = settingFile.ReadString("SCREEN", "NUM_time", "30");
        }
        public Form_OnOff(MainForm f)
        {
            InitializeComponent();
            this.f                       = f;
            settingFile                  = new IniFiles(Application.StartupPath + "\\setting.ini");
            dateTimePicker1.Format       = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "yyyy-MM-dd HH:mm:ss";
            dateTimePicker2.Format       = DateTimePickerFormat.Custom;
            dateTimePicker2.CustomFormat = "yyyy-MM-dd HH:mm:ss";
            languageFile                 = new IniFiles(Application.StartupPath + "\\LanguagePack" + f.package);

            Init_FormString();

            if (f.Chinese_English == 1)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                ApplyResource();
            }
            else if (f.Chinese_English == 0)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
                ApplyResource();
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHT");
                ApplyResource();
            }

            if (f.Delay_on)
            {
                checkBox1.Checked = true;
            }
            else
            {
                checkBox1.Checked = false;
            }
            if (f.Delay_off)
            {
                checkBox2.Checked = true;
            }
            else
            {
                checkBox2.Checked = false;
            }
            if (f.Timing_on)
            {
                checkBox3.Checked     = true;
                dateTimePicker1.Value = f.on;
            }
            else
            {
                checkBox3.Checked = false;
            }
            if (f.Timing_off)
            {
                checkBox4.Checked     = true;
                dateTimePicker2.Value = f.off;
            }
            else
            {
                checkBox4.Checked = false;
            }
            //if (f.Delay_on || f.Delay_off)
            comboBox1.SelectedIndex = f.Delay_time1 / 100 - 1;

            string s = settingFile.ReadString("SETTING", "On_time", DateTime.Now.ToString());

            dateTimePicker1.Value = DateTime.Parse(s);
            s = settingFile.ReadString("SETTING", "Off_time", DateTime.Now.ToString());
            dateTimePicker2.Value = DateTime.Parse(s);
        }
        /// <summary>
        /// 确认串口设置信息,并保存至文件中。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_confirm_Click(object sender, EventArgs e)
        {
            if (f.TCPCOM)
            {
                if (textBox_IP.Text == "" || textBox_Port.Text == "")
                {
                    string ts = languageFile.ReadString("ONOFFFORM", "T4", "设置的IP地址和端口不能为空!");
                    string tp = languageFile.ReadString("MESSAGEBOX", "TP", "提示");
                    MessageBox.Show(ts, tp);
                    return;
                }
                if (checkBox3.Checked)
                {
                    f.PJLink_Pro = true;
                }
                else
                {
                    f.PJLink_Pro = false;
                }
                if (IsIP(textBox_IP.Text))
                {
                    if (combo_netpro.SelectedIndex == 0)
                    {
                        f.TCPServer = new IOCPServer(IPAddress.Parse(textBox_IP.Text), int.Parse(textBox_Port.Text), (int)numericUpDown1.Value);
                    }
                    else if (combo_netpro.SelectedIndex == 1)
                    {
                        f.TCPClient = new client(IPAddress.Parse(textBox_IP.Text), int.Parse(textBox_Port.Text));
                    }
                    else
                    {
                        f.UDPClient = new System.Net.Sockets.UdpClient();
                    }
                    f.IP   = IPAddress.Parse(textBox_IP.Text);
                    f.PORT = int.Parse(textBox_Port.Text);
                }
                else
                {
                    string ts = languageFile.ReadString("ONOFFFORM", "T5", "IP 地址信息不正确!");
                    string tp = languageFile.ReadString("MESSAGEBOX", "TP", "提示");
                    MessageBox.Show(ts, tp);
                }
            }
            else
            {
                if (cb_port1.Text.Equals("") || cb_baudRate1.Text.Equals(""))
                {
                    string ts = languageFile.ReadString("ONOFFFORM", "T1", "串口1设置不能为空!");
                    string tp = languageFile.ReadString("MESSAGEBOX", "TP", "提示");
                    MessageBox.Show(ts, tp);
                    return;
                }
                //串口设置和打开
                String portName;
                int    baudrate;
                if (cb_multiCom.SelectedIndex == 0)//选的dan串口
                {
                    portName        = cb_port1.Text;
                    baudrate        = int.Parse(cb_baudRate1.Text);
                    f.PortName      = portName;
                    f.BaudRate      = baudrate;
                    f.uMultiComPort = 1;
                }
                else
                {//选的串口2
                    if (cb_port2.Text.Equals("") || cb_baudRate2.Text.Equals(""))
                    {
                        string ts = languageFile.ReadString("ONOFFFORM", "T2", "串口2设置不能为空!");
                        string tp = languageFile.ReadString("MESSAGEBOX", "TP", "提示");
                        MessageBox.Show(ts, tp);
                        return;
                    }
                    portName = cb_port1.Text;
                    baudrate = int.Parse(cb_baudRate1.Text);
                    if (cb_port1.Text == cb_port2.Text)
                    {
                        string ts = languageFile.ReadString("ONOFFFORM", "T3", "两个串口设置不能为同一个串口号!");
                        string tp = languageFile.ReadString("MESSAGEBOX", "TP", "提示");
                        MessageBox.Show(ts, tp);
                        return;
                    }
                    f.PortName      = portName;
                    f.BaudRate      = baudrate;
                    portName        = cb_port2.Text;
                    baudrate        = int.Parse(cb_baudRate2.Text);
                    f.PortName2     = portName;
                    f.BaudRate2     = baudrate;
                    f.uMultiComPort = 2;
                }
                f.Init_port();
            }
            //SerialPortUtil.setSerialPort(portName, baudrate);
            //SerialPortUtil.openSerialPort();

            //保存配置至ini文件
            settingFile = new IniFiles(Application.StartupPath + "\\setting.ini");
            settingFile.WriteString("Com Set", "port1", cb_port1.Text);
            //Console.WriteLine(cb_port1.Text);
            settingFile.WriteString("Com Set", "baudrate1", cb_baudRate1.Text);
            settingFile.WriteString("Com Set", "port2", cb_port2.Text);
            settingFile.WriteString("Com Set", "baudrate2", cb_baudRate2.Text);
            settingFile.WriteString("Com Set", "timeout", cb_timeout.Text);
            settingFile.WriteInteger("Com Set", "MultiCom", cb_multiCom.SelectedIndex + 1);

            settingFile.WriteString("Com Set", "IP", textBox_IP.Text);
            settingFile.WriteString("Com Set", "Port", textBox_Port.Text);
            settingFile.WriteBool("Com Set", "TCPCOM", f.TCPCOM);
            settingFile.WriteBool("Com Set", "PJLink", checkBox3.Checked);
            settingFile.WriteInteger("Com Set", "TCPP", combo_netpro.SelectedIndex);
            settingFile.WriteInteger("Com Set", "Con", (int)numericUpDown1.Value);
            this.Close();
        }
        /// <summary>
        /// 初始化串口
        /// </summary>
        public void initSerialPort()
        {
            settingFile = new IniFiles(Application.StartupPath + "\\setting.ini");
            String readPort1 = settingFile.ReadString("Com Set", "port1", "COM1"); //串口1
            String readPort2 = settingFile.ReadString("Com Set", "port2", "COM1"); //串口2

            String[] serialPorts = System.IO.Ports.SerialPort.GetPortNames();
            cb_port1.Items.Clear();
            cb_port2.Items.Clear();
            for (int i = 0; i < serialPorts.Length; i++) //找出所有串口,并选择文件中的
            {
                cb_port1.Items.Add(serialPorts[i]);      //初始化串口1
                if (readPort1.Equals(serialPorts[i]))
                {
                    cb_port1.SelectedIndex = i;
                }
                cb_port2.Items.Add(serialPorts[i]);//初始化串口2
                if (readPort2.Equals(serialPorts[i]))
                {
                    cb_port2.SelectedIndex = i;
                }

                //Console.WriteLine(serialPorts[i]);
            }
            if (cb_port1.Items.Count > 0 && cb_port1.SelectedIndex < 0)//如果文件读出来的串口名没有,则默认第一个。
            {
                cb_port1.SelectedIndex = 0;
            }
            if (cb_port2.Items.Count > 0 && cb_port2.SelectedIndex < 0)//如果文件读出来的串口名没有,则默认第一个。串口2
            {
                cb_port2.SelectedIndex = 0;
            }

            cb_baudRate1.Text = settingFile.ReadString("Com Set", "baudrate1", "9600");        //串口1
            cb_baudRate2.Text = settingFile.ReadString("Com Set", "baudrate2", "9600");        //串口1
            cb_timeout.Text   = settingFile.ReadString("Com Set", "timeout", "10");            //延时

            cb_multiCom.SelectedIndex = settingFile.ReadInteger("Com Set", "MultiCom", 1) - 1; //多串口选择
            if (cb_serialSelect.Items.Count > 0)
            {
                cb_serialSelect.SelectedIndex = 0;//串口选择,默认为串口1
            }
            combo_netpro.SelectedIndex = settingFile.ReadInteger("Com Set", "TCPP", 0);
            textBox_IP.Text            = settingFile.ReadString("Com Set", "IP", "127.0.01");
            textBox_Port.Text          = settingFile.ReadString("Com Set", "Port", "8234");
            numericUpDown1.Value       = (decimal)settingFile.ReadInteger("Com Set", "Con", 16);
            if (f.TCPCOM)
            {
                checkBox2.Checked = true;
                groupBox1.Enabled = false;
                groupBox2.Enabled = true;
            }
            else
            {
                checkBox1.Checked = true;
                groupBox1.Enabled = true;
                groupBox2.Enabled = false;
            }
            if (f.PJLink_Pro)
            {
                checkBox3.Checked = true;
            }
            else
            {
                checkBox3.Checked = false;
            }
        }
        public Form_Log(MainForm f)
        {
            InitializeComponent();
            this.f      = f;
            settingFile = new IniFiles(Application.StartupPath + "\\setting.ini");
            //comboBox1.SelectedIndex = 0;

            languageFile      = new IniFiles(Application.StartupPath + "\\LanguagePack" + f.package);
            this.Text         = languageFile.ReadString("LOGFORM", "TITLE", "权限登录");
            this.label1.Text  = languageFile.ReadString("LOGFORM", "USER", "用户名:");
            this.label2.Text  = languageFile.ReadString("LOGFORM", "PASSWORD", "密码:");
            this.label3.Text  = languageFile.ReadString("LOGFORM", "PPERMISION", "用户权限:");
            this.button1.Text = languageFile.ReadString("LOGFORM", "LOG", "登录");
            this.button2.Text = languageFile.ReadString("LOGFORM", "CLOSE", "关闭");
            this.button3.Text = languageFile.ReadString("LOGFORM", "EXIT", "退出");
            this.button4.Text = languageFile.ReadString("LOGFORM", "CHANGE", "密码修改");
            string sg = languageFile.ReadString("LOGFORM", "USER1", "普通用户");
            string sa = languageFile.ReadString("LOGFORM", "USER2", "管理员用户");

            comboBox1.Items.Clear();
            comboBox1.Items.Add(sg);
            comboBox1.Items.Add(sa);

            string s1 = settingFile.ReadString("SETTING", "Pwd", "0");

            //Console.WriteLine(s1);
            if (s1 == "0")
            {
                button4.Visible         = false;
                button3.Visible         = false;
                button1.Visible         = true;
                button2.Visible         = true;
                comboBox1.SelectedIndex = 0;
            }
            else if (s1 == "1")
            {
                button1.Visible         = false;
                button2.Visible         = false;
                button4.Visible         = true;
                button3.Visible         = true;
                comboBox1.SelectedIndex = 1;
                comboBox1.Enabled       = false;
            }
            else
            {
                button4.Visible         = false;
                button3.Visible         = false;
                button1.Visible         = true;
                button2.Visible         = true;
                comboBox1.SelectedIndex = 0;
            }


            if (f.Chinese_English == 1)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                ApplyResource();
            }
            else if (f.Chinese_English == 0)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
                ApplyResource();
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHT");
                ApplyResource();
            }
        }
Beispiel #8
0
        //private IniFiles settingFile;
        //AutoSizeFormClass asc = new AutoSizeFormClass();
        public Form_Info(MainForm f)
        {
            this.f = f;
            InitializeComponent();

            languageFile        = new IniFiles(Application.StartupPath + "\\LanguagePack" + f.package);
            this.Text           = languageFile.ReadString("INFOFORM", "TITLE", "版本信息");
            this.groupBox1.Text = languageFile.ReadString("INFOFORM", "INFO", "信息");
            this.label2.Text    = languageFile.ReadString("INFOFORM", "SV", "版本信息");
            this.label3.Text    = languageFile.ReadString("INFOFORM", "AWH", "系统运行总时间:");
            this.button2.Text   = languageFile.ReadString("INFOFORM", "UD", "更新显示");
            this.button1.Text   = languageFile.ReadString("INFOFORM", "SD", "屏幕显示");


            if (f.Chinese_English == 1)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                ApplyResource();
            }
            else if (f.Chinese_English == 0)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
                ApplyResource();
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHT");
                ApplyResource();
            }
            //serialPort1.PortName = f.PortName;
            //serialPort1.BaudRate = f.BaudRate;
            //settingFile = new IniFiles(Application.StartupPath + "\\setting.ini");
            //Console.WriteLine(serialPort1.PortName + "," + serialPort1.BaudRate);

            /*
             * try
             * {
             *  serialPort1.Open();
             * }
             * catch
             * {
             *  serialPort1.Close();
             *  if (f.Chinese_English)
             *  {
             *      MessageBox.Show("   Serial open error。");
             *      return;
             *  }
             *  else
             *  {
             *      MessageBox.Show("   串口打开出错。");
             *      return;
             *  }
             * }
             * if (f.Chinese_English)
             * {
             *  System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
             *  ApplyResource();
             * }
             * else
             * {
             *  System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
             *  ApplyResource();
             * }
             * int s1 = settingFile.ReadInteger("SETTING", "Time_hour", 0);
             * int s2 = settingFile.ReadInteger("SETTING", "Time_minute", 0);
             * if (f.Chinese_English)
             * {
             *  if (s1 > 0)
             *      label4.Text = s1 + "/hour " + s2 + "/minute";
             *  else
             *      label4.Text = s2+ "/minute ";
             * }
             * else
             * {
             *  if (s1 > 0)
             *      label4.Text = s1 + "/小时 " + s2 + "/分钟";
             *  else
             *      label4.Text = s2 + "/分钟 ";
             * }
             * */
            //Init();
            //Thread.Sleep(200);
        }