📄 consumeform.aspx.cs
字号:
//文件名:ConsumeForm.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ConsumeManage_ConsumeForm : System.Web.UI.Page
{
private static DataTable MyConsumeTable = new DataTable();
private static int MyID = 0;
protected void Page_Load(object sender, EventArgs e)
{
string MyForbidString = Session["MyForbid"].ToString();
if (MyForbidString.IndexOf("B3") > 1)
{
Server.Transfer("~/SystemManage/AllErrorHelp.aspx");
}
if (!IsPostBack)
{
//创建无连接的数据表
DataColumn[] MyKey = new DataColumn[1];
MyConsumeTable = new DataTable("消费入账");
DataColumn MyColumn = new DataColumn();
MyColumn.DataType = System.Type.GetType("System.Int16");
MyColumn.ColumnName = "自编号";
MyConsumeTable.Columns.Add(MyColumn);
MyKey[0] = MyColumn;
MyConsumeTable.PrimaryKey = MyKey;
MyConsumeTable.Columns.Add("入住编号", System.Type.GetType("System.String"));
MyConsumeTable.Columns.Add("消费编号", System.Type.GetType("System.String"));
MyConsumeTable.Columns.Add("商品名称", System.Type.GetType("System.String"));
MyConsumeTable.Columns.Add("消费数量", System.Type.GetType("System.Int16"));
MyConsumeTable.Columns.Add("折扣价格", System.Type.GetType("System.Double"));
MyConsumeTable.Columns.Add("说明", System.Type.GetType("System.String"));
MyConsumeTable.Columns.Add("记账时间", System.Type.GetType("System.DateTime"));
MyConsumeTable.Columns.Add("操作人员", System.Type.GetType("System.String"));
this.TextBox1.Text = "1";
}
this.Page.Title = "当前位置:消费管理->其他消费登记";
this.GridView1.DataSource = MyConsumeTable;
this.Button3.OnClientClick = "return confirm('请检查旅客消费信息是否正确,一旦保存就无法修改,是否继续?')";
}
protected void Button4_Click(object sender, EventArgs e)
{//随机生成消费编号
this.TextBox4.Text = System.Guid.NewGuid().ToString().ToUpper();
this.TextBox5.Text = Session["MyUserName"].ToString();
this.TextBox6.Text = DateTime.Now.ToShortDateString();
MyConsumeTable.Rows.Clear();
this.GridView1.DataBind();
MyID = 0;
}
protected void Button1_Click(object sender, EventArgs e)
{//向临时数据表中新增消费信息
MyID = MyID + 1;
DataRow MyRow = MyConsumeTable.NewRow();
MyRow[0] = MyID;
MyRow["入住编号"] = this.DropDownList2.SelectedValue.ToString();
MyRow["消费编号"] = this.TextBox4.Text;
MyRow["商品名称"] = this.DropDownList3.SelectedValue.ToString();
MyRow["消费数量"] = this.TextBox1.Text;
MyRow["折扣价格"] = this.TextBox2.Text;
MyRow["说明"] = this.TextBox3.Text;
MyRow["记账时间"] = this.TextBox6.Text;
MyRow["操作人员"] = this.TextBox5.Text;
MyConsumeTable.Rows.Add(MyRow);
this.GridView1.DataBind();
}
protected void Button3_Click(object sender, EventArgs e)
{//保存旅客消费信息
String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MyHotelDBConnectionString"].ConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
SqlBulkCopy MyBulkCopy = new SqlBulkCopy(MyConnection);
MyBulkCopy.DestinationTableName = "消费入账";
MyBulkCopy.WriteToServer(MyConsumeTable);
MyConsumeTable.Rows.Clear();
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
Button4_Click(null, null);
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MyHotelDBConnectionString"].ConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
string MySQL = "Select 单价 From 消费商品 Where 名称='" +this.DropDownList3.SelectedValue.ToString()+"'";
SqlCommand MyCommand = new SqlCommand(MySQL, MyConnection);
this.TextBox2.Text = MyCommand.ExecuteScalar().ToString();
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
}
public DataTable MyTable
{//设置要传递到打印页的数据表
get
{
return MyConsumeTable;
}
}
public String My入住房号
{//设置要传递到打印页的入住房号
get
{
return this.DropDownList1.SelectedValue.ToString();
}
}
public String My客人姓名
{//设置要传递到打印页的客人姓名
get
{
return this.DropDownList2.SelectedItem.Text;
}
}
protected void Button2_Click(object sender, EventArgs e)
{//打印旅客消费信息
Server.Transfer("~/ConsumeManage/ConsumePrint.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -