119 lines
3.8 KiB
C#
119 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace Education.Forms.基本資料
|
|
{
|
|
public partial class 片語管理 : FormBase
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
FunctionName = "片語管理";
|
|
|
|
Form_View = fv片語;
|
|
Grid_View = gv片語;
|
|
FormView_DataSource = ds片語Form;
|
|
GridView_DataSource = ds片語Grid;
|
|
|
|
AddTabButton(MultiView1, 0, tab處理);
|
|
AddTabButton(MultiView1, 1, tab查詢);
|
|
|
|
if (!IsPostBack)
|
|
{
|
|
ActivateTab(MultiView1, 0);
|
|
}
|
|
else
|
|
{
|
|
Grid_View.DataBind();
|
|
Form_View.DataBind();
|
|
}
|
|
|
|
if (Form_View.CurrentMode != FormViewMode.ReadOnly)
|
|
{
|
|
Grid_View.Visible = false;
|
|
}
|
|
}
|
|
|
|
protected void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
Grid_View.PageIndex = 0;
|
|
Grid_View.DataBind();
|
|
}
|
|
|
|
protected void btnClear_Click(object sender, EventArgs e)
|
|
{
|
|
ddl適用欄位_Search.SelectedValue = "";
|
|
txt片語內容_Search.Text = "";
|
|
}
|
|
|
|
protected override void GridView_DataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
|
|
{
|
|
base.GridView_DataSource_Selected(sender, e);
|
|
|
|
if (MultiView1.ActiveViewIndex == 1)
|
|
{
|
|
if (e.ReturnValue is 片語List list && list.Count > 0)
|
|
ActivateTab(MultiView1, 0);
|
|
else
|
|
lbMessage.Text = "找不到合乎條件的資料";
|
|
}
|
|
}
|
|
|
|
protected void dsForm_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
|
|
{
|
|
e.ObjectInstance = Dao片語;
|
|
}
|
|
|
|
protected void dsGrid_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
|
|
{
|
|
e.ObjectInstance = Dao片語;
|
|
}
|
|
|
|
protected string Get適用欄位Value()
|
|
{
|
|
var 適用欄位Items = FindControl<CheckBoxList>(Form_View, "cbl適用欄位").Items;
|
|
var 適用欄位Value = new List<string>();
|
|
for (var i = 0; i < 適用欄位Items.Count; i++)
|
|
{
|
|
var item = 適用欄位Items[i];
|
|
if (item.Selected)
|
|
適用欄位Value.Add(item.Value);
|
|
}
|
|
return string.Join(",", 適用欄位Value.ToArray());
|
|
}
|
|
|
|
protected override void FormView_ItemInserting(object sender, FormViewInsertEventArgs e)
|
|
{
|
|
base.FormView_ItemInserting(sender, e);
|
|
if (e.Values.Contains("適用欄位"))
|
|
e.Values["適用欄位"] = Get適用欄位Value();
|
|
else
|
|
e.Values.Add("適用欄位", Get適用欄位Value());
|
|
}
|
|
|
|
protected override void FormView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
|
|
{
|
|
base.FormView_ItemUpdating(sender, e);
|
|
if (e.NewValues.Contains("適用欄位"))
|
|
e.NewValues["適用欄位"] = Get適用欄位Value();
|
|
else
|
|
e.NewValues.Add("適用欄位", Get適用欄位Value());
|
|
}
|
|
|
|
protected override void FormView_EditDataBound(object sender, EventArgs e)
|
|
{
|
|
base.FormView_EditDataBound(sender, e);
|
|
CheckBoxList cbl適用欄位 = FindControl<CheckBoxList>(Form_View, "cbl適用欄位");
|
|
|
|
foreach (ListItem item in cbl適用欄位.Items)
|
|
{
|
|
item.Selected = (Form_View.DataItem as 片語Item).適用欄位.IndexOf(item.Value) >= 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|