1

标题听起来很拗口,所以让我试着解释一下。我非常擅长开发 Web 表单,这是我使用框架和 MVC 的第二次尝试(不要问第一个)。从这样的表开始:

Title: Milestones
Id int - Auto, PK
Project_Id int - FK, 许多里程碑到一个项目,暂时提供静态
Number int
Name varchar(50)
Status_Id int - FK 一个状态到一个里程碑
PlannedDate date
LatestEstimate date
MilestoneType_ID int - FK 一种类型到一个里程碑

这些都位于 SQL 服务器上,由实体拉入,然后由 ObjectDataSource 拉入,如下所示:

    <asp:ObjectDataSource runat="server" ID="MilestonesObjectSource" SelectMethod="GetByProject"
        DeleteMethod="DeleteMilestone" TypeName="TCProjectManagement.Models.MilestonesAddition">
        <SelectParameters>
            <asp:Parameter DefaultValue="6" Name="ProjectID" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Type="Int32" Name="Id" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Type="Int32" Name="Id" />
            <asp:Parameter Type="Int32" Name="Number" />
            <asp:Parameter Type="String" Name="Name" />
            <asp:Parameter Type="Int32" Name="Status_Id" />
            <asp:Parameter Type="DateTime" Name="PlannedDate" />
            <asp:Parameter Type="DateTime" Name="LatestEstimate" />
            <asp:Parameter Type="Int32" Name="MilestoneType_ID" />
        </UpdateParameters>
    </asp:ObjectDataSource>

到目前为止,一切都很好。数据拉取似乎没问题。我还有几个专门处理外键的对象源,所以我会跳过那些,因为它们似乎在工作。

我遇到的问题是试图将许多似乎不太协调的例子拼接在一起。我的目标,没有特别的顺序:

1) Pin Editing:点击按钮进行编辑,再次点击确认。与其让某人推断双击以进行更改,不如这样做。到目前为止,这种方法是有效的。
2) 外键下拉菜单:当不在编辑模式时,应显示外键的“名称”字段。在编辑时,它应该是一个下拉选项(只有三个)。尽管我做了什么,这仍然是空白。
3) 删除:按一个按钮删除一行。我把按钮放在那里,但它是用于编辑的 JS 的副本。我需要用什么来删除它?
4)日期:这根本不起作用。奇怪的部分之一是,从 SQL 服务器的 Date 类型,它在实体中更改为 DateTime 并始终保持这种状态。但是,我无法获得所需的 ext:DateField 控制来与提供的数据合作,因为它显示时间并且在编辑时完全空白。我知道我在这里做错了。
5)保存更改:不太确定我是否设置正确(或根本不正确)。

Javascript的规定:

<script type="text/javascript">
            var pinEditors = function (btn, pressed) {
                var columnConfig = btn.column,
                column = columnConfig.column;

                if (pressed) {
                    column.pinOverComponent();
                    column.showComponent(columnConfig.record, true);
                } else {
                    column.unpinOverComponent();
                    column.hideComponent(true);
                }
            };
            var pinDeleters = function (btn, pressed) { };
        </script>

