コード例 #1
0
        private void CancelSend(object sender)
        {
            SendMailInvoke  mi      = new SendMailInvoke(invokeSendMail);
            MySqlConnection Conn    = new MySqlConnection(sManager.GetConnStr());
            MySqlCommand    setname = new MySqlCommand("set names 'gbk';", Conn);
            MySqlCommand    chgDB   = new MySqlCommand("USE " + ServerManager.CharactersDB + ";", Conn);

            try
            {
                this.Invoke(mi, new object[] { 1, "正在取消..." });
                this.Invoke(mi, new object[] { 2, string.Empty });
                this.Invoke(mi, new object[] { 3, "0" });
                Conn.Open();
                setname.ExecuteNonQuery();
                setname.Dispose();
                chgDB.ExecuteNonQuery();
                chgDB.Dispose();
                MySqlCommand unsetAuto_Increment = new MySqlCommand("alter table mail modify id int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                unsetAuto_Increment = new MySqlCommand("alter table item_text modify id int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                unsetAuto_Increment = new MySqlCommand("alter table item_instance modify guid int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                int CurrentDelPos      = 0;
                int CurrentDelProgress = 0;
                int TotalDelCount      = Inserted_item_text.Count + Inserted_item_instance.Count + Inserted_mail.Count * 2;
                this.Invoke(mi, new object[] { 2, "删除邮件内容..." });
                foreach (string str in Inserted_item_text)
                {
                    CurrentDelPos++;
                    this.Invoke(mi, new object[] { 2, "删除邮件内容..." + CurrentDelPos.ToString() + "/" + Inserted_item_text.Count });
                    MySqlCommand Del_item_text = new MySqlCommand("DELETE FROM item_text WHERE id='" + str + "';", Conn);
                    Del_item_text.ExecuteNonQuery();
                    CurrentDelProgress++;
                    this.Invoke(mi, new object[] { 3, (CurrentDelProgress * 1000 / TotalDelCount).ToString() });
                }
                CurrentDelPos = 0;
                this.Invoke(mi, new object[] { 2, "删除物品信息..." });
                foreach (string str in Inserted_item_instance)
                {
                    CurrentDelPos++;
                    this.Invoke(mi, new object[] { 2, "删除物品信息..." + CurrentDelPos.ToString() + "/" + Inserted_item_instance.Count });
                    MySqlCommand Del_item_instance = new MySqlCommand("DELETE FROM item_instance WHERE guid='" + str + "';", Conn);
                    Del_item_instance.ExecuteNonQuery();
                    CurrentDelProgress++;
                    this.Invoke(mi, new object[] { 3, (CurrentDelProgress * 1000 / TotalDelCount).ToString() });
                }
                CurrentDelPos = 0;
                this.Invoke(mi, new object[] { 2, "删除邮件信息..." });
                foreach (string str in Inserted_mail)
                {
                    CurrentDelPos++;
                    this.Invoke(mi, new object[] { 2, "删除邮件信息..." + CurrentDelPos.ToString() + "/" + Inserted_mail.Count });
                    MySqlCommand Del_mail       = new MySqlCommand("DELETE FROM mail WHERE id='" + str + "';", Conn);
                    MySqlCommand Del_mail_items = new MySqlCommand("DELETE FROM mail_items WHERE mail_id='" + str + "';", Conn);
                    Del_mail.ExecuteNonQuery();
                    CurrentDelProgress++;
                    this.Invoke(mi, new object[] { 3, (CurrentDelProgress * 1000 / TotalDelCount).ToString() });
                    Del_mail_items.ExecuteNonQuery();
                    CurrentDelProgress++;
                    this.Invoke(mi, new object[] { 3, (CurrentDelProgress * 1000 / TotalDelCount).ToString() });
                }
                foreach (DataRow dr in this.SendMailResault.Tables[0].Rows)
                {
                    if (dr[4].ToString() == "已发送")
                    {
                        dr[4] = "已取消";
                    }
                }
                this.Invoke(mi, new object[] { 0, "用户取消了发送" });
            }
            catch (Exception err)
            {
                this.Invoke(mi, new object[] { 5, err.Message });
            }
        }
コード例 #2
0
        private void SendMail(object sender)
        {
            SendMailInvoke mi = new SendMailInvoke(invokeSendMail);
            MySqlConnection Conn = new MySqlConnection(sManager.GetConnStr());
            MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
            MySqlCommand chgDB = new MySqlCommand("USE " + ServerManager.CharactersDB + ";", Conn);
            try
            {
                Conn.Open();
                setname.ExecuteNonQuery();
                setname.Dispose();
                chgDB.ExecuteNonQuery();
                chgDB.Dispose();
                MySqlCommand setAuto_Increment = new MySqlCommand("alter table mail modify id int not null auto_increment;", Conn);
                setAuto_Increment.ExecuteNonQuery();
                setAuto_Increment = new MySqlCommand("alter table item_text modify id int not null auto_increment;", Conn);
                setAuto_Increment.ExecuteNonQuery();
                setAuto_Increment = new MySqlCommand("alter table item_instance modify guid int not null auto_increment;", Conn);
                setAuto_Increment.ExecuteNonQuery();
                setAuto_Increment.Dispose();
                foreach (DataRow dr in ReceiversSet.Tables[0].Rows)
                {
                    SendMailResault.Tables[0].Rows.Add(new object[] { dr[0], dr[1], dr[2], dr[3], "未发送" });
                }
                int ReceiversCount = SendMailResault.Tables[0].Rows.Count;
                this.Invoke(mi, new object[] { 1, "正在发送..." });
                for (int CurrentReceiver = 0; CurrentReceiver < ReceiversCount; CurrentReceiver++)
                {
                    this.Invoke(mi, new object[] { 1, "正在发送..." + (CurrentReceiver + 1).ToString() + "/" + ReceiversCount.ToString() });
                    this.Invoke(mi, new object[] { 3, (CurrentReceiver * 1000 / ReceiversCount).ToString() });
                    int CurrentProgress = CurrentReceiver * 1000 / ReceiversCount;
                    int InsertProgress = 2;
                    int CurrentInsertProgress = 0;
                    int has_items = 0;
                    int TotalItemsCount = 0;
                    int CurrentItemsCount = 0;
                    if (ItemsSet.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in ItemsSet.Tables[0].Rows)
                        {
                            TotalItemsCount += Convert.ToInt32(dr[1]);
                        }
                        has_items = 1;
                        InsertProgress = TotalItemsCount * 2 + 2;
                    }
                    this.Invoke(mi, new object[] { 2, "插入邮件内容" });
                    MySqlCommand InsertMail = new MySqlCommand("INSERT INTO item_text(text) VALUES('" + MailText + "');", Conn);
                    InsertMail.ExecuteNonQuery();
                    InsertMail = new MySqlCommand("SELECT LAST_INSERT_ID();", Conn);
                    object Current_item_text_id = InsertMail.ExecuteScalar();
                    Inserted_item_text.Add(Current_item_text_id);
                    CurrentInsertProgress++;
                    this.Invoke(mi, new object[] { 3, (CurrentProgress + 1000 / ReceiversCount * CurrentInsertProgress / InsertProgress).ToString() });
                    this.Invoke(mi, new object[] { 2, "插入邮件信息" });
                    InsertMail = new MySqlCommand("INSERT INTO mail(messageType, stationery, mailTemplateId, sender, receiver, subject, itemTextId, has_items, expire_time, deliver_time, money, cod, checked) VALUES(0, 61, 0, 0, " + this.ReceiversSet.Tables[0].Rows[CurrentReceiver][2].ToString() + ", '" + MailTittle + "', " + Current_item_text_id.ToString() + ", " + has_items.ToString() + ", " + this.ExpireTime + ", " + this.DeliverTime + ", 0, 0, 0);", Conn);
                    InsertMail.ExecuteNonQuery();
                    InsertMail = new MySqlCommand("SELECT LAST_INSERT_ID();", Conn);
                    object Current_mail_id = InsertMail.ExecuteScalar();
                    Inserted_mail.Add(Current_mail_id);
                    CurrentInsertProgress++;
                    this.Invoke(mi, new object[] { 3, (CurrentProgress + 1000 / ReceiversCount * CurrentInsertProgress / InsertProgress).ToString() });
                    if (ItemsSet.Tables[0].Rows.Count > 0)
                    {

                        foreach (DataRow ItemRow in ItemsSet.Tables[0].Rows)
                        {
                            for (int InsertItemRepeatCount = 0; InsertItemRepeatCount < Convert.ToInt32(ItemRow[1]); InsertItemRepeatCount++)
                            {
                                CurrentItemsCount++;
                                this.Invoke(mi, new object[] { 2, "插入物品信息..."+CurrentItemsCount.ToString()+"/"+TotalItemsCount.ToString() });
                                MySqlCommand InsertItem = new MySqlCommand("INSERT INTO item_instance(owner_guid,data) VALUES(0,null);", Conn);
                                InsertItem.ExecuteNonQuery();
                                InsertItem = new MySqlCommand("SELECT LAST_INSERT_ID();", Conn);
                                object Current_item_instance_guid = InsertItem.ExecuteScalar();
                                Inserted_item_instance.Add(Current_item_instance_guid);
                                CurrentInsertProgress++;
                                this.Invoke(mi, new object[] { 3, (CurrentProgress + 1000 / ReceiversCount * CurrentInsertProgress / InsertProgress).ToString() });
                                InsertItem = new MySqlCommand("UPDATE item_instance SET data='" + Current_item_instance_guid.ToString() + " 1073741824 3 " + ItemRow[0].ToString() + " 1065353216 0 0 0 0 0 0 0 0 0 " + ItemRow[1].ToString() + " 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ' WHERE guid='" + Current_item_instance_guid.ToString() + "';", Conn);
                                InsertItem.ExecuteNonQuery();
                                InsertItem = new MySqlCommand("INSERT INTO mail_items(mail_id,item_guid,item_template,receiver) VALUES(" + Current_mail_id.ToString() + "," + Current_item_instance_guid + "," + ItemRow[0].ToString() + "," + this.ReceiversSet.Tables[0].Rows[CurrentReceiver][2].ToString() + ");", Conn);
                                InsertItem.ExecuteNonQuery();
                                CurrentInsertProgress++;
                                this.Invoke(mi, new object[] { 3, (CurrentProgress + 1000 / ReceiversCount * CurrentInsertProgress / InsertProgress).ToString() });
                            }
                        }
                    }
                    this.SendMailResault.Tables[0].Rows[CurrentReceiver][4] = "已发送";
                }
                MySqlCommand unsetAuto_Increment = new MySqlCommand("alter table mail modify id int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                unsetAuto_Increment = new MySqlCommand("alter table item_text modify id int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                unsetAuto_Increment = new MySqlCommand("alter table item_instance modify guid int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                this.Invoke(mi, new object[] { 4, "成功发送" + Inserted_mail.Count.ToString() + "封邮件" });

            }
            catch (Exception err)
            {
                if(err.Message!=string.Empty)
                    this.Invoke(mi, new object[] { 0, err.Message });
            }
            finally
            {
                Conn.Close();
            }
        }
コード例 #3
0
        private void SendMail(object sender)
        {
            SendMailInvoke  mi      = new SendMailInvoke(invokeSendMail);
            MySqlConnection Conn    = new MySqlConnection(sManager.GetConnStr());
            MySqlCommand    setname = new MySqlCommand("set names 'gbk';", Conn);
            MySqlCommand    chgDB   = new MySqlCommand("USE " + ServerManager.CharactersDB + ";", Conn);

            try
            {
                Conn.Open();
                setname.ExecuteNonQuery();
                setname.Dispose();
                chgDB.ExecuteNonQuery();
                chgDB.Dispose();
                MySqlCommand setAuto_Increment = new MySqlCommand("alter table mail modify id int not null auto_increment;", Conn);
                setAuto_Increment.ExecuteNonQuery();
                setAuto_Increment = new MySqlCommand("alter table item_text modify id int not null auto_increment;", Conn);
                setAuto_Increment.ExecuteNonQuery();
                setAuto_Increment = new MySqlCommand("alter table item_instance modify guid int not null auto_increment;", Conn);
                setAuto_Increment.ExecuteNonQuery();
                setAuto_Increment.Dispose();
                foreach (DataRow dr in ReceiversSet.Tables[0].Rows)
                {
                    SendMailResault.Tables[0].Rows.Add(new object[] { dr[0], dr[1], dr[2], dr[3], "未发送" });
                }
                int ReceiversCount = SendMailResault.Tables[0].Rows.Count;
                this.Invoke(mi, new object[] { 1, "正在发送..." });
                for (int CurrentReceiver = 0; CurrentReceiver < ReceiversCount; CurrentReceiver++)
                {
                    this.Invoke(mi, new object[] { 1, "正在发送..." + (CurrentReceiver + 1).ToString() + "/" + ReceiversCount.ToString() });
                    this.Invoke(mi, new object[] { 3, (CurrentReceiver * 1000 / ReceiversCount).ToString() });
                    int CurrentProgress       = CurrentReceiver * 1000 / ReceiversCount;
                    int InsertProgress        = 2;
                    int CurrentInsertProgress = 0;
                    int has_items             = 0;
                    int TotalItemsCount       = 0;
                    int CurrentItemsCount     = 0;
                    if (ItemsSet.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in ItemsSet.Tables[0].Rows)
                        {
                            TotalItemsCount += Convert.ToInt32(dr[1]);
                        }
                        has_items      = 1;
                        InsertProgress = TotalItemsCount * 2 + 2;
                    }
                    this.Invoke(mi, new object[] { 2, "插入邮件内容" });
                    MySqlCommand InsertMail = new MySqlCommand("INSERT INTO item_text(text) VALUES('" + MailText + "');", Conn);
                    InsertMail.ExecuteNonQuery();
                    InsertMail = new MySqlCommand("SELECT LAST_INSERT_ID();", Conn);
                    object Current_item_text_id = InsertMail.ExecuteScalar();
                    Inserted_item_text.Add(Current_item_text_id);
                    CurrentInsertProgress++;
                    this.Invoke(mi, new object[] { 3, (CurrentProgress + 1000 / ReceiversCount * CurrentInsertProgress / InsertProgress).ToString() });
                    this.Invoke(mi, new object[] { 2, "插入邮件信息" });
                    InsertMail = new MySqlCommand("INSERT INTO mail(messageType, stationery, mailTemplateId, sender, receiver, subject, itemTextId, has_items, expire_time, deliver_time, money, cod, checked) VALUES(0, 61, 0, 0, " + this.ReceiversSet.Tables[0].Rows[CurrentReceiver][2].ToString() + ", '" + MailTittle + "', " + Current_item_text_id.ToString() + ", " + has_items.ToString() + ", " + this.ExpireTime + ", " + this.DeliverTime + ", 0, 0, 0);", Conn);
                    InsertMail.ExecuteNonQuery();
                    InsertMail = new MySqlCommand("SELECT LAST_INSERT_ID();", Conn);
                    object Current_mail_id = InsertMail.ExecuteScalar();
                    Inserted_mail.Add(Current_mail_id);
                    CurrentInsertProgress++;
                    this.Invoke(mi, new object[] { 3, (CurrentProgress + 1000 / ReceiversCount * CurrentInsertProgress / InsertProgress).ToString() });
                    if (ItemsSet.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow ItemRow in ItemsSet.Tables[0].Rows)
                        {
                            for (int InsertItemRepeatCount = 0; InsertItemRepeatCount < Convert.ToInt32(ItemRow[1]); InsertItemRepeatCount++)
                            {
                                CurrentItemsCount++;
                                this.Invoke(mi, new object[] { 2, "插入物品信息..." + CurrentItemsCount.ToString() + "/" + TotalItemsCount.ToString() });
                                MySqlCommand InsertItem = new MySqlCommand("INSERT INTO item_instance(owner_guid,data) VALUES(0,null);", Conn);
                                InsertItem.ExecuteNonQuery();
                                InsertItem = new MySqlCommand("SELECT LAST_INSERT_ID();", Conn);
                                object Current_item_instance_guid = InsertItem.ExecuteScalar();
                                Inserted_item_instance.Add(Current_item_instance_guid);
                                CurrentInsertProgress++;
                                this.Invoke(mi, new object[] { 3, (CurrentProgress + 1000 / ReceiversCount * CurrentInsertProgress / InsertProgress).ToString() });
                                InsertItem = new MySqlCommand("UPDATE item_instance SET data='" + Current_item_instance_guid.ToString() + " 1073741824 3 " + ItemRow[0].ToString() + " 1065353216 0 0 0 0 0 0 0 0 0 " + ItemRow[1].ToString() + " 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ' WHERE guid='" + Current_item_instance_guid.ToString() + "';", Conn);
                                InsertItem.ExecuteNonQuery();
                                InsertItem = new MySqlCommand("INSERT INTO mail_items(mail_id,item_guid,item_template,receiver) VALUES(" + Current_mail_id.ToString() + "," + Current_item_instance_guid + "," + ItemRow[0].ToString() + "," + this.ReceiversSet.Tables[0].Rows[CurrentReceiver][2].ToString() + ");", Conn);
                                InsertItem.ExecuteNonQuery();
                                CurrentInsertProgress++;
                                this.Invoke(mi, new object[] { 3, (CurrentProgress + 1000 / ReceiversCount * CurrentInsertProgress / InsertProgress).ToString() });
                            }
                        }
                    }
                    this.SendMailResault.Tables[0].Rows[CurrentReceiver][4] = "已发送";
                }
                MySqlCommand unsetAuto_Increment = new MySqlCommand("alter table mail modify id int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                unsetAuto_Increment = new MySqlCommand("alter table item_text modify id int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                unsetAuto_Increment = new MySqlCommand("alter table item_instance modify guid int not null;", Conn);
                unsetAuto_Increment.ExecuteNonQuery();
                this.Invoke(mi, new object[] { 4, "成功发送" + Inserted_mail.Count.ToString() + "封邮件" });
            }
            catch (Exception err)
            {
                if (err.Message != string.Empty)
                {
                    this.Invoke(mi, new object[] { 0, err.Message });
                }
            }
            finally
            {
                Conn.Close();
            }
        }
コード例 #4
0
 private void CancelSend(object sender)
 {
     SendMailInvoke mi = new SendMailInvoke(invokeSendMail);
     MySqlConnection Conn = new MySqlConnection(sManager.GetConnStr());
     MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
     MySqlCommand chgDB = new MySqlCommand("USE " + ServerManager.CharactersDB + ";", Conn);
     try
     {
         this.Invoke(mi, new object[] { 1, "正在取消..." });
         this.Invoke(mi, new object[] { 2, string.Empty });
         this.Invoke(mi, new object[] { 3, "0" });
         Conn.Open();
         setname.ExecuteNonQuery();
         setname.Dispose();
         chgDB.ExecuteNonQuery();
         chgDB.Dispose();
         MySqlCommand unsetAuto_Increment = new MySqlCommand("alter table mail modify id int not null;", Conn);
         unsetAuto_Increment.ExecuteNonQuery();
         unsetAuto_Increment = new MySqlCommand("alter table item_text modify id int not null;", Conn);
         unsetAuto_Increment.ExecuteNonQuery();
         unsetAuto_Increment = new MySqlCommand("alter table item_instance modify guid int not null;", Conn);
         unsetAuto_Increment.ExecuteNonQuery();
         int CurrentDelPos = 0;
         int CurrentDelProgress = 0;
         int TotalDelCount = Inserted_item_text.Count + Inserted_item_instance.Count + Inserted_mail.Count * 2;
         this.Invoke(mi, new object[] { 2, "删除邮件内容..." });
         foreach (string str in Inserted_item_text)
         {
             CurrentDelPos++;
             this.Invoke(mi, new object[] { 2, "删除邮件内容..." + CurrentDelPos.ToString() + "/" + Inserted_item_text.Count });
             MySqlCommand Del_item_text = new MySqlCommand("DELETE FROM item_text WHERE id='" + str + "';", Conn);
             Del_item_text.ExecuteNonQuery();
             CurrentDelProgress++;
             this.Invoke(mi, new object[] { 3, (CurrentDelProgress * 1000 / TotalDelCount).ToString() });
         }
         CurrentDelPos = 0;
         this.Invoke(mi, new object[] { 2, "删除物品信息..." });
         foreach (string str in Inserted_item_instance)
         {
             CurrentDelPos++;
             this.Invoke(mi, new object[] { 2, "删除物品信息..." + CurrentDelPos.ToString() + "/" + Inserted_item_instance.Count });
             MySqlCommand Del_item_instance = new MySqlCommand("DELETE FROM item_instance WHERE guid='" + str + "';", Conn);
             Del_item_instance.ExecuteNonQuery();
             CurrentDelProgress++;
             this.Invoke(mi, new object[] { 3, (CurrentDelProgress * 1000 / TotalDelCount).ToString() });
         }
         CurrentDelPos = 0;
         this.Invoke(mi, new object[] { 2, "删除邮件信息..." });
         foreach (string str in Inserted_mail)
         {
             CurrentDelPos++;
             this.Invoke(mi, new object[] { 2, "删除邮件信息..." + CurrentDelPos.ToString() + "/" + Inserted_mail.Count });
             MySqlCommand Del_mail = new MySqlCommand("DELETE FROM mail WHERE id='" + str + "';", Conn);
             MySqlCommand Del_mail_items = new MySqlCommand("DELETE FROM mail_items WHERE mail_id='" + str + "';", Conn);
             Del_mail.ExecuteNonQuery();
             CurrentDelProgress++;
             this.Invoke(mi, new object[] { 3, (CurrentDelProgress * 1000 / TotalDelCount).ToString() });
             Del_mail_items.ExecuteNonQuery();
             CurrentDelProgress++;
             this.Invoke(mi, new object[] { 3, (CurrentDelProgress * 1000 / TotalDelCount).ToString() });
         }
         foreach (DataRow dr in this.SendMailResault.Tables[0].Rows)
         {
             if (dr[4].ToString() == "已发送")
                 dr[4] = "已取消";
         }
         this.Invoke(mi, new object[] { 0, "用户取消了发送" });
     }
     catch (Exception err)
     {
         this.Invoke(mi, new object[] { 5, err.Message });
     }
 }