ERP发货系统的修改(四十三)
产品添加批号后相应修改产品库存表中对应批次产品的数量:
/// /// 产品添加批号后相应修改产品库存表中对应批次产品的数量 /// /// 库存表主键编号 /// 发货的数量 /// int public static int BioProStockUpdateCount(int stockproid, int procount) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@ID",stockproid), new SqlParameter("@ProCout",procount) }; return DataBaseHelper.ExcuteSqlReturnInt("BioProStockUpdateCount", CommandType.StoredProcedure, pars); }
视图实现按发货单查询产品批次信息,将查询结果进行数据 绑定:
CREATE VIEW [dbo].[ViewSendProBaths]ASSELECT a.ProBatchID, a.SendProID, a.batchNum,a.boxNum,a.proCount,a.ProStockID,CONVERT(NVARCHAR(10),a.stockDate,121) AS stockDate,a.stockID,CONVERT(NVARCHAR(10),a.expirationDate,121) AS expirationDate, CONVERT(NVARCHAR(10),a.makeDate,121)AS makeDate,a.isprinted ,b.SendID,b.ProID,b.ProCount AS procounttotalFROM dbo.BioSendProBatch AS a INNER JOIN dbo.BioSendGoodsProAS b ON b.SendProID = a.SendProID
当前产品批次的数量和库存表中的数量进行比较:(Ajax代码)
//判断产品数量是否满足需求 function isProBathCountFull(obj) { //库存表编号(主键) var prostockid = $($(obj).parent().parent().find("input[name='stockproid']")[0]).val(); var procount=$(obj).val(); if (prostockid != '' && prostockid !=undefined) { if (procount != '' && procount !=undefined && procount != '0') { $.ajax({ type: "POST", //设置提交方式 url: "getProBatchCount.aspx", data: "prostockid=" + prostockid + "&procount=" + procount, //提交数据 success: function (msg) { if (msg == "OK") { } else { alert(msg); $(obj).attr("value", ""); } } }); } } else { alert("请先选择产品"); $(obj).attr("value", ""); } }
后台代码:
protected void Page_Load(object sender, EventArgs e) { string returnResult = "";//定义返回状态 this.Response.Clear(); string prostockid = Request.Form["prostockid"].ToString(); string procount = Request.Form["procount"].ToString(); returnResult = prostockid + " " + procount; object obj = SqlComm.GetObjectByCondition("dbo.BioProStock", "isnull(ProCout,0)", " ID=" + prostockid); if (obj != null) { if (int.Parse(obj.ToString()) < int.Parse(procount)) { returnResult = "此产品此批次库存不足,最多发货数据" + obj.ToString(); } else { returnResult = "OK"; } } this.Response.Write(returnResult); this.Response.End(); }
修改的前台代码:
后台代码:
public partial class SendGoodsEdit: BasePage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DepartMentBand(); pageinfobind(); } } public DataTable dt; public DataTable probathsdt; string taskid = "8"; string listid = "75"; /// /// 是否具备财务权限,默认为Fasle /// public static string isfinance = "false"; public static string isquality = "false"; public static string isprobatch = "false"; public static string isstock = "false"; public static int probaths = 0; /// /// 页面信息加载 /// protected void pageinfobind() { //是否具有财务权限 isfinance = SqlComm.getUserRightsByUserId(Session["Userid"].ToString()).Contains("," + ((int)RightEmun.finance).ToString() + ",") ? "true" : "false"; //是否具备质量审核权限 isquality = SqlComm.getUserRightsByUserId(Session["Userid"].ToString()).Contains("," + ((int)RightEmun.quality).ToString() + ",")?"true":"false"; //是否具备添加产品批号的权限 isprobatch= SqlComm.getUserRightsByUserId(Session["Userid"].ToString()).Contains("," + ((int)RightEmun.probatch).ToString() + ",") ? "true" : "false"; //是否具备仓库审核权限 isstock = SqlComm.getUserRightsByUserId(Session["Userid"].ToString()).Contains("," + ((int)RightEmun.stock).ToString() + ",") ? "true" : "false"; BioSendGoodsBLL sendgoodsview = new BioSendGoodsBLL(); ViewBioSendAppInfo viewsendinfo= sendgoodsview.GetModel(int.Parse(taskid)); ddlDepartMent.SelectedValue= viewsendinfo.DepartMentID.ToString(); this.lbApplayUser.Text = viewsendinfo.AppUserName; this.hf_applayUserid.Value = viewsendinfo.AppUserId.ToString(); this.txtRealUserID.Text = viewsendinfo.RealUserID.ToString(); this.lbRealUserName.Text = viewsendinfo.RealUser; this.lbTime.Text = Convert.ToDateTime(viewsendinfo.submitTime).ToString("yyyy-MM-dd"); this.txtSendCom.Text = viewsendinfo.ReceiveComID.ToString(); getLinkMan(); this.ddlOuserCom.SelectedItem.Text = viewsendinfo.OurCom; this.ddlTypes.SelectedItem.Text = viewsendinfo.sendType; this.ddlLinkMan.SelectedValue = viewsendinfo.Receiver; this.txtTelphone.Text = viewsendinfo.telephone; this.txtMobile.Text = viewsendinfo.mobile; if (viewsendinfo.BillNo != null && viewsendinfo.BillNo != "") { this.lbBillNo.Text = viewsendinfo.BillNo; this.cbisfinance.Checked = true; if (bool.Parse(isfinance)) { this.cbisfinance.Enabled = false; } } if (viewsendinfo.QualityUserid != null && viewsendinfo.QualityUserid != 0 && viewsendinfo.isQualityCheck != false) { this.cbquality.Checked = true; this.cbquality.Enabled = false; } //是否仓库审核 if (viewsendinfo.isOutStockCheck == true) { this.cbISstock.Checked = true; this.cbISstock.Disabled = true; this.txtPostUnit.Text = viewsendinfo.postUnit.ToString(); this.txtPhone.Text = viewsendinfo.postPhone.ToString(); this.txtPostWay.Text = viewsendinfo.postWay; this.ddlPostWay.SelectedValue = viewsendinfo.postWay; this.txtpostRemark.Text = viewsendinfo.postRemak; //ScriptManager.RegisterStartupScript(this,this.GetType(), "trpostinfoshow", "$('#trpostinfo').show()", true); } //if (this.cbisfinance.Checked == true && this.cbquality.Checked == true && bool.Parse(isprobatch)) //{ // ClientScript.RegisterStartupScript(this.GetType(), "test", "showobjbyName('btnaddbatch')", true); //} dt=SqlComm.GetDataByCondition("dbo.BioSendGoodsPro", "*,ProName=dbo.FN_getProNameByProID(ProID)", " SendID=" + taskid).Tables[0]; probathsdt= SqlComm.GetDataByCondition("dbo.ViewSendProBaths", "*,ProName=dbo.FN_getProNameByProID(ProID)", " SendID=" + taskid).Tables[0]; probaths = probathsdt.Rows.Count; if (probathsdt.Rows.Count > 0) { ClientScript.RegisterStartupScript(this.GetType(), "showprobatchs", "$('#trprobatch').show()", true); } //加载历史审批记录 this.lbHistory.Text= SqlComm.getTaskListRecordsMindsByCondition(taskid, ((int)TaskNavigateEmun.ProSend).ToString()); this.hf_subject.Value = SqlComm.getTaskListSubjectByCondition(listid); this.hf_FirstTransmitter.Value = SqlComm.getFirstTransmitterByCondition(listid); this.hf_FirstAccepter.Value = SqlComm.getFirstAccpterByCondition(listid); //string rights= SqlComm.getUserRightsByUserId(Session["Userid"].ToString()); //判断是否具有财务权限和部门经理角色,如果是,则显示“拒绝审核按钮”,否则不显示 if ((Web.UserLogin.user.RoleId == 3 && Web.UserLogin.user.DepartmentId == int.Parse(this.ddlDepartMent.SelectedValue.ToString())) || bool.Parse(isfinance)) { this.btnReject.Visible = true; } else { this.btnReject.Visible = false; } } /// /// 绑定部门信息 /// private void DepartMentBand() { ddlDepartMent.DataSource = SqlComm.getDepartMent(); ddlDepartMent.DataTextField = "DepartmentName"; ddlDepartMent.DataValueField = "DepartmentId"; ddlDepartMent.DataBind(); //ddlDepartMent.Items.Add(new ListItem("--请选择部门--", "0")); //ddlDepartMent.SelectedValue = "0"; } protected void btnSubmit_Click(object sender, EventArgs e) { //部门经理角色 并且当前用户所属部门为表单所选部门 try { //判断是否具备财务权限 并且当前财务审核通过 if (bool.Parse(isfinance) && this.cbisfinance.Checked == true) { SqlComm.UpdateTableByCondition("dbo.BioSendAppInfo", "BillNo='" + this.lbBillNo.Text + "',BillUserID='" + Session["Userid"] + "'", " SendId=" + taskid); } //判断是否具备质量申请权限,并且当前的财务审核通过之后才能提交质量审核 if (bool.Parse(isquality) && this.cbisfinance.Checked == true && this.cbquality.Checked == true) { SqlComm.UpdateTableByCondition("dbo.BioSendAppInfo", "QualityUserid='" + Session["Userid"].ToString() + "',isQualityCheck=" + 1, " SendId=" + taskid); } if (this.cbisfinance.Checked == true && this.cbquality.Checked == true && bool.Parse(isprobatch)==true) { string proname = Request["proname0"].ToString(); string proId = Request["proIds"].ToString(); string txtProCount = Request["txtProCount0"].ToString(); string txtProBatch=Request["txtProBatch0"].ToString(); string txtProBoxNum = Request["txtProBoxNum0"].ToString(); string txtMarkDate = Request["txtMarkDate0"].ToString(); string txtExPirationDate = Request["txtExPirationDate0"].ToString(); string SendProID = Request["SendProID2"].ToString(); string stockproid = Request["stockproid"].ToString(); string stockDate = Request["txtStockDate0"].ToString(); string stockid = Request["stockid"].ToString(); //默认产品批次,如果为新添加产品批次则初始值为0,如果是修改数据则为数据库中绑定的产品批次数据 string oldprobatchcount = Request["oldprobatchcount"].ToString(); string ProBatchID=Request["ProBatchID"].ToString(); //string[] pronamess = proname.Split(','); //string[] proIdss = proId.Split(','); string[] txtProCounts = txtProCount.Split(','); string[] txtProBatchs=txtProBatch.Split(','); string[] txtProBoxNums = txtProBoxNum.Split(','); string[] txtMarkDates = txtMarkDate.Split(','); string[] txtExPirationDates = txtExPirationDate.Split(','); string[] SendProIDs = SendProID.Split(','); string[] stockproids = stockproid.Split(','); string[] stockDates = stockDate.Split(','); string[] stockids = stockid.Split(','); string[] oldprobatchcounts = oldprobatchcount.Split(','); string []ProBatchIDs=ProBatchID.Split(','); BioSendProBatch probacth = new BioSendProBatch(); BioSendGoodsBLL sendbll = new BioSendGoodsBLL(); for (int i = 0; i < SendProIDs.Length; i++) { //probacth.ProStockID probacth.SendProID = int.Parse(SendProIDs[i]); //1:old 10 new 8 2:old 10 new 12 probacth.proCount = int.Parse(txtProCounts[i]); probacth.ProStockID = int.Parse(stockproids[i]); probacth.stockDate = DateTime.Parse(stockDates[i]); probacth.stockID = int.Parse(stockids[i]); probacth.batchNum = txtProBatchs[i]; probacth.boxNum = txtProBoxNums[i]; probacth.makeDate = DateTime.Parse(txtMarkDates[i]); probacth.expirationDate = DateTime.Parse(txtExPirationDates[i]); if (oldprobatchcounts[i] == "0") { //添加产品批次 sendbll.BioSendProBatchADD(probacth); //修改产品库存数据(出库) SqlComm.BioProStockUpdateCount(int.Parse(probacth.ProStockID.ToString()), int.Parse(probacth.proCount.ToString())); } else { if (oldprobatchcounts[i] != txtProCounts[i]) { //修改当前批次表中相应产品数据 SqlComm.UpdateTableByCondition("dbo.BioSendProBatch", "proCount=" + int.Parse(txtProCounts[i]), "ProBatchID=" + ProBatchIDs[i]); int batchcount = int.Parse(txtProCounts[i]) - int.Parse(oldprobatchcounts[i]); //修改产品库存表中对应批次的数据 SqlComm.UpdateTableByCondition("dbo.BioProStock", "ProCout=(ProCout-(" + batchcount + "))", "ID=" + stockproids[i]); } } } } TaskListInsert(); ContextUtil.SetComplete(); } catch (Exception ex) { ContextUtil.SetAbort(); ClientScript.RegisterStartupScript(this.GetType(),"test","alert('提交失败,数据回滚')",true); } } /// /// 添加新的流行表数据并修改之前的数据 /// private void TaskListInsert() { TaskListRecord tasklistRecord = new TaskListRecord() { Subject = this.hf_subject.Value, Accepter = int.Parse(txtNetUserId.Text), AuditingSate = 0, DepartMentId = int.Parse(this.ddlDepartMent.SelectedValue.ToString()), FirstAccepter = int.Parse(hf_FirstAccepter.Value), FirstSumitTime = Convert.ToDateTime(this.lbTime.Text), FirstTransmitter = int.Parse(hf_FirstTransmitter.Value), Mind = this.txtRemark.Text, Pass = 1, SumitTime = DateTime.Now, TaskID = int.Parse(taskid), TaskTableID = (int)TaskNavigateEmun.ProSend, Transmitter = int.Parse(Session["Userid"].ToString()) }; SqlComm.TaskListRecordAdd(tasklistRecord); SqlComm.UpdateTableByCondition("dbo.TaskListRecord", " AuditingSate=1", " ListID=" + listid); } static DataSet ds; protected void txtSendCom_TextChanged(object sender, EventArgs e) { getLinkMan(); } private void getLinkMan() { ds = null; this.txtTelphone.Text = ""; this.txtMobile.Text = ""; this.txtLinkman.Text = ""; if (this.txtSendCom.Text.Trim() != "" && this.txtSendCom.Text.Trim() != "请选择") { ds = SqlComm.GetDataByCondition("BioCrmLinkmanInfo", "LinkmanID,LinkmanName,WorkPhone,Mobile", " CustomerID=" + this.txtSendCom.Text); this.ddlLinkMan.DataSource = ds.Tables[0]; this.ddlLinkMan.DataTextField = "LinkmanName"; this.ddlLinkMan.DataValueField = "LinkmanID"; this.ddlLinkMan.DataBind(); if (ds.Tables[0].Rows.Count == 0) { this.ddlLinkMan.Visible = false; } else { this.ddlLinkMan.Visible = true; DataTable dt = ds.Tables[0]; DataRow[] dr = dt.Select("LinkmanID=" + this.ddlLinkMan.SelectedValue.ToString()); this.txtTelphone.Text = dr[0]["WorkPhone"].ToString(); this.txtMobile.Text = dr[0]["Mobile"].ToString(); this.txtLinkman.Text = this.ddlLinkMan.SelectedValue.ToString(); } } } protected void ddlLinkMan_SelectedIndexChanged(object sender, EventArgs e) { if (ds.Tables[0].Rows.Count > 0) { DataTable dt = ds.Tables[0]; DataRow[] dr=dt.Select("LinkmanID=" + this.ddlLinkMan.SelectedValue.ToString()); this.txtTelphone.Text= dr[0]["WorkPhone"].ToString(); this.txtMobile.Text = dr[0]["Mobile"].ToString(); this.txtLinkman.Text = this.ddlLinkMan.SelectedValue.ToString(); } } /// /// 拒绝审核 /// /// /// protected void btnReject_Click(object sender, EventArgs e) { TaskListRecord tasklistRecord = new TaskListRecord() { Subject = this.hf_subject.Value, Accepter = int.Parse(this.hf_FirstTransmitter.Value), AuditingSate = 0, DepartMentId = int.Parse(this.ddlDepartMent.SelectedValue.ToString()), FirstAccepter = int.Parse(hf_FirstAccepter.Value), FirstSumitTime = Convert.ToDateTime(this.lbTime.Text), FirstTransmitter = int.Parse(hf_FirstTransmitter.Value), Mind = this.txtRemark.Text, Pass = 1, SumitTime = DateTime.Now, TaskID = int.Parse(taskid), TaskTableID = (int)TaskNavigateEmun.ProSend, Transmitter = int.Parse(Session["Userid"].ToString()) }; SqlComm.TaskListRecordAdd(tasklistRecord); SqlComm.UpdateTableByCondition("dbo.TaskListRecord", " AuditingSate=1", " ListID=" + listid); } protected void cbisfinance_CheckedChanged(object sender, EventArgs e) { if (this.cbisfinance.Checked) { this.lbBillNo.Text = SqlComm.SPGetBillNo(taskid); } else { this.lbBillNo.Text = "未生成"; } if(bool.Parse(isquality)) { ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "$('#spanquality').show();", true); } } protected void btnRun_Click(object sender, EventArgs e) { try { if (this.cbISstock.Checked == false) { ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('如果没有选择出库审核,则不能发货执行')", true); return; } string postway = ""; if (this.ddlPostWay.SelectedItem.Text == "自定义") { postway = this.txtPostWay.Text; } else { postway = this.ddlPostWay.SelectedItem.Text; } bool isok= SqlComm.UpdateTableByCondition("BioSendAppInfo", "Stockuserid='" + Session["Userid"] + "',isOutStockCheck=1,postUnit='" + this.txtPostUnit.Text + "',postPhone='" + this.txtPhone.Text + "',postWay='" + postway + "',postRemak='" + this.txtpostRemark.Text + "',isSend=1", "SendId=" + taskid); TaskListRecord tasklistRecord = new TaskListRecord() { Subject = this.hf_subject.Value, Accepter = int.Parse(hf_FirstTransmitter.Value), AuditingSate = 2, DepartMentId = int.Parse(this.ddlDepartMent.SelectedValue.ToString()), FirstAccepter = int.Parse(hf_FirstAccepter.Value), FirstSumitTime = Convert.ToDateTime(this.lbTime.Text), FirstTransmitter = int.Parse(hf_FirstTransmitter.Value), Mind = this.txtRemark.Text, Pass = 1, SumitTime = DateTime.Now, TaskID = int.Parse(taskid), TaskTableID = (int)TaskNavigateEmun.ProSend, Transmitter = int.Parse(Session["Userid"].ToString()) }; if (isok) { SqlComm.TaskListRecordAdd(tasklistRecord); SqlComm.UpdateTableByCondition("dbo.TaskListRecord", " AuditingSate=1", " ListID=" + listid); } else { //提示错误信息 } ContextUtil.SetComplete();//提交事务 } catch (Exception ex) { ContextUtil.SetAbort();//撤销事务 } } }
详细页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SendGoodsShow.aspx.cs" Transaction="Required" Inherits="BioErpWeb.SendGoods.SendGoodsShow" %>