Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="action">新的操作名称</param>
        /// <param name="typeFldName">类别字段名称</param>
        /// <param name="typeID">类别值</param>
        private int AddOperate(string action, int typeID)
        {
            CustomConcatenatedField f = (CustomConcatenatedField)base.Field;
            string  lstID             = f.LookupList;
            SPSite  s         = SPControl.GetContextSite(Context);
            int     itemID    = 0;
            SPWeb   lookupWeb = SPControl.GetContextWeb(Context);
            int     userID    = lookupWeb.CurrentUser.ID;
            SPField typeFld   = GetCascadedField;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(lookupWeb.Site.ID))
                {
                    using (SPWeb web = site.AllWebs[lookupWeb.ID])
                    {
                        SPList lookupList      = web.Lists[new Guid(lstID)];
                        SPListItem addItem     = lookupList.Items.Add();
                        addItem["Title"]       = action;
                        addItem[typeFld.Title] = typeID;
                        addItem[lookupList.Fields.GetFieldByInternalName("Flag").Title] = "11";
                        addItem["Author"]      = userID;
                        web.AllowUnsafeUpdates = true;
                        addItem.Update();
                        web.AllowUnsafeUpdates = false;
                        itemID = addItem.ID;
                    }
                }
            });
            return(itemID);
        }
Esempio n. 2
0
        private void InitControls(int id = 0, int level = 2)
        {
            bool multiLevel                   = MultiLevel;
            CustomConcatenatedField f         = (CustomConcatenatedField)base.Field;
            SPFieldLookup           fldParent = GetCascadedField;
            string          parentField       = multiLevel ? fldParent.InternalName : "";
            List <ListItem> itemDesc          = new List <ListItem>();

            ListItem[] cateItems = GetListItems(fldParent.LookupList, fldParent.LookupField, parentField, 0, ref itemDesc);

            DropDownList1.Items.Clear();
            DropDownList1.Items.AddRange(cateItems);//顶级先填充
            ddlDes.Items.Clear();
            if (itemDesc.Count > 0)
            {
                ddlDes.Items.AddRange(itemDesc.ToArray());
            }


            if (f.SPLookupWidth != "")
            {
                DropDownList1.Width = int.Parse(f.SPLookupWidth);
            }

            //顶级不变,从第二开始
            List <int> selectdValues = new List <int>();

            if (id > 0)//以前有值
            {
                selectdValues.Add(id);
                GetSeletedParentIDs(id, multiLevel, ref selectdValues);
                selectdValues.Reverse();    //自下而上改为自上而下
                if (selectdValues[0] == -1) //处理操作被删除的情况
                {
                    selectdValues[0] = int.Parse(DropDownList1.Items[0].Value);
                }

                DropDownList1.SelectedValue = selectdValues[0].ToString();
            }
            else//以前无值
            {
                id = int.Parse(DropDownList1.SelectedValue);//查找以当前ID为父ID的项
                selectdValues.Add(id);
                GetAllIDs(id, multiLevel, ref selectdValues);
            }
            if (ddlDes.Items.Count > 0)
            {
                spanDesc.InnerText = ddlDes.Items[DropDownList1.SelectedIndex].Text;
            }

            FillChildLevel(selectdValues, level);
        }
Esempio n. 3
0
        /// <summary>
        /// 自上而下获取ID
        /// </summary>
        /// <param name="parentID"></param>
        /// <param name="ids"></param>
        private void GetAllIDs(int parentID, bool multiLevel, ref List <int> ids)
        {
            CustomConcatenatedField f   = (CustomConcatenatedField)base.Field;
            SPFieldLookup           fld = GetCascadedField;
            int id = GetListItemsOfFirstID(f.LookupList, f.LookupField, fld.InternalName, parentID);

            if (id > 0)
            {
                ids.Add(id);
                if (multiLevel)
                {
                    GetAllIDs(id, multiLevel, ref ids);
                }
            }
        }
        void IFieldEditor.OnSaveChange(SPField field, bool isNewField)
        {
            this.EnsureChildControls();
            if (field != null)
            {
                CustomConcatenatedField _f = field as CustomConcatenatedField;

                SPSite _site = SPControl.GetContextSite(this.Context);
                SPWeb  _web  = _site.OpenWeb();
                _f.LookupWebId   = _web.ID;
                _f.LookupList    = ddlListName.SelectedValue;
                _f.LookupField   = ddlFieldName.SelectedValue;
                _f.SPLookupList  = ddlListName.SelectedValue;
                _f.SPLookupField = ddlFieldName.SelectedValue;
                _f.SPLookupWidth = txtWidth.Text;
            }
        }
        //编辑字段配置信息绑定到控件上
        void IFieldEditor.InitializeWithField(SPField field)
        {
            if (!Page.IsPostBack)
            {
                this.EnsureChildControls();
                BindSPListFieldData(ddlListName);
                if (ddlListName.Items.Count > 0 && ddlFieldName.Items.Count == 0)
                {
                    FillListFields(ddlListName.Items[0].Value);
                }
            }

            if (!Page.IsPostBack && field != null)
            {
                CustomConcatenatedField fields = (CustomConcatenatedField)field;
                this.ddlListName.SelectedValue = fields.SPLookupList;
                ddlFieldName.SelectedValue     = fields.SPLookupField;
                txtWidth.Text = fields.SPLookupWidth;
            }
            ddlListName.AutoPostBack          = true;
            ddlListName.SelectedIndexChanged += DdlListName_SelectedIndexChanged;
        }
