|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace EHotelMS.View.Admin
{
public partial class Rooms : System.Web.UI.Page
{
Models.Functions Con;
protected void Page_Load(object sender, EventArgs e)
{
Con = new Models.Functions();
ShowRooms();
GetStatus(); // 修改:原 GetCategories() 改为 GetStatus()
}
private void ShowRooms()
{
string Query = "select * from MatchTb"; // 修改:原 RoomTb1 改为 MatchTb
RoomsGV.DataSource = Con.GetData(Query);
RoomsGV.DataBind();
// 修改列名以匹配数据库字段
RoomsGV.HeaderRow.Cells[1].Text = "匹配ID";
RoomsGV.HeaderRow.Cells[2].Text = "男嘉宾ID";
RoomsGV.HeaderRow.Cells[3].Text = "女嘉宾ID";
RoomsGV.HeaderRow.Cells[4].Text = "匹配时间";
RoomsGV.HeaderRow.Cells[5].Text = "匹配反馈";
RoomsGV.HeaderRow.Cells[6].Text = "匹配状态";
}
private void GetStatus()
{
// 修改:原 CategoryTb1 改为 MatchStatusTb(如果有)
// 如果没有数据库表,直接绑定前端已有的选项
if (!Page.IsPostBack)
{
StatusCb.Items.Clear();
StatusCb.Items.Add("正在匹配");
StatusCb.Items.Add("匹配失败");
StatusCb.Items.Add("匹配成功");
}
}
protected void SaveBtn_Click(object sender, EventArgs e)
{
try
{
string matchId = RNameTb.Value; // 匹配ID
string maleGuestId = MGuestIdTb.Value; // 男嘉宾ID
string femaleGuestId = FGuestIdTb.Value; // 女嘉宾ID
string matchTime = LocationTb.Value; // 匹配时间
string feedback = CostTb.Value; // 匹配反馈
string status = StatusCb.SelectedValue; // 匹配状态
string Query = "INSERT INTO MatchTb VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')";
Query = string.Format(Query, matchId, maleGuestId, femaleGuestId, matchTime, feedback, status);
Con.setData(Query);
ShowRooms();
ErrMsg.InnerText = "匹配信息已添加!";
ClearFields();
}
catch (Exception Ex)
{
ErrMsg.InnerText = Ex.Message;
}
}
int Key = 0;
protected void RoomsGV_SelectedIndexChanged(object sender, EventArgs e)
{
Key = Convert.ToInt32(RoomsGV.SelectedRow.Cells[1].Text);
RNameTb.Value = RoomsGV.SelectedRow.Cells[1].Text; // 匹配ID
MGuestIdTb.Value = RoomsGV.SelectedRow.Cells[2].Text; // 男嘉宾ID
FGuestIdTb.Value = RoomsGV.SelectedRow.Cells[3].Text; // 女嘉宾ID
LocationTb.Value = RoomsGV.SelectedRow.Cells[4].Text; // 匹配时间
CostTb.Value = RoomsGV.SelectedRow.Cells[5].Text; // 匹配反馈
StatusCb.SelectedValue = RoomsGV.SelectedRow.Cells[6].Text; // 匹配状态
}
protected void EditBtn_Click(object sender, EventArgs e)
{
try
{
string matchId = RNameTb.Value;
string maleGuestId = MGuestIdTb.Value;
string femaleGuestId = FGuestIdTb.Value;
string matchTime = LocationTb.Value;
string feedback = CostTb.Value;
string status = StatusCb.SelectedValue;
string Query = "UPDATE MatchTb SET MaleGuestId='{1}', FemaleGuestId='{2}', MatchTime='{3}', Feedback='{4}', Status='{5}' WHERE MatchId='{0}'";
Query = string.Format(Query, matchId, maleGuestId, femaleGuestId, matchTime, feedback, status);
Con.setData(Query);
ShowRooms();
ErrMsg.InnerText = "匹配信息已更新!";
ClearFields();
}
catch (Exception Ex)
{
ErrMsg.InnerText = Ex.Message;
}
}
protected void DeleteBtn_Click(object sender, EventArgs e)
{
try
{
string matchId = RNameTb.Value;
string Query = "DELETE FROM MatchTb WHERE MatchId='{0}'";
Query = string.Format(Query, matchId);
Con.setData(Query);
ShowRooms();
ErrMsg.InnerText = "匹配信息已删除!";
ClearFields();
}
catch (Exception Ex)
{
ErrMsg.InnerText = Ex.Message;
}
}
private void ClearFields()
{
RNameTb.Value = "";
MGuestIdTb.Value = "";
FGuestIdTb.Value = "";
LocationTb.Value = "";
CostTb.Value = "";
StatusCb.SelectedIndex = -1;
}
}
} |
|