Пример #1
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string showname = "";

            memoryData.contact.Clear();

            if (listBox1.SelectedItem != null)
            {
                contactList.Text = "";
                ContactGroup2 tar = (ContactGroup2)memoryData.GroupContact2[0];
                //Contactstruct

                for (int i = 0; i < listBox1.SelectedItems.Count; i++)
                {
                    for (int j = 0; j < tar.groupmember.Count; j++)
                    {
                        Contactstruct add = (Contactstruct)tar.groupmember[j];
                        if (listBox1.SelectedItems[i].ToString() == add.name)
                        {
                            showname = showname + listBox1.SelectedItems[i].ToString() + ";";
                            memoryData.contact.Add(add);
                        }
                    }
                }
            }

            contactList.Text = showname;
        }
        private void delContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (contactlist.SelectedItem != null)
            {
                if (grouplist.SelectedItem.ToString() == "all contact")
                {
                    //remove from group
                    for (int i = 0; i < memoryData.GroupContact2.Count; i++)
                    {
                        ContactGroup2 tar = (ContactGroup2)memoryData.GroupContact2[i];

                        for (int a = 0; a < tar.groupmember.Count; a++)
                        {
                            Contactstruct edit = (Contactstruct)tar.groupmember[a];
                            if (edit.name != contactlist.SelectedItem.ToString())
                            {
                                tar.groupmember.Remove(edit);
                                memoryData.GroupContact2[i] = tar;
                            }
                        }
                    }

                    //remove from contact data
                    for (int i = 0; i < memoryData.contact.Count; i++)
                    {
                        Contactstruct tar = (Contactstruct)memoryData.contact[i];
                        if (tar.name == contactlist.SelectedItem.ToString())
                        {
                            memoryData.contact.Remove(tar);
                        }
                    }

                    contactlist.Items.RemoveAt(contactlist.SelectedIndex);
                }
                else
                {
                    for (int i = 1; i < memoryData.GroupContact2.Count; i++)
                    {
                        ContactGroup2 tarGroup = (ContactGroup2)memoryData.GroupContact2[i];
                        if (tarGroup.groupname == grouplist.SelectedItem.ToString())
                        {
                            if (tarGroup.groupmember != null)
                            {
                                for (int a = 0; a < tarGroup.groupmember.Count; a++)
                                {
                                    Contactstruct deltar = (Contactstruct)tarGroup.groupmember[a];
                                    if (deltar.name == contactlist.SelectedItem.ToString())
                                    {
                                        tarGroup.groupmember.Remove(deltar);
                                        memoryData.GroupContact2[i] = tarGroup;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        private void CMDApply_Click(object sender, EventArgs e)
        {
            option_contact lForm1 = (option_contact)this.Owner;//把Form2的父窗口指針賦給lForm1

            lForm1.ReGroup = groupTextbox.Text;

            if (CMD == "edit")
            {
                for (int i = 0; i < memoryData.GroupContact2.Count; i++)
                {
                    ContactGroup2 edit = (ContactGroup2)memoryData.GroupContact2[i];
                    if (edit.groupname == groupName)
                    {
                        edit.groupname = groupTextbox.Text;
                        edit.groupmember.Clear();

                        for (int cc = 0; cc < memoryData.contact.Count; cc++)
                        {
                            Contactstruct add = (Contactstruct)memoryData.contact[cc];
                            edit.groupmember.Add(add);
                        }

                        memoryData.GroupContact2[i] = edit;

                        break;
                    }
                }
            }
            else if (CMD == "add")
            {
                ContactGroup2 addGroup = new ContactGroup2();
                addGroup.groupname   = groupTextbox.Text;
                addGroup.groupmember = new ArrayList();

                for (int cc = 0; cc < memoryData.contact.Count; cc++)
                {
                    Contactstruct add = (Contactstruct)memoryData.contact[cc];
                    addGroup.groupmember.Add(add);
                }

                memoryData.GroupContact2.Add(addGroup);
            }


            lForm1.ReGroup = groupTextbox.Text;

            this.Close();
        }
 private void delGroupToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (grouplist.SelectedItem.ToString() != "all contact")  // "all contact" is default item
     {
         for (int i = 1; i < memoryData.GroupContact2.Count; i++)
         {
             ContactGroup2 deltar = (ContactGroup2)memoryData.GroupContact2[i];
             if (deltar.groupname == grouplist.SelectedItem.ToString())
             {
                 memoryData.GroupContact2.Remove(deltar);
                 grouplist.Items.RemoveAt(grouplist.SelectedIndex);
                 break;
             }
         }
     }
 }
Пример #5
0
        private void option_add_group_Load(object sender, EventArgs e)
        {
            groupTextbox.Text = groupName;
            //load all contact info
            ContactGroup2 gtar = (ContactGroup2)memoryData.GroupContact2[0];

            if (gtar.groupmember != null)
            {
                for (int i = 0; i < gtar.groupmember.Count; i++)
                {
                    Contactstruct tar = (Contactstruct)gtar.groupmember[i];
                    loadContact.Add(tar);
                    listBox1.Items.Add(tar.name);
                }
            }

            if (listBox1.Items.Count != 0)
            {
                if (CMD == "add")
                {
                    groupTextbox.ReadOnly = false;
                }
                else if (CMD == "edit")
                {
                    //groupTextbox.ReadOnly = true;

                    for (int i = 0; i < memoryData.GroupContact2.Count; i++)
                    {
                        ContactGroup2 tar = (ContactGroup2)memoryData.GroupContact2[i];
                        if (tar.groupname == groupName)
                        {
                            for (int cc = 0; cc < tar.groupmember.Count; cc++)
                            {
                                Contactstruct add   = (Contactstruct)tar.groupmember[cc];
                                int           index = listBox1.FindString(add.name);
                                if (index != -1)
                                {
                                    listBox1.SetSelected(index, true);
                                }
                            }

                            break;
                        }
                    }
                }
            }
        }
        private void editContact_Click(object sender, EventArgs e)
        {
            if (contactlist.SelectedItem != null)
            {
                option_add_contact lForm = new option_add_contact();
                lForm.Owner   = this;//重要的一步,主要是使Form2的Owner指針指向Form1
                lForm.CMD     = "edit";
                lForm.contact = contactlist.SelectedItem.ToString();
                lForm.ShowDialog();

                if (reContact != null)
                {
                    for (int i = 0; i < memoryData.contact.Count; i++)
                    {
                        Contactstruct tar = (Contactstruct)memoryData.contact[i];
                        if (tar.name == reContact)
                        {
                            contactName.Text         = tar.name;
                            contactMail.Text         = tar.mail;
                            contactPhone.Text        = tar.phone;
                            contactDescription.Text  = tar.description;
                            contactlist.SelectedItem = reContact;
                        }
                    }


                    ContactGroup2 gptar = (ContactGroup2)memoryData.GroupContact2[0];
                    for (int cc = 0; cc < gptar.groupmember.Count; cc++)
                    {
                        Contactstruct edit = (Contactstruct)gptar.groupmember[cc];
                        if (edit.name == reContact)
                        {
                            edit.name             = contactName.Text;
                            edit.mail             = contactMail.Text;
                            edit.phone            = contactPhone.Text;
                            edit.description      = contactDescription.Text;
                            gptar.groupmember[cc] = edit;
                            break;
                        }
                    }

                    reContact = null;
                }
            }
        }
        private void grouplist_SelectedIndexChanged(object sender, EventArgs e)
        {
            contactName.Text        = "";
            contactMail.Text        = "";
            contactPhone.Text       = "";
            contactDescription.Text = "";

            if (grouplist.SelectedItem != null)
            {
                for (int i = 0; i < memoryData.GroupContact2.Count; i++)
                {
                    ContactGroup2 tar = (ContactGroup2)memoryData.GroupContact2[i];
                    if (tar.groupname == grouplist.SelectedItem.ToString())
                    {
                        contactlist.Items.Clear();
                        if (tar.groupmember != null)
                        {
                            for (int a = 0; a < tar.groupmember.Count; a++)
                            {
                                Contactstruct edit = (Contactstruct)tar.groupmember[a];
                                if (edit.name != null)
                                {
                                    contactlist.Items.Add(edit.name);
                                }
                            }
                        }
                    }
                }
            }

            if (grouplist.SelectedItem != null)
            {
                if (grouplist.SelectedItem.ToString() == "all contact")
                {
                    addContact.Enabled  = true;
                    editContact.Enabled = true;
                }
                else
                {
                    addContact.Enabled  = false;
                    editContact.Enabled = false;
                }
            }
        }
        private void Savegroup()
        {
            string  curFile  = Application.StartupPath + @"\Resources\mailGroup.txt";
            Boolean findfile = File.Exists(curFile);

            if (findfile == true)
            {
                System.IO.File.Delete(Application.StartupPath + @"\Resources\mailGroup.txt");
            }


            StringBuilder buffer = new StringBuilder();
            string        mem    = "";

            if (memoryData.GroupContact2.Count > 0)
            {
                for (int i = 0; i < memoryData.GroupContact2.Count; i++)
                {
                    ContactGroup2 tar = (ContactGroup2)memoryData.GroupContact2[i];
                    buffer.Append("#" + tar.groupname);

                    if (tar.groupmember != null)
                    {
                        for (int a = 0; a < tar.groupmember.Count; a++)
                        {
                            Contactstruct member = (Contactstruct)tar.groupmember[a];

                            if (member.name != null && member.name != "" && member.mail != null && member.mail != "")
                            {
                                mem = member.name + "$" + member.mail + "$" + member.phone + "$" + member.description;
                                buffer.Append("#" + mem);
                            }
                        }
                    }


                    buffer.Append(Environment.NewLine);
                }
            }
            File.WriteAllText(Application.StartupPath + @"\Resources\mailGroup.txt", buffer.ToString());
        }
Пример #9
0
        private void config_OutputObjectText_Load(object sender, EventArgs e)
        {
            for (int site = 0; site < deviceList.Nodes.Count; site++)
            {
                for (int fab = 0; fab < deviceList.Nodes[site].Nodes.Count; fab++)
                {
                    for (int area = 0; area < deviceList.Nodes[site].Nodes[fab].Nodes.Count; area++)
                    {
                        for (int device = 0; device < deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes.Count; device++)
                        {
                            if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Tag.ToString() == "lon")
                            {
                                for (int obj = 0; obj < deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes.Count; obj++)
                                {
                                    for (int nv = deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes.Count - 1; nv >= 0; nv--)
                                    {
                                        //string[] chk = deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Text.Split('#');
                                        //string snvt = chk[0].Substring(0, 3);

                                        //if (snvt == "UCP" || snvt == "pro" || snvt == "nci" || snvt == "nvo")
                                        //{
                                        //    deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Remove();
                                        //}
                                        if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Tag.ToString() != NVType2)
                                        {
                                            deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Remove();
                                        }
                                        else if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Tag.ToString() == NVType2)
                                        {
                                            if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Text != "VirtFb")
                                            {
                                                string snvt = deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Text.Substring(0, 3);
                                                if (snvt != "nvi")
                                                {
                                                    deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Remove();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            deviceList.CollapseAll();
            for (int i = 0; i < memoryData.OutputTextData.Count; i++)
            {
                OutputTextObjectstruct lt = (OutputTextObjectstruct)memoryData.OutputTextData[i];
                if (lt.name == textboxName)
                {
                    if (lt.target != "")
                    {
                        string[] index = lt.targetindex.Split('_');
                        deviceList.SelectedNode = deviceList.Nodes[int.Parse(index[0])].Nodes[int.Parse(index[1])].Nodes[int.Parse(index[2])].Nodes[int.Parse(index[3])].Nodes[int.Parse(index[4])].Nodes[int.Parse(index[5])];
                        deviceList.Select();
                    }
                    else
                    {
                        deviceList.SelectedNode = deviceList.Nodes[0].Nodes[0].Nodes[0];
                        deviceList.Nodes[0].Expand();
                        deviceList.Nodes[0].Nodes[0].Expand();
                        deviceList.Nodes[0].Nodes[0].Nodes[0].Expand();
                    }

                    textX.Text       = lt.x.ToString();
                    textY.Text       = lt.y.ToString();
                    textwidth.Text   = lt.width.ToString();
                    textheight.Text  = lt.height.ToString();
                    description.Text = lt.description;

                    if (lt.log == true)
                    {
                        checkBox1.Checked = true;
                    }

                    if (lt.mail == true)
                    {
                        checkBox2.Checked = true;
                    }

                    if (lt.SMS == true)
                    {
                        checkBox3.Checked = true;
                    }

                    //load group contact list
                    for (int g = 0; g < memoryData.GroupContact2.Count; g++)
                    {
                        ContactGroup2 tar = (ContactGroup2)memoryData.GroupContact2[g];
                        GroupContact.Items.Add(tar.groupname);
                    }

                    GroupContact.SelectedIndex = 0;
                }
            }
        }
        private void CMDApply_Click(object sender, EventArgs e)
        {
            if (contactMail.Text != "" && contactName.Text != "")
            {
                Boolean adname = true;
                for (int i = 0; i < memoryData.contact.Count; i++)
                {
                    Contactstruct tar = (Contactstruct)memoryData.contact[i];
                    if (tar.name == contactName.Text)
                    {
                        adname = false;
                        break;
                    }
                }

                option_contact lForm1 = (option_contact)this.Owner;//把Form2的父窗口指針賦給lForm1
                lForm1.ReContact = contactName.Text;
                if (CMD == "add")
                {
                    if (adname == true)
                    {
                        Contactstruct add = new Contactstruct();
                        add.name        = contactName.Text;
                        add.mail        = contactMail.Text;
                        add.phone       = contactPhone.Text;
                        add.description = contactDescription.Text;
                        memoryData.contact.Add(add);

                        ContactGroup2 tar = (ContactGroup2)memoryData.GroupContact2[0];

                        tar.groupmember.Add(add);

                        memoryData.GroupContact2[0] = tar;
                    }
                    else
                    {
                        lForm1.ReContact = null;
                        adname           = true;
                        MessageBox.Show("contact name already in use.");
                    }
                }
                else if (CMD == "edit")
                {
                    for (int i = 0; i < memoryData.contact.Count; i++)
                    {
                        Contactstruct edit = (Contactstruct)memoryData.contact[i];
                        if (edit.name == contact)
                        {
                            string oldname = edit.name;
                            edit.name             = contactName.Text;
                            edit.mail             = contactMail.Text;
                            edit.phone            = contactPhone.Text;
                            edit.description      = contactDescription.Text;
                            memoryData.contact[i] = edit;

                            if (memoryData.GroupContact2.Count != 0)
                            {
                                for (int a = 0; a < memoryData.GroupContact2.Count; a++)
                                {
                                    ContactGroup2 editTarget = (ContactGroup2)memoryData.GroupContact2[a];
                                    for (int b = 0; b < editTarget.groupmember.Count; b++)
                                    {
                                        Contactstruct editContact = (Contactstruct)editTarget.groupmember[b];
                                        if (editContact.name == oldname)
                                        {
                                            editContact.name          = contactName.Text;
                                            editContact.mail          = contactMail.Text;
                                            editContact.phone         = contactPhone.Text;
                                            editContact.description   = contactDescription.Text;
                                            editTarget.groupmember[b] = editContact;
                                        }
                                    }
                                    memoryData.GroupContact2[a] = editTarget;
                                }
                            }
                        }
                    }
                }


                this.Close();
            }
            else
            {
                MessageBox.Show("★ can't empty!");
            }
        }
Пример #11
0
        private void Loadgroup()
        {
            try
            {
                //load sample

                string  curFile  = Application.StartupPath + @"\Resources\mailGroup.txt";
                Boolean findfile = File.Exists(curFile);

                if (findfile == true)
                {
                    StreamReader rd = new StreamReader(Application.StartupPath + @"\Resources\mailGroup.txt");
                    while (rd.EndOfStream == false)
                    {
                        string[] getConfig = rd.ReadLine().Split('#');
                        if (getConfig[1] != "")
                        {
                            ContactGroup2 groupLoad = new ContactGroup2();
                            groupLoad.groupname   = getConfig[1];
                            groupLoad.groupmember = new System.Collections.ArrayList();

                            Contactstruct addmember = new Contactstruct();
                            for (int i = 2; i < getConfig.Length; i++)
                            {
                                string[] member = getConfig[i].Split('$');
                                //Contactstruct addmember = new Contactstruct();
                                addmember.name        = member[0];
                                addmember.mail        = member[1];
                                addmember.phone       = member[2];
                                addmember.description = member[3];

                                groupLoad.groupmember.Add(addmember);
                            }

                            memoryData.GroupContact2.Add(groupLoad);


                            if (getConfig[1] == "all contact")
                            {
                                ContactGroup2 tarGroup = (ContactGroup2)memoryData.GroupContact2[0];
                                if (tarGroup.groupmember != null)
                                {
                                    for (int a = 0; a < tarGroup.groupmember.Count; a++)
                                    {
                                        Contactstruct addMember = (Contactstruct)tarGroup.groupmember[a];
                                        memoryData.contact.Add(addMember);
                                        contactlist.Items.Add(addMember.name);
                                    }
                                }
                            }
                            else
                            {
                                grouplist.Items.Add(groupLoad.groupname);
                            }
                        }
                    }
                    rd.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #12
0
        private void config_OutputObjectButton_Load(object sender, EventArgs e)
        {
            for (int site = 0; site < deviceList.Nodes.Count; site++)
            {
                for (int fab = 0; fab < deviceList.Nodes[site].Nodes.Count; fab++)
                {
                    for (int area = 0; area < deviceList.Nodes[site].Nodes[fab].Nodes.Count; area++)
                    {
                        for (int device = 0; device < deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes.Count; device++)
                        {
                            if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Tag.ToString() == "lon")
                            {
                                for (int obj = 0; obj < deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes.Count; obj++)
                                {
                                    for (int nv = deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes.Count - 1; nv >= 0; nv--)
                                    {
                                        //string[] chk = deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Text.Split('#');
                                        //string snvt = chk[0].Substring(0, 3);

                                        //if (snvt == "UCP" || snvt == "pro" || snvt == "nci" || snvt == "nvo")
                                        //{
                                        //    deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Remove();
                                        //}
                                        string[] tmpStr = NVType2.Split('@');
                                        if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Tag.ToString() != "SNVT_switch") //tmpStr[1])
                                        {
                                            deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Remove();
                                        }
                                        else if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Tag.ToString() == tmpStr[1])
                                        {
                                            if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Text != "VirtFb")
                                            {
                                                string snvt = deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Text.Substring(0, 3);
                                                if (snvt != "nvi")
                                                {
                                                    deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Remove();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            deviceList.CollapseAll();
            for (int i = 0; i < memoryData.OutputButtonData.Count; i++)
            {
                OutputButtonObjectstruct lt = (OutputButtonObjectstruct)memoryData.OutputButtonData[i];
                if (lt.name == picboxName)
                {
                    if (lt.target != "")
                    {
                        string[] index = lt.targetindex.Split('_');
                        deviceList.SelectedNode = deviceList.Nodes[int.Parse(index[0])].Nodes[int.Parse(index[1])].Nodes[int.Parse(index[2])].Nodes[int.Parse(index[3])].Nodes[int.Parse(index[4])].Nodes[int.Parse(index[5])];
                        deviceList.Select();
                    }
                    else
                    {
                        deviceList.SelectedNode = deviceList.Nodes[0].Nodes[0].Nodes[0];
                        deviceList.Nodes[0].Expand();
                        deviceList.Nodes[0].Nodes[0].Expand();
                        deviceList.Nodes[0].Nodes[0].Nodes[0].Expand();
                    }

                    textX.Text       = lt.x.ToString();
                    textY.Text       = lt.y.ToString();
                    textwidth.Text   = lt.width.ToString();
                    textheight.Text  = lt.height.ToString();
                    description.Text = lt.description;

                    if (lt.log == true)
                    {
                        checkBox1.Checked = true;
                    }
                    if (lt.mail == true)
                    {
                        checkBox2.Checked = true;
                    }
                    if (lt.SMS == true)
                    {
                        checkBox3.Checked = true;
                    }

                    //load group contact list
                    for (int g = 0; g < memoryData.GroupContact2.Count; g++)
                    {
                        ContactGroup2 gc = (ContactGroup2)memoryData.GroupContact2[g];
                        GroupContact.Items.Add(gc.groupname);
                    }

                    GroupContact.SelectedIndex = 0;

                    if (lt.buttontype == "0")
                    {
                        buttonType1.Checked = true;
                    }
                    else if (lt.buttontype == "1")
                    {
                        buttonType2.Checked = true;
                    }
                    else if (lt.buttontype == "2")
                    {
                        buttonType3.Checked = true;
                    }
                    else if (lt.buttontype == "3")
                    {
                        buttonType4.Checked = true;
                    }
                    else if (lt.buttontype == "4")
                    {
                        buttonType5.Checked = true;

                        userOnImagePath  = lt.userOnImagePath;
                        userOffImagePath = lt.userOffImagePath;
                        userON.Image     = Image.FromFile(userOnImagePath);
                        userOFF.Image    = Image.FromFile(userOffImagePath);
                    }

                    if (lt.NVvalue == "100.0 1")
                    {
                        valueType1.Checked = true;
                    }
                    else if (lt.NVvalue == "0.0 0")
                    {
                        valueType2.Checked = true;
                    }
                    else if (lt.NVvalue == "toggle")
                    {
                        valueType4.Checked = true;
                    }
                }
            }
        }
Пример #13
0
        private void config_OutputObjectPopEdit_Load(object sender, EventArgs e)
        {
            for (int site = 0; site < deviceList.Nodes.Count; site++)
            {
                for (int fab = 0; fab < deviceList.Nodes[site].Nodes.Count; fab++)
                {
                    for (int area = 0; area < deviceList.Nodes[site].Nodes[fab].Nodes.Count; area++)
                    {
                        for (int device = 0; device < deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes.Count; device++)
                        {
                            if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Tag.ToString() == "lon")
                            {
                                for (int obj = 0; obj < deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes.Count; obj++)
                                {
                                    for (int nv = deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes.Count - 1; nv >= 0; nv--)
                                    {
                                        string[] tmpStr = NVType2.Split('@');
                                        if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Tag.ToString() != tmpStr[1])
                                        {
                                            deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Remove();
                                        }
                                        else if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Tag.ToString() == tmpStr[1])
                                        {
                                            if (deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Text != "VirtFb")
                                            {
                                                string snvt = deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Text.Substring(0, 3);
                                                if (snvt != "nvi")
                                                {
                                                    deviceList.Nodes[site].Nodes[fab].Nodes[area].Nodes[device].Nodes[obj].Nodes[nv].Remove();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            deviceList.CollapseAll();

            for (int i = 0; i < memoryData.OutputPopData.Count; i++)
            {
                OutputPopObjectstruct tar = (OutputPopObjectstruct)memoryData.OutputPopData[i];
                if (tar.name == popName)
                {
                    if (tar.target != "")
                    {
                        string[] index = tar.targetindex.Split('_');
                        deviceList.SelectedNode = deviceList.Nodes[int.Parse(index[0])].Nodes[int.Parse(index[1])].Nodes[int.Parse(index[2])].Nodes[int.Parse(index[3])].Nodes[int.Parse(index[4])].Nodes[int.Parse(index[5])];
                        deviceList.Select();
                    }
                    else
                    {
                        deviceList.SelectedNode = deviceList.Nodes[0].Nodes[0].Nodes[0];
                        deviceList.Nodes[0].Expand();
                        deviceList.Nodes[0].Nodes[0].Expand();
                        deviceList.Nodes[0].Nodes[0].Nodes[0].Expand();
                    }

                    if (tar.AlignText.ToString() != "")
                    {
                        textAlign.Text = tar.AlignText.ToString();
                    }
                    if (tar.AlignIMG.ToString() != "")
                    {
                        imageAlign.Text = tar.AlignIMG.ToString();
                    }

                    Demobutton.BackColor = Color.FromArgb(tar.backColor);
                    description.Text     = tar.description;

                    if (tar.backImage != null && tar.backImage != "")
                    {
                        Demobutton.Image = Image.FromFile(tar.backImage);
                        imagePath        = tar.backImage;
                    }

                    if (tar.useBackIMG == true)
                    {
                        backgroundimage.Checked = true;
                    }
                    else if (tar.useBackColor == true)
                    {
                        backgroundcolor.Checked = true;
                    }

                    if (tar.log == true)
                    {
                        checkBox1.Checked = true;
                    }

                    if (tar.mail == true)
                    {
                        checkBox2.Checked = true;
                    }

                    if (tar.SMS == true)
                    {
                        checkBox3.Checked = true;
                    }
                    //load group contact list
                    for (int g = 0; g < memoryData.GroupContact2.Count; g++)
                    {
                        ContactGroup2 gc = (ContactGroup2)memoryData.GroupContact2[g];
                        GroupContact.Items.Add(gc.groupname);
                    }

                    GroupContact.SelectedIndex = 0;
                }
            }
        }
        private void CMDApply_Click(object sender, EventArgs e)
        {
            if (inputVal.Text != "")
            {
                if (target != "")
                {
                    string[] path = target.Split('@');
                    //SmartServer.SOAP ss = new SmartServer.SOAP();
                    SOAP20_DLL.SOAP ws = new SOAP20_DLL.SOAP();
                    //ss.writeNV(ip, path[2], inputVal.Text);
                    string requestVal          = ws.writeNV(ip, path[2], inputVal.Text);
                    OutputPopObjectstruct edit = (OutputPopObjectstruct)memoryData.OutputPopData[listIndex];

                    string formatForMySqlDate = DateTime.Now.ToString("yyyy-MM-dd");
                    string formatForMySqlTime = DateTime.Now.ToString("HH:mm:ss");
                    //save to database
                    if (memoryData.database.Count != 0)
                    {
                        database SQLstr = (database)memoryData.database[0];

                        //save to database
                        //open database   ///////////////////////////////////////////////////////////////////////
                        string          connStr = "server=" + SQLstr.ip + ";port=" + SQLstr.port + ";uid=" + SQLstr.user + ";pwd=" + SQLstr.password + ";database=" + SQLstr.DBname;
                        MySqlConnection conn    = new MySqlConnection(connStr);
                        MySqlCommand    addList = conn.CreateCommand();
                        conn.Open();

                        string sql = @"SELECT * FROM output_list WHERE site='" + edit.site + "' and fab='" + edit.fab + "' and area='" + edit.area
                                     + "' and device='" + edit.device + "' and function='" + edit.function + "' and NVname='" + edit.NV + "' ";

                        MySqlCommand    cmdCHK  = new MySqlCommand(sql, conn);
                        MySqlDataReader dataCHK = cmdCHK.ExecuteReader();
                        int             listid  = 0;

                        if (dataCHK.HasRows == true)
                        {
                            dataCHK.Read();
                            //有查到資料
                            listid = int.Parse(dataCHK.GetString(0));
                            dataCHK.Close();

                            addList.CommandText = @"update nico_db.output_list set description = '" + edit.description + "' where id = " + listid;
                            addList.ExecuteNonQuery();

                            MySqlCommand addValue = conn.CreateCommand();

                            addValue.CommandText = @"Insert into output_value(list_id,NVvalue_txt,date,time) values('" + listid + "','"
                                                   + inputVal.Text + "','" + formatForMySqlDate + "','" + formatForMySqlTime + "')";

                            addValue.ExecuteNonQuery();
                        }
                        else
                        {
                            dataCHK.Close();
                            // MySqlCommand addList = conn.CreateCommand();

                            //沒有查到資料
                            addList.CommandText = @"Insert into output_list(site,fab,area,device,function,NVname,NVtype,description,ip) values('"
                                                  + edit.site + "','" + edit.fab + "','" + edit.area + "','" + edit.device + "','" + edit.function + "','"
                                                  + edit.NV + "','" + edit.NVtype + "','" + edit.description + "','" + edit.ip + "');";

                            addList.ExecuteNonQuery();
                            //get list_id
                            dataCHK = cmdCHK.ExecuteReader();
                            dataCHK.Read();
                            if (dataCHK.HasRows == true)
                            {
                                listid = int.Parse(dataCHK.GetString(0));
                                dataCHK.Close();
                            }

                            //write to output_value
                            MySqlCommand addValue = conn.CreateCommand();

                            addValue.CommandText = @"Insert into output_value(list_id,NVvalue_txt,date,time) values('" + listid + "','"
                                                   + inputVal.Text + "','" + formatForMySqlDate + "','" + formatForMySqlTime + "')";

                            addValue.ExecuteNonQuery();
                        }

                        conn.Close();
                        //close database    ////////////////////////////////////////////////////////////////////////
                    }


                    //send email
                    if (edit.mail == true)
                    {
                        for (int m = 0; m < memoryData.GroupContact2.Count; m++)
                        {
                            ContactGroup2 mg = (ContactGroup2)memoryData.GroupContact2[m];
                            if (edit.contactGroup == mg.groupname)
                            {
                                using (FileStream input = new FileStream(Application.StartupPath + @"\Resources\SMTP.dat", FileMode.Open))
                                {   // 讀取整數值
                                    BinaryReader reader = new BinaryReader(input);
                                    string       data   = reader.ReadString();

                                    int    numOfBytes = data.Length / 8;
                                    byte[] bytes      = new byte[numOfBytes];
                                    for (int ri = 0; ri < numOfBytes; ++ri)
                                    {
                                        bytes[ri] = Convert.ToByte(data.Substring(8 * ri, 8), 2);
                                    }
                                    //File.WriteAllBytes(fileName, bytes);
                                    string   val          = GetString(bytes);
                                    string[] SpStr        = val.Split('$');
                                    string   SMTPhost     = SpStr[1];
                                    string   SMTPport     = SpStr[2];
                                    Boolean  SSL          = Boolean.Parse(SpStr[3]);
                                    string   userName     = SpStr[4];
                                    string   userPassword = SpStr[5];

                                    string targetpath = edit.site + "/" + edit.fab + "/" + edit.area + "/" + edit.device + "/" + edit.function + "/" + edit.NV;


                                    for (int sg = 0; sg < mg.groupmember.Count; sg++)
                                    {
                                        Contactstruct sgm = (Contactstruct)mg.groupmember[sg];
                                        if (sgm.mail != null && sgm.mail != "")
                                        {
                                            email.From    = new MailAddress(userName);                                                     //寄件人
                                            email.Subject = "IO trigger!  target : " + targetpath;                                         //標題
                                            email.Body    = "trigger time = " + formatForMySqlDate + " " + formatForMySqlTime + Environment.NewLine
                                                            + "trigger value = " + inputVal.Text + Environment.NewLine + edit.description; //內容
                                            email.To.Add(sgm.mail);                                                                        //收件人
                                            SMTP.EnableSsl   = true;
                                            SMTP.Port        = int.Parse(SMTPport);                                                        //smtp port
                                            SMTP.Host        = SMTPhost;                                                                   //smtp host(主機ip)
                                            SMTP.Credentials = new System.Net.NetworkCredential(userName, userPassword);                   //寄件人,密碼
                                            SMTP.Send(email);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("not target!");
                }
            }
        }