<%@ Page Title="Plan Forecast & Firm" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="plan_order.aspx.cs" Inherits="edicenter.plan_order" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <br /><br /><br /><br />
 <div class="container-fluid">
        <div class="row row-offcanvas row-offcanvas-right">

        <div class="col-xs-12 col-sm-12">
    <div class="row">

         <div class="panel panel-primary">
      <div class="panel-heading">&nbsp&nbsp Plan Forecast & Firm - Vender รายการแผนการผลิตและสั่งสินค้า(Sequence Number) สำหรับดาวน์โหลดหรือยืนยัน&nbsp&nbsp&nbsp&nbsp&nbsp[<%= Session["ULogin"].ToString().Trim() %>]</div>
      <div class="panel-body">
           &nbsp&nbsp
     <asp:Label ID="lblCompany" runat="server" Text="" Font-Bold="true"></asp:Label>
               <br />
        &nbsp&nbsp
        <asp:Label ID="lblVenderID" runat="server" Text="Vender:" Font-Bold="true"></asp:Label>
        <asp:Label ID="lblVender" runat="server" Text=""></asp:Label>&nbsp&nbsp      
        <asp:Label ID="Label23" runat="server" Text="SANo." Font-Bold="true"></asp:Label>
        <asp:Label ID="lblSANo" runat="server" Text=""></asp:Label>&nbsp&nbsp   
        <asp:Label ID="Label13" runat="server" Text="Item:" Font-Bold="true"></asp:Label>
        <asp:Label ID="lblItem" runat="server" Text=""></asp:Label>&nbsp&nbsp  
        <asp:Label ID="lblEvent" runat="server" Text="" Font-Bold="true" ForeColor="blue"></asp:Label>&nbsp&nbsp&nbsp&nbsp&nbsp
        <asp:Label ID="lblDateFrm" runat="server" Text="" Font-Bold="true"></asp:Label>&nbsp
        <asp:Label ID="lblTo" runat="server" Text="To"></asp:Label>&nbsp
        <asp:Label ID="lblDateTo" runat="server" Text="" Font-Bold="true"></asp:Label>
               <br />
        &nbsp&nbsp&nbsp<asp:Label ID="lblResultMonth" runat="server" Text="" Font-Bold="true" ForeColor="blue"></asp:Label>&nbsp
        <asp:Button ID="btnDL" runat="server" Text="Download Format#B" Width="150px" OnClick="btnDL_Click" />&nbsp&nbsp&nbsp
        <asp:Button ID="btnUpExcel" runat="server" Text="Confirm By Excel" Width="130px" OnClick="btnUpExcel_Click" />&nbsp
               <br /> <br />
        &nbsp&nbsp&nbsp<asp:Label ID="lblResultSearch" runat="server" Text=""></asp:Label>&nbsp
               <br /><br />
        <asp:FileUpload ID="FileUpload1" runat="server" />               
        <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />&nbsp&nbsp&nbsp
           <br />
&nbsp;<asp:Repeater id="myRepeater" runat="server">
	<HeaderTemplate>
