Thank you!This is all source.I put it replaced with CheckBoxList or RadioButtonList,But still won't do.If there is no way,I will use js to realize.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestAddShopInfo.ascx.cs"
Inherits="UserControls_TestAddShopInfo" EnableViewState="true" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<style type="text/css">
.labelStyle
{
color: #444;
font-size: 11px;
background-color: #e7f0f6;
}
label
{
color: #444;
font-size: 12px;
}
</style>
<ext:FormPanel ID="FormPanel1" Collapsible="true" Header="false" Icon="PageAdd" runat="server"
Title="添加新概念店" MonitorValid="true" Padding="5" ButtonAlign="Right" Width="830px"
Layout="Form">
<Items>
<ext:FormPanel Header="true" Icon="UserAdd" ID="fpnlShopkeeper" Border="true" Collapsible="true"
runat="server" Title="店主信息" AutoHeight="true" LabelWidth="120">
<Content>
<ext:FormPanel runat="server" Border="false" PaddingSummary="0" ID="FormPanel11"
Layout="Column">
<Items>
<ext:ComboBox Editable="false" ID="ddlTypeOfIdentificationDocument" runat="server">
</ext:ComboBox>
<ext:DisplayField runat="server" ID="df" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtIDNO" runat="server">
</ext:TextField>
<ext:DisplayField runat="server" ID="DisplayField4" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtName" runat="server">
</ext:TextField>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" Border="false" PaddingSummary="0" ID="FormPanel2" Layout="Column">
<Items>
<ext:TextField ID="txtNationality" runat="server">
</ext:TextField>
<ext:DisplayField runat="server" ID="DisplayField2" Text=" ">
</ext:DisplayField>
<ext:ComboBox ID="ddlMaritalStatus" Editable="false" runat="server">
</ext:ComboBox>
<ext:DisplayField runat="server" ID="DisplayField3" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtHighestEducation" runat="server">
</ext:TextField>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel3" Layout="Column">
<Items>
<ext:ComboBox ID="ddlSex" Editable="false" runat="server">
</ext:ComboBox>
<ext:DisplayField runat="server" ID="DisplayField1" Text=" ">
</ext:DisplayField>
<ext:DateField ID="txtBirthday" runat="server">
</ext:DateField>
<ext:DisplayField runat="server" ID="DisplayField5" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtQQ" runat="server">
</ext:TextField>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel4" Layout="Column">
<Items>
<ext:TextField ID="txtHomePhone" runat="server">
</ext:TextField>
<ext:DisplayField runat="server" ID="DisplayField6" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtMobilePhone" runat="server">
</ext:TextField>
<ext:DisplayField runat="server" ID="DisplayField7" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtEmail" runat="server">
</ext:TextField>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel5" Layout="Column">
<Items>
<ext:NumberField ID="txtShopCount" runat="server">
</ext:NumberField>
<ext:DisplayField runat="server" ID="DisplayField8" Text=" ">
</ext:DisplayField>
<ext:DateField ID="txtOpeningTime" runat="server">
</ext:DateField>
<ext:DisplayField runat="server" ID="DisplayField9" Text=" ">
</ext:DisplayField>
</Items>
</ext:FormPanel>
</Content>
</ext:FormPanel>
<ext:FormPanel ID="fpnlShopInfo" Icon="PhoneAdd" Border="true" Collapsible="true"
runat="server" Title="门店信息" AutoHeight="true" LabelWidth="120">
<Content>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel7" Layout="Column">
<Items>
<ext:ComboBox ID="ddlArea" Editable="false" runat="server">
</ext:ComboBox>
<ext:DisplayField runat="server" ID="DisplayField10" Text=" ">
</ext:DisplayField>
<ext:ComboBox ID="ddlProvince" Editable="false" runat="server">
</ext:ComboBox>
<ext:DisplayField runat="server" ID="DisplayField11" Text=" ">
</ext:DisplayField>
<ext:ComboBox ID="ddlCitys" Editable="false" runat="server">
</ext:ComboBox>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel8" Layout="Column">
<Items>
<ext:TextField ID="txtShopName" IsRemoteValidation="true" runat="server">
<RemoteValidation OnValidation="CheckField">
</RemoteValidation>
</ext:TextField>
<ext:DisplayField runat="server" ID="DisplayField13" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtShopPhone" runat="server">
</ext:TextField>
<ext:DisplayField runat="server" ID="DisplayField12" Text=" ">
</ext:DisplayField>
<ext:ComboBox ID="ddlShopType" Editable="false" runat="server">
</ext:ComboBox>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel9" Layout="Column">
<Items>
<ext:TextField ID="txtOracleNO" runat="server">
</ext:TextField>
<ext:DisplayField runat="server" ID="DisplayField14" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtContractNO" runat="server">
</ext:TextField>
<ext:DisplayField runat="server" ID="DisplayField15" Text=" ">
</ext:DisplayField>
<ext:TextField ID="txtAddress" runat="server">
</ext:TextField>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" Border="false" PaddingSummary="0" ID="fpnlAcreage"
Layout="Form">
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel12"
Layout="Column">
<Items>
<ext:ComboBox ID="ddlOwnerType" Editable="false" runat="server">
</ext:ComboBox>
<ext:DisplayField runat="server" ID="DisplayField16" Text=" ">
</ext:DisplayField>
<ext:ComboBox ID="ddlFrontageState" Editable="false" runat="server">
</ext:ComboBox>
<ext:DisplayField runat="server" ID="DisplayField17" Text=" ">
</ext:DisplayField>
<ext:ComboBox ID="ddlCrossroadsState" Editable="false" runat="server">
</ext:ComboBox>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel13"
Layout="Column">
<Items>
<ext:NumberField ID="txtFloor" runat="server">
</ext:NumberField>
<ext:DisplayField runat="server" ID="DisplayField18" Text=" ">
</ext:DisplayField>
<ext:NumberField ID="txtFloorNum" runat="server">
</ext:NumberField>
<ext:DisplayField runat="server" ID="DisplayField19" Text=" ">
</ext:DisplayField>
<ext:NumberField ID="txtSignboardAcreage" runat="server">
</ext:NumberField>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel14"
Layout="Column">
<Items>
<ext:NumberField ID="txtEmployeeNum" runat="server">
</ext:NumberField>
<ext:DisplayField runat="server" ID="DisplayField20" Text=" ">
</ext:DisplayField>
<ext:NumberField ID="txtTechnicianNum" runat="server">
</ext:NumberField>
<ext:DisplayField runat="server" ID="DisplayField21" Text=" ">
</ext:DisplayField>
<ext:NumberField ID="txtCustomerNum" runat="server">
</ext:NumberField>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel15"
Layout="Column">
<Items>
<ext:NumberField ID="txtRoomNum" runat="server">
</ext:NumberField>
<ext:DisplayField runat="server" ID="DisplayField22" Text=" ">
</ext:DisplayField>
<ext:NumberField ID="txtBedNum" runat="server">
</ext:NumberField>
<ext:DisplayField runat="server" ID="DisplayField23" Text=" ">
</ext:DisplayField>
<ext:NumberField ID="txtMonthlySales" runat="server">
</ext:NumberField>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel16"
Layout="Column">
<Items>
<ext:FormPanel ID="Panel1" IsFormField="true" FieldLabel="商店圈" runat="server" Border="false"
Width="820" Height="40">
<Content>
<asp:CheckBoxList ID="cblBusinessDistrict" runat="server">
</asp:CheckBoxList>
</Content>
</ext:FormPanel>
<%-- <ext:CheckboxGroup ID="cblBusinessDistrict" runat="server">
</ext:CheckboxGroup>--%>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel17"
Layout="Column">
<Items>
<ext:FormPanel ID="FormPanel6" IsFormField="true" FieldLabel="十大功能检测仪" runat="server"
Border="false" Width="250" Height="50">
<Content>
<asp:RadioButtonList ID="rblDetectorState" RepeatLayout="Table" Width="120" runat="server"></asp:RadioButtonList>
</Content>
</ext:FormPanel>
<%--<ext:RadioGroup runat="server" Width="280px" ID="rblDetectorState">
</ext:RadioGroup>--%>
<ext:DisplayField runat="server" ID="DisplayField25" Text="( ">
</ext:DisplayField>
<ext:DateField LabelWidth="80" ID="txtInstallationValidity" Width="180" runat="server">
</ext:DateField>
<ext:DisplayField runat="server" ID="DisplayField24" Text=" ">
</ext:DisplayField>
<ext:DateField LabelWidth="80" ID="txtLastDecorationDate" Width="180" runat="server">
</ext:DateField>
<ext:DisplayField runat="server" ID="DisplayField26" Text=" )">
</ext:DisplayField>
</Items>
</ext:FormPanel>
</Content>
</ext:FormPanel>
<ext:FormPanel ID="FormPanel19" Icon="ApplicationCascade" Border="true" Collapsible="true"
runat="server" Title="竞争环境" AutoHeight="true" LabelWidth="120">
<Content>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel20"
Layout="Column">
<Items>
<ext:FormPanel runat="server" IsFormField="true" FieldLabel="临近竞争店" Border="false"
Width="820" Height="40">
<Content>
<asp:CheckBoxList ID="cblCompeteShops" runat="server">
</asp:CheckBoxList>
</Content>
</ext:FormPanel>
<%-- <ext:CheckboxGroup ID="cblCompeteShops" runat="server">
</ext:CheckboxGroup>--%>
</Items>
</ext:FormPanel>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel21"
Layout="Column">
<Items>
<ext:TextArea ID="txtCompeteRemark" Width="600" Height="100" runat="server">
</ext:TextArea>
</Items>
</ext:FormPanel>
</Content>
</ext:FormPanel>
<ext:FormPanel ID="FormPanel10" Icon="ApplicationAdd" Border="true" Collapsible="true"
runat="server" Title="硬件配套" AutoHeight="true" LabelWidth="120">
<Content>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel18"
Layout="Column" Height="80">
<%--<Items>
<ext:CheckboxGroup ID="cblHardwares" runat="server">
</ext:CheckboxGroup>
</Items>--%>
<Content>
<asp:CheckBoxList ID="cblHardwares" runat="server">
</asp:CheckBoxList>
</Content>
</ext:FormPanel>
</Content>
</ext:FormPanel>
<ext:FormPanel ID="FormPanel22" Icon="UserComment" Border="true" Collapsible="true"
runat="server" Title="需求建议" AutoHeight="true" LabelWidth="120">
<Content>
<ext:FormPanel runat="server" PaddingSummary="0" Border="false" ID="FormPanel23"
Layout="Column">
<Items>
<ext:TextArea ID="txtRemark" MaxLength="10" Width="600" Height="100" runat="server">
</ext:TextArea>
</Items>
</ext:FormPanel>
</Content>
</ext:FormPanel>
</Items>
<Buttons>
<ext:Button ID="btnSave" runat="server" Text="保存" Icon="Disk">
<DirectEvents>
<Click OnEvent="btnSave_Click">
<EventMask ShowMask="true" Msg="正在处理..." />
</Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="Button2" runat="server" Text="提交" Icon="PageAdd" />
</Buttons>
<BottomBar>
<ext:StatusBar ID="StatusBar1" runat="server" />
</BottomBar>
<TopBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:ToolbarFill ID="ToolbarFill1" runat="server" />
<ext:Button ID="tbSave" runat="server" Icon="Disk" Text="保存">
<DirectEvents>
<Click OnEvent="btnSave_Click">
<EventMask ShowMask="true" Msg="正在处理数据..." />
</Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="btnSaveRecord" runat="server" Icon="PageAdd" Text="提交">
<DirectEvents>
<%-- <Click OnEvent="SaveClick" Before="return #{FormPanel1}.getForm().isValid();" Success="Ext.Msg.alert('', 'Saved');">
<ExtraParams>
<ext:Parameter Name="recordId" Value="#{Store1}.getAt(0).id" Mode="Raw" />
</ExtraParams>
</Click>--%>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Listeners>
<ClientValidation Handler="#{btnSave}.setDisabled(!valid);#{tbSave}.setDisabled(!valid);this.getBottomToolbar().setStatus({text : valid ? '验证通过,可以提交数据' : '表单验证未通过,您不能提交数据', iconCls: valid ? 'icon-accept' : 'icon-exclamation'});" />
</Listeners>
</ext:FormPanel>
<script type="text/javascript">
Ext.onReady(function () {
setLabelClass();
});
function setLabelClass() {
$(".x-form-item-label").addClass("labelStyle");
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Xml.Linq;
using Ext.Net;
using NBShopMode.Shop;
using NBShopService;
using System.Reflection;
using System.Text;
public partial class UserControls_TestAddShopInfo : System.Web.UI.UserControl
{
NBShopService.AttributesServices attributes = new NBShopService.AttributesServices();
ShopService shopServices = new ShopService();
protected void Page_Load(object sender, EventArgs e)
{
Loading();
}
private void Loading()
{
string xmlPath = Server.MapPath("~/App_Data/AddShopperFileds.xml");
ShopID = shopServices.GetNewGuid();
ShopInfo shopInfo = shopServices.SelectAllShopInfoByShopId(ShopID);
ShopkeeperID = shopInfo.Shopkeeper.Id;
try
{
//默认宽度
int _width = 200;
//默认验证提示模式
string _msgTarget = null;
if (File.Exists(xmlPath))
{
XElement elements = XElement.Load(xmlPath);
var fields = elements.Descendants("Field");
var GlobalDefaultConfig = elements.Element("GlobalDefaultConfig");
var attrDefaultWidth = GlobalDefaultConfig.Element("Width");
if (attrDefaultWidth != null && MyRegex.IsNumberRegex(attrDefaultWidth.Value))
_width = Convert.ToInt32(attrDefaultWidth.Value);
var defaultMsgTarget = GlobalDefaultConfig.Element("MsgTarget");
if (defaultMsgTarget != null)
_msgTarget = defaultMsgTarget.Value;
if (!IsPostBack)
{
SetFields(_width, _msgTarget, fields);
#region 绑定属性(性别、十字路口等等)
#region 绑定性别
BindComobox(shopServices.SelectSexKind() as List<NBShopMode.Attributes.SysAttribute>, "ddlSex", "AttributeValue", "AttributeId", shopInfo.Shopkeeper.SexTypeId);
#endregion
#region 十字路口
BindComobox(shopServices.SelectCrossroadsStatus() as List<NBShopMode.Attributes.SysAttribute>, "ddlCrossroadsState", "AttributeValue", "AttributeId", shopInfo.Shop.CrossroadsStatusValue);
#endregion
#region 临街状态
BindComobox(shopServices.SelectFrontageStatus() as List<NBShopMode.Attributes.SysAttribute>, "ddlFrontageState", "AttributeValue", "AttributeId", shopInfo.Shop.FrontageStatusValue);
#endregion
#region 婚姻状态
BindComobox(shopServices.SelectMaritalStatus() as List<NBShopMode.Attributes.SysAttribute>, "ddlMaritalStatus", "AttributeValue", "AttributeId", shopInfo.Shopkeeper.MaritalStatus);
#endregion
#region 店铺持有类型
BindComobox(shopServices.SelectShopHoldKind() as List<NBShopMode.Attributes.SysAttribute>, "ddlOwnerType", "AttributeValue", "AttributeId", shopInfo.Shop.HoldStatusValue);
#endregion
#region 店铺类型
BindComobox(shopServices.SelectShopKind() as List<NBShopMode.Attributes.SysAttribute>, "ddlShopType", "AttributeValue", "AttributeId", shopInfo.Shop.ShopTypeValue);
#endregion
#region 证件类型
BindComobox(shopServices.SelectCredentialsKind() as List<NBShopMode.Attributes.SysAttribute>, "ddlTypeOfIdentificationDocument", "AttributeValue", "AttributeId", shopInfo.Shopkeeper.CredentialsName);
#endregion
#endregion
}
#region 绑定商店圈、临近竞争店、硬件设备等信息
BindCheckGroup(shopInfo.IlBusinessDistrict as List<BusinessDistrict>, "cblBusinessDistrict", "BDTypeName", "BDTypeId", "CheckValue");
BindCheckGroup(shopInfo.IlCompete as List<Compete>, "cblCompeteShops", "CompeteShopName", "CompeteShopId", "CheckValue");
BindCheckGroup(shopInfo.IlSupportingFacility as List<SupportingFacility>, "cblHardwares", "SFTypeName", "SFTypeId", "CheckValue");
BindRadioGroup(shopServices.SelectCheckMeterStatus() as List<NBShopMode.Attributes.SysAttribute>, "rblDetectorState", "AttributeValue", "AttributeId", shopInfo.Shop.CheckMeterStatusValue, false);
#endregion
#region 绑定面积信息
List<Acreage> lstAcreage = shopInfo.IlAcreage as List<Acreage>;
int i = 0;
foreach (var item in lstAcreage)
{
Ext.Net.FormPanel _fp = new FormPanel();
_fp.PaddingSummary = "0";
_fp.Border = false;
_fp.Layout = "Column";
Ext.Net.NumberField _nf1 = new NumberField();
_nf1.FieldLabel = item.AcreageTypeName + "(M²)";
_nf1.MinValue = 0;
_nf1.Text = Math.Round(item.AcreageValue, 2).ToString();
_nf1.Width = 250;
_nf1.LabelWidth = 120;
_nf1.ID = "Acreage" + i;
_fp.Items.Add(_nf1);
Ext.Net.DisplayField _df = new DisplayField();
_df.Text = "( ";
_fp.Items.Add(_df);
Ext.Net.NumberField _nf2 = new NumberField();
_nf2.FieldLabel = "长(M)";
_nf2.LabelWidth = 75;
_nf2.MinValue = 0;
_nf2.Text = Math.Round(item.Length, 2).ToString();
_nf2.Width = 160;
_nf2.ID = "AcreageLength" + i;
_fp.Items.Add(_nf2);
Ext.Net.NumberField _nf3 = new NumberField();
_nf3.FieldLabel = " 宽(M)";
_nf3.MinValue = 0;
_nf3.LabelWidth = 75;
_nf3.Text = Math.Round(item.Wide, 2).ToString();
_nf3.Width = 160;
_nf3.ID = "AcreageWide" + i;
_fp.Items.Add(_nf3);
Ext.Net.NumberField _nf4 = new NumberField();
_nf4.FieldLabel = " 高(M)";
_nf4.MinValue = 0;
_nf4.LabelWidth = 75;
_nf4.Text = Math.Round(item.High, 2).ToString();
_nf4.Width = 160;
_nf4.ID = "AcreageHigh" + i;
_fp.Items.Add(_nf4);
Ext.Net.DisplayField _df2 = new DisplayField();
_df2.Text = " )";
_fp.Items.Add(_df2);
Ext.Net.Hidden _hdAcreageTypeId = new Hidden();
_hdAcreageTypeId.Value = item.AcreageTypeId;
_hdAcreageTypeId.ID = "AcreageTypeId" + i;
_fp.Items.Add(_hdAcreageTypeId);
fpnlAcreage.Items.Add(_fp);
i++;
}
#endregion
GC.Collect();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
//LogManager.WriteErrorLog(ex);
}
}
protected void CheckField(object sender, RemoteValidationEventArgs e)
{
TextField field = (TextField)sender;
if (field.Text.Length > 0)
{
if (field.Text.Contains("测试"))
{
e.Success = false;
e.ErrorMessage = "该项已存在,请不要重复添加!";
}
else
{
e.Success = true;
}
}
else
{
e.Success = false;
e.ErrorMessage = "请填写店名!";
}
}
/// <summary>
/// 绑定复选框组
/// </summary>
/// <typeparam name="T">类类型</typeparam>
/// <param name="lst">泛型集合</param>
/// <param name="ID">复选框组ID</param>
/// <param name="TextPropertyName">需要绑定的文本属性字段名(大写小都必须一致)</param>
/// <param name="ValuePropertyName">需要绑定的值属性字段名(大写小都必须一致)</param>
/// <param name="CheckedPropertyName">需要绑定的选择属性字段名(大写小都必须一致)</param>
protected void BindCheckGroup<T>(List<T> lst, string ID, string TextPropertyName, string ValuePropertyName, string CheckedPropertyName)
{
#region 绑定商圈类型列表
if (lst != null && lst.Count > 0)
{
Control _control = this.FindControl(ID);
if (_control is Ext.Net.CheckboxGroup)
{
CheckboxGroup groupChks = _control as Ext.Net.CheckboxGroup;
if (groupChks == null)
return;
groupChks.ColumnsNumber = 4;
groupChks.Items.Clear();
foreach (var item in lst)
{
T t = item;
Type type = t.GetType();
Ext.Net.Checkbox chk = new Ext.Net.Checkbox();
PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
if (TextProInfo == null)
ThrowNullException(type, TextPropertyName);
PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
if (ValueProInfo == null)
ThrowNullException(type, ValuePropertyName);
PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
if (CheckedProInfo == null)
ThrowNullException(type, CheckedPropertyName);
object objText = TextProInfo.GetValue(t, null);
chk.BoxLabel = objText == null ? string.Empty : objText.ToString();
object objValue = ValueProInfo.GetValue(t, null).ToString();
chk.Tag = objValue == null ? string.Empty : objValue.ToString();
if (CheckedProInfo.GetValue(t, null).ToString() == "1")
chk.Checked = true;
groupChks.Items.Add(chk);
}
}
else if (_control is CheckBoxList)
{
CheckBoxList _cbl = _control as CheckBoxList;
_cbl.RepeatDirection = RepeatDirection.Horizontal;
_cbl.RepeatLayout = RepeatLayout.Table;
_cbl.RepeatColumns = 7;
_cbl.Width = Unit.Parse("100%");
foreach (var item in lst)
{
T t = item;
Type type = t.GetType();
Ext.Net.Checkbox chk = new Ext.Net.Checkbox();
PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
if (TextProInfo == null)
ThrowNullException(type, TextPropertyName);
PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
if (ValueProInfo == null)
ThrowNullException(type, ValuePropertyName);
PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
if (CheckedProInfo == null)
ThrowNullException(type, CheckedPropertyName);
object objText = TextProInfo.GetValue(t, null);
object objValue = ValueProInfo.GetValue(t, null).ToString();
System.Web.UI.WebControls.ListItem _li = new System.Web.UI.WebControls.ListItem();
_li.Text = objText == null ? string.Empty : objText.ToString();
_li.Value = objValue == null ? string.Empty : objValue.ToString();
if (CheckedProInfo.GetValue(t, null).ToString() == "1")
_li.Selected = true;
_cbl.Items.Add(_li);
}
}
}
#endregion
}
/// <summary>
/// 通过反射绑定下拉列表
/// </summary>
/// <typeparam name="T">类类型</typeparam>
/// <param name="lst">泛型集合</param>
/// <param name="ID">下拉列表ID</param>
/// <param name="TextPropertyName">文本属性名</param>
/// <param name="ValuePropertyName">值属性名</param>
/// <param name="_SelectValue">选择的值</param>
protected void BindComobox<T>(List<T> lst, string ID, string TextPropertyName, string ValuePropertyName, string _SelectValue)
{
if (lst != null && lst.Count > 0)
{
ComboBox _cbos = this.FindControl(ID) as Ext.Net.ComboBox;
if (_cbos == null)
return;
_cbos.Items.Clear();
foreach (var item in lst)
{
T t = item;
Type type = t.GetType();
Ext.Net.ListItem _li = new Ext.Net.ListItem();
PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
if (TextProInfo == null)
ThrowNullException(type, TextPropertyName);
PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
if (ValueProInfo == null)
ThrowNullException(type, ValuePropertyName);
object objText = TextProInfo.GetValue(t, null);
_li.Text = objText == null ? string.Empty : objText.ToString();
object objValue = ValueProInfo.GetValue(t, null).ToString();
_li.Value = objValue == null ? string.Empty : objValue.ToString();
_cbos.Items.Add(_li);
}
if (!string.IsNullOrEmpty(_SelectValue))
_cbos.SelectByValue(_SelectValue);
}
}
/// <summary>
/// 反射设置选择框组的值
/// </summary>
/// <typeparam name="T">类类型</typeparam>
/// <param name="lst">泛型集合</param>
/// <param name="ID">控件服务器ID</param>
/// <param name="TextPropertyName">文本属性名</param>
/// <param name="ValuePropertyName">值属性名</param>
/// <param name="CheckedPropertyName">选择框属性名</param>
/// <param name="_className">类名</param>
/// <param name="_dicFields">扩展字段集合</param>
/// <returns>泛型集合(NewGuid()表示生成新的Guid)</returns>
protected List<T> SetValueFromCheckGroup<T>(List<T> lst, string ID, string TextPropertyName, string ValuePropertyName, string CheckedPropertyName, string _className, Dictionary<string, string> _dicFields)
{
Control _control = this.FindControl(ID);
if (_control == null)
{
return null;
}
if (_control is Ext.Net.CheckboxGroup)
{
#region ExtCheckGroupBox
CheckboxGroup groupChks = _control as Ext.Net.CheckboxGroup;
//反射加载NBShopMode程序集
Assembly _assembly = Assembly.Load("NBShopMode");
foreach (var item in groupChks.Items)
{
Ext.Net.Checkbox chk = item as Ext.Net.Checkbox;
if (chk != null)
{
//通过反射创建该类的实例
T _t = (T)_assembly.CreateInstance(_className, true);
//获取类型
Type _type = _t.GetType();
if (_type == null)
return null;
//获取文本属性
PropertyInfo TextProInfo = _type.GetProperty(TextPropertyName);
if (TextProInfo == null)
ThrowNullException(_type, TextPropertyName);
//获取值属性
PropertyInfo ValueProInfo = _type.GetProperty(ValuePropertyName);
if (ValueProInfo == null)
ThrowNullException(_type, ValuePropertyName);
//获取选择属性
PropertyInfo CheckedProInfo = _type.GetProperty(CheckedPropertyName);
if (CheckedProInfo == null)
ThrowNullException(_type, CheckedPropertyName);
//设置文本属性的值
if (!string.IsNullOrEmpty(chk.BoxLabel))
TextProInfo.SetValue(_t, Convert.ChangeType(chk.BoxLabel, TextProInfo.PropertyType), null);
//设置值属性的值
if (!string.IsNullOrEmpty(chk.Tag))
ValueProInfo.SetValue(_t, Convert.ChangeType(chk.Tag, ValueProInfo.PropertyType), null);
//设置选择属性的值(1表示选择,0表示未选择)
if (chk.Checked)
CheckedProInfo.SetValue(_t, Convert.ChangeType(1, CheckedProInfo.PropertyType), null);
else
CheckedProInfo.SetValue(_t, Convert.ChangeType(0, CheckedProInfo.PropertyType), null);
//如果扩展字段不为空
if (_dicFields != null && _dicFields.Count >= 0)
{
foreach (var _key in _dicFields.Keys)
{
PropertyInfo _pro = _type.GetProperty(_key);
if (_dicFields[_key] == "NewGuid()")
_pro.SetValue(_t, Convert.ChangeType(Guid.NewGuid().ToString().Replace("-", "").ToUpper(), _pro.PropertyType), null);
else
_pro.SetValue(_t, Convert.ChangeType(_dicFields[_key], _pro.PropertyType), null);
}
}
lst.Add(_t);
}
}
return lst;
#endregion
}
else if (_control is CheckBoxList)
{
#region CheckBoxList
CheckBoxList groupChks = _control as CheckBoxList;
//反射加载NBShopMode程序集
Assembly _assembly = Assembly.Load("NBShopMode");
foreach (System.Web.UI.WebControls.ListItem item in groupChks.Items)
{
//通过反射创建该类的实例
T _t = (T)_assembly.CreateInstance(_className, true);
//获取类型
Type _type = _t.GetType();
if (_type == null)
return null;
//获取文本属性
PropertyInfo TextProInfo = _type.GetProperty(TextPropertyName);
if (TextProInfo == null)
ThrowNullException(_type, TextPropertyName);
//获取值属性
PropertyInfo ValueProInfo = _type.GetProperty(ValuePropertyName);
if (ValueProInfo == null)
ThrowNullException(_type, ValuePropertyName);
//获取选择属性
PropertyInfo CheckedProInfo = _type.GetProperty(CheckedPropertyName);
if (CheckedProInfo == null)
ThrowNullException(_type, CheckedPropertyName);
//设置文本属性的值
if (!string.IsNullOrEmpty(item.Text))
TextProInfo.SetValue(_t, Convert.ChangeType(item.Text, TextProInfo.PropertyType), null);
//设置值属性的值
if (!string.IsNullOrEmpty(item.Value))
ValueProInfo.SetValue(_t, Convert.ChangeType(item.Value, ValueProInfo.PropertyType), null);
//设置选择属性的值(1表示选择,0表示未选择)
if (item.Selected)
CheckedProInfo.SetValue(_t, Convert.ChangeType(1, CheckedProInfo.PropertyType), null);
else
CheckedProInfo.SetValue(_t, Convert.ChangeType(0, CheckedProInfo.PropertyType), null);
//如果扩展字段不为空
if (_dicFields != null && _dicFields.Count >= 0)
{
foreach (var _key in _dicFields.Keys)
{
PropertyInfo _pro = _type.GetProperty(_key);
if (_dicFields[_key] == "NewGuid()")
_pro.SetValue(_t, Convert.ChangeType(Guid.NewGuid().ToString().Replace("-", "").ToUpper(), _pro.PropertyType), null);
else
_pro.SetValue(_t, Convert.ChangeType(_dicFields[_key], _pro.PropertyType), null);
}
}
lst.Add(_t);
}
return lst;
#endregion
}
return null;
}
/// <summary>
/// 绑定单选框组
/// </summary>
/// <typeparam name="T">类类型</typeparam>
/// <param name="lst">泛型集合</param>
/// <param name="ID">复选框组ID</param>
/// <param name="TextPropertyName">需要绑定的文本属性字段名(大写小都必须一致)</param>
/// <param name="ValuePropertyName">需要绑定的值属性字段名(大写小都必须一致)</param>
/// <param name="CheckedPropertyName">需要绑定的选择属性字段名(大写小都必须一致)</param>
/// <param name="isCheckedPropertyName">是否是选择属性字段名,如果如false,则CheckedPropertyName表示选中的值</param>
protected void BindRadioGroup<T>(List<T> lst, string ID, string TextPropertyName, string ValuePropertyName, string CheckedPropertyName, bool isCheckedPropertyName)
{
if (lst != null && lst.Count > 0)
{
Control _control = this.FindControl(ID);
if (_control is Ext.Net.RadioGroup)
{
RadioGroup groupRadios = this.FindControl(ID) as Ext.Net.RadioGroup;
if (groupRadios == null)
return;
//groupRadios.SubmitValue = true;
if (lst.Count <= 4)
{
groupRadios.ColumnsNumber = lst.Count;
}
else
{
groupRadios.ColumnsNumber = 4;
}
groupRadios.Items.Clear();
foreach (var item in lst)
{
T t = item;
Type type = t.GetType();
Ext.Net.Radio rdo = new Ext.Net.Radio();
PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
if (TextProInfo == null)
ThrowNullException(type, TextPropertyName);
PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
if (ValueProInfo == null)
ThrowNullException(type, ValuePropertyName);
object objText = TextProInfo.GetValue(t, null);
rdo.BoxLabel = objText == null ? string.Empty : objText.ToString();
object objValue = ValueProInfo.GetValue(t, null).ToString();
rdo.Tag = objValue == null ? string.Empty : objValue.ToString();
if (!isCheckedPropertyName)
{
if (rdo.Tag == CheckedPropertyName)
rdo.Checked = true;
groupRadios.Items.Add(rdo);
continue;
}
PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
if (CheckedProInfo == null)
ThrowNullException(type, CheckedPropertyName);
if (CheckedProInfo.GetValue(t, null).ToString() == "1")
rdo.Checked = true;
groupRadios.Items.Add(rdo);
}
}
else if (_control is RadioButtonList)
{
RadioButtonList _rbl = _control as RadioButtonList;
_rbl.DataTextField = TextPropertyName;
_rbl.DataValueField = ValuePropertyName;
_rbl.DataSource = lst;
_rbl.RepeatDirection = RepeatDirection.Horizontal;
//_rbl.RepeatLayout = RepeatLayout.Flow;
_rbl.DataBind();
if (!isCheckedPropertyName)
_rbl.SelectedValue = CheckedPropertyName;
}
}
}
private static void ThrowNullException(Type type, string errorMsg)
{
StringBuilder sbPropertiesList = new StringBuilder(errorMsg);
sbPropertiesList.Append("不存在!<br/>");
PropertyInfo[] pros = type.GetProperties();
foreach (var proItem in pros)
{
sbPropertiesList.Append(proItem.Name).Append("<br />");
}
throw new Exception(errorMsg + sbPropertiesList.ToString());
}
protected void btnSave_Click(object sender, DirectEventArgs e)
{
try
{
SaveShopIno();
}
catch (Exception ex)
{
NBShopCommon.LogManager.WriteErrorLog(ex);
}
}
private void SaveShopIno()
{
Shopkeeper keeper = new Shopkeeper();
SetValues(keeper, this);
//店主ID
keeper.Id = ShopkeeperID;
#region 性别
if (ddlSex.SelectedItem != null)
{
keeper.SexTypeId = ddlSex.SelectedItem.Value;
keeper.SexTypeName = ddlSex.SelectedItem.Text;
}
#endregion
#region 证件类型
if (ddlTypeOfIdentificationDocument.SelectedItem != null)
{
keeper.CredentialsId = ddlTypeOfIdentificationDocument.SelectedItem.Value;
keeper.CredentialsName = ddlTypeOfIdentificationDocument.SelectedItem.Text;
}
#endregion
#region 婚姻状态
if (ddlMaritalStatus.SelectedItem != null)
{
keeper.MaritalStatus = ddlMaritalStatus.SelectedItem.Value;
keeper.MaritalStatusName = ddlMaritalStatus.SelectedItem.Text;
}
#endregion
//店铺ID
keeper.ShopId = ShopID;
#region 商圈信息
List<BusinessDistrict> lstBusinessDistrict = new List<BusinessDistrict>();
Dictionary<string, string> dicBusinessDistrictFields = new Dictionary<string, string>();
dicBusinessDistrictFields.Add("BDId", "NewGuid()");
dicBusinessDistrictFields.Add("ShopId", ShopID);
SetValueFromCheckGroup(lstBusinessDistrict, "cblBusinessDistrict", "BDTypeName", "BDTypeId", "CheckValue", "NBShopMode.Shop.BusinessDistrict", dicBusinessDistrictFields);
#endregion
#region 临近竞争店
List<Compete> lstCompete = new List<Compete>();
Dictionary<string, string> dicCompeteFields = new Dictionary<string, string>();
dicCompeteFields.Add("CompeteId", "NewGuid()");
dicCompeteFields.Add("ShopId", ShopID);
SetValueFromCheckGroup(lstCompete, "cblCompeteShops", "CompeteShopName", "CompeteShopId", "CheckValue", "NBShopMode.Shop.Compete", dicCompeteFields);
#endregion
#region 配套设备
List<SupportingFacility> lstSupportingFacility = new List<SupportingFacility>();
Dictionary<string, string> dicSupportingFacilityFields = new Dictionary<string, string>();
dicSupportingFacilityFields.Add("SFId", "NewGuid()");
dicSupportingFacilityFields.Add("ShopId", ShopID);
SetValueFromCheckGroup(lstSupportingFacility, "cblCompeteShops", "SFTypeName", "SFTypeId", "CheckValue", "NBShopMode.Shop.SupportingFacility", dicSupportingFacilityFields);
#endregion
Shop shop = new Shop();
SetValues(shop, this);
//店铺ID
shop.ShopId = ShopID;
#region 区域、城市、省份、店铺持有类型、临街状态、十字路口、检测仪
#region 区域
if (ddlArea.SelectedItem != null)
{
shop.AreaId = ddlArea.SelectedItem.Value;
shop.AreaName = ddlArea.SelectedItem.Text;
}
#endregion
#region 城市
if (ddlCitys.SelectedItem != null)
{
shop.CityId = ddlCitys.SelectedItem.Value;
shop.CityName = ddlCitys.SelectedItem.Text;
}
#endregion
#region 省份
if (ddlProvince.SelectedItem != null)
{
shop.ProvinceId = ddlProvince.SelectedItem.Value;
shop.ProvinceName = ddlProvince.SelectedItem.Text;
}
#endregion
#region 店铺类型
if (ddlShopType.SelectedItem != null)
{
shop.ShopTypeId = ddlShopType.SelectedItem.Value;
shop.ShopTypeValue = ddlShopType.SelectedItem.Text;
}
#endregion
#region 店铺持有类型
if (ddlOwnerType.SelectedItem != null)
{
shop.HoldStatus = ddlOwnerType.SelectedItem.Text;
shop.HoldStatusValue = ddlOwnerType.SelectedItem.Value;
}
#endregion
#region 店铺临街状态
if (ddlFrontageState.SelectedItem != null)
{
shop.FrontageStatus = ddlFrontageState.SelectedItem.Text;
shop.FrontageStatusValue = ddlFrontageState.SelectedItem.Value;
}
#endregion
#region 店铺所处十字路口
if (ddlCrossroadsState.SelectedItem != null)
{
shop.CrossroadsStatus = ddlCrossroadsState.SelectedItem.Text;
shop.CrossroadsStatusValue = ddlCrossroadsState.SelectedItem.Value;
}
#endregion
#region 检测仪状态
//rblDetectorState.CheckedItems.ForEach(delegate(Radio radio)
//{
// shop.CheckMeterStatus = radio.BoxLabel;
// shop.CheckMeterStatusValue = radio.Tag;
//});
if (rblDetectorState.SelectedItem != null)
{
shop.CheckMeterStatus = rblDetectorState.SelectedItem.Text;
shop.CheckMeterStatusValue = rblDetectorState.SelectedItem.Value;
}
#endregion
#endregion
#region 设置面积
List<Acreage> lstAcreage = new List<Acreage>();
for (int i = 0; i < fpnlAcreage.Items.Count; i++)
{
Acreage acr = new Acreage();
acr.AcreageId
= shopServices.GetNewGuid();
#region 面积类型ID
Hidden hf = fpnlAcreage.FindControl("AcreageTypeId" + i) as Hidden;
if (hf != null)
acr.AcreageTypeId = hf.Value.ToString();
#endregion
#region 面积值
NumberField txtAcreageValue = fpnlAcreage.FindControl("Acreage" + i) as NumberField;
if (txtAcreageValue != null)
{
acr.AcreageTypeName = txtAcreageValue.FieldLabel.Substring(0, txtAcreageValue.FieldLabel.Length - 5);
acr.AcreageValue = Convert.ToDecimal(txtAcreageValue.Text);
}
#endregion
#region 高
NumberField txtAcreageHigh = fpnlAcreage.FindControl("AcreageHigh" + i) as NumberField;
if (txtAcreageHigh != null)
acr.High = Convert.ToDecimal(txtAcreageHigh.Text);
#endregion
#region 长
NumberField txtAcreageLength = fpnlAcreage.FindControl("AcreageLength" + i) as NumberField;
if (txtAcreageLength != null)
acr.Length = Convert.ToDecimal(txtAcreageLength.Text);
#endregion
#region 宽
NumberField txtAcreageWide = fpnlAcreage.FindControl("AcreageWide" + i) as NumberField;
if (txtAcreageLength != null)
acr.Wide = Convert.ToDecimal(txtAcreageWide.Text);
#endregion
acr.ShopId = ShopID;
lstAcreage.Add(acr);
}
#endregion
#region 设置店铺信息
ShopInfo shopInfo = new ShopInfo()
{
IlAcreage = lstAcreage,
IlBusinessDistrict = lstBusinessDistrict,
IlCompete = lstCompete,
IlSupportingFacility = lstSupportingFacility,
Shop = shop,
Shopkeeper = keeper
};
#endregion
NBShopCommon.LogManager.WriteTraceLog(NBShopCommon.JSONHelper.ToJSON(shopInfo));
}
private void SetFields(int _width, string _msgTarget, IEnumerable<XElement> fields)
{
foreach (var item in fields)
{
//最大允许长度
int? _maxLength = null;
//显示文本
string _labelText = string.Empty;
//是否允许空
bool _allowBlank = true;
//文本控件ID
string textControlID = item.Attributes("TextControlID").First().Value;
//值(显示的文本)
_labelText = item.Value;
var control = this.FindControl(textControlID);
//最大允许长度
var attrMaxLength = item.Attributes("MaxLength").FirstOrDefault();
if (attrMaxLength != null && MyRegex.IsNumberRegex(attrMaxLength.Value))
_maxLength = Convert.ToInt32(attrMaxLength.Value);
//是否可为空
var attrAllowBlank = item.Attributes("AllowBlank").FirstOrDefault();
if (attrAllowBlank != null)
{
switch (attrAllowBlank.Value.ToLower())
{
case "false":
_allowBlank = false;
break;
case "true":
_allowBlank = true;
break;
}
}
if (control is TextFieldBase)
{
Ext.Net.TextFieldBase txt = control as Ext.Net.TextFieldBase;
txt.FieldLabel = _labelText;
txt.AllowBlank = _allowBlank;
if (txt.Width.IsEmpty || txt.Width == null)
txt.Width = _width;
if (control is NumberField)
{
if (txt.Text.Length == 0)
txt.Text = "0";
}
txt.MsgTarget = MessageTarget.Side;
}
else if (control is Ext.Net.ComboBox)
{
Ext.Net.ComboBox txt = control as Ext.Net.ComboBox;
txt.FieldLabel = _labelText;
txt.AllowBlank = _allowBlank;
txt.Width = _width;
txt.MsgTarget = MessageTarget.Side;
}
else if (control is Ext.Net.CheckboxBase)
{
Ext.Net.CheckboxBase txt = control as Ext.Net.CheckboxBase;
txt.FieldLabel = _labelText;
txt.MsgTarget = MessageTarget.Side;
txt.LazyMode = LazyMode.Instance;
}
else if (control is Ext.Net.CheckboxGroupBase)
{
Ext.Net.CheckboxGroupBase txt = control as Ext.Net.CheckboxGroupBase;
txt.FieldLabel = _labelText;
txt.AllowBlank = _allowBlank;
txt.MsgTarget = MessageTarget.Side;
}
}
}
/// <summary>
/// 设置类型的属性值
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
/// <param name="userControl">用户控件</param>
public static void SetValues<T>(T t, System.Web.UI.UserControl userControl)
{
Type type = t.GetType();
if (type.IsClass)
{
var properties = type.GetProperties();
foreach (var item in properties)
{
if (item.CanWrite)
{
System.Web.UI.Control control = userControl.FindControl("txt" + item.Name);
if (control != null)
{
string text = string.Empty;
if (control is Ext.Net.TextFieldBase)
text = (control as TextFieldBase).Text.Trim();
if (item.PropertyType.IsEnum)
{
item.SetValue(t, Enum.ToObject(item.PropertyType, text), null);
}
else
{
item.SetValue(t, Convert.ChangeType(text, item.PropertyType), null);
}
}
}
}
}
}
public string ShopID
{
get
{
return Session["ShopID"].ToString();
}
set
{
Session["ShopID"] = value;
}
}
public string ShopkeeperID { get; set; }
}