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

📄 printform.cs

📁 一个很好的宾馆管理系统 VC++和SQL做的
💻 CS
字号:
//文件名:PrintForm.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;

namespace MyHotel
{
    public partial class PrintForm : Form
    {
        public PrintForm()
        {
            InitializeComponent();
        }
        public string MyOperator;
        public string MyCompany;
        

        private void 查询Button_Click(object sender, EventArgs e)
        {
            this.帐单GroupBox.Text = this.帐单类型ComboBox.Text;
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            DataTable MyTable = new DataTable();
            string MySQL = "Select * From 客房入住单 WHERE  房号 LIKE '%"+this.酒店房号TextBox.Text+"%' OR 客人姓名 LIKE '%"+this.客人姓名TextBox.Text+"%'";
            if (this.帐单类型ComboBox.Text == "旅客结帐单")
            {
                MySQL = "Select 自编号,入住编号,结帐编号,房号,客人姓名,入住日期,结帐日期,店内消费,住宿费,电话费,用餐费,店内消费+住宿费+电话费+用餐费 as 费用金额合计,预收押金,结帐金额,操作人员,说明 From 客房结帐单 WHERE  房号 LIKE '%" + this.酒店房号TextBox.Text + "%' OR 客人姓名 LIKE '%" + this.客人姓名TextBox.Text + "%'";
            }
            SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
            MyAdapter.Fill(MyTable);
            this.帐单DataGridView.DataSource = MyTable;
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
        }

