private void BindGrid() { string condition = " 1 = 1 "; if (ViewState["DetailViewID"] != null) { condition += " AND DetailViewID = '" + ViewState["DetailViewID"].ToString() + "'"; } if (tbx_Find.Text != "") { condition += " AND (Name like '%" + tbx_Find.Text + "%' OR Code like '%" + tbx_Find.Text + "%')"; } if (ddl_DisplayType.SelectedValue != "0") { condition += " AND DisplayType = " + ddl_DisplayType.SelectedValue; } IList <UD_Panel> list = UD_PanelBLL.GetModelList(condition); gv_List.TotalRecordCount = list.Count; gv_List.PageIndex = (int)ViewState["PageIndex"]; gv_List.BindGrid <UD_Panel>(list); }
protected void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if (!Page.IsPostBack) { if (Request.QueryString["PanelID"] != null) { ViewState["PanelID"] = new Guid(Request.QueryString["PanelID"]); } else { return; } ViewState["PageIndex"] = 0; BindDropDown(); BindGrid(); } #region Detail详细信息,不需要定义表关系 UD_PanelBLL bll = new UD_PanelBLL((Guid)ViewState["PanelID"]); lbl_PanelName.Text = bll.Model.Name; if (bll.Model.DisplayType == 1) { //Detail详细信息,不需要定义表关系 MCSTabControl1.Items[2].Visible = false; } #endregion }
protected void bt_OK_Click(object sender, EventArgs e) { UD_PanelBLL _pl; if (ViewState["PanelID"] != null) _pl = new UD_PanelBLL((Guid)ViewState["PanelID"]); else _pl = new UD_PanelBLL(); _pl.Model.Code = tbx_Code.Text; _pl.Model.Name = tbx_Name.Text; if (tbx_SortID.Text != "") _pl.Model.SortID = int.Parse(tbx_SortID.Text); _pl.Model.Enable = rbl_Enable.SelectedValue; if (tbx_FieldCount.Text != "") _pl.Model.FieldCount = int.Parse(tbx_FieldCount.Text); _pl.Model.DisplayType = int.Parse(rbl_DisplayType.SelectedValue); if (ddl_DetailView.SelectedValue != "0") _pl.Model.DetailViewID = new Guid(ddl_DetailView.SelectedValue); _pl.Model.Description = tbx_Description.Text.Replace("|", "") + "|" + tbx_DBConnectString.Text.Replace("|", ""); _pl.Model.AdvanceFind = rbl_AdvanceFind.SelectedValue; _pl.Model.DefaultSortFields = tbx_DefaultSortFields.Text; _pl.Model.TableStyle = ddl_TableStyle.SelectedValue; if (ViewState["PanelID"] != null) _pl.Update(); else _pl.Add(); Response.Redirect("PanelDetail.aspx?PanelID=" + _pl.Model.ID.ToString()); }
protected void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if (!Page.IsPostBack) { if (Request.QueryString["PanelID"] != null) ViewState["PanelID"] = new Guid(Request.QueryString["PanelID"]); else return; ViewState["PageIndex"] = 0; BindDropDown(); BindGrid(); } #region Detail详细信息,不需要定义表关系 UD_PanelBLL bll = new UD_PanelBLL((Guid)ViewState["PanelID"]); lbl_PanelName.Text = bll.Model.Name; if (bll.Model.DisplayType == 1) { //Detail详细信息,不需要定义表关系 MCSTabControl1.Items[2].Visible = false; } #endregion }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ViewState["ID"] = 0; if (Request.QueryString["PanelID"] != null) { ViewState["PanelID"] = new Guid(Request.QueryString["PanelID"]); } else { Response.Redirect("PanelList.aspx"); } #region Detail详细信息,不需要定义表关系 UD_PanelBLL bll = new UD_PanelBLL((Guid)ViewState["PanelID"]); lbl_PanelName.Text = bll.Model.Name; if (bll.Model.DisplayType == 1) { //Detail详细信息,不需要定义表关系 MCSTabControl1.Items[2].Visible = false; } #endregion BindGrid(); } }
private void BindDropDown() { ddl_PanelList.DataSource = UD_PanelBLL.GetModelList("AdvanceFind='Y'"); ddl_PanelList.DataBind(); ddl_PanelList.Items.Insert(0, new ListItem("请选择...", "0")); ddl_PanelList_SelectedIndexChanged(null, null); if (Request.QueryString["Panel"] != null && ddl_PanelList.Items.FindByValue(Request.QueryString["Panel"]) != null) { ddl_PanelList.SelectedValue = Request.QueryString["Panel"]; BindGrid(); } }
public static IList <ADFind_FindCondition> GetMyADFind(string panelcode, int staff) { string condition = ""; UD_Panel panel = new UD_PanelBLL(panelcode, true).Model; if (panel != null) { condition = "Panel='" + panel.ID.ToString() + "' AND (OpStaff=" + staff + " OR IsPublic='Y')"; } else { condition = "1=2"; } return(GetModelList(condition)); }
protected void bt_OK_Click(object sender, EventArgs e) { UD_PanelBLL _pl; if (ViewState["PanelID"] != null) { _pl = new UD_PanelBLL((Guid)ViewState["PanelID"]); } else { _pl = new UD_PanelBLL(); } _pl.Model.Code = tbx_Code.Text; _pl.Model.Name = tbx_Name.Text; if (tbx_SortID.Text != "") { _pl.Model.SortID = int.Parse(tbx_SortID.Text); } _pl.Model.Enable = rbl_Enable.SelectedValue; if (tbx_FieldCount.Text != "") { _pl.Model.FieldCount = int.Parse(tbx_FieldCount.Text); } _pl.Model.DisplayType = int.Parse(rbl_DisplayType.SelectedValue); if (ddl_DetailView.SelectedValue != "0") { _pl.Model.DetailViewID = new Guid(ddl_DetailView.SelectedValue); } _pl.Model.Description = tbx_Description.Text.Replace("|", "") + "|" + tbx_DBConnectString.Text.Replace("|", ""); _pl.Model.AdvanceFind = rbl_AdvanceFind.SelectedValue; _pl.Model.DefaultSortFields = tbx_DefaultSortFields.Text; _pl.Model.TableStyle = ddl_TableStyle.SelectedValue; if (ViewState["PanelID"] != null) { _pl.Update(); } else { _pl.Add(); } Response.Redirect("PanelDetail.aspx?PanelID=" + _pl.Model.ID.ToString()); }
private void BindData() { Guid _id = (Guid)ViewState["PanelID"]; UD_PanelBLL _pl = new UD_PanelBLL(_id); lbl_ID.Text = _pl.Model.ID.ToString(); tbx_Code.Text = _pl.Model.Code; tbx_Name.Text = _pl.Model.Name; tbx_SortID.Text = _pl.Model.SortID.ToString(); rbl_Enable.SelectedValue = _pl.Model.Enable; tbx_FieldCount.Text = _pl.Model.FieldCount.ToString(); rbl_DisplayType.SelectedValue = _pl.Model.DisplayType.ToString(); rbl_DisplayType_SelectedIndexChanged(null, null); if (!string.IsNullOrEmpty(_pl.Model.Description)) { int pos = _pl.Model.Description.IndexOf("|"); if (pos == -1) { tbx_Description.Text = _pl.Model.Description; } else { tbx_Description.Text = _pl.Model.Description.Substring(0, pos); if (pos + 1 < _pl.Model.Description.Length) { tbx_DBConnectString.Text = _pl.Model.Description.Substring(pos + 1); } } } ddl_DetailView.SelectedValue = _pl.Model.DetailViewID.ToString(); rbl_AdvanceFind.SelectedValue = _pl.Model.AdvanceFind; ddl_TableStyle.SelectedValue = _pl.Model.TableStyle; tbx_DefaultSortFields.Text = _pl.Model.DefaultSortFields; bt_OK.Text = "修改"; bt_OK.ForeColor = System.Drawing.Color.Red; //Detail详细信息,不需要定义表关系 if (_pl.Model.DisplayType == 1) { MCSTabControl1.Items[2].Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { #region 获取页面参数 ViewState["PanelID"] = Request.QueryString["PanelID"] != null ? new Guid(Request.QueryString["PanelID"]) : Guid.Empty; #endregion if ((Guid)ViewState["PanelID"] != Guid.Empty) { UD_PanelBLL _p = new UD_PanelBLL((Guid)ViewState["PanelID"]); lb_PanelName.Text = _p.Model.Name; } else { MessageBox.ShowAndClose(this, "对不起,PanelID不能为空!"); return; } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Request.QueryString["ID"] != null) { ViewState["ID"] = new Guid(Request.QueryString["ID"]); } if (Request.QueryString["PanelID"] != null) { ViewState["PanelID"] = new Guid(Request.QueryString["PanelID"]); } else { Response.Redirect("PanelList.aspx"); } UD_PanelBLL bll = new UD_PanelBLL((Guid)ViewState["PanelID"]); if (bll.Model.DisplayType == 2) { tr_detail.Visible = false; } BindDropDownList(); if (ViewState["ID"] != null) { BindData(); } else { #region 设置默认排序号 tbx_SortID.Text = (bll.GetFieldMaxSort() + 1).ToString(); #endregion } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ViewState["ID"] = 0; if (Request.QueryString["PanelID"] != null) ViewState["PanelID"] = new Guid(Request.QueryString["PanelID"]); else Response.Redirect("PanelList.aspx"); #region Detail详细信息,不需要定义表关系 UD_PanelBLL bll = new UD_PanelBLL((Guid)ViewState["PanelID"]); lbl_PanelName.Text = bll.Model.Name; if (bll.Model.DisplayType == 1) { //Detail详细信息,不需要定义表关系 MCSTabControl1.Items[2].Visible = false; } #endregion BindGrid(); } }
private void BindDropDown() { UD_PanelBLL panelbll = new UD_PanelBLL(PanelCode, true); if (panelbll.Model != null) { ViewState["Panel"] = panelbll.Model.ID; //获取当前Panel已保存的查询条件 ddl_FindCondition.DataSource = ADFind_FindConditionBLL.GetMyADFind(PanelCode, (int)Session["UserID"]); ddl_FindCondition.DataBind(); ddl_FindCondition.Items.Insert(0, new ListItem("请选择...", "0")); //获取当前Pannel中包括的数据表 ddl_TableName.DataSource = UD_Panel_TableBLL.GetTableListByPanelID(panelbll.Model.ID); ddl_TableName.DataBind(); ddl_TableName_SelectedIndexChanged(null, null); bt_SaveCondition.OnClientClick = "javascript:OpenNewAdvancedFind('" + panelbll.Model.ID.ToString() + "')"; } else { MessageBox.Show(this.Page, "对不起,指定的PanelCode未在UD_Panel表中找到对应项!"); } }
/// <summary> /// Init the components of the panel through the special pageid /// </summary> private void InitComponents() { HtmlTable T_Content = new HtmlTable(); T_Content.CellPadding = 0; T_Content.CellSpacing = 0; T_Content.Width = "100%"; T_Content.Border = 0; T_Content.ID = "T_Content_" + ID; this.Controls.Add(T_Content); UD_DetailViewBLL _DetailViewBll = new UD_DetailViewBLL(DetailViewCode, true); IList <UD_Panel> _panellist = _DetailViewBll.GetDetailPanels(); Hashtable _htFieldControlsInfo = new Hashtable(); foreach (UD_Panel _panelmodel in _panellist) { HtmlTableRow tr_panel = new HtmlTableRow();//Create one TableRow for a panel tr_panel.ID = _panelmodel.Code; if (_panelmodel.Enable.ToUpper() == "N") { tr_panel.Visible = false; } HtmlTableCell tc_panel = new HtmlTableCell(); string _tablestytle = _panelmodel.TableStyle; string[] _tablestyles = _panelmodel.TableStyle.Split(new char[] { ',' }); if (_tablestyles.Length < 3) { _tablestyles = ("tabForm,dataLabel,dataField").Split(new char[] { ',' }); } #region The title of the panel if (_panelmodel.Name != "") { HtmlTable tb_panel_title = new HtmlTable(); tb_panel_title.CellPadding = 0; tb_panel_title.CellSpacing = 0; tb_panel_title.Width = "100%"; tb_panel_title.Height = "28px"; tb_panel_title.Border = 0; tb_panel_title.Attributes["class"] = "h3Row"; HtmlTableRow tr_panel_title = new HtmlTableRow(); HtmlTableCell tc_panel_title = new HtmlTableCell(); tc_panel_title.InnerHtml = "<h3>" + _panelmodel.Name + "</h3>"; tr_panel_title.Cells.Add(tc_panel_title); tb_panel_title.Rows.Add(tr_panel_title); tc_panel.Controls.Add(tb_panel_title); } #endregion #region The content of the panel IList <UD_Panel_ModelFields> fields = new UD_PanelBLL(_panelmodel.ID, true).GetModelFields(); int FieldCount = _panelmodel.FieldCount; HtmlTable tb_panel_content = new HtmlTable(); tb_panel_content.Width = "100%"; tb_panel_content.Attributes["class"] = _tablestyles[0]; int i = 0; foreach (UD_Panel_ModelFields _panel_modelfields in fields) { if (_panel_modelfields.Visible == "N") { continue; } UD_ModelFields _modelfieldsmodel = new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model; UD_TableList _tablemodel = new UD_TableListBLL(_modelfieldsmodel.TableID, true).Model; #region 判断该控件是否已存在 if (_htFieldControlsInfo.Contains(_tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName)) { continue; } #endregion #region 判断是否要增加新行 HtmlTableRow tr_panel_detail; if (i >= FieldCount || i == 0) { tr_panel_detail = new HtmlTableRow(); tb_panel_content.Rows.Add(tr_panel_detail); i = 0; } else { tr_panel_detail = tb_panel_content.Rows[tb_panel_content.Rows.Count - 1]; } #endregion #region 增加Label Cell HtmlTableCell tc_displayname = new HtmlTableCell(); tc_displayname.Attributes["Class"] = _tablestyles[1]; tc_displayname.InnerText = string.IsNullOrEmpty(_panel_modelfields.LabelText) ? _modelfieldsmodel.DisplayName : _panel_modelfields.LabelText; if (tc_displayname.InnerText.Length <= 6) { tc_displayname.Attributes["Style"] = "width: 80px; height: 18px;"; } else { tc_displayname.Attributes["Style"] = "width: 100px; height: 18px;"; } tc_displayname.Attributes["nowrap"] = "nowrap"; tr_panel_detail.Cells.Add(tc_displayname); #endregion #region 增加Field Cell HtmlTableCell tc_control = new HtmlTableCell(); tc_control.Attributes["Class"] = _tablestyles[2]; if (_panel_modelfields.ColSpan > 0) { if (i + _panel_modelfields.ColSpan <= FieldCount) { tc_control.ColSpan = 2 * _panel_modelfields.ColSpan - 1; i = i + _panel_modelfields.ColSpan; } else { tc_control.ColSpan = 2 * (FieldCount - i) - 1; i = 0; } } else { i++; } WebControl control = null; int RelationType = _modelfieldsmodel.RelationType; string RelationTableName = _modelfieldsmodel.RelationTableName; string RelationValueField = _modelfieldsmodel.RelationValueField; string RelationTextField = _modelfieldsmodel.RelationTextField; #region 根据控件类型生成相应的控件 switch (_panel_modelfields.ControlType) { case 1: //Label control = new Label(); break; case 2: //TextBox control = new TextBox(); if (_modelfieldsmodel.DataType == 4) { control.Attributes["onfocus"] = "WdatePicker();"; } break; case 3: //DropDownList control = new DropDownList(); if (RelationType == 1) //Relation to the dictionary { ((DropDownList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true); } else if (RelationType == 2) //Relation to the model table { ((DropDownList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField); } else { break; } ((DropDownList)control).DataTextField = "Value"; ((DropDownList)control).DataValueField = "Key"; ((DropDownList)control).DataBind(); if (_modelfieldsmodel.DataType != 5) { ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", "0")); } else { ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", Guid.Empty.ToString())); } break; case 4: //RadioButtonList control = new RadioButtonList(); if (RelationType == 1) //Relation to the dictionary { ((RadioButtonList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true); } else if (RelationType == 2) //Relation to the model table { ((RadioButtonList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField); } else { break; } ((RadioButtonList)control).RepeatColumns = 6; ((RadioButtonList)control).RepeatDirection = RepeatDirection.Horizontal; ((RadioButtonList)control).DataTextField = "Value"; ((RadioButtonList)control).DataValueField = "Key"; ((RadioButtonList)control).DataBind(); if (((RadioButtonList)control).Items.Count != 0) { ((RadioButtonList)control).SelectedIndex = 0; } break; case 5: //MutiLinesTextBox control = new TextBox(); ((TextBox)control).TextMode = TextBoxMode.MultiLine; if (_panel_modelfields.ControlHeight > 0) { ((TextBox)control).Height = new Unit(_panel_modelfields.ControlHeight); } break; case 6: //TextBox supports search control = new MCSSelectControl(); if (RelationType == 2) //Relation to the model table { control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName; if (_panel_modelfields.SearchPageURL != "") { ((MCSSelectControl)control).PageUrl = _panel_modelfields.SearchPageURL; } else if (_modelfieldsmodel.SearchPageURL != "") { ((MCSSelectControl)control).PageUrl = _modelfieldsmodel.SearchPageURL; } } break; case 7: //MCSTreeControl control = new MCSTreeControl(); if (RelationType == 2) //Relation to the model table { control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName; if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity") { #region 如果为管理片区字段,则取所能管辖的片区 if (System.Web.HttpContext.Current.Session["AccountType"] == null || (int)System.Web.HttpContext.Current.Session["AccountType"] == 1) { //员工 Org_StaffBLL staff = new Org_StaffBLL((int)System.Web.HttpContext.Current.Session["UserID"]); ((MCSTreeControl)control).DataSource = staff.GetStaffOrganizeCity(); ((MCSTreeControl)control).IDColumnName = "ID"; ((MCSTreeControl)control).NameColumnName = "Name"; ((MCSTreeControl)control).ParentColumnName = "SuperID"; if (((MCSTreeControl)control).DataSource.Select("ID = 1").Length > 0 || staff.Model.OrganizeCity == 0) { ((MCSTreeControl)control).RootValue = "0"; if (!Page.IsPostBack) { ((MCSTreeControl)control).SelectValue = "0"; } } else { ((MCSTreeControl)control).RootValue = new Addr_OrganizeCityBLL(staff.Model.OrganizeCity).Model.SuperID.ToString(); if (!Page.IsPostBack) { ((MCSTreeControl)control).SelectValue = staff.Model.OrganizeCity.ToString(); } } } else if ((int)System.Web.HttpContext.Current.Session["AccountType"] == 2 && System.Web.HttpContext.Current.Session["OrganizeCity"] != null) { //商业客户 int city = (int)System.Web.HttpContext.Current.Session["OrganizeCity"]; Addr_OrganizeCityBLL citybll = new Addr_OrganizeCityBLL(city); ((MCSTreeControl)control).DataSource = citybll.GetAllChildNodeIncludeSelf(); ((MCSTreeControl)control).RootValue = citybll.Model.SuperID.ToString(); ((MCSTreeControl)control).IDColumnName = "ID"; ((MCSTreeControl)control).NameColumnName = "Name"; ((MCSTreeControl)control).ParentColumnName = "SuperID"; if (!Page.IsPostBack) { ((MCSTreeControl)control).SelectValue = city.ToString(); } } #endregion } else if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity") { ((MCSTreeControl)control).TableName = "MCS_SYS.dbo.Addr_OfficialCity"; ((MCSTreeControl)control).IDColumnName = "ID"; ((MCSTreeControl)control).NameColumnName = "Name"; ((MCSTreeControl)control).ParentColumnName = "SuperID"; ((MCSTreeControl)control).RootValue = "0"; if (!Page.IsPostBack) { ((MCSTreeControl)control).SelectValue = "0"; } } else { ((MCSTreeControl)control).TableName = RelationTableName; ((MCSTreeControl)control).IDColumnName = RelationValueField; ((MCSTreeControl)control).NameColumnName = RelationTextField; ((MCSTreeControl)control).ParentColumnName = "SuperID"; } } break; } #endregion control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName; control.Enabled = _panel_modelfields.Enable.ToUpper() == "Y"; if (_panel_modelfields.ControlWidth > 0) { control.Width = _panel_modelfields.ControlWidth; } tc_control.Controls.Add(control); #region 如果是文本框时,加上输入验证控件 if (_panel_modelfields.IsRequireField == "Y") { Label lbl_reqinfo = new Label(); lbl_reqinfo.Text = " *"; lbl_reqinfo.ForeColor = System.Drawing.Color.Red; tc_control.Controls.Add(lbl_reqinfo); } if (_panel_modelfields.ControlType == 2 || _panel_modelfields.ControlType == 5) { if (_panel_modelfields.IsRequireField == "Y") { RequiredFieldValidator _requiredfieldvalidator = new RequiredFieldValidator(); _requiredfieldvalidator.ControlToValidate = control.ID; _requiredfieldvalidator.Display = ValidatorDisplay.Dynamic; _requiredfieldvalidator.ErrorMessage = "必填"; _requiredfieldvalidator.ForeColor = System.Drawing.Color.Red; _requiredfieldvalidator.ValidationGroup = _validationgroup; tc_control.Controls.Add(_requiredfieldvalidator); } if (_panel_modelfields.RegularExpression != "") { RegularExpressionValidator _regularexpressionvalidator = new RegularExpressionValidator(); _regularexpressionvalidator.ControlToValidate = control.ID; _regularexpressionvalidator.ErrorMessage = "数据格式不正确"; _regularexpressionvalidator.ForeColor = System.Drawing.Color.Red; _regularexpressionvalidator.ValidationExpression = _panel_modelfields.RegularExpression; _regularexpressionvalidator.ValidationGroup = ValidationGroup; _regularexpressionvalidator.Display = ValidatorDisplay.Dynamic; tc_control.Controls.Add(_regularexpressionvalidator); } else { if (_modelfieldsmodel.DataType == 1 || _modelfieldsmodel.DataType == 2 || _modelfieldsmodel.DataType == 4) //非varchar 字符串 { CompareValidator _comparevalidator = new CompareValidator(); _comparevalidator.ControlToValidate = control.ID; _comparevalidator.Operator = ValidationCompareOperator.DataTypeCheck; _comparevalidator.Display = ValidatorDisplay.Dynamic; _comparevalidator.ForeColor = System.Drawing.Color.Red; _comparevalidator.ValidationGroup = _validationgroup; if (_modelfieldsmodel.DataType == 1)//int { _comparevalidator.Type = ValidationDataType.Integer; _comparevalidator.ErrorMessage = "应为整数"; } if (_modelfieldsmodel.DataType == 2)//decimal { _comparevalidator.Type = ValidationDataType.Double; _comparevalidator.ErrorMessage = "应为数字"; } if (_modelfieldsmodel.DataType == 4)//datetime { _comparevalidator.Type = ValidationDataType.Date; _comparevalidator.ErrorMessage = "日期格式不正确"; } tc_control.Controls.Add(_comparevalidator); } } } #endregion if (!string.IsNullOrEmpty(_panel_modelfields.Description)) { Label lb = new Label(); lb.Text = " " + _panel_modelfields.Description; tc_control.Controls.Add(lb); } tr_panel_detail.Cells.Add(tc_control); #endregion #region 将控件记录到字段控件HashTable中 FieldControlInfo fieldcontrolinfo = new FieldControlInfo(); fieldcontrolinfo.FieldID = _modelfieldsmodel.ID; fieldcontrolinfo.FieldName = _modelfieldsmodel.FieldName; fieldcontrolinfo.ModelName = _tablemodel.ModelClassName; fieldcontrolinfo.ControlType = _panel_modelfields.ControlType; fieldcontrolinfo.ControlName = control.ID; fieldcontrolinfo.DisplayMode = _panel_modelfields.DisplayMode; fieldcontrolinfo.Panel_Field_ID = _panel_modelfields.ID; _htFieldControlsInfo.Add(fieldcontrolinfo.ControlName, fieldcontrolinfo); #endregion } #endregion tc_panel.Controls.Add(tb_panel_content); tr_panel.Cells.Add(tc_panel); T_Content.Rows.Add(tr_panel); } ViewState["FieldControlsInfo"] = _htFieldControlsInfo; }
private void BindDropDown() { ddl_PanelList.DataSource = UD_PanelBLL.GetModelList("AdvanceFind='Y'"); ddl_PanelList.DataBind(); ddl_PanelList.Items.Insert(0, new ListItem("请选择...", "0")); }
/// <summary> /// Init the components of the panel through the special pageid /// </summary> private void InitComponents() { HtmlTable T_Content = new HtmlTable(); T_Content.CellPadding = 0; T_Content.CellSpacing = 0; T_Content.Width = "100%"; T_Content.Border = 0; T_Content.ID = "T_Content_" + ID; this.Controls.Add(T_Content); UD_DetailViewBLL _DetailViewBll = new UD_DetailViewBLL(DetailViewCode, true); IList<UD_Panel> _panellist = _DetailViewBll.GetDetailPanels(); Hashtable _htFieldControlsInfo = new Hashtable(); foreach (UD_Panel _panelmodel in _panellist) { HtmlTableRow tr_panel = new HtmlTableRow();//Create one TableRow for a panel tr_panel.ID = _panelmodel.Code; if (_panelmodel.Enable.ToUpper() == "N") tr_panel.Visible = false; HtmlTableCell tc_panel = new HtmlTableCell(); string _tablestytle = _panelmodel.TableStyle; string[] _tablestyles = _panelmodel.TableStyle.Split(new char[] { ',' }); if (_tablestyles.Length < 3) _tablestyles = ("tabForm,dataLabel,dataField").Split(new char[] { ',' }); #region The title of the panel if (_panelmodel.Name != "") { HtmlTable tb_panel_title = new HtmlTable(); tb_panel_title.CellPadding = 0; tb_panel_title.CellSpacing = 0; tb_panel_title.Width = "100%"; tb_panel_title.Height = "28px"; tb_panel_title.Border = 0; tb_panel_title.Attributes["class"] = "h3Row"; HtmlTableRow tr_panel_title = new HtmlTableRow(); HtmlTableCell tc_panel_title = new HtmlTableCell(); tc_panel_title.InnerHtml = "<h3>" + _panelmodel.Name + "</h3>"; tr_panel_title.Cells.Add(tc_panel_title); tb_panel_title.Rows.Add(tr_panel_title); tc_panel.Controls.Add(tb_panel_title); } #endregion #region The content of the panel IList<UD_Panel_ModelFields> fields = new UD_PanelBLL(_panelmodel.ID, true).GetModelFields(); int FieldCount = _panelmodel.FieldCount; HtmlTable tb_panel_content = new HtmlTable(); tb_panel_content.Width = "100%"; tb_panel_content.Attributes["class"] = _tablestyles[0]; int i = 0; foreach (UD_Panel_ModelFields _panel_modelfields in fields) { if (_panel_modelfields.Visible == "N") continue; UD_ModelFields _modelfieldsmodel = new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model; UD_TableList _tablemodel = new UD_TableListBLL(_modelfieldsmodel.TableID, true).Model; #region 判断该控件是否已存在 if (_htFieldControlsInfo.Contains(_tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName)) continue; #endregion #region 判断是否要增加新行 HtmlTableRow tr_panel_detail; if (i >= FieldCount || i == 0) { tr_panel_detail = new HtmlTableRow(); tb_panel_content.Rows.Add(tr_panel_detail); i = 0; } else { tr_panel_detail = tb_panel_content.Rows[tb_panel_content.Rows.Count - 1]; } #endregion #region 增加Label Cell HtmlTableCell tc_displayname = new HtmlTableCell(); tc_displayname.Attributes["Class"] = _tablestyles[1]; tc_displayname.InnerText = string.IsNullOrEmpty(_panel_modelfields.LabelText) ? _modelfieldsmodel.DisplayName : _panel_modelfields.LabelText; if (tc_displayname.InnerText.Length <= 6) tc_displayname.Attributes["Style"] = "width: 80px; height: 18px;"; else tc_displayname.Attributes["Style"] = "width: 100px; height: 18px;"; tc_displayname.Attributes["nowrap"] = "nowrap"; tr_panel_detail.Cells.Add(tc_displayname); #endregion #region 增加Field Cell HtmlTableCell tc_control = new HtmlTableCell(); tc_control.Attributes["Class"] = _tablestyles[2]; if (_panel_modelfields.ColSpan > 0) { if (i + _panel_modelfields.ColSpan <= FieldCount) { tc_control.ColSpan = 2 * _panel_modelfields.ColSpan - 1; i = i + _panel_modelfields.ColSpan; } else { tc_control.ColSpan = 2 * (FieldCount - i) - 1; i = 0; } } else { i++; } WebControl control = null; int RelationType = _modelfieldsmodel.RelationType; string RelationTableName = _modelfieldsmodel.RelationTableName; string RelationValueField = _modelfieldsmodel.RelationValueField; string RelationTextField = _modelfieldsmodel.RelationTextField; #region 根据控件类型生成相应的控件 switch (_panel_modelfields.ControlType) { case 1://Label control = new Label(); break; case 2://TextBox control = new TextBox(); if (_modelfieldsmodel.DataType == 4) { control.Attributes["onfocus"] = "WdatePicker();"; } break; case 3://DropDownList control = new DropDownList(); if (RelationType == 1)//Relation to the dictionary { ((DropDownList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true); } else if (RelationType == 2)//Relation to the model table { ((DropDownList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField); } else break; ((DropDownList)control).DataTextField = "Value"; ((DropDownList)control).DataValueField = "Key"; ((DropDownList)control).DataBind(); if (_modelfieldsmodel.DataType != 5) ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", "0")); else ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", Guid.Empty.ToString())); break; case 4://RadioButtonList control = new RadioButtonList(); if (RelationType == 1)//Relation to the dictionary { ((RadioButtonList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true); } else if (RelationType == 2)//Relation to the model table { ((RadioButtonList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField); } else break; ((RadioButtonList)control).RepeatColumns = 6; ((RadioButtonList)control).RepeatDirection = RepeatDirection.Horizontal; ((RadioButtonList)control).DataTextField = "Value"; ((RadioButtonList)control).DataValueField = "Key"; ((RadioButtonList)control).DataBind(); if (((RadioButtonList)control).Items.Count != 0) ((RadioButtonList)control).SelectedIndex = 0; break; case 5://MutiLinesTextBox control = new TextBox(); ((TextBox)control).TextMode = TextBoxMode.MultiLine; if (_panel_modelfields.ControlHeight > 0) ((TextBox)control).Height = new Unit(_panel_modelfields.ControlHeight); break; case 6://TextBox supports search control = new MCSSelectControl(); if (RelationType == 2)//Relation to the model table { control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName; if (_panel_modelfields.SearchPageURL != "") ((MCSSelectControl)control).PageUrl = _panel_modelfields.SearchPageURL; else if (_modelfieldsmodel.SearchPageURL != "") ((MCSSelectControl)control).PageUrl = _modelfieldsmodel.SearchPageURL; } break; case 7://MCSTreeControl control = new MCSTreeControl(); if (RelationType == 2)//Relation to the model table { control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName; if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity") { #region 如果为管理片区字段,则取所能管辖的片区 if (System.Web.HttpContext.Current.Session["AccountType"] == null || (int)System.Web.HttpContext.Current.Session["AccountType"] == 1) { //员工 Org_StaffBLL staff = new Org_StaffBLL((int)System.Web.HttpContext.Current.Session["UserID"]); ((MCSTreeControl)control).DataSource = staff.GetStaffOrganizeCity(); ((MCSTreeControl)control).IDColumnName = "ID"; ((MCSTreeControl)control).NameColumnName = "Name"; ((MCSTreeControl)control).ParentColumnName = "SuperID"; if (((MCSTreeControl)control).DataSource.Select("ID = 1").Length > 0 || staff.Model.OrganizeCity == 0) { ((MCSTreeControl)control).RootValue = "0"; if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = "0"; } else { ((MCSTreeControl)control).RootValue = new Addr_OrganizeCityBLL(staff.Model.OrganizeCity).Model.SuperID.ToString(); if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = staff.Model.OrganizeCity.ToString(); } } else if ((int)System.Web.HttpContext.Current.Session["AccountType"] == 2 && System.Web.HttpContext.Current.Session["OrganizeCity"] != null) { //商业客户 int city = (int)System.Web.HttpContext.Current.Session["OrganizeCity"]; Addr_OrganizeCityBLL citybll = new Addr_OrganizeCityBLL(city); ((MCSTreeControl)control).DataSource = citybll.GetAllChildNodeIncludeSelf(); ((MCSTreeControl)control).RootValue = citybll.Model.SuperID.ToString(); ((MCSTreeControl)control).IDColumnName = "ID"; ((MCSTreeControl)control).NameColumnName = "Name"; ((MCSTreeControl)control).ParentColumnName = "SuperID"; if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = city.ToString(); } #endregion } else if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity") { ((MCSTreeControl)control).TableName = "MCS_SYS.dbo.Addr_OfficialCity"; ((MCSTreeControl)control).IDColumnName = "ID"; ((MCSTreeControl)control).NameColumnName = "Name"; ((MCSTreeControl)control).ParentColumnName = "SuperID"; ((MCSTreeControl)control).RootValue = "0"; if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = "0"; } else { ((MCSTreeControl)control).TableName = RelationTableName; ((MCSTreeControl)control).IDColumnName = RelationValueField; ((MCSTreeControl)control).NameColumnName = RelationTextField; ((MCSTreeControl)control).ParentColumnName = "SuperID"; } } break; } #endregion control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName; control.Enabled = _panel_modelfields.Enable.ToUpper() == "Y"; if (_panel_modelfields.ControlWidth > 0) control.Width = _panel_modelfields.ControlWidth; tc_control.Controls.Add(control); #region 如果是文本框时,加上输入验证控件 if (_panel_modelfields.IsRequireField == "Y") { Label lbl_reqinfo = new Label(); lbl_reqinfo.Text = " *"; lbl_reqinfo.ForeColor = System.Drawing.Color.Red; tc_control.Controls.Add(lbl_reqinfo); } if (_panel_modelfields.ControlType == 2 || _panel_modelfields.ControlType == 5) { if (_panel_modelfields.IsRequireField == "Y") { RequiredFieldValidator _requiredfieldvalidator = new RequiredFieldValidator(); _requiredfieldvalidator.ControlToValidate = control.ID; _requiredfieldvalidator.Display = ValidatorDisplay.Dynamic; _requiredfieldvalidator.ErrorMessage = "必填"; _requiredfieldvalidator.ForeColor = System.Drawing.Color.Red; _requiredfieldvalidator.ValidationGroup = _validationgroup; tc_control.Controls.Add(_requiredfieldvalidator); } if (_panel_modelfields.RegularExpression != "") { RegularExpressionValidator _regularexpressionvalidator = new RegularExpressionValidator(); _regularexpressionvalidator.ControlToValidate = control.ID; _regularexpressionvalidator.ErrorMessage = "数据格式不正确"; _regularexpressionvalidator.ForeColor = System.Drawing.Color.Red; _regularexpressionvalidator.ValidationExpression = _panel_modelfields.RegularExpression; _regularexpressionvalidator.ValidationGroup = ValidationGroup; _regularexpressionvalidator.Display = ValidatorDisplay.Dynamic; tc_control.Controls.Add(_regularexpressionvalidator); } else { if (_modelfieldsmodel.DataType == 1 || _modelfieldsmodel.DataType == 2 || _modelfieldsmodel.DataType == 4) //非varchar 字符串 { CompareValidator _comparevalidator = new CompareValidator(); _comparevalidator.ControlToValidate = control.ID; _comparevalidator.Operator = ValidationCompareOperator.DataTypeCheck; _comparevalidator.Display = ValidatorDisplay.Dynamic; _comparevalidator.ForeColor = System.Drawing.Color.Red; _comparevalidator.ValidationGroup = _validationgroup; if (_modelfieldsmodel.DataType == 1)//int { _comparevalidator.Type = ValidationDataType.Integer; _comparevalidator.ErrorMessage = "应为整数"; } if (_modelfieldsmodel.DataType == 2)//decimal { _comparevalidator.Type = ValidationDataType.Double; _comparevalidator.ErrorMessage = "应为数字"; } if (_modelfieldsmodel.DataType == 4)//datetime { _comparevalidator.Type = ValidationDataType.Date; _comparevalidator.ErrorMessage = "日期格式不正确"; } tc_control.Controls.Add(_comparevalidator); } } } #endregion if (!string.IsNullOrEmpty(_panel_modelfields.Description)) { Label lb = new Label(); lb.Text = " " + _panel_modelfields.Description; tc_control.Controls.Add(lb); } tr_panel_detail.Cells.Add(tc_control); #endregion #region 将控件记录到字段控件HashTable中 FieldControlInfo fieldcontrolinfo = new FieldControlInfo(); fieldcontrolinfo.FieldID = _modelfieldsmodel.ID; fieldcontrolinfo.FieldName = _modelfieldsmodel.FieldName; fieldcontrolinfo.ModelName = _tablemodel.ModelClassName; fieldcontrolinfo.ControlType = _panel_modelfields.ControlType; fieldcontrolinfo.ControlName = control.ID; fieldcontrolinfo.DisplayMode = _panel_modelfields.DisplayMode; fieldcontrolinfo.Panel_Field_ID = _panel_modelfields.ID; _htFieldControlsInfo.Add(fieldcontrolinfo.ControlName, fieldcontrolinfo); #endregion } #endregion tc_panel.Controls.Add(tb_panel_content); tr_panel.Cells.Add(tc_panel); T_Content.Rows.Add(tr_panel); } ViewState["FieldControlsInfo"] = _htFieldControlsInfo; }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Request.QueryString["ID"] != null) ViewState["ID"] = new Guid(Request.QueryString["ID"]); if (Request.QueryString["PanelID"] != null) ViewState["PanelID"] = new Guid(Request.QueryString["PanelID"]); else Response.Redirect("PanelList.aspx"); UD_PanelBLL bll = new UD_PanelBLL((Guid)ViewState["PanelID"]); if (bll.Model.DisplayType == 2) tr_detail.Visible = false; BindDropDownList(); if (ViewState["ID"] != null) { BindData(); } else { #region 设置默认排序号 tbx_SortID.Text = (bll.GetFieldMaxSort() + 1).ToString(); #endregion } } }
private void BindData() { Guid _id = (Guid)ViewState["PanelID"]; UD_PanelBLL _pl = new UD_PanelBLL(_id); lbl_ID.Text = _pl.Model.ID.ToString(); tbx_Code.Text = _pl.Model.Code; tbx_Name.Text = _pl.Model.Name; tbx_SortID.Text = _pl.Model.SortID.ToString(); rbl_Enable.SelectedValue = _pl.Model.Enable; tbx_FieldCount.Text = _pl.Model.FieldCount.ToString(); rbl_DisplayType.SelectedValue = _pl.Model.DisplayType.ToString(); rbl_DisplayType_SelectedIndexChanged(null, null); if (!string.IsNullOrEmpty(_pl.Model.Description)) { int pos = _pl.Model.Description.IndexOf("|"); if (pos == -1) tbx_Description.Text = _pl.Model.Description; else { tbx_Description.Text = _pl.Model.Description.Substring(0, pos); if (pos + 1 < _pl.Model.Description.Length) tbx_DBConnectString.Text = _pl.Model.Description.Substring(pos + 1); } } ddl_DetailView.SelectedValue = _pl.Model.DetailViewID.ToString(); rbl_AdvanceFind.SelectedValue = _pl.Model.AdvanceFind; ddl_TableStyle.SelectedValue = _pl.Model.TableStyle; tbx_DefaultSortFields.Text = _pl.Model.DefaultSortFields; bt_OK.Text = "修改"; bt_OK.ForeColor = System.Drawing.Color.Red; //Detail详细信息,不需要定义表关系 if (_pl.Model.DisplayType == 1) { MCSTabControl1.Items[2].Visible = false; } }
private void CreateSqlString() { string _sqlstring = ""; string _selectstr = "SELECT "; string _fromstr = ""; string _tmpfrom = ""; //字段如果是关联时,临时生成的from sql #region create the select string UD_PanelBLL _panelbll = new UD_PanelBLL(PanelCode, true); if (_panelbll.Model == null) { throw new Exception("Panel:" + PanelCode + ",未能找到该Code对应的Panel,Code无效!"); } Dictionary <string, UD_Panel_ModelFields> dicTreeColumnList = new Dictionary <string, UD_Panel_ModelFields>(); IList <UD_Panel_ModelFields> _panel_modelfieldsmodels = _panelbll.GetModelFields(); OrderFields = _panelbll.Model.DefaultSortFields; if (_panel_modelfieldsmodels.Count == 0) { //未定义Panel字段 ViewState["SqlString"] = ""; return; } if (!string.IsNullOrEmpty(_panelbll.Model.Description)) { string[] _array = _panelbll.Model.Description.Split(new char[] { '|' }, StringSplitOptions.None); if (_array.Length >= 2) { ViewState["DBConnectString"] = _array[1]; } } foreach (UD_Panel_ModelFields _panel_modelfields in _panel_modelfieldsmodels) { UD_ModelFields _modelfield = new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model; UD_TableList _tablemodel = new UD_TableListBLL(_modelfield.TableID, true).Model; string _fieldfullname = _tablemodel.ModelClassName + "_" + _modelfield.FieldName; #region 判断字段关联类型,决定如果创建SQL switch (_modelfield.RelationType) { case 1: //Relation to dic if (_panel_modelfields.DisplayMode == 1) //Bound the id value of the field { if (_modelfield.Flag == "Y") { _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ","; } else //扩展字段 { _selectstr += "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ","; } } else //Bound the text value of the field { //计算出关联字典表的别名"_vname" string _vname = "V_Dictionary_Data" + "_" + _modelfield.FieldName; if (_modelfield.Flag == "Y") { _selectstr += _vname + ".Name" + " AS " + _fieldfullname + ","; _tmpfrom += " left join V_Dictionary_Data AS " + _vname + " ON " + _tablemodel.Name + "." + _modelfield.FieldName + "=" + _vname + ".Code AND " + _vname + ".TableName='" + _modelfield.RelationTableName + "' "; } else //扩展字段 { _selectstr += _vname + ".Name" + " AS " + _fieldfullname + ","; _tmpfrom += " left join V_Dictionary_Data AS " + _vname + " ON [dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") =" + _vname + ".Code AND " + _vname + ".TableName='" + _modelfield.RelationTableName + "' "; } } break; case 2: //Relation to model table if (_panel_modelfields.TreeLevel > 0 && new UD_TableListBLL(_modelfield.RelationTableName).Model.TreeFlag == "Y") { #region 字段关联到树形结构表,且要显示上层父结点信息 _fieldfullname += _panel_modelfields.TreeLevel.ToString(); if (_modelfield.Flag == "Y") { _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ","; } else //扩展字段 { _selectstr += "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ","; } dicTreeColumnList.Add(_fieldfullname, _panel_modelfields); #endregion #region 注释 //if (param.TreeLevel == 100 && param.DisplayMode == 2) //{ // //显示字段路径全称 // if (_modelfield.Flag == "Y") // _selectstr += "[dbo].[Exuf_TreeTable_GetFullName]('" + _modelfield.RelationTableName + "'," + _tablemodel.Name + "." + _modelfield.FieldName + ",1) AS " + _fieldfullname + ","; // else//扩展字段 // _selectstr += "[dbo].[Exuf_TreeTable_GetFullName]('" + _modelfield.RelationTableName + "'," + "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + "),0) AS " + _fieldfullname + ","; //} //else //{ // _fieldfullname += param.TreeLevel.ToString(); // if (param.DisplayMode == 1)//Bound the id value of the field // { // if (_modelfield.Flag == "Y") // _selectstr += "[dbo].[Exuf_TreeTable_GetSuperIDByLevel]('" + _modelfield.RelationTableName + "'," + _tablemodel.Name + "." + _modelfield.FieldName + "," + param.TreeLevel.ToString() + ") AS " + _fieldfullname + ","; // else//扩展字段 // { // _selectstr += "[dbo].[Exuf_TreeTable_GetSuperIDByLevel]('" + _modelfield.RelationTableName + "'," + "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ")," + param.TreeLevel.ToString() + ") AS " + _fieldfullname + ","; // } // } // else//Bound the text value of the field // { // if (_modelfield.Flag == "Y") // _selectstr += "[dbo].[Exuf_TreeTable_GetSuperNameByLevel]('" + _modelfield.RelationTableName + "'," + _tablemodel.Name + "." + _modelfield.FieldName + "," + param.TreeLevel.ToString() + ") AS " + _fieldfullname + ","; // else//扩展字段 // _selectstr += "[dbo].[Exuf_TreeTable_GetSuperNameByLevel]('" + _modelfield.RelationTableName + "'," + "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ")," + param.TreeLevel.ToString() + ") AS " + _fieldfullname + ","; // } //} #endregion } else { #region 需关联到树形结构表 if (_panel_modelfields.DisplayMode == 1) //Bound the id value of the field { if (_modelfield.Flag == "Y") { _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ","; } else //扩展字段 { _selectstr += "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ","; } } else //Bound the text value of the field { #region 计算出关联表的别名"_vname" string _vname = ""; int pos = _modelfield.RelationTableName.LastIndexOf('.'); if (pos >= 0) { _vname = _modelfield.RelationTableName.Substring(pos + 1) + "_" + _modelfield.FieldName; } else { _vname = _modelfield.RelationTableName + "_" + _modelfield.FieldName; } #endregion if (_modelfield.Flag == "Y") { _selectstr += _vname + "." + _modelfield.RelationTextField + " AS " + _fieldfullname + ","; _tmpfrom += " left join " + _modelfield.RelationTableName + " AS " + _vname + " ON " + _tablemodel.Name + "." + _modelfield.FieldName + "=" + _vname + "." + _modelfield.RelationValueField; } else //扩展字段 { _selectstr += _vname + "." + _modelfield.RelationTextField + " AS " + _fieldfullname + ","; _tmpfrom += " left join " + _modelfield.RelationTableName + " AS " + _vname + " ON [dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") =" + _vname + "." + _modelfield.RelationValueField; } } #endregion } break; default: //No relation if (_modelfield.Flag == "Y") { _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ","; } else { _selectstr += "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ","; } break; } #endregion //Add a bound field to the gridview according to the selected field BoundField _boundfield = new BoundField(); _boundfield.HeaderText = string.IsNullOrEmpty(_panel_modelfields.LabelText) ? _modelfield.DisplayName : _panel_modelfields.LabelText; _boundfield.DataField = _fieldfullname; _boundfield.SortExpression = _fieldfullname; if (!_panel_modelfields.FormatString.StartsWith("{0:")) { _boundfield.DataFormatString = "{0:" + _panel_modelfields.FormatString + "}"; } else { _boundfield.DataFormatString = _panel_modelfields.FormatString; } //_boundfield.Visible = _panel_modelfieldsmodel.Visible == "Y"; if (_panel_modelfields.Visible == "Y") { if (_panel_modelfields.SortID - 1 > Columns.Count) { Columns.Add(_boundfield); } else { Columns.Insert(_panel_modelfields.SortID - 1, _boundfield); } } } _selectstr = _selectstr.Substring(0, _selectstr.Length - 1); #endregion #region create the from string of sql IList <UD_Panel_TableRelation> _panel_tablerelations = _panelbll.GetTableRelations(); if (_panel_tablerelations.Count == 0) { IList <UD_Panel_Table> _panel_tables = _panelbll.GetPanelTables(); if (_panel_tables.Count == 0) { throw new Exception("Panel:" + PanelCode + "在定义中未包括包含的表信息!"); } _fromstr = " FROM " + new UD_TableListBLL(_panel_tables[0].TableID, true).Model.Name; } else { foreach (UD_Panel_TableRelation _panel_tablerelation in _panel_tablerelations) { string _parenttablename = new UD_TableListBLL(_panel_tablerelation.ParentTableID, true).Model.Name; string _childtablename = new UD_TableListBLL(_panel_tablerelation.ChildTableID, true).Model.Name; UD_ModelFields _parentfield = new UD_ModelFieldsBLL(_panel_tablerelation.ParentFieldID, true).Model; UD_ModelFields _childfield = new UD_ModelFieldsBLL(_panel_tablerelation.ChildFieldID, true).Model; if (_panel_tablerelation.JoinMode == "") { _panel_tablerelation.JoinMode = "LEFT JOIN"; } if (_fromstr == "") { _fromstr = " FROM " + _parenttablename + " "; } if (_parentfield.Flag == "Y" && _childfield.Flag == "Y") { _fromstr += " " + _panel_tablerelation.JoinMode + " " + _childtablename + " ON " + _parenttablename + "." + _parentfield.FieldName + "=" + _childtablename + "." + _childfield.FieldName + " "; } else { _fromstr += " " + _panel_tablerelation.JoinMode + " " + _childtablename + " ON "; if (_parentfield.Flag == "Y") { _fromstr += "CONVERT(VarChar," + _parenttablename + "." + _parentfield.FieldName + ")"; } else { _fromstr += "[dbo].[UF_Spilt](" + _parenttablename + ".ExtPropertys,'|'," + new UD_ModelFieldsBLL(_panel_tablerelation.ParentFieldID, true).Model.Position + ")"; } _fromstr += " = "; if (_childfield.Flag == "Y") { _fromstr += "CONVERT(VarChar," + _childtablename + "." + _childfield.FieldName + ")"; } else { _fromstr += "[dbo].[UF_Spilt](" + _childtablename + ".ExtPropertys,'|'," + new UD_ModelFieldsBLL(_panel_tablerelation.ChildFieldID, true).Model.Position + ")"; } } if (_panel_tablerelation.RelationCondition != "") { _fromstr += " AND " + _panel_tablerelation.RelationCondition + " "; } } } if (_tmpfrom != "") { _fromstr += _tmpfrom; } _sqlstring = _selectstr + _fromstr; #endregion ViewState["SqlString"] = _sqlstring; ViewState["TreeColumn"] = dicTreeColumnList; }