📄 checkoutform.cs
字号:
//文件名:CheckOutForm.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 CheckOutForm : Form
{
public CheckOutForm()
{
InitializeComponent();
}
public string MyOperator;
public String MyCompany;
private string My入住编号;
private DateTime My结帐日期;
private DateTime My入住日期;
private double My店内消费 = 0;
private double My电话费 = 0;
private double My用餐费 = 0;
private double My住宿费 = 0;
private double My费用总额 = 0;
private string My结帐编号 = "";
private double My预收押金 = 0;
private double My结帐金额 = 0;
private int My住宿人数 = 0;
private void CheckOutForm_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();
}
}
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店内消费 = 0;
My电话费 = 0;
My用餐费 = 0;
My住宿费 = 0;
My费用总额 = 0;
My预收押金 = 0;
My结帐金额 = 0;
this.预收押金TextBox.Text = "0";
this.电话费TextBox.Text = "";
this.用餐费TextBox.Text = "";
this.店内消费TextBox.Text = "";
this.住宿费TextBox.Text = "";
this.结帐金额TextBox.Text = "";
this.费用总额TextBox.Text = "0";
this.My入住编号 = this.旅客姓名ComboBox.SelectedValue.ToString();
String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
string MySQL = "Select Count(*) From 客房结帐单 Where 入住编号='" + this.My入住编号 + "'";
SqlCommand MyCommand = new SqlCommand(MySQL, MyConnection);
int MyCount = (int)MyCommand.ExecuteScalar();
if (MyCount > 0)
{
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
return;
}
MySQL = "Select SUM(预收押金) From 客房入住单 Where 入住编号='" + this.My入住编号 + "'";
MyCommand = new SqlCommand(MySQL, MyConnection);
this.预收押金TextBox.Text = MyCommand.ExecuteScalar().ToString();
MySQL = "Select SUM(金额) From 话费入帐 Where 入住编号='" + this.My入住编号 + "'";
MyCommand = new SqlCommand(MySQL, MyConnection);
this.电话费TextBox.Text = MyCommand.ExecuteScalar().ToString();
MySQL = "Select SUM(金额) From 餐费入帐 Where 入住编号='" + this.My入住编号 + "'";
MyCommand = new SqlCommand(MySQL, MyConnection);
this.用餐费TextBox.Text = MyCommand.ExecuteScalar().ToString();
MySQL = "Select SUM(数量*折扣价格) From 消费入帐 Where 入住编号='" + this.My入住编号 + "'";
MyCommand = new SqlCommand(MySQL, MyConnection);
this.店内消费TextBox.Text = MyCommand.ExecuteScalar().ToString();
this.My结帐日期 = this.结帐日期DateTimePicker.Value;
MySQL = "Select 折扣价格,入住日期,住宿人数 From 客房入住单 Where 入住编号='" + this.My入住编号 + "'";
DataTable MyNewTable = new DataTable();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
MyAdapter.Fill(MyNewTable);
string My折扣价格 = MyNewTable.Rows[0][0].ToString();
this.折扣价格TextBox.Text = My折扣价格.ToString();
this.My入住日期 = (DateTime)MyNewTable.Rows[0][1];
this.入住日期TextBox.Text = this.My入住日期.ToLongDateString();
this.My住宿人数 = (int)MyNewTable.Rows[0][2];
TimeSpan MySpan = this.My结帐日期.Subtract(My入住日期);
My住宿费 = Convert.ToDouble(My折扣价格) * Math.Round(MySpan.TotalDays, 0) * My住宿人数;
this.住宿费TextBox.Text = My住宿费.ToString();
if (this.店内消费TextBox.Text.Length > 1)
My店内消费 = Convert.ToDouble(this.店内消费TextBox.Text);
if (this.电话费TextBox.Text.Length > 1)
My电话费 = Convert.ToDouble(this.电话费TextBox.Text);
if (this.用餐费TextBox.Text.Length > 1)
My用餐费 = Convert.ToDouble(this.用餐费TextBox.Text);
My费用总额 = My住宿费 + My电话费 + My用餐费 + My店内消费;
this.费用总额TextBox.Text = My费用总额.ToString();
this.My预收押金=Convert.ToDouble(this.预收押金TextBox.Text);
this.My结帐金额 = My费用总额 - this.My预收押金;
this.结帐金额TextBox.Text = My结帐金额.ToString();
MySQL = "Select * From 客房入住单 Where 入住编号='" + this.My入住编号 + "'";
DataTable MyGuestTable = new DataTable();
SqlDataAdapter MyDataAdapter = new SqlDataAdapter(MySQL, MyConnection);
MyDataAdapter.Fill(MyGuestTable);
this.客房入住单DataGridView.DataSource = MyGuestTable;
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
My结帐编号 = System.Guid.NewGuid().ToString().ToUpper();
}
private void 结帐日期DateTimePicker_ValueChanged(object sender, EventArgs e)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -