Beispiel #1
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);
        }
 private static string GetAtrribute(
     XmlElement ele,
     string atrrName)
 {
     return(GroupSchemas.GetAtrribute(ele, atrrName, string.Empty));
 }
        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"));
        }