private void user_check_Load(object sender, EventArgs e)
        {
            database SQLstr = (database)memoryData.database[0];

            ip.Text           = SQLstr.ip;
            userName.Text     = SQLstr.user;
            userPassword.Text = SQLstr.password;
            SMTPport.Text     = SQLstr.port;
            DBname.Text       = SQLstr.DBname;
        }
        private void CMD_add_Click(object sender, EventArgs e)
        {
            getUser.name = null;
            user_check2_add le = new user_check2_add();

            le.Owner = this;
            le.ShowDialog();

            if (getUser.name != null)
            {
                int findtar = listBox1.FindString(getUser.name);
                if (findtar != -1)
                {
                    MessageBox.Show("This name already in use!");
                }
                else
                {
                    database        SQLstr  = (database)memoryData.database[0];
                    MySqlConnection conn    = new MySqlConnection(MYSQL_str);
                    MySqlCommand    command = conn.CreateCommand();
                    conn.Open();
                    command.CommandText = @"Insert into user_data(name,pass,level) values('"
                                          + getUser.name + "','" + getUser.pass + "','" + getUser.level + "')";

                    command.ExecuteNonQuery();

                    conn.Close();

                    int    chkno    = 0;
                    string chkname  = "";
                    string chkpass  = "";
                    string chklevel = "";

                    conn.Open();
                    command.CommandText = "SELECT * FROM nico_db.user_data where name = '" + getUser.name + "'";
                    MySqlDataReader reader;
                    reader = command.ExecuteReader();
                    reader.Read();
                    chkno    = (int)reader["no"];
                    chkname  = (String)reader["name"];
                    chkpass  = (String)reader["pass"];
                    chklevel = (String)reader["level"];
                    conn.Close();

                    AccountList add = new AccountList();
                    add.no    = chkno;
                    add.name  = chkname;
                    add.pass  = chkpass;
                    add.level = chklevel;
                    memoryData.accountListTemp.Add(add);
                    listBox1.Items.Add(chkname);
                }
            }
        }
