<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

            <script type="text/javascript">
                    function ProcessEditing()
                    {
                      if($find("<%= BusinessGrid.ClientID %>").get_masterTableView().get_selectedItems().length > 0)
                      {
                        return true;
                      }
                      else
                      {
                        alert('You have to select item in the grid for editing');
                        return false;
                      }  
                    }
                    function DeleteProduct()
                    {
                      if($find("<%= BusinessGrid.ClientID %>").get_masterTableView().get_selectedItems().length > 0)
                      {
                        return confirm('Are you sure you want to delete this product');
                      }
                      else
                      {
                        alert('You have to select item in the grid to be deleted');
                        return false;
                      }  
                    }
            </script>

        </telerik:RadCodeBlock>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="DetailsGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="BusinessGrid">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="BusinessGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="DetailsGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="DetailsGrid">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="BusinessGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="DetailsGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px"
            Width="75px" Transparency="55">
            <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>'
                style="border: 0;" />
        </telerik:RadAjaxLoadingPanel>
        <div class="exampleTop">
            <h1>
                Furniture DeTrevi</h1>
        </div>
        <div class="exampleWrap">
            <div class="exampleLeft">
                <img src="Img/gridTop.gif" alt="" style="float: left;" /><div style="clear: both;">
                    <telerik:RadGrid ID="BusinessGrid" runat="server" AutoGenerateColumns="False" GridLines="None"
                        DataSourceID="productsDataSource1" AllowPaging="true" PageSize="4" Width="476px"
                        AllowMultiRowEdit="true" AllowAutomaticDeletes="true" EnableEmbeddedSkins="false"
                        Skin="Business" OnItemCommand="BusinessGrid_ItemCommand">
                        <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top" DataSourceID="productsDataSource1"
                            AllowAutomaticDeletes="true" TableLayout="Fixed">
                            <CommandItemTemplate>
                                <asp:ImageButton ID="btnNew" runat="server" CommandName="AddDetail" CausesValidation="false"
                                    ImageUrl="Img/businessgrid_new.gif" />
                                <asp:ImageButton ID="btnEditProduct" runat="server" CommandName="EditDetail" CausesValidation="false"
                                    ImageUrl="Img/businessgrid_edit.gif" OnClientClick="if (!ProcessEditing()) return false;" />
                                <asp:ImageButton ID="btnDeleteProduct" runat="server" CommandName="DeleteSelected"
                                    OnClientClick="if (!DeleteProduct()) return false;" CausesValidation="false"
                                    ImageUrl="Img/businessgrid_delete.gif" />
                            </CommandItemTemplate>
                            <Columns>
                                <telerik:GridTemplateColumn HeaderText="Photo" UniqueName="TemplateColumn" HeaderStyle-Width="60px">
                                    <ItemTemplate>
                                        <asp:Image ID="ProductImage" runat="server" Width="100%" ImageUrl='<%# (Eval("Name") is System.DBNull)? "Img/ImageNotAvailable.gif" : "Img/" + Eval("Name") %>'
                                            AlternateText="No preview available" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="ProductName" HeaderText="Product name" UniqueName="ProductName" />
                                <telerik:GridBoundColumn DataField="Manufacturer" HeaderText="Manufacturer" UniqueName="Manufacturer" />
                                <telerik:GridTemplateColumn UniqueName="Materials" HeaderText="Materials" HeaderStyle-Width="152px">
                                    <ItemTemplate>
                                        <asp:Literal ID="ltrlFront" runat="server" Text='<%# "<b>Front</b>: " + Eval("Front") + "<br/>" %>' />
                                        <asp:Literal ID="ltrlBack" runat="server" Text='<%# "<b>Back</b>: " + Eval("Back") + "<br/>" %>' />
                                        <asp:Literal ID="ltrlLining" runat="server" Text='<%# "<b>Lining</b>: " + Eval("Lining") + "<br/>" %>' />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="Price" HeaderText="Unit <br/> price" UniqueName="Price"
                                    DataFormatString="{0:$###,###.##}" HeaderStyle-Width="51px" />
                            </Columns>
                        </MasterTableView>
                        <ClientSettings EnablePostBackOnRowClick="true">
                            <Selecting AllowRowSelect="true" />
                        </ClientSettings>
                        <PagerStyle NextPageText="&amp;gt;" PrevPageText="&amp;lt;" Mode="NextPrevAndNumeric">
                        </PagerStyle>
                    </telerik:RadGrid></div>
                <img src="Img/gridBottom.gif" alt="" style="float: left;" />
            </div>
            <div class="exampleRight">
                <div class="rightTop">
                    <!-- -->
                </div>
                <div class="rightMiddle">
                    <div class="productDetails">
                        <telerik:RadGrid ID="DetailsGrid" runat="server" AutoGenerateColumns="False" GridLines="None"
                            DataSourceID="productsDataSource2" ShowHeader="false" AllowAutomaticUpdates="true"
                            Skin="" AllowAutomaticInserts="true" OnItemInserted="DetailsGrid_ItemInserted"
                            OnItemUpdated="DetailsGrid_ItemUpdated" OnPreRender="DetailsGrid_PreRender" OnCancelCommand="DetailsGrid_CancelCommand"
                            OnItemCreated="DetailsGrid_ItemCreated" OnInsertCommand="DetailsGrid_InsertCommand"
                            Width="217px" Style="overflow: hidden;" OnItemCommand="DetailsGrid_ItemCommand">
                            <MasterTableView DataKeyNames="ID" DataSourceID="productsDataSource2" ShowHeader="false"
                                AllowAutomaticUpdates="true" AllowAutomaticInserts="true" Width="219px">
                                <Columns>
                                    <telerik:GridTemplateColumn HeaderText="" UniqueName="TemplateColumn">
                                        <EditItemTemplate>
                                            <div style="height: 67px; margin-top: 45px; margin-bottom: 7px;">
                                                <asp:Image ID="Image1" runat="server" ImageUrl='<%# (Eval("Name") is System.DBNull)? "Img/ImageNotAvailable.gif" : "Img/" + Eval("Name") %>'
                                                    AlternateText="No preview available" Style="margin-left: -35px; position: absolute;" />
                                            </div>
                                        </EditItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="ProductName" HeaderText="Product name" UniqueName="ProductName"
                                        ColumnEditorID="TextEditor" />
                                    <telerik:GridDropDownColumn DataField="Manufacturer" ListTextField="Manufacturer"
                                        ListValueField="Manufacturer" ColumnEditorID="DropDownEditor1" DataSourceID="manufacturerDataSource"
                                        HeaderText="Manufacturer" UniqueName="Manufacturer" DropDownControlType="DropDownList" />
                                    <telerik:GridDropDownColumn DataField="SalesRepresentative" ListTextField="SalesRepresentative"
                                        ColumnEditorID="DropDownEditor2" ListValueField="SalesRepresentative" DataSourceID="salesRepDataSource"
                                        HeaderText="Sales representative" UniqueName="SalesRepresentative" DropDownControlType="DropDownList" />
                                    <telerik:GridTemplateColumn UniqueName="Materials" HeaderText="Materials">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="txtBoxFront" runat="server" Text='<%# Bind("Front") %>' Style="width: 110px;" />
                                            <asp:TextBox ID="txtBoxBack" runat="server" Text='<%# Bind("Back") %>' Style="width: 110px;" />
                                            <asp:TextBox ID="txtBoxLining" runat="server" Text='<%# Bind("Lining") %>' Style="width: 110px;" />
                                        </EditItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="Price" HeaderText="Unit price" UniqueName="Price"
                                        ColumnEditorID="TextEditor" />
                                    <telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity" UniqueName="Quantity"
                                        ColumnEditorID="TextEditor" />
                                    <telerik:GridButtonColumn UniqueName="column" CommandName="Delete" Text="Delete" />
                                </Columns>
                            </MasterTableView>
                        </telerik:RadGrid>
                    </div>
                </div>
                <div class="rightBottom">
                    <!-- -->
                </div>
            </div>
            <div class="fclear">
                <!-- -->
            </div>
        </div>
        <!-- exampleWrap -->
        <div class="exampleBottom">
            <!-- -->
        </div>
        <telerik:GridTextBoxColumnEditor ID="TextEditor" runat="server">
            <TextBoxStyle Width="110px" />
        </telerik:GridTextBoxColumnEditor>
        <telerik:GridDropDownListColumnEditor ID="DropDownEditor1" runat="server">
            <DropDownStyle Width="115px" />
        </telerik:GridDropDownListColumnEditor>
        <telerik:GridDropDownListColumnEditor ID="DropDownEditor2" runat="server">
            <DropDownStyle Width="115px" />
        </telerik:GridDropDownListColumnEditor>
        <br />
        <asp:SqlDataSource id="productsDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:TelerikConnectionString %>"
            providername="System.Data.SqlClient" selectcommand="SELECT ID, Name, ProductName, Manufacturer, SalesRepresentative, Front, Back, Lining, Price, Quantity FROM [Products]"
            deletecommand="DELETE FROM [Products] WHERE [ID] = @ID">
            <DeleteParameters>
                <asp:Parameter Name="original_ID" Type="Int32" />
            </DeleteParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource id="productsDataSource2" runat="server" connectionstring="<%$ ConnectionStrings:TelerikConnectionString %>"
            providername="System.Data.SqlClient" selectcommand="SELECT [ID], [Name], [ProductName], [Manufacturer], [SalesRepresentative], [Front], [Back], [Lining], [Price], [Quantity] FROM [Products] WHERE [ID] = @ID"
            insertcommand="INSERT INTO Products(ProductName, Manufacturer, SalesRepresentative, Front, Back, Lining, Price, Quantity VALUES (@ProductName, @Manufacturer, @SalesRepresentative, @Front, @Back, @Lining, @Price, @Quantity)"
            updatecommand="UPDATE [Products] SET [ProductName] = @ProductName, [Manufacturer] = @Manufacturer, [SalesRepresentative] = @SalesRepresentative, [Front] = @Front, [Back] = @Back, [Lining] = @Lining, [Price] = @Price, [Quantity] = @Quantity 
                               WHERE [ID] = @ID AND [ProductName] = @ProductName AND [Manufacturer] = @Manufacturer AND [SalesRepresentative] = @SalesRepresentative AND [Front] = @Front AND [Back] = @Back AND [Lining] = @Lining AND [Price] = @Price AND [Quantity] = @Quantity"
            oldvaluesparameterformatstring="original_{0}" conflictdetection="CompareAllValues"
            >
            <SelectParameters>
                <asp:ControlParameter ControlID="BusinessGrid" DefaultValue="18" Name="ID" PropertyName="SelectedValue"
                    Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="ID" Type="Int32" />
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:Parameter Name="Manufacturer" Type="String" />
                <asp:Parameter Name="SalesRepresentative" Type="String" />
                <asp:Parameter Name="Front" Type="String" />
                <asp:Parameter Name="Back" Type="String" />
                <asp:Parameter Name="Lining" Type="String" />
                <asp:Parameter Name="Price" Type="Decimal" />
                <asp:Parameter Name="Quantity" Type="Int16" />
                <asp:Parameter Name="original_ID" Type="Int32" />
                <asp:Parameter Name="original_ProductName" Type="String" />
                <asp:Parameter Name="original_Manufacturer" Type="String" />
                <asp:Parameter Name="original_SalesRepresentative" Type="String" />
                <asp:Parameter Name="original_Front" Type="String" />
                <asp:Parameter Name="original_Back" Type="String" />
                <asp:Parameter Name="original_Lining" Type="String" />
                <asp:Parameter Name="original_Price" Type="Decimal" />
                <asp:Parameter Name="original_Quantity" Type="Int16" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:Parameter Name="Manufacturer" Type="String" />
                <asp:Parameter Name="SalesRepresentative" Type="String" />
                <asp:Parameter Name="Front" Type="String" />
                <asp:Parameter Name="Back" Type="String" />
                <asp:Parameter Name="Lining" Type="String" />
                <asp:Parameter Name="Price" Type="Decimal" />
                <asp:Parameter Name="Quantity" Type="Int16" />
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource id="manufacturerDataSource" runat="server" connectionstring="<%$ ConnectionStrings:TelerikConnectionString %>"
            providername="System.Data.SqlClient" selectcommand="SELECT [ID], [Manufacturer] FROM [Products]"
            >
        </asp:SqlDataSource>
        <asp:SqlDataSource id="salesRepDataSource" runat="server" connectionstring="<%$ ConnectionStrings:TelerikConnectionString %>"
            providername="System.Data.SqlClient" selectcommand="SELECT [ID], [SalesRepresentative] FROM [Products]"
            >
        </asp:SqlDataSource>
    </form>
</body>
</html>
