Ejemplo n.º 1
0
        public string Data(
            Context context,
            SiteSettings ss,
            DeptModel deptModel)
        {
            var column = ss.GetColumn(
                context: context,
                columnName: From);

            if (column?.CanRead(
                    context: context,
                    ss: ss,
                    mine: deptModel.Mine(context: context)) == true)
            {
                switch (column.ColumnName)
                {
                case "TenantId":
                    return(deptModel.TenantId.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "DeptId":
                    return(deptModel.DeptId.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Ver":
                    return(deptModel.Ver.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "DeptCode":
                    return(deptModel.DeptCode.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Dept":
                    return(deptModel.Dept.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "DeptName":
                    return(deptModel.DeptName.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Body":
                    return(deptModel.Body.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Title":
                    return(deptModel.Title.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Disabled":
                    return(deptModel.Disabled.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Comments":
                    return(deptModel.Comments.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Creator":
                    return(deptModel.Creator.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Updator":
                    return(deptModel.Updator.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "CreatedTime":
                    return(deptModel.CreatedTime.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "UpdatedTime":
                    return(deptModel.UpdatedTime.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "VerUp":
                    return(deptModel.VerUp.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                case "Timestamp":
                    return(deptModel.Timestamp.ToLookup(
                               context: context,
                               ss: ss,
                               column: column,
                               type: Type));

                default:
                    switch (Def.ExtendedColumnTypes.Get(column.Name))
                    {
                    case "Class":
                        return(deptModel.GetClass(column: column).ToLookup(
                                   context: context,
                                   ss: ss,
                                   column: column,
                                   type: Type));

                    case "Num":
                        return(deptModel.GetNum(column: column).ToLookup(
                                   context: context,
                                   ss: ss,
                                   column: column,
                                   type: Type));

                    case "Date":
                        return(deptModel.GetDate(column: column).ToLookup(
                                   context: context,
                                   ss: ss,
                                   column: column,
                                   type: Type));

                    case "Description":
                        return(deptModel.GetDescription(column: column).ToLookup(
                                   context: context,
                                   ss: ss,
                                   column: column,
                                   type: Type));

                    case "Check":
                        return(deptModel.GetCheck(column: column).ToLookup(
                                   context: context,
                                   ss: ss,
                                   column: column,
                                   type: Type));

                    case "Attachments":
                        return(deptModel.GetAttachments(column: column).ToLookup(
                                   context: context,
                                   ss: ss,
                                   column: column,
                                   type: Type));

                    default:
                        return(string.Empty);
                    }
                }
            }
            return(string.Empty);
        }
Ejemplo n.º 2
0
        public static HtmlBuilder Tr(
            this HtmlBuilder hb,
            Context context,
            SiteSettings ss,
            DataRow dataRow,
            IEnumerable <Column> columns,
            bool editRow,
            bool checkRow,
            string idColumn,
            RecordSelector recordSelector = null,
            FormDataSet formDataSet       = null)
        {
            var dataId      = dataRow.Long(idColumn);
            var dataVersion = dataRow.Int("Ver");
            var isHistory   = dataRow.Bool("IsHistory");
            var EditColumns = !isHistory
                ? columns.ToDictionary(
                column => column.ColumnName,
                column => EditColumn(
                    context: context,
                    column: column))
                : new Dictionary <string, bool>();

            BaseItemModel rowModel = null;

            switch (ss.ReferenceType)
            {
            case "Issues":
                var issueModel = new IssueModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow,
                    formData: editRow
                            ? formDataSet?.FirstOrDefault(o =>
                                                          o.Id == dataRow.Long("IssueId"))?.Data
                            : null);
                ss.SetColumnAccessControls(
                    context: context,
                    mine: issueModel.Mine(context: context));
                rowModel = issueModel;
                break;

            case "Results":
                var resultModel = new ResultModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow,
                    formData: editRow
                            ? formDataSet?.FirstOrDefault(o =>
                                                          o.Id == dataRow.Long("ResultId"))?.Data
                            : null);
                ss.SetColumnAccessControls(
                    context: context,
                    mine: resultModel.Mine(context: context));
                rowModel = resultModel;
                break;
            }
            ;
            var serverScriptRowValues = rowModel?.SetByBeforeOpeningPageServerScript(
                context: context,
                ss: ss);
            var extendedRowCss = serverScriptRowValues?.ExtendedRowCss;

            extendedRowCss = extendedRowCss.IsNullOrEmpty() ? string.Empty : " " + extendedRowCss;
            return(hb.Tr(
                       attributes: new HtmlAttributes()
                       .Class("grid-row" + extendedRowCss)
                       .DataId(dataId.ToString())
                       .DataVer(dataVersion)
                       .DataLatest(1, _using: !isHistory)
                       .Add(name: "data-history", value: "1", _using: isHistory)
                       .Add(name: "data-locked", value: "1", _using: dataRow.Bool("Locked")),
                       action: () =>
            {
                if (editRow)
                {
                    hb.Td(action: () => hb
                          .Button(
                              title: Displays.Reload(context: context),
                              controlCss: "button-icon",
                              onClick: $"$p.getData($(this)).Id={dataId};$p.send($(this));",
                              icon: "ui-icon-refresh",
                              action: "ReloadRow",
                              method: "post",
                              _using: !isHistory)
                          .Button(
                              title: Displays.Copy(context: context),
                              controlCss: "button-icon",
                              onClick: $"$p.getData($(this)).OriginalId={dataId};$p.send($(this));",
                              icon: "ui-icon-copy",
                              action: "CopyRow",
                              method: "post",
                              _using: !isHistory && context.CanCreate(ss: ss))
                          .Hidden(
                              controlId: $"{ss.ReferenceType}_Timestamp_{ss.SiteId}_{dataId}",
                              css: "timestamp",
                              value: dataRow
                              .Field <DateTime>("UpdatedTime")
                              .ToString("yyyy/M/d H:m:s.fff")));
                }
                else if (checkRow)
                {
                    hb.Td(action: () => hb
                          .CheckBox(
                              controlCss: "grid-check",
                              _checked: recordSelector.Checked(dataId),
                              dataId: dataId.ToString(),
                              _using: !isHistory));
                }
                var depts = new Dictionary <string, DeptModel>();
                var groups = new Dictionary <string, GroupModel>();
                var registrations = new Dictionary <string, RegistrationModel>();
                var users = new Dictionary <string, UserModel>();
                var sites = new Dictionary <string, SiteModel>();
                var issues = new Dictionary <string, IssueModel>();
                var results = new Dictionary <string, ResultModel>();
                ServerScriptModelRow serverScriptValues = null;
                columns.ForEach(column =>
                {
                    var key = column.TableName();
                    switch (column.SiteSettings?.ReferenceType)
                    {
                    case "Depts":
                        var deptModel = depts.Get(key);
                        if (deptModel == null)
                        {
                            deptModel = new DeptModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            depts.Add(key, deptModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: deptModel.Mine(context: context));
                            serverScriptValues = deptModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            deptModel: deptModel);
                        break;

                    case "Groups":
                        var groupModel = groups.Get(key);
                        if (groupModel == null)
                        {
                            groupModel = new GroupModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            groups.Add(key, groupModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: groupModel.Mine(context: context));
                            serverScriptValues = groupModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            groupModel: groupModel);
                        break;

                    case "Registrations":
                        var registrationModel = registrations.Get(key);
                        if (registrationModel == null)
                        {
                            registrationModel = new RegistrationModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            registrations.Add(key, registrationModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: registrationModel.Mine(context: context));
                            serverScriptValues = registrationModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            registrationModel: registrationModel);
                        break;

                    case "Users":
                        var userModel = users.Get(key);
                        if (userModel == null)
                        {
                            userModel = new UserModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            users.Add(key, userModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: userModel.Mine(context: context));
                            serverScriptValues = userModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            userModel: userModel);
                        break;

                    case "Sites":
                        var siteModel = sites.Get(key);
                        if (siteModel == null)
                        {
                            siteModel = new SiteModel(
                                context: context,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("SiteId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            sites.Add(key, siteModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: siteModel.Mine(context: context));
                            serverScriptValues = siteModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            siteModel: siteModel);
                        break;

                    case "Issues":
                        var issueModel = issues.Get(key);
                        if (issueModel == null)
                        {
                            issueModel = new IssueModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("IssueId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            issues.Add(key, issueModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: issueModel.Mine(context: context));
                            serverScriptValues = issueModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        if (!issueModel.Locked && EditColumns.Get(column.ColumnName) && column.CanUpdate(baseModel: issueModel))
                        {
                            hb.Td(
                                css: column.TextAlign == SiteSettings.TextAlignTypes.Right
                                            ? " right-align"
                                            : string.Empty,
                                action: () => hb.Field(
                                    context: context,
                                    column: column,
                                    issueModel: issueModel,
                                    ss: column.SiteSettings,
                                    controlOnly: true,
                                    idSuffix: issueModel.IdSuffix()));
                        }
                        else
                        {
                            hb.TdValue(
                                context: context,
                                ss: column.SiteSettings,
                                column: column,
                                issueModel: issueModel,
                                serverScriptValues: serverScriptValues
                                ?.Columns
                                ?.Get(column?.ColumnName));
                        }
                        break;

                    case "Results":
                        var resultModel = results.Get(key);
                        if (resultModel == null)
                        {
                            resultModel = new ResultModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("ResultId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            results.Add(key, resultModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: resultModel.Mine(context: context));
                            serverScriptValues = resultModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        if (!resultModel.Locked && EditColumns.Get(column.ColumnName) && column.CanUpdate(baseModel: resultModel))
                        {
                            hb.Td(
                                css: column.TextAlign == SiteSettings.TextAlignTypes.Right
                                            ? " right-align"
                                            : string.Empty,
                                action: () => hb.Field(
                                    context: context,
                                    column: column,
                                    resultModel: resultModel,
                                    ss: column.SiteSettings,
                                    controlOnly: true,
                                    idSuffix: resultModel.IdSuffix()));
                        }
                        else
                        {
                            hb.TdValue(
                                context: context,
                                ss: column.SiteSettings,
                                column: column,
                                resultModel: resultModel,
                                serverScriptValues: serverScriptValues
                                ?.Columns
                                ?.Get(column?.ColumnName));
                        }
                        break;
                    }
                });
            }));
        }
Ejemplo n.º 3
0
        private string SearchFormatText(Context context, SiteSettings ss, DataRow dataRow)
        {
            var text = SearchFormat;

            switch (ss.ReferenceType)
            {
            case "Depts":
                var deptModel = new DeptModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow);
                var deptMine = deptModel.Mine(context: context);
                ss.IncludedColumns(SearchFormat)
                .Where(column => column.CanRead(
                           context: context,
                           ss: ss,
                           mine: null))
                .ForEach(column =>
                         text = text.Replace(
                             $@"[{column.ColumnName}]",
                             $@"{deptModel.ToDisplay(
                                    context: context,
                                    ss: ss,
                                    column: column,
                                    mine: deptMine)}"));
                break;

            case "Groups":
                var groupModel = new GroupModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow);
                var groupMine = groupModel.Mine(context: context);
                ss.IncludedColumns(SearchFormat)
                .Where(column => column.CanRead(
                           context: context,
                           ss: ss,
                           mine: null))
                .ForEach(column =>
                         text = text.Replace(
                             $@"[{column.ColumnName}]",
                             $@"{groupModel.ToDisplay(
                                    context: context,
                                    ss: ss,
                                    column: column,
                                    mine: groupMine)}"));
                break;

            case "Users":
                var userModel = new UserModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow);
                var userMine = userModel.Mine(context: context);
                ss.IncludedColumns(SearchFormat)
                .Where(column => column.CanRead(
                           context: context,
                           ss: ss,
                           mine: null))
                .ForEach(column =>
                         text = text.Replace(
                             $@"[{column.ColumnName}]",
                             $@"{userModel.ToDisplay(
                                    context: context,
                                    ss: ss,
                                    column: column,
                                    mine: userMine)}"));
                break;

            case "Issues":
                var issueModel = new IssueModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow);
                var issueMine = issueModel.Mine(context: context);
                ss.IncludedColumns(SearchFormat)
                .Where(column => column.CanRead(
                           context: context,
                           ss: ss,
                           mine: null))
                .ForEach(column =>
                         text = text.Replace(
                             $@"[{column.ColumnName}]",
                             $@"{issueModel.ToDisplay(
                                    context: context,
                                    ss: ss,
                                    column: column,
                                    mine: issueMine)}"));
                break;

            case "Results":
                var resultModel = new ResultModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow);
                var resultMine = resultModel.Mine(context: context);
                ss.IncludedColumns(SearchFormat)
                .Where(column => column.CanRead(
                           context: context,
                           ss: ss,
                           mine: null))
                .ForEach(column =>
                         text = text.Replace(
                             $@"[{column.ColumnName}]",
                             $@"{resultModel.ToDisplay(
                                    context: context,
                                    ss: ss,
                                    column: column,
                                    mine: resultMine)}"));
                break;
            }
            return(text);
        }