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

📄 telephoneform.cs

📁 一个很好的宾馆管理系统 VC++和SQL做的
💻 CS
字号:
//文件名:TelephoneForm.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 TelephoneForm : Form
    {
        public TelephoneForm()
        {
            InitializeComponent();
        }
        private string My话费编号;
        private string My入住编号;
        public string MyOperator;
        public string MyCompany;
        private DateTime MyDate;
        private int MyID;
        private DataTable MyTelephoneTable = new DataTable();
        private void TelephoneForm_Load(object sender, EventArgs e)
        {
            this.酒店房号ComboBox.Items.Clear();
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            DataTable MyRoomTable = new DataTable();
            //获取酒店已入住房间信息
            string MySQL = "Select * From 酒店房间 Where 已入住人数<>0 ";
            SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
            MyAdapter.Fill(MyRoomTable);
            this.酒店房号ComboBox.DataSource = MyRoomTable;
            this.酒店房号ComboBox.DisplayMember = "房号";
            this.酒店房号ComboBox.ValueMember = "房号";
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
            //创建无连接的数据表
            DataColumn[] MyKey = new DataColumn[1];
            MyTelephoneTable = new DataTable("旅客话费表");
            DataColumn MyColumn = new DataColumn();
            MyColumn.DataType = System.Type.GetType("System.Int32");
            MyColumn.ColumnName = "序号";
            MyTelephoneTable.Columns.Add(MyColumn);
            MyKey[0] = MyColumn;
            MyTelephoneTable.PrimaryKey = MyKey;
            MyTelephoneTable.Columns.Add("通话时间", typeof(String));
            MyTelephoneTable.Columns.Add("类别", typeof(String));
            MyTelephoneTable.Columns.Add("金额", typeof(float));
            MyTelephoneTable.Columns.Add("说明", typeof(String));
            this.旅客话费表DataGridView.DataSource = MyTelephoneTable;
            this.通话时间TextBox.Text = DateTime.Now.ToLongDateString();
        }

        private void 酒店房号ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            //获取入住客人信息
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            string MySQL = "Select 客人姓名,入住编号 From 客房入住单 Where 房号='" + this.酒店房号ComboBox.Text + "' AND 入住编号 NOT IN(Select 入住编号 FROM 客房结帐单)";
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            DataTable MyGuestTable = new DataTable();
            SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
            MyAdapter.Fill(MyGuestTable);
            this.旅客姓名ComboBox.DataSource = MyGuestTable;
            this.旅客姓名ComboBox.DisplayMember = "客人姓名";
            this.旅客姓名ComboBox.ValueMember = "入住编号";
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }    
        }

        private void 旅客姓名ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            My入住编号 = this.旅客姓名ComboBox.SelectedValue.ToString();
            My话费编号 = System.Guid.NewGuid().ToString();
            MyDate = DateTime.Now;
            MyTelephoneTable.Rows.Clear();
            MyID = 0;
        }

        private void 新增Button_Click(object sender, EventArgs e)
        {
            MyID = MyID + 1;
            DataRow MyRow = MyTelephoneTable.NewRow();
            MyRow[0] = MyID;
            MyRow["通话时间"] = this.通话时间TextBox.Text;
            MyRow["类别"] = this.类别ComboBox.Text;
            MyRow["金额"] = Convert.ToDouble(this.金额TextBox.Text);
            MyRow["说明"] = this.说明TextBox.Text;
            MyTelephoneTable.Rows.Add(MyRow);
        }
        private string GetNewID()
        {
            //自动计算话费编号
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.CommandText = "Select max(自编号) 最大编号 From 话费入帐";
            object MyResult = MyCommand.ExecuteScalar();
            Int64 MyID = 1;
            if (MyResult != System.DBNull.Value)
            {
                String MyMaxID = MyResult.ToString().Trim();
                MyMaxID = MyMaxID.Substring(2, MyMaxID.Length - 2);
                MyID = Convert.ToInt64(MyMaxID) + 1;
            }
            int MyLength = MyID.ToString().Length;
            string MyNewID = "";
            switch (MyLength)
            {
                case 1:
                    MyNewID = "HF0000000" + MyID.ToString();
                    break;
                case 2:
                    MyNewID = "HF000000" + MyID.ToString();
                    break;
                case 3:
                    MyNewID = "HF00000" + MyID.ToString();
                    break;
                case 4:
                    MyNewID = "HF0000" + MyID.ToString();
                    break;
                case 5:
                    MyNewID = "HF000" + MyID.ToString();
                    break;
                case 6:
                    MyNewID = "HF00" + MyID.ToString();
                    break;
                case 7:
                    MyNewID = "HF0" + MyID.ToString();
                    break;
            }
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
            return MyNewID;
        }

        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)
        {
            //打印话费明细单
            e.Graphics.DrawString(this.MyCompany + "话费明细单", new Font("宋体", 20), Brushes.Black, 220, 80);
            e.Graphics.DrawString("话费明细单编号:" + this.My话费编号.ToUpper(), 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.酒店房号ComboBox.Text, new Font("宋体", 12), Brushes.Black, 110, 195);
            e.Graphics.DrawString("姓名:" + this.旅客姓名ComboBox.Text, new Font("宋体", 12), Brushes.Black, 300, 195);
            e.Graphics.DrawString("入住编号:" + this.My入住编号, new Font("宋体", 12), Brushes.Black, 530, 195);
            e.Graphics.DrawLine(new Pen(Color.Black), 100, 215, 720, 215);

            e.Graphics.DrawString("序号", new Font("宋体", 12), Brushes.Black, 110, 220);
            e.Graphics.DrawString("通话时间", new Font("宋体", 12), Brushes.Black, 200, 220);
            e.Graphics.DrawString("类别", new Font("宋体", 12), Brushes.Black, 350, 220);
            e.Graphics.DrawString("金额", new Font("宋体", 12), Brushes.Black, 450, 220);
            e.Graphics.DrawString("说明", new Font("宋体", 12), Brushes.Black, 550, 220);
            int MyPosY = 240;
            float MyAmount = 0;
            for (int i = 0; i < MyTelephoneTable.Rows.Count; i++)
            {
                e.Graphics.DrawLine(new Pen(Color.Black), 100, MyPosY, 720, MyPosY);
                e.Graphics.DrawString(MyTelephoneTable.Rows[i][0].ToString(), new Font("宋体", 12), Brushes.Black, 110, MyPosY + 5);
                e.Graphics.DrawString(MyTelephoneTable.Rows[i][1].ToString(), new Font("宋体", 12), Brushes.Black, 160, MyPosY + 5);
                e.Graphics.DrawString(MyTelephoneTable.Rows[i][2].ToString(), new Font("宋体", 12), Brushes.Black, 350, MyPosY + 5);
                e.Graphics.DrawString(MyTelephoneTable.Rows[i][3].ToString(), new Font("宋体", 12), Brushes.Black, 450, MyPosY + 5);
                e.Graphics.DrawString(MyTelephoneTable.Rows[i][4].ToString(), new Font("宋体", 12), Brushes.Black, 550, MyPosY + 5);
                MyAmount = MyAmount + (float)MyTelephoneTable.Rows[i][3];
                MyPosY = MyPosY + 25;
            }
            e.Graphics.DrawLine(new Pen(Color.Black), 100, MyPosY, 720, MyPosY);
            e.Graphics.DrawString("合计金额:" + MyAmount.ToString(), new Font("宋体", 12), Brushes.Black, 360, MyPosY + 5);
            e.Graphics.DrawLine(new Pen(Color.Black, (float)3.00), 100, MyPosY + 25, 720, MyPosY + 25);
            e.Graphics.DrawString("打印日期:" + this.MyDate.ToLongDateString() + this.MyDate.ToLongTimeString(), new Font("宋体", 12), Brushes.Black, 450, MyPosY + 30);
            e.Graphics.DrawString("温馨提示:为了维护您及他人的合法权益,请不要带未经登记的人员进出您的房间。", new Font("宋体", 12), Brushes.Black, 100, MyPosY + 50);
            e.Graphics.DrawString("警察提示:请保管好您的物品,重要物品请寄存于酒店寄存处,免费寄存!", new Font("宋体", 12), Brushes.Black, 100, MyPosY + 70);
            e.Graphics.DrawString("谢谢合作!", new Font("宋体", 20), Brushes.Black, 550, MyPosY + 90);
        }

        private void 保存Button_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("请检查旅客话费信息是否正确,一旦保存就无法修改,是否继续?", "信息提示", MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            string MySQL = "INSERT INTO 话费入帐 (自编号,入住编号,话费编号,通话时间,类别,金额,说明,操作人员,记帐时间)VALUES(@自编号,@入住编号,@话费编号,@通话时间,@类别,@金额,@说明, @操作人员, @记帐时间)";
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.CommandText = MySQL;
            MyCommand.Parameters.Add(new SqlParameter("@自编号", SqlDbType.VarChar));
            MyCommand.Parameters.Add(new SqlParameter("@入住编号", SqlDbType.VarChar));
            MyCommand.Parameters.Add(new SqlParameter("@话费编号", SqlDbType.VarChar));
            MyCommand.Parameters.Add(new SqlParameter("@通话时间", SqlDbType.VarChar));
            MyCommand.Parameters.Add(new SqlParameter("@类别", SqlDbType.VarChar));        
            MyCommand.Parameters.Add(new SqlParameter("@金额", SqlDbType.Float));
            MyCommand.Parameters.Add(new SqlParameter("@说明", SqlDbType.VarChar));
            MyCommand.Parameters.Add(new SqlParameter("@操作人员", SqlDbType.VarChar));
            MyCommand.Parameters.Add(new SqlParameter("@记帐时间", SqlDbType.DateTime));
            for (int i = 0; i < MyTelephoneTable.Rows.Count; i++)
            {
                MyCommand.Parameters["@自编号"].Value = GetNewID();
                MyCommand.Parameters["@入住编号"].Value = this.My入住编号;
                MyCommand.Parameters["@话费编号"].Value = this.My话费编号.ToUpper();
                MyCommand.Parameters["@通话时间"].Value = MyTelephoneTable.Rows[i][1].ToString();
                MyCommand.Parameters["@类别"].Value = MyTelephoneTable.Rows[i][2].ToString();
                MyCommand.Parameters["@金额"].Value = Convert.ToDouble(MyTelephoneTable.Rows[i][3].ToString());
                MyCommand.Parameters["@说明"].Value = MyTelephoneTable.Rows[i][4].ToString();
                MyCommand.Parameters["@操作人员"].Value = this.MyOperator;
                MyCommand.Parameters["@记帐时间"].Value = this.MyDate;
                MyCommand.ExecuteNonQuery();
            }
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
            MyTelephoneTable.Rows.Clear();
        }
    }
}

⌨️ 快捷键说明

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