Beispiel #1
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);
        }
Beispiel #2
0
        public object Clone()
        {
            GroupSchemas gss = new GroupSchemas();

            foreach (GroupSchema gs in this.InnerList)
            {
                gss.Add(gs.Clone() as GroupSchema);
            }
            return(gss);
        }
Beispiel #3
0
        public static GroupSchemas GetSchemasNoSetDefaultSchema(
            string xml,
            string localeid)
        {
            XmlDocument schemaXmlDoc = null;

            if (!string.IsNullOrEmpty(xml))
            {
                schemaXmlDoc = new XmlDocument();
                schemaXmlDoc.LoadXml(xml);
            }

            GroupSchemas gss = new GroupSchemas(false);

            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 (false)
                {
                    gss.Add(GroupSchemas.GetDefaultCrossSchema());
                }
                else
                {
                    gss.Add(GroupSchemas.GetDefaultGroupSchema());
                }
            }
            return(gss);
        }
        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);
        }