62,073
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 初始化界面
/// </summary>
protected void InitPage()
{
this.pvm_ObjectDataSource.SelectParameters["property_id"].DefaultValue = Property_ID.ToString();
GridView2.DataBind();
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 ADOnline.Model;
using ADOnline.Web.Common;
using ADOnline.Bll;
using System.Collections.Generic;
using System.Reflection;
namespace ADOnline.Web.FileManager.UserControl
{
public partial class PropertyValuesManager : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["property_id"] == null)
ViewState.Add("property_id", -1);
if (ViewState["extend_id"] == null)
ViewState.Add("extend_id", -1);
if (ViewState["pv_list"] == null)
ViewState.Add("pv_list", new List<PropertyValues>());
InitPage();
}
#region 页面属性
public int Property_ID//属性编号
{
get { return Convert.ToInt32(ViewState["property_id"]); }
set { ViewState["property_id"] = value; }
}
public int Extend_ID//继承属性编号
{
get { return Convert.ToInt32(ViewState["extend_id"]); }
set{ViewState["extend_id"]=value;}
}
public List<PropertyValues> PV_List//父属性值集合
{
get { return (List<PropertyValues>)ViewState["pv_list"]; }
set { ViewState["pv_list"] = value; }
}
#endregion
/// <summary>
/// 初始化界面
/// </summary>
protected void InitPage()
{
this.pvm_ObjectDataSource.SelectParameters["property_id"].DefaultValue = Property_ID.ToString();
if (Extend_ID >0)
{
PV_List = BPropertyValues.GetExtendValues(Extend_ID,1);
this.ddlFatherValue.DataSource = PV_List;
this.ddlFatherValue.DataBind();
}
else
this.ddlFatherValue.Enabled = false;
}
/// <summary>
/// 添加新的属性值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAdd_Click(object sender, EventArgs e)
{
PropertyValues pv = new PropertyValues();
pv.Property_ID = Property_ID;
pv.PV_FatherID = this.ddlFatherValue.SelectedValue == DBNull.Value.ToString() ? 0 : Convert.ToInt32(this.ddlFatherValue.SelectedValue);
pv.PV_ProExtendID = Extend_ID < 0 ? 0 : Extend_ID;
pv.PV_Value = this.txtValue.Text;
pv.PV_State = 1;
BPropertyValues.Add(pv);
Response.Write("<script>alert('添加成功!');</script>");
this.txtValue.Text = string.Empty;
}
/// <summary>
/// 数据保存事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
PropertyValues pv = new PropertyValues();
pv.Property_ID = Property_ID;
pv.PropertyValues_ID = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Values[0].ToString());
pv.PV_ProExtendID = Extend_ID == -1 ? 0 : Extend_ID;
pv.PV_Value = ((TextBox)(GridView2.Rows[e.RowIndex].Cells[0].Controls[0])).Text;
string fatherid = ((DropDownList)GridView2.Rows[e.RowIndex].FindControl("pvm_ddlValues")).SelectedValue;
pv.PV_FatherID = (fatherid == DBNull.Value.ToString() ? 0 : Convert.ToInt32(fatherid));
pv.PV_State = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Values[1].ToString());
BPropertyValues.Update(pv);
this.GridView2.EditIndex = -1;
e.Cancel = true;
}
/// <summary>
/// 行命令事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "stop")
{
string[] argvalues = e.CommandArgument.ToString().Split(',');
int pro_values_id = Convert.ToInt32(argvalues[0]);
BPropertyValues.UpdatePVState(0, pro_values_id);
}
else if (e.CommandName == "use")
{
string[] argvalues = e.CommandArgument.ToString().Split(',');
int pro_values_id = Convert.ToInt32(argvalues[0]);
BPropertyValues.UpdatePVState(1, pro_values_id);
}
}
/// <summary>
/// Gridview行绑定事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex != GridView2.EditIndex)
{
if (GridView2.DataKeys[e.Row.RowIndex].Values[1].ToString() == "0")
{
((LinkButton)e.Row.FindControl("lbtnUse")).Visible = true;
((LinkButton)e.Row.FindControl("lbtnStop")).Visible = false;
}
else
{
((LinkButton)e.Row.FindControl("lbtnUse")).Visible = false;
((LinkButton)e.Row.FindControl("lbtnStop")).Visible = true;
}
}
}
}
}
}
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PropertyValuesManager.ascx.cs" Inherits="ADOnline.Web.FileManager.UserControl.PropertyValuesManager" %>
<div id="propertyValue" runat="server">
<asp:GridView ID="GridView2" Width="100%" DataKeyNames="PropertyValues_ID,PV_State,PV_FatherID" runat="server" AutoGenerateColumns="False" OnRowUpdating="GridView2_RowUpdating" DataSourceID="pvm_ObjectDataSource" OnRowCommand="GridView2_RowCommand" OnRowDataBound="GridView2_RowDataBound" >
<Columns>
<asp:BoundField DataField="PV_Value" HeaderText="属性值" />
<asp:BoundField HeaderText="父属性名称" DataField="PV_ExtendName" ReadOnly="True" />
<asp:TemplateField HeaderText="父属性值">
<EditItemTemplate>
<asp:DropDownList ID="pvm_ddlValues" runat="server" Width="106px" SelectedValue='<%# Eval("PV_FatherID") %>' DataTextField="PV_Value" DataSource="<%# PV_List %>" DataValueField="PropertyValues_ID">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("PV_FatherValue") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="lbtnEdit" runat="server" CommandName="edit" Font-Size="14px">编辑</asp:LinkButton>
<asp:LinkButton ID="lbtnUse" runat="server" CommandName="use" Font-Size="14px" CommandArgument='<%# Eval("PropertyValues_ID")+","+((GridViewRow)Container).RowIndex %>'>启用</asp:LinkButton>
<asp:LinkButton ID="lbtnStop" runat="server" CommandName="stop" Font-Size="14px" CommandArgument='<%# Eval("PropertyValues_ID")+","+((GridViewRow)Container).RowIndex %>'>禁用</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lbtnSave" runat="server" CommandName="update" Font-Size="14px">更新</asp:LinkButton>
<asp:LinkButton ID="lbtnCancel" runat="server" CommandName="cancel" Font-Size="14px">取消</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle HorizontalAlign="Center" ForeColor="#0066CC" Font-Size="14px" Height="35px" BackColor="#E9F2FF" VerticalAlign="Middle"/>
<AlternatingRowStyle BackColor="White" />
<HeaderStyle ForeColor="White" BackColor="#507CD1" Font-Size="14px" Height="35px" />
</asp:GridView>
<asp:ObjectDataSource ID="pvm_ObjectDataSource" runat="server" SelectMethod="GetExtendValues"
TypeName="ADOnline.Bll.BPropertyValues">
<SelectParameters>
<asp:Parameter Name="property_id" Type="Int32" />
<asp:Parameter DefaultValue="-1" Name="state" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddlFatherValue" runat="server" Width="148px" DataTextField="PV_Value" DataValueField="PropertyValues_ID">
</asp:DropDownList>
<asp:Button ID="btnAdd" runat="server" Text="添 加" OnClick="btnAdd_Click" />
<input type="hidden" id="hidIsEdit" runat="server" value="0" />
</div>