<%@ Page Title="Edit Material" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" 
    CodeBehind="MaterialsEdit.aspx.cs" Inherits="SMTBETECH_V3.MaterialsEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<style type="text/css">
   
    .GridPager a, .GridPager span {
        display: block;
        height: 28px;
        width: 24px;
        font-weight: bold;
        text-align: center;
        text-decoration: none;
    }

    .GridPager a {
        background-color: #f5f5f5;
        color: #969696;
        border: 1px solid #969696;
    }

    .GridPager span {
        /*background-color: #A1DCF2;*/
        background-color: steelblue;
        color: whitesmoke;
        border: 1px solid #3AC0F2;
    }
</style>

<script>
    function isNumberKey(sender, evt) {
        var txt = sender.value;
        var dotcontainer = txt.split('.');
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if (!(dotcontainer.length == 1 && charCode == 46) && charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

        return true;
    }
</script>


<h2 id="title"><%: Title %></h2>



    <asp:ScriptManagerProxy ID="ScriptManagerProxyMaterialsEdit" runat="server"></asp:ScriptManagerProxy>
    <asp:UpdatePanel ID="UpdatePanelMaterialsEdit" runat="server">

        <ContentTemplate>

            <div class="row mb-1">
                <div class="col-2">
                    <label style="font-weight:bold" for="FormMaterialID" class="form-label">Id:</label>
                    <asp:TextBox disabled="true" CssClass="form-control" runat="server" ID="FormMaterialID"></asp:TextBox>
                </div>
                <div class="col">
                    <label style="font-weight:bold" for="FormPartNumber" class="form-label">Part Number:</label>
                    <asp:TextBox CssClass="form-control" runat="server" ID="FormPartNumber" style="text-transform:uppercase"></asp:TextBox>
                </div>
            </div>

           <div class="row mb-1">
                <div class="col">
                    <label style="font-weight:bold" for="FormDescription" class="form-label">Description:</label>
                    <asp:TextBox CssClass="form-control" runat="server" ID="FormDescription"></asp:TextBox>
                </div>
            </div>

            <hr />


                <div class="row mb-1">
                <div class="col-6">
                    <label style="font-weight:bold" for="FormQuantity" class="form-label">Quantity:</label>
                    <asp:TextBox disabled="true" CssClass="form-control" runat="server" ID="FormQuantity" style="text-align:right;color:blue"
                        OnFocus="this.select()" OnKeyPress="return isNumberKey(this, event);"></asp:TextBox>
                </div>
                <div class="col-6">
                    <label style="font-weight:bold" for="FormPrice" class="form-label">Price:</label>
                    <asp:TextBox CssClass="form-control" runat="server" ID="FormPrice" style="text-align:right;color:blue" 
                        OnTextChanged="FormPrice_TextChanged" AutoPostBack="true"
                        OnFocus="this.select()" OnKeyPress="return isNumberKey(this, event);"></asp:TextBox>
                </div>

            </div>

        <hr />


<%--Start PN Customers --%>

<h5>Customer Part Numbers:</h5>

<asp:Button ID="btnSelectPNCustomer" runat="server" CssClass="btn btn-primary btn-sm" Text="Select Customer" />

    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderPNCustomers" runat="server"
        BackgroundCssClass="modalBackground"
        DropShadow ="true"
        TargetControlID="btnSelectPNCustomer"
        PopupControlID="PanelPNCustomers"
        CancelControlID="btnCancelPNCustomerSelectCustomer" />

    <asp:Panel ID="PanelPNCustomers" runat="server" style="display:none; text-align:left; width:350px; 
        background-color:White; border-width:2px; border-color:steelblue; border-style:solid; padding:10px;">

          <h4>Select Customer</h4>
              <hr />

               <%-- Start Grid PN Customers--%>

            <asp:Panel ID="PanelSearchPNCustomers" runat="server" DefaultButton="btnSearchPNCustomer">
                <div class="row" style="width:100%">
                    <div class="col-6">
                        <asp:TextBox CssClass="form-control" placeholder="Search Customer"  runat="server"
                            ID="txtSearchPNCustomer" AutoPostBack="false" onFocus="this.select()"/>
                    </div>
                    <div class="col-6" style="text-align:left">
                        <asp:Button CssClass="btn btn-primary btn-sm" ID="btnSearchPNCustomer" runat="server" 
                            Text="Search" OnClick="btnSearchPNCustomer_Click"/>
                        <asp:Button CssClass="btn btn-primary btn-sm" ID="btnClearSearchPNCustomer" runat="server"
                            Text="Clear" OnClick="btnClearSearchPNCustomer_Click"/>
                    </div>
               </div>
                <p></p>
            </asp:Panel>

        <div style="overflow-x:scroll">
            <asp:GridView CssClass="table table-bordered table-striped table-sm"
                ID="GVPNCustomers"
                runat="server"
                AutoGenerateColumns="False"
                AllowPaging="True"
                AllowSorting="False"
                OnRowCommand="GVPNCustomers_RowCommand" OnPageIndexChanging="GVPNCustomers_PageIndexChanging" PageSize="5">
            <HeaderStyle CssClass="table-primary" />
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" InsertVisible="False" SortExpression="Id"></asp:BoundField>

                <asp:ButtonField HeaderStyle-Wrap="false" HeaderStyle-Width="300px" ItemStyle-Wrap="false" SortExpression="CustomerName" 
                    CommandName="SelectPNCustomer" DataTextField="CustomerName" HeaderText="Customer Name" />

                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" DataField="CustomerAbbrevation" HeaderText="Customer Abbrevation" SortExpression="CustomerAbbrevation"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" DataField="VendorNo" HeaderText="Vendor No" SortExpression="VendorNo"></asp:BoundField>
                <asp:BoundField DataField="TaxId" HeaderText="Tax Id" SortExpression="TaxId"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false"  DataField="BillToStreet" HeaderText="Bill To Street" SortExpression="BillToStreet"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false"  DataField="BillToSuburb" HeaderText="Bill To Suburb" SortExpression="BillToSuburb"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="BillToMunicipality" HeaderText="Bill To Municipality" SortExpression="BillToMunicipality"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="BillToZipCode" HeaderText="Bill To ZipCode" SortExpression="BillToZipCode"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="BillToState" HeaderText="Bill To State" SortExpression="BillToState"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="BillToCountry" HeaderText="Bill To Country" SortExpression="BillToCountry"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false"  DataField="ShipToStreet" HeaderText="Ship To Street" SortExpression="ShipToStreet"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToSuburb" HeaderText="Ship To Suburb" SortExpression="ShipToSuburb"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToMunicipality" HeaderText="Ship To Municipality" SortExpression="ShipToMunicipality"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToZipCode" HeaderText="Ship To ZipCode" SortExpression="ShipToZipCode"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToState" HeaderText="Ship To State" SortExpression="ShipToState"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToCountry" HeaderText="Ship To Country" SortExpression="ShipToCountry"></asp:BoundField>
                <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="TermsPayment" HeaderText="Terms Payment" SortExpression="TermsPayment"></asp:BoundField>
                <asp:BoundField DataField="Currency" HeaderText="Currency" SortExpression="Currency"></asp:BoundField>
                <asp:BoundField ItemStyle-Wrap="false" ItemStyle-Width="200px" DataField="CreationDate" HeaderText="Creation Date" SortExpression="CreationDate"></asp:BoundField>
                <asp:BoundField ItemStyle-Wrap="false" ItemStyle-Width="200px" DataField="ModifiedDate" HeaderText="Modified Date" SortExpression="ModifiedDate"></asp:BoundField>
            </Columns>
                    <PagerStyle CssClass="GridPager" />

            </asp:GridView>
        </div>

            <p></p>
             <div>
             Total:
             <asp:Label runat="server" ID="lblPNCustomersCount"></asp:Label>
             </div>


             <%--End Grid PN Customers--%>

             <p></p>

             <div style="text-align:right;">            
                 <asp:Button ID="btnCancelPNCustomerSelectCustomer" CssClass="btn btn-secondary btn-sm" runat="server" Text="Cancel" />
             </div>


    </asp:Panel>


<asp:Panel ID="PanelAddPNCustomer" runat="server" DefaultButton="btnAddPNCustomer">

    <div class="row mb-1">
        <div class="col" style="display:none">
            <label style="font-weight:bold" for="FormPNCustomerIdCustomer" class="form-label">Id Customer:</label>
            <asp:TextBox CssClass="form-control" runat="server" ID="FormPNCustomerIdCustomer"></asp:TextBox>
        </div>
        <div class="col">
           <label style="font-weight:bold" for="FormPNCustomerCustomerName" class="form-label">Selected Customer Name:</label>
           <asp:TextBox disabled="true" CssClass="form-control" runat="server" ID="FormPNCustomerCustomerName"></asp:TextBox>
       </div>
        <div class="col-4">
           <label style="font-weight:bold" for="FormPNCustomerPartNumber" class="form-label">Part Number:</label>
           <asp:TextBox CssClass="form-control" runat="server" ID="FormPNCustomerPartNumber" style="text-align:right;color:blue;text-transform:uppercase"></asp:TextBox>
           <%--<asp:TextBox onkeyup="this.value=this.value.toUpperCase()" CssClass="form-control" runat="server" ID="TextBox1" style="text-align:right;color:blue"></asp:TextBox>--%>
       </div>
    </div>

 
     <div class="row mb-3">
        <div style="text-align:right">
            <asp:Button ID="btnAddPNCustomer" runat="server" CssClass="btn btn-primary btn-sm" Text="Add Part Number" OnClick="btnAddPNCustomer_Click" />
        </div>
    </div>

</asp:Panel>


            <%--Start PN Customers Part Numbers--%>

        <p></p>

        <asp:GridView CssClass="table table-bordered table-striped table-sm" ShowHeaderWhenEmpty="true"
            ID="GVCustomersPartNumbers" runat="server" AutoGenerateColumns="false" OnRowCommand="GVCustomersPartNumbers_RowCommand">
            <Columns>
                
                <asp:BoundField Visible="false" DataField="Id" HeaderText="Id" SortExpression="Id">
                    <ItemStyle Width="200px" />
                </asp:BoundField>
                
                <asp:BoundField Visible="false" DataField="IdCustomer" HeaderText="IdCustomer" SortExpression="IdCustomer">
                    <ItemStyle Width="200px" />
                </asp:BoundField>
                <asp:BoundField DataField="CustomerName" HeaderText="Customer Name" SortExpression="CustomerName">
                    <ItemStyle Width="300px" />
                </asp:BoundField>
                <asp:BoundField DataField="PartNumber" HeaderText="Part Number" SortExpression="PartNumber">
                    <ItemStyle Width="300px" ForeColor="Blue" />
                </asp:BoundField>


                <asp:TemplateField HeaderStyle-CssClass="col-1" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>                        
                        <asp:Button runat="server" ID="btnDeleteCustomerPartNumber" CssClass="btn btn-close" 
                            CommandName="DeleteCustomerPartNumber" CommandArgument='<%# Eval("Id") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EmptyDataTemplate>No Part Numbers</EmptyDataTemplate>
        </asp:GridView>




        <%--End PN Customers Part Numbers--%>


<%--End PN Customers --%>


            <hr />
                       

<%-- Start Customers --%>

<h5>Customer Prices:</h5>

<asp:Button ID="btnSelectCustomer" runat="server" CssClass="btn btn-primary btn-sm" Text="Select Customer" />

            <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderMaterialsEdit" runat="server"
                BackgroundCssClass="modalBackground"
                DropShadow ="true"
                TargetControlID="btnSelectCustomer"
                PopupControlID="PanelSelectCustomers"
                CancelControlID="btnCancelSelectCustomer" />

            <asp:Panel ID="PanelSelectCustomers" runat="server" style="display:none; text-align:left; width:350px; 
            background-color:White; border-width:2px; border-color:steelblue; border-style:solid; padding:10px;">

                <h4>Select Customer</h4>
                <hr />

                 <%-- Start Grid Customers--%>

              <asp:Panel ID="PanelSearchCustomer" runat="server" DefaultButton="btnSearch">
                  <div class="row" style="width:100%">
                      <div class="col-6">
                          <asp:TextBox CssClass="form-control" placeholder="Search Customer"  runat="server"
                              ID="txtSearchCustomer" AutoPostBack="false" onFocus="this.select()"/>
                      </div>
                      <div class="col-6" style="text-align:left">
                          <asp:Button CssClass="btn btn-primary btn-sm" ID="btnSearch" runat="server" 
                              Text="Search" OnClick="btnSearch_Click"/>
                          <asp:Button CssClass="btn btn-primary btn-sm" ID="btnClearSearch" runat="server"
                              Text="Clear" OnClick="btnClearSearch_Click"/>
                      </div>
                 </div>
                  <p></p>
              </asp:Panel>

                
                <div style="overflow-x:scroll">
                <asp:GridView CssClass="table table-bordered table-striped table-sm"
                    ID="GVCustomers"
                    runat="server"
                    AutoGenerateColumns="False"
                    AllowPaging="True"
                    AllowSorting="False"
                    OnRowCommand="GVCustomers_RowCommand" OnPageIndexChanging="GVCustomers_PageIndexChanging" PageSize="5">
                <HeaderStyle CssClass="table-primary" />
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" InsertVisible="False" SortExpression="Id"></asp:BoundField>

                    <asp:ButtonField HeaderStyle-Wrap="false" HeaderStyle-Width="300px" ItemStyle-Wrap="false" SortExpression="CustomerName" 
                        CommandName="SelectCustomer" DataTextField="CustomerName" HeaderText="Customer Name" />

                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" DataField="CustomerAbbrevation" HeaderText="Customer Abbrevation" SortExpression="CustomerAbbrevation"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" DataField="VendorNo" HeaderText="Vendor No" SortExpression="VendorNo"></asp:BoundField>
                    <asp:BoundField DataField="TaxId" HeaderText="Tax Id" SortExpression="TaxId"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false"  DataField="BillToStreet" HeaderText="Bill To Street" SortExpression="BillToStreet"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false"  DataField="BillToSuburb" HeaderText="Bill To Suburb" SortExpression="BillToSuburb"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="BillToMunicipality" HeaderText="Bill To Municipality" SortExpression="BillToMunicipality"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="BillToZipCode" HeaderText="Bill To ZipCode" SortExpression="BillToZipCode"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="BillToState" HeaderText="Bill To State" SortExpression="BillToState"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="BillToCountry" HeaderText="Bill To Country" SortExpression="BillToCountry"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false"  DataField="ShipToStreet" HeaderText="Ship To Street" SortExpression="ShipToStreet"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToSuburb" HeaderText="Ship To Suburb" SortExpression="ShipToSuburb"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToMunicipality" HeaderText="Ship To Municipality" SortExpression="ShipToMunicipality"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToZipCode" HeaderText="Ship To ZipCode" SortExpression="ShipToZipCode"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToState" HeaderText="Ship To State" SortExpression="ShipToState"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="ShipToCountry" HeaderText="Ship To Country" SortExpression="ShipToCountry"></asp:BoundField>
                    <asp:BoundField HeaderStyle-Wrap="false" HeaderStyle-Width="200px" ItemStyle-Wrap="false" DataField="TermsPayment" HeaderText="Terms Payment" SortExpression="TermsPayment"></asp:BoundField>
                    <asp:BoundField DataField="Currency" HeaderText="Currency" SortExpression="Currency"></asp:BoundField>
                    <asp:BoundField ItemStyle-Wrap="false" ItemStyle-Width="200px" DataField="CreationDate" HeaderText="Creation Date" SortExpression="CreationDate"></asp:BoundField>
                    <asp:BoundField ItemStyle-Wrap="false" ItemStyle-Width="200px" DataField="ModifiedDate" HeaderText="Modified Date" SortExpression="ModifiedDate"></asp:BoundField>
                </Columns>
                        <PagerStyle CssClass="GridPager" />

                </asp:GridView>
                </div>

                    <p></p>
                    <div>
                    Total:
                    <asp:Label runat="server" ID="lblCount"></asp:Label>
                    </div>


                    <%--End Grid Customers--%>

                    <p></p>

                    <div style="text-align:right;">            
                        <asp:Button ID="btnCancelSelectCustomer" CssClass="btn btn-secondary btn-sm" runat="server" Text="Cancel" />
                    </div>

            </asp:Panel>


<asp:Panel ID="PanelAddCustomerPrice" runat="server" DefaultButton="btnAddCustomerPrice">

    <div class="row mb-1">
        <div class="col" style="display:none">
            <label style="font-weight:bold" for="FormIdCustomer" class="form-label">Id Customer:</label>
            <asp:TextBox CssClass="form-control" runat="server" ID="FormIdCustomer"></asp:TextBox>
        </div>
        <div class="col">
           <label style="font-weight:bold" for="FormCustomerName" class="form-label">Selected Customer Name:</label>
           <asp:TextBox disabled="true" CssClass="form-control" runat="server" ID="FormCustomerName"></asp:TextBox>
       </div>
        <div class="col-4">
           <label style="font-weight:bold" for="FormCustomerPrice" class="form-label">Price:</label>
           <asp:TextBox OnFocus="this.select()" CssClass="form-control" runat="server" ID="FormCustomerPrice" style="text-align:right;color:blue"></asp:TextBox>
       </div>
    </div>

 
     <div class="row mb-3">
        <div style="text-align:right">
            <asp:Button ID="btnAddCustomerPrice" runat="server" CssClass="btn btn-primary btn-sm" Text="Add Price" OnClick="btnAddCustomerPrice_Click" />
        </div>
    </div>

</asp:Panel>

<%--Start Materials Customers Price--%>

        <p></p>

        <asp:GridView CssClass="table table-bordered table-striped table-sm" ShowHeaderWhenEmpty="true"
            ID="GVCustomersPrices" runat="server" AutoGenerateColumns="false" OnRowCommand="GVCustomersPrices_RowCommand">
            <Columns>
                
                 <asp:BoundField Visible="false" DataField="Id" HeaderText="Id" SortExpression="Id">
                     <ItemStyle Width="200px" />
                 </asp:BoundField>

                <asp:BoundField Visible="false" DataField="IdCustomer" HeaderText="IdCustomer" SortExpression="IdCustomer">
                    <ItemStyle Width="200px" />
                </asp:BoundField>
                <asp:BoundField DataField="CustomerName" HeaderText="Customer Name" SortExpression="CustomerName">
                    <ItemStyle Width="300px" />
                </asp:BoundField>
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" DataFormatString="{0:C2}">
                    <ItemStyle Width="100px" HorizontalAlign="Right" ForeColor="Blue" />
                </asp:BoundField>


                <asp:TemplateField HeaderStyle-CssClass="col-1" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>                        
                        <asp:Button runat="server" ID="btnDeleteCustomerPrice" CssClass="btn btn-close" 
                            CommandName="DeleteCustomerPrice" CommandArgument='<%# Eval("Id") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EmptyDataTemplate>No Prices</EmptyDataTemplate>
        </asp:GridView>




<%--End Materials Customers Price--%>



<%-- End Customers --%>


<hr />

<asp:Button ID="btnSave" runat="server" CssClass="btn btn-primary" Text="Save" OnClick="btnSave_Click" OnClientClick="return confirm('Update Material ? ');" />
<asp:Button ID="btnBack" runat="server" CssClass="btn btn-secondary" Text="Back to Materials" OnClick="btnBack_Click" />



        </ContentTemplate>

    </asp:UpdatePanel>


</asp:Content>