和 ASP 代码:

    <ext:GridPanel ID="MilestonesGridPanel" runat="server" Title="Milestones" Width="1000px"
        Height="300px">
        <Store>
            <ext:Store ID="MilestonesGridStore" runat="server" DataSourceID="MilestonesObjectSource">
                <Model>
                    <ext:Model runat="server" IDProperty="Id">
                        <Fields>
                            <ext:ModelField Name="Id" Type="Int" />
                            <ext:ModelField Name="Number" Type="Int" />
                            <ext:ModelField Name="Name" Type="String" />
                            <ext:ModelField Name="Status_Id" Type="Int" />
                            <ext:ModelField Name="PlannedDate" />
                            <ext:ModelField Name="LatestEstimate" />
                            <ext:ModelField Name="MilestoneType_ID" Type="Int" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </Store>
        <ColumnModel>
            <Columns>
                <ext:Column ID="IdColumn" runat="server" DataIndex="Id" Text="DBID" Visible="false" />
                <ext:ComponentColumn ID="NumberColumn" runat="server" DataIndex="Number" OverOnly="true"
                    Pin="true" Flex="1" Text="Number" Editor="true">
                    <Component>
                        <ext:NumberField ID="NumberColumnNumberField" runat="server" />
                    </Component>
                </ext:ComponentColumn>
                <ext:ComponentColumn ID="NameColumn" runat="server" DataIndex="Name" OverOnly="true"
                    Pin="true" Flex="1" Text="Name" Editor="true">
                    <Component>
                        <ext:TextField ID="NameColumnTextField" runat="server" />
                    </Component>
                </ext:ComponentColumn>
                <ext:ComponentColumn ID="StatusColumn" runat="server" DataIndex="Status_Id" OverOnly="true"
                    Pin="true" Flex="1" Text="Status" Editor="true">
                    <Component>
                        <ext:ComboBox ID="StatusColumnDropDownBox" runat="server" QueryMode="Local" Editable="false"
                            StoreID="MilestoneStatusStore" DisplayField="Name" ValueField="ID" EmptyText="Empty" />
                    </Component>
                </ext:ComponentColumn>
                <ext:ComponentColumn ID="PlannedDateColumn" runat="server" DataIndex="PlannedDate"
                    OverOnly="true" Pin="true" Flex="1" Text="Planned Date" Editor="true">
                    <Renderer Format="Date" FormatArgs="'m/d/y'" />
                    <Component>
                        <ext:DateField ID="PlannedDateColumnTextField" runat="server" Format="MM/dd/yyyy"
                            EmptyText="Empty" />
                    </Component>
                </ext:ComponentColumn>
                <ext:ComponentColumn ID="LatestEstimateColumn" runat="server" DataIndex="LatestEstimate"
                    OverOnly="true" Pin="true" Flex="1" Text="Latest ETA" Editor="true">
                    <Renderer Format="Date" FormatArgs="'m/d/y'" />
                    <Component>
                        <ext:DateField ID="LatestEstimateColumnTextField" runat="server" Format="MM/dd/yyyy"
                            EmptyText="Empty" />
                    </Component>
                </ext:ComponentColumn>
                <ext:ComponentColumn ID="MilestoneTypeColumn" runat="server" DataIndex="MilestoneType_ID"
                    OverOnly="true" Pin="true" Flex="1" Text="Milestone Type" Editor="true">
                    <Component>
                        <ext:ComboBox ID="MilestoneTypeColumnComboBox" runat="server" QueryMode="Local" Editable="false"
                            StoreID="MilestoneTypesStore" DisplayField="Name" ValueField="ID" EmptyText="Empty" />
                    </Component>
                </ext:ComponentColumn>
                <ext:ComponentColumn ID="EditColumn" runat="server" Width="30" PinAllColumns="false"
                    AutoWidthComponent="false" OverOnly="true" Text="Edit" Sortable="False">
                    <Component>
                        <ext:Button ID="EditButton" runat="server" ToolTip="Pin Editors" Icon="Pencil" AllowDepress="true"
                            EnableToggle="true" Width="25">
                            <Listeners>
                                <Toggle Fn="pinEditors" />
                            </Listeners>
                        </ext:Button>
                    </Component>
                </ext:ComponentColumn>
                <ext:ComponentColumn ID="DeleteColumn" runat="server" Width="30" PinAllColumns="false"
                    AutoWidthComponent="false" OverOnly="true" Text="Delete" Sortable="False">
                    <Component>
                        <ext:Button ID="DeleteButton" runat="server" ToolTip="Delete Milestone" Icon="Delete"
                            AllowDepress="true" EnableToggle="false" Width="25">
                            <Listeners>
                                <Click Handler="#{MilestonesGridStore}.remove(this.parentMenu.dataRecord)" />
                            </Listeners>
                        </ext:Button>
                    </Component>
                </ext:ComponentColumn>
            </Columns>
        </ColumnModel>
        <SelectionModel>
            <ext:RowSelectionModel runat="server" Mode="Single">
                <Listeners>
                    <Select Handler="#{DeleteMilestoneGridButton}.enable();" />
                    <Deselect Handler="if (!#{MilestonesGridPanel}.selModel.hasSelection()) { 
                                #{DeleteMilestoneGridButton}.disable();
                                       }" />
                </Listeners>
            </ext:RowSelectionModel>
        </SelectionModel>
        <Buttons>
            <ext:Button ID="AddtoMilestoneGridButton" runat="server" Text="Insert" Icon="Add">
                <Listeners>
                    <Click Handler="#{MilestonesGridStore}.insert(0, {}); #{MilestonesGridPanel}.editingPlugin.startEditByPosition({row:0, column:0});" />
                </Listeners>
            </ext:Button>
            <ext:Button ID="DeleteMilestoneGridButton" runat="server" Text="Delete" Icon="Delete"
                Disabled="true">
                <Listeners>
                    <Click Handler="#{MilestonesGridPanel}.deleteSelected();
                                    if (!#{MilestonesGridPanel}.hasSelection()) {
                                        #{DeleteMilestoneGridButton}.disable();
                                    }" />
                </Listeners>
            </ext:Button>
            <ext:Button ID="RefreshMilestonesGridButton" runat="server" Text="RefresH" Icon="Reload">
                <Listeners>
                    <Click Handler="#{MilestonesGridStore}.load();" />
                </Listeners>
            </ext:Button>
            <ext:Button ID="SaveMilestoneGridButton" runat="server" Text="Save" Icon="Disk">
                <Listeners>
                    <Click Handler="#{MilestonesGridStore}.sync();" />
                </Listeners>
            </ext:Button>
        </Buttons>
    </ext:GridPanel>
4

0 回答 0