<table class="table table-bordered">
<tr style="background-color:#fa7b16; color:black; font-weight:bold;height:35px;" align="Left">
                <td>No.</td>
                <td>SA No.</td>
                <td>Item</td>
                <td>Seq.</td>
                <td>Locat.</td>
                <td>Plant</td>
                <td>ArtNo.</td>
                <td>MatNo.</td>
                <td>Description</td>
                <td>Time</td>
                <td>Date</td>
                <td>ReSch</td>
                <td>R.Status</td>
                <td>Quantity</td>
                <td>Unit</td>
                <td>FileNo.</td>
                <td>Time Firm</td>
                <td>Date Firm</td>
                <td>Qty Firm</td>
                <td>Revise</td>
                <td>Confirm</td>
                <td>Status</td>
                <td>MRP</td>
                <td>MRPName</td>
                <td>Download</td>
                </tr>           	
   </HeaderTemplate>             
	<ItemTemplate>    
			 <tr style="background-color:#FFFFFF; color:black; height:35px;" align="left">
             <td><asp:Label id="Label2" runat="server" Text='<%# myRepeater.Items.Count + 1 %>'></asp:Label></td>     
             <td><asp:Label id="lblCustomerID" runat="server" Text='<%# Text_CheckColumn(0,"",Container.DataItem) %>'></asp:Label></td>        
             <td><asp:Label id="Label3" runat="server" Text='<%# Text_CheckColumn(1,"",Container.DataItem)%>'></asp:Label></td>        
             <td><asp:Label id="Label7" runat="server" Text='<%# Text_CheckColumn(2,"",Container.DataItem) %>'></asp:Label></td>
             <td><asp:Label id="Label21" runat="server" Text='<%# Text_CheckColumn(13,"",Container.DataItem) %>'></asp:Label></td>   
             <td><asp:Label id="Label10" runat="server" Text='<%# Text_CheckColumn(7,"",Container.DataItem) %>'></asp:Label></td>   
             <td><asp:Label id="Label12" runat="server" Text='<%# Text_CheckColumn(10,"",Container.DataItem) %>'></asp:Label></td> 
             <td><asp:Label id="Label26" runat="server" Text='<%# Text_CheckColumn(16,"",Container.DataItem) %>'></asp:Label></td> 
             <td><asp:Label id="Label5" runat="server" width="300px" Text='<%# Text_CheckColumn(4,"",Container.DataItem) %>'></asp:Label></td> 
             <td><asp:Label id="Label4" runat="server" Text='<%# Text_CheckColumn(9,Session["event_f"].ToString(),Container.DataItem) %>'></asp:Label></td>   
             <td><asp:Label id="Label8" runat="server" Text='<%# Text_CheckColumn(3,"",Container.DataItem) %>'></asp:Label></td>         
             <td><asp:Label id="Label24" runat="server" Text='<%# Text_CheckColumn(14,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label25" runat="server" Text='<%# Text_CheckColumn(15,"",Container.DataItem) %>'></asp:Label></td>                                               
             <td><asp:Label id="Label6" runat="server" Text='<%# Text_CheckColumn(5,Session["event_f"].ToString(),Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label9" runat="server" Text='<%# Text_CheckColumn(6,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label14" runat="server" Text='<%# Text_CheckColumn(8,"",Container.DataItem) %>'></asp:Label></td> 
             <td><input id="txtTime_<%# ID_indexes(Container.DataItem) %>" type="text" value="<%# Value_TxtTime(Container.DataItem) %>" <%# ReadOnly_TimeDate(Container.DataItem) %> style="width:80px"/></td> 
             <td><input id="txtDate_<%# ID_indexes(Container.DataItem) %>" type="text" value="<%# Value_TxtDate(Container.DataItem) %>" <%# ReadOnly_TimeDate(Container.DataItem) %> style="width:80px"/></td>  
             <td><input id="txtQty_<%# ID_indexes(Container.DataItem) %>" type="text" value="<%# Value_TxtQty(Container.DataItem) %>" <%# ReadOnly_TxtQty(Container.DataItem) %> style="width:80px"/></td>     
             <td><input id="btnMo_<%# ID_indexes(Container.DataItem) %>" type="<%# Button_CheckModify(Container.DataItem) %>" value="RV" onclick="modify_click(<%# ID_indexes(Container.DataItem) %>)" class="btn-block" /></td>          
             <td><input id="btnCF_<%# ID_indexes(Container.DataItem) %>" type="<%# Button_CheckVenderFirm(Container.DataItem) %>" value="CF" onclick="confirm_click(<%# Value_ID_DIV(Container.DataItem) %>)" class="btn-block" /></td>          
             <td><asp:Label id="Label15" runat="server" width="150px" Text="<%# Text_CheckVenderFirm(Container.DataItem) %>"></asp:Label></td>               
             <td><asp:Label id="Label17" runat="server" Text='<%# Text_CheckColumn(11,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label18" runat="server" Text='<%# Text_CheckColumn(12,"",Container.DataItem) %>'></asp:Label></td> 
             <td><input id="btnDL_<%# ID_indexes(Container.DataItem) %>" type="button" value="DL" onclick="download_click(<%# ID_indexes(Container.DataItem) %>)" class="btn-block" /></td>                                                                                                 
	        </tr>
   </ItemTemplate>
    
        <AlternatingItemTemplate>          
			 <tr style="background-color:#20B2AA; color:black; height:35px;" align="left">
             <td><asp:Label id="Label2" runat="server" Text='<%# myRepeater.Items.Count + 1 %>'></asp:Label></td>
             <td><asp:Label id="lblCustomerID" runat="server" Text='<%# Text_CheckColumn(0,"",Container.DataItem) %>'></asp:Label></td>        
             <td><asp:Label id="Label3" runat="server" Text='<%# Text_CheckColumn(1,"",Container.DataItem) %>'></asp:Label></td>        
             <td><asp:Label id="Label7" runat="server" Text='<%# Text_CheckColumn(2,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label22" runat="server" Text='<%# Text_CheckColumn(13,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label10" runat="server" Text='<%# Text_CheckColumn(7,"",Container.DataItem) %>'></asp:Label></td>   
             <td><asp:Label id="Label13" runat="server" Text='<%# Text_CheckColumn(10,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label27" runat="server" Text='<%# Text_CheckColumn(16,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label5" runat="server" width="300px" Text='<%# Text_CheckColumn(4,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label4" runat="server" Text='<%# Text_CheckColumn(9,Session["event_f"].ToString(),Container.DataItem) %>'></asp:Label></td>   
             <td><asp:Label id="Label11" runat="server" Text='<%# Text_CheckColumn(3,"",Container.DataItem) %>'></asp:Label></td>
             <td><asp:Label id="Label24" runat="server" Text='<%# Text_CheckColumn(14,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label25" runat="server" Text='<%# Text_CheckColumn(15,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label6" runat="server" Text='<%# Text_CheckColumn(5,Session["event_f"].ToString(),Container.DataItem) %>'></asp:Label></td>            
             <td><asp:Label id="Label9" runat="server" Text='<%# Text_CheckColumn(6,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label14" runat="server" Text='<%# Text_CheckColumn(8,"",Container.DataItem) %>'></asp:Label></td>  
             <td><input id="txtTime_<%# ID_indexes(Container.DataItem) %>" type="text" value="<%# Value_TxtTime(Container.DataItem) %>" <%# ReadOnly_TimeDate(Container.DataItem) %> style="width:80px"/></td>
             <td><input id="txtDate_<%# ID_indexes(Container.DataItem) %>" type="text" value="<%# Value_TxtDate(Container.DataItem) %>" <%# ReadOnly_TimeDate(Container.DataItem) %> style="width:80px"/></td>
             <td><input id="txtQty_<%# ID_indexes(Container.DataItem) %>" type="text" value="<%# Value_TxtQty(Container.DataItem) %>" <%# ReadOnly_TxtQty(Container.DataItem) %> style="width:80px"/></td>  
             <td><input id="btnMo_<%# ID_indexes(Container.DataItem) %>" type="<%# Button_CheckModify(Container.DataItem) %>" value="RV" onclick="modify_click(<%# ID_indexes(Container.DataItem) %>)" class="btn-block" style="color:black"/></td>                          
             <td><input id="btnCF_<%# ID_indexes(Container.DataItem) %>" type="<%# Button_CheckVenderFirm(Container.DataItem) %>" value="CF" onclick="confirm_click(<%# Value_ID_DIV(Container.DataItem) %>)" class="btn-block" style="color:black"/></td>         
             <td><asp:Label id="Label16" runat="server" width="150px" Text="<%# Text_CheckVenderFirm(Container.DataItem) %>"></asp:Label></td>               
             <td><asp:Label id="Label19" runat="server" Text='<%# Text_CheckColumn(11,"",Container.DataItem) %>'></asp:Label></td>  
             <td><asp:Label id="Label20" runat="server" Text='<%# Text_CheckColumn(12,"",Container.DataItem) %>'></asp:Label></td>  
             <td><input id="btnDL_<%# ID_indexes(Container.DataItem) %>" type="button" value="DL" onclick="download_click(<%# ID_indexes(Container.DataItem) %>)" class="btn-block" style="color:black"/></td>                 
             </tr>		           
	</AlternatingItemTemplate> 

	</asp:Repeater> </table>
               <br />
        
      </div>
    </div>
                
      </div>
            </div>

         </div>

       <script src="css/js/jquery.min.js"></script>
       <script src="css/js/bootstrap.min.js"></script>
       <script type="text/javascript">
           /* $(document).ready(function () { });*/
           function load_click(doc)
           {
               var DOC_NEW = $("#PO_" + doc).text();
               if (DOC_NEW == "") {
                   alert("คุณไม่สามารถโหลดได้");
                   $("#btn" + doc).attr("disabled", "disabled").removeClass("btn btn-primary").addClass("btn btn-danger").html("Close Download");                                    
               } else {
                   $("#btn" + doc).attr("disabled", "disabled").removeClass("btn btn-primary").addClass("btn btn-success").html("Downloaded");
                   window.open("load_files.aspx?DC="+doc+"");
               }            
           }
           function confirm_click(id)
           {
               var index = id;
               var txtTime = document.getElementById("txtTime_"+index).value;
               var txtDate = document.getElementById("txtDate_"+index).value;
               var txtQty = document.getElementById("txtQty_"+index).value;
               if((txtQty=="")||(txtTime=="")||(txtDate==""))
                   alert("โปรดใส่ข้อมูลให้ครบถ้วน");
               else if((txtTime.length > 8)||(txtTime.length < 8))
                   alert("โปรดใส่ข้อมูลเวลาให้ถูกต้อง HH:MM:SS");
               else if((txtDate.length > 10)||(txtDate.length < 10))
                   alert("โปรดใส่ข้อมูลวันเดือนปีให้ถูกต้อง DD-MM-YYYY");      
               else if(txtTime[2]!=":")
                   alert("โปรดใส่ข้อมูลเวลาให้ถูกต้อง HH:MM:SS");
               else if(txtTime[5]!=":")
                   alert("โปรดใส่ข้อมูลเวลาให้ถูกต้อง HH:MM:SS");
               else if(txtDate[2]!="-")
                   alert("โปรดใส่ข้อมูลวันเดือนปีให้ถูกต้อง DD-MM-YYYY");  
               else if(txtDate[5]!="-")
                   alert("โปรดใส่ข้อมูลวันเดือนปีให้ถูกต้อง DD-MM-YYYY");  
               else
               {
                   var flag = 1,flagDot = 0;
                   for (var i=0; i < txtQty.length; i++)
                   {
                       if(txtQty[i]==" "){flag=0;break;}
                           /*else 
                           {
                               var intQ = parseInt(txtQty[i]);
                               if(intQ.toString() == "NaN"){flag=0;break;}
                           }*/
                       else 
                       {
                           var intQ = parseInt(txtQty[i]);
                           if(txtQty[i]=="."){flagDot++;}
                           else if((txtQty[i]!=".")&&(intQ.toString() == "NaN")){flag=0;break;}
                       }
                   }
                   for (var i=0; i < txtDate.length; i++)
                   {
                       if(txtDate[i]==" "){flag=0;break;}
                       else 
                       {
                           if((i!=2)&&(i!=5))
                           {
                               var intQ = parseInt(txtDate[i]);
                               if(intQ.toString() == "NaN"){flag=0;break;}
                           }
                       }
                   }
                   for (var i=0; i < txtTime.length; i++)
                   {
                       if(txtTime[i]==" "){flag=0;break;}
                       else 
                       {
                           if((i!=2)&&(i!=5))
                           {
                               var intQ = parseInt(txtTime[i]);
                               if(intQ.toString() == "NaN"){flag=0;break;}
                           }
                       }
                   }
                   if(flag==1)
                   {
                       if(txtQty[0]=="0"){alert("ไม่สามารถใส่จำนวนสินค้าเป็น 0");document.getElementById("txtQty_"+index).value = "";}
                       else
                       {
                           if(flagDot<=1)
                           {
                               var hh = parseInt(txtTime[0]+txtTime[1]);
                               var mm = parseInt(txtTime[3]+txtTime[4]);
                               var ss = parseInt(txtTime[6]+txtTime[7]);
                               //var dd = parseInt(txtDay[0]+txtTime[1]);
                               //var mo = parseInt(txtMon[3]+txtTime[4]);
                               if((hh>23)||(mm>59)||(ss>59))
                               {
                                   alert("โปรดใส่ข้อมูลเวลาให้ถูกต้อง HH:MM:SS");
                               }
                               else
                               {
                                   if(txtQty.indexOf(".")!=-1)
                                   {
                                       var nDot = txtQty.indexOf(".");
                                       if(((txtQty.length-nDot)<=4)&&((txtQty.length-nDot)>=2))
                                       {
                                           var confirm_value = document.createElement("INPUT");
                                           confirm_value.type = "hidden";
                                           confirm_value.name = "confirm_value";
                                           if (confirm("Press Button Yes to Confirm?")) 
                                           {
                                               confirm_value.value = "Yes";
                                               //$.post("Vender_Confirm.aspx",{id:index+"_"+txtQty,tm:txtTime,dt:txtDate});
                                               //window.location.href = window.location.href;
                                               window.open("Vender_Confirm.aspx?DC="+id+"?"+txtQty+"?"+txtTime+"?"+txtDate+"","_self");
                                               //window.opener.history.go(0);
                                           } 
                                           else {confirm_value.value = "No";}
                                       }
                                       else if((txtQty.length-nDot)<2){alert("คุณใส่จุดทศนิยมไม่ถูกต้อง");}
                                       else {alert("กำหนดให้จำนวนสินค้ามีหลักทศนิยมได้ไม่เกิน 3 หลัก");}
                                   } 
                                   else 
                                   {
                                       var confirm_value = document.createElement("INPUT");
                                       confirm_value.type = "hidden";
                                       confirm_value.name = "confirm_value";
                                       if (confirm("Press Button Yes to Confirm?")) 
                                       {
                                           confirm_value.value = "Yes";
                                           //$.post("Vender_Confirm.aspx",{id:index+"_"+txtQty,tm:txtTime,dt:txtDate});
                                           //window.location.href = window.location.href;
                                           window.open("Vender_Confirm.aspx?DC="+id+"?"+txtQty+"?"+txtTime+"?"+txtDate+"","_self");
                                           //window.opener.history.go(0);
                                       } 
                                       else {confirm_value.value = "No";}
                                   }
                               }
                           }
                           else {alert("คุณใส่จุดทศนิยมในจำนวนสินค้าไม่ถูกต้อง");}
                       }
                   }
                   else {alert("โปรดใส่ข้อมูลให้ถูกต้องตามรูปแบบและไม่เว้นวรรค");}
               }
           }
           /*
           function confirm_click(id)
           {
               var index = id.toString().substring(0,id.toString().indexOf(".",0));
               //var div = id.toString().substring(id.toString().indexOf(".",0)+1);
               var txtQty = document.getElementById("txtQty_"+index).value;
               if(txtQty=="")
                   alert("โปรดใสจำนวนสินค้าเพื่อยืนยัน");
               else
               {
                   var flag = 1;
                   for (var i=0; i < txtQty.length; i++)
                   {
                       if(txtQty[i]==" "){flag=0;break;}
                       else 
                       {
                           var intQ = parseInt(txtQty[i]);
                           if(intQ.toString() == "NaN"){flag=0;break;}
                       }
                   }
                   if(flag==1)
                   { 
                       var confirm_value = document.createElement("INPUT");
                       confirm_value.type = "hidden";
                       confirm_value.name = "confirm_value";
                       if (confirm("Press Button Yes to Confirm?")) 
                       {
                           confirm_value.value = "Yes";
                           $.post("Vender_Confirm.aspx",{id:index+"_"+txtQty});
                           window.location.reload();   
                       } 
                       else {confirm_value.value = "No";}
                   }
                   else {alert("โปรดใส่จำนวนสินค้าเป็นตัวเลขเท่านั้นและไม่เว้นวรรค");document.getElementById("txtQty_"+index).value = "";}
               }
           }*/
           function cancel_click(id)
           {
               var confirm_value = document.createElement("INPUT");
               confirm_value.type = "hidden";
               confirm_value.name = "confirm_value";
               if (confirm("Press Button Yes to Cancel?")) 
               {
                   confirm_value.value = "Yes";
                   $.post("MP_Cancel.aspx",{id:id});
                   window.location.reload();   
               } 
               else 
                   confirm_value.value = "No";
               //document.forms[0].appendChild(confirm_value);
               //window.alert("Test");
               //$.post("Vender_Confirm.aspx",{A:"B",B:"B"});
               //$.post("Vender_Confirm.aspx",{id:id});
               //window.location.reload();            
           }
           function modify_click(id)
           {
               <%= Session["ShowPageMF"] = "1" %>
               //$.post("page_viewmodify.aspx",{id:id});
               //window.open("page_viewmodify.aspx?DC="+id+"");   
               window.open("plan_revise_vender.aspx?DC="+id+"")
           }
           function download_click(id)
           {  
               //window.open("load_files.aspx?DC="+id+"");
               window.open("Vender_ExportExcel.aspx?DC="+id+"");
           }
           /*
           $.post("WebFormTest.aspx",{A:"XX"},function(data){
               alert(data);
           });
           */
           /*function btn_disable(id)
           {
               //document.getElementById("btnCF_" + id).setAttribute("value","Yes");
               document.getElementById("btnCF_" + id).disabled=true;
           }*/
       </script>
    </div>
</asp:Content>
