Exemple #1
0
        private void Button15_Click(object sender, EventArgs e)
        {
            //remove card
            //MessageBox.Show("Button15_Click");
            int selectCount = 0;

            foreach (ListViewItem item in listView3.SelectedItems)
            {
                selectCount++;
                listView3.Items.Remove(item);
            }
            if (selectCount == 0)
            {
                MessageBox.Show("Select the object to remove");
            }
            else
            {
                if (device is WarningDevice && deviceCom is WarningDeviceCom)
                {
                    WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom;
                    clickEventNum = CLICKEVENTNUM.REMOVEWARNCARD;
                    warningDeviceCom.sendSetWarningCardsCom(getListViewItemsToCardID(listView3));
                }
            }
        }
Exemple #2
0
        private void receivedData48(object data)
        {
            if (clickEventNum == CLICKEVENTNUM.GETWARNCARD || clickEventNum == CLICKEVENTNUM.ADDWARNCARD || clickEventNum == CLICKEVENTNUM.LISTVIEWITEMWARNCLICK || clickEventNum == CLICKEVENTNUM.SEARCHWARNID)
            {
                listView3.Items.Clear();
                if (data is List <Differentiable> )
                {
                    List <Differentiable> warnCardDevices = data as List <Differentiable>;
                    foreach (Differentiable warnCardDevice in warnCardDevices)
                    {
                        if (warnCardDevice is CardDevice)
                        {
                            ListViewItem listViewItem = new ListViewItem();
                            listViewItem.Text      = getID(warnCardDevice.getId());
                            listViewItem.BackColor = Color.DeepSkyBlue;
                            listView3.Items.Add(listViewItem);
                        }
                    }
                }
                if (clickEventNum == CLICKEVENTNUM.ADDWARNCARD)
                {
                    byte[] idBytes = getID(textBox5.Text, 3);
                    bool   isExist = false;
                    if (data is List <Differentiable> )
                    {
                        List <Differentiable> warnCardDevices = data as List <Differentiable>;
                        foreach (Differentiable warnCardDevice in warnCardDevices)
                        {
                            if (warnCardDevice is CardDevice)
                            {
                                byte[] warnCardDeviceID = warnCardDevice.getId();
                                bool[] isExistBytes     = new bool[idBytes.Length];
                                bool   isOk             = true;
                                for (int i = 0; i < idBytes.Length; i++)
                                {
                                    if (idBytes[i] == warnCardDeviceID[i])
                                    {
                                        isExistBytes[i] = true;
                                    }
                                    else
                                    {
                                        isOk            = false;
                                        isExistBytes[i] = false;
                                    }
                                }
                                if (isOk)
                                {
                                    isExist = true;
                                }
                                //foreach(bool isExistByte in isExistBytes)
                                //{
                                //    if (!isExistByte)
                                //    {

                                //    }
                                //}
                            }
                        }
                    }
                    if (isExist)
                    {
                    }
                    else
                    {
                        byte[]       setCardBytes    = new byte[300];
                        ListViewItem addListViewItem = new ListViewItem();
                        addListViewItem.Text      = getID(getID(textBox5.Text, 3));
                        addListViewItem.BackColor = Color.DeepSkyBlue;
                        listView3.Items.Add(addListViewItem);
                        for (int i = 0; i < listView3.Items.Count; i++)
                        {
                            string cardIDStr   = listView3.Items[i].Text;
                            byte[] cardIDBytes = getID(cardIDStr, 3);
                            setCardBytes[i * 3]     = cardIDBytes[0];
                            setCardBytes[i * 3 + 1] = cardIDBytes[1];
                            setCardBytes[i * 3 + 2] = cardIDBytes[2];
                        }
                        WarningDeviceCom warningDeviceCom = deviceCom as WarningDeviceCom;
                        warningDeviceCom.sendSetWarningCardsCom(setCardBytes);
                    }
                }
                else
                {
                    showResult();
                }
            }
        }