private void btnSend_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; var mail = new Mail(con.charconn); string exp = DateTimeToUnixTimestamp(dtpExp.Value).ToString().Split(',')[0]; string del = DateTimeToUnixTimestamp(dtpDel.Value).ToString().Split(',')[0]; mail.Delivery = del; mail.Expire = exp; mail.COD = rdbCOD.Checked; for (int i = 0; i < lstAtt.Items.Count; i++) { var item = new Item(); item.Entry = int.Parse(lstAtt.Items[i].ToString().Split('{', '}')[1]); item.Quantity = int.Parse(lstAtt.Items[i].ToString().Split('[', ']')[1]); mail.Items.Add(item); } if (selnames.Count < 1) { MessageBox.Show(this, "Please select at least one receiver.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } if (txtBody.Text == "") { MessageBox.Show(this, "Please enter a body message.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } if (txtSubject.Text == "") { MessageBox.Show(this, "Please enter a subject.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } List <int> guids = new List <int>(); int stationary = 0; int ssender = -1; Int64 money = 0; int hasitems = 0; int type = 0; mail.Sender = -1; MySqlCommand cmd0 = new MySqlCommand("SELECT `guid` FROM `characters` WHERE `name`='" + txtSender.Text + "' LIMIT 1;", con.charconn); MySqlDataReader reader0 = cmd0.ExecuteReader(); while (reader0.Read()) { mail.Sender = reader0.GetInt32("guid"); } reader0.Close(); if (mail.Sender == -1) { type = 3; cmd0 = new MySqlCommand("SELECT `entry` FROM `creature_template` WHERE `name`='" + txtSender.Text + "';", con.worldconn); reader0 = cmd0.ExecuteReader(); while (reader0.Read()) { mail.Sender = reader0.GetInt32("entry"); } reader0.Close(); if (mail.Sender == -1) { MessageBox.Show(this, "NPC not found, remember that the sender field is case sensetive!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } } for (int i = 0; i < selnames.Count; i++) { MySqlCommand cmd = new MySqlCommand("SELECT `guid` FROM `characters` WHERE `name`='" + selnames[i] + "' LIMIT 1;", con.charconn); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { mail.Receivers.Add(reader.GetInt32("guid")); } reader.Close(); } switch (txtStyle.SelectedIndex) { case 0: mail.Style = 41; break; case 1: mail.Style = 61; break; case 2: mail.Style = 62; break; case 3: mail.Style = 64; break; case 4: mail.Style = 65; break; case 5: mail.Style = 1; break; } money = Convert.ToInt64(c.Value); money += Convert.ToInt64(s.Value * 100); money += Convert.ToInt64(g.Value * 10000); mail.Cash = money; if (lstAtt.Items.Count > 0) { hasitems = 1; } mail.Body = txtBody.Text; mail.Subject = txtSubject.Text; DialogResult dr; while (true) { //Exception ex = con.ExecuteMail(txtSubject.Text.Replace("'", "`"), stationary, txtBody.Text.Replace("'", "`"), guids, ssender, money.ToString(), hasitems, type, false, del.ToString(), exp.ToString()); MySqlException ex = mail.Send(); if (ex != null) { dr = MessageBox.Show(this, "Something went wrong. Error message:\n" + ex.Message, "Error!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (dr == System.Windows.Forms.DialogResult.Cancel) { break; } } else { MessageBox.Show(this, "Success! The mail will appear in the characters' inbox after one relog.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } } this.Cursor = Cursors.Default; }
private void btnSend_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; var mail = new Mail(con.charconn); string exp = DateTimeToUnixTimestamp(dtpExp.SelectionRange.Start).ToString().Split(',')[0]; string del = DateTimeToUnixTimestamp(dtpDel.SelectionRange.Start).ToString().Split(',')[0]; mail.Delivery = del; mail.Expire = exp; mail.COD = rdbCOD.Checked; foreach (ListViewItem item in lstSelectedItems.Items) { var itemselected = new Item(); itemselected.Entry = int.Parse(item.Text); itemselected.Quantity = int.Parse(item.SubItems[2].Text); mail.Items.Add(itemselected); } if (selnames.Count < 1) { MessageBox.Show(this, "Please select at least one receiver.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } if (txtBody.Text == "") { MessageBox.Show(this, "Please enter a body message.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } if (txtSubject.Text == "") { MessageBox.Show(this, "Please enter a subject.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } List<int> guids = new List<int>(); mail.Type = 0; mail.Sender = -1; int stationary = 0; int ssender = -1; Int64 money = 0; int hasitems = 0; int type = 0; MySqlCommand cmd0 = new MySqlCommand("SELECT `guid` FROM `characters` WHERE `name`='" + txtSender.Text + "' LIMIT 1;", con.charconn); MySqlDataReader reader0 = cmd0.ExecuteReader(); while (reader0.Read()) mail.Sender = reader0.GetInt32("guid"); reader0.Close(); if (mail.Sender == -1) { mail.Type = 3; cmd0 = new MySqlCommand("SELECT `entry` FROM `creature_template` WHERE `name`='" + txtSender.Text + "';", con.worldconn); reader0 = cmd0.ExecuteReader(); while (reader0.Read()) { mail.Sender = reader0.GetInt32("entry"); } reader0.Close(); if (mail.Sender == -1) { MessageBox.Show(this, "NPC not found, remember that the sender field is case sensetive!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } } for (int i = 0; i < selnames.Count; i++) { MySqlCommand cmd = new MySqlCommand("SELECT `guid` FROM `characters` WHERE `name`='" + selnames[i] + "' LIMIT 1;", con.charconn); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) mail.Receivers.Add(reader.GetInt32("guid")); reader.Close(); } switch (txtStyle.SelectedIndex) { case 0: mail.Style = 41; break; case 1: mail.Style = 61; break; case 2: mail.Style = 62; break; case 3: mail.Style = 64; break; case 4: mail.Style = 65; break; case 5: mail.Style = 1; break; } money = Convert.ToInt64(c.Value); money += Convert.ToInt64(s.Value * 100); money += Convert.ToInt64(g.Value * 10000); mail.Cash = money; if (lstSelectedItems.Items.Count > 0) hasitems = 1; mail.Body = txtBody.Text; mail.Subject = txtSubject.Text; DialogResult dr; while (true) { //Exception ex = con.ExecuteMail(txtSubject.Text.Replace("'", "`"), stationary, txtBody.Text.Replace("'", "`"), guids, ssender, money.ToString(), hasitems, type, false, del.ToString(), exp.ToString()); MySqlException ex = mail.Send(); if (ex != null) { dr = MessageBox.Show(this, "Something went wrong. Error message:\n" + ex.Message, "Error!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (dr == System.Windows.Forms.DialogResult.Cancel) break; } else { MessageBox.Show(this, "Success! The mail will appear in the characters' inbox after one relog.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } } this.Cursor = Cursors.Default; }