Esempio n. 1
0
        private void addRule_Click(object sender, EventArgs e)
        {
            string ircode    = IRCode.Text;
            string keycode   = keyCode.Text;
            string lableText = lable.Text;

            if (ircode.Length == 0 || keycode.Length == 0 || lableText.Length == 0)
            {
                console.AppendText("红外、键值、标签都不能为空\r\n");
                return;
            }

            if (!Regex.IsMatch(ircode, "^[0-9a-fA-F]+$"))
            {
                console.AppendText("红外码只能是十六进制数字\r\n");
                return;
            }

            if (Int32.Parse(ircode) == 0)
            {
                console.AppendText("红外码不能是0\r\n");
                return;
            }

            if (pairs.ContainsKey(Int32.Parse(ircode)))
            {
                console.AppendText(ircode + "已经在列表中了\r\n");
                return;
            }

            RulePair rp = new RulePair();

            rp.keyCode = keycode;
            rp.lable   = lableText;

            pairs.Add(Convert.ToInt32("0x" + ircode, 16), rp);
            IRCode.Text  = "";
            keyCode.Text = "";
            lable.Text   = "";

            updateRulesList();
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            updateComList();

            FileInfo fi = new FileInfo("config.json");

            if (fi.Exists)
            {
                string fileContent = File.ReadAllText("config.json", Encoding.UTF8);

                JObject root = JsonConvert.DeserializeObject <JObject>(fileContent);

                state.Checked = (bool)root["enable"];
                var lastBaudrate = (int)root["last_baudrate"];
                var lastCom      = (string)root["last_com"];
                startMinimun.Checked = (bool)root["start_minimun"];
                startOpen.Checked    = (bool)root["start_open"];

                if (lastBaudrate != 0)
                {
                    baudrate.Text = lastBaudrate.ToString();
                }
                else
                {
                    baudrate.SelectedIndex = 2;
                }

                if (comSelect.Items.Count == 1 && lastCom.Length == 0)
                {
                    comSelect.SelectedIndex = 0;
                }
                else
                {
                    foreach (var item in CustomSerialPort.GetPortNames())
                    {
                        if (item == lastCom)
                        {
                            comSelect.Text = lastCom;
                            break;
                        }
                    }
                }

                if (startMinimun.Checked)
                {
                    Thread thread = new Thread(new ThreadStart(() =>
                    {
                        Thread.Sleep(1000);
                        Visible = false;
                    }));
                    thread.Start();
                }

                if (startOpen.Checked)
                {
                    openSerial();
                }

                JArray ja = (JArray)root["pairs"];
                foreach (var item in ja)
                {
                    RulePair rp = new RulePair();
                    rp.keyCode = (string)item["keycode"];
                    rp.lable   = (string)item["lable"];

                    pairs.Add(Int32.Parse((string)item["ircode"]), rp);
                }

                updateRulesList();

                //rulesList.Items.
            }
        }