ERP系统之采购(一) (T-SQL+VIEW+ASP.NET+模版+自定义用户控件+AJAX)

     前不久由于数据库结构的更改,故重新修改了ERP的功能。下面描述一下ERP系统中的采购和采购退货业务流程以及代码描述。由于本文章较长,请大家自备水、食物以及保健用品,如有观看此文章内伤之人,本作者概不负责。

  采购功能,是为企业采购货物。此流程包含有:①新建采购单;②在采购单中添加供应商以及需要产品的库房和采购备注;③在采购单中添加需要采购的产品;④进行审核;⑤打印采购单;⑥收货。

  在整个的采购功能中,必须先规划好数据库的结构。就目前而言,数据库中要建立的表有:

  ①总库存表;

  ②批次库存表;

  ③仓位库存表;

  ④批次库存表;

  ⑤仓位库存表;

  ⑥历史批次出入库表;

  ⑦历史仓位出入库表;

  ⑧采购单表;

  ⑨采购明细表; 

  创建的总库存(Stock)表  

具体结构如下图所示:

  

  创建批次库存表(StockBatch)

具体结构如下图所示:

创建仓位库存(StocPlace)

  具体结构如下图所示:

创建历史批次表(HistoryBatch)

 具体结构如下图所示:

创建历史仓位表(HistoryStock)

具体表结构如下图所示:

创建采购表(PurchaseOrder)

 

具体表结构如下图所示:

创建采购明细表(PurchaseOrderDeatail)

具体表结构如下图所示:

  创建表格完成后具体分析需要的页面结点。总上所述页面节点为:1、新建采购单、2、审核、3、收货。但是在各个页面中都需要什么功能呢?一个使用方便的功能决定了整个系统的布局。

  1、新建采购单:①进入页面时要显示状态为“新建”状态的所有采购单的信息,包括“采购单号”、“库房”、“供应商”、“采购员”、“采购日期”、“数量”、“采购实洋”、“当前状态”、“操作”。其中“操作”中显示的是“修改”,当采购单还没有进行审核时是可以进行修改的。而在修改页面中需要显示的具体的采购明细。下面就开始着手去做吧。

  ①当建立采购单时,需要在数据库的“采购单表”中生成采购单。其中包含内容为:“采购单号(自增)”、“采购员”、“采购日期”为详细信息,此时采购单的状态为“10”。属于“新增采购单/待审”  

  ②新建完成后,需要添加据图的采购明细,新建一个产品搜索页面,可对需要采购的产品进行搜索,然后添加到采购页面中。具体的搜索页面效果如图:

  

 具体的前台页面代码如图:

  

View Code
  1 <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Content.master" CodeFile="SelectBook.aspx.cs"
  2     Inherits="WBPmodule_Book_BookInfo_SelectBook" %>
  3 
  4 <asp:Content ID="PageHead" ContentPlaceHolderID="PageHead" runat="Server">
  5     <base target="_self"/>
  6     <script type="text/javascript">
  7         $(document).ready(function () {
  8             //隔行换色
  9             setTrColor("ListTable");
 10             $("input[name='BiCode']").select();
 11 
 12             //绑定批销单回车键
 13             $("input[name='BiCode']").bind('keyup', function (event) {
 14                 if (event.keyCode == "13") {
 15                     //获取订单信息
 16                     if ($("input[name='BiCode']").val() != "") {
 17                         Search();
 18                     }
 19                 }
 20             });
 21 
 22             //绑定批销单回车键
 23             $("input[name='BiName']").bind('keyup', function (event) {
 24                 if (event.keyCode == "13") {
 25                     //获取订单信息
 26                     if ($("input[name='BiName']").val() != "") {
 27                         Search();
 28                     }
 29                 }
 30             });
 31         });
 32 
 33         function Search() {
 34             form1.submit();
 35         }
 36 
 37         //将所有值返回到父窗口
 38         function doSearch(biID) {
 39             window.returnValue = biID;
 40             window.close();
 41         } 
 42     </script>
 43 </asp:Content>
 44 <asp:Content ID="QuickAction" ContentPlaceHolderID="QuickAction" runat="Server">
 45     <form id="form1" runat="server" action="">
 46     条码:<input name="BiCode" value="<%=BiCode %>" style="width:120px;" />
 47     书名:<input name="BiName" value="<%=BiName %>" style="width:100px;" />
 48     </form>
 49 </asp:Content>
 50 <asp:Content ID="ContentBody" ContentPlaceHolderID="ContentBody" runat="Server">
 51     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="ListTable">
 52         <tr>
 53             <td class="ListTitle" style="width: 8%;">
 54                 商品ID
 55             </td>
 56             <td class="ListTitle" style="width: 10%;">
 57                 条形码
 58             </td>
 59             <td class="ListTitle" style="width: 45%;">
 60                 书名
 61             </td>
 62             <td class="ListTitle" style="width: 25%;">
 63                 出版社
 64             </td>
 65             <td class="ListTitle" style="width: 6%;">
 66                 定价
 67             </td>
 68             <td class="ListTitle" style="width: 6%;">
 69                 操作
 70             </td>
 71         </tr>
 72         <%
 73             for (int i = 0; i < BookInfoList.Count; i++)
 74             {
 75         %>
 76         <tr>
 77             <td class="ListContent">
 78                 <%= WebUtility.CreateBookCode(BookInfoList[i].BiID)%>
 79             </td>
 80             <td class="ListContent">
 81                 <%= BookInfoList[i].BiCode%>
 82             </td>
 83             <td class="ListContent">
 84                 <%= BookInfoList[i].BiName%>
 85             </td>
 86             <td class="ListContent">
 87                 <%= BookInfoList[i].BibsID.BsName%>
 88             </td>
 89             <td class="ListContent">
 90                 <%= BookInfoList[i].BiPrice%>
 91             </td>
 92             <td class="ListContent">
 93                 <a href="javascript:doSearch('<%= BookInfoList[i].BiID%>')">选择</a>
 94 
 95             </td>
 96         </tr>
 97         <%
 98             }
 99         %>
100         <tr>
101             <td colspan="6" id="ListTotal" class="ListTotal">
102             </td>
103         </tr>
104     </table>
105 </asp:Content>

 

后台代码如图:

View Code
 1 using System;
 2 using System.Collections.Generic;
 3 
 4 using BNutility;
 5 using BNmodel;
 6 using BNbll;
 7 
 8 public partial class WBPmodule_Book_BookInfo_SelectBook : System.Web.UI.Page
 9 {
10     //声明图书条形码变量
11     protected string BiCode = "";
12     //声明图书名称变量
13     protected string BiName = "";
14     //声明图书信息业务逻辑
15     BookInfoManager BookInfo_Bll = new BookInfoManager();
16 
17     //声明图书信息实例
18     protected List<BookInfo> BookInfoList = new List<BookInfo>();
19     protected void Page_Load(object sender, EventArgs e)
20     {
21 
22         BiCode = Request.Form["biCode"];
23         BiName = Request.Form["biName"];
24         List<SqlWhere> sqlwhere = new List<SqlWhere>();
25         sqlwhere.Add(new SqlWhere(BookInfo.BISTATUS, SqlWhere.Oper.Equal, 1));
26         //sqlwhere.Add(new SqlWhere(BookInfo.BIISCOMPOSE, SqlWhere.Oper.Equal, 0));
27 
28         //条形码和书名
29         if (!String.IsNullOrEmpty(BiCode))
30         {
31             sqlwhere.Add(new SqlWhere(BookInfo.BICODE, SqlWhere.Oper.Equal, BiCode));
32         }
33         if (!String.IsNullOrEmpty(BiName))
34         {
35             sqlwhere.Add(new SqlWhere(BookInfo.BINAME, SqlWhere.Oper.Like, BiName));
36         }
37         if (!String.IsNullOrEmpty(BiCode) || !String.IsNullOrEmpty(BiName))
38         {
39             BookInfoList = BookInfo_Bll.GetList(0, 0, "biID,biName,biCode,bibsID:{bsName},biPrice", sqlwhere, null);
40         }
41 
42     }
43 }

当单击添加添加后,会生成一条“采购明细”,其中会有一个文本框,文本框中输入的是的申请采购的数量。单击空白处,保存数值。此时,在采购明细表中的prodApplyAmount,则会发生变化。

③其中在每一条明细的后面都可以进行删除操作,当进行删除操作时,将会删除明细表中的数据。

具体前台代码如图所示:

 

