using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Html; using Autofac; using EMIS.Entities; using EMIS.Utility; using EMIS.CommonLogic.SystemServices; using Bowin.Common; using Bowin.Web.Controls.Mvc; using Bowin.Common.JSON; using System.Text; namespace EMIS.Web.Controls { public static class ConditionExtensions { // public IConfiguretermsInfoServices iConfiguretermsInfoServices { get; set; } /// /// 动态查询控件,需要通过数据库配置具体的查询项 /// /// /// 页面标识,默认为List,同一菜单内的不同页面可通过该字段区分,对应数据库中的MUNClass字段 /// 菜单编号,对应数据库中的MNUID字段 /// public static MvcHtmlString PositionCondition(this HtmlHelper htmlHelper, string menuClass = "List", string mnuNo = "") { var positionConditionId = "ul_" + Guid.NewGuid().ToString().Replace("-", ""); var request = htmlHelper.ViewContext.RequestContext.HttpContext.Request; var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); if (mnuNo == "") { mnuNo = request["MNU"]; } StringBuilder sb = new StringBuilder(); sb.Append("
"); sb.Append("
"); sb.Append(" "); sb.Append("
"); sb.Append("
"); sb.Append(""); return MvcHtmlString.Create(sb.ToString()); } //public static MvcHtmlString PositionCondition(this HtmlHelper htmlHelper, string menuClass = "List", IDictionary htmlAttributes = null, string mnuNo = "") //{ // string menuNo = HttpContext.Current.Request["MNU"]; // string html = ""; // string columnName = string.Empty; // List listAttribute = null; // if (!string.IsNullOrEmpty(mnuNo)) // { // menuNo = mnuNo; // } // using (var scope = AutofacHelper.Container.BeginLifetimeScope()) // { // IConfiguretermsInfoServices configuretermsInfoServices = scope.Resolve(); // listAttribute = configuretermsInfoServices.GetConfiguretermsInfo(menuNo, menuClass); // foreach (var item in listAttribute) // { // columnName += item.Value.Replace(".", "") + "Query" + item.ControlType + "_div" + ","; // if (htmlAttributes == null) // { // htmlAttributes = new Dictionary { { "data-condition", item.listControl } }; // } // } // } // DropdownListOptions dropdownListOptions = new DropdownListOptions(); // dropdownListOptions.BindType = DropdownListBindType.None; // dropdownListOptions.ItemSourceUrl = UrlHelper.GenerateContentUrl("~/Common/DynamicConditionDropDown?menuNo=" // + menuNo + "&formClass=" + menuClass, htmlHelper.ViewContext.HttpContext); // dropdownListOptions.BindType = DropdownListBindType.None; // dropdownListOptions.Name = "Attribute"; // dropdownListOptions.ID = "Attribute"; // dropdownListOptions.OnSelect = "SystemQueryControl.QueryControl"; // DropdownListOptions dropdownListOptions1 = new DropdownListOptions(); // List listdlt = new List{ // new DropdownListItem{ Text = "=", Value = "=" }, // new DropdownListItem{ Text = ">=", Value = ">=" }, // new DropdownListItem{ Text = ">", Value = ">" }, // new DropdownListItem{ Text = "<=", Value = "<=" }, // new DropdownListItem{ Text = "<", Value = "<" }, // new DropdownListItem{ Text = "<>", Value = "<>" }, // new DropdownListItem{ Text = "左", Value = "左" }, // new DropdownListItem{ Text = "右", Value = "右" }, // new DropdownListItem{ Text = "中", Value = "中" }, // }; // dropdownListOptions1.BindType = DropdownListBindType.None; // dropdownListOptions1.ItemList = listdlt; // dropdownListOptions1.Name = "Condition"; // dropdownListOptions1.ID = "Condition"; // html = "
\n"; // html += "
" + // "" + // "
    " + // "
  • 查询:
  • " + // "
  • " + // Bowin.Web.Controls.Mvc.DropdownList.CreateControl(dropdownListOptions, htmlAttributes).Render() + // "
  • " + // "
  • " + // Bowin.Web.Controls.Mvc.DropdownList.CreateControl(dropdownListOptions1, htmlAttributes).Render() + // "
  • " + // "
  • " + // GetQueryControl(htmlHelper, listAttribute) + // "
  • " + // "
  • 查询
  • " + // "
" + // "
"; // html += "
"; // return MvcHtmlString.Create(html); //} /// /// 获取查询控件 /// /// /// /// private static string GetQueryControl(HtmlHelper htmlHelper, List listAttribute) { string control = string.Empty; int i = 0; string cl = string.Empty; foreach (var item in listAttribute) { string controlName = item.Value.Replace(".", ""); cl = i == 0 ? "" : "class='divquery'"; IDictionary htmlAttributes = new Dictionary { { "data-condition", item.listControl } }; if (item.ControlType == "TextBox") { TextBoxOptions tbop = new TextBoxOptions { ID = controlName + "_QueryTextBox", Name = controlName + "_QueryTextBox" }; var ss = htmlHelper.TextBox(tbop, htmlAttributes); control += "
" + htmlHelper.TextBox(tbop, htmlAttributes) + "
"; } else if (item.ControlType == "DropdownList") { DropdownListOptions dropdownListOptions = new DropdownListOptions(); dropdownListOptions.BindType = DropdownListBindType.SelectAll; dropdownListOptions.ID = controlName + "_QueryDropdownList"; dropdownListOptions.Name = controlName + "_QueryDropdownList"; dropdownListOptions.ItemSourceUrl = item.PostUrl; dropdownListOptions.TextField = item.ControlTextFiled; dropdownListOptions.ValueField = item.ControlValueFiled; var ss = htmlHelper.DropdownList(dropdownListOptions, htmlAttributes); control += "
" + htmlHelper.DropdownList(dropdownListOptions, htmlAttributes) + "
"; } else if (item.ControlType == "DictionaryDropDownList") { DropdownListOptions dropdownListOptions = new DropdownListOptions(); dropdownListOptions.BindType = DropdownListBindType.SelectAll; dropdownListOptions.ID = controlName + "_QueryDictionaryDropDownList"; dropdownListOptions.Name = controlName + "_QueryDictionaryDropDownList"; dropdownListOptions.TextField = item.ControlTextFiled; dropdownListOptions.ValueField = item.ControlValueFiled; var ss = htmlHelper.DictionaryDropDownList(item.DictionaryCode, dropdownListOptions, htmlAttributes).ToHtmlString(); control += "
" + htmlHelper.DictionaryDropDownList(item.DictionaryCode, dropdownListOptions, htmlAttributes).ToHtmlString() + "
"; } else if (item.ControlType == "CheckBox") { var ss = htmlHelper.CheckBox(controlName + "_QueryCheckBox", true, new { ID = controlName + "_QueryCheckBox" }) + "是/否"; control += "
" + htmlHelper.CheckBox(controlName + "_QueryCheckBox", true, new { ID = controlName + "_QueryCheckBox" }) + "是/否" + "
"; } else if (item.ControlType == "ComboGrid") { List lstgridColumn = new List(); using (var scope = AutofacHelper.Container.BeginLifetimeScope()) { IConfiguretermsInfoServices configuretermsServices = scope.Resolve(); List listBModify = configuretermsServices.GetConfiguretermsExpand(item.ID); foreach (var bmitem in listBModify) { BoundFieldColumn bfc = new BoundFieldColumn { FieldName = bmitem.ColumnValue, HeaderText = bmitem.ColumnName, Width = 0.1, Align = AlignStyle.Center }; lstgridColumn.Add(bfc); } } ComboGridOptions cgop = new ComboGridOptions { TextField = item.ControlTextFiled, ValueField = item.ControlValueFiled, ID = controlName + "_QueryComboGrid", Name = controlName + "_QueryComboGrid", GridOptions = new DataGridOptions { Columns = lstgridColumn, IsCheckOnSelect = true, DataSourceUrl = UrlHelper.GenerateContentUrl(item.PostUrl, htmlHelper.ViewContext.HttpContext), IsPagination = true, IsShowRowNumbers = true, IsSingleSelect = false } }; control += "
" + htmlHelper.ComboGrid(cgop, htmlAttributes) + "
"; } else if (item.ControlType == "TextBoxDate") { TextBoxOptions tbop = new TextBoxOptions { ID = controlName + "_QueryTextBoxDate", Name = controlName + "_QueryTextBoxDate", TextBoxType = TextBoxType.Date }; var ss = htmlHelper.TextBox(tbop, htmlAttributes); control += "
" + htmlHelper.TextBox(tbop, htmlAttributes) + "
"; } i++; } return control; } /// /// 批量修改控件,需要通过数据库配置具体的修改项 /// /// /// 自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary { /// { "style", "width: 100%;" }, { "name", "ddlUsers" } /// } /// /// public static MvcHtmlString PositionBatchModify(this HtmlHelper htmlHelper, IDictionary htmlAttributes = null) { var request = htmlHelper.ViewContext.RequestContext.HttpContext.Request; var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); string menuNo = request["MNU"]; string html = ""; string listControlID = string.Empty; string columnName = string.Empty; List listAttribute = null; IBatchModifyServices catchModifyServices = AutofacHelper.Container.Resolve(); listAttribute = catchModifyServices.GetBatchModifyList(menuNo); foreach (var item in listAttribute) { listControlID = item.listControl; columnName += item.Value + item.ControlType + "_div" + ","; } DropdownListOptions dropdownListOptions = new DropdownListOptions(); dropdownListOptions.BindType = DropdownListBindType.PleaseSelect; dropdownListOptions.ItemSourceUrl = UrlHelper.GenerateContentUrl("~/Common/BatchUpdateDropDown?menuNo=" + menuNo, htmlHelper.ViewContext.HttpContext); dropdownListOptions.BindType = DropdownListBindType.None; dropdownListOptions.Name = "DropdownBatchModify"; dropdownListOptions.ID = "DropdownBatchModify"; dropdownListOptions.OnSelect = "SystemBatchModifyControl.BatchModifyControl"; //if (!string.IsNullOrEmpty(postFormUrl)) // postFormUrl = "method=\"post\" action='" + postFormUrl + "'"; html = "
\n"; html += "
" + "
" + "
    " + "
  • 批量修改:
  • " + "
  • " + Bowin.Web.Controls.Mvc.DropdownList.CreateControl(dropdownListOptions, htmlAttributes).Render() + "
  • " + "
  • " + GetBatchControl(htmlHelper, listAttribute) + "
  • " + "
  • 确定   取消
  • " + "
" + "" + "" + "" + "
" + "
"; html += "
"; return MvcHtmlString.Create(html); } /// /// 批量修改控件 /// /// /// /// private static string GetBatchControl(HtmlHelper htmlHelper, List listAttribute) { string control = string.Empty; int i = 0; foreach (var item in listAttribute) { if (item.ControlType == "TextBox") { TextBoxOptions tbop = new TextBoxOptions { ID = item.Value + "_TextBox", Name = item.Value + "_TextBox" }; control += "
" + htmlHelper.TextBox(tbop) + "
"; } else if (item.ControlType == "DropdownList") { DropdownListOptions dropdownListOptions = new DropdownListOptions(); dropdownListOptions.BindType = DropdownListBindType.PleaseSelect; dropdownListOptions.ID = item.Value + "_DropdownList"; dropdownListOptions.Name = item.Value + "_DropdownList"; dropdownListOptions.ItemSourceUrl = item.PostUrl; dropdownListOptions.TextField = item.ControlTextFiled; dropdownListOptions.ValueField = item.ControlValueFiled; control += "
" + htmlHelper.DropdownList(dropdownListOptions) + "
"; } else if (item.ControlType == "DictionaryDropDownList") { DropdownListOptions dropdownListOptions = new DropdownListOptions(); dropdownListOptions.BindType = DropdownListBindType.PleaseSelect; dropdownListOptions.ID = item.Value + "_DictionaryDropDownList"; dropdownListOptions.Name = item.Value + "_DictionaryDropDownList"; dropdownListOptions.TextField = item.ControlTextFiled; dropdownListOptions.ValueField = item.ControlValueFiled; control += "
" + htmlHelper.DictionaryDropDownList(item.DictionaryCode, dropdownListOptions).ToHtmlString() + "
"; } else if (item.ControlType == "CheckBox") { control += "
" + //"" + "是/否" + //htmlHelper.CheckBox(item.Value + "_CheckBox") + "是/否" + "
"; } else if (item.ControlType == "ComboGrid") { List lstgridColumn = new List(); using (var scope = AutofacHelper.Container.BeginLifetimeScope()) { IBatchModifyServices bcatchModifyServices = scope.Resolve(); List listBModify = bcatchModifyServices.GetBatchModifyExpandList(item.BatchModifyID); foreach (var bmitem in listBModify) { BoundFieldColumn bfc = new BoundFieldColumn { FieldName = bmitem.ColumnValue, HeaderText = bmitem.ColumnName, Width = 0.1, Align = AlignStyle.Center }; lstgridColumn.Add(bfc); } } ComboGridOptions cgop = new ComboGridOptions { TextField = item.ControlTextFiled, ValueField = item.ControlValueFiled, ID = item.Value + "_ComboGrid", Name = item.Value + "_ComboGrid", GridOptions = new DataGridOptions { Columns = lstgridColumn, IsCheckOnSelect = true, DataSourceUrl = UrlHelper.GenerateContentUrl(item.PostUrl, htmlHelper.ViewContext.HttpContext), IsPagination = true, IsShowRowNumbers = true, IsSingleSelect = false } }; control += "
" + htmlHelper.ComboGrid(cgop) + "
"; } else if (item.ControlType == "TextBoxDate") { TextBoxOptions tbop = new TextBoxOptions { ID = item.Value + "_TextBoxDate", Name = item.Value + "_TextBoxDate", TextBoxType = TextBoxType.Date }; control += "
" + htmlHelper.TextBox(tbop) + "
"; } else if (item.ControlType == "TextBoxDateTime") { TextBoxOptions tbop = new TextBoxOptions { ID = item.Value + "_TextBoxDateTime", Name = item.Value + "_TextBoxDateTime", TextBoxType = TextBoxType.DateTime }; control += "
" + htmlHelper.TextBox(tbop) + "
"; } else if (item.ControlType == "NumberBox") { TextBoxOptions tbop = new TextBoxOptions { ID = item.Value + "_NumberBox", Name = item.Value + "_NumberBox", TextBoxType = TextBoxType.Normal }; control += "
" + htmlHelper.TextBox(tbop, new Dictionary { { "number", "true" } }) + "
"; } i++; } return control; } } }