        private void 打印Button_Click(object sender, EventArgs e)
        {
            this.printPreviewDialog1.Document = this.printDocument1;
            this.printPreviewDialog1.ShowDialog();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            if (this.帐单类型ComboBox.Text == "旅客结帐单")
            {
                double MyAmount =Convert.ToDouble(this.帐单DataGridView.CurrentRow.Cells[11].Value.ToString()) -
                    Convert.ToDouble(this.帐单DataGridView.CurrentRow.Cells[12].Value.ToString());
                string MyAmountInfo = "实收金额:" + MyAmount.ToString();
                if (MyAmount < 0)
                {
                    MyAmountInfo = "实补金额:" + MyAmount.ToString().Remove(0, 1);
                }

                this.帐单DataGridView.CurrentRow.Cells[2].Value.ToString();
                //打印旅客结帐单
                e.Graphics.DrawString(this.MyCompany + "旅客结帐单", new Font("宋体", 20), Brushes.Black, 220, 80);
                e.Graphics.DrawString("结帐编号:" + this.帐单DataGridView.CurrentRow.Cells[2].Value.ToString(), new Font("宋体", 12), Brushes.Black, 100, 150);
                e.Graphics.DrawString("操作员:" + this.MyOperator, new Font("宋体", 12), Brushes.Black, 600, 150);

                e.Graphics.DrawLine(new Pen(Color.Black, (float)3.00), 100, 185, 720, 185);

                e.Graphics.DrawString("房号:" + this.帐单DataGridView.CurrentRow.Cells[3].Value.ToString(), new Font("宋体", 12), Brushes.Black, 110, 195);
                e.Graphics.DrawString("姓名:" + this.帐单DataGridView.CurrentRow.Cells[4].Value.ToString(), new Font("宋体", 12), Brushes.Black, 300, 195);
                e.Graphics.DrawString("入住编号:" + this.帐单DataGridView.CurrentRow.Cells[1].Value.ToString(), new Font("宋体", 12), Brushes.Black, 500, 195);

                e.Graphics.DrawLine(new Pen(Color.Black), 100, 215, 720, 215);
                e.Graphics.DrawString("         序号          费用类别           金额", new Font("宋体", 12), Brushes.Black, 110, 220);
                e.Graphics.DrawLine(new Pen(Color.Black), 100, 240, 720, 240);
                e.Graphics.DrawString("           1     店内消费               " + this.帐单DataGridView.CurrentRow.Cells[7].Value.ToString(), new Font("宋体", 12), Brushes.Black, 110, 245);
                e.Graphics.DrawString("           2     住宿费                " + this.帐单DataGridView.CurrentRow.Cells[8].Value.ToString(), new Font("宋体", 12), Brushes.Black, 110, 265);
                e.Graphics.DrawString("           3     电话费                " + this.帐单DataGridView.CurrentRow.Cells[9].Value.ToString(), new Font("宋体", 12), Brushes.Black, 110, 285);
                e.Graphics.DrawString("           4     用餐费                " + this.帐单DataGridView.CurrentRow.Cells[10].Value.ToString(), new Font("宋体", 12), Brushes.Black, 110, 305);
                e.Graphics.DrawLine(new Pen(Color.Black), 100, 325, 720, 325);

                e.Graphics.DrawString("                                     费用金额合计:" + this.帐单DataGridView.CurrentRow.Cells[11].Value.ToString(), new Font("宋体", 12), Brushes.Black, 110, 330);

                e.Graphics.DrawLine(new Pen(Color.Black), 100, 350, 720, 350);
                e.Graphics.DrawString("入住日期:" + this.帐单DataGridView.CurrentRow.Cells[5].Value.ToString() + "         结帐日期:" + this.帐单DataGridView.CurrentRow.Cells[6].Value.ToString(), new Font("宋体", 12), Brushes.Black, 110, 355);
                e.Graphics.DrawLine(new Pen(Color.Black), 100, 375, 720, 375);
                e.Graphics.DrawString("预收押金:" + this.帐单DataGridView.CurrentRow.Cells[12].Value.ToString() + "                           " + MyAmountInfo, new Font("宋体", 12), Brushes.Black, 110, 380);

                e.Graphics.DrawLine(new Pen(Color.Black, (float)3.00), 100, 400, 720, 400);
                DateTime MyDate = DateTime.Now;
                e.Graphics.DrawString("打印日期:" + MyDate.ToLongDateString() + MyDate.ToLongTimeString(), new Font("宋体", 12), Brushes.Black, 450, 405);
                e.Graphics.DrawString("温馨提示:为了维护您及他人的合法权益,请不要带未经登记的人员进出您的房间。", new Font("宋体", 12), Brushes.Black, 100, 425);
                e.Graphics.DrawString("警察提示:请保管好您的物品,重要物品请寄存于酒店寄存处,免费寄存!", new Font("宋体", 12), Brushes.Black, 100, 445);
                e.Graphics.DrawString("谢谢合作!", new Font("宋体", 20), Brushes.Black, 550, 465);
            }
            else
            {           
                e.Graphics.DrawString(this.MyCompany + "旅客入住单", new Font("宋体", 20), Brushes.Black, 220, 80);
                e.Graphics.DrawString("入住编号:" + this.帐单DataGridView.CurrentRow.Cells[0].Value.ToString(), new Font("宋体", 12), Brushes.Black, 100, 150);
                DateTime MyPrintTime = DateTime.Now;
                e.Graphics.DrawString("打印日期:" + MyPrintTime.ToLongDateString() + MyPrintTime.ToLongTimeString(), new Font("宋体", 12), Brushes.Black, 450, 150);
                e.Graphics.DrawLine(new Pen(Color.Black), 100, 180, 720, 180);
                e.Graphics.DrawLine(new Pen(Color.Black), 100, 220, 720, 220);
                e.Graphics.DrawLine(new Pen(Color.Black), 100, 260, 720, 260);
                e.Graphics.DrawLine(new Pen(Color.Black), 100, 300, 720, 300);
                e.Graphics.DrawLine(new Pen(Color.Black), 100, 340, 720, 340);

                e.Graphics.DrawLine(new Pen(Color.Black), 100, 180, 100, 340);
                e.Graphics.DrawLine(new Pen(Color.Black), 220, 180, 220, 340);
                e.Graphics.DrawLine(new Pen(Color.Black), 400, 180, 400, 340);
                e.Graphics.DrawLine(new Pen(Color.Black), 720, 180, 720, 340);

                e.Graphics.DrawString("房号:" + this.帐单DataGridView.CurrentRow.Cells[1].Value.ToString(), new Font("宋体", 12), Brushes.Black, 105, 190);
                e.Graphics.DrawString("姓名:" + this.帐单DataGridView.CurrentRow.Cells[6].Value.ToString(), new Font("宋体", 12), Brushes.Black, 105, 230);
                e.Graphics.DrawString("性别:" + this.帐单DataGridView.CurrentRow.Cells[11].Value.ToString(), new Font("宋体", 12), Brushes.Black, 105, 270);
                e.Graphics.DrawString("人数:" + this.帐单DataGridView.CurrentRow.Cells[10].Value.ToString(), new Font("宋体", 12), Brushes.Black, 105, 310);

                e.Graphics.DrawString("折扣价格:" + this.帐单DataGridView.CurrentRow.Cells[2].Value.ToString(), new Font("宋体", 12), Brushes.Black, 225, 190);
                e.Graphics.DrawString("预收押金:" + this.帐单DataGridView.CurrentRow.Cells[3].Value.ToString(), new Font("宋体", 12), Brushes.Black, 225, 230);
                e.Graphics.DrawString("入住日期:" + this.帐单DataGridView.CurrentRow.Cells[4].Value.ToString().Remove(10), new Font("宋体", 12), Brushes.Black, 225, 270);
                e.Graphics.DrawString("离开日期:" + this.帐单DataGridView.CurrentRow.Cells[5].Value.ToString().Remove(10), new Font("宋体", 12), Brushes.Black, 225, 310);

                e.Graphics.DrawString("证件名称:" + this.帐单DataGridView.CurrentRow.Cells[7].Value.ToString(), new Font("宋体", 12), Brushes.Black, 405, 190);
                e.Graphics.DrawString("证件编号:" + this.帐单DataGridView.CurrentRow.Cells[8].Value.ToString(), new Font("宋体", 12), Brushes.Black, 405, 230);
                e.Graphics.DrawString("证件地址:" + this.帐单DataGridView.CurrentRow.Cells[9].Value.ToString(), new Font("宋体", 12), Brushes.Black, 405, 270);
                e.Graphics.DrawString("联系电话:" + this.帐单DataGridView.CurrentRow.Cells[12].Value.ToString(), new Font("宋体", 12), Brushes.Black, 405, 310);

                e.Graphics.DrawString("操作员:" + this.MyOperator, new Font("宋体", 12), Brushes.Black, 600, 350);

                e.Graphics.DrawString("温馨提示:为了维护您及他人的合法权益,请不要带未经登记的人员进出您的房间。", new Font("宋体", 12), Brushes.Black, 100, 380);
                e.Graphics.DrawString("警察提示:请保管好您的物品,重要物品请寄存于酒店寄存处,免费寄存!", new Font("宋体", 12), Brushes.Black, 100, 400);
                e.Graphics.DrawString("谢谢合作!", new Font("宋体", 20), Brushes.Black, 550, 420);
            }
        }
  
    }
}

⌨️ 快捷键说明

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