Пример #1
0
        public static string Editor(SiteSettings ss, DeptModel deptModel)
        {
            var invalid = DeptValidators.OnEditing(ss, deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(HtmlTemplates.Error(invalid));
            }
            var hb = new HtmlBuilder();

            ss.SetColumnAccessControls(deptModel.Mine());
            return(hb.Template(
                       ss: ss,
                       verType: deptModel.VerType,
                       methodType: deptModel.MethodType,
                       referenceType: "Depts",
                       title: deptModel.MethodType == BaseModel.MethodTypes.New
                    ? Displays.Depts() + " - " + Displays.New()
                    : deptModel.Title.Value,
                       action: () =>
            {
                hb
                .Editor(
                    ss: ss,
                    deptModel: deptModel)
                .Hidden(controlId: "TableName", value: "Depts")
                .Hidden(controlId: "Id", value: deptModel.DeptId.ToString());
            }).ToString());
        }
Пример #2
0
        public static string Histories(
            SiteSettings ss, int deptId, Message message = null)
        {
            var deptModel = new DeptModel(ss, deptId);

            ss.SetColumnAccessControls(deptModel.Mine());
            var columns = ss.GetHistoryColumns(checkPermission: true);

            if (!ss.CanRead())
            {
                return(Error.Types.HasNotPermission.MessageJson());
            }
            var hb = new HtmlBuilder();

            hb
            .HistoryCommands(ss: ss)
            .Table(
                attributes: new HtmlAttributes().Class("grid history"),
                action: () => hb
                .THead(action: () => hb
                       .GridHeader(
                           columns: columns,
                           sort: false,
                           checkRow: true))
                .TBody(action: () => hb
                       .HistoriesTableBody(
                           ss: ss,
                           columns: columns,
                           deptModel: deptModel)));
            return(new DeptsResponseCollection(deptModel)
                   .Html("#FieldSetHistories", hb)
                   .Message(message)
                   .ToJson());
        }
Пример #3
0
        private static HtmlBuilder FieldSetGeneral(
            this HtmlBuilder hb,
            SiteSettings ss,
            DeptModel deptModel)
        {
            var mine = deptModel.Mine();

            return(hb.FieldSet(id: "FieldSetGeneral", action: () => hb
                               .FieldSetGeneralColumns(
                                   ss: ss, deptModel: deptModel)));
        }
Пример #4
0
        public static Error.Types OnCreating(SiteSettings ss, DeptModel deptModel)
        {
            if (!ss.CanCreate())
            {
                return(Error.Types.HasNotPermission);
            }
            ss.SetColumnAccessControls(deptModel.Mine());
            foreach (var column in ss.Columns
                     .Where(o => !o.CanCreate)
                     .Where(o => !ss.FormulaTarget(o.ColumnName))
                     .Where(o => !o.Linking))
            {
                switch (column.ColumnName)
                {
                case "DeptCode":
                    if (deptModel.DeptCode_Updated() &&
                        (column.DefaultInput.IsNullOrEmpty() ||
                         column.DefaultInput.ToString() != deptModel.DeptCode))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "DeptName":
                    if (deptModel.DeptName_Updated() &&
                        (column.DefaultInput.IsNullOrEmpty() ||
                         column.DefaultInput.ToString() != deptModel.DeptName))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Body":
                    if (deptModel.Body_Updated() &&
                        (column.DefaultInput.IsNullOrEmpty() ||
                         column.DefaultInput.ToString() != deptModel.Body))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn("Comments").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;
                }
            }
            return(Error.Types.None);
        }
Пример #5
0
        public static Error.Types OnCreating(
            IContext context, SiteSettings ss, DeptModel deptModel, bool api = false)
        {
            if (api && (context.ContractSettings.Api == false || !Parameters.Api.Enabled))
            {
                return(Error.Types.InvalidRequest);
            }
            if (!context.CanCreate(ss: ss))
            {
                return(Error.Types.HasNotPermission);
            }
            ss.SetColumnAccessControls(context: context, mine: deptModel.Mine(context: context));
            foreach (var column in ss.Columns
                     .Where(o => !o.CanCreate)
                     .Where(o => !ss.FormulaTarget(o.ColumnName))
                     .Where(o => !o.Linking))
            {
                switch (column.ColumnName)
                {
                case "DeptCode":
                    if (deptModel.DeptCode_Updated(context: context, column: column))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "DeptName":
                    if (deptModel.DeptName_Updated(context: context, column: column))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Body":
                    if (deptModel.Body_Updated(context: context, column: column))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn(context: context, columnName: "Comments").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;
                }
            }
            return(Error.Types.None);
        }
