未实现的异常未被用户代码处理

时间:2017-07-08 07:01:30

标签: c# mysql database visual-studio visual-studio-2010

每次我尝试打印错误都会显示出来。 它说“未实现的异常未被用户代码处理”。 如何解决这个问题? 这是我的代码

(a ** b) % 10

每次我尝试打印错误都会显示出来。 它说“未实现的异常未被用户代码处理”。 如何解决这个问题? 而另一个班级在这里

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;
     }

}
}

3 个答案:

答案 0 :(得分:2)

您必须在DrawDataGridView课程中实施Print方法。

答案 1 :(得分:1)

PrintDocument本身无法知道你想要打印什么。你告诉它格式化,但不是内容。

告诉它的方法是使用System.Drawing命名空间来绘制文档,使用事件的Graphics属性作为输出设备。输出设备是一个打印机驱动程序,它会将您的行,文本等转换为适当的代码,以便在特定的打印机上呈现,例如:后记,PCL,等等。这对你来说并不重要。您只需要在虚拟的二维空间中输出文本,线条和图像。

所以

  1. 将这些方法重新放回

  2. 实施DrawDataGridView !!!现在就做一些简单的事情让你知道它有效,比如

    internal bool DrawDataGridView(System.Drawing.Graphics graphics)
    {
        graphics.DrawString("Hello world!");
    }
    
  3. 一旦你有了这个工作,接下来你必须弄清楚如何正确地呈现文档的内容。但那可能是另一个问题。

答案 2 :(得分:0)

internal bool DrawDataGridView(System.Drawing.Graphics graphics)
{
    throw new NotImplementedException();
}

throw行造成了问题。您需要删除该行并在那里添加实现。