update from old git
This commit is contained in:
103
web/admin/region/bed/bedstatus/create.aspx.cs
Normal file
103
web/admin/region/bed/bedstatus/create.aspx.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public partial class admin_region_bed_bedstatus_create : MyWeb.config
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack) // 加這行
|
||||
{
|
||||
if (Guid.TryParse(Request.QueryString["statusid"], out Guid id))
|
||||
{
|
||||
LoadData(id);
|
||||
L_title.Text = "編輯區域類型";
|
||||
}
|
||||
var categoryList = RegionRoomBedStatus.GetCategoryList();
|
||||
// 假设你的下拉控件ID叫 ddlCategory
|
||||
TB_Category.DataSource = categoryList;
|
||||
TB_Category.DataTextField = "Text"; // 显示文字
|
||||
TB_Category.DataValueField = "Value"; // 选项值
|
||||
TB_Category.DataBind();
|
||||
TB_Category.Items.Insert(0, new ListItem("--请选择分类--", ""));
|
||||
}
|
||||
}
|
||||
private void LoadData(Guid id)
|
||||
{
|
||||
var rt = _db.RegionRoomBedStatus.FirstOrDefault(r => r.Uuid == id);
|
||||
if (rt == null)
|
||||
{
|
||||
L_msg.Text = "<div class='alert alert-danger'>找不到資料</div>";
|
||||
BTN_Save.Enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
HF_Id.Value = rt.Uuid.ToString();
|
||||
TB_Name.Text = rt.Name;
|
||||
TB_Code.Text = rt.Code;
|
||||
TB_Category.SelectedValue = rt.Category?.ToString();
|
||||
Description.Text = rt.Description;
|
||||
|
||||
}
|
||||
protected void BTN_Save_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
RegionRoomBedStatus rt;
|
||||
if (Guid.TryParse(HF_Id.Value, out Guid id))
|
||||
{
|
||||
// 更新
|
||||
rt = _db.RegionRoomBedStatus.FirstOrDefault(r => r.Uuid == id);
|
||||
if (rt == null)
|
||||
{
|
||||
L_msg.Text = "<div class='alert alert-danger'>資料不存在</div>";
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 新增
|
||||
rt = new RegionRoomBedStatus();
|
||||
rt.Uuid = Guid.NewGuid();
|
||||
_db.RegionRoomBedStatus.Add(rt);
|
||||
}
|
||||
|
||||
rt.Name = TB_Name.Text.Trim();
|
||||
if (rt.Name.Length == 0)
|
||||
{
|
||||
L_msg.Text = "<div class='alert alert-danger'>名稱不能为空</div>";
|
||||
return;
|
||||
}
|
||||
rt.Code = TB_Code.Text.Trim();
|
||||
rt.Description = Description.Text.Trim();
|
||||
if(int.TryParse(TB_Category.SelectedValue, out int category))
|
||||
{
|
||||
rt.Category = category;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.Category = null;
|
||||
}
|
||||
_db.SaveChanges();
|
||||
|
||||
L_msg.Text = "<div class='alert alert-success'>儲存成功</div>";
|
||||
|
||||
// 如果是新增,更新隱藏欄位並切換標題為編輯
|
||||
if (HF_Id.Value == "")
|
||||
{
|
||||
HF_Id.Value = rt.Uuid.ToString();
|
||||
L_title.Text = "編輯區域類型";
|
||||
}
|
||||
Response.Redirect("index.aspx");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
L_msg.Text = $"<div class='alert alert-danger'>錯誤:{ex.Message}</div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user