Пример #6
0
        public static string History(SiteSettings ss, int deptId)
        {
            var deptModel = new DeptModel(ss, deptId);

            ss.SetColumnAccessControls(deptModel.Mine());
            deptModel.Get(
                ss,
                where : Rds.DeptsWhere()
                .DeptId(deptModel.DeptId)
                .Ver(Forms.Int("Ver")),
                tableType: Sqls.TableTypes.NormalAndHistory);
            deptModel.VerType = Forms.Bool("Latest")
                ? Versions.VerTypes.Latest
                : Versions.VerTypes.History;
            return(EditorResponse(ss, deptModel).ToJson());
        }
Пример #7
0
        public static string Histories(SiteSettings ss, int deptId)
        {
            var deptModel = new DeptModel(ss, deptId);

            ss.SetColumnAccessControls(deptModel.Mine());
            var columns = ss.GetHistoryColumns(checkPermission: true);

            if (!ss.CanRead())
            {
                return(Error.Types.HasNotPermission.MessageJson());
            }
            var hb = new HtmlBuilder();

            hb.Table(
                attributes: new HtmlAttributes().Class("grid"),
                action: () => hb
                .THead(action: () => hb
                       .GridHeader(
                           columns: columns,
                           sort: false,
                           checkRow: false))
                .TBody(action: () =>
                       new DeptCollection(
                           ss: ss,
                           column: HistoryColumn(columns),
                           where : Rds.DeptsWhere().DeptId(deptModel.DeptId),
                           orderBy: Rds.DeptsOrderBy().Ver(SqlOrderBy.Types.desc),
                           tableType: Sqls.TableTypes.NormalAndHistory)
                       .ForEach(deptModelHistory => hb
                                .Tr(
                                    attributes: new HtmlAttributes()
                                    .Class("grid-row history not-link")
                                    .DataAction("History")
                                    .DataMethod("post")
                                    .DataVer(deptModelHistory.Ver)
                                    .DataLatest(1, _using:
                                                deptModelHistory.Ver == deptModel.Ver),
                                    action: () => columns
                                    .ForEach(column => hb
                                             .TdValue(
                                                 ss: ss,
                                                 column: column,
                                                 deptModel: deptModelHistory))))));
            return(new DeptsResponseCollection(deptModel)
                   .Html("#FieldSetHistories", hb).ToJson());
        }