Beispiel #3
0
        private void apply_Click(object sender, EventArgs e)
        {
            string   user   = textBox1.Text;
            string   pass   = textBox2.Text;
            string   level  = "";
            string   getMD5 = MD5code(pass);
            string   connStr;
            database SQLstr = (database)memoryData.database[0];

            connStr = "server=" + SQLstr.ip + ";port=" + SQLstr.port + ";uid=" + SQLstr.user + ";pwd=" + SQLstr.password + ";database=" + SQLstr.DBname;
            MySqlConnection conn    = new MySqlConnection(connStr);
            MySqlCommand    command = conn.CreateCommand();

            try
            {
                conn.Open();

                //連線MYSQL 取回要比對的資料
                command.CommandText = "SELECT * FROM nico_db.user_data where name = '" + user + "' and pass ="******"'" + getMD5 + "'";
                MySqlDataReader reader;
                reader = command.ExecuteReader();
                if (reader.HasRows != false)
                {
                    reader.Read();
                    level = (String)reader["level"];
                    if (level == "admin")
                    {
                        option_account le = new option_account();
                        le.MYSQL_str = connStr;
                        le.Show();

                        conn.Close();
                        this.Close();
                    }
                    else
                    {
                        conn.Close();
                        MessageBox.Show("need administrator account!");
                    }
                }
                else
                {
                    conn.Close();
                    MessageBox.Show("user name or password error!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void option_database_Load(object sender, EventArgs e)
        {
            //string cnstr = string.Format("server={0};database={1};uid={2};pwd={3}", Server, Database, dbuid, dbpwd);//標準連線設定
            //string cnstr = string.Format("server={0};database={1};uid={2};pwd={3}; Connect Timeout=180", Server, Database, dbuid, dbpwd);//逾時連線時間設定
            //string cnstr = string.Format("server={0};database={1};uid={2};pwd={3}; Port=3306", Server, Database, dbuid, dbpwd);//通訊端口設定,MySQL的預設端口為3306
            //string cnstr = string.Format("server={0};database={1};uid={2};pwd={3}; Charset=utf8", Server, Database, dbuid, dbpwd);//編碼設定

            if (memoryData.database.Count != 0)
            {
                database tar = (database)memoryData.database[0];
                ip.Text           = tar.ip;
                SMTPport.Text     = tar.port;
                userName.Text     = tar.user;
                userPassword.Text = tar.password;
                DBname.Text       = tar.DBname;
            }
        }
        private void CMD_edit_Click(object sender, EventArgs e)
        {
            int         selectItem = listBox1.SelectedIndex;
            AccountList tar        = (AccountList)memoryData.accountListTemp[selectItem];

            string editName  = user.Text;
            string editPass  = MD5code(password.Text);
            string editLevel = "";

            if (account_admin.Checked == true)
            {
                editLevel = "admin";
            }
            else if (account_designer.Checked == true)
            {
                editLevel = "design";
            }
            else if (account_viewer.Checked == true)
            {
                editLevel = "view";
            }
            try
            {
                database        SQLstr  = (database)memoryData.database[0];
                MySqlConnection conn    = new MySqlConnection(MYSQL_str);
                MySqlCommand    command = conn.CreateCommand();
                conn.Open();
                command.CommandText = @"update nico_db.user_data set name ='" + editName + "',pass = '******',level = '" + editLevel + "' where no = '" + tar.no + "'";
                command.ExecuteNonQuery();
                conn.Close();

                tar.name  = editName;
                tar.pass  = editPass;
                tar.level = editLevel;
                memoryData.accountListTemp[selectItem] = tar;
                listBox1.SelectedIndex     = -1;
                listBox1.Items[selectItem] = editName;
                listBox1.SelectedIndex     = selectItem;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void option_account_Load(object sender, EventArgs e)
        {
            database        SQLstr  = (database)memoryData.database[0];
            MySqlConnection conn    = new MySqlConnection(MYSQL_str);
            MySqlCommand    command = conn.CreateCommand();

            int    number   = 0;
            string name     = "";
            string password = "";
            string level    = "";

            try
            {
                conn.Open();
                command.CommandText = "SELECT * FROM nico_db.user_data";
                MySqlDataReader reader;
                reader = command.ExecuteReader();
                memoryData.accountListTemp.Clear();
                while (reader.Read())
                {
                    number   = (int)reader["no"];
                    name     = (String)reader["name"];
                    password = (String)reader["pass"];
                    level    = (String)reader["level"];
                    AccountList add = new AccountList();
                    add.no    = number;
                    add.name  = name;
                    add.pass  = password;
                    add.level = level;
                    memoryData.accountListTemp.Add(add);
                    listBox1.Items.Add(name);
                }

                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void CMDApply_Click(object sender, EventArgs e)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append("$" + ip.Text);
            buffer.Append("$" + userName.Text);
            buffer.Append("$" + userPassword.Text);
            buffer.Append("$" + SMTPport.Text);
            buffer.Append("$" + DBname.Text);

            byte[] bstr = GetBytes(buffer.ToString());
            string str  = Format(bstr);

            using (FileStream output = File.Create(Application.StartupPath + @"\Resources\database.dat"))
            {         // 寫入整數值
                BinaryWriter writer = new BinaryWriter(output);

                writer.Write(str);
            }

            database add = new database();

            add.ip       = ip.Text;
            add.port     = SMTPport.Text;
            add.user     = userName.Text;
            add.password = userPassword.Text;
            add.DBname   = DBname.Text;

            if (memoryData.database.Count != 0)
            {
                memoryData.database[0] = add;
            }
            else
            {
                memoryData.database.Add(add);
            }

            this.Close();
        }
Beispiel #8
0
        private void cmdApply_Click(object sender, EventArgs e)
        {
            string[] InputInfo   = TargetPath.Split('/');
            string   site        = InputInfo[0];
            string   fab         = InputInfo[1];
            string   area        = InputInfo[2];
            string   device      = InputInfo[3];
            string   function    = InputInfo[4];
            string   nv          = InputInfo[5];
            string   nvType      = InputInfo[6];
            string   description = InputInfo[7];
            string   ip          = InputInfo[8];
            int      getid       = 0;

            string connStr = "";

            if (check_date.Checked == true && check_value.Checked == false)
            {
                try
                {
                    string date1, date2, time1, time2;

                    date1 = from_date.Value.ToString("yyyy-MM-dd");
                    date2 = to_date.Value.ToString("yyyy-MM-dd");
                    time1 = from_time.Value.ToString("HH:mm:ss");
                    time2 = to_time.Value.ToString("HH:mm:ss");

                    database SQLstr = (database)memoryData.database[0];
                    connStr = "server=" + SQLstr.ip + ";port=" + SQLstr.port + ";uid=" + SQLstr.user + ";pwd=" + SQLstr.password + ";database=" + SQLstr.DBname;
                    MySqlConnection conn    = new MySqlConnection(connStr);
                    MySqlCommand    command = conn.CreateCommand();
                    conn.Open();
                    command.CommandText = "SELECT * FROM nico_db.input_list where site = '" + site
                                          + "' and fab = '" + fab + "' and area = '" + area + "' and device = '" + device
                                          + "' and function = '" + function + "' and NVname = '" + nv + "' and ip = '" + ip + "'";

                    MySqlDataReader reader;
                    reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        if (reader.HasRows != false)
                        {
                            reader.Read();

                            //string level = (String)reader["id"];
                            getid = (int)reader["id"];
                            conn.Close();
                            conn.Open();

                            //Sql  String
                            string mySelectQuery = "SELECT * FROM nico_db.input_value where list_id ='" + getid
                                                   + "' and date between '" + date1 + "' and '" + date2 + "' and time between '" + time1
                                                   + "' and '" + time2 + "' limit " + limit.Text;
                            //這個 adapter是Mysql的 adapter;
                            MySqlDataAdapter adapter = new MySqlDataAdapter(mySelectQuery, conn);

                            DataTable dt = new DataTable("log");
                            adapter.Fill(dt);
                            //insert column
                            System.Data.DataColumn newColumn = new System.Data.DataColumn("dt", typeof(System.String));
                            dt.Columns.Add(newColumn);

                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                dt.Rows[i].BeginEdit();
                                dt.Rows[i]["dt"] = dt.Rows[i].ItemArray[4] + " " + dt.Rows[i].ItemArray[5];

                                dt.Rows[i].EndEdit();
                            }

                            dataGridView1.DataSource = dt;
                            dataGridView1.DataSource = dt;

                            search_tagData_Show showForm = new search_tagData_Show();
                            showForm.dataGridView1.DataSource         = dt;
                            showForm.dataGridView1.Columns[0].Visible = false;
                            showForm.dataGridView1.Columns[1].Visible = false;
                            showForm.dataGridView1.Columns[2].Visible = false;
                            showForm.dataGridView1.Columns[6].Visible = false;

                            showForm.site.Text         = site;
                            showForm.fab.Text          = fab;
                            showForm.area.Text         = area;
                            showForm.device.Text       = device;
                            showForm.function.Text     = function;
                            showForm.nv.Text           = nv;
                            showForm.nvType.Text       = nvType;
                            showForm.description.Text  = description;
                            showForm.ip.Text           = ip;
                            showForm.index.Text        = getid.ToString();
                            showForm.count.Text        = dt.Rows.Count.ToString();
                            showForm.CMD_chart.Enabled = true;
                            showForm.dt = dt;
                            showForm.Show();

                            conn.Close();
                            break;
                        }
                        else
                        {
                            MessageBox.Show("data not found!");
                            conn.Close();
                        }
                    }

                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (check_date.Checked == true && check_value.Checked == true)
            {
                try
                {
                    string date1, date2, time1, time2;
                    string svalue1, svalue2, set1, set2;

                    date1 = from_date.Value.ToString("yyyy-MM-dd");
                    date2 = to_date.Value.ToString("yyyy-MM-dd");
                    time1 = from_time.Value.ToString("HH:mm:ss");
                    time2 = to_time.Value.ToString("HH:mm:ss");


                    database SQLstr = (database)memoryData.database[0];
                    connStr = "server=" + SQLstr.ip + ";port=" + SQLstr.port + ";uid=" + SQLstr.user + ";pwd=" + SQLstr.password + ";database=" + SQLstr.DBname;
                    MySqlConnection conn    = new MySqlConnection(connStr);
                    MySqlCommand    command = conn.CreateCommand();
                    conn.Open();
                    command.CommandText = "SELECT * FROM nico_db.input_list where site = '" + site
                                          + "' and fab = '" + fab + "' and area = '" + area + "' and device = '" + device
                                          + "' and function = '" + function + "' and NVname = '" + nv + "' and ip = '" + ip + "'";

                    MySqlDataReader reader;
                    reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        if (reader.HasRows != false)
                        {
                            reader.Read();

                            //string level = (String)reader["id"];
                            getid = (int)reader["id"];
                            conn.Close();
                            conn.Open();
                            string mySelectQuery = "";
                            if (radio_value.Checked == true)
                            {
                                svalue1 = value1.Text;
                                set1    = combo_value.Text;

                                //Sql  String
                                mySelectQuery = "SELECT * FROM nico_db.input_value where list_id ='" + getid
                                                + "' and date between '" + date1 + "' and '" + date2 + "' and time between '" + time1
                                                + "' and '" + time2 + "' " + "and NVvalue_real " + set1 + " '" + svalue1 + "'" + " limit " + limit.Text;
                            }
                            else if (radio_between.Checked == true)
                            {
                                svalue1 = value2.Text;
                                svalue2 = value3.Text;
                                set1    = combo_between1.Text;
                                set2    = combo_between2.Text;

                                //Sql  String
                                mySelectQuery = "SELECT * FROM nico_db.input_value where list_id ='" + getid
                                                + "' and date between '" + date1 + "' and '" + date2 + "' and time between '" + time1
                                                + "' and '" + time2 + "' and NVvalue_real " + set1 + " " + svalue1
                                                + " and NVvalue_real " + set2 + " " + svalue2 + " limit " + limit.Text;
                            }


                            //這個 adapter是Mysql的 adapter;
                            MySqlDataAdapter adapter = new MySqlDataAdapter(mySelectQuery, conn);

                            DataTable dt = new DataTable("log");
                            adapter.Fill(dt);

                            //insert column
                            System.Data.DataColumn newColumn = new System.Data.DataColumn("dt", typeof(System.String));
                            dt.Columns.Add(newColumn);

                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                dt.Rows[i].BeginEdit();
                                dt.Rows[i]["dt"] = dt.Rows[i].ItemArray[4] + " " + dt.Rows[i].ItemArray[5];

                                dt.Rows[i].EndEdit();
                            }

                            dataGridView1.DataSource = dt;


                            search_tagData_Show showForm = new search_tagData_Show();
                            showForm.dataGridView1.DataSource         = dt;
                            showForm.dataGridView1.Columns[0].Visible = false;
                            showForm.dataGridView1.Columns[1].Visible = false;
                            showForm.dataGridView1.Columns[2].Visible = false;
                            showForm.dataGridView1.Columns[6].Visible = false;

                            showForm.site.Text         = site;
                            showForm.fab.Text          = fab;
                            showForm.area.Text         = area;
                            showForm.device.Text       = device;
                            showForm.function.Text     = function;
                            showForm.nv.Text           = nv;
                            showForm.nvType.Text       = nvType;
                            showForm.description.Text  = description;
                            showForm.ip.Text           = ip;
                            showForm.index.Text        = getid.ToString();
                            showForm.count.Text        = dt.Rows.Count.ToString();
                            showForm.CMD_chart.Enabled = false;
                            showForm.dt = dt;
                            showForm.Show();

                            conn.Close();
                            break;
                        }
                        else
                        {
                            MessageBox.Show("data not found!");
                            conn.Close();
                        }
                    }

                    //this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (check_date.Checked == false && check_value.Checked == true)
            {
                try
                {
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (check_date.Checked == false && check_value.Checked == false)
            {
                //no action
            }
        }
        private void apply_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            //check id & password
            string user   = textBox1.Text;
            string pass   = textBox2.Text;
            string action = "";


            if (user == "nicosu" && pass == "nico8960")
            {
                Form1 lForm1 = (Form1)this.Owner;//把Form2的父窗口指針賦給lForm1
                lForm1.User  = "******";
                lForm1.AccLV = "admin";
                this.Close();
            }
            else
            {
                //contace to database
                string getMD5  = MD5code(pass);
                string connStr = "";
                string level   = "";
                if (show_db.Checked == false)
                {
                    database SQLstr = (database)memoryData.database[0];
                    connStr = "server=" + SQLstr.ip + ";port=" + SQLstr.port + ";uid=" + SQLstr.user + ";pwd=" + SQLstr.password + ";database=" + SQLstr.DBname;
                }
                else if (show_db.Checked == true)
                {
                    connStr = "server=" + ip.Text + ";port=" + SMTPport.Text + ";uid=" + userName.Text + ";pwd=" + userPassword.Text + ";database=" + DBname.Text;
                }

                MySqlConnection conn    = new MySqlConnection(connStr);
                MySqlCommand    command = conn.CreateCommand();
                try
                {
                    conn.Open();
                    //連線MYSQL 取回要比對的資料
                    command.CommandText = "SELECT * FROM nico_db.user_data where name = '" + user + "' and pass ="******"'" + getMD5 + "'";
                    MySqlDataReader reader;
                    action = "read";
                    reader = command.ExecuteReader();

                    //while (reader.Read())
                    // {
                    reader.Read();
                    level = (String)reader["level"];
                    conn.Close();

                    Form1 lForm1 = (Form1)this.Owner;//把Form2的父窗口指針賦給lForm1
                    lForm1.User  = user;
                    lForm1.AccLV = level;;

                    conn.Open();
                    //save login event to database
                    string formatForMySqlDate = DateTime.Now.ToString("yyyy-MM-dd");
                    string formatForMySqlTime = DateTime.Now.ToString("HH:mm:ss");
                    command.CommandText = @"Insert into log(name,level,date,time) values('"
                                          + textBox1.Text + "','" + level + "','" + formatForMySqlDate + "','" + formatForMySqlTime + "')";
                    action = "save";
                    command.ExecuteNonQuery();
                    conn.Close();
                    Cursor.Current = Cursors.Default;
                    this.Close();

                    database SQLstr = (database)memoryData.database[0];
                    SQLstr.ip              = ip.Text;
                    SQLstr.user            = userName.Text;
                    SQLstr.password        = userPassword.Text;
                    SQLstr.port            = SMTPport.Text;
                    SQLstr.DBname          = DBname.Text;
                    memoryData.database[0] = SQLstr;
                    //}
                }
                catch (Exception ex)
                {
                    if (action == "read")
                    {
                        MessageBox.Show("user name or password error!");
                    }
                    else
                    {
                        MessageBox.Show(ex.Message);
                    }
                    conn.Close();
                    Cursor.Current = Cursors.Default;
                }
            }
        }
        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!");
                }
            }
        }