Esempio n. 6
0
        /// <summary>
        /// 填充自上向下的级别数
        /// </summary>
        /// <returns></returns>
        private void FillChildLevel(List <int> selectedValues, int level)
        {
            CustomConcatenatedField f   = (CustomConcatenatedField)base.Field;
            SPFieldLookup           fld = GetCascadedField;

            ListItem[] items;
            bool       multiLevel = MultiLevel;
            int        tEnd       = selectedValues.Count - 1;//只有两级时,查阅项字段在另一个列表中,否则遍历会进入死
            bool       allowAdd   = false;

            if (tEnd == 0)//类别下操作为空,会出错2018-11-16
            {
                tEnd     = 1;
                allowAdd = true;
            }
            //循环
            string ddlID;

            if (multiLevel)
            {
                tEnd = selectedValues.Count;
            }
            int           parentID;
            HtmlTableRow  row;
            HtmlTableCell cell;

            for (int i = 0; i < tEnd; i++)
            {
                parentID = selectedValues[i];
                List <ListItem> lstDesc = new List <System.Web.UI.WebControls.ListItem>();
                items       = GetListItems(f.LookupList, f.LookupField, fld.InternalName, parentID, ref lstDesc);
                ddlID       = "DropDownList" + level;
                this.ddlNew = (DropDownList)TemplateContainer.FindControl(ddlID);
                if (items.Length > 0 || allowAdd)//还有下一级
                {
                    if (ddlNew == null)
                    {
                        ddlNew    = new DropDownList();
                        ddlNew.ID = ddlID;
                        if (f.SPLookupWidth != "")
                        {
                            ddlNew.Width = int.Parse(f.SPLookupWidth);
                        }
                        row  = new HtmlTableRow();
                        cell = new HtmlTableCell();
                        cell.Controls.Add(ddlNew);
                        row.Cells.Add(cell);
                        tblLevel.Rows.Add(row);

                        cell = new HtmlTableCell();
                        row.Cells.Add(cell);
                        tblLevel.Rows.Add(row);
                    }
                    else
                    {
                        if (f.SPLookupWidth != "")
                        {
                            ddlNew.Width = int.Parse(f.SPLookupWidth);
                        }
                    }
                    if (multiLevel)
                    {
                        ddlNew.AutoPostBack          = true;
                        ddlNew.SelectedIndexChanged += Ddl_SelectedIndexChanged;
                    }
                    ddlNew.Items.Clear();
                    ddlNew.Items.AddRange(items);
                    if ((i + 1) < selectedValues.Count)
                    {
                        ddlNew.SelectedValue = selectedValues[i + 1].ToString();
                    }
                    level = level + 1;
                }
            }
            //保留最后一级的选项
            if (multiLevel)
            {
                ViewState["lastID"] = selectedValues[tEnd - 1].ToString();//保留最后一级当前所选ID,临时的
                //txtCustAction.Visible = false;
                spanTxtDesc.Visible = false;
            }
            else//二级的,添加自定义操作
            {
                ViewState["lastID"] = null;
                this.txtCustAction  = (TextBox)TemplateContainer.FindControl("txtNewAction");//动态加的
                if (txtCustAction == null)
                {
                    TextBox txtNewAction = new TextBox();
                    txtNewAction.ID = "txtNewAction";

                    if (f.SPLookupWidth != "")
                    {
                        txtNewAction.Width = int.Parse(f.SPLookupWidth) - 10;
                    }
                    //txtCustAction.Visible = true;

                    tblLevel.Rows[level - 2].Cells[1].Controls.Add(txtNewAction);
                }
                spanTxtDesc.Visible = true;
            }
            //原来的是三级,更改选项后变成了两级,级别减少了
            for (int j = tblLevel.Rows.Count; j >= level; j--)
            {
                tblLevel.Rows.RemoveAt(j - 1);
            }
        }