修改挂单功能

This commit is contained in:
2025-09-09 16:25:28 +08:00
parent e6c6b1f43f
commit ded24a8446
23 changed files with 1073 additions and 231 deletions

View File

@@ -16,7 +16,7 @@
</div>
<div class="card-body">
<asp:Literal ID="L_msg" runat="server" />
<asp:HiddenField ID="HF_Id" runat="server" />
<asp:HiddenField ID="HF_Code" runat="server" />
<div class="form-group mb-3">
<label for="TB_Name">名稱</label>

View File

@@ -1,35 +1,36 @@
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 (!IsPostBack)
{
if (Guid.TryParse(Request.QueryString["statusid"], out Guid id))
var code = Request.QueryString["code"];
if (!string.IsNullOrEmpty(code))
{
LoadData(id);
LoadData(code);
L_title.Text = "編輯區域類型";
}
var categoryList = RegionRoomBedStatus.GetCategoryList();
// 假设你的下拉控件ID叫 ddlCategory
TB_Category.DataSource = categoryList;
TB_Category.DataTextField = "Text"; // 示文字
TB_Category.DataValueField = "Value"; // 选项
TB_Category.DataTextField = "Text"; // 示文字
TB_Category.DataValueField = "Value"; // 選項
TB_Category.DataBind();
TB_Category.Items.Insert(0, new ListItem("--请选择分类--", ""));
TB_Category.Items.Insert(0, new ListItem("--請選擇分類--", ""));
}
}
private void LoadData(Guid id)
private void LoadData(string code)
{
var rt = _db.RegionRoomBedStatus.FirstOrDefault(r => r.Uuid == id);
var rt = _db.RegionRoomBedStatus.FirstOrDefault(r => r.Code == code);
if (rt == null)
{
L_msg.Text = "<div class='alert alert-danger'>找不到資料</div>";
@@ -37,22 +38,24 @@ public partial class admin_region_bed_bedstatus_create : MyWeb.config
return;
}
HF_Id.Value = rt.Uuid.ToString();
HF_Code.Value = rt.Code; // ✅ 以 Code 為唯一識別
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))
var code = HF_Code.Value; // ✅ 用隱藏欄位的 Code 判斷
if (!string.IsNullOrEmpty(code))
{
// 更新
rt = _db.RegionRoomBedStatus.FirstOrDefault(r => r.Uuid == id);
rt = _db.RegionRoomBedStatus.FirstOrDefault(r => r.Code == code);
if (rt == null)
{
L_msg.Text = "<div class='alert alert-danger'>資料不存在</div>";
@@ -63,19 +66,20 @@ public partial class admin_region_bed_bedstatus_create : MyWeb.config
{
// 新增
rt = new RegionRoomBedStatus();
rt.Uuid = Guid.NewGuid();
rt.Code = TB_Code.Text.Trim(); // ✅ 以 Code 當主鍵
_db.RegionRoomBedStatus.Add(rt);
}
rt.Name = TB_Name.Text.Trim();
if (rt.Name.Length == 0)
if (string.IsNullOrEmpty(rt.Name))
{
L_msg.Text = "<div class='alert alert-danger'>名稱不能空</div>";
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))
if (int.TryParse(TB_Category.SelectedValue, out int category))
{
rt.Category = category;
}
@@ -83,16 +87,18 @@ public partial class admin_region_bed_bedstatus_create : MyWeb.config
{
rt.Category = null;
}
_db.SaveChanges();
L_msg.Text = "<div class='alert alert-success'>儲存成功</div>";
// 如果是新增,更新隱藏欄位並切換標題為編輯
if (HF_Id.Value == "")
// 如果是新增,更新隱藏欄位並切換標題
if (string.IsNullOrEmpty(HF_Code.Value))
{
HF_Id.Value = rt.Uuid.ToString();
HF_Code.Value = rt.Code;
L_title.Text = "編輯區域類型";
}
Response.Redirect("index.aspx");
}
catch (Exception ex)
@@ -100,4 +106,4 @@ public partial class admin_region_bed_bedstatus_create : MyWeb.config
L_msg.Text = $"<div class='alert alert-danger'>錯誤:{ex.Message}</div>";
}
}
}
}

View File

@@ -20,7 +20,7 @@
:loading="loading"
>
<template #item.actions="{item}">
<a :href="'create.aspx?statusid='+item.uuid" class="btn btn-primary"><i class="mdi mdi-pencil"></i>修改</a>
<a :href="'create.aspx?code='+item.code" class="btn btn-primary"><i class="mdi mdi-pencil"></i>修改</a>
<button
type="button"
class="btn btn-outline-danger"
@@ -46,11 +46,10 @@
data() {
return {
headers: [
{ text: 'Id', value: 'id' },
{ text: '狀態名稱', value: 'name' },
{ text: '狀態代碼', value: 'code' },
{ text: '描述', value: 'description' },
{ text: '状态分类', value: 'categoryName'},
{ text: '状态分类', value: 'categoryName' },
{ text: '', value: 'actions' }
],
items: [],
@@ -75,10 +74,10 @@
},
deleteStatus(item) {
axios.post('/api/region/bed/status/delete', null, {
params: { id: item.uuid }
params: { code: item.code }
})
.then(() => {
this.items = this.items.filter(i => i.uuid != item.uuid);
this.items = this.items.filter(i => i.code != item.code);
this.$refs.messageModal.open({
title: '操作成功',
message: '刪除成功!',

View File

@@ -112,7 +112,7 @@
<h2 class="region-title mb-3">{{ region.regionPath }}</h2>
<div class="row g-3 justify-content-start">
<div v-for="room in region.room" :key="room.ruid" class="col-12 col-md-6 col-lg-4">
<div v-for="room in region.room" :key="room.ruid" class="col-12 col-md-6 col-lg-6">
<div class="card h-100 shadow-sm" style="min-height: 300px; max-height: 400px; overflow-y: auto; border-radius: 0.5rem;">
<!-- 上部:房間名稱 -->
@@ -138,20 +138,26 @@
<thead>
<tr>
<th scope="col">床位名稱</th>
<th scope="col">是否可用</th>
<th scope="col">使用明細</th>
<th scope="col">掛單</th>
<th scope="col">當前狀態</th>
</tr>
</thead>
<tbody>
<tr v-for="bed in room.beds" :key="bed.uuid"
:class="bed.canuse ? 'table-success' : 'table-danger'">
<td>{{ bed.name }}</td>
<td :class="!bed.canuse ? 'text-danger' : 'text-success'">
{{ bed.canuse ? '是' : '否' }}
</td>
<td>
<button type="button" class="btn btn-primary" @click="showBedSchedule(bed)">查看明細</button>
</td>
<td>
<button type="button" class="btn btn-primary">
快速掛單
</button>
</td>
<td>
{{bed.statusname}}
</td>
</tr>
</tbody>
</table>
@@ -251,6 +257,7 @@
{ text: '使用日期', value: 'scheduledate' },
{ text: '掛單單號', value: 'guaDanOrderNo' },
{ text: '標題', value: 'title' },
{ text: '掛單人', value: 'usename' },
{ text: '查看掛單', value: 'actions' },
],
},
@@ -381,9 +388,6 @@
return { maleBeds, femaleBeds };
}
}
})
</script>
</asp:Content>