View Code
  1 <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Manage.master" CodeFile="ApplyEdit.aspx.cs"
  2     Inherits="WBPmodule_Purchase_In_ApplyEdit" %>
  3 
  4 <asp:Content ID="PageHead" ContentPlaceHolderID="PageHead" runat="Server">
  5     <script src="http://www.cnblogs.com/../JS/JQuery.js" type="text/javascript"></script>
  6     <script type="text/javascript">
  7         $(document).ready(function () {
  8             //绑定验证
  9             ValidForm();
 10 
 11             //隔行换色
 12             setTrColor("ListTable");
 13 
 14             //计算总数
 15             CheckTotal();
 16 
 17         });
 18 
 19         var DontActionStatus = ",Auditor,Difference,InStock,NotConfirmation,Confirmation,NotAccounting,Accounting,Delete,";
 20 
 21         //保存主单
 22         function SavePurchase() {
 23             if (SubmitValidForm($("#PurchaseOrder"))) {
 24                 $.ajax({
 25                     url: "Ajax.ashx",
 26                     data: {
 27                         OpType: "SavePurchaseOrder",
 28                         PoID: parseInt($("input[name='poID']").val().replace("CG", ""), 10),
 29                         SdcID: $("select[name='sdcID']").val(),
 30                         BsID: $("select[name='bsID']").val(),
 31                         PoEstimateDate: $("input[name='poEstimateDate']").val(),
 32                         PoRemark: $("input[name='poRemark']").val()
 33                     },
 34                     async: true,
 35                     cache: false,
 36                     dataType: "html",
 37                     error: function (a, b, c) {
 38                         if (b == "error") {
 39                             var InfoStatus = "lose";
 40                             var InfoContent = "采购单保存失败";
 41                             var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 42                             ShowInfo(InfoStatus, InfoContent, InfoAction);
 43                         }
 44                     },
 45                     success: function (Result) {
 46                         if (DontActionStatus.indexOf("," + Result + ",") >= 0) {
 47                             var InfoStatus = "lose";
 48                             var InfoContent = "采购单保存失败<br />" + GetPurchaseStatus(Result);
 49                             var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 50                             ShowInfo(InfoStatus, InfoContent, InfoAction);
 51                         }
 52                         else {
 53                             var InfoStatus = "win";
 54                             var InfoContent = "采购单保存成功";
 55                             var InfoAction = "<a href=\"javascript:RedirectPage('170202', 'EditPoID=" + Result + "')\">确定</a>";
 56                             ShowInfo(InfoStatus, InfoContent, InfoAction);
 57                         }
 58                     }
 59                 });
 60             }
 61         }
 62 
 63         //添加明细
 64         function AddDetail() {
 65             var PoID = parseInt($("input[name='poID']").val().replace("CG", ""), 10);
 66             if (PoID > 0) {
 67                 if (SubmitValidForm($("#ListTable"))) {
 68                     var BiID = MakeAnotherWindow('http://www.cnblogs.com/Book/BookInfo/SelectBook.aspx', '', '750', '550', 'yes');
 69                     if (BiID != "") {
 70                         $.ajax({
 71                             url: "Ajax.ashx",
 72                             data: {
 73                                 OpType: "GetBookInfo",
 74                                 PoID: PoID,
 75                                 BiID: BiID,
 76                                 SdcID: $("select[name='sdcID']").val()
 77                             },
 78                             async: true,
 79                             cache: false,
 80                             dataType: "html",
 81                             error: function (a, b, c) {
 82                                 if (b == "error") {
 83                                     var InfoStatus = "lose";
 84                                     var InfoContent = "图书信息获取失败";
 85                                     var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 86                                     ShowInfo(InfoStatus, InfoContent, InfoAction);
 87                                 }
 88                             },
 89                             success: function (Result) {
 90                                 if (DontActionStatus.indexOf("," + Result + ",") >= 0) {
 91                                     var InfoStatus = "lose";
 92                                     var InfoContent = "采购单保存失败<br />" + GetPurchaseStatus(Result);
 93                                     var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 94                                     ShowInfo(InfoStatus, InfoContent, InfoAction);
 95                                 }
 96                                 else {
 97                                     switch (Result) {
 98                                         case "Exist":
 99                                             $("#POD_AMOUNT_" + BiID).select();
100                                             break;
101                                         default:
102                                             $(Result).insertAfter($("#ListTable tr:eq(0)"));
103                                             if (parseFloat($("#POD_DISCOUNT_" + BiID).val()) > 0) {
104                                                 //指定折扣焦点
105                                                 $("#POD_AMOUNT_" + BiID).select();
106                                             }
107                                             else {
108                                                 //指定折扣焦点
109                                                 $("#POD_DISCOUNT_" + BiID).select();
110                                             }
111 
112                                             //绑定折扣回车键
113                                             $("#POD_DISCOUNT_" + BiID).bind('keyup', function (event) {
114                                                 if (event.keyCode == "13") {
115                                                     //获取订单信息
116                                                     $("#POD_AMOUNT_" + BiID).select();
117                                                 }
118                                             });
119                                             //绑定数量回车键
120                                             $("#POD_AMOUNT_" + BiID).bind('keyup', function (event) {
121                                                 if (event.keyCode == "13") {
122                                                     //获取订单信息
123                                                     $("#POD_STOCK_" + BiID).select();
124                                                 }
125                                             });
126                                             //绑定供应商库存回车键
127                                             $("#POD_STOCK_" + BiID).bind('keyup', function (event) {
128                                                 if (event.keyCode == "13") {
129                                                     //获取订单信息
130                                                     $("#POD_ESTIMATE_" + BiID).select();
131                                                 }
132                                             });
133                                             break;
134                                     }
135                                 }
136                             }
137                         });
138                     }
139                 }
140             } else {
141                 alert("请先保存采购单信息");
142             }
143         }
144 
145         //保存明细
146         function SaveDetail(BiID) {
147             $("#POD_STATUS_" + BiID).html("");
148             var PoID = parseInt($("input[name='poID']").val().replace("CG", ""), 10);
149             if (PoID > 0) {
150                 if (SubmitValidForm($("#ListTable"))) {
151                     $.ajax({
152                         url: "Ajax.ashx",
153                         data: {
154                             OpType: "SaveDetail",
155                             PoID: PoID,
156                             BiID: BiID,
157                             SdcID: $("select[name='sdcID']").val(),
158                             Price: $("#POD_PRICE_" + BiID).val(),
159                             Amount: $("#POD_AMOUNT_" + BiID).val(),
160                             Stock: $("#POD_STOCK_" + BiID).val(),
161                             Estimate: $("#POD_ESTIMATE_" + BiID).val()
162                         },
163                         async: true,
164                         cache: false,
165                         dataType: "html",
166                         error: function (a, b, c) {
167                             if (b == "error") {
168                                 $("#POD_STATUS_" + BiID).html("<img src=\"http://www.cnblogs.com/../Image/error.png\">");
169                             }
170                         },
171                         success: function (Result) {
172                             if (DontActionStatus.indexOf("," + Result + ",") >= 0) {
173                                 var InfoStatus = "lose";
174                                 var InfoContent = "采购单保存失败<br />" + GetPurchaseStatus(Result);
175                                 var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
176                                 ShowInfo(InfoStatus, InfoContent, InfoAction);
177                             }
178                             else {
179                                
180                                 $("#POD_STATUS_" + BiID).html("<img src=\"http://www.cnblogs.com/../Image/right.png\">");
181                                 CheckTotal();
182                             }
183 
184                         }
185                     });
186                 }
187             } else {
188                 alert("请先保存采购单信息");
189             }
190         }
191 
192         //通过折扣计算实洋
193         function CheckPrice(biID, biPrice) {
194             $("#POD_PRICE_" + biID).val((biPrice * $("#POD_DISCOUNT_" + biID).val() / 100).toFixed(4));
195             SaveDetail(biID);
196         }
197 
198         //汇总
199         function CheckTotal() {
200             var CountPrice = 0;
201             var CountAmount = 0;
202             $("TR[name='PurchaseDetail']").each(function () {
203                 var BiID = $(this).attr("id");
204 
205                 //绑定折扣回车键
206                 $("#POD_DISCOUNT_" + BiID).bind('keyup', function (event) {
207                     if (event.keyCode == "13") {
208                         //获取订单信息
209                         $("#POD_AMOUNT_" + BiID).select();
210                     }
211                 });
212                 //绑定数量回车键
213                 $("#POD_AMOUNT_" + BiID).bind('keyup', function (event) {
214                     if (event.keyCode == "13") {
215                         //获取订单信息
216                         $("#POD_STOCK_" + BiID).select();
217                     }
218                 });
219                 //绑定供应商库存回车键
220                 $("#POD_STOCK_" + BiID).bind('keyup', function (event) {
221                     if (event.keyCode == "13") {
222                         //获取订单信息
223                         $("#POD_ESTIMATE_" + BiID).select();
224                     }
225                 });
226 
227                 CountPrice += parseFloat($("#POD_PRICE_" + BiID).val()) * parseFloat($("#POD_AMOUNT_" + BiID).val());
228                 CountAmount += parseInt($("#POD_AMOUNT_" + BiID).val());
229             });
230             $("#Price_Total").val(CountPrice.toFixed(4));
231             $("#Amount_Total").val($("TR[name='PurchaseDetail']").length + "(" + CountAmount + ")");
232         }
233 
234         function DeleteDetail(BiID) {
235             $.ajax({
236                 url: "Ajax.ashx",
237                 data: {
238                     OpType: "DeleteDetail",
239                     PoID: parseInt($("input[name='poID']").val().replace("CG", ""), 10),
240                     BiID: BiID
241                 },
242                 async: false,
243                 cache: false,
244                 dataType: "html",
245                 error: function (a, b, c) {
246                     if (b == "error") {
247                         var InfoStatus = "lose";
248                         var InfoContent = "采购明细删除失败";
249                         var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
250                         ShowInfo(InfoStatus, InfoContent, InfoAction);
251                     }
252                 },
253                 success: function (Result) {
254                     if (Result == "false") {
255                         var InfoStatus = "lose";
256                         var InfoContent = "采购明细删除失败<br />" + GetPurchaseStatus(Result);
257                         var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
258                         ShowInfo(InfoStatus, InfoContent, InfoAction);
259                     }
260                     else {
261                         $("TR").remove("#" + BiID);
262                     }
263                     CheckTotal();
264                 }
265             });
266         }
267 
268         //通过折扣计算实洋
269         function CheckPrice(biID, biPrice) {
270             $("#POD_PRICE_" + biID).val((biPrice * $("#POD_DISCOUNT_" + biID).val() / 100).toFixed(4));
271             SaveDetail(biID);
272         }
273 
274     </script>
275 </asp:Content>
276 <asp:Content ID="QuickAction" ContentPlaceHolderID="QuickAction" runat="Server">
277     <a href="JavaScript:AddDetail()">新增明细</a> | <a href="JavaScript:RedirectPage('170201','page=<%= page%>&poID=<%= poID%>&sdcID=<%= sdcID%>&bsID=<%= bsID%>&poStatus=<%= poStatus%>&poDateBegin=<%= poDateBegin%>&poDateEnd=<%= poDateEnd%>&poEstimateDateBegin=<%= poEstimateDateBegin%>&poEstimateDateEnd=<%= poEstimateDateEnd%>')">
278         返回</a>
279 </asp:Content>
280 <asp:Content ID="Search" ContentPlaceHolderID="Search" runat="Server">
281     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="PurchaseOrder">
282         <tr>
283             <td id="poID_Title" class="SearchTitle" style="width: 10%">
284             </td>
285             <td style="width: 13%">
286                 <input name="poID" type="text" title="采购单号" value="<%=  WebUtility.CreatePurchaseOrderCode(EditPoID)%>"
287                     notnull disabled />
288             </td>
289             <td id="sdcID_Title" class="SearchTitle" style="width: 10%">
290             </td>
291             <td style="width: 13%">
292                 <select name="sdcID" title="采购库房" style="width: 100%;" notnull>
293                     <option value="">全部</option>
294                     <%
295                         for (int i = 0; i < StockDataClass_List.Count; i++)
296                         {
297                     %>
298                     <option value="<%= StockDataClass_List[i].SdcID%>" <%= (StockDataClass_List[i].SdcID == EditSdcID) ? "selected" : ""%>>
299                         <%= StockDataClass_List[i].SdcName%></option>
300                     <%
301                         }
302                     %>
303                 </select>
304             </td>
305             <td id="bsID_Title" class="SearchTitle" style="width: 10%">
306             </td>
307             <td style="width: 13%">
308                 <select name="bsID" title="供 应 商" style="width: 100%;" notnull>
309                     <option value="">全部</option>
310                     <%
311             
312                         for (int i = 0; i < BookSupply_List.Count; i++)
313                         {
314                     %>
315                     <option value="<%= BookSupply_List[i].BsID%>" <%= (BookSupply_List[i].BsID == EditBsID) ? "selected" : ""%>>
316                         <%= BookSupply_List[i].BsName%></option>
317                     <%
318                         }
319                     %>
320                 </select>
321             </td>
322             <td id="poEstimateDate_Title" class="SearchTitle" style="width: 10%">
323             </td>
324             <td style="width: 13%">
325                 <input name="poEstimateDate" type="text" title="到货日期" onclick="SetDateTime(this, false)"
326                     notnull readonly value="<%=EstimateDate %>" />
327             </td>
328             <td rowspan="2" style="width: 8%" align="center">
329                 <input id="Save" type="button" value="保存" onclick="SavePurchase()" />
330             </td>
331         </tr>
332         <tr>
333             <td id="poRemark_Title" class="SearchTitle" style="width: 10%">
334             </td>
335             <td colspan="3">
336                 <input name="poRemark" type="text" title="采购备注"  value="<%=PoRemark %>"/>
337             </td>
338             <td id="poAuditorRemark_Title" class="SearchTitle" style="width: 10%" >
339             </td>
340             <td colspan="3">
341                 <input name="poAuditorRemark" type="text" title="审核意见" disabled />
342             </td>
343         </tr>
344     </table>
345 </asp:Content>
346 <asp:Content ID="ContentBody" ContentPlaceHolderID="ContentBody" runat="Server">
347     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="ListTable">
348         <tr>
349             <td class="ListTitle" style="width: 3%">
350             </td>
351             <td class="ListTitle" style="width: 7%">
352                 商品ID
353             </td>
354             <td class="ListTitle" style="width: 7%">
355                 条形码
356             </td>
357             <td class="ListTitle" style="width: 28%">
358                 书名
359             </td>
360             <td class="ListTitle" style="width: 12%">
361                 出版社
362             </td>
363             <td class="ListTitle" style="width: 6%">
364                 定价
365             </td>
366             <td class="ListTitle" style="width: 5%">
367                 折扣
368             </td>
369             <td class="ListTitle" style="width: 6%">
370                 采购实洋
371             </td>
372             <td class="ListTitle" style="width: 6%">
373                 采购数量
374             </td>
375             <td class="ListTitle" style="width: 7%">
376                 供应商库存
377             </td>
378             <td class="ListTitle" style="width: 8%">
379                 供货周期(天)
380             </td>
381             <td class="ListTitle" style="width: 5%">
382                 操作
383             </td>
384         </tr>
385         <%
386             for (int i = 0; i < PurchaseOrderDetail_List.Count; i++)
387             {
388                 int PodDiscount = 0;
389                 int Stock = 0;
390                 int Estimate = 0;
391                 if (PurchaseOrderDetail_List[i].BiID.BiPrice > 0)
392                 {
393 
394                     PodDiscount = Convert.ToInt32(PurchaseOrderDetail_List[i].PodPrice / PurchaseOrderDetail_List[i].BiID.BiPrice * 100);
395                 }
396 
397                 dt = GetStock(Convert.ToInt32(PurchaseOrderDetail_List[i].PoID.PoID));
398                 if (dt.Rows.Count > 0)
399                 {
400                     Stock = Convert.ToInt32(dt.Rows[i]["sPurchaseAmount"]);
401                     Estimate = Convert.ToInt32(dt.Rows[i]["sPurchaseCycle"]);
402                 }
403                
404         %>
405         <tr name="PurchaseDetail" id="<%= PurchaseOrderDetail_List[i].BiID.BiID%>">
406             <td class="ListContent" id="POD_STATUS_<%= PurchaseOrderDetail_List[i].BiID.BiID%>">
407             </td>
408             <td class="ListContent">
409                 <%= WebUtility.CreateBookCode(PurchaseOrderDetail_List[i].BiID.BiID)%>
410             </td>
411             <td class="ListContent">
412                 <%= PurchaseOrderDetail_List[i].BiID.BiCode%>
413             </td>
414             <td class="ListContent">
415                 <%= PurchaseOrderDetail_List[i].BiID.BiName%>
416             </td>
417             <td class="ListContent">
418                 <%= PurchaseOrderDetail_List[i].BiID.BibsID.BsName%>
419             </td>
420             <td class="ListContent">
421                 <%= PurchaseOrderDetail_List[i].BiID.BiPrice.ToString("F2")%>
422             </td>
423             <td class="ListContent">
424                 <input id="POD_DISCOUNT_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" type="text"
425                     value="<%=PodDiscount %>" style="text-align: right;" datatype="n0" onchange="CheckPrice('<%= PurchaseOrderDetail_List[i].BiID.BiID%>','<%= PurchaseOrderDetail_List[i].BiID.BiPrice%>')" />
426             </td>
427             <td class="ListContent">
428                 <input id="POD_PRICE_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" value="<%= PurchaseOrderDetail_List[i].PodPrice.ToString("F4")%>"
429                     type="text" style="text-align: right;" onchange="SaveDetail('<%= PurchaseOrderDetail_List[i].BiID.BiID%>')"
430                     datatype="d0" notnull />
431             </td>
432             <td class="ListContent">
433                 <input id="POD_AMOUNT_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" value="<%= PurchaseOrderDetail_List[i].PodBuyAmount%>"
434                     type="text" style="text-align: right;" onchange="SaveDetail('<%= PurchaseOrderDetail_List[i].BiID.BiID%>')"
435                     datatype="n1" notnull />
436             </td>
437             <td class="ListContent">
438                 <input id="POD_STOCK_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" type="text" style="text-align: right;"
439                     value="<%=Stock %>" onchange="SaveDetail('<%= PurchaseOrderDetail_List[i].BiID.BiID%>')"
440                     datatype="n0" notnull />
441             </td>
442             <td class="ListContent">
443                 <input id="POD_ESTIMATE_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" type="text"
444                     value="<%=Estimate %>" onchange="SaveDetail('<%= PurchaseOrderDetail_List[i].BiID.BiID%>')"
445                     style="text-align: right;" datatype="n0" notnull />
446             </td>
447             <td class="ListContent">
448                 <a href="javascript:DeleteDetail('<%= PurchaseOrderDetail_List[i].BiID.BiID%>')">删除</a>
449             </td>
450         </tr>
451         <%      
452             }
453         %>
454         <tr>
455             <td class="ListTotal" colspan="6" style="text-align: right;">
456                 合计:
457             </td>
458             <td class="ListTotal" colspan="2">
459                 <input id="Price_Total" type="text" style="text-align: right;" disabled />
460             </td>
461             <td class="ListTotal">
462                 <input id="Amount_Total" type="text" style="text-align: right;" disabled />
463             </td>
464             <td class="ListTotal" colspan="3">
465             </td>
466         </tr>
467     </table>
468 </asp:Content>

 

具体后台代码如图所示:

View Code
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Web.UI;
  4 
  5 using BNbll;
  6 using BNmodel;
  7 using BNutility;
  8 using System.Data;
  9 
 10 public partial class WBPmodule_Purchase_In_ApplyEdit : System.Web.UI.Page
 11 {
 12     protected int page = 1;
 13     protected string poID = "";
 14     protected string sdcID = "";
 15     protected string bsID = "";
 16     protected string poStatus = "";
 17     protected string poDateBegin = "";
 18     protected string poDateEnd = "";
 19     protected string poEstimateDateBegin = "";
 20     protected string poEstimateDateEnd = "";
 21     protected string bsID_Responsible = "";
 22 
 23     protected int EditPoID;
 24     protected int EditSdcID = 34;
 25     protected int EditBsID = 0;
 26     protected string EstimateDate = DateTime.Now.ToString("yyyy-MM-dd");
 27     protected string PoRemark = "";
 28     protected string PoAuditorRemark = "";
 29     protected DataTable dt;
 30 
 31 
 32     protected List<StockDataClass> StockDataClass_List = new List<StockDataClass>();
 33     protected List<BookSupply> BookSupply_List = new List<BookSupply>();
 34     protected List<PurchaseOrderDetail> PurchaseOrderDetail_List = new List<PurchaseOrderDetail>();
 35 
 36 
 37     BookSupplyManager BookSupply_Bll = new BookSupplyManager();
 38     SYS_UserInfoManager UserInfo_Bll = new SYS_UserInfoManager();
 39     StockDataClassManager StockDataClass_Bll = new StockDataClassManager();
 40     PurchaseOrderManager PurchaseOrder_Bll = new PurchaseOrderManager();
 41     PurchaseOrderDetailManager PurchaseOrderDetail_Bll = new PurchaseOrderDetailManager();
 42 
 43 
 44     protected void Page_Load(object sender, EventArgs e)
 45     {
 46         poID = Request.QueryString["poID"];
 47         sdcID = Request.QueryString["sdcID"];
 48         bsID = Request.QueryString["bsID"];
 49         poStatus = Request.QueryString["poStatus"];
 50         poDateBegin = Request.QueryString["poDateBegin"];
 51         poDateEnd = Request.QueryString["poDateEnd"];
 52         poEstimateDateBegin = Request.QueryString["poEstimateDateBegin"];
 53         poEstimateDateEnd = Request.QueryString["poEstimateDateEnd"];
 54         page = WebUtility.CheckParamID(Request.QueryString["Page"], page);
 55 
 56 
 57         if (!String.IsNullOrEmpty(Request.QueryString["EditPoID"]))
 58         {
 59             EditPoID = WebUtility.CheckParamID(Request.QueryString["EditPoID"], 0);
 60             PurchaseOrder PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(EditPoID, "SdcID:{SdcID},BsID:{BsID},PoEstimateDate,PoRemark,PoAuditorRemark");
 61             EditSdcID = PurchaseOrder_Info.SdcID.SdcID;
 62             EditBsID = PurchaseOrder_Info.BsID.BsID;
 63             EstimateDate = PurchaseOrder_Info.PoEstimateDate.ToString("yyyy-MM-dd");
 64             PoRemark = PurchaseOrder_Info.PoRemark;
 65             PoAuditorRemark = PurchaseOrder_Info.PoAuditorRemark;
 66 
 67             List<SqlWhere> PurchaseOrderDetailWhere = new List<SqlWhere>();
 68             PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, EditPoID));
 69             PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "PoID:{PoID},BiID:{BiID,BiCode,BiName,BibsID:{BsName},BiPrice},PodPrice,PodBuyAmount", PurchaseOrderDetailWhere, null);
 70         }
 71 
 72         if (UserInfo_Bll.CookieUserID != "0")
 73         {
 74             BookSupplyManager BookSupplyResponsible_Bll = new BookSupplyManager();
 75             List<BookSupply> BookSupplyResponsible_List = new List<BookSupply>();
 76             List<SqlWhere> BookSupplyResponsibleWhere = new List<SqlWhere>();
 77             BookSupplyResponsibleWhere.Add(new SqlWhere(BookSupply.BSISSUPPLIER, SqlWhere.Oper.Equal, 1));
 78             BookSupplyResponsibleWhere.Add(new SqlWhere(BookSupply.BSSTATUS, SqlWhere.Oper.Equal, 1));
 79             BookSupplyResponsibleWhere.Add(new SqlWhere(BookSupply.BSSALESMAN, SqlWhere.Oper.Equal, UserInfo_Bll.CookieUserID));
 80             BookSupplyResponsible_List = BookSupplyResponsible_Bll.GetList(0, 0, "bsID", BookSupplyResponsibleWhere, null);
 81             if (BookSupply_List.Count > 0)
 82             {
 83                 for (int i = 0; i < BookSupplyResponsible_List.Count; i++)
 84                 {
 85                     bsID_Responsible += "," + BookSupplyResponsible_List[i].BsID;
 86                 }
 87                 bsID_Responsible = bsID_Responsible.Substring(1, bsID_Responsible.Length - 1);
 88             }
 89         }
 90 
 91         List<SqlWhere> StockDataCalssWhere = new List<SqlWhere>();
 92         StockDataCalssWhere.Add(new SqlWhere(StockDataClass.SDCID, SqlWhere.Oper.In, "31,34"));
 93         StockDataCalssWhere.Add(new SqlWhere(StockDataClass.SDCPARENTID, SqlWhere.Oper.Equal, 1));
 94         StockDataCalssWhere.Add(new SqlWhere(StockDataClass.SDCSTATUS, SqlWhere.Oper.Equal, 1));
 95         StockDataClass_List = StockDataClass_Bll.GetList(0, 0, "sdcID,sdcName", StockDataCalssWhere, null);
 96 
 97         List<SqlWhere> BookSupplyWhere = new List<SqlWhere>();
 98         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSID, SqlWhere.Oper.MoreEqual, 0));
 99         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSISSUPPLIER, SqlWhere.Oper.Equal, 1));
