📄 leavingdetails.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.IO;
using BLL;
using Model;
public partial class LeavingDetails : System.Web.UI.Page
{
private RoomOperatorBLL roomOp = new RoomOperatorBLL();
private const string path = "Operator.log";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.QueryString["roomId"] != null)
{
int id = int.Parse(Request.QueryString["roomId"].ToString());
ViewState.Add("roomId", id);//将房间编号添加到 ViewState 中防止在本页面丢失
SetDataFormURL(id);
}
}
}
/// <summary>
/// 从URL 参数中获得的编号查询出房间信息
/// </summary>
/// <param name="id"></param>
private void SetDataFormURL(int id)
{
if (id > 0)
{
Room room = roomOp.GetRoomByRoomID(id);
if (room != null)
{
this.lbl_roomNumber.Text = room.Roomnumber;
this.lbl_Type.Text = room.TypeId.Typename;
this.lbl_Money.Text = "¥" + room.TypeId.Typeprice.ToString();
}
}
}
protected void txt_payMoney_TextChanged(object sender, EventArgs e)
{
string money = this.txt_payMoney.Text;
string must_pay = this.lbl_Money.Text;
if (must_pay.Contains("¥"))
must_pay = must_pay.Remove(must_pay.IndexOf("¥"), 1);
if (!string.IsNullOrEmpty(money) && !string.IsNullOrEmpty(must_pay))
{
int pay_int = 0; //初始化
double pay_double = 0.0d;
int pay_must = int.Parse(must_pay);
if (money.IndexOf(".") != -1)//如果付款中带有小数点
{
pay_double = double.Parse(money);//则使用 double 转换否则使用 int 转换
this.lbl_backMoney.Text = "¥" + Convert.ToString(Math.Round(pay_double - pay_must, 2)) + "元";
}
else
{
pay_int = int.Parse(money);
this.lbl_backMoney.Text = "¥" + Convert.ToString(pay_int - pay_must) + "元";
}
}
if (string.IsNullOrEmpty(money))
lbl_backMoney.Text = "";
}
protected void imgBtn_Balance_Click(object sender, ImageClickEventArgs e)
{
string money = lbl_backMoney.Text;
string error = string.Empty;
if (money.Contains("¥")) //如果找还中带有人民币符号则删除,
money = money.Remove(money.IndexOf("¥"), 1);
if (money.Contains("元"))//如果找还中还带有元的字样也进行删除操作
money = money.Remove(money.IndexOf("元"), 1);
if (!string.IsNullOrEmpty(money))
{
try
{
if (money.IndexOf(".") == -1)//如果不带小数点则用 int 转换并判断是否小于0
{
if (int.Parse(money) < 0)
error = "您的金额不足!!";
}
else
{
if (double.Parse(money) < 0)//如果带小数点则用 double 转换并判断是否小于0
error = "您的金额不足!!";
}
if (!string.IsNullOrEmpty(error))//如果有错误则提示
{
Response.Write("<script>alert('" + error + "')</script>");
if (ViewState["roomId"] != null)
Server.Transfer("~/LeavingDetails.aspx?roomId=" + ViewState["roomId"].ToString());
}
else
{
if (ViewState["roomId"] != null)
{
int id = int.Parse(ViewState["roomId"].ToString());
Room room = roomOp.GetRoomByRoomID(id);//按房间编号查询房间信息
if (room != null)
{
room.Guessnumber = 0;//修改入住人数为0
room.State = "空闲";//修改房间状态为空闲
if (roomOp.ModifyValuesFormRoom(room)) //如果修改成功
{
PrintLog(room);
Response.Write("<script>javascript:window.close()</script>");//关闭当前窗口
}
}
}
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + ex.StackTrace + "')</script>");
}
}
}
/// <summary>
/// 打印日志信息
/// </summary>
/// <param name="temp"></param>
private void PrintLog(Room temp)
{
if (temp != null)
{
string info = "房间号:" + temp.Roomnumber + " 操作员:" + DropDownList1.Text + " 时间:" + DateTime.Now.ToString() + " 收银:" + lbl_Money.Text + "元";
StreamWriter writer = null;
if (!File.Exists(path))//判断文件是否存在,如果存在则直接追加
{
FileStream stream = File.Create(path);
stream.Close();
writer = new StreamWriter(path);
writer.WriteLine(info);
writer.Close();
}
else
{
writer = File.AppendText(path);
writer.WriteLine(info);
writer.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -