private static void SetDateDimensions(XmlElement xe, GroupSchema gs)
 {
     foreach (XmlElement n in xe.ChildNodes)
     {
         string key   = n.GetAttribute(GroupSchemas._xmlKeyName);
         int    value = Convert.ToInt32(n.GetAttribute(GroupSchemas._xmlKeyDateDimensionLevel));
         gs.DateDimensions.Add(key, value);
     }
 }
 private void SetOtherSchemaBDefault(GroupSchemas haveSaveGroupSchemas, GroupSchema gs)
 {
     if (gs.bDefault)
     {
         for (int i = 0; i < haveSaveGroupSchemas.Count; i++)
         {
             haveSaveGroupSchemas[i].bDefault = haveSaveGroupSchemas[i].ID == gs.ID ? true : false;
         }
     }
 }
        private void AddDateDimensions(XmlDocument doc, XmlElement parent, GroupSchema gs)
        {
            XmlElement xe = this.AddSubElement(doc, parent, GroupSchemas._xmlKeyDateDimensions);

            foreach (string key in gs.DateDimensions.Keys)
            {
                XmlElement xec = this.AddSubElement(doc, xe, GroupSchemas._xmlKeyDateDimension);
                xec.SetAttribute(GroupSchemas._xmlKeyName, key);
                xec.SetAttribute(GroupSchemas._xmlKeyDateDimensionLevel, gs.DateDimensions[key].ToString());
            }
        }
 private bool HaveSameName(GroupSchemas groupSchemas, GroupSchema group)
 {
     foreach (GroupSchema gs in groupSchemas)
     {
         if (gs.Name.Equals(group.Name) && gs.ID != group.ID)
         {
             return(true);
         }
     }
     return(false);
 }
        private void AddLangElement(
            XmlDocument doc,
            XmlElement parent,
            string id,
            GroupSchema gs)
        {
            XmlElement xeL = this.AddSubElement(doc, parent, GroupSchemas._xmlKeyLang);

            xeL.SetAttribute(GroupSchemas._xmlKeyIDLower, id);
            xeL.SetAttribute(GroupSchemas._xmlKeyName, gs.GetNameWithEmpty(id));
        }
 private void AddSchemaItem(
     GroupSchema gs,
     XmlDocument doc,
     XmlElement parent)
 {
     for (int i = 0; i < gs.SchemaItems.Count; i++)
     {
         XmlElement xeSi = this.AddSubElement(doc, parent, GroupSchemas._xmlKeySchemaItem);
         this.AddSchemaItemItem(gs.SchemaItems[i], doc, xeSi);
     }
 }
        private void AddMulitLangInfoElement(
            GroupSchema gs,
            XmlDocument doc,
            XmlElement parent)
        {
            XmlElement xeMli = this.AddSubElement(doc, parent, GroupSchemas._xmlKeyMulitLangInfo);

            foreach (string localeid in GroupSchemas._localeIds)
            {
                this.AddLangElement(doc, xeMli, localeid, gs);
            }
        }
        private static GroupSchema GetDefaultCrossSchema()
        {
            GroupSchema gs = new GroupSchema();

            gs.ID       = GroupSchemas._xmlValueDefaultNoGroupId;
            gs.bDefault = false;
            //gs.CurrentLocaleId = localeid;
            gs.SetName(GroupSchemas._xmlValueZhCn, "无交叉方案");
            gs.SetName(GroupSchemas._xmlValueZhTw, "無交叉方案");
            gs.SetName(GroupSchemas._xmlValueEnUs, "No cross schema");
            gs.bShowDetail = true;
            return(gs);
        }
        /// <summary>
        /// 构造一个"无分组"的分组对象
        /// </summary>
        private static GroupSchema GetDefaultGroupSchema()
        {
            GroupSchema gs = new GroupSchema();

            gs.ID       = GroupSchemas._xmlValueDefaultNoGroupId;
            gs.bDefault = false;
            //gs.CurrentLocaleId = localeid;
            gs.SetName(GroupSchemas._xmlValueZhCn, "无分组项展现");
            gs.SetName(GroupSchemas._xmlValueZhTw, "無分組項展現");
            gs.SetName(GroupSchemas._xmlValueEnUs, "No group item");
            gs.bShowDetail = true;
            return(gs);
        }
        private GroupSchema GetGroupSchemaById(GroupSchemas groupSchemas, string id)
        {
            GroupSchema schema = null;

            foreach (GroupSchema gs in groupSchemas)
            {
                if (gs.ID == id)
                {
                    return(gs);
                }
            }
            return(schema);
        }
