protected void Page_Load(object sender, EventArgs e) { //返回用户列表页面的URL(包含了用户列表页面的查询条件) if (Request["return"] != null) { this.mbar["back"].NavigateUrl = Request["return"]; } if (!IsPostBack) { this.txtID.Value = "0"; //加载下拉框 this.ddlItemStatus.Items.Clear(); this.ddlItemStatus.Items.Add(new ListItem("有效", ItemSpecStatus.Enable.ToString())); this.ddlItemStatus.Items.Add(new ListItem("停用", ItemSpecStatus.Disable.ToString())); //如果是编辑 int skuID = WebUtil.ParamInt("id", 0); if (skuID > 0) { this.txtID.Value = skuID.ToString(); //隐藏ID WebUtil.DisableControl(this.txtItemCode); using (ISession session = new Session()) { ItemSpec spec = ItemSpec.Retrieve(session, skuID); this.ddlItemStatus.SelectedValue = Cast.Enum <ItemSpecStatus>(spec.Status).ToString(); int itemID = spec.ItemID; ItemMaster master = ItemMaster.Retrieve(session, itemID); this.txtItemCode.Text = master.ItemCode; this.txtItemName.Text = master.ItemName; this.txtItemSpec.Text = master.ItemDesc; } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int skuid = WebUtil.ParamInt("sku", 0); if (skuid <= 0) { this.divMsg.InnerText = "无效的SKU"; return; } using (ISession session = new Session()) { ItemSpec spec = ItemSpec.Retrieve(session, skuid); if (spec == null) { this.divMsg.InnerText = "SKU " + skuid.ToString() + "不存在"; return; } //显示sku信息 this.lblItemCode.Text = spec.ItemCode; this.lblSize.Text = spec.SizeCode; ItemMaster master = ItemMaster.Retrieve(session, spec.ItemCode); this.lblItemName.Text = master == null ? "" : master.ItemName; ItemColor color = ItemColor.Retrieve(session, spec.ColorCode); this.lblColor.Text = spec.ColorCode + " " + (color == null ? "" : color.ColorText); this.lblOVSQty.Text = spec.EnableOS ? RenderUtil.FormatNumber(spec.OSQty, "#0.##", "0") : "0"; //现有库存 StockSummary sto = StockSummary.Retrieve(session, skuid); this.lblStockQty.Text = sto == null ? "0" : RenderUtil.FormatNumber(sto.StockQty, "#0.##"); this.lblFrozenQty.Text = sto == null ? "0" : RenderUtil.FormatNumber(sto.FrozenQty, "#0.##"); //在途采购记录 IList <POLine> lines = POHead.PipelineInvQuery(session, skuid); this.repeater.DataSource = lines; this.repeater.DataBind(); decimal pipelineStockQty = 0M; //计算汇总在途量 foreach (POLine line in lines) { pipelineStockQty += (line.PurchaseQty - line.ReceiveQty); } this.lblPipelineStock.Text = RenderUtil.FormatNumber(pipelineStockQty, "#0.##"); if (lines.Count <= 0) { this.divMsg.InnerText = "该SKU没有在途采购"; } else { this.divMsg.InnerText = ""; } } } }
protected void mboor_ItemCommand(object sender, Magic.Web.UI.MagicItemEventArgs args) { if (args.CommandName == "delete") { using (ISession session = new Session()) { session.BeginTransaction(); try { bool deleted = false; foreach (RepeaterItem item in this.rInfo.Items) { HtmlInputCheckBox chk = item.FindControl("chkItem") as HtmlInputCheckBox; if (chk != null && chk.Checked && Cast.Int(chk.Value) > 0) { Magic.Basis.ItemSpec spec = ItemSpec.Retrieve(session, Cast.Int(chk.Value)); ItemMaster master = ItemMaster.Retrieve(session, spec.ItemID); if (master.ItemType == ItemType.AssistantItem) { if (spec != null) { spec.Delete(session); } if (master != null) { master.Delete(session); } deleted = true; } } } session.Commit(); if (deleted) { this.QueryAndBindDate(session, this.mpage.CurrentPageIndex, this.mpage.PageSize, true); } WebUtil.ShowMsg(this, "选择的辅料已经被删除", "操作成功"); } catch (Exception err) { session.Rollback(); WebUtil.ShowError(this, err); } this.QueryAndBindDate(session, this.mpage.CurrentPageIndex, this.mpage.PageSize, true); } } }
protected void MagicItemCommand(object sender, MagicItemEventArgs e) { if (e.CommandName != "Save") { return; } using (ISession session = new Session()) { try { session.BeginTransaction(); foreach (RepeaterItem ri in this.repeater.Items) { HiddenField hidSkuId = ri.FindControl("hidSkuId") as HiddenField; int skuId = Cast.Int(hidSkuId.Value); CheckBox chkMethod = ri.FindControl("chkMethod") as CheckBox; TextBox txt; txt = ri.FindControl("txtMax") as TextBox; decimal max = Cast.Decimal(txt.Text); txt = ri.FindControl("txtSafe") as TextBox; decimal safe = Cast.Decimal(txt.Text); txt = ri.FindControl("txtMin") as TextBox; decimal min = Cast.Decimal(txt.Text); ItemSpec sku = ItemSpec.Retrieve(session, skuId); if (sku != null && ((sku.StoMethod > 0) != chkMethod.Checked || sku.StoMax != max || sku.StoMin != min || sku.StoSafe != safe)) { sku.StoMethod = chkMethod.Checked ? 1 : 0; sku.StoMax = max; sku.StoMin = min; sku.StoSafe = safe; sku.Update(session, "StoMethod", "StoMax", "StoMin", "StoSafe"); } } session.Commit(); WebUtil.ShowMsg(this, "保存成功"); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er.Message); } } }
protected void MagicItemCommand(object sender, MagicItemEventArgs e) { if (e.CommandName == "Save") { #region 保存 using (ISession session = new Session()) { IList <StockInLine> linesToSave = new List <StockInLine>(); System.Text.StringBuilder error = new System.Text.StringBuilder(); foreach (RepeaterItem item in this.repeatControl.Items) { HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox; TextBox text; StockInLine line = StockInLine.Retrieve(session, this.OrderNumber, chk.Value); text = item.FindControl("txtQty") as TextBox; line.Quantity = Cast.Decimal(text.Text.Trim()); text = item.FindControl("txtSec") as TextBox; line.SectionCode = text.Text.Trim(); DropDownList drp = item.FindControl("drpArea") as DropDownList; line.AreaCode = drp.SelectedValue; if (string.IsNullOrEmpty(line.AreaCode) || line.AreaCode.Trim().Length <= 0) { error.Append(chk.Attributes["sku"]).Append("未选择库位;"); } else if (!string.IsNullOrEmpty(line.SectionCode) && line.SectionCode.Trim().Length > 0) { WHSection section = WHSection.Retrieve(session, line.AreaCode, line.SectionCode); if (section == null) { error.Append(chk.Attributes["sku"]) .Append("库位").Append(line.AreaCode).Append("中不存在货架").Append(line.SectionCode).Append(";"); } } linesToSave.Add(line); } if (error.Length > 0) { WebUtil.ShowError(this, error.ToString()); return; } try { //检查 StockInHead head = StockInHead.Retrieve(session, this.OrderNumber); if (head == null) { return; } session.BeginTransaction(); head.CreateOrUpdateLines(session, linesToSave); session.Commit(); WebUtil.ShowMsg(this, "保存成功"); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); } } #endregion } else if (e.CommandName == "Delete") { #region 除 using (ISession session = new Session()) { try { session.BeginTransaction(); foreach (RepeaterItem item in this.repeatControl.Items) { HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox; if (chk.Checked) { StockInLine line = StockInLine.Retrieve(session, this.OrderNumber, chk.Value.Trim()); if (line != null) { line.Delete(session); } } } session.Commit(); this.QueryAndBindData(session, null); WebUtil.ShowMsg(this, "选择的明细已经删除"); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); } } #endregion } else if (e.CommandName == "Release") { #region 发布 using (ISession session = new Session()) { try { StockInHead head = StockInHead.Retrieve(session, this.OrderNumber); session.BeginTransaction(); head.Release(session); session.Commit(); WebUtil.ShowMsg(this, "发布成功"); this.QueryAndBindData(session, head); this.SetView(head); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); } } #endregion } else if (e.CommandName == "Close") { #region 关闭 using (ISession session = new Session()) { try { StockInHead head = StockInHead.Retrieve(session, this.OrderNumber); if (head == null) { return; } session.BeginTransaction(); head.Close(session); session.Commit(); WebUtil.ShowMsg(this, "产品入库单" + head.OrderNumber + "已经完成"); this.QueryAndBindData(session, head); this.SetView(head); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); } } #endregion } else if (e.CommandName == "Add") { #region 添加明细 using (ISession session = new Session()) { ItemSpec sku = ItemSpec.Retrieve(session, this.txtSku.Text.Trim().ToUpper()); if (sku == null) { WebUtil.ShowError(this, "SKU: " + this.txtSku.Text.Trim() + "不存在"); return; } StockInHead head = StockInHead.Retrieve(session, this.OrderNumber); StockInLine line = new StockInLine(); line.OrderNumber = this.OrderNumber; line.LocationCode = head.LocationCode; line.LineNumber = head.NextLineNumber(); line.AreaCode = ""; line.SectionCode = ""; line.Price = sku.AvgMoveCost; line.Quantity = 0M; line.RefQuantity = 0M; line.SKUID = sku.SKUID; line.StockDetailID = 0; line.UnitID = 0; bool isError = false; try { session.BeginTransaction(); line.Create(session); head.Update(session, "CurrentLineNumber"); session.Commit(); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); isError = true; } if (!isError) { this.txtSku.Text = ""; this.QueryAndBindData(session, head); this.SetView(head); } } #endregion } }
private static WHTransLine BuildTransLine(ISession session, TransItemWrapper wrapper, IWHTransHead transHead, int commitDate, int commitTime, ref int lineNumber, OrderTransDef orderTransDef) { WHArea area = null; WHTransLine line = new WHTransLine(); line.LineNumber = lineNumber++; line.SKUID = wrapper.SKUID; line.TransDate = commitDate; line.TransTime = commitTime; line.UnitID = wrapper.UnitID; line.CurrencyCode = wrapper.CurrencyCode; line.RefOrderType = transHead.OrderTypeCode; line.RefOrderNumber = transHead.OrderNumber; line.RefOrderLine = wrapper.LineNumber; line.OriginalOrderType = transHead.OriginalOrderType; line.OriginalOrderNumber = transHead.OrginalOrderNumber; line.OriginalOrderLine = wrapper.OriginalOrderLine; line.TaxValue = wrapper.TaxValue; line.StockDetailID = wrapper.StockDetailID; ItemSpec itemSpec = ItemSpec.Retrieve(session, line.SKUID); line.AvgMoveCost = itemSpec.AvgMoveCost; //TODO: 目前只支持的配置实现方式有限 //交易类型 if (orderTransDef.StepType == TransStepType.Single) { if (orderTransDef.TransTypeFrom == TransTypeFrom.ConfigValue) { line.TransTypeCode = orderTransDef.TransTypeCode; } else if (orderTransDef.TransTypeFrom == TransTypeFrom.InterfaceValue) { line.TransTypeCode = wrapper.TransTypeCode; } else { throw new Exception(string.Format("WHTransaction: TransTypeFrom {0} not supported", (int)orderTransDef.TransTypeFrom)); } } else if (orderTransDef.StepType == TransStepType.MultiSelect) { if (orderTransDef.TransTypeFrom == TransTypeFrom.InterfaceValue) { line.TransTypeCode = wrapper.TransTypeCode; } else { throw new Exception(string.Format("WHTransaction: TransTypeFrom {0} not supported by TransStepType.MultiSelect", (int)orderTransDef.TransTypeFrom)); } } //交易数量 if (orderTransDef.TransQtyFrom == TransQtyFrom.QualifiedQty) { line.TransQty = wrapper.QualifiedQty; } else if (orderTransDef.TransQtyFrom == TransQtyFrom.UnQualifiedQty) { line.TransQty = wrapper.UnQualifiedQty; } else { throw new Exception(string.Format("WHTransaction: TransQtyFrom {0} not supported", (int)orderTransDef.TransQtyFrom)); } //交易仓库信息。LocationCode, AreaCode必须有,SectionCode可以有可以没有 if (orderTransDef.TransLocationFrom == TransLocationFrom.ConfigValue) { //从(交易-仓库配置)中取库房区域、货架信息 //不会从(产品-默认存储位置)读取,因为出入库单据如果用到(产品-默认存储位置),需要在界面提供选择,因此仓库获取类型变为TransLocationFrom.InterfaceValue IList <WHAreaCfg> areaCfg = WHAreaCfg.Retrieve(session, line.TransTypeCode); if (areaCfg == null || areaCfg.Count <= 0) { throw new Exception(string.Format("WHTransaction: area cfg does not exists for transaction type {0}", line.TransTypeCode)); } area = WHArea.Retrieve(session, areaCfg[0].AreaCode); if (area == null) { throw new Exception(string.Format("WHTransaction: area {0} does not exist", areaCfg[0].AreaCode)); } line.LocationCode = area.LocationCode; line.AreaCode = area.AreaCode; } else if (orderTransDef.TransLocationFrom == TransLocationFrom.InterfaceValue) { if (string.IsNullOrEmpty(wrapper.LocationCode) || wrapper.LocationCode.Trim().Length <= 0 || string.IsNullOrEmpty(wrapper.AreaCode) || wrapper.AreaCode.Trim().Length <= 0) { throw new Exception(string.Format("WHTransaction: LocationCode or AreaCode is empty in transaction order line {0}", wrapper.LineNumber)); } line.LocationCode = wrapper.LocationCode; line.AreaCode = wrapper.AreaCode; line.SectionCode = wrapper.SectionCode; } else { throw new Exception(string.Format("WHTransaction: TransLocationFrom {0} not supported", (int)orderTransDef.TransLocationFrom)); } area = WHArea.Retrieve(session, line.AreaCode); if (area == null) { throw new Exception(string.Format("WHTransaction: invalidate AreaCode {0}", line.AreaCode)); } //如果库位被锁定(例如正在进行盘点作业)则不允许交易 if (area.IsLocked && orderTransDef.TransTypeCode != "301") //盘点的交易类型为301 { throw new Exception("库位" + area.AreaCode + "-" + area.Name + "正在盘点,无法执行出入库操作"); } line.IsScrap = area.IsScrap; line.IsQC = area.IsQC; line.IsNonFormal = area.IsNonFormal; TransTypeDef transTypeDef = TransTypeDef.Retrieve(session, orderTransDef.TransTypeCode); if (transTypeDef == null) { throw new Exception(string.Format("WHTransaction: invalidate transaction type code {0}", orderTransDef.TransTypeCode)); } line.TransQty = line.TransQty * ((int)transTypeDef.TransProperty); //交易描述 line.TransReason = transTypeDef.TransDefText; if (!string.IsNullOrEmpty(transTypeDef.TransDefDesc) && transTypeDef.TransDefDesc.Trim().Length > 0) { line.TransReason = line.TransReason + " - " + transTypeDef.TransDefDesc; } //交易价格 if (transTypeDef.PriceSourceType == TransTypePriceSource.FromSourceOrder) { line.TransPrice = wrapper.Price; } else if (transTypeDef.PriceSourceType == TransTypePriceSource.FromMovAvgCost) { line.TransPrice = itemSpec.AvgMoveCost; } else if (transTypeDef.PriceSourceType == TransTypePriceSource.FromAreaCfg) { if (!area.UseFixCost || area.CostFixValue < 0M) { throw new Exception(string.Format("WHTransaction: TransTypePriceSource is FromAreaCfg, but it does not exists in AreaCode {0}", area.AreaCode)); } line.TransPrice = area.CostFixValue; } line.TransPrice = line.TransPrice * area.CostTransRate - area.FixedComsumeValue; if (line.TransPrice < 0M) { line.TransPrice = 0M; } //if ((line.TransTypeCode == "101" || line.TransTypeCode == "301") && itemSpec.EnableOS) //{ // itemSpec.EnableOS = false; // itemSpec.Update(session, "EnableOS"); //} log.DebugFormat("trans line built: trans type:{0}, qty={1}, area={2}, section={3}, price={4}", line.TransTypeCode, line.TransQty, line.AreaCode, line.SectionCode, line.TransPrice); return(line); }
public void CreateOrUpdateLines(ISession session, IList <StockInLine> lines) { if (this.Status != StockInStatus.New) { log.WarnFormat("order status is {0}, attemping to update lines is denied", this.Status.ToString()); throw new Exception("单据不是新建状态,不可以更新"); } bool needUpdateHead = false; foreach (StockInLine line in lines) { StockDetail sto = null; if (this.OrderTypeCode == StockInHead.ORD_TYPE_PRD_IN || this.OrderTypeCode == StockInHead.ORD_TYPE_ASSIST_IN) { sto = StockDetail.Retrieve(session, line.SKUID, line.LocationCode, line.AreaCode, line.SectionCode); if (sto == null) { sto = new StockDetail(); sto.LocationCode = line.LocationCode; sto.SKUID = line.SKUID; sto.AreaCode = line.AreaCode; sto.SectionCode = string.IsNullOrEmpty(line.SectionCode) ? " " : line.SectionCode; sto.LotNumber = " "; sto.StockQty = 0M; sto.FrozenQty = 0M; sto.Create(session); } } else { sto = StockDetail.Retrieve(session, line.StockDetailID); } if (sto == null) { log.ErrorFormat("add line for {0}, stock detail id {1} not exists", this.OrderNumber, line.StockDetailID); throw new Exception("库存项不存在"); } if ((this.OrderTypeCode == StockInHead.ORD_TYPE_ASSIST_OUT || this.OrderTypeCode == StockInHead.ORD_TYPE_PRD_OUT) && (line.Quantity > sto.StockQty - sto.FrozenQty)) { throw new Exception("领用数量超过可使用库存数量"); } if (!string.IsNullOrEmpty(line.LineNumber) && line.LineNumber.Trim().Length > 0) { //更新 line.RefQuantity = sto.StockQty; line.LocationCode = sto.LocationCode; line.AreaCode = sto.AreaCode; line.SectionCode = sto.SectionCode; line.StockDetailID = sto.StockDetailID; ItemSpec sku = ItemSpec.Retrieve(session, sto.SKUID); line.Price = sku.AvgMoveCost; line.Update(session, "LocationCode", "AreaCode", "SectionCode", "StockDetailID", "RefQuantity", "Quantity", "Price"); } else { //创建 line.OrderNumber = this.OrderNumber; line.LineNumber = this.NextLineNumber(); line.LocationCode = sto.LocationCode; line.AreaCode = sto.AreaCode; line.SectionCode = sto.SectionCode; line.StockDetailID = sto.StockDetailID; line.SKUID = sto.SKUID; line.UnitID = 0; line.RefQuantity = sto.StockQty; ItemSpec sku = ItemSpec.Retrieve(session, sto.SKUID); line.Price = sku.AvgMoveCost; line.Create(session); needUpdateHead = true; } } if (needUpdateHead) { this.Update(session, "CurrentLineNumber"); } }
protected void mbar_ItemCommand(object sender, Magic.Web.UI.MagicItemEventArgs args) { if (args.CommandName == "save") { using (ISession session = new Session()) { try { string itemCode = this.txtItemCode.Text.Trim(); string itemStatus = this.ddlItemStatus.SelectedValue; string itemName = this.txtItemName.Text.Trim(); string itemDesc = this.txtItemSpec.Text.Trim(); if (this.IsNew) { //新增 ItemMaster master = new ItemMaster(); master.ItemCode = itemCode; //判断输入的itemCode是否重复 if (session.CreateEntityQuery <ItemMaster>().Where(Exp.Eq("ItemCode", itemCode)).Count() > 0) { WebUtil.ShowMsg(this, string.Format("辅料编号{0}已经存在", master.ItemCode), "错误"); return; } master.ItemType = ItemType.AssistantItem; master.ItemName = itemName; master.ItemDesc = itemDesc; session.BeginTransaction(); master.Create(session); ItemSpec spec = new ItemSpec(); spec.ItemID = master.ItemID; spec.ItemCode = itemCode; spec.Status = Cast.Enum <ItemSpecStatus>(itemStatus); spec.ColorCode = " "; spec.BarCode = itemCode; spec.OperateTime = DateTime.Now; spec.Operator = 0;// Magic.Security.SecuritySession.CurrentUser.UserId; spec.PubDate = DateTime.Now; spec.AvgMoveCost = 0; spec.EnableCost = true; spec.EnableOS = false; spec.Create(session); session.Commit(); } else { session.BeginTransaction(); ItemSpec spec = ItemSpec.Retrieve(session, this.SKUID); spec.Status = Cast.Enum <ItemSpecStatus>(itemStatus); spec.Update(session, "Status"); int itemID = spec.ItemID; ItemMaster master = ItemMaster.Retrieve(session, itemID); master.ItemName = itemName; master.ItemDesc = itemDesc; master.Update(session, "ItemName", "ItemDesc"); session.Commit(); } } catch (System.Exception e) { session.Rollback(); throw e; } } this.Response.Redirect(WebUtil.Param("return")); } }
public void AddLines(ISession session, IList <WHTransferLine> lines) { if (this.Status != WHTransferStatus.New) { log.WarnFormat("status of transfer order {0} is not New, lines can't be added", this.OrderNumber); throw new Exception(string.Format("移库单{0}不是新建状态,无法添加明细", this.OrderNumber)); } //检查 System.Text.StringBuilder builder = new System.Text.StringBuilder(); bool msghead = false; ItemSpec sku = null;; foreach (WHTransferLine line in lines) { msghead = false; sku = null; StockDetail sto = StockDetail.Retrieve(session, line.FromStockID); if (sto == null) { log.ErrorFormat("detail stock ID {0} not exists", line.FromStockID); throw new Exception(string.Format("库存明细ID {0}不存在", line.FromStockID)); } line.OrderNumber = this.OrderNumber; line.LineNumber = this.NextLineNumber(); line.SKUID = sto.SKUID; line.FromLocation = Cast.String(this.FromLocation, "").Trim().ToUpper(); line.ToLocation = Cast.String(this.ToLocation, "").Trim().ToUpper(); line.FromArea = Cast.String(sto.AreaCode).Trim().ToUpper(); line.FromSection = Cast.String(sto.SectionCode).Trim().ToUpper(); line.UnitID = 0; bool isAreaEmpty = false; if (string.IsNullOrEmpty(line.ToArea) || line.ToArea.Trim().Length <= 0) { if (!msghead) { if (sku == null) { sku = ItemSpec.Retrieve(session, sto.SKUID); } builder.Append(sku.BarCode).Append(":"); } builder.Append("移入库位为空;"); isAreaEmpty = true; } else if (!string.IsNullOrEmpty(line.ToSection) && line.ToSection.Trim().Length > 0) { WHSection section = WHSection.Retrieve(session, line.ToArea, line.ToSection); if (section == null) { if (!msghead) { if (sku == null) { sku = ItemSpec.Retrieve(session, sto.SKUID); } builder.Append(sku.BarCode).Append(":"); } builder.Append("移入库位").Append(line.ToArea).Append("中不存在货架").Append(line.ToSection).Append(";"); } } if (!isAreaEmpty && line.FromArea == Cast.String(line.ToArea).Trim().ToUpper() && line.FromSection == Cast.String(line.ToSection, "").Trim().ToUpper()) { if (sku == null) { sku = ItemSpec.Retrieve(session, sto.SKUID); } builder.Append(sku.BarCode).Append(":"); builder.Append("来源库位-货架与移入库位-货架一样;"); } } if (builder.Length > 0) { log.Warn(builder.ToString()); throw new Exception(builder.ToString()); } foreach (WHTransferLine line in lines) { line.Create(session); } this.Update(session, "CurrentLineNumber"); }