100         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSSTATUS, SqlWhere.Oper.Equal, 1));
101         if (!String.IsNullOrEmpty(bsID_Responsible))
102         {
103             BookSupplyWhere.Add(new SqlWhere(BookSupply.BSID, SqlWhere.Oper.In, bsID_Responsible));
104         }
105         List<SqlOrder> BookSupplyOrder = new List<SqlOrder>();
106         BookSupplyOrder.Add(new SqlOrder(BookSupply.BSNAME, true));
107         BookSupply_List = BookSupply_Bll.GetList(0, 0, "bsID,bsName", BookSupplyWhere, BookSupplyOrder);
108     }
109     public DataTable GetStock(int PoID)
110     {
111 
112         StockManager Stock_Bll = new StockManager();
113 
114 
115         dt = Stock_Bll.GetStock(PoID);
116         return dt;
117     }
118 
119 
120 }

此时也需要建立相应的AJAX一般处理程序,对数据库进行操作。具体代码如下所示:

View Code
  1 <%@ WebHandler Language="C#" Class="Ajax" %>
  2 
  3 using System;
  4 using System.Collections.Generic;
  5 using System.Web;
  6 
  7 using BNbll;
  8 using BNmodel;
  9 using BNutility;
 10 
 11 public class Ajax : IHttpHandler
 12 {
 13 
 14     public void ProcessRequest(HttpContext context)
 15     {
 16         string OpType = context.Request.QueryString["OpType"];
 17 
 18         string PoID = context.Request.QueryString["PoID"];
 19         string SdcID = context.Request.QueryString["SdcID"];
 20         string BsID = context.Request.QueryString["BsID"];
 21         string PoEstimateDate = context.Request.QueryString["PoEstimateDate"];
 22         string PoRemark = context.Request.QueryString["PoRemark"];
 23 
 24         string BiID = context.Request.QueryString["BiID"];
 25 
 26         string Price = context.Request.QueryString["Price"];
 27         string Amount = context.Request.QueryString["Amount"];
 28         string StockAmount = context.Request.QueryString["Stock"];
 29         string Estimate = context.Request.QueryString["Estimate"];
 30 
 31         string PoAuditorRemark = context.Request.QueryString["PoAuditorRemark"];
 32         string PoAuditorStatus = context.Request.QueryString["PoAuditorStatus"];
 33 
 34         string PoReceiveUser = context.Request.QueryString["PoReceiveUser"];
 35         string PoSupplierOrder = context.Request.QueryString["PoSupplierOrder"];
 36         string PoReceiveAuditorRemark = context.Request.QueryString["PoReceiveAuditorRemark"];
 37 
 38 
 39         string SendAmount = context.Request.QueryString["SendAmount"];
 40         string ReceiveAmount = context.Request.QueryString["ReceiveAmount"];
 41         string InStock = context.Request.QueryString["InStock"];
 42 
 43 
 44         string PoDifferenceStatus = context.Request.QueryString["PoDifferenceStatus"];
 45         string PoDifferenceAuditorRemark = context.Request.QueryString["PoDifferenceAuditorRemark"];
 46 
 47         string PoAccountingStatus = context.Request.QueryString["PoAccountingStatus"];
 48         string PoAccountRemark = context.Request.QueryString["PoAccountRemark"];
 49         string PoAccountCode = context.Request.QueryString["PoAccountCode"];
 50 
 51 
 52         //string SendAmount = context.Request.QueryString["SendAmount"];
 53         //string ReceiveAmount = context.Request.QueryString["ReceiveAmount"];
 54         //string InStock = context.Request.QueryString["InStock"];
 55 
 56 
 57 
 58         string Result = "";
 59 
 60 
 61 
 62 
 63         PurchaseOrderManager PurchaseOrder_Bll = new PurchaseOrderManager();
 64         List<SqlWhere> PurchaseOrderWhere = new List<SqlWhere>();
 65         List<PurchaseOrder> PurchaseOrder_List = new List<PurchaseOrder>();
 66         PurchaseOrder PurchaseOrder_Info = new PurchaseOrder();
 67 
 68 
 69 
 70         PurchaseOrderDetailManager PurchaseOrderDetail_Bll = new PurchaseOrderDetailManager();
 71         List<SqlWhere> PurchaseOrderDetailWhere = new List<SqlWhere>();
 72         List<SqlOrder> PurchaseOrderDetailOrder = new List<SqlOrder>();
 73         List<PurchaseOrderDetail> PurchaseOrderDetail_List = new List<PurchaseOrderDetail>();
 74         PurchaseOrderDetail PurchaseOrderDetail_Info = new PurchaseOrderDetail();
 75         StockManager Stock_Bll = new StockManager();
 76         List<Stock> Stock_List = new List<Stock>();
 77         DiscountManager Discount_Bll = new DiscountManager();
 78         List<Discount> Discount_List = new List<Discount>();
 79 
 80 
 81 
 82 
 83         BookInfoManager BookInfo_Bll = new BookInfoManager();
 84         List<SqlWhere> BookInfoWhere = new List<SqlWhere>();
 85         List<BookInfo> BookInfo_List = new List<BookInfo>();
 86         BookInfo BookInfo_Info = new BookInfo();
 87 
 88 
 89         SYS_UserInfoManager UserInfo_Bll = new SYS_UserInfoManager();
 90         BookSupplyManager BookSupply_Bll = new BookSupplyManager();
 91         StockDataClassManager StockDataClass_Bll = new StockDataClassManager();
 92 
 93         Stock Stock_Info = new Stock();
 94 
 95 
 96         switch (OpType)
 97         {
 98             //保存采购主单
 99             case "SavePurchaseOrder":
100 
101 
102                 if (!String.IsNullOrEmpty(PoID) && PoID != "0")
103                 {
104                     PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID,PoStatus");
105                 }
106                 if (PurchaseOrder_Info.PoStatus == 10 || PurchaseOrder_Info.PoStatus == 11)
107                 {
108                     PurchaseOrder_Info.SdcID = StockDataClass_Bll.GetModels(Convert.ToInt32(SdcID), "SdcID");
109                     PurchaseOrder_Info.BsID = BookSupply_Bll.GetModels(Convert.ToInt32(BsID), "BsID");
110                     PurchaseOrder_Info.PoUser = UserInfo_Bll.GetModels(Convert.ToInt32(UserInfo_Bll.CookieUserID), "SysuiID");
111                     PurchaseOrder_Info.PoEstimateDate = Convert.ToDateTime(PoEstimateDate);
112                     PurchaseOrder_Info.PoDate = DateTime.Now;
113                     PurchaseOrder_Info.PoStatus = 10;
114                     PurchaseOrder_Info.PoRemark = PoRemark;
115                     PurchaseOrder_Info.PoIsDifference = false;
116 
117                     if (PoID == "0")
118                     {
119                         PoID = PurchaseOrder_Bll.SaveModels(PurchaseOrder_Info).ToString();
120                     }
121                     else
122                     {
123                         PurchaseOrder_Bll.SaveModels(PurchaseOrder_Info);
124                     }
125                     Result = PoID;
126                 }
127                 else
128                 {
129                     Result = CheckStatus(PurchaseOrder_Info.PoStatus);
130                 }
131                 break;
132 
133 
134             //获取订单详细信息
135             case "GetBookInfo":
136                 if (!String.IsNullOrEmpty(PoID) && PoID != "0")
137                 {
138                     PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID,PoStatus");
139                     if (PurchaseOrder_Info.PoStatus == 10 || PurchaseOrder_Info.PoStatus == 11)
140                     {
141                         PurchaseOrderDetailWhere.Clear();
142                         PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, PoID));
143                         PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.BIID, SqlWhere.Oper.Equal, BiID));
144                         PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "PodID", PurchaseOrderDetailWhere, null);
145                         if (PurchaseOrderDetail_List.Count > 0)
146                         {
147                             Result = "Exist";
148                         }
149                         else
150                         {
151                             BookInfo_Info = BookInfo_Bll.GetModels(Convert.ToInt32(BiID), "BiID,BiCode,BiName,BibsID:{BsName},BiPrice");
152 
153                             PurchaseOrderDetail_Info.PoID = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID");
154                             PurchaseOrderDetail_Info.BiID = BookInfo_Bll.GetModels(Convert.ToInt32(BiID), "BiID");
155                             PurchaseOrderDetail_Info.PodPrice = 0;
156                             PurchaseOrderDetail_Info.PodBuyAmount = 0;
157                             PurchaseOrderDetail_Info.PodSendAmount = 0;
158                             PurchaseOrderDetail_Info.PodReceiveAmount = 0;
159                             PurchaseOrderDetail_Info.PodPayAmount = 0;
160                             PurchaseOrderDetail_Info.PodReturnAmount = 0;
161                             PurchaseOrderDetail_Info.PodPlace = "";
162                             PurchaseOrderDetail_Bll.SaveModels(PurchaseOrderDetail_Info);
163 
164                             double DInDiscount = 0;
165                             List<SqlWhere> Discount_Where = new List<SqlWhere>();
166                             Discount_Where.Add(new SqlWhere(Discount.BIID, SqlWhere.Oper.Equal, BiID));
167                             List<SqlOrder> Discount_Order = new List<SqlOrder>();
168                             Discount_Order.Add(new SqlOrder(Discount.DID, false));
169                             Discount_List = Discount_Bll.GetList(1, 1, "dInDiscount", Discount_Where, Discount_Order);
170                             if (Discount_List.Count > 0)
171                             {
172                                 DInDiscount = Discount_List[0].DInDiscount;
173                             }
174 
175 
176                             int sPurchaserCycle = 0;
177                             int sPurchaseAmount = 0;
178                             List<SqlWhere> Stock_Where = new List<SqlWhere>();
179                             Stock_Where.Add(new SqlWhere(Stock.BIID, SqlWhere.Oper.Equal, BiID));
180                             Stock_Where.Add(new SqlWhere(Stock.SDCID, SqlWhere.Oper.Equal, SdcID));
181                             Stock_List = Stock_Bll.GetList(1, 1, "SPurchaseCycle,sPurchaseAmount", Stock_Where, null);
182                             if (Stock_List.Count > 0)
183                             {
184                                 sPurchaserCycle = Stock_List[0].SPurchaseCycle;
185                                 sPurchaseAmount = Stock_List[0].SPurchaseAmount;
186                             }
187 
188 
189                             Result += "<tr name=\"PurchaseDetail\" id=\"" + BookInfo_Info.BiID + "\">";
190                             Result += "    <td class=\"ListContent\" id=\"POD_STATUS_" + BookInfo_Info.BiID + "\"></td>";
191                             Result += "    <td class=\"ListContent\">";
192                             Result += "        " + WebUtility.CreateBookCode(BookInfo_Info.BiID);
193                             Result += "    </td>";
194                             Result += "    <td class=\"ListContent\">";
195                             Result += "        " + BookInfo_Info.BiCode;
196                             Result += "    </td>";
197                             Result += "    <td class=\"ListContent\">";
198                             Result += "        " + BookInfo_Info.BiName;
199                             Result += "    </td>";
200                             Result += "    <td class=\"ListContent\">";
201                             Result += "        " + BookInfo_Info.BibsID.BsName;
202                             Result += "    </td>";
203                             Result += "    <td class=\"ListContent\">";
204                             Result += "        " + BookInfo_Info.BiPrice;
205                             Result += "    </td>";
206                             Result += "    <td class=\"ListContent\">";
207                             Result += "        <input id=\"POD_DISCOUNT_" + BookInfo_Info.BiID + "\" value=\"" + DInDiscount * 100 + "\" type=\"text\" style=\"text-align: right;\" datatype=\"n1\" onchange=\"CheckPrice('" + BookInfo_Info.BiID + "','" + BookInfo_Info.BiPrice + "')\" />";
208                             Result += "    </td>";
209                             Result += "    <td class=\"ListContent\">";
210                             Result += "        <input id=\"POD_PRICE_" + BookInfo_Info.BiID + "\" value=\"" + (BookInfo_Info.BiPrice * DInDiscount).ToString("F4") + "\" type=\"text\" style=\"text-align: right;\" datatype=\"d0\" notnull onchange=\"SaveDetail('" + BookInfo_Info.BiID + "')\" />";
211                             Result += "    </td>";
212                             Result += "    <td class=\"ListContent\">";
213                             Result += "        <input id=\"POD_AMOUNT_" + BookInfo_Info.BiID + "\" type=\"text\" style=\"text-align: right;\" datatype=\"n1\" notnull onchange=\"SaveDetail('" + BookInfo_Info.BiID + "')\" />";
214                             Result += "    </td>";
215                             Result += "    <td class=\"ListContent\">";
216                             Result += "        <input id=\"POD_STOCK_" + BookInfo_Info.BiID + "\" value=\"" + sPurchaseAmount + "\" type=\"text\" style=\"text-align: right;\" datatype=\"n0\" notnull onchange=\"SaveDetail('" + BookInfo_Info.BiID + "')\" />";
217                             Result += "    </td>";
218                             Result += "    <td class=\"ListContent\">";
219                             Result += "        <input id=\"POD_ESTIMATE_" + BookInfo_Info.BiID + "\" value=\"" + sPurchaserCycle + "\" type=\"text\" style=\"text-align: right;\" datatype=\"n0\" notnull onchange=\"SaveDetail('" + BookInfo_Info.BiID + "')\" />";
220                             Result += "    </td>";
221                             Result += "    <td class=\"ListContent\">";
222                             Result += "        <a href=\"javascript:DeleteDetail('" + BookInfo_Info.BiID + "')\">删除</a>";
223                             Result += "    </td>";
224                             Result += "</tr>";
225                         }
226                     }
227                     else
228                     {
229                         Result = CheckStatus(PurchaseOrder_Info.PoStatus);
230                     }
231                 }
232                 break;
233 
234             //保存采购明细
235             case "SaveDetail":
236                 if (!String.IsNullOrEmpty(PoID) && PoID != "0")
237                 {
238                     PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID,PoStatus");
239                     if (PurchaseOrder_Info.PoStatus < 62)
240                     {
241                         PurchaseOrderDetailWhere.Clear();
242                         PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, PoID));
243                         PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.BIID, SqlWhere.Oper.Equal, BiID));
244                         PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "PodID,PodSendAmount,PodReceiveAmount,PodReturnAmount,PodPayAmount", PurchaseOrderDetailWhere, null);
245                         if (PurchaseOrderDetail_List.Count > 0)
246                         {
247                             PurchaseOrderDetail_Info = PurchaseOrderDetail_List[0];
248                         }
249                         PurchaseOrderDetail_Info.PoID = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID");
250                         PurchaseOrderDetail_Info.BiID = BookInfo_Bll.GetModels(Convert.ToInt32(BiID), "BiID");
251                         PurchaseOrderDetail_Info.PodPrice = Convert.ToDouble(Price);
252                         PurchaseOrderDetail_Info.PodBuyAmount = Convert.ToInt32(Amount);
253                         PurchaseOrderDetail_Info.PodPlace = "";
254                         PurchaseOrderDetail_Bll.SaveModels(PurchaseOrderDetail_Info);
255 
256                         Stock_Bll.SaveIn(Convert.ToInt32(StockAmount), Convert.ToInt32(Estimate), Convert.ToInt32(BiID), Convert.ToInt32(SdcID));
257                     }
258                     else
259                     {
260                         Result = CheckStatus(PurchaseOrder_Info.PoStatus);
261                     }
262                 }
263                 break;
264 
265             //删除采购明细
266             case "DeleteDetail":
267                 if (!String.IsNullOrEmpty(PoID) && PoID != "0")
268                 {
269                     PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID,PoStatus");
270                     if (PurchaseOrder_Info.PoStatus == 10 || PurchaseOrder_Info.PoStatus == 11)
271                     {
272                         PurchaseOrderDetailWhere.Clear();
273                         PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, PoID));
274                         PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.BIID, SqlWhere.Oper.Equal, BiID));
275                         PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "PodID", PurchaseOrderDetailWhere, null);
276                         if (PurchaseOrderDetail_List.Count > 0)
277                         {
278                             PurchaseOrderDetail_Bll.Delete(PurchaseOrderDetail_List[0].PodID);
279                         }
280                     }
281                     else
282                     {
283                         Result = CheckStatus(PurchaseOrder_Info.PoStatus);
284                     }
285                 }
286                 break;
287    }
288 }

