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

📄 入库登记.cs

📁 本人课程设计时开发的一个医院管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing.Printing;

namespace WindowsApplication1
{
    public partial class 入库登记 : Form
    {
        SqlCommand cmd;
        DataSet ds=new DataSet();
        SqlDataReader dr;
        SqlDataAdapter da;
        SqlConnection cn = new SqlConnection();

        PrintDialog pdlg = new PrintDialog();
        internal PrintDocument PDoc = new PrintDocument();
        internal PrintDocument PDoc2 = new PrintDocument();

        public 入库登记()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            PDoc.PrintPage += new PrintPageEventHandler(PDoc_PrintPage);

            cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
            cn.Open();

            cmd = new SqlCommand("Select * from Medicine_In", cn);
            da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            da.Fill(ds, "MedicineIn");
            DataTable dt = ds.Tables["MedicineIn"];
            label6.Text = "000"+dt.Rows.Count.ToString()+ dateTimePicker1.Value.ToString();

            cmd = new SqlCommand("Select Medicine_Code,Medicine_Name from Medicine_Store", cn);
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                comboBox1.Items.Add(dr["Medicine_Code"].ToString());
                comboBox2.Items.Add(dr["Medicine_Name"].ToString());
            }

            cn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
            cn.Open();

            SqlTransaction tran = null;
            try
            {
                tran = cn.BeginTransaction();
                SqlCommand cmd = new SqlCommand("insert into Medicine_In(MedicineIn_Code,Provider_Code,Provider_Name,Medicine_Code,Amount,Money,MedicineIn_Date,Man,Remark)values(@MedicineIn_Code,@Provider_Code,@Provider_Name,@Medicine_Code,@Amount,@Money,@MedicineIn_Date,@Man,@Remark)", cn, tran);
                cmd.Parameters.Add(new SqlParameter("@MedicineIn_Code", label6.Text));
                cmd.Parameters.Add(new SqlParameter("@Provider_Code", textBox1.Text));
                cmd.Parameters.Add(new SqlParameter("@Provider_Name", textBox2.Text));
                cmd.Parameters.Add(new SqlParameter("@Medicine_Code", comboBox1.Text));
                cmd.Parameters.Add(new SqlParameter("@Amount", Convert.ToInt32(textBox5.Text)));
                cmd.Parameters.Add(new SqlParameter("@Money", Convert.ToDouble(textBox6.Text)));
                cmd.Parameters.Add(new SqlParameter("@MedicineIn_Date", dateTimePicker1.Text));
                cmd.Parameters.Add(new SqlParameter("@Man", textBox3.Text));
                cmd.Parameters.Add(new SqlParameter("@Remark", ""));

                cmd.ExecuteNonQuery();
                tran.Commit();
                MessageBox.Show("更新成功");
            }
            catch (SqlException ex)
            {
                tran.Rollback();
                MessageBox.Show(ex.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
            cn.Open();

            SqlTransaction tran = null;
            try
            {
                if (textBox4.Text == "")
                {
                    cn.Close();
                    MessageBox.Show("票号不能为空");
                    return;
                }
                
                tran = cn.BeginTransaction();
                SqlCommand cmd = new SqlCommand("delete from Medicine_In where MedicineIn_Code = @MedicineIn_Code", cn, tran);
                cmd.Parameters.Add(new SqlParameter("@MedicineIn_Code", textBox4.Text));
                
                cmd.ExecuteNonQuery();
                tran.Commit();
                MessageBox.Show("删除成功");
            }
            catch (SqlException ex)
            {
                tran.Rollback();
                MessageBox.Show(ex.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //--------------------------------------------------------------------------------------------------------------

        private void PDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            int x = 20;
            int y = 20;

            /*for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                x = 20;
                y += 50;
                if (y >= e.PageBounds.Height - 80)
                {
                    e.HasMorePages = true;
                    return;
                }
                e.HasMorePages = false;
                for (int j = 0; j < dataGridView1.Columns.Count; j++)
                {
                    e.Graphics.DrawString(dataGridView1.Rows[i].Cells[j].Value.ToString(), new Font("Arial", 20, FontStyle.Bold), Brushes.Black, x, y);

                    x += 200;
                    if (x >= e.PageBounds.Right - 20)
                    {
                        x = 20;

                    }
                }*/
            e.Graphics.DrawString("票号:" + label6.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
            y += 100;
            if (y >= e.PageBounds.Height - 80)
            {
                e.HasMorePages = true;
                y = 20;
            }
            e.HasMorePages = false;
            e.Graphics.DrawString("日期:" + dateTimePicker1.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
            y += 100;
            if (y >= e.PageBounds.Height - 80)
            {
                e.HasMorePages = true;
                y = 20;
            }
            e.HasMorePages = false;
            e.Graphics.DrawString("供应商编号:"+textBox1.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
            y += 100;
            if (y >= e.PageBounds.Height - 80)
            {
                e.HasMorePages = true;
                y = 20;
            }
            e.HasMorePages = false;
            e.Graphics.DrawString("供应商名称:"+textBox2.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
            y += 100;
            if (y >= e.PageBounds.Height - 80)
            {
                e.HasMorePages = true;
                y = 20;
            }
            e.HasMorePages = false;
            e.Graphics.DrawString("经办人:"+textBox3.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
            y += 100;
            if (y >= e.PageBounds.Height - 80)
            {
                e.HasMorePages = true;
                y = 20;
            }
            e.HasMorePages = false;
            e.Graphics.DrawString("药品编码:"+comboBox1.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
            y += 100;
            if (y >= e.PageBounds.Height - 80)
            {
                e.HasMorePages = true;
                y = 20;
            }
            e.HasMorePages = false;
            e.Graphics.DrawString("药品名称:"+comboBox2.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
            y += 100;
            if (y >= e.PageBounds.Height - 80)
            {
                e.HasMorePages = true;
                y = 20;
            }
            e.HasMorePages = false;
            e.Graphics.DrawString("数量:"+textBox5.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
            y += 100;
            if (y >= e.PageBounds.Height - 80)
            {
                e.HasMorePages = true;
                y = 20;
            }
            e.Graphics.DrawString("总价:"+textBox6.Text, new Font("Arial", 40, FontStyle.Bold), Brushes.Black, x, y);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            pdlg.Document = PDoc;
            DialogResult result = pdlg.ShowDialog();
            if (result == DialogResult.OK)
                PDoc.Print();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            PrintPreviewDialog ob = new PrintPreviewDialog();
            ob.Document = PDoc;
            ob.ShowDialog();
        }
    }
}

⌨️ 快捷键说明

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