每次嘗試打印時顯示錯誤。它說「未實現的異常未被用戶代碼處理」。 如何解決這個問題! 這裏是我的代碼未實現的異常由用戶代碼未處理
namespace RunwayMedlinc
{
public partial class patient : Form
{
Print print;
MySqlConnection con;
String sql;
MySqlCommand cmd;
MySqlDataAdapter data, data2, data3;
DataTable table = new DataTable();
DataTable table2 = new DataTable();
DataTable table3 = new DataTable();
DataSet da = new DataSet();
int age;
public patient()
{
InitializeComponent();
}
public void view()
{
try
{
sql = "select p.mrn AS 'MRN', pp.name AS 'PATIENT NAME', pp.bday AS 'BIRTHDAY', p.age AS 'AGE', pp.gender AS 'GENDER', p.admit AS 'ADMIT DATE', p.discharge AS 'DISCHARGE DATE', p.md AS 'PHYSICIAN'FROM p inner join pp ON p.mrn=pp.mrn where admit like'%" + year.Text + "%' and admit like'%" + month.Text + "%'";
cmd = new MySqlCommand(sql, con);
data.SelectCommand = cmd;
pview.DataSource = table;
table.Clear();
data.Fill(table);
pview.DataSource = table;
}
catch (Exception exx)
{
MessageBox.Show(exx.Message, "Error");
}
}
public void bew()
{
try
{
sql = "select p.mrn AS 'MRN', pp.name AS 'PATIENT NAME', pp.bday AS 'BIRTHDAY', p.age AS 'AGE', pp.gender AS 'GENDER', p.admit AS 'ADMIT DATE', p.discharge AS 'DISCHARGE DATE', p.md AS 'PHYSICIAN'FROM p inner join pp ON p.mrn=pp.mrn where admit like'%" + year2.Text + "%' and admit like'%" + month2.Text + "%'";
cmd = new MySqlCommand(sql, con);
data2.SelectCommand = cmd;
pview2.DataSource = table2;
table2.Clear();
data2.Fill(table2);
}
catch (Exception exx)
{
MessageBox.Show(exx.Message, "Error");
}
}
private void search_Enter(object sender, EventArgs e)
{
if (search.ForeColor == Color.Gray)
{
search.Clear();
search.ForeColor = Color.Black;
}
}
private void search_Leave(object sender, EventArgs e)
{
if (search.Text == "")
{
search.ForeColor = Color.Gray;
search.Text = "SEARCH PATIENT...";
}
}
private void search2_Enter(object sender, EventArgs e)
{
if (search2.ForeColor == Color.Gray)
{
search2.Clear();
search2.ForeColor = Color.Black;
}
}
private void search2_Leave(object sender, EventArgs e)
{
if (search2.Text == "")
{
search2.ForeColor = Color.Gray;
search2.Text = "SEARCH PATIENT...";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
time.Text = DateTime.Now.ToString("h:mm:ss tt");
date.Text = DateTime.Now.ToString("MMMM d, yyyy");
}
private void patient_Load(object sender, EventArgs e)
{
con = new MySqlConnection();
con.ConnectionString = "server=Localhost;" + "username=root;" + "password=;" + "database=runway";
con.Open();
sql = "select mrn from p";
cmd = new MySqlCommand(sql, con);
data = new MySqlDataAdapter();
data2 = new MySqlDataAdapter();
month.Text = Convert.ToString(DateTime.Now.ToString("MMMM"));
year.Text = Convert.ToString(DateTime.Now.ToString("yyyy"));
month2.Text = Convert.ToString(DateTime.Now.ToString("MMMM"));
year2.Text = Convert.ToString(DateTime.Now.ToString("yyyy"));
view();
bew();
}
private void clear_Click(object sender, EventArgs e)
{
mrn.Clear();
name.Clear();
phy.Clear();
m.Checked = false;
f.Checked = false;
bdate.Value = DateTime.Now;
admit.Value = DateTime.Now;
disch.Value = DateTime.Now;
add.Enabled = true;
mrn.ReadOnly = false;
name.ReadOnly = false;
phy.ReadOnly = false;
m.Enabled = true;
f.Enabled = true;
bdate.Enabled = true;
admit.Enabled = true;
}
private void phy_Enter(object sender, EventArgs e)
{
if (phy.ReadOnly == false)
{
phy.Clear();
}
}
private void add_Click(object sender, EventArgs e)
{
if (mrn.Text == "" || name.Text == "" || (m.Checked == false && f.Checked == false))
{
MessageBox.Show("Please fill out all information.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
DateTime x = admit.Value;
DateTime y = bdate.Value;
if (x.Month < y.Month || (x.Month == y.Month && x.Day < y.Day))
{
age = x.Year - y.Year - 1;
}
else
{
age = x.Year - y.Year;
}
if (m.Checked == true)
{
if (name.ReadOnly == false)
{
sql = "insert into pp(mrn, name, gender, bday)values (?a, ?b, ?c, ?d)";
cmd = new MySqlCommand(sql, con);
cmd.Parameters.AddWithValue("?a", mrn.Text);
cmd.Parameters.AddWithValue("?b", name.Text);
cmd.Parameters.AddWithValue("?c", m.Text);
cmd.Parameters.AddWithValue("?d", bdate.Text);
cmd.ExecuteNonQuery();
}
}
if (f.Checked == true)
{
if (name.ReadOnly == false)
{
sql = "insert into pp(mrn, name, gender, bday)values (?a, ?b, ?c, ?d)";
cmd = new MySqlCommand(sql, con);
cmd.Parameters.AddWithValue("?a", mrn.Text);
cmd.Parameters.AddWithValue("?b", name.Text);
cmd.Parameters.AddWithValue("?c", f.Text);
cmd.Parameters.AddWithValue("?d", bdate.Text);
cmd.ExecuteNonQuery();
}
}
sql = "insert into p(mrn, admit, discharge, md, age)values (?a, ?e, ?f, ?g, ?z)";
cmd = new MySqlCommand(sql, con);
cmd.Parameters.AddWithValue("?a", mrn.Text);
cmd.Parameters.AddWithValue("?e", admit.Text);
cmd.Parameters.AddWithValue("?f", null);
cmd.Parameters.AddWithValue("?g", phy.Text);
cmd.Parameters.AddWithValue("?z", age);
cmd.ExecuteNonQuery();
MessageBox.Show("Patient Successfully Added!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
mrn.Clear();
name.Clear();
phy.Text = "MANGASEP, CONCEPCION R.";
m.Checked = false;
f.Checked = false;
bdate.Value = DateTime.Now;
admit.Value = DateTime.Now;
disch.Value = DateTime.Now;
month2.Text = Convert.ToString(DateTime.Now.ToString("MMMM"));
year2.Text = Convert.ToString(DateTime.Now.ToString("yyyy"));
bew();
}
}
private void search_TextChanged(object sender, EventArgs e)
{
if (search.ForeColor != Color.Gray)
{
try
{
sql = "select p.mrn AS 'MRN', pp.name AS 'PATIENT NAME', pp.bday AS 'BIRTHDAY', p.age AS 'AGE', pp.gender AS 'GENDER', p.admit AS 'ADMIT DATE', p.discharge AS 'DISCHARGE DATE', p.md AS 'PHYSICIAN'FROM p inner join pp ON p.mrn=pp.mrn where admit like'%" + year.Text + "%' and admit like'%" + month.Text + "%' and name like'%" + search.Text + "%'";
cmd = new MySqlCommand(sql, con);
data.SelectCommand = cmd;
pview.DataSource = table;
table.Clear();
data.Fill(table);
}
catch (Exception exx)
{
MessageBox.Show(exx.Message, "Error");
}
}
}
private void search2_TextChanged(object sender, EventArgs e)
{
if (search2.ForeColor != Color.Gray)
{
try
{
sql = "select p.mrn AS 'MRN', pp.name AS 'PATIENT NAME', pp.bday AS 'BIRTHDAY', p.age AS 'AGE', pp.gender AS 'GENDER', p.admit AS 'ADMIT DATE', p.discharge AS 'DISCHARGE DATE', p.md AS 'PHYSICIAN'FROM p inner join pp ON p.mrn=pp.mrn where admit like'%" + year2.Text + "%' and admit like'%" + month2.Text + "%' and name like'%" + search2.Text + "%'";
cmd = new MySqlCommand(sql, con);
data2.SelectCommand = cmd;
pview2.DataSource = table2;
table2.Clear();
data2.Fill(table2);
}
catch (Exception exx)
{
MessageBox.Show(exx.Message, "Error");
}
}
}
private void pview2_Click(object sender, EventArgs e)
{
mrn.Text = pview2.SelectedRows[0].Cells[0].Value.ToString();
name.Text = pview2.SelectedRows[0].Cells[1].Value.ToString();
if (pview2.SelectedRows[0].Cells[4].Value.ToString() == "MALE")
{
m.Checked = true;
}
else
{
f.Checked = true;
}
bdate.Text = pview2.SelectedRows[0].Cells[2].Value.ToString();
admit.Text = pview2.SelectedRows[0].Cells[5].Value.ToString();
phy.Text = pview2.SelectedRows[0].Cells[7].Value.ToString();
add.Enabled = false;
mrn.ReadOnly = true;
name.ReadOnly = true;
phy.ReadOnly = true;
m.Enabled = false;
f.Enabled = false;
bdate.Enabled = false;
admit.Enabled = false;
}
private void update_Click(object sender, EventArgs e)
{
sql = "Update p set discharge= '" + disch.Text + "' where mrn = '" + mrn.Text + "'";
cmd = new MySqlCommand(sql, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Patient Successfuly Updated!");
add.Enabled = true;
mrn.Clear();
mrn.ReadOnly = false;
name.Clear();
name.ReadOnly = false;
phy.Text = "MANGASEP, CONCEPCION R.";
phy.ReadOnly = false;
m.Checked = false;
f.Checked = false;
bdate.Value = DateTime.Now;
admit.Value = DateTime.Now;
disch.Value = DateTime.Now;
month2.Text = Convert.ToString(DateTime.Now.ToString("MMMM"));
year2.Text = Convert.ToString(DateTime.Now.ToString("yyyy"));
bew();
}
private void mrn_TextChanged(object sender, EventArgs e)
{
sql = "Select name, gender, bday from pp where mrn = '" + mrn.Text + "'";
cmd = new MySqlCommand(sql, con);
data3 = new MySqlDataAdapter();
data3.SelectCommand = cmd;
table3 = new DataTable();
data3.Fill(table3);
if (table3.Rows.Count > 0)
{
name.Text = Convert.ToString(table3.Rows[0][0]);
if (Convert.ToString(table3.Rows[0][1]) == "MALE")
{
m.Checked = true; ;
}
else
{
f.Checked = true;
}
bdate.Value = Convert.ToDateTime(table3.Rows[0][2]);
name.ReadOnly = true;
m.Enabled = false;
f.Enabled = false;
bdate.Enabled = false;
}
else
{
name.Clear();
m.Checked = false;
f.Checked = false;
bdate.Value = DateTime.Now;
name.ReadOnly = false;
m.Enabled = true;
f.Enabled = true;
bdate.Enabled = true;
}
}
private void year_SelectedIndexChanged(object sender, EventArgs e)
{
view();
}
private void month_SelectedIndexChanged(object sender, EventArgs e)
{
view();
}
private void mrn_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != '.'))
{
e.Handled = true;
}
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
month.Text = Convert.ToString(DateTime.Now.ToString("MMMM"));
year.Text = Convert.ToString(DateTime.Now.ToString("yyyy"));
month2.Text = Convert.ToString(DateTime.Now.ToString("MMMM"));
year2.Text = Convert.ToString(DateTime.Now.ToString("yyyy"));
search.ForeColor = Color.Gray;
search.Text = "SEARCH PATIENT...";
search2.ForeColor = Color.Gray;
search2.Text = "SEARCH PATIENT...";
mrn.Clear();
name.Clear();
phy.Text = "MANGASEP, CONCEPCION R.";
m.Checked = false;
f.Checked = false;
bdate.Value = DateTime.Now;
admit.Value = DateTime.Now;
disch.Value = DateTime.Now;
}
private void month2_SelectedIndexChanged(object sender, EventArgs e)
{
bew();
}
private void year2_SelectedIndexChanged(object sender, EventArgs e)
{
bew();
}
private bool SetupThePrinting()
{
PrintDialog MyPrintDialog = new PrintDialog();
MyPrintDialog.AllowCurrentPage = false;
MyPrintDialog.AllowPrintToFile = false;
MyPrintDialog.AllowSelection = false;
MyPrintDialog.AllowSomePages = false;
MyPrintDialog.PrintToFile = false;
MyPrintDialog.ShowHelp = false;
MyPrintDialog.ShowNetwork = false;
if (MyPrintDialog.ShowDialog() != DialogResult.OK)
return false;
dokumento.DocumentName = "List of Patients";
dokumento.PrinterSettings = MyPrintDialog.PrinterSettings;
dokumento.DefaultPageSettings = MyPrintDialog.PrinterSettings.DefaultPageSettings;
dokumento.DefaultPageSettings.Landscape = false;
dokumento.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(10, 10, 10, 10);
dokumento.DefaultPageSettings.Landscape = MyPrintDialog.PrinterSettings.DefaultPageSettings.Landscape;
print = new Print(pview, dokumento, true, true, Environment.NewLine + "" + Environment.NewLine + "" + "Runway Medlinc" + Environment.NewLine + "" + Environment.NewLine + "List of Patients"
+ Environment.NewLine + "" + Environment.NewLine + month.Text + " " + year.Text, new Font("Times New Roman", 12, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);
return true;
}
private void printer_Click(object sender, EventArgs e)
{
if (SetupThePrinting())
{
PrintPreviewDialog MyPrintPreviewDialog = new PrintPreviewDialog();
MyPrintPreviewDialog.Document = dokumento;
MyPrintPreviewDialog.ShowDialog();
dokumento.Print();
}
}
private void dokumento_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
bool more = print.DrawDataGridView(e.Graphics);
if (more == true)
e.HasMorePages = true;
}
}
}
每次我嘗試打印錯誤出現。它說「未實現的異常未被用戶代碼處理」。 如何解決這個問題! 和其他類是在這裏
namespace RunwayMedlinc
{
class Print
{
private System.Windows.Forms.DataGridView pview;
private System.Drawing.Printing.PrintDocument dokumento;
private bool p;
private bool p_2;
private string p_3;
private System.Drawing.Font font;
private System.Drawing.Color color;
private bool p_4;
public Print(System.Windows.Forms.DataGridView pview, System.Drawing.Printing.PrintDocument dokumento, bool p, bool p_2, string p_3, System.Drawing.Font font, System.Drawing.Color color, bool p_4)
{
this.pview = pview;
this.dokumento = dokumento;
this.p = p;
this.p_2 = p_2;
this.p_3 = p_3;
this.font = font;
this.color = color;
this.p_4 = p_4;
}
internal bool DrawDataGridView(System.Drawing.Graphics graphics)
{
throw new NotImplementedException();
}
}
}
如何在Print類中實現DrawDataGridView方法? –