Exemple #1
0
        /// <summary>
        /// 修改时勾选listbox
        /// </summary>
        /// <param name="user"></param>
        /// <param name="clauseContract"></param>
        /// <param name="masterId"></param>
        /// <param name="isCreate"></param>
        /// <param name="contractId"></param>
        /// <returns></returns>
        private System.Text.StringBuilder UpdateCheckItems(UserModel user, int contractId)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            try
            {
                ContractClauseDAL dal = new ContractClauseDAL();
                NFMT.Common.ResultModel result = dal.LoadByContractId(user, contractId);
                if (result.ResultStatus != 0)
                    return sb.Clear();

                List<Model.ContractClause> contractClauses = result.ReturnValue as List<Model.ContractClause>;
                if (contractClauses == null || !contractClauses.Any())
                    return sb.Clear();

                foreach (Model.ContractClause contractClause in contractClauses.OrderBy(a => a.ClauseId))
                {
                    sb.AppendFormat("var item = $(\"#listbox_\"+{0}).jqxListBox(\"getItemByValue\", \"{1}\");", string.Format("masterIds.indexOf({0})", contractClause.MasterId), contractClause.ClauseId);
                    sb.AppendFormat("$(\"#listbox_\"+{0}).jqxListBox(\"removeItem\",item);", string.Format("masterIds.indexOf({0})", contractClause.MasterId));
                    sb.AppendFormat("$(\"#listbox_\"+{0}).jqxListBox(\"insertAt\",item, 0);", string.Format("masterIds.indexOf({0})", contractClause.MasterId));
                    sb.AppendFormat("$(\"#listbox_\"+{0}).jqxListBox(\"checkIndex\",0);", string.Format("masterIds.indexOf({0})", contractClause.MasterId));
                    sb.Append(Environment.NewLine);
                }
            }
            catch
            {
                return sb.Clear();
            }

            return sb;
        }
Exemple #2
0
        /// <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;
            }
        }