此时,采购单已经建立完成,并且添加了具体的明细(可对明细进行增、删、改、查)。

2、审核采购单。新建采购单之后,需要对采购单的正确性进行审核。审核页面分为两个,第一个是显示所有的需要进行审核的采购单的页面审核。第二个是显示采购单明细的页面。我们把第一个叫做显示页,第二个叫做编辑页。

显示页的前台代码如图所示:

View Code
  1 <%@ Page Language="C#" AutoEventWireup="true"MasterPageFile="~/Manage.master"  CodeFile="AuditorManage.aspx.cs" Inherits="WBPmodule_Purchase_In_AuditorManage" %>
  2 
  3 <%@ Register Src="Search.ascx" TagName="Search" TagPrefix="uc1" %>
  4 <%@ Register Src="http://www.cnblogs.com/../PageChange.ascx" TagName="PageChange" TagPrefix="uc2" %>
  5 <asp:Content ID="PageHead" ContentPlaceHolderID="PageHead" runat="Server">
  6     <script type="text/javascript">
  7         $(document).ready(function () {
  8             //绑定验证
  9             ValidForm();
 10 
 11             //隔行换色
 12             setTrColor("ListTable");
 13 
 14             //绑定批销单回车键
 15             $("input[name='poID']").bind('keyup', function (event) {
 16                 if (event.keyCode == "13") {
 17                     //获取订单信息
 18                     if ($("input[name='poID']").val() != "") {
 19                         Search();
 20                     }
 21                 }
 22             });
 23         });
 24     </script>
 25 </asp:Content>
 26 <asp:Content ID="QuickAction" ContentPlaceHolderID="QuickAction" runat="Server">
 27 </asp:Content>
 28 <asp:Content ID="Search" ContentPlaceHolderID="Search" runat="Server">
 29     <uc1:Search ID="Search1" runat="server" />
 30 </asp:Content>
 31 <asp:Content ID="ContentBody" ContentPlaceHolderID="ContentBody" runat="Server">
 32     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="ListTable">
 33         <tr>
 34             <td class="ListTitle" style="width: 7%">采购单号
 35             </td>
 36             <td class="ListTitle" style="width: 6%">库房
 37             </td>
 38             <td class="ListTitle" style="width: 15%">供应商
 39             </td>
 40             <td class="ListTitle" style="width: 10%">采购员
 41             </td>
 42             <td class="ListTitle" style="width: 15%">采购日期
 43             </td>
 44             <td class="ListTitle" style="width: 10%">预计到货日期
 45             </td>
 46             <td class="ListTitle" style="width: 10%; text-align: right; padding-right: 10px;">单品(册数)
 47             </td>
 48             <td class="ListTitle" style="width: 10%; text-align: right; padding-right: 10px;">采购实洋
 49             </td>
 50             <td class="ListTitle" style="width: 11%">当前状态
 51             </td>
 52             <td class="ListTitle" style="width: 5%">操作
 53             </td>
 54         </tr>
 55         <%
 56             for (int i = 0; i < PurchaseOrderList.Rows.Count; i++)
 57             {
 58         %>
 59         <tr>
 60             <td class="ListContent">
 61                 <%= WebUtility.CreatePurchaseOrderCode(Convert.ToInt32(PurchaseOrderList.Rows[i]["poID"]))%>
 62             </td>
 63             <td class="ListContent">
 64                 <%= PurchaseOrderList.Rows[i]["sdcName"]%>
 65             </td>
 66             <td class="ListContent">
 67                 <%= PurchaseOrderList.Rows[i]["bsName"]%>
 68             </td>
 69             <td class="ListContent">
 70                 <%= PurchaseOrderList.Rows[i]["sysuiName"]%>
 71             </td>
 72             <td class="ListContent">
 73                 <%= Convert.ToDateTime(PurchaseOrderList.Rows[i]["poDate"]).ToString("yyyy-MM-dd hh:mm:ss")%>
 74             </td>
 75             <td class="ListContent">
 76                 <%= Convert.ToDateTime(PurchaseOrderList.Rows[i]["poEstimateDate"]).ToString("yyyy-MM-dd")%>
 77             </td>
 78             <td class="ListContent" style="text-align: right; padding-right: 10px;">
 79                 <%= GetPurhaseOrderDetail(Convert.ToInt32(PurchaseOrderList.Rows[i]["poID"]))%>(<%= PurchaseOrderList.Rows[i]["BuyAmount"]%>)
 80             </td>
 81             <td class="ListContent" style="text-align: right; padding-right: 10px;">
 82                 <%= Convert.ToDouble(PurchaseOrderList.Rows[i]["pdPrice"]).ToString("F4")%>
 83             </td>
 84             <td class="ListContent">
 85                 <%= WebUtility.PurchaseStatus(Convert.ToInt32(PurchaseOrderList.Rows[i]["poStatus"]))%>
 86             </td>
 87             <td class="ListContent">
 88                 <a href="JavaScript:RedirectPage('170302','EditPoID=<%= PurchaseOrderList.Rows[i]["poID"]%>&page=<%= page%>&poID=<%= poID%>&sdcID=<%=  sdcID%>&bsID=<%=  bsID%>&poStatus=<%=  poStatus%>&poDateBegin=<%=  poDateBegin%>&poDateEnd=<%=  poDateEnd%>&poEstimateDateBegin=<%=  poEstimateDateBegin%>&poEstimateDateEnd=<%=  poEstimateDateEnd%>')">审核</a>
 89             </td>
 90         </tr>
 91         <%
 92             }
 93         %>
 94         <tr>
 95             <td class="ListTotal" colspan="10">
 96                 <uc2:PageChange ID="PageChange1" runat="server" />
 97             </td>
 98         </tr>
 99     </table>
100 </asp:Content>

显示页后台代码如图所示:

View Code
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Data;
  4 using System.Web.UI;
  5 
  6 using BNbll;
  7 using BNmodel;
  8 using BNutility;
  9 
 10 public partial class WBPmodule_Purchase_In_AuditorManage : System.Web.UI.Page
 11 {
 12     protected string poID = "";
 13     protected string sdcID = "";
 14     protected string bsID = "";
 15     protected string poStatus = "";
 16     protected string poDateBegin = "";
 17     protected string poDateEnd = "";
 18     protected string poEstimateDateBegin = "";
 19     protected string poEstimateDateEnd = "";
 20     protected string bsID_Responsible = "";
 21 
 22     protected string DefaultStatus = "10";
 23     protected int page = 1;
 24 
 25 
 26     PurchaseOrderManager PurchaseOrder_Bll = new PurchaseOrderManager();
 27     PurchaseOrderDetailManager PurchaseOrderDetail_Bll = new PurchaseOrderDetailManager();
 28     SYS_UserInfoManager UserInfo_Bll = new SYS_UserInfoManager();
 29 
 30     protected DataTable PurchaseOrderList = new DataTable();
 31 
 32     protected void Page_Load(object sender, EventArgs e)
 33     {
 34         poID = Request.QueryString["poID"];
 35         sdcID = Request.QueryString["sdcID"];
 36         bsID = Request.QueryString["bsID"];
 37         poStatus = Request.QueryString["poStatus"];
 38         poDateBegin = Request.QueryString["poDateBegin"];
 39         poDateEnd = Request.QueryString["poDateEnd"];
 40         poEstimateDateBegin = Request.QueryString["poEstimateDateBegin"];
 41         poEstimateDateEnd = Request.QueryString["poEstimateDateEnd"];
 42         page = WebUtility.CheckParamID(Request.QueryString["Page"], page);
 43 
 44         if (String.IsNullOrEmpty(poStatus))
 45         {
 46             poStatus = DefaultStatus;
 47         }
 48         Search1.ChangeStatus(poStatus, bsID_Responsible);
 49 
 50         List<SqlWhere> PurchaseWhere = new List<SqlWhere>();
 51 
 52         if (!String.IsNullOrEmpty(poID))
 53         {
 54             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.POID, SqlWhere.Oper.Equal, poID));
 55         }
 56         if (!String.IsNullOrEmpty(sdcID))
 57         {
 58             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.SDCID, SqlWhere.Oper.Equal, sdcID));
 59         }
 60         if (!String.IsNullOrEmpty(bsID))
 61         {
 62             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.BSID, SqlWhere.Oper.Equal, bsID));
 63         }
 64         if (poStatus.ToUpper() != "ALL")
 65         {
 66             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.POSTATUS, SqlWhere.Oper.Equal, poStatus));
 67         }
 68         if (!String.IsNullOrEmpty(poDateBegin))
 69         {
 70             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.PODATE, SqlWhere.Oper.MoreEqual, poDateBegin + " 00:00:00"));
 71         }
 72         if (!String.IsNullOrEmpty(poDateEnd))
 73         {
 74             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.PODATE, SqlWhere.Oper.LessEqual, poDateEnd + " 23:59:59:998"));
 75         }
 76         if (!String.IsNullOrEmpty(poEstimateDateBegin))
 77         {
 78             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.POESTIMATEDATE, SqlWhere.Oper.MoreEqual, poEstimateDateBegin + " 00:00:00"));
 79         }
 80         if (!String.IsNullOrEmpty(poEstimateDateEnd))
 81         {
 82             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.POESTIMATEDATE, SqlWhere.Oper.LessEqual, poEstimateDateEnd + " 23:59:59:998"));
 83         }
 84         if (!String.IsNullOrEmpty(bsID_Responsible))
 85         {
 86             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.BSID, SqlWhere.Oper.In, bsID_Responsible));
 87         }
 88 
 89 
 90         //初始化分页控件
 91         PageChange1.GetPage(page, PurchaseOrder_Bll.DoCount(PurchaseWhere), "&poID=" + poID + "&sdcID=" + sdcID + "&bsID=" + bsID + "&poStatus=" + poStatus + "&poDateBegin=" + poDateBegin + "&poDateEnd=" + poDateEnd + "&poEstimateDateBegin=" + poEstimateDateBegin + "&poEstimateDateEnd=" + poEstimateDateEnd);
 92         //获得订单
 93         PurchaseOrderList = PurchaseOrder_Bll.GetList(PageChange1.PageIndex, PageChange1.PageSize, PurchaseWhere, null, "Apply");
 94     }
 95 
 96     protected int GetPurhaseOrderDetail(int poID)
 97     {
 98         List<SqlWhere> DetailWhere = new List<SqlWhere>();
 99         DetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, poID));
100         List<PurchaseOrderDetail> PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "podID", DetailWhere, null);
101         return PurchaseOrderDetail_List.Count;
102     }
103 }

在显示页面中单击超链接“审核则进入到编辑页中。编辑页中有“通过”和“驳回”两个按钮,主要是对采购单的状态进行修改。如果采购单正确,则单击通过,此时使用AJAX一般处理程序将采购单的状态修改为"12";如果采购单不正确,则单击“驳回”,此时使用AJAX一般处理程序将采购单的状态修改为"11"。

审核编辑页的前台代码如图所示:

View Code
  1 <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Manage.master" CodeFile="AuditorEdit.aspx.cs" Inherits="WBPmodule_Purchase_In_AuditorEdit" %>
  2 
  3 <asp:Content ID="PageHead" ContentPlaceHolderID="PageHead" runat="Server">
  4     <script type="text/javascript">
  5         $(document).ready(function () {
  6             //绑定验证
  7             ValidForm();
  8 
  9             //隔行换色
 10             setTrColor("ListTable");
 11 
 12             //计算总数
 13             CheckTotal();
 14         });
 15 
 16         var DontActionStatus = ",Auditor,Difference,InStock,NotConfirmation,Confirmation,NotAccounting,Accounting,Delete,";
 17 
 18         //保存主单
 19         function SavePurchase(AuditorStatus) {
 20             if (SubmitValidForm($("#PurchaseOrder"))) {
 21                 $.ajax({
 22                     url: "Ajax.ashx",
 23                     data: {
 24                         OpType: "Auditor",
 25                         PoID: parseInt($("input[name='poID']").val().replace("CG", ""), 10),
 26                         PoAuditorRemark: $("input[name='poAuditorRemark']").val(),
 27                         PoAuditorStatus: AuditorStatus
 28                     },
 29                     async: true,
 30                     cache: false,
 31                     dataType: "html",
 32                     error: function (a, b, c) {
 33                         if (b == "error") {
 34                             var InfoStatus = "lose";
 35                             var InfoContent = "采购单审核失败";
 36                             var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 37                             ShowInfo(InfoStatus, InfoContent, InfoAction);
 38                         }
 39                     },
 40                     success: function (Result) {
 41                         if (DontActionStatus.indexOf("," + Result + ",") >= 0) {
 42                             var InfoStatus = "lose";
 43                             var InfoContent = "采购单保存失败<br />" + GetPurchaseStatus(Result);
 44                             var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 45                             ShowInfo(InfoStatus, InfoContent, InfoAction);
 46                         }
 47                         else {
 48                             var InfoStatus = "win";
 49                             var InfoContent = "采购单审核成功";
 50                             var InfoAction = "<a href=\"javascript:RedirectPage('170301','page=<%= page%>&poID=<%= poID%>&sdcID=<%= sdcID%>&bsID=<%= bsID%>&poStatus=<%= poStatus%>&poDateBegin=<%= poDateBegin%>&poDateEnd=<%= poDateEnd%>&poEstimateDateBegin=<%= poEstimateDateBegin%>&poEstimateDateEnd=<%= poEstimateDateEnd%>')\">确定</a>";
 51                             ShowInfo(InfoStatus, InfoContent, InfoAction);
 52                         }
 53                     }
 54                 });
 55             }
 56         }
 57 
 58         //汇总
 59         function CheckTotal() {
 60             var CountPrice = 0;
 61             var CountAmount = 0;
 62             $("TR[name='PurchaseDetail']").each(function () {
 63                 var BiID = $(this).attr("id");
 64 
 65                 //绑定折扣回车键
 66                 $("#POD_DISCOUNT_" + BiID).bind('keyup', function (event) {
 67                     if (event.keyCode == "13") {
 68                         //获取订单信息
 69                         $("#POD_AMOUNT_" + BiID).select();
 70                     }
 71                 });
 72                 //绑定数量回车键
 73                 $("#POD_AMOUNT_" + BiID).bind('keyup', function (event) {
 74                     if (event.keyCode == "13") {
 75                         //获取订单信息
 76                         $("#POD_STOCK_" + BiID).select();
 77                     }
 78                 });
 79                 //绑定供应商库存回车键
 80                 $("#POD_STOCK_" + BiID).bind('keyup', function (event) {
 81                     if (event.keyCode == "13") {
 82                         //获取订单信息
 83                         $("#POD_ESTIMATE_" + BiID).select();
 84                     }
 85                 });
 86 
 87                 CountPrice += parseFloat($("#POD_PRICE_" + BiID).val()) * parseFloat($("#POD_AMOUNT_" + BiID).val());
 88                 CountAmount += parseInt($("#POD_AMOUNT_" + BiID).val());
 89             });
 90             $("#Price_Total").val(CountPrice.toFixed(4));
 91             $("#Amount_Total").val($("TR[name='PurchaseDetail']").length + "(" + CountAmount + ")");
 92         }
 93     </script>
 94 </asp:Content>
 95 <asp:Content ID="QuickAction" ContentPlaceHolderID="QuickAction" runat="Server">
 96     <a href="JavaScript:RedirectPage('170301','page=<%= page%>&poID=<%= poID%>&sdcID=<%= sdcID%>&bsID=<%= bsID%>&poStatus=<%= poStatus%>&poDateBegin=<%= poDateBegin%>&poDateEnd=<%= poDateEnd%>&poEstimateDateBegin=<%= poEstimateDateBegin%>&poEstimateDateEnd=<%= poEstimateDateEnd%>')">返回</a>
 97 </asp:Content>
 98 <asp:Content ID="Search" ContentPlaceHolderID="Search" runat="Server">
 99     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="PurchaseOrder">