Пример #8
0
        public static Error.Types OnUpdating(SiteSettings ss, DeptModel deptModel)
        {
            if (!ss.CanUpdate())
            {
                return(Error.Types.HasNotPermission);
            }
            ss.SetColumnAccessControls(deptModel.Mine());
            foreach (var controlId in Forms.Keys())
            {
                switch (controlId)
                {
                case "Depts_DeptCode":
                    if (deptModel.DeptCode_Updated &&
                        !ss.GetColumn("DeptCode").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Depts_DeptName":
                    if (deptModel.DeptName_Updated &&
                        !ss.GetColumn("DeptName").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Depts_Body":
                    if (deptModel.Body_Updated &&
                        !ss.GetColumn("Body").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn("Comments").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;
                }
            }
            return(Error.Types.None);
        }
Пример #9
0
        public static Error.Types OnUpdating(
            Context context, SiteSettings ss, DeptModel deptModel)
        {
            if (!context.CanUpdate(ss: ss))
            {
                return(Error.Types.HasNotPermission);
            }
            ss.SetColumnAccessControls(context: context, mine: deptModel.Mine(context: context));
            foreach (var column in ss.Columns
                     .Where(o => !o.CanUpdate)
                     .Where(o => !ss.FormulaTarget(o.ColumnName)))
            {
                switch (column.ColumnName)
                {
                case "DeptCode":
                    if (deptModel.DeptCode_Updated(context: context))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "DeptName":
                    if (deptModel.DeptName_Updated(context: context))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Body":
                    if (deptModel.Body_Updated(context: context))
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn(context: context, columnName: "Comments").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;
                }
            }
            return(Error.Types.None);
        }
        public static ErrorData OnCreating(
            Context context, SiteSettings ss, DeptModel deptModel, bool api = false)
        {
            if (api && (context.ContractSettings.Api == false || !Parameters.Api.Enabled))
            {
                return(new ErrorData(type: Error.Types.InvalidRequest));
            }
            if (!context.CanCreate(ss: ss))
            {
                return(!context.CanRead(ss: ss)
                    ? new ErrorData(type: Error.Types.NotFound)
                    : new ErrorData(type: Error.Types.HasNotPermission));
            }
            ss.SetColumnAccessControls(context: context, mine: deptModel.Mine(context: context));
            foreach (var column in ss.Columns
                     .Where(o => !o.CanCreate)
                     .Where(o => !ss.FormulaTarget(o.ColumnName))
                     .Where(o => !o.Linking))
            {
                switch (column.ColumnName)
                {
                case "DeptCode":
                    if (deptModel.DeptCode_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "DeptName":
                    if (deptModel.DeptName_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Body":
                    if (deptModel.Body_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Comments":
                    if (deptModel.Comments_Updated(context: context))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                default:
                    switch (Def.ExtendedColumnTypes.Get(column.Name))
                    {
                    case "Class":
                        if (deptModel.Class_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Num":
                        if (deptModel.Num_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Date":
                        if (deptModel.Date_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Description":
                        if (deptModel.Description_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Check":
                        if (deptModel.Check_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Attachments":
                        if (deptModel.Attachments_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;
                    }
                    break;
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }
Пример #11
0
        public static HtmlBuilder TdValue(
            this HtmlBuilder hb, SiteSettings ss, Column column, DeptModel deptModel)
        {
            if (!column.GridDesign.IsNullOrEmpty())
            {
                return(hb.TdCustomValue(
                           ss: ss,
                           gridDesign: column.GridDesign,
                           deptModel: deptModel));
            }
            else
            {
                var mine = deptModel.Mine();
                switch (column.Name)
                {
                case "DeptId":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.DeptId)
                            : hb.Td(column: column, value: string.Empty));

                case "Ver":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.Ver)
                            : hb.Td(column: column, value: string.Empty));

                case "DeptCode":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.DeptCode)
                            : hb.Td(column: column, value: string.Empty));

                case "Dept":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.Dept)
                            : hb.Td(column: column, value: string.Empty));

                case "Body":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.Body)
                            : hb.Td(column: column, value: string.Empty));

                case "Comments":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.Comments)
                            : hb.Td(column: column, value: string.Empty));

                case "Creator":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.Creator)
                            : hb.Td(column: column, value: string.Empty));

                case "Updator":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.Updator)
                            : hb.Td(column: column, value: string.Empty));

                case "CreatedTime":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.CreatedTime)
                            : hb.Td(column: column, value: string.Empty));

                case "UpdatedTime":
                    return(ss.ReadColumnAccessControls.Allowed(column, ss.PermissionType, mine)
                            ? hb.Td(column: column, value: deptModel.UpdatedTime)
                            : hb.Td(column: column, value: string.Empty));

                default: return(hb);
                }
            }
        }
Пример #12
0
        private static HtmlBuilder FieldSetGeneral(
            this HtmlBuilder hb,
            SiteSettings ss,
            DeptModel deptModel)
        {
            var mine = deptModel.Mine();

            return(hb.FieldSet(id: "FieldSetGeneral", action: () =>
            {
                ss.GetEditorColumns().ForEach(column =>
                {
                    switch (column.ColumnName)
                    {
                    case "DeptId":
                        hb.Field(
                            ss,
                            column,
                            deptModel.MethodType,
                            deptModel.DeptId.ToControl(ss, column),
                            column.ColumnPermissionType());
                        break;

                    case "Ver":
                        hb.Field(
                            ss,
                            column,
                            deptModel.MethodType,
                            deptModel.Ver.ToControl(ss, column),
                            column.ColumnPermissionType());
                        break;

                    case "DeptCode":
                        hb.Field(
                            ss,
                            column,
                            deptModel.MethodType,
                            deptModel.DeptCode.ToControl(ss, column),
                            column.ColumnPermissionType());
                        break;

                    case "DeptName":
                        hb.Field(
                            ss,
                            column,
                            deptModel.MethodType,
                            deptModel.DeptName.ToControl(ss, column),
                            column.ColumnPermissionType());
                        break;

                    case "Body":
                        hb.Field(
                            ss,
                            column,
                            deptModel.MethodType,
                            deptModel.Body.ToControl(ss, column),
                            column.ColumnPermissionType());
                        break;
                    }
                });
                hb.VerUpCheckBox(deptModel);
            }));
        }