⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.cs

📁 java编写的邮件群发软件
💻 CS
📖 第 1 页 / 共 3 页
字号:
            {
                string _mn = this.sendMailList.Items[this.sendMailList.SelectedItems[0].Index].SubItems[0].Text;
                try
                {
                    doh.Reset();
                    doh.ConditionExpress = "mail=@mail";
                    doh.AddConditionParameter("@mail", _mn);
                    doh.Delete("xk_fromMail");
                    this.sendMailList.Items.Remove(this.sendMailList.Items[this.sendMailList.SelectedItems[0].Index]);

                    this.mailName.Enabled = true;

                    this.mailName.Text = "";
                    this.mailServer.Text = "";
                    this.mailUsername.Text = "";
                    this.mailPassword.Text = "";

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
                txtImportMails.Text = this.openFileDialog1.FileName;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (cbMailGroup.SelectedValue == null || Validator.StrToInt(cbMailGroup.SelectedValue.ToString(), 0) == 0)
            {
                ShowMsgBox("请选择邮件组!");
                return;
            }
            string gId = cbMailGroup.SelectedValue.ToString();
            StreamReader sr = new StreamReader(txtImportMails.Text);
            if (sr == null)
            {
                ShowMsgBox("文件不存在!");
                return;
            }

            string temStr = sr.ReadToEnd();
            sr.Close();
            string[] mailstr = temStr.Split(',');

            //去掉重复项
            temStr = string.Empty;
            for (int i = 0; i < mailstr.Length; i++)
            {
                if (temStr.IndexOf(mailstr[i]) == -1)
                {
                    temStr += mailstr[i];
                    doh.Reset();
                    doh.AddFieldItem("mail", mailstr[i]);
                    doh.AddFieldItem("groupId", gId);
                    doh.Insert("xk_toMails");
                }
            }

            ShowMsgBox("导入成功");
            cbMailGroup_SelectedIndexChanged(null, null);
        }
        #endregion

        #region 接收设置
        private void cbMailGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbMailGroup.SelectedValue != null && Validator.StrToInt(cbMailGroup.SelectedValue.ToString(), 0) > 0)
            {
                doh.Reset();
                doh.SqlCmd = "select id,mail from xk_toMails where groupId=" + cbMailGroup.SelectedValue.ToString();
                DataTable dt = doh.GetDataTable();
                ArrayList mylist = new ArrayList();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    mylist.Add(new DictionaryEntry(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString()));
                }
                if (mylist.Count == 0)
                    mylist.Add(new DictionaryEntry(0, ""));
                lstGroupMails.DataSource = mylist;
                lstGroupMails.DisplayMember = "Value";
                lstGroupMails.ValueMember = "Key";

                txtGroupId.Text = cbMailGroup.SelectedValue.ToString();
                txtGroupMails.Text = dt.Rows.Count.ToString();
                txtGroupName.Text = cbMailGroup.Text;
            }
            txtMailId.Text = "";
            txtMailName.Text = "";
        }

        private void lstGroupMails_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (lstGroupMails.SelectedValue != null && Validator.StrToInt(lstGroupMails.SelectedValue.ToString(), 0) > 0)
            {
                txtMailId.Text = lstGroupMails.SelectedValue.ToString();
                txtMailName.Text = lstGroupMails.Text;
            }
        }

        private void btnModGroup_Click(object sender, EventArgs e)
        {
            if (txtGroupName.Text.Trim() != "")
            {
                doh.Reset();
                doh.AddFieldItem("title", txtGroupName.Text);
                if (txtGroupId.Text != "" && Validator.StrToInt(txtGroupId.Text, 0) > 0)
                {
                    doh.ConditionExpress = "id=" + txtGroupId.Text;
                    doh.Update("xk_mailGroup");
                }
                else
                    doh.Insert("xk_mailGroup");
                txtGroupId.Text = "";
                txtGroupName.Text = "";
                txtGroupMails.Text = "";
                LoadGroups();
            }
        }

        private void btnDelGroup_Click(object sender, EventArgs e)
        {
            if (txtGroupId.Text != "" && Validator.StrToInt(txtGroupId.Text, 0) > 0)
            {
                if (MessageBox.Show(this, "确定要删除吗?将同时删除本组所有邮件地址!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    doh.Reset();
                    doh.ConditionExpress = "id=" + txtGroupId.Text;
                    doh.Delete("xk_mailGroup");

                    doh.Reset();
                    doh.ConditionExpress = "groupId=" + txtGroupId.Text;
                    doh.Delete("xk_toMails");

                    txtGroupId.Text = "";
                    txtGroupName.Text = "";
                    txtGroupMails.Text = "";

                    LoadGroups();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (cbMailGroup.SelectedValue == null || Validator.StrToInt(cbMailGroup.SelectedValue.ToString(), 0) == 0)
            {
                ShowMsgBox("请先选择邮件组!");
                return;
            }
            if (txtMailName.Text.Trim() != "")
            {
                doh.Reset();
                doh.AddFieldItem("mail", txtMailName.Text);
                doh.AddFieldItem("groupId", cbMailGroup.SelectedValue.ToString());
                if (txtMailId.Text != "" && Validator.StrToInt(txtMailId.Text, 0) > 0)
                {
                    doh.ConditionExpress = "id=" + txtMailId.Text;
                    doh.Update("xk_toMails");
                }
                else
                {
                    for (int i = 0; i < lstGroupMails.Items.Count; i++)
                    {
                        string dd = ((DictionaryEntry)lstGroupMails.Items[i]).Value.ToString();
                        if (dd == txtMailName.Text.Trim())
                        {
                            ShowMsgBox("本组中已经有此项!");
                            return;
                        }
                    }

                    doh.Insert("xk_toMails");
                }

                txtMailId.Text = "";
                txtMailName.Text = "";

                cbMailGroup_SelectedIndexChanged(null, null);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtMailId.Text != "" && Validator.StrToInt(txtMailId.Text, 0) > 0)
            {
                DialogResult dr = MessageBox.Show(this, "确定要删除吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    doh.Reset();
                    doh.ConditionExpress = "id=" + txtMailId.Text;
                    doh.Delete("xk_toMails");

                    txtMailId.Text = "";
                    txtMailName.Text = "";

                    cbMailGroup_SelectedIndexChanged(null, null);
                }
            }
        }
        #endregion

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (sendtimes < totalTask)
            {
                //Current Thread Plus
                if (currentTask < sendMailList.Items.Count)
                {
                    int oldTask = currentTask;
                    currentTask = sendtimes / StaticInfo.toMails.Count;
                    if (oldTask != currentTask)
                        currentThread = 0;
                }

                for (int i = 0; i < thread.Length; i++)
                {
                    if (currentThread >= StaticInfo.toMails.Count)
                        currentThread = 0;
                    if (thread[i] == null || thread[i].ThreadState == ThreadState.Stopped)
                    {
                        thread[i] = new Thread(SendMail);
                        thread[i].IsBackground = true;
                        thread[i].Name = currentTask + "," + currentThread;
                        thread[i].Start();
                        currentThread++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < thread.Length; i++)
                {
                    if (thread[i].ThreadState != ThreadState.Stopped)
                        return;
                }
                timer1.Stop();
                btnStartSend.Enabled = true;
                statMail.Text = "等待任务...";

                StreamReader sr = new StreamReader(Application.StartupPath + "\\log.txt");
                string oldlog = sr.ReadToEnd();
                sr.Close();
                StreamWriter sw = new StreamWriter(Application.StartupPath + "\\log.txt");
                for (int i = 0; i < logs.Count; i++)
                    sw.WriteLine(logs[i]);
                sw.WriteLine("//---------------------------------------------------------------------");
                sw.WriteLine();
                sw.WriteLine(oldlog);
                sw.Close();

                if (hasErr)
                {
                    ShowMsgBox("任务完成,但有错误发生");
                }
                else
                    ShowMsgBox("任务完成");
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Name == tabSendLog.Name)
            {
                StreamReader sr = new StreamReader(Application.StartupPath + "\\log.txt");
                string oldlog = sr.ReadToEnd();
                sr.Close();
                txtSendLog.Text = oldlog;
            }
        }

        private void btnClearLog_Click(object sender, EventArgs e)
        {
            StreamWriter sw = new StreamWriter(Application.StartupPath + "\\log.txt");
            sw.Write(string.Empty);
            sw.Close();
            txtSendLog.Text = string.Empty;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -