protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int refId = 0; if (string.IsNullOrEmpty(Request.QueryString["id"])) Response.Redirect("MasterClauseAllot.aspx"); if(!int.TryParse(Request.QueryString["id"],out refId)) Response.Redirect("MasterClauseAllot.aspx"); NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser; NFMT.Data.BLL.ClauseContractBLL refBLL = new NFMT.Data.BLL.ClauseContractBLL(); NFMT.Common.ResultModel result = refBLL.Get(user, refId); if(result.ResultStatus!=0) Response.Redirect("MasterClauseAllot.aspx"); NFMT.Data.Model.ClauseContract masterClause = result.ReturnValue as NFMT.Data.Model.ClauseContract; if(masterClause==null || masterClause.RefId<=0) Response.Redirect("MasterClauseAllot.aspx"); NFMT.Data.BLL.ContractMasterBLL masterBLL = new NFMT.Data.BLL.ContractMasterBLL(); result = masterBLL.Get(user,masterClause.MasterId); if(result.ResultStatus!=0) Response.Redirect("MasterClauseAllot.aspx"); NFMT.Data.Model.ContractMaster master = result.ReturnValue as NFMT.Data.Model.ContractMaster; if(master==null || master.MasterId<=0) Response.Redirect("MasterClauseAllot.aspx"); NFMT.Data.BLL.ContractClauseBLL clauseBLL = new NFMT.Data.BLL.ContractClauseBLL(); result = clauseBLL.Get(user, masterClause.ClauseId); if(result.ResultStatus!=0) Response.Redirect("MasterClauseAllot.aspx"); NFMT.Data.Model.ContractClause clause = result.ReturnValue as NFMT.Data.Model.ContractClause; if(clause==null || clause.ClauseId<=0) Response.Redirect("MasterClauseAllot.aspx"); this.spnClauseEtext.InnerHtml = clause.ClauseEnText; this.spnClauseText.InnerHtml = clause.ClauseText; this.spnMasterEname.InnerHtml = master.MasterEname; this.spnMasterName.InnerHtml = master.MasterName; this.chkIsChose.Checked = masterClause.IsChose; this.txbSort.Value = masterClause.Sort.ToString(); this.hidRefId.Value = masterClause.RefId.ToString(); int masterId = 0; int.TryParse(Request.QueryString["mid"],out masterId); this.navigation1.Routes.Add("合约模板列表", "MasterClauseAllot.aspx"); this.navigation1.Routes.Add("模板条款分配", string.Format("MasterClauseCreate.aspx?id={0}",masterId)); this.navigation1.Routes.Add("分配修改",string.Empty); } }
/// <summary> /// 动态生成控件绑定javascript代码 /// </summary> /// <param name="user"></param> /// <param name="isCreate">是否在新增时调用</param> /// <returns></returns> public string GetListBoxsInit(UserModel user, OperateEnum operate, int contractId) { try { List<NFMT.Data.Model.ClauseContract> clauseContracts = GetClauseContracts(user); if (clauseContracts == null || !clauseContracts.Any()) return string.Empty; System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.Text.StringBuilder sbCheck = new System.Text.StringBuilder(); System.Text.StringBuilder sbMasterIdsArray = new System.Text.StringBuilder(); NFMT.Data.BLL.ContractClauseBLL contractClauseBLL = new NFMT.Data.BLL.ContractClauseBLL(); NFMT.Common.ResultModel result = new NFMT.Common.ResultModel(); sb.Append("$(\"#jqxTabs\").jqxTabs({ width: \"99%\", position: \"top\" }); "); sb.Append(Environment.NewLine); int i = 0; foreach (int masterId in clauseContracts.Select(a => a.MasterId).Distinct()) { if (i == 1) { sb.Append("$('#jqxTabs').on('selected', function (event) {"); sb.Append(Environment.NewLine); sb.Append("var clickedItem = event.args.item;"); sb.Append(Environment.NewLine); } if (i != 0) { sb.AppendFormat("if(clickedItem =={0}&&is{0}Inited==false) ", i.ToString()); sb.Append("{"); } sb.Append("var localdataArray = ["); foreach (NFMT.Data.Model.ClauseContract clauseContract in clauseContracts.Where(a => a.MasterId == masterId).OrderByDescending(a => a.IsChose).ThenBy(b => b.Sort)) { result = contractClauseBLL.Get(user, clauseContract.ClauseId); if (result.ResultStatus != 0) continue; NFMT.Data.Model.ContractClause contractClause = result.ReturnValue as NFMT.Data.Model.ContractClause; if (contractClause == null) continue; sb.AppendFormat("[\"{0}\",\"{1}\"],", clauseContract.ClauseId.ToString(), contractClause.ClauseText); //勾选 if (operate == OperateEnum.新增) sbCheck.Append(CreateCheckItems(user, clauseContract, masterId, i)); } if (!string.IsNullOrEmpty(sb.ToString())) sb = sb.Remove(sb.Length - 1, 1); sb.Append("];"); sb.Append(Environment.NewLine); sb.AppendFormat("var source{0}=", masterId.ToString()); sb.Append("{localdata:localdataArray,async:false ,datatype:\"array\",datafields: [{ name: \"id\",type: \"int\", map: \"0\" },{ name: \"name\",type: \"string\", map: \"1\"}]};"); sb.Append(Environment.NewLine); sb.Append("try{"); sb.Append(Environment.NewLine); sb.AppendFormat("var listboxDataAdapter{0} = new $.jqx.dataAdapter(source{0});", masterId.ToString()); sb.Append(Environment.NewLine); sb.AppendFormat("$(\"#listbox_{0}\").jqxListBox( ", i.ToString()); sb.Append("{ "); sb.AppendFormat("source: listboxDataAdapter{0}, checkboxes: true,displayMember: \"name\", valueMember: \"id\",autoHeight:true,width:\"99%\",allowDrag:true,autoItemsHeight: true ", masterId.ToString()); sb.Append(Environment.NewLine); sbMasterIdsArray.Append(Environment.NewLine); sbMasterIdsArray.AppendFormat("masterIds.push({0});", masterId); sbMasterIdsArray.Append(Environment.NewLine); sbMasterIdsArray.AppendFormat(" var is{0}Inited = false;", i.ToString()); sb.Append("}); "); sb.Append(Environment.NewLine); sb.AppendFormat("is{0}Inited = true;", i.ToString()); sb.Append(Environment.NewLine); sb.Append(sbCheck); sb.Append(Environment.NewLine); sb.Append("}catch(e){alert(e.Message);}"); sb.Append(Environment.NewLine); if (i != 0) sb.Append("}"); i++; } if (i > 1) sb.Append("})"); //勾选 if (operate == OperateEnum.修改 || operate == OperateEnum.明细) { ContractClauseDAL dal = new ContractClauseDAL(); result = dal.LoadByContractId(user, contractId); if (result.ResultStatus == 0) { List<Model.ContractClause> contractClauses = result.ReturnValue as List<Model.ContractClause>; if (contractClauses != null && contractClauses.Any()) { int masterId = contractClauses.First().MasterId; sbCheck.AppendFormat("$('#jqxTabs').jqxTabs('select', {0}); ", string.Format("masterIds.indexOf({0})", masterId)); sbCheck.Append("for(var i =0;i<masterIds.length;i++){"); sbCheck.AppendFormat("if(masterIds[i]=={0})", masterId); sbCheck.Append("{continue;}"); if (operate == OperateEnum.明细) sbCheck.Append("$('#jqxTabs').jqxTabs('removeAt', i);"); //else // sbCheck.Append("$('#jqxTabs').jqxTabs('disableAt', i);"); sbCheck.Append("}"); sbCheck.Append(UpdateCheckItems(user, contractId)); if (operate == OperateEnum.明细) { sbCheck.AppendFormat("var items = $(\"#listbox_\"+{0}).jqxListBox('getItems');", string.Format("masterIds.indexOf({0})", masterId)); sbCheck.Append("var i =items.length-1;"); sbCheck.Append("for(;i>=0;i--){if(items[i].checked==false){"); sbCheck.AppendFormat("$(\"#listbox_\"+{0}).jqxListBox('removeItem', items[i]);", string.Format("masterIds.indexOf({0})", masterId)); sbCheck.Append("}}"); } sbCheck.Append(Environment.NewLine); if (operate == OperateEnum.明细) sbCheck.AppendFormat("$(\"#listbox_\"+{0}).jqxListBox(\"disabled\",true);", string.Format("masterIds.indexOf({0})", masterId)); } } } else sbCheck.Clear(); return sbMasterIdsArray.Append(sb).Append(Environment.NewLine).Append(sbCheck).Append(Environment.NewLine).ToString(); } catch { return string.Empty; } }