示例#1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            EditContact editContact = new EditContact();
            editContact.ShowDialog();
            if (editContact.DialogResult == DialogResult.OK)
            {
                // add record
                string insertStr = String.Format("INSERT INTO [Contact] ([Email Address], [Name], [comment]) VALUES ('{0}', '{1}', '{2}')",
                    editContact.EmailAddress, editContact.ContactName, editContact.Comment);
                if (DBAccess.ExecuteSQL(insertStr))
                {
                    MessageBox.Show("添加联系人成功!", "邮件系统");
                }
                else
                {
                    MessageBox.Show("添加联系人失败!", "邮件系统");
                }

                LoadContact();
            }
        }
示例#2
0
        private void EditContact(int row)
        {
            // edit record
            EditContact editContact = new EditContact();
            editContact.ID = dataGridViewContact.Rows[row].Cells[0].Value.ToString();
            editContact.EmailAddress = dataGridViewContact.Rows[row].Cells[1].Value.ToString();
            editContact.ContactName = dataGridViewContact.Rows[row].Cells[2].Value.ToString();
            editContact.Comment = dataGridViewContact.Rows[row].Cells[3].Value.ToString();
            editContact.ShowDialog();
            if (editContact.DialogResult == DialogResult.OK)
            {
                // add record
                string updateStr = String.Format("UPDATE [Contact] SET [Email Address] = '{0}', [Name] = '{1}', [comment] = '{2}' WHERE [ID] = {3}",
                    editContact.EmailAddress, editContact.ContactName, editContact.Comment, editContact.ID);
                if (DBAccess.ExecuteSQL(updateStr))
                {
                    MessageBox.Show("更新联系人成功!", "邮件系统");
                }
                else
                {
                    MessageBox.Show("更新联系人失败!", "邮件系统");
                }

                LoadContact();
            }
        }