100         <tr>
101             <td id="poID_Title" class="SearchTitle" style="width: 10%"></td>
102             <td style="width: 13%">
103                 <input name="poID" type="text" title="采购单号" value="<%=  WebUtility.CreatePurchaseOrderCode(EditPoID)%>"
104                     notnull disabled />
105             </td>
106             <td id="sdcID_Title" class="SearchTitle" style="width: 10%"></td>
107             <td style="width: 13%">
108                 <select name="sdcID" title="采购库房" style="width: 100%;" notnull disabled>
109                     <option value="">全部</option>
110                     <%
111                         for (int i = 0; i < StockDataClass_List.Count; i++)
112                         {
113                     %>
114                     <option value="<%= StockDataClass_List[i].SdcID%>" <%= (StockDataClass_List[i].SdcID == EditSdcID) ? "selected" : ""%>>
115                         <%= StockDataClass_List[i].SdcName%></option>
116                     <%
117                         }
118                     %>
119                 </select>
120             </td>
121             <td id="bsID_Title" class="SearchTitle" style="width: 10%"></td>
122             <td style="width: 13%">
123                 <select name="bsID" title="供 应 商" style="width: 100%;" notnull disabled>
124                     <option value="">全部</option>
125                     <%
126             
127                         for (int i = 0; i < BookSupply_List.Count; i++)
128                         {
129                     %>
130                     <option value="<%= BookSupply_List[i].BsID%>" <%= (BookSupply_List[i].BsID == EditBsID) ? "selected" : ""%>>
131                         <%= BookSupply_List[i].BsName%></option>
132                     <%
133                         }
134                     %>
135                 </select>
136             </td>
137             <td id="poEstimateDate_Title" class="SearchTitle" style="width: 10%"></td>
138             <td style="width: 13%">
139                 <input name="poEstimateDate" type="text" title="到货日期" value="<%= EstimateDate%>" notnull disabled />
140             </td>
141             <td style="width: 8%" align="center">
142                 <input id="Button1" type="button" value="同意" onclick="SavePurchase('True')" />
143             </td>
144         </tr>
145         <tr>
146             <td id="poRemark_Title" class="SearchTitle" style="width: 10%"></td>
147             <td colspan="3">
148                 <input name="poRemark" type="text" title="采购备注" value="<%= PoRemark%>"  disabled/>
149             </td>
150             <td id="poAuditorRemark_Title" class="SearchTitle" style="width: 10%"></td>
151             <td colspan="3">
152                 <input name="poAuditorRemark" type="text" title="审核意见" value="<%= PoAuditorRemark%>" />
153             </td>
154             <td style="width: 8%" align="center">
155                 <input id="Button2" type="button" value="驳回" onclick="SavePurchase('False')" />
156             </td>
157         </tr>
158     </table>
159 </asp:Content>
160 <asp:Content ID="ContentBody" ContentPlaceHolderID="ContentBody" runat="Server">
161     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="ListTable">
162         <tr>
163             <td class="ListTitle" style="width: 3%"></td>
164             <td class="ListTitle" style="width: 7%">商品ID
165             </td>
166             <td class="ListTitle" style="width: 7%">条形码
167             </td>
168             <td class="ListTitle" style="width: 30%">书名
169             </td>
170             <td class="ListTitle" style="width: 15%">出版社
171             </td>
172             <td class="ListTitle" style="width: 6%">定价
173             </td>
174             <td class="ListTitle" style="width: 5%">折扣
175             </td>
176             <td class="ListTitle" style="width: 6%">采购实洋
177             </td>
178             <td class="ListTitle" style="width: 6%">采购数量
179             </td>
180             <td class="ListTitle" style="width: 7%">供应商库存
181             </td>
182             <td class="ListTitle" style="width: 8%">供货周期(天)
183             </td>
184         </tr>
185         <%
186             for (int i = 0; i < PurchaseOrderDetail_List.Count; i++)
187             {
188                 int PodDiscount = 0;
189                 if (PurchaseOrderDetail_List[i].BiID.BiPrice > 0)
190                 {
191                     PodDiscount = Convert.ToInt32(PurchaseOrderDetail_List[i].PodPrice / PurchaseOrderDetail_List[i].BiID.BiPrice * 100);
192                 }
193                 dt = GetStock(PurchaseOrderDetail_List[i].PoID.PoID);
194                 if (dt.Rows.Count > 0)
195                 {
196                     int Stock = Convert.ToInt32(dt.Rows[i]["sPurchaseAmount"]);
197                     int Estimate = Convert.ToInt32(dt.Rows[i]["sPurchaseCycle"]);
198                
199              
200         %>
201         <tr name="PurchaseDetail" id="<%= PurchaseOrderDetail_List[i].BiID.BiID%>">
202             <td class="ListContent" id="POD_STATUS_<%= PurchaseOrderDetail_List[i].BiID.BiID%>"></td>
203             <td class="ListContent">
204                 <%= WebUtility.CreateBookCode(PurchaseOrderDetail_List[i].BiID.BiID)%>
205             </td>
206             <td class="ListContent">
207                 <%= PurchaseOrderDetail_List[i].BiID.BiCode%>
208             </td>
209             <td class="ListContent">
210                 <%= PurchaseOrderDetail_List[i].BiID.BiName%>
211             </td>
212             <td class="ListContent">
213                 <%= PurchaseOrderDetail_List[i].BiID.BibsID.BsName%>
214             </td>
215             <td class="ListContent">
216                 <%= PurchaseOrderDetail_List[i].BiID.BiPrice.ToString("F2")%>
217             </td>
218             <td class="ListContent">
219                 <input type="text" value="<%= PodDiscount%>" style="text-align: right;" disabled />
220             </td>
221             <td class="ListContent">
222                 <input id="POD_PRICE_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" value="<%= PurchaseOrderDetail_List[i].PodPrice.ToString("F4")%>" type="text" style="text-align: right;" disabled/>
223             </td>
224             <td class="ListContent">
225                 <input id="POD_AMOUNT_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" value="<%= PurchaseOrderDetail_List[i].PodBuyAmount%>" type="text" style="text-align: right;" disabled />
226             </td>
227             <td class="ListContent">
228                 <input value="<%=Stock%>" type="text" style="text-align: right;" disabled />
229             </td>
230             <td class="ListContent">
231                 <input value="<%= Estimate%>" type="text" style="text-align: right;" disabled/>
232             </td>
233         </tr>
234         <%    }   
235             }
236         %>
237         <tr>
238             <td class="ListTotal" colspan="6" style="text-align:right;">合计:</td>
239             <td class="ListTotal" colspan="2">
240                 <input id="Price_Total" type="text" style="text-align: right;" disabled />
241             </td>
242             <td class="ListTotal">
243                 <input id="Amount_Total" type="text" style="text-align: right;" disabled />
244             </td>
245             <td class="ListTotal" colspan="2"></td>
246         </tr>
247     </table>
248 </asp:Content>

审核编辑页的后台代码如图所示:

 

View Code
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Web.UI;
  4 
  5 using BNbll;
  6 using BNmodel;
  7 using BNutility;
  8 using System.Data;
  9 
 10 
 11 public partial class WBPmodule_Purchase_In_AuditorEdit : System.Web.UI.Page
 12 {
 13     protected int page = 1;
 14     protected string poID = "";
 15     protected string sdcID = "";
 16     protected string bsID = "";
 17     protected string poStatus = "";
 18     protected string poDateBegin = "";
 19     protected string poDateEnd = "";
 20     protected string poEstimateDateBegin = "";
 21     protected string poEstimateDateEnd = "";
 22     protected string bsID_Responsible = "";
 23 
 24     protected int EditPoID = 0;
 25     protected int EditSdcID = 0;
 26     protected int EditBsID = 0;
 27     protected string EstimateDate = DateTime.Now.ToString("yyyy-MM-dd");
 28     protected string PoRemark = "";
 29     protected string PoAuditorRemark = "";
 30 
 31     protected DataTable dt;
 32 
 33 
 34 
 35 
 36     protected List<StockDataClass> StockDataClass_List = new List<StockDataClass>();
 37     protected List<BookSupply> BookSupply_List = new List<BookSupply>();
 38     protected List<PurchaseOrderDetail> PurchaseOrderDetail_List = new List<PurchaseOrderDetail>();
 39 
 40 
 41     BookSupplyManager BookSupply_Bll = new BookSupplyManager();
 42     SYS_UserInfoManager UserInfo_Bll = new SYS_UserInfoManager();
 43     StockDataClassManager StockDataClass_Bll = new StockDataClassManager();
 44     PurchaseOrderManager PurchaseOrder_Bll = new PurchaseOrderManager();
 45     PurchaseOrderDetailManager PurchaseOrderDetail_Bll = new PurchaseOrderDetailManager();
 46 
 47 
 48     protected void Page_Load(object sender, EventArgs e)
 49     {
 50         poID = Request.QueryString["poID"];
 51         sdcID = Request.QueryString["sdcID"];
 52         bsID = Request.QueryString["bsID"];
 53         poStatus = Request.QueryString["poStatus"];
 54         poDateBegin = Request.QueryString["poDateBegin"];
 55         poDateEnd = Request.QueryString["poDateEnd"];
 56         poEstimateDateBegin = Request.QueryString["poEstimateDateBegin"];
 57         poEstimateDateEnd = Request.QueryString["poEstimateDateEnd"];
 58         page = WebUtility.CheckParamID(Request.QueryString["Page"], page);
 59 
 60 
 61         if (!String.IsNullOrEmpty(Request.QueryString["EditPoID"]))
 62         {
 63             EditPoID = WebUtility.CheckParamID(Request.QueryString["EditPoID"], 0);
 64             PurchaseOrder PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(EditPoID, "SdcID:{SdcID},BsID:{BsID},PoEstimateDate,PoRemark,PoAuditorRemark");
 65             EditSdcID = PurchaseOrder_Info.SdcID.SdcID;
 66             EditBsID = PurchaseOrder_Info.BsID.BsID;
 67             EstimateDate = PurchaseOrder_Info.PoEstimateDate.ToString("yyyy-MM-dd");
 68             PoRemark = PurchaseOrder_Info.PoRemark;
 69             PoAuditorRemark = PurchaseOrder_Info.PoAuditorRemark;
 70 
 71 
 72             List<SqlWhere> PurchaseOrderDetailWhere = new List<SqlWhere>();
 73             PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, EditPoID));
 74             PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "PoID:{PoID},BiID:{BiID,BiCode,BiName,BibsID:{BsName},BiPrice},PodPrice,PodBuyAmount", PurchaseOrderDetailWhere, null);
 75         }
 76 
 77         List<SqlWhere> StockDataCalssWhere = new List<SqlWhere>();
 78         StockDataCalssWhere.Add(new SqlWhere(StockDataClass.SDCPARENTID, SqlWhere.Oper.Equal, 1));
 79         StockDataCalssWhere.Add(new SqlWhere(StockDataClass.SDCSTATUS, SqlWhere.Oper.Equal, 1));
 80         StockDataClass_List = StockDataClass_Bll.GetList(0, 0, "sdcID,sdcName", StockDataCalssWhere, null);
 81 
 82         List<SqlWhere> BookSupplyWhere = new List<SqlWhere>();
 83         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSID, SqlWhere.Oper.MoreEqual, 0));
 84         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSISSUPPLIER, SqlWhere.Oper.Equal, 1));
 85         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSSTATUS, SqlWhere.Oper.Equal, 1));
 86         if (!String.IsNullOrEmpty(bsID_Responsible))
 87         {
 88             BookSupplyWhere.Add(new SqlWhere(BookSupply.BSID, SqlWhere.Oper.In, bsID_Responsible));
 89         }
 90         List<SqlOrder> BookSupplyOrder = new List<SqlOrder>();
 91         BookSupplyOrder.Add(new SqlOrder(BookSupply.BSNAME, true));
 92         BookSupply_List = BookSupply_Bll.GetList(0, 0, "bsID,bsName", BookSupplyWhere, BookSupplyOrder);
 93 
 94 
 95 
 96     }
 97 
 98     public DataTable GetStock(int PoID)
 99     {
100         
101         StockManager Stock_Bll = new StockManager();
102           dt=Stock_Bll.GetStock(PoID);
103           return dt;
104     }
105 }

 

AJAX一般处理程序的代码如图所示:

View Code
 1  //审核采购单
 2             case "Auditor":
 3                 if (!String.IsNullOrEmpty(PoID) && PoID != "0")
 4                 {
 5                     PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID,PoStatus");
 6                     if (PurchaseOrder_Info.PoStatus == 10 || PurchaseOrder_Info.PoStatus == 11 || PurchaseOrder_Info.PoStatus == 12)
 7                     {
 8                         PurchaseOrder_Info.PoAuditorUser = UserInfo_Bll.GetModels(Convert.ToInt32(UserInfo_Bll.CookieUserID), "SysuiID");
 9                         PurchaseOrder_Info.PoAuditorDate = DateTime.Now;
10                         PurchaseOrder_Info.PoAuditorRemark = PoAuditorRemark;
11                         PurchaseOrder_Info.PoAuditorStatus = Convert.ToBoolean(PoAuditorStatus);
12                         if (PurchaseOrder_Info.PoAuditorStatus)
13                         {
14                             PurchaseOrder_Info.PoStatus = 12;
15                         }
16                         else
17                         {
18                             PurchaseOrder_Info.PoStatus = 11;
19                         }
20                         PurchaseOrder_Bll.Auditor(PurchaseOrder_Info);
21                     }
22                     else
23                     {
24                         Result = CheckStatus(PurchaseOrder_Info.PoStatus);
25                     }
26                 }
27                 break;

 

 当采购单状态为"11"时,可对采购单进行修改,再此进行审核。

3、审核通过后,然后收货。在收货中同样存在两个页面,第一个是显示页,用来显示等待收货的所有采购单;另一个是编辑页,保存收货的数量。

显示页中会默认的显示待收货的所有采购单。显示页的前台代码如图所示:

View Code
  1 <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Manage.master" CodeFile="ReceiveManage.aspx.cs" Inherits="WBPmodule_Purchase_In_ReceiveManage" %>
  2 
  3 <%@ Register Src="Search.ascx" TagName="Search" TagPrefix="uc1" %>
  4 <%@ Register Src="http://www.cnblogs.com/../PageChange.ascx" TagName="PageChange" TagPrefix="uc2" %>
  5 <asp:Content ID="PageHead" ContentPlaceHolderID="PageHead" runat="Server">
  6     <script type="text/javascript">
  7         $(document).ready(function () {
  8             //绑定验证
  9             ValidForm();
 10 
 11             //隔行换色
 12             setTrColor("ListTable");
 13 
 14             //绑定批销单回车键
 15             $("input[name='poID']").bind('keyup', function (event) {
 16                 if (event.keyCode == "13") {
 17                     //获取订单信息
 18                     if ($("input[name='poID']").val() != "") {
 19                         Search();
 20                     }
 21                 }
 22             });
 23         });
 24     </script>
 25 </asp:Content>
 26 <asp:Content ID="QuickAction" ContentPlaceHolderID="QuickAction" runat="Server">
 27 </asp:Content>
 28 <asp:Content ID="Search" ContentPlaceHolderID="Search" runat="Server">
 29     <uc1:Search ID="Search1" runat="server" />
 30 </asp:Content>
 31 <asp:Content ID="ContentBody" ContentPlaceHolderID="ContentBody" runat="Server">
 32     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="ListTable">
 33         <tr>
 34             <td class="ListTitle" style="width: 7%">采购单号
 35             </td>
 36             <td class="ListTitle" style="width: 6%">库房
 37             </td>
 38             <td class="ListTitle" style="width: 15%">供应商
 39             </td>
 40             <td class="ListTitle" style="width: 10%">采购员
 41             </td>
 42             <td class="ListTitle" style="width: 15%">采购日期
 43             </td>
 44             <td class="ListTitle" style="width: 10%">预计到货日期
 45             </td>
 46             <td class="ListTitle" style="width: 10%; text-align: right; padding-right: 10px;">单品(册数)
 47             </td>
 48             <td class="ListTitle" style="width: 10%; text-align: right; padding-right: 10px;">采购实洋
 49             </td>
 50             <td class="ListTitle" style="width: 11%">当前状态
 51             </td>
 52             <td class="ListTitle" style="width: 5%">操作
 53             </td>
 54         </tr>
 55         <%
 56             for (int i = 0; i < PurchaseOrderList.Rows.Count; i++)
 57             {
 58         %>
 59         <tr>
 60             <td class="ListContent">
 61                 <%= WebUtility.CreatePurchaseOrderCode(Convert.ToInt32(PurchaseOrderList.Rows[i]["poID"]))%>
 62             </td>
 63             <td class="ListContent">
 64                 <%= PurchaseOrderList.Rows[i]["sdcName"]%>
 65             </td>
 66             <td class="ListContent">
 67                 <%= PurchaseOrderList.Rows[i]["bsName"]%>
 68             </td>
 69             <td class="ListContent">
 70                 <%= PurchaseOrderList.Rows[i]["sysuiName"]%>
 71             </td>
 72             <td class="ListContent">
 73                 <%= Convert.ToDateTime(PurchaseOrderList.Rows[i]["poDate"]).ToString("yyyy-MM-dd hh:mm:ss")%>
 74             </td>
 75             <td class="ListContent">
 76                 <%= Convert.ToDateTime(PurchaseOrderList.Rows[i]["poEstimateDate"]).ToString("yyyy-MM-dd")%>
 77             </td>
 78             <td class="ListContent" style="text-align: right; padding-right: 10px;">
 79                 <%= GetPurhaseOrderDetail(Convert.ToInt32(PurchaseOrderList.Rows[i]["poID"]))%>(<%= PurchaseOrderList.Rows[i]["BuyAmount"]%>)
 80             </td>
 81             <td class="ListContent" style="text-align: right; padding-right: 10px;">
 82                 <%= Convert.ToDouble(PurchaseOrderList.Rows[i]["pdPrice"]).ToString("F4")%>
 83             </td>
 84             <td class="ListContent">
 85                 <%= WebUtility.PurchaseStatus(Convert.ToInt32(PurchaseOrderList.Rows[i]["poStatus"]))%>
 86             </td>
 87             <td class="ListContent">
 88                 <a href="JavaScript:RedirectPage('170402','EditPoID=<%= PurchaseOrderList.Rows[i]["poID"]%>&page=<%= page%>&poID=<%= poID%>&sdcID=<%=  sdcID%>&bsID=<%=  bsID%>&poStatus=<%=  poStatus%>&poDateBegin=<%=  poDateBegin%>&poDateEnd=<%=  poDateEnd%>&poEstimateDateBegin=<%=  poEstimateDateBegin%>&poEstimateDateEnd=<%=  poEstimateDateEnd%>')">收货</a>
 89             </td>
 90         </tr>
 91         <%
 92             }
 93         %>
 94         <tr>
 95             <td class="ListTotal" colspan="10">
 96                 <uc2:PageChange ID="PageChange1" runat="server" />
 97             </td>
 98         </tr>
 99     </table>
100 </asp:Content>

显示页后台代码如图所示:

View Code
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Data;
  4 using System.Web.UI;
  5 
  6 using BNbll;
  7 using BNmodel;
  8 using BNutility;
  9 
 10 public partial class WBPmodule_Purchase_In_ReceiveManage : System.Web.UI.Page
 11 {
 12     protected string poID = "";
 13     protected string sdcID = "";
 14     protected string bsID = "";
 15     protected string poStatus = "";
 16     protected string poDateBegin = "";
 17     protected string poDateEnd = "";
 18     protected string poEstimateDateBegin = "";
 19     protected string poEstimateDateEnd = "";
 20     protected string bsID_Responsible = "";
 21 
 22     protected string DefaultStatus = "12";
 23     protected int page = 1;
 24 
 25 
 26     PurchaseOrderManager PurchaseOrder_Bll = new PurchaseOrderManager();
 27     PurchaseOrderDetailManager PurchaseOrderDetail_Bll = new PurchaseOrderDetailManager();
 28     SYS_UserInfoManager UserInfo_Bll = new SYS_UserInfoManager();
 29 
 30     protected DataTable PurchaseOrderList = new DataTable();
 31 
 32     protected void Page_Load(object sender, EventArgs e)
 33     {
 34         poID = Request.QueryString["poID"];
 35         sdcID = Request.QueryString["sdcID"];
 36         bsID = Request.QueryString["bsID"];
 37         poStatus = Request.QueryString["poStatus"];
 38         poDateBegin = Request.QueryString["poDateBegin"];
 39         poDateEnd = Request.QueryString["poDateEnd"];
 40         poEstimateDateBegin = Request.QueryString["poEstimateDateBegin"];
 41         poEstimateDateEnd = Request.QueryString["poEstimateDateEnd"];
 42         page = WebUtility.CheckParamID(Request.QueryString["Page"], page);
 43 
 44         if (String.IsNullOrEmpty(poStatus))
 45         {
 46             poStatus = DefaultStatus;
 47         }
 48         Search1.ChangeStatus(poStatus, bsID_Responsible);
 49 
 50         List<SqlWhere> PurchaseWhere = new List<SqlWhere>();
 51 
 52         if (!String.IsNullOrEmpty(poID))
 53         {
 54             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.POID, SqlWhere.Oper.Equal, poID));
 55         }
 56         if (!String.IsNullOrEmpty(sdcID))
 57         {
 58             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.SDCID, SqlWhere.Oper.Equal, sdcID));
 59         }
 60         if (!String.IsNullOrEmpty(bsID))
 61         {
 62             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.BSID, SqlWhere.Oper.Equal, bsID));
 63         }
 64         if (poStatus.ToUpper() != "ALL")
 65         {
 66             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.POSTATUS, SqlWhere.Oper.Equal, poStatus));
 67         }
 68         if (!String.IsNullOrEmpty(poDateBegin))
 69         {
 70             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.PODATE, SqlWhere.Oper.MoreEqual, poDateBegin + " 00:00:00"));
 71         }
 72         if (!String.IsNullOrEmpty(poDateEnd))
 73         {
 74             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.PODATE, SqlWhere.Oper.LessEqual, poDateEnd + " 23:59:59:998"));
 75         }
 76         if (!String.IsNullOrEmpty(poEstimateDateBegin))
 77         {
 78             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.POESTIMATEDATE, SqlWhere.Oper.MoreEqual, poEstimateDateBegin + " 00:00:00"));
 79         }
 80         if (!String.IsNullOrEmpty(poEstimateDateEnd))
 81         {
 82             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.POESTIMATEDATE, SqlWhere.Oper.LessEqual, poEstimateDateEnd + " 23:59:59:998"));
 83         }
 84         if (!String.IsNullOrEmpty(bsID_Responsible))
 85         {
 86             PurchaseWhere.Add(new SqlWhere(PurchaseOrder.BSID, SqlWhere.Oper.In, bsID_Responsible));
 87         }
 88 
 89 
 90         //初始化分页控件
 91         PageChange1.GetPage(page, PurchaseOrder_Bll.DoCount(PurchaseWhere), "&poID=" + poID + "&sdcID=" + sdcID + "&bsID=" + bsID + "&poStatus=" + poStatus + "&poDateBegin=" + poDateBegin + "&poDateEnd=" + poDateEnd + "&poEstimateDateBegin=" + poEstimateDateBegin + "&poEstimateDateEnd=" + poEstimateDateEnd);
 92         //获得订单
 93         PurchaseOrderList = PurchaseOrder_Bll.GetList(PageChange1.PageIndex, PageChange1.PageSize, PurchaseWhere, null, "Apply");
 94     }
 95 
 96     protected int GetPurhaseOrderDetail(int poID)
 97     {
 98         List<SqlWhere> DetailWhere = new List<SqlWhere>();
 99         DetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, poID));
100         List<PurchaseOrderDetail> PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "podID", DetailWhere, null);
101         return PurchaseOrderDetail_List.Count;
102     }
103 }

单击显示页中的超链接“收货”可进入收货编辑页面。编辑页面中需要填写多个信息,“收货人”、“收货备注”、“发货数”、“收获数”、“仓位”(说明产品收货之后会放在仓库中的某个仓位中)。填好信息之后,单击“收货”按钮,此时将使用AJAX一般处理程序调用底层的方法,底层方法调用具体的存储过程。同时更新 Stock、StockPlace、StockBatch、HistoryStock、HistoryBatch、PurchaseOrderDetail、PurchaseOrder表中的数据。

编辑页面前台代码如图所示:

View Code
  1 <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Manage.master" CodeFile="ReceiveEdit.aspx.cs" Inherits="WBPmodule_Purchase_In_ReceiveEdit" %>
  2 
  3 <asp:Content ID="PageHead" ContentPlaceHolderID="PageHead" runat="Server">
  4     <script type="text/javascript">
  5         $(document).ready(function () {
  6             //绑定验证
  7             ValidForm();
  8 
  9             //隔行换色
 10             setTrColor("ListTable");
 11 
 12             //计算总数
 13             CheckTotal();
 14         });
 15 
 16         var DontActionStatus = ",NewOrder,Refuser,Difference,InStock,NotConfirmation,Confirmation,NotAccounting,Accounting,Delete,";
 17 
 18         //收货
 19         function SavePurchase() {
 20             if (SubmitValidForm()) {
 21                 $.ajax({
 22                     url: "Ajax.ashx",
 23                     data: {
 24                         OpType: "Receive",
 25                         PoID: parseInt($("input[name='poID']").val().replace("CG", ""), 10),
 26                         PoReceiveUser: $("input[name='poReceiveUserID']").val(),
 27                         PoSupplierOrder: $("input[name='poSupplierOrder']").val(),
 28                         PoReceiveAuditorRemark: $("input[name='poReceiveAuditorRemark']").val()
 29                     },
 30                     async: true,
 31                     cache: false,
 32                     dataType: "html",
 33                     error: function (a, b, c) {
 34                         if (b == "error") {
 35                             var InfoStatus = "lose";
 36                             var InfoContent = "采购单收货失败";
 37                             var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 38                             ShowInfo(InfoStatus, InfoContent, InfoAction);
 39                         }
 40                     },
 41                     success: function (Result) {
 42                         if (DontActionStatus.indexOf("," + Result + ",") >= 0) {
 43                             var InfoStatus = "lose";
 44                             var InfoContent = "采购单收货失败<br />" + GetPurchaseStatus(Result);
 45                             var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 46                             ShowInfo(InfoStatus, InfoContent, InfoAction);
 47                         }
 48                         else {
 49                             if (Result == "Succeed") {
 50                                 var InfoStatus = "win";
 51                                 var InfoContent = "采购单收货成功";
 52                                 var InfoAction = "<a href=\"javascript:RedirectPage('170401','page=<%= page%>&poID=<%= poID%>&sdcID=<%= sdcID%>&bsID=<%= bsID%>&poStatus=<%= poStatus%>&poDateBegin=<%= poDateBegin%>&poDateEnd=<%= poDateEnd%>&poEstimateDateBegin=<%= poEstimateDateBegin%>&poEstimateDateEnd=<%= poEstimateDateEnd%>')\">确定</a>";
 53                                 ShowInfo(InfoStatus, InfoContent, InfoAction);
 54                             }
 55                             else {
 56                                 var InfoStatus = "lose";
 57                                 var InfoContent = "采购单收货失败ff";
 58                                 var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
 59                                 ShowInfo(InfoStatus, InfoContent, InfoAction);
 60                             }
 61                         }
 62                     }
 63                 });
 64             }
 65         }
 66 
 67         //保存明细
 68         function SaveDetail(BiID) {
 69             $("#POD_STATUS_" + BiID).html("");
 70             var PoID = parseInt($("input[name='poID']").val().replace("CG", ""), 10);
 71             var SendAmount = $("#POD_SENDAMOUNT_" + BiID).val();
 72             var ReceiveAmount = $("#POD_RECEIVEAMOUNT_" + BiID).val();
 73             var InStock = $("#POD_STOCK_" + BiID).val();
 74             if (parseInt(ReceiveAmount) == 0) {
 75                 $("#POD_STOCK_" + BiID).removeAttr("notnull");
 76             }
 77             else {
 78                 $("#POD_STOCK_" + BiID).attr("notnull", "");
 79             }
 80             if (PoID > 0) {
 81                 if (ValidObj($("#POD_SENDAMOUNT_" + BiID)) && ValidObj($("#POD_RECEIVEAMOUNT_" + BiID)) && ValidObj($("#POD_STOCK_" + BiID))) {
 82                     $.ajax({
 83                         url: "Ajax.ashx",
 84                         data: {
 85                             OpType: "SaveReceiveDetail",
 86                             PoID: PoID,
 87                             BiID: BiID,
 88                             SendAmount: SendAmount,
 89                             ReceiveAmount: ReceiveAmount,
 90                             InStock: InStock
 91                         },
 92                         async: true,
 93                         cache: false,
 94                         dataType: "html",
 95                         error: function (a, b, c) {
 96                             if (b == "error") {
 97                                 $("#POD_STATUS_" + BiID).html("<img src=\"http://www.cnblogs.com/../Image/error.png\">");
 98                             }
 99                         },
100                         success: function (Result) {
101                             if (DontActionStatus.indexOf("," + Result + ",") >= 0) {
102                                 var InfoStatus = "lose";
103                                 var InfoContent = "采购单收货失败<br />" + GetPurchaseStatus(Result);
104                                 var InfoAction = "<a href=\"javascript:HidInfo()\">确定</a>";
105                                 ShowInfo(InfoStatus, InfoContent, InfoAction);
106                             }
107                             else {
108                                 $("#POD_STATUS_" + BiID).html("<img src=\"http://www.cnblogs.com/../Image/right.png\">");
109                             }
110                         }
111                     });
112                     CheckTotal();
113                 }
114             } else {
115                 alert("请先保存采购单信息");
116             }
117         }
118 
119         //汇总
120         function CheckTotal() {
121             var CountBuyAmount = 0;
122             var CountSendAmount = 0;
123             var CountReceiveAmount = 0;
124             $("TR[name='PurchaseDetail']").each(function (i) {
125                 var BiID = $(this).attr("id");
126 
127                 //绑定折扣回车键
128                 $("#POD_SENDAMOUNT_" + BiID).bind('keyup', function (event) {
129                     if (event.keyCode == "13") {
130                         //获取订单信息
131                         $("#POD_RECEIVEAMOUNT_" + BiID).select();
132                     }
133                 });
134                 //绑定数量回车键
135                 $("#POD_RECEIVEAMOUNT_" + BiID).bind('keyup', function (event) {
136                     if (event.keyCode == "13") {
137                         //获取订单信息
138                         $("#POD_STOCK_" + BiID).select();
139                     }
140                 });
141 
142                 CountBuyAmount += parseInt($("#POD_BUYAMOUNT_" + BiID).val());
143                 CountSendAmount += parseInt($("#POD_SENDAMOUNT_" + BiID).val());
144                 CountReceiveAmount += parseInt($("#POD_RECEIVEAMOUNT_" + BiID).val());
145             });
146             $("#BuyAmount_Total").val($("TR[name='PurchaseDetail']").length + "(" + CountBuyAmount + ")");
147             $("#SendAmount_Total").val($("TR[name='PurchaseDetail']").length + "(" + CountSendAmount + ")");
148             $("#ReceiveAmount_Total").val($("TR[name='PurchaseDetail']").length + "(" + CountReceiveAmount + ")");
149         }
150         //得到收货人员工姓名
151         function GetName() {
152             $.ajax({
153                 url: "Ajax.ashx",
154                 data: {
155                     OpType: "GetName",
156                     PoReceiveUser: $("input[name='poReceiveUserID']").val()
157                 },
158                 async: true,
159                 cache: false,
160                 dataType: "html",
161                 error: function (a, b, c) {
162                     if (b == "error") {
163                         var InfoStatus = "lose";
164                         var InfoContent = "人员查询失败</br>可能是您输入的信息有误</br>请检查";
165                         var InfoAction = "<a href=\"javascript:HidInfo()\">我再检查一下</a>";
166                         ShowInfo(InfoStatus, InfoContent, InfoAction);
167                     }
168                 },
169                 success: function (Result) {
170                     $("input[name='poReceiveUser']").val(Result);
171                 }
172             });
173         }
174 
175         function ReceivePrint() {
176             MakeAnotherWindow("ReceivePrint.aspx?poID=" + parseInt($("input[name='poID']").val().replace("CG", ""), 10), '',750, 520, "auto");
177         }
178     </script>
179 </asp:Content>
180 <asp:Content ID="QuickAction" ContentPlaceHolderID="QuickAction" runat="Server">
181     <a href="JavaScript:RedirectPage('170401','page=<%= page%>&poID=<%= poID%>&sdcID=<%= sdcID%>&bsID=<%= bsID%>&poStatus=<%= poStatus%>&poDateBegin=<%= poDateBegin%>&poDateEnd=<%= poDateEnd%>&poEstimateDateBegin=<%= poEstimateDateBegin%>&poEstimateDateEnd=<%= poEstimateDateEnd%>')">返回</a>
182 </asp:Content>
183 <asp:Content ID="Search" ContentPlaceHolderID="Search" runat="Server">
184     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="PurchaseOrder">
185         <tr>
186             <td id="poID_Title" class="SearchTitle" style="width: 10%"></td>
187             <td style="width: 13%">
188                 <input name="poID" type="text" title="采购单号" value="<%=  WebUtility.CreatePurchaseOrderCode(EditPoID)%>"
189                     notnull disabled />
190             </td>
191             <td id="sdcID_Title" class="SearchTitle" style="width: 10%"></td>
192             <td style="width: 13%">
193                 <select name="sdcID" title="采购库房" style="width: 100%;" notnull disabled>
194                     <option value="">全部</option>
195                     <%
196                         for (int i = 0; i < StockDataClass_List.Count; i++)
197                         {
198                     %>
199                     <option value="<%= StockDataClass_List[i].SdcID%>" <%= (StockDataClass_List[i].SdcID == EditSdcID) ? "selected" : ""%>>
200                         <%= StockDataClass_List[i].SdcName%></option>
201                     <%
202                         }
203                     %>
204                 </select>
205             </td>
206             <td id="bsID_Title" class="SearchTitle" style="width: 10%"></td>
207             <td style="width: 13%">
208                 <select name="bsID" title="供 应 商" style="width: 100%;" notnull disabled>
209                     <option value="">全部</option>
210                     <%
211             
212                         for (int i = 0; i < BookSupply_List.Count; i++)
213                         {
214                     %>
215                     <option value="<%= BookSupply_List[i].BsID%>" <%= (BookSupply_List[i].BsID == EditBsID) ? "selected" : ""%>>
216                         <%= BookSupply_List[i].BsName%></option>
217                     <%
218                         }
219                     %>
220                 </select>
221             </td>
222             <td id="poEstimateDate_Title" class="SearchTitle" style="width: 10%"></td>
223             <td style="width: 13%">
224                 <input name="poEstimateDate" type="text" title="到货日期" value="<%= EstimateDate%>" notnull disabled />
225             </td>
226             <td rowspan="<%= (PoIsDifference) ? 4 : 3%>" style="width: 8%; text-align: center; vertical-align: middle;">
227                 <input id="Button1" type="button" value="收货" style="height: 40px; font-weight: bold; margin-bottom: 15px;" onclick="SavePurchase()" />
228                 <input id="Button2" type="button" value="打印" style="height: 40px; font-weight: bold;" onclick="ReceivePrint()" />
229             </td>
230         </tr>
231         <tr>
232             <td id="poRemark_Title" class="SearchTitle" style="width: 10%"></td>
233             <td colspan="3">
234                 <input name="poRemark" type="text" title="采购备注" value="<%= PoRemark%>" disabled />
235             </td>
236             <td id="poAuditorRemark_Title" class="SearchTitle" style="width: 10%"></td>
237             <td colspan="3">
238                 <input name="poAuditorRemark" type="text" title="审核意见" value="<%= PoAuditorRemark%>" disabled />
239             </td>
240         </tr>
241         <tr>
242             <td id="poReceiveUserID_Title" class="SearchTitle" style="width: 10%"></td>
243             <td>
244                 <input name="poReceiveUserID" value="<%= PoReceiveUserID%>" type="text" title="收货人" style="width: 40%" onkeyup="GetName()" notnull /><input name="poReceiveUser" value="<%= PoReceiveUser%>" type="text" style="width: 49%" notnull readonly />
245             </td>
246             <td id="poSupplierOrder_Title" class="SearchTitle" style="width: 10%"></td>
247             <td>
248                 <input name="poSupplierOrder" value="<%= PoSupplierOrder%>" type="text" title="发货单号" notnull />
249             </td>
250             <td id="poReceiveAuditorRemark_Title" class="SearchTitle" style="width: 10%"></td>
251             <td colspan="3">
252                 <input name="poReceiveAuditorRemark" value="<%= PoReceiveAuditorRemark%>" type="text" title="收货备注" />
253             </td>
254         </tr>
255         <%
256             if (PoIsDifference)
257             {
258         %>
259         <tr>
260             <td id="poDifferenceAuditorUser_Title" class="SearchTitle" style="width: 10%"></td>
261             <td>
262                 <input name="poDifferenceAuditorUser" value="<%= PoDifferenceAuditorUser%>" type="text" title="差异确认人" disabled />
263             </td>
264             <td id="poDifferenceAuditorDate_Title" class="SearchTitle" style="width: 10%"></td>
265             <td>
266                 <input name="poDifferenceAuditorDate" value="<%= PoDifferenceAuditorDate%>" type="text" title="确认时间" disabled />
267             </td>
268             <td id="poDifferenceAuditorStatus_Title" class="SearchTitle" style="width: 10%"></td>
269             <td>
270                 <input name="poDifferenceAuditorStatus" value="<%= PoDifferenceAuditorStatus%>" type="text" title="确认状态" disabled />
271             </td>
272             <td id="poDifferenceAuditorRemark_Title" class="SearchTitle" style="width: 10%"></td>
273             <td>
274                 <input name="poDifferenceAuditorRemark" value="<%= PoDifferenceAuditorRemark%>" type="text" title="确认备注" disabled />
275             </td>
276         </tr>
277         <%
278             }
279         %>
280     </table>
281 </asp:Content>
282 <asp:Content ID="ContentBody" ContentPlaceHolderID="ContentBody" runat="Server">
283     <table border="0" cellpadding="3" cellspacing="0" style="width: 100%;" id="ListTable">
284         <tr>
285             <td class="ListTitle" style="width: 3%"></td>
286             <td class="ListTitle" style="width: 7%">商品ID
287             </td>
288             <td class="ListTitle" style="width: 8%">条形码
289             </td>
290             <td class="ListTitle" style="width: 27%">书名
291             </td>
292             <td class="ListTitle" style="width: 15%">出版社
293             </td>
294             <td class="ListTitle" style="width: 8%">定价
295             </td>
296             <td class="ListTitle" style="width: 8%">采购数量
297             </td>
298             <td class="ListTitle" style="width: 8%">发货数量
299             </td>
300             <td class="ListTitle" style="width: 8%">实收数量
301             </td>
302             <td class="ListTitle" style="width: 8%">上架货位
303             </td>
304         </tr>
305         <%
306             for (int i = 0; i < PurchaseOrderDetail_List.Count; i++)
307             {
308                 string PodSendAmount = "";
309                 string PodReceiveAmount = "";
310                 if (PurchaseOrderDetail_List[i].PodSendAmount > 0)
311                 {
312                     PodSendAmount = PurchaseOrderDetail_List[i].PodSendAmount.ToString();
313                 }
314                 if (PurchaseOrderDetail_List[i].PodReceiveAmount > 0)
315                 {
316                     PodReceiveAmount = PurchaseOrderDetail_List[i].PodReceiveAmount.ToString();
317                 }
318 
319                 string InStock = PurchaseOrderDetail_List[i].PodPlace;
320                 if (InStock == null)
321                 {
322                     InStock = GetPlace(PurchaseOrderDetail_List[i].BiID.BiID);
323                 }
324                 
325         %>
326         <tr name="PurchaseDetail" id="<%= PurchaseOrderDetail_List[i].BiID.BiID%>">
327             <td class="ListContent" id="POD_STATUS_<%= PurchaseOrderDetail_List[i].BiID.BiID%>"></td>
328             <td class="ListContent">
329                 <%= WebUtility.CreateBookCode(PurchaseOrderDetail_List[i].BiID.BiID)%>
330             </td>
331             <td class="ListContent">
332                 <%= PurchaseOrderDetail_List[i].BiID.BiCode%>
333             </td>
334             <td class="ListContent">
335                 <%= PurchaseOrderDetail_List[i].BiID.BiName%>
336             </td>
337             <td class="ListContent">
338                 <%= PurchaseOrderDetail_List[i].BiID.BibsID.BsName%>
339             </td>
340             <td class="ListContent">
341                 <%= PurchaseOrderDetail_List[i].BiID.BiPrice.ToString("F2")%>
342             </td>
343             <td class="ListContent">
344                 <input id="POD_BUYAMOUNT_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" type="text" style="text-align: right;" value="<%= Convert.ToInt32(PurchaseOrderDetail_List[i].PodBuyAmount)%>" readonly />
345             </td>
346             <td class="ListContent">
347                 <input id="POD_SENDAMOUNT_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" value="<%= PodSendAmount%>" type="text" style="text-align: right;" onchange="SaveDetail('<%= PurchaseOrderDetail_List[i].BiID.BiID%>')"
348                     datatype="n0" notnull />
349             </td>
350             <td class="ListContent">
351                 <input id="POD_RECEIVEAMOUNT_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" value="<%= PodReceiveAmount%>" type="text" style="text-align: right;" onchange="SaveDetail('<%= PurchaseOrderDetail_List[i].BiID.BiID%>')"
352                     datatype="n0" notnull />
353             </td>
354             <td class="ListContent">
355                 <input id="POD_STOCK_<%= PurchaseOrderDetail_List[i].BiID.BiID%>" value="<%= InStock%>"  <%= (InStock=="") ? "":"disabled" %>     type="text" style="text-align: right;" onchange="SaveDetail('<%= PurchaseOrderDetail_List[i].BiID.BiID%>')"   notnull   />
356             </td>
357         </tr>
358         <%
359             }
360         %>
361         <tr>
362             <td class="ListTotal" colspan="6" style="text-align: right;">合计:</td>
363             <td class="ListTotal">
364                 <input id="BuyAmount_Total" type="text" style="text-align: right;" disabled />
365             </td>
366             <td class="ListTotal">
367                 <input id="SendAmount_Total" type="text" style="text-align: right;" disabled />
368             </td>
369             <td class="ListTotal">
370                 <input id="ReceiveAmount_Total" type="text" style="text-align: right;" disabled />
371             </td>
372             <td class="ListTotal"></td>
373         </tr>
374     </table>
375 </asp:Content>

编辑页面后台代码如图所示:

View Code
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Web.UI;
  4 
  5 using BNbll;
  6 using BNmodel;
  7 using BNutility;
  8 
  9 public partial class WBPmodule_Purchase_In_ReceiveEdit : System.Web.UI.Page
 10 {
 11     protected int page = 1;
 12     protected string poID = "";
 13     protected string sdcID = "";
 14     protected string bsID = "";
 15     protected string poStatus = "";
 16     protected string poDateBegin = "";
 17     protected string poDateEnd = "";
 18     protected string poEstimateDateBegin = "";
 19     protected string poEstimateDateEnd = "";
 20     protected string bsID_Responsible = "";
 21 
 22     protected int EditPoID = 0;
 23     protected int EditSdcID = 0;
 24     protected int EditBsID = 0;
 25     protected string EstimateDate = DateTime.Now.ToString("yyyy-MM-dd");
 26     protected string PoRemark = "";
 27     protected string PoAuditorRemark = "";
 28     protected string PoReceiveUser = "";
 29     protected string PoReceiveUserID = "";
 30     protected string PoSupplierOrder = "";
 31     protected string PoReceiveAuditorRemark = "";
 32 
 33     protected bool PoIsDifference = false;
 34     protected string PoDifferenceAuditorUser = "";
 35     protected string PoDifferenceAuditorDate = "";
 36     protected string PoDifferenceAuditorStatus = "";
 37     protected string PoDifferenceAuditorRemark = "";
 38 
 39 
 40     protected List<StockDataClass> StockDataClass_List = new List<StockDataClass>();
 41     protected List<BookSupply> BookSupply_List = new List<BookSupply>();
 42     protected List<PurchaseOrderDetail> PurchaseOrderDetail_List = new List<PurchaseOrderDetail>();
 43     protected List<Stock> Stock_List = new List<Stock>();
 44 
 45 
 46     BookSupplyManager BookSupply_Bll = new BookSupplyManager();
 47     SYS_UserInfoManager UserInfo_Bll = new SYS_UserInfoManager();
 48     StockDataClassManager StockDataClass_Bll = new StockDataClassManager();
 49     PurchaseOrderManager PurchaseOrder_Bll = new PurchaseOrderManager();
 50     PurchaseOrderDetailManager PurchaseOrderDetail_Bll = new PurchaseOrderDetailManager();
 51 
 52     protected void Page_Load(object sender, EventArgs e)
 53     {
 54         poID = Request.QueryString["poID"];
 55         sdcID = Request.QueryString["sdcID"];
 56         bsID = Request.QueryString["bsID"];
 57         poStatus = Request.QueryString["poStatus"];
 58         poDateBegin = Request.QueryString["poDateBegin"];
 59         poDateEnd = Request.QueryString["poDateEnd"];
 60         poEstimateDateBegin = Request.QueryString["poEstimateDateBegin"];
 61         poEstimateDateEnd = Request.QueryString["poEstimateDateEnd"];
 62         page = WebUtility.CheckParamID(Request.QueryString["Page"], page);
 63 
 64 
 65         if (!String.IsNullOrEmpty(Request.QueryString["EditPoID"]))
 66         {
 67             EditPoID = WebUtility.CheckParamID(Request.QueryString["EditPoID"], 0);
 68             PurchaseOrder PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(EditPoID, "SdcID:{SdcID},BsID:{BsID},PoEstimateDate,PoRemark,PoAuditorRemark,PoReceiveUser:{SysuiID,SysuiName},PoSupplierOrder,PoReceiveAuditorRemark,PoIsDifference,PoDifferenceAuditorUser:{SysuiName},PoDifferenceAuditorDate,PoDifferenceAuditorStatus,PoDifferenceAuditorRemark");
 69             EditSdcID = PurchaseOrder_Info.SdcID.SdcID;
 70             EditBsID = PurchaseOrder_Info.BsID.BsID;
 71             EstimateDate = PurchaseOrder_Info.PoEstimateDate.ToString("yyyy-MM-dd");
 72             PoRemark = PurchaseOrder_Info.PoRemark;
 73             PoAuditorRemark = PurchaseOrder_Info.PoAuditorRemark;
 74             if (PurchaseOrder_Info.PoReceiveUser != null)
 75             {
 76                 PoReceiveUser = PurchaseOrder_Info.PoReceiveUser.SysuiName;
 77                 PoReceiveUserID = PurchaseOrder_Info.PoReceiveUser.SysuiID.ToString();
 78             }
 79             PoSupplierOrder = PurchaseOrder_Info.PoSupplierOrder;
 80             PoReceiveAuditorRemark = PurchaseOrder_Info.PoReceiveAuditorRemark;
 81 
 82             PoIsDifference = PurchaseOrder_Info.PoIsDifference;
 83             if(PurchaseOrder_Info.PoDifferenceAuditorUser!=null)
 84             {
 85             PoDifferenceAuditorUser = PurchaseOrder_Info.PoDifferenceAuditorUser.SysuiName;
 86             }
 87             PoDifferenceAuditorDate = PurchaseOrder_Info.PoDifferenceAuditorDate.ToString("yyyy-MM-dd");
 88             if (PurchaseOrder_Info.PoDifferenceAuditorStatus)
 89             {
 90                 PoDifferenceAuditorStatus = "已确认";
 91             }
 92             else
 93             {
 94                 PoDifferenceAuditorStatus = "不认可";
 95             }
 96             PoDifferenceAuditorRemark = PurchaseOrder_Info.PoDifferenceAuditorRemark;
 97 
 98             List<SqlWhere> PurchaseOrderDetailWhere = new List<SqlWhere>();
 99             PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, EditPoID));
100             PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "PodID,BiID:{BiID,BiCode,BiName,BibsID:{BsName},BiPrice},PodPrice,PodBuyAmount,PodSendAmount,PodReceiveAmount,PodPlace", PurchaseOrderDetailWhere, null);
101         }
102 
103         List<SqlWhere> StockDataCalssWhere = new List<SqlWhere>();
104         StockDataCalssWhere.Add(new SqlWhere(StockDataClass.SDCPARENTID, SqlWhere.Oper.Equal, 1));
105         StockDataCalssWhere.Add(new SqlWhere(StockDataClass.SDCSTATUS, SqlWhere.Oper.Equal, 1));
106         StockDataClass_List = StockDataClass_Bll.GetList(0, 0, "sdcID,sdcName", StockDataCalssWhere, null);
107 
108         List<SqlWhere> BookSupplyWhere = new List<SqlWhere>();
109         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSID, SqlWhere.Oper.MoreEqual, 0));
110         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSISSUPPLIER, SqlWhere.Oper.Equal, 1));
111         BookSupplyWhere.Add(new SqlWhere(BookSupply.BSSTATUS, SqlWhere.Oper.Equal, 1));
112         if (!String.IsNullOrEmpty(bsID_Responsible))
113         {
114             BookSupplyWhere.Add(new SqlWhere(BookSupply.BSID, SqlWhere.Oper.In, bsID_Responsible));
115         }
116         List<SqlOrder> BookSupplyOrder = new List<SqlOrder>();
117         BookSupplyOrder.Add(new SqlOrder(BookSupply.BSNAME, true));
118         BookSupply_List = BookSupply_Bll.GetList(0, 0, "bsID,bsName", BookSupplyWhere, BookSupplyOrder);
119     }
120 
121     public string GetPlace(int BiID)
122     {
123         string InStock = "";
124         List<SqlWhere> StockPlaceWhere = new List<SqlWhere>();
125         StockPlaceWhere.Add(new SqlWhere(StockPlace.BIID, SqlWhere.Oper.Equal, BiID));
126         List<SqlOrder> StockPlaceOrder = new List<SqlOrder>();
127         StockPlaceOrder.Add(new SqlOrder(StockPlace.SPDATE, false));
128 
129         List<StockPlace> StockPlace_List = new List<StockPlace>();
130         StockPlaceManager StockPlace_Bll=new StockPlaceManager();
131         StockPlace_List = StockPlace_Bll.GetList(1, 1, "SpPlace", StockPlaceWhere, StockPlaceOrder);
132         if (StockPlace_List.Count > 0)
133         {
134             if (StockPlace_List[0].SpPlace == null)
135             {
136                 StockPlace_List[0].SpPlace = "";
137                     
138               
139             }
140             InStock = StockPlace_List[0].SpPlace.ToString();
141         }
142         
143        
144         return InStock;
145     }
146 
147 }

AJAX一般处理程序代码如图所示:

View Code
 1 //获取收货人姓名
 2             case "GetName":
 3                 if (!string.IsNullOrEmpty(PoReceiveUser))
 4                 {
 5                     SYS_UserInfo UserInfo_Models = UserInfo_Bll.GetModels(Convert.ToInt32(PoReceiveUser), "sysuiName");
 6                     if (UserInfo_Models != null)
 7                     {
 8                         Result = UserInfo_Models.SysuiName;
 9                     }
10                     else
11                     {
12                         Result = "工号不存在";
13                     }
14                 }
15                 break;
16             //保存收货明细
17             case "SaveReceiveDetail":
18                 if (!String.IsNullOrEmpty(PoID) && PoID != "0")
19                 {
20                     PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID,PoStatus");
21                     if (PurchaseOrder_Info.PoStatus == 12)
22                     {
23                         PurchaseOrderDetailWhere.Clear();
24                         PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.POID, SqlWhere.Oper.Equal, PoID));
25                         PurchaseOrderDetailWhere.Add(new SqlWhere(PurchaseOrderDetail.BIID, SqlWhere.Oper.Equal, BiID));
26                         PurchaseOrderDetail_List = PurchaseOrderDetail_Bll.GetList(0, 0, "PodID,PodPrice,PodBuyAmount,PodReturnAmount,PodPayAmount", PurchaseOrderDetailWhere, null);
27                         if (PurchaseOrderDetail_List.Count > 0)
28                         {
29                             PurchaseOrderDetail_Info = PurchaseOrderDetail_List[0];
30                         }
31                         PurchaseOrderDetail_Info.PoID = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID");
32                         PurchaseOrderDetail_Info.BiID = BookInfo_Bll.GetModels(Convert.ToInt32(BiID), "BiID");
33                         PurchaseOrderDetail_Info.PodSendAmount = Convert.ToInt32(SendAmount);
34                         PurchaseOrderDetail_Info.PodReceiveAmount = Convert.ToInt32(ReceiveAmount);
35                         PurchaseOrderDetail_Info.PodPlace = InStock;
36 
37                         PurchaseOrderDetail_Bll.SaveModels(PurchaseOrderDetail_Info);
38                     }
39                     else
40                     {
41                         Result = CheckStatus(PurchaseOrder_Info.PoStatus);
42                     }
43                 }
44                 break;
45             //收货一次性入库
46             case "Receive":
47                 if (!String.IsNullOrEmpty(PoID) && PoID != "0")
48                 {
49                     PurchaseOrder_Info = PurchaseOrder_Bll.GetModels(Convert.ToInt32(PoID), "PoID,PoStatus");
50                     if (PurchaseOrder_Info.PoStatus == 12)
51                     {
52                         Result = PurchaseOrder_Bll.Receive(PurchaseOrder_Info.PoID, PoReceiveUser, PoSupplierOrder, UserInfo_Bll.CookieUserID, PoReceiveAuditorRemark);
53                     }
54                     else
55                     {
56                         Result = CheckStatus(PurchaseOrder_Info.PoStatus);
57                     }
58                 }
59                 break;

对各表操作的存储过程如下所示:

View Code
  1 USE [BookNet]
  2 GO
  3 /****** Object:  StoredProcedure [dbo].[PurchaseReceive]    Script Date: 01/10/2013 17:21:58 ******/
  4 SET ANSI_NULLS ON
  5 GO
  6 SET QUOTED_IDENTIFIER ON
  7 GO
  8 
  9 ALTER PROCEDURE [dbo].[PurchaseReceive]
 10     @poID int,
 11     @poReceiveUser int,
 12     @poSupplierOrder varchar(50),
 13     @poReceiveAuditorUser int,
 14     @poReceiveAuditorRemark varchar(500)
 15 AS
 16 BEGIN
 17     DECLARE @bsID int
 18     DECLARE @sdcID int
 19     DECLARE @status int
 20     DECLARE @poIsDifference bit
 21 
 22     DECLARE @podID int
 23     DECLARE @biID int
 24     DECLARE @podPrice decimal(14,4)
 25     DECLARE @podSendAmount int
 26     DECLARE @podReceiveAmount int
 27     DECLARE @podPlace varchar(20)
 28 
 29     DECLARE @spID int = 0
 30     
 31     DECLARE @sbID int =0
 32     DECLARE @spAmount int =0
 33 
 34     DECLARE @Result varchar(20)=''
 35 
 36     --获取采购单信息
 37     SELECT @bsID = bsID, @sdcID = sdcID, @status = poStatus FROM PurchaseOrder WHERE poID= @PoID
 38 
 39     --判断订单是否已发货
 40     IF @status = 0
 41         BEGIN
 42             SET @Result = 'Delete'
 43         END
 44 
 45     --判断订单是否已发货
 46     IF @status = 10
 47         BEGIN
 48             SET @Result = 'NewOrder'
 49         END
 50 
 51     --判断订单是否已发货
 52     IF @status = 11
 53         BEGIN
 54             SET @Result = 'Refuser'
 55         END
 56 
 57     --判断订单是否已发货
 58     IF @status = 31
 59         BEGIN
 60             SET @Result = 'Difference'
 61         END
 62 
 63     --判断订单是否已发货
 64     IF @status = 32
 65         BEGIN
 66             SET @Result = 'InStock'
 67         END
 68 
 69     --判断订单是否已发货
 70     IF @status = 41
 71         BEGIN
 72             SET @Result = 'NotConfirmation'
 73         END
 74 
 75     --判断订单是否已发货
 76     IF @status = 42
 77         BEGIN
 78             SET @Result = 'Confirmation'
 79         END
 80 
 81     --判断订单是否已发货
 82     IF @status = 61
 83         BEGIN
 84             SET @Result = 'NotAccounting'
 85         END
 86 
 87     --判断订单是否已发货
 88     IF @status = 62
 89         BEGIN
 90             SET @Result = 'Accounting'
 91         END
 92 
 93         
 94     --判断订单是否可以分配库存
 95     IF @status = 12
 96         BEGIN
 97             BEGIN TRAN--开始事务    
 98             DECLARE @ErrorCount INT --定义错误计数器
 99             SET @ErrorCount = 0
100 
101             --修改采购单状态
102             UPDATE PurchaseOrder SET poStatus = 32, poReceiveUser = @poReceiveUser, poReceiveAuditorUser = @poReceiveAuditorUser, poReceiveAuditorDate = GETDATE(), poReceiveAuditorRemark = @poReceiveAuditorRemark, poSupplierOrder = @poSupplierOrder WHERE poID = @poID
103             SET @ErrorCount = @ErrorCount + @@ERROR
104             
105             
106 
107             --获取采购明细
108             DECLARE PurchaseOrderList CURSOR FOR SELECT podID, biID, podPrice, podSendAmount, podReceiveAmount, podPlace FROM PurchaseOrderDetail WHERE poID = @poID
109             
110             --打开采购明细游标
111             OPEN PurchaseOrderList
112 
113             --填充采购明细游标
114             FETCH NEXT FROM PurchaseOrderList INTO @podID, @biID, @podPrice, @podSendAmount, @podReceiveAmount, @podPlace
115 
116             --开始采购明细游标
117             WHILE @@FETCH_STATUS<>-1
118                 BEGIN
119                     IF @podSendAmount <> @podReceiveAmount
120                         BEGIN
121                             SET @poIsDifference = 1
122                         END
123                         
124                         UPDATE Stock SET sAmount=sAmount+@podReceiveAmount WHERE biID=@biID AND sdcID=@sdcID
125                         --插入批次库存
126                         INSERT INTO StockBatch VALUES(11,@podID,@bsID,@sdcID,@biID,@podID,@podPrice,@podReceiveAmount,0,@poReceiveUser,GETDATE())
127                         SET @ErrorCount = @ErrorCount + @@ERROR    
128                     
129                         SELECT @sbID=sbID FROM StockBatch WHERE sdcID=@sdcID AND bsID=@bsID AND biID=@biID AND podID=@podID
130                         INSERT INTO HistoryBatch VALUES(11,@poID,@podID,@sdcID,null,@bsID,@biID,@sbID,@podPrice,0,0,0,@podReceiveAmount,0,@poReceiveUser,GETDATE())
131                         SET @ErrorCount = @ErrorCount + @@ERROR    
132                                         
133                         SET @spID=0
134                         SELECT @spID=spID,@spAmount=spAmount FROM StockPlace WHERE sdcID=@sdcID AND spPlace=@podPlace AND biID=@biID
135                         IF  @spID=0
136                             BEGIN
137                                 INSERT INTO StockPlace VALUES(@sdcID,@podPlace,@biID,@podReceiveAmount,@spAmount,@poReceiveUser,GETDATE())
138                                 SET @ErrorCount = @ErrorCount + @@ERROR
139                                 INSERT INTO HistoryStock VALUES(11,@poID,@podID,@sdcID,@biID,@podPlace,@spAmount,@podReceiveAmount,@poReceiveUser,GETDATE())
140                                 SET @ErrorCount = @ErrorCount + @@ERROR
141                                                         
142                             END
143                         ELSE
144                             BEGIN
145                                 UPDATE StockPlace SET spAmount=spAmount+@podReceiveAmount WHERE spID=@spID
146                                 SET @ErrorCount = @ErrorCount + @@ERROR
147                                 INSERT INTO HistoryStock VALUES(11,@poID,@podID,@sdcID,@biID,@podPlace,@spAmount,@podReceiveAmount,@poReceiveUser,GETDATE())
148                                 SET @ErrorCount = @ErrorCount + @@ERROR                        
149                             END
150                     --自动完成缺货订单发货
151                     --EXECUTE OrderLack @biID, @sdcID
152 
153                     --继续下一条采购明细游标
154                     FETCH NEXT FROM PurchaseOrderList INTO @podID, @biID, @podPrice, @podSendAmount, @podReceiveAmount, @podPlace
155                 END
156             --关闭采购明细游标
157             CLOSE PurchaseOrderList
158             --删除采购明细游标
159             DEALLOCATE PurchaseOrderList
160 
161             IF @poIsDifference = 1
162                 BEGIN
163                     --修改采购单状态
164                     UPDATE PurchaseOrder SET poStatus = 31, poIsDifference = 1 WHERE poID = @poID
165                     SET @ErrorCount = @ErrorCount + @@ERROR
166                 END
167             
168             IF @ErrorCount = 0
169                 BEGIN
170                     COMMIT TRAN--事务提交语句
171                     SET @Result = 'Succeed'
172                 END
173             ELSE
174                 BEGIN
175                     ROLLBACK TRAN--事务回滚语句
176                     SET @Result = 'ReceiveFail'
177                 END
178         END
179     SELECT @Result AS Result
180 END

关于采购功能的描到此就结束了,ERP主要是业务流程的问题。后面还要有记账、以及差异确认、折扣确认流程。这里就不一一详细讲解,后面的只是修改采购单的状态。这里描述的很简单,实际上的系统中注意的东西太多,没有办法一一写出。如有同路人,可共同讨论,共同进步~

posted @ 2013-01-10 17:31  孙进  阅读(1302)  评论(0编辑  收藏  举报