Exemplo n.º 11
0
        public object Clone()
        {
            GroupSchema gs = new GroupSchema();

            gs.ID               = this.ID;
            gs.Name             = this.Name;
            gs.bDefault         = this.bDefault;
            gs.bGroupItemsAhead = this.bGroupItemsAhead;
            gs.bShowSubTotal    = this.bShowSubTotal;

            //************2012-5-17 add by yanghx
            gs.bShowDetail = this.bShowDetail;
            gs.ShowStyle   = this.ShowStyle;
            //**************

            gs.SchemaItems = this.SchemaItems.Clone() as GroupSchemaItems;
            //gs.CurrentLocaleId = this.CurrentLocaleId;
            gs._names = this._names.Clone() as Hashtable;
            foreach (string key in this.DateDimensions.Keys)
            {
                gs.DateDimensions.Add(key, this.DateDimensions[key]);
            }
            //复制排序
            if (this.SortSchema != null)
            {
                gs.SortSchema = new QuickSortSchema();
                foreach (QuickSortItem sortItem in this.SortSchema.QuickSortItems)
                {
                    QuickSortItem newItem = new QuickSortItem(sortItem.Level, sortItem.Name, sortItem.SortDirection, sortItem.Priority);
                    gs.SortSchema.QuickSortItems.Add(newItem);
                }
            }
            //复制列排序
            if (this.ColumnSortSchema != null && this.ColumnSortSchema.QuickSortItems != null)
            {
                gs.ColumnSortSchema = new QuickSortSchema();
                foreach (QuickSortItem sortItem in this.ColumnSortSchema.QuickSortItems)
                {
                    QuickSortItem newItem = new QuickSortItem(sortItem.Level, sortItem.Name, sortItem.SortDirection, sortItem.Priority);
                    gs.ColumnSortSchema.QuickSortItems.Add(newItem);
                }
            }
            //11.1增加行分组复制
            if (this.CrossRowGroup != null &&
                (this.CrossRowGroup.SchemaItems != null || this.CrossRowGroup.SortSchema != null))
            {
                gs.CrossRowGroup = this.CrossRowGroup.Clone() as GroupSchema;
            }
            gs.BShowHorizonTotal = this.BShowHorizonTotal;
            return(gs);
        }
 /// <summary>
 /// 添加交叉列的内容
 /// </summary>
 /// <param name="gs"></param>
 /// <param name="doc"></param>
 /// <param name="xeGs"></param>
 private void AddColumnSortItems(GroupSchema gs, XmlDocument doc, XmlElement parent)
 {
     if (gs.ColumnSortSchema != null)
     {
         XmlElement xeSortColumnItems = this.AddSubElement(doc, parent, GroupSchemas._xmlKeyQuickSortColumnItems);
         foreach (QuickSortItem item in gs.ColumnSortSchema.QuickSortItems)
         {
             XmlElement sort = this.AddSubElement(doc, xeSortColumnItems, GroupSchemas._xmlKeyItem);
             sort.SetAttribute(GroupSchemas._xmlKeyName, item.Name);
             sort.SetAttribute(GroupSchemas._xmlKeyOrder, item.SortDirection.ToString());
             sort.SetAttribute(GroupSchemas._xmlKeySortLevel, item.Level.ToString());
             sort.SetAttribute(GroupSchemas._xmlKeyPriority, item.Priority.ToString());
         }
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// 从XML获取分组集合对象
        /// </summary>
        public static GroupSchemas GetSchemas(
            XmlDocument schemaXmlDoc,
            string localeid, bool bcross)
        {
            GroupSchemas gss = new GroupSchemas(bcross);

            if (schemaXmlDoc != null)
            {
                XmlElement root = schemaXmlDoc.DocumentElement;
                if (root != null)
                {
                    foreach (XmlElement ele in root.ChildNodes)
                    {
                        gss.Add(GroupSchemas.GetGroupSchemaFromXml(ele, localeid));
                    }
                }
            }

            // 如果没有无分组项,则要添加
            if (gss[GroupSchemas._xmlValueDefaultNoGroupId] == null)
            {
                if (bcross)
                {
                    gss.Add(GroupSchemas.GetDefaultCrossSchema());
                }
                else
                {
                    gss.Add(GroupSchemas.GetDefaultGroupSchema());
                }
            }

            // 如果还没有默认分组,取第一个分组为默认分组
            GroupSchema defaultSchema = gss[0];

            foreach (GroupSchema gs in gss)
            {
                if (gs.bDefault)
                {
                    defaultSchema = gs;
                    break;
                }
            }
            defaultSchema.bDefault = true;
            gss.Default            = defaultSchema;
            return(gss);
        }
        //private static void AddSchemaTo(
        //    Report report,
        //    XmlElement xmlRoot,
        //    SectionType detailtype,
        //    string localeid )
        //{
        //    foreach( XmlElement ele in xmlRoot.ChildNodes )
        //    {
        //        GroupSchema gs = GroupSchemas.GetGroupSchemaFromXml(
        //            ele,
        //            localeid );
        //        report.GroupSchemas.Add( gs );
        //        if( gs.bDefault )
        //            report.CurrentSchemaID = gs.ID ;
        //    }
        //}

        /// <summary>
        /// 从XML的GroupSchema元素构造一个分组对象
        /// </summary>
        private static GroupSchema GetGroupSchemaFromXml(
            XmlElement groupSchemaElement,
            string localeid)
        {
            GroupSchema gs = new GroupSchema();

            GroupSchemas.SetGroupSchemaProperty(localeid, gs, groupSchemaElement);

            int groupLevel = 0;

            foreach (XmlElement ele in groupSchemaElement.ChildNodes)
            {
                switch (ele.Name)
                {
                case GroupSchemas._xmlKeyMulitLangInfo:
                    GroupSchemas.SetGroupSchemaName(ele, gs);
                    break;

                case GroupSchemas._xmlKeySchemaItem:
                    groupLevel++;
                    gs.SchemaItems.Add(GroupSchemas.GetGroupSchemaItem(ele, groupLevel));
                    break;

                case GroupSchemas._xmlKeyDateDimensions:
                    SetDateDimensions(ele, gs);
                    break;

                case GroupSchemas._xmlKeyQuickSortItems:
                    SetQuickSortItems(ele, gs, false);
                    break;

                case GroupSchemas._xmlKeyQuickSortColumnItems:
                    SetQuickSortItems(ele, gs, true);
                    break;

                case GroupSchemas._xmlKeyCrossRowGroup:
                    gs.CrossRowGroup = GetGroupSchemaFromXml(ele, localeid);
                    break;

                default:
                    break;
                }
            }
            return(gs);
        }
        private void InitSort(GroupSchema gs)
        {
            QuickSortSchema sortSchema = new QuickSortSchema();
            int             Priority   = 1;

            if (gs.SchemaItems.Count < 1)
            {
                return;
            }
            if (gs.SchemaItems.Count < 3)
            {
                foreach (GroupSchemaItem group in gs.SchemaItems)
                {
                    foreach (string name in group.Items)
                    {
                        QuickSortItem item = new QuickSortItem();
                        item.Level    = group.Level;
                        item.Priority = Priority;
                        Priority++;
                        item.Name          = name;
                        item.SortDirection = SortDirection.Descend;
                        sortSchema.QuickSortItems.Add(item);
                    }
                }
            }
            else
            {
                gs.SortSchema = sortSchema;
                GroupSchemaItem column = gs.SchemaItems[1];
                foreach (string name in column.Items)
                {
                    QuickSortItem item = new QuickSortItem();
                    item.Level    = 2;
                    item.Priority = Priority;
                    Priority++;
                    item.Name          = name;
                    item.SortDirection = SortDirection.Descend;
                    sortSchema.QuickSortItems.Add(item);
                }
                gs.ColumnSortSchema = sortSchema;
            }
        }
 private static void SetGroupSchemaName(
     XmlElement ele,
     GroupSchema gs)
 {
     foreach (string localeId in GroupSchemas._localeIds)
     {
         string path = string.Format(
             "{0}[@{1}='{2}']",
             GroupSchemas._xmlKeyLang,
             GroupSchemas._xmlKeyIDLower,
             localeId);
         XmlNode node = ele.SelectSingleNode(path);
         if (node != null)
         {
             gs.SetName(
                 localeId,
                 node.Attributes[GroupSchemas._xmlKeyName].Value);
         }
     }
 }
        private void AddCrossRowGroup(GroupSchema gs, XmlDocument doc, XmlElement parent)
        {
            XmlElement xeGs = this.AddSubElement(doc, parent, GroupSchemas._xmlKeyCrossRowGroup);

            xeGs.SetAttribute(GroupSchemas._xmlKeyID, gs.ID);
            xeGs.SetAttribute(GroupSchemas._xmlKeybDefault, gs.bDefault.ToString());
            xeGs.SetAttribute(GroupSchemas._xmlKeyIsShowSubTotal, gs.bShowSubTotal.ToString());
            xeGs.SetAttribute(GroupSchemas._xmlKeybShowDetial, gs.bShowDetail.ToString());
            xeGs.SetAttribute(GroupSchemas._xmlKeybGroupItemsAhead, gs.bGroupItemsAhead.ToString());
            xeGs.SetAttribute(GroupSchemas._xmlKeyShowStyle, Convert.ToString((int)gs.ShowStyle));
            xeGs.SetAttribute(GroupSchemas._xmlKeySwitchItem, gs.SwitchItem);
            xeGs.SetAttribute(GroupSchemas._xmlKeyVersion, gs.GuidVersion);
            xeGs.SetAttribute(GroupSchemas._xmlKeyLastUserGuid, gs.LastUserGuid);
            this.AddMulitLangInfoElement(gs, doc, xeGs);
            this.AddSchemaItem(gs, doc, xeGs);
            //添加排序内容
            this.AddSortItems(gs, doc, xeGs);
            this.AddColumnSortItems(gs, doc, xeGs);
            this.AddDateDimensions(doc, xeGs, gs);
        }
Exemplo n.º 18
0
 public bool Contains(GroupSchema value)
 {
     return(List.Contains(value));
 }
Exemplo n.º 19
0
 public void Remove(GroupSchema value)
 {
     List.Remove(value);
 }
Exemplo n.º 20
0
 public void Insert(int index, GroupSchema value)
 {
     BeforeAdd(value);
     List.Insert(index, value);
 }
Exemplo n.º 21
0
 public int IndexOf(GroupSchema value)
 {
     return(List.IndexOf(value));
 }
Exemplo n.º 22
0
 public void Append(int index, GroupSchema value)
 {
     BeforeAdd(value);
     this.List.Insert(index, value);
 }
Exemplo n.º 23
0
 public int Add(GroupSchema value)
 {
     BeforeAdd(value);
     return(List.Add(value));
 }
        public string SaveCrossSchemasWithLock(U8LoginInfor login, string viewID, string crossSchemas, string actionType)
        {
            //1开一个新的连接,并开事务
            SqlConnection cnn = new SqlConnection(login.UfMetaCnnString);

            cnn.Open();
            SqlTransaction tran   = cnn.BeginTransaction();
            string         result = string.Empty;

            try
            {
                //21 首先获取当前数据库的groupSchemas,并构造要保存的groupSchemas
                XmlDocument  doc = this.GetCrossSchemasWithXLock(viewID, tran); //tran
                GroupSchemas haveSaveCrossSchemas = GroupSchemas.GetSchemas(doc, "");
                GroupSchemas toSaveCrossSchemas   = GroupSchemas.GetSchemasNoSetDefaultSchema(crossSchemas, "");
                //3然后每一个groupSchema做对比
                if (toSaveCrossSchemas.Count <= 0)
                {
                    return(toSaveCrossSchemas.ToXml().InnerXml);
                }
                GroupSchema cs = toSaveCrossSchemas[0];//要更新的
                foreach (GroupSchema group in toSaveCrossSchemas)
                {
                    if (group.ID != NOGROUPID)
                    {
                        cs = group;
                    }
                }
                GroupSchema oldGs = GetGroupSchemaById(haveSaveCrossSchemas, cs.ID);//数据库中已经有的
                switch (actionType.ToLower().Trim())
                {
                case "delete":
                    if (oldGs == null)
                    {
                        throw new ResourceReportException(String4Report.GetString("U8.UAP.Services.ReportData.ReportDataFacade.Delete.Ex", login.LocaleID));    //"没有权限"
                        //throw new Exception(String4Report.GetString("操作失败,别人已经删除"));
                    }
                    haveSaveCrossSchemas.Remove(oldGs);
                    break;

                case "add":
                    if (HaveSameName(haveSaveCrossSchemas, cs))
                    {
                        throw new ResourceReportException(String4Report.GetString("U8.UAP.Services.ReportData.ReportDataFacade.Add.Ex", login.LocaleID));
                        //throw new Exception(String4Report.GetString("存在重名的分组/交叉,请再次打开报表后更改"));
                    }
                    cs.GuidVersion = Guid.NewGuid().ToString();
                    haveSaveCrossSchemas.Add(cs);
                    SetOtherSchemaBDefault(haveSaveCrossSchemas, cs);
                    break;

                case "modify":
                    if (oldGs == null)
                    {
                        throw new ResourceReportException(String4Report.GetString("U8.UAP.Services.ReportData.ReportDataFacade.Delete.Ex", login.LocaleID));    //"没有权限"
                        //throw new Exception(String4Report.GetString("操作失败,别人已经删除"));
                    }
                    //表明同一个用户在操作,不校验并发
                    if (string.IsNullOrEmpty(oldGs.LastUserGuid) || oldGs.LastUserGuid == cs.LastUserGuid)
                    {
                        if (HaveSameName(haveSaveCrossSchemas, cs))
                        {
                            throw new ResourceReportException(String4Report.GetString("U8.UAP.Services.ReportData.ReportDataFacade.Modify.Ex2", login.LocaleID));
                            //throw new Exception(String4Report.GetString("存在重名的分组/交叉,请再次打开报表后更改"));
                        }
                        haveSaveCrossSchemas.Remove(oldGs);
                        cs.GuidVersion = Guid.NewGuid().ToString();
                        haveSaveCrossSchemas.Add(cs);
                        SetOtherSchemaBDefault(haveSaveCrossSchemas, cs);
                    }
                    //表明同一个用户在操作,不校验并发
                    else
                    {
                        if (oldGs.GuidVersion == cs.GuidVersion)
                        {
                            if (HaveSameName(haveSaveCrossSchemas, cs))
                            {
                                throw new ResourceReportException(String4Report.GetString("U8.UAP.Services.ReportData.ReportDataFacade.Modify.Ex2", login.LocaleID));
                                //throw new Exception(String4Report.GetString("存在重名的分组/交叉,请再次打开报表后更改"));
                            }
                            haveSaveCrossSchemas.Remove(oldGs);
                            cs.GuidVersion = Guid.NewGuid().ToString();
                            haveSaveCrossSchemas.Add(cs);
                            SetOtherSchemaBDefault(haveSaveCrossSchemas, cs);
                        }
                        else
                        {
                            throw new ResourceReportException(String4Report.GetString("U8.UAP.Services.ReportData.ReportDataFacade.Modify.Ex3", login.LocaleID));
                            //throw new Exception(String4Report.GetString("操作失败,别人已经修改"));
                        }
                    }
                    break;

                default:
                    break;
                }
                result = haveSaveCrossSchemas.ToXml().InnerXml;
                string     sql     = "UPDATE UAP_ReportView SET PreservedField = @CrossSchemas WHERE ID=@ViewID";
                SqlCommand command = new SqlCommand(sql, cnn);
                command.Parameters.Add(new SqlParameter("CrossSchemas", result));
                command.Parameters.Add(new SqlParameter("ViewID", viewID));

                SqlHelper.ExecuteNonQuery(tran, command);
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw e;
            }
            finally
            {
                if (cnn.State == ConnectionState.Open)
                {
                    cnn.Close();
                }
            }
            return(result);
        }
        private static void SetGroupSchemaProperty(
            string localeid,
            GroupSchema gs,
            XmlElement groupSchemaElement)
        {
            gs.ID       = GroupSchemas.GetAtrribute(groupSchemaElement, GroupSchemas._xmlKeyID);
            gs.bDefault = Boolean.Parse(GroupSchemas.GetAtrribute(
                                            groupSchemaElement,
                                            GroupSchemas._xmlKeybDefault,
                                            "False"));
            string s = GroupSchemas.GetAtrribute(
                groupSchemaElement,
                GroupSchemas._xmlKeybShowDetial,
                "False");

            if (s == "1")
            {
                s = "True";
            }
            else if (s == "0")
            {
                s = "False";
            }
            gs.bShowDetail = Boolean.Parse(s);
            //添加是否显示小计
            string showSubTotal = GroupSchemas.GetAtrribute(
                groupSchemaElement,
                GroupSchemas._xmlKeyIsShowSubTotal);
            bool bShowSubTotal = false;

            if (!string.IsNullOrEmpty(showSubTotal))
            {
                if (showSubTotal.ToLower() == "true")
                {
                    bShowSubTotal = true;
                }
            }

            gs.bShowSubTotal    = bShowSubTotal;
            gs.bGroupItemsAhead = Boolean.Parse(GroupSchemas.GetAtrribute(
                                                    groupSchemaElement,
                                                    GroupSchemas._xmlKeybGroupItemsAhead,
                                                    "True"));
            int showStyle = Convert.ToInt32(GroupSchemas.GetAtrribute(
                                                groupSchemaElement,
                                                GroupSchemas._xmlKeyShowStyle,
                                                "2"));

            gs.ShowStyle = (ShowStyle)showStyle;
            if (gs.ShowStyle == ShowStyle.NoGroupSummary) //折叠展现默认显示小计,即折叠的一级元素
            {
                gs.bShowSubTotal = true;
            }
            gs.SwitchItem = GroupSchemas.GetAtrribute(
                groupSchemaElement,
                GroupSchemas._xmlKeySwitchItem,
                "");
            //modifytime赋值
            gs.GuidVersion = GroupSchemas.GetAtrribute(
                groupSchemaElement,
                GroupSchemas._xmlKeyVersion,
                "");
            gs.LastUserGuid = GroupSchemas.GetAtrribute(
                groupSchemaElement,
                GroupSchemas._xmlKeyLastUserGuid,
                "");
            gs.bShowCrossNullColumn = Boolean.Parse(GroupSchemas.GetAtrribute(
                                                        groupSchemaElement,
                                                        GroupSchemas._xmlKeyShowNullCrossColumn,
                                                        "True"));
            gs.BShowHorizonTotal = Boolean.Parse(GroupSchemas.GetAtrribute(
                                                     groupSchemaElement,
                                                     GroupSchemas._xmlKeyBShowHorizonTotal,
                                                     "True"));
        }