/// <summary> /// 库存调整单添加或更新明细 /// <para>以StockDetailID判断INVCheckLine明细对象是否已经存在,不存在则新增,存在则更新</para> /// <para>如果是新增,lines中对象的各个属性必须都已经设置好;如果是更新,只更新CurrentQty属性</para> /// </summary> /// <param name="session"></param> /// <param name="lines"></param> public void CreateOrUpdateLines(ISession session, IList <INVCheckLine> lines) { if (this.Status != INVCheckStatus.New && this.Status != INVCheckStatus.Confirm) { log.WarnFormat("status of sto {0} {1} is {2}, attemping to update lines is denied", this.OrderTypeCode == ORDER_TYPE_CHK ? "chk" : "adj", this.OrderNumber, this.Status.ToString()); throw new Exception("不可以更新"); } bool needUpdateHead = false; foreach (INVCheckLine line in lines) { INVCheckLine temp = this.GetLine(session, line.StockDetailID); if (temp != null) { temp.CurrentQty = line.CurrentQty; temp.Update(session, "CurrentQty"); } else { line.LineNumber = this.NextLineNumber(); needUpdateHead = true; line.Create(session); } } if (needUpdateHead) { this.Update(session, "CurrentLineNumber"); } }
/// <summary> /// 保存库存盘点明细,lines中每个对象必须设置好LineNumber、CurrentQty这2个属性 /// </summary> /// <param name="session"></param> /// <param name="orderNumber"></param> /// <param name="lines"></param> public void UpdateLines(ISession session, IList <INVCheckLine> lines) { if (lines == null || lines.Count <= 0) { return; } foreach (INVCheckLine line in lines) { INVCheckLine lineToSave = INVCheckLine.Retrieve(session, this.OrderNumber, line.LineNumber); if (lineToSave == null) { throw new Exception("库存盘点单" + this.OrderNumber + "中不存在明细项目" + line.LineNumber); } lineToSave.CurrentQty = line.CurrentQty; lineToSave.Update(session, "CurrentQty"); } }
public static void ConfirmInvCheckOrder(ISession _session, string InvCheckNumber) { string strSQL = @" SELECT SUM(A.StockQty) AS StockQty,A.LocationCode AS LocationCode,A.AreaCode AS AreaCode,A.SectionCode AS SectionCode, B.SKUID AS SKUID,B.StandardPrice AS Price,B.BasicUnit AS Unit FROM StockDetail A LEFT JOIN ItemSpec B ON A.SKUID=B.SKUID WHERE A.AreaCode In (SELECT AreaCode FROM INVCheckWh WHERE OrderNumber=?) GROUP BY A.LocationCode,A.AreaCode,A.SectionCode, B.SKUID,B.StandardPrice,B.BasicUnit"; DataSet ds = _session.CreateObjectQuery(strSQL) .Attach(typeof(StockDetail)) .Attach(typeof(Magic.Basis.ItemSpec)) .Attach(typeof(Magic.Basis.ItemMaster)) .Attach(typeof(INVCheckWh)) .SetValue(0, InvCheckNumber, EntityManager.GetEntityMapping(typeof(INVCheckWh)).GetPropertyMapping("OrderNumber").DbTypeInfo) .DataSet(); INVCheckHead objHead = new INVCheckHead(); objHead.OrderNumber = InvCheckNumber; objHead.Status = INVCheckStatus.Confirm; objHead.Update(_session, "Status"); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { INVCheckLine objItem = new INVCheckLine(); objItem.AreaCode = Cast.String(ds.Tables[0].Rows[i]["AreaCode"]); objItem.BeforeQty = Cast.Decimal(ds.Tables[0].Rows[i]["StockQty"], 0M); objItem.CurrentQty = objItem.BeforeQty; objItem.LineNumber = objHead.NextLineNumber(); objItem.LocationCode = Cast.String(ds.Tables[0].Rows[i]["LocationCode"]); objItem.OrderNumber = InvCheckNumber; objItem.SectionCode = Cast.String(ds.Tables[0].Rows[i]["SectionCode"]); objItem.SKUID = Cast.Int(ds.Tables[0].Rows[i]["SKUID"], 0); objItem.Create(_session); } }
public static void ConfirmInvCheckOrder(ISession _session,string InvCheckNumber) { string strSQL = @" SELECT SUM(A.StockQty) AS StockQty,A.LocationCode AS LocationCode,A.AreaCode AS AreaCode,A.SectionCode AS SectionCode, B.SKUID AS SKUID,B.StandardPrice AS Price,B.BasicUnit AS Unit FROM StockDetail A LEFT JOIN ItemSpec B ON A.SKUID=B.SKUID WHERE A.AreaCode In (SELECT AreaCode FROM INVCheckWh WHERE OrderNumber=?) GROUP BY A.LocationCode,A.AreaCode,A.SectionCode, B.SKUID,B.StandardPrice,B.BasicUnit"; DataSet ds = _session.CreateObjectQuery(strSQL) .Attach(typeof(StockDetail)) .Attach(typeof(Magic.Basis.ItemSpec)) .Attach(typeof(Magic.Basis.ItemMaster)) .Attach(typeof(INVCheckWh)) .SetValue(0, InvCheckNumber, EntityManager.GetEntityMapping(typeof(INVCheckWh)).GetPropertyMapping("OrderNumber").DbTypeInfo) .DataSet(); INVCheckHead objHead = new INVCheckHead(); objHead.OrderNumber = InvCheckNumber; objHead.Status = INVCheckStatus.Confirm; objHead.Update(_session, "Status"); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { INVCheckLine objItem = new INVCheckLine(); objItem.AreaCode = Cast.String(ds.Tables[0].Rows[i]["AreaCode"]); objItem.BeforeQty = Cast.Decimal(ds.Tables[0].Rows[i]["StockQty"], 0M); objItem.CurrentQty = objItem.BeforeQty; objItem.LineNumber = objHead.NextLineNumber(); objItem.LocationCode = Cast.String(ds.Tables[0].Rows[i]["LocationCode"]); objItem.OrderNumber = InvCheckNumber; objItem.SectionCode = Cast.String(ds.Tables[0].Rows[i]["SectionCode"]); objItem.SKUID = Cast.Int(ds.Tables[0].Rows[i]["SKUID"], 0); objItem.Create(_session); } }
public INVCheckLine NewLineAdj(ISession session, int stoDetailId, decimal adjQty) { StockDetail sto = StockDetail.Retrieve(session, stoDetailId); if (sto == null) { log.ErrorFormat("add stock adj line for {0}, stock detail id {1} not exists", this.OrderNumber, stoDetailId); throw new Exception("选择的库存项不存在"); } INVCheckLine line = new INVCheckLine(); line.OrderNumber = this.OrderNumber; line.StockDetailID = stoDetailId; line.LocationCode = sto.LocationCode; line.AreaCode = sto.AreaCode; line.SectionCode = sto.SectionCode; line.BeforeQty = sto.StockQty; line.CurrentQty = adjQty; line.SKUID = sto.SKUID; line.UnitID = 0; return(line); }
protected void MagicItemCommand(object sender, MagicItemEventArgs e) { if (e.CommandName == "Save") { SaveCheckOrder(); } if (e.CommandName == "Close") { try { if (this.txtInvCheckNumber.Text.Trim().Length == 0) { WebUtil.ShowMsg(this, "只有签核通过的库存调整单才可以关闭!"); return; } using (_session = new Session()) { Magic.ERP.Orders.INVCheckHead objhead = Magic.ERP.Orders.INVCheckHead.Retrieve(_session, this.txtInvCheckNumber.Text.Trim()); if ((objhead.Status == Magic.ERP.INVCheckStatus.Release) && (objhead.ApproveResult == Magic.ERP.ApproveStatus.Approve)) { Magic.ERP.ERPUtil.CommitWHTrans(_session, objhead); } else { WebUtil.ShowMsg(this, "只有签核通过的库存调整单才可以关闭!"); return; } } } catch (Exception ex) { WebUtil.ShowMsg(this,"关闭库存调整单失败,请与管理员联系!"); } } if (e.CommandName == "Insert") { try { if (this.hidSkuId.Value.Trim().Length == 0) { WebUtil.ShowMsg(this, "请先选择物料!"); return; } string strSKUID = this.hidSkuId.Value; string strLocation = this.ddlLocation.SelectedValue; string strArea = this.ddlArea.SelectedValue; string strSection = this.ddlSection.SelectedValue; int intNewQuantity = 0; try { intNewQuantity = int.Parse(this.txtNewQuantity.Text); if (intNewQuantity < 0) { WebUtil.ShowMsg(this, "物料库存数量必须为整数,请重新输入!"); return; } } catch (Exception ex) { WebUtil.ShowMsg(this, "物料库存数量必须为整数,请重新输入!"); return; } using(_session = new Session()) { } Magic.ERP.Orders.INVCheckLine objLine = new INVCheckLine(); objLine.AreaCode = strArea; objLine.BeforeQty = int.Parse(this.txtOldQuantity.Value); objLine.CurrentQty = intNewQuantity; objLine.LineNumber = ""; objLine.LocationCode = strLocation; objLine.OrderNumber = this.txtInvCheckNumber.Text; objLine.SectionCode = strSection; objLine.SKUID = int.Parse(strSKUID); SaveItem(objLine,this.txtItemName.Value,this.txtItemSize.Value,this.txtItemColor.Value,this.ddlLocation.SelectedItem.Text, this.ddlArea.SelectedItem.Text,this.ddlSection.SelectedItem.Text); if (this.tblAddItem.Style["display"] == null) { this.tblAddItem.Style.Add("display", "none"); } else { this.tblAddItem.Style["display"] = "none"; } this.txtItemName.Value = ""; this.txtItemColor.Value = ""; this.txtItemSize.Value = ""; this.ddlLocation.SelectedIndex = 0; this.txtOldQuantity.Value = "0"; this.txtNewQuantity.Text = ""; this.ddlArea.Items.Clear(); this.ddlSection.Items.Clear(); } catch (Exception ex) { logger.Error(ex); WebUtil.ShowError(this,ex); } } if (e.CommandName == "Return") { string strURL = "StockAdjustmentManage.aspx" ; if ((WebUtil.Param("return") != null) && (WebUtil.Param("return").Length > 0)) { strURL = WebUtil.Param("return").Trim(); } Response.Redirect(strURL); } }
private void SaveItem(INVCheckLine objLine,string ItemName,string SizeText,string ColorText,string LocationName,string AreaName,string SectionName) { DataSet dt = Session["InvAdjustmentItem"] as DataSet; if ((dt!=null) || (dt.Tables[0].Rows.Count== 0)) { // Add` // SELECT A.BeforeQty AS BeforeQty,A.CurrentQty AS CurrentQty,C.ItemCode AS ItemCode,B.SKUID AS SKUID, //C.ItemName AS ItemName,E.SizeText AS SizeText,D.ColorText AS ColorText, //L.Name AS LocationName,R.Name AS AreaName,S.Text AS SectionName,L.LocationCode AS LocationCode, //R.AreaCode AS AreaCode,S.SectionCode AS SectionCode DataRow dtRow = dt.Tables[0].NewRow(); dtRow["CurrentQty"] = objLine.CurrentQty; dtRow["BeforeQty"] = objLine.BeforeQty ; dtRow["ItemCode"] = ""; dtRow["SKUID"] = objLine.SKUID; dtRow["ItemName"] = ItemName; dtRow["SizeText"] = SizeText; dtRow["ColorText"] = ColorText; dtRow["LocationName"] = LocationName; dtRow["AreaName"] = AreaName; dtRow["SectionName"] = SectionName; dtRow["LocationCode"] = objLine.LocationCode; dtRow["AreaCode"] = objLine.AreaCode; dtRow["SectionCode"] = objLine.SectionCode; dt.Tables[0].Rows.Add(dtRow); } else { dt.Tables[0].Rows[0]["CurrentQty"] = objLine.CurrentQty; } Session["InvAdjustmentItem"] = dt; this.rptInvCheck.DataSource = dt; this.rptInvCheck.DataBind(); }
private void SaveCheckOrder() { try { DataSet ds = Session["InvAdjustmentItem"] as DataSet; Dictionary<int, int> lstCurrentQuantity = new Dictionary<int, int>(); for (int i = 0; i < this.rptInvCheck.Items.Count; i++) { TextBox objBox = this.rptInvCheck.Items[i].FindControl("txtCurrentQuantity") as TextBox; System.Web.UI.HtmlControls.HtmlInputHidden objSKU = this.rptInvCheck.Items[i].FindControl("hidSKUID") as System.Web.UI.HtmlControls.HtmlInputHidden; try { lstCurrentQuantity.Add(Cast.Int(objSKU.Value), Cast.Int(objBox.Text)); } catch (Exception ex) { WebUtil.ShowMsg(this, "调整数量非法,请重新输入!"); return; } } using (_session = new Session()) { _session.BeginTransaction(); try { INVCheckHead objHead = INVCheckHead.Retrieve(_session, this.txtInvCheckNumber.Text); bool blnInsert = false; if (objHead == null) { blnInsert = true; objHead = new INVCheckHead(); objHead.CreateTime = DateTime.Now; objHead.CreateUser = Magic.Security.SecuritySession.CurrentUser.UserId; objHead.Note = this.txtMemo.Text; objHead.OrderNumber = Magic.ERP.ERPUtil.NextOrderNumber(Magic.ERP.Orders.INVCheckHead.ORDER_TYPE_ADJ); objHead.OrderTypeCode = INVCheckHead.ORDER_TYPE_ADJ; objHead.Status = Magic.ERP.INVCheckStatus.New; objHead.Create(_session); } else { if ((objHead.Status == Magic.ERP.INVCheckStatus.Release) || (objHead.Status == Magic.ERP.INVCheckStatus.Close)) { WebUtil.ShowMsg(this, "发布以后的盘点单不可以进行修改"); return; } objHead.Note = this.txtMemo.Text; blnInsert = false; _session.CreateEntityQuery<INVCheckLine>().Where(Exp.Eq("OrderNumber", objHead.OrderNumber)).Delete(); } objHead.CurrentLineNumber = ""; List<INVCheckLine> List = new List<INVCheckLine>(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { INVCheckLine objLine = new INVCheckLine(); objLine.SKUID = Cast.Int(ds.Tables[0].Rows[i]["SKUID"]); objLine.AreaCode = Cast.String(ds.Tables[0].Rows[i]["AreaCode"]); objLine.BeforeQty = Cast.Decimal(ds.Tables[0].Rows[i]["BeforeQty"]); objLine.CurrentQty = lstCurrentQuantity[objLine.SKUID]; objLine.LineNumber = objHead.NextLineNumber(); objLine.LocationCode = Cast.String(ds.Tables[0].Rows[i]["LocationCode"]); objLine.OrderNumber = objHead.OrderNumber; objLine.SectionCode = Cast.String(ds.Tables[0].Rows[i]["SectionCode"]); objLine.Create(_session); } objHead.Update(_session, "CurrentLineNumber"); this.txtInvCheckNumber.Text = objHead.OrderNumber; _session.Commit(); } catch (Exception ex) { _session.Rollback(); throw ex; } } WebUtil.ShowMsg(this, "库存盘点单保存成功", "操作成功"); } catch (Exception ex) { logger.Info("保存库存盘点单", ex); WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员"); } }
public INVCheckLine NewLineAdj(ISession session, int stoDetailId, decimal adjQty) { StockDetail sto = StockDetail.Retrieve(session, stoDetailId); if (sto == null) { log.ErrorFormat("add stock adj line for {0}, stock detail id {1} not exists", this.OrderNumber, stoDetailId); throw new Exception("ѡ��Ŀ�������"); } INVCheckLine line = new INVCheckLine(); line.OrderNumber = this.OrderNumber; line.StockDetailID = stoDetailId; line.LocationCode = sto.LocationCode; line.AreaCode = sto.AreaCode; line.SectionCode = sto.SectionCode; line.BeforeQty = sto.StockQty; line.CurrentQty = adjQty; line.SKUID = sto.SKUID; line.UnitID = 0; return line; }
protected void MagicItemCommand(object sender, MagicItemEventArgs e) { if (e.CommandName == "Save") { if (this.FileUpload1.FileName.Trim().Length <= 0) { WebUtil.ShowMsg(this, "请选择盘点结果文件"); return; } string fileName = this.FileUpload1.FileName; if (!fileName.EndsWith(".xls")) { WebUtil.ShowMsg(this, "请选择有效的Excel文件"); return; } string filePath = System.IO.Path.Combine(DownloadUtil.DownloadFolder, "CK_IMP_" + DateTime.Now.ToString("yyMMdd_HHmmss") + ".xls"); this.FileUpload1.SaveAs(filePath); IList<INVCheckLine> lines = new List<INVCheckLine>(); #region 读取文件 ExcelApp excelapp = null; ExcelWorkbook excelBook = null; ExcelWorksheet excelSheet = null; try { excelapp = new ExcelApp(); excelapp.DisplayAlerts = false; excelBook = excelapp.Open(filePath, 0); excelSheet = excelBook.Worksheets(1); int rowIndex = 2; string lineNum = Cast.String(excelSheet.Range(rowIndex, rowIndex, 1, 1).Value).Trim(); decimal qty; while (lineNum.Length==4) { qty = Cast.Decimal(excelSheet.Range(rowIndex, rowIndex, 9, 9).Value, 0M); INVCheckLine line = new INVCheckLine(); line.LineNumber = lineNum; line.CurrentQty = qty; lines.Add(line); rowIndex++; lineNum = Cast.String(excelSheet.Range(rowIndex, rowIndex, 1, 1).Value).Trim(); } } catch (Exception er) { WebUtil.ShowError(this, er.Message); return; } finally { if (excelSheet != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet.COMObject); if (excelBook != null) { excelBook.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook.COMObject); } if (excelapp != null) { excelapp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(excelapp.COMObject); } } #endregion using (ISession session = new Session()) { try { INVCheckHead head = INVCheckHead.Retrieve(session, WebUtil.Param("ordNum")); if (head == null) { WebUtil.ShowError(this, "盘点单"+WebUtil.Param("ordNum")+"不存在"); return; } session.BeginTransaction(); head.ClearCheckQty(session); head.UpdateLines(session, lines); session.Commit(); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er.Message); return; } } this.Response.Redirect(WebUtil.Param("return")); } }