ERP产品销售发货判断库存功能(四十二)
产品数量的前端(键盘抬起的事件):
<td> <input type="text" name="proCount" onkeyup="isProCountFull(this)" class="{required:true,min:1,digits:true}" style="width: 100px" /> </td>
js代码:
<script type="text/javascript"> function isProCountFull(obj) { var proid = $($(obj).parent().parent().find("input[name='proID']")[0]).val(); var procount=$(obj).val(); if (proid != '' && proid != null) { if (procount != '' && procount != null && procount != '0') { $.ajax({ type: "POST", //设置提交方式 url: "getProCount.aspx", data: "proid=" + proid + "&procount=" + procount, //提交数据 success: function (msg) { if (msg == "OK") { } else { alert(msg); $(obj).attr("value", ""); } } }); } } else { alert("请先选择产品"); $(obj).attr("value", ""); } } //判断是否有重复名称的产品 function issameproid(obj) { var proidcount = 0; // proidscount = $(document).find("input[name='proID']").length; var proid = $($(obj).parent().find("input[name='proID']")[0]).val(); $(document).find("input[name='proID']").each(function () { if ($(this).val() == proid) { proidcount++; if (proidcount >= 2) { alert("选择产品有重复,请重新选择"); $($(obj).parent().find("input[name='proName']")[0]).attr("value", ""); $($(obj).parent().find("input[name='proId']")[0]).attr("value", ""); } } }); } </script>
判断产品的总量是否到达:
var isprocount=false; $("#trprobatch").show(); var obj = window.event.srcElement; var tr = obj.parentNode.parentNode; var inputs = tr.getElementsByTagName("input"); $("#divprobatch").find("input[name='proIds']").each(function () { if (inputs[1].value == $(this).val()) { boxnum++; procount += parseInt($(this).parent().parent().find("input[name='txtProCount0']").val()); if (procount > parseInt(inputs[3].value)) { isprocount=true; if(isprocount) { $(this).parent().parent().find("input[name='txtProCount0']").attr("value", "0"); alert("产品总数已经达到,不能为此产品添加批号"); } // event.stopPropagation(); } }
后端代码(getProCount.aspx):
protected void Page_Load(object sender, EventArgs e) { string returnResult = "";//定义返回状态 this.Response.Clear(); //获取前端的数据 string proid = Request.Form["proid"].ToString(); string procount = Request.Form["procount"].ToString(); returnResult = proid + " " + procount; object obj= SqlComm.GetObjectByCondition("dbo.BioProStock", "isnull(sum(ProCout),0)", " ProID=" + proid); if (obj != null) { if (int.Parse(obj.ToString()) < int.Parse(procount)) { returnResult = "此产品库存不足,最多发货数据" + obj.ToString(); } else { returnResult = "OK"; } } this.Response.Write(returnResult); this.Response.End(); }
根据产品的编号获取产品的名称:
-- Description: 根据产品的编号获取产品的名称 -- ============================================= CREATE FUNCTION FN_getProNameByProID ( @ProID int ) RETURNS nvarchar(100) AS BEGIN DECLARE @ProName nvarchar(50) SELECT @ProName= ProName FROM BiotbProduct WHERE ProID=@ProID RETURN @ProName END
选择发货产品批次的页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SendGoodsSelectProStock.aspx.cs" Inherits="BioErpWeb.SendGoods.SendGoodsSelectProStock" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="../Styles/Style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #form1 { text-align: center; } .style10 { height: 30px; width: 763px; } .style2 { width: 100%; } .style11 { width: 74px; } .style12 { width: 217px; } .style13 { width: 91px; } .style14 { width: 47px; } .style15 { width: 70px; } .style18 { height: 44px; width: 763px; } .style19 { width: 763px; } #tb1 { width: 767px; } </style> <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript"> var procount = 0; function stockClick(control) { var tr = control.parentNode.parentNode; var txts = tr.getElementsByTagName('td'); var rowIndex = control.parentNode.parentNode.rowIndex; var input = control.parentNode; var inputhf = input.getElementsByTagName('input'); document.getElementById('lbproStockID').innerText = txts[1].innerHTML; document.getElementById('Label2').innerText = txts[2].innerHTML; document.getElementById('lbProBatch').innerText = txts[3].innerHTML; procount= parseInt(txts[4].innerHTML); document.getElementById('lbExpDate').innerText = txts[5].innerHTML; document.getElementById('lbStockDate').innerText = txts[6].innerHTML; document.getElementById('lbMakeDate').innerText = txts[7].innerHTML; document.getElementById('lbMakeDate').innerText = txts[7].innerHTML; document.getElementById('lbstockid').innerText = txts[8].innerHTML; } function returnSendEdit() { if ($("#lbStockID").html() == "" || $("#txtCount").val() == "" || $("#txtCount").val() == "0") { alert("请选择产品批次信息,并填写数量"); } else { var returnbacklist = new Array($("#lbproStockID").html(), $("#lbProBatch").html(), $("#txtCount").val(), $("#lbExpDate").html(), $("#lbStockDate").html(), $("#lbMakeDate").html(), $("#lbstockid").html()); window.returnValue = returnbacklist; window.close(); } } //判断填写产品数量是否超出当前产品库存 function isOvercount() { if (parseInt($("#txtCount").val()) > procount) { alert("填写产品数量越界,请重新填写"); $("#txtCount").attr("value", "0"); } } </script> </head> <body> <form id="form1" runat="server"> <div > <div style="margin:0px auto; width:762px;"> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="765px" CssClass="gray2"> <Columns> <asp:TemplateField> <ItemTemplate> <input id= "Radio1" onclick="stockClick(this)" value="<%#DataBinder.Eval(Container.DataItem,"id")%>" name= "stock" type= "radio" /> </ItemTemplate> <HeaderStyle CssClass="blue6" /> <ItemStyle Width="1%" /> </asp:TemplateField> <asp:BoundField DataField="ID" HeaderText="库存号" > <HeaderStyle CssClass="blue6" /> <ItemStyle Width="3%" /> </asp:BoundField> <asp:BoundField DataField="proName" HeaderText="产品全名" > <HeaderStyle CssClass="blue6" /> <ItemStyle Width="14%" /> </asp:BoundField> <asp:BoundField DataField="BathNum" HeaderText="批号" > <HeaderStyle CssClass="blue6" /> <ItemStyle Width="6%" /> </asp:BoundField> <asp:BoundField DataField="ProCout" HeaderText="数量" > <HeaderStyle CssClass="blue6" /> <ItemStyle Width="3%" /> </asp:BoundField> <asp:BoundField DataField="ExpirateDate" HeaderText="有效期" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="false" > <HeaderStyle CssClass="blue6" /> <ItemStyle Width="4%" /> </asp:BoundField> <asp:BoundField DataField="StockDate" HeaderText="入库日期" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="false" > <HeaderStyle CssClass="blue6" /> <ItemStyle Width="4%" /> </asp:BoundField> <asp:BoundField DataField="makeDate" HeaderText="生产日期" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="false" > <HeaderStyle CssClass="blue6" /> <ItemStyle Width="4%" /> </asp:BoundField> <asp:BoundField DataField="StockID" HeaderText="仓库编号" HtmlEncode="false" > <HeaderStyle CssClass="blue6" /> <ItemStyle Width="4%" /> </asp:BoundField> </Columns> </asp:GridView> </div> <div style="margin:0px auto; width:751px;"> <table id="tb1" cellpadding="0" cellspacing="0"> <tr> <td id="tdNoData" style="display:none; color: #FF0000; font-size: 25px; font-weight: inherit;line-height: 30px;" class="style18"> 这个产品现在没有库存!</td> </tr> <tr id="tr1"> <td style="text-align:left;" class="style10"> 注意:你填写的数量请不要超过你选择的库存的数量!</td> </tr> <tr id="tr2"> <td class="style19"> <table class="style2" border="1" style="border-collapse:collapse;" > <tr class="blue6"> <td class="style11"> 库存号</td> <td class="style12"> 产品全名</td> <td class="style13"> 批号</td> <td class="style14"> 数量</td> <td class="style11"> 有效期</td> <td class="style15"> 入库日期</td> <td> 生产日期</td> <td>仓库编号</td> </tr> <tr> <td class="style11"> <asp:Label ID="lbproStockID" runat="server" CssClass="gray2"></asp:Label> </td> <td class="style12"> <asp:Label ID="Label2" runat="server" CssClass="gray2"></asp:Label> </td> <td class="style13"> <asp:Label ID="lbProBatch" runat="server" CssClass="gray2"></asp:Label> </td> <td class="style14"> <asp:TextBox ID="txtCount" onkeyup="isOvercount()" runat="server" CssClass="input" Width="41px"></asp:TextBox> </td> <td class="style11"> <asp:Label ID="lbExpDate" runat="server" CssClass="gray2"></asp:Label> </td> <td class="style15"> <asp:Label ID="lbStockDate" runat="server" CssClass="gray2"></asp:Label> </td> <td> <asp:Label ID="lbMakeDate" runat="server" CssClass="gray2"></asp:Label> </td> <td> <asp:Label ID="lbstockid" runat="server" CssClass="gray2"></asp:Label> </td> </tr> </table> </td> </tr> <tr> <td class="style19"> <table cellpadding="0" cellspacing="0" style=" width:99%; margin:10px;" > <tr> <td style=" text-align:right;"> <span><input id="Button1" class="btn1" onclick="returnSendEdit()" style=" width:80px;" type="button" value="确定" /></span> <span><input id="Button2" class="btn2" style=" width:80px;" onclick="{window.close()}" type="button" value="关闭" /></span></td> </tr> </table> </td> </tr> <tr> <td class="style19"> </td> </tr> </table> </div> </div> </form> </body> </html>
后台的代码:
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["proID"] != null && Request.QueryString["proID"] != "") { this.GridView1.DataSource = SqlComm.GetDataByCondition("dbo.BioProStock", "*,ProName=dbo.FN_getProNameByProID(proid)", "ProId=" + Request.QueryString["proID"]); this.GridView1.DataBind(); } }
发货产品添加批号,对应修改产品库存数量:
--发货产品添加批号,对应修改产品库存数量 --====================================== CREATE PROC [dbo].[BioProStockUpdateCount] ( @ID INT, @ProCout INT --此产品批次的数量 ) AS DECLARE @realCount INT SELECT @realCount= ProCout FROM dbo.BioProStock WHERE ID=@ID IF(@realCount>@ProCout) BEGIN UPDATE dbo.BioProStock SET ProCout=@realCount-@ProCout WHERE ID=@ID END ELSE BEGIN DELETE FROM dbo.BioProStock WHERE ID=@ID END