Beispiel #1
0
        private void SaveTopicType_Click(object sender, EventArgs e)
        {
            int  num  = 0;
            bool flag = false;

            foreach (object current in this.DataGrid1.GetKeyIDArray())
            {
                string s             = current.ToString();
                Int32  typeid        = Int32.Parse(s);
                string controlValue  = this.DataGrid1.GetControlValue(num, "name");
                string controlValue2 = this.DataGrid1.GetControlValue(num, "displayorder");
                string controlValue3 = this.DataGrid1.GetControlValue(num, "description");
                if (!this.CheckValue(controlValue, controlValue2, controlValue3) || TopicType.IsExist(controlValue, typeid))
                {
                    flag = true;
                }
                else
                {
                    var sortedList = TopicType.GetTopicTypeArray();
                    //DataTable existTopicTypeOfForum = Forums.GetExistTopicTypeOfForum();
                    DataTable topicTypes = TopicType.FindAllWithCache().ToDataTable();
                    foreach (var item in XForum.Root.AllChilds)
                    {
                        var text = item.Field.TopicTypes + "";
                        if (String.IsNullOrEmpty(text.Trim()))
                        {
                            continue;
                        }

                        string topicTypeString = this.GetTopicTypeString(text, sortedList[typeid].ToString().Trim());
                        if (!(String.IsNullOrEmpty(topicTypeString)))
                        {
                            string value = topicTypeString.Replace("," + sortedList[typeid].ToString().Trim() + ",", "," + controlValue + ",");
                            text = text.Replace(topicTypeString + "|", "");
                            ArrayList arrayList = new ArrayList();
                            string[]  array     = text.Split('|');
                            for (int i = 0; i < array.Length; i++)
                            {
                                string text2 = array[i];
                                if (text2 != "")
                                {
                                    arrayList.Add(text2);
                                }
                            }
                            bool flag2 = false;
                            for (int j = 0; j < arrayList.Count; j++)
                            {
                                int displayOrder = this.GetDisplayOrder(arrayList[j].ToString().Split(',')[1], topicTypes);
                                if (displayOrder > int.Parse(controlValue2))
                                {
                                    arrayList.Insert(j, value);
                                    flag2 = true;
                                    break;
                                }
                            }
                            if (!flag2)
                            {
                                arrayList.Add(value);
                            }
                            text = "";
                            foreach (object current2 in arrayList)
                            {
                                text = text + current2.ToString() + "|";
                            }

                            //TopicTypes.UpdateForumTopicType(text, int.Parse(dataRow["fid"].ToString()));
                            //var ff = ForumField.FindByID(int.Parse(dataRow["fid"].ToString()));
                            var ff = item.Field;
                            if (ff != null)
                            {
                                ff.TopicTypes = text;
                                ff.Save();
                            }
                            XCache.Remove("/Forum/TopicTypesOption" + item.ID);
                            XCache.Remove("/Forum/TopicTypesLink" + item.ID);
                        }
                    }

                    //TopicTypes.UpdateTopicTypes(controlValue, int.Parse(controlValue2), controlValue3, typeid);
                    var entity = TopicType.FindByID(typeid);
                    if (entity != null)
                    {
                        entity.Name         = controlValue;
                        entity.DisplayOrder = Int32.Parse(controlValue);
                        entity.Description  = controlValue3;
                        entity.Save();
                    }
                    num++;
                }
            }

            //XCache.Remove("/Forum/TopicTypes");
            XCache.Remove(CacheKeys.FORUM_FORUM_LIST);
            if (flag)
            {
                base.RegisterStartupScript("", "<script>alert('数据库中已存在相同的主题分类名称或为空,该记录不能被更新!');window.location.href='forum_topictypesgrid.aspx';</script>");
                return;
            }
            base.RegisterStartupScript("PAGE", "window.location.href='forum_topictypesgrid.aspx';");
        }