private void Save(ISession session, StockInHead head) { if (head == null) { return; } IList <StockInLine> linesToSave = new List <StockInLine>(); foreach (RepeaterItem item in this.repeatControl.Items) { HtmlInputHidden txt = item.FindControl("hidLine") as HtmlInputHidden; TextBox text; StockInLine line = StockInLine.Retrieve(session, this.OrderNumber, txt.Value); text = item.FindControl("txtPrice") as TextBox; line.Price = Cast.Decimal(text.Text, line.Price); linesToSave.Add(line); } head.UpdatePrice(session, linesToSave); }
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 } }
protected void MagicItemCommand(object sender, MagicItemEventArgs e) { if (e.CommandName == "Save") { #region 保存 IList <StockInLine> linesToSave = new List <StockInLine>(); foreach (RepeaterItem item in this.repeatControl.Items) { HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox; DropDownList drp = item.FindControl("drpArea") as DropDownList; TextBox text; StockInLine line = new StockInLine(); line.OrderNumber = this.OrderNumber; line.LineNumber = chk.Value.Trim(); line.AreaCode = drp.SelectedValue; text = item.FindControl("txtSection") as TextBox; line.SectionCode = text.Text.Trim(); text = item.FindControl("txtQualifiedQty") as TextBox; line.Quantity = Cast.Decimal(text.Text.Trim()); text = item.FindControl("txtPrice") as TextBox; line.Price = Cast.Decimal(text.Text.Trim()); linesToSave.Add(line); } using (ISession session = new Session()) { try { //检查 StockInHead head = StockInHead.Retrieve(session, this.OrderNumber); if (head == null) { return; } head.UpdateLines(session, linesToSave); WebUtil.ShowMsg(this, "保存成功"); } catch (Exception er) { 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 { session.BeginTransaction(); StockInHead head = StockInHead.Retrieve(session, this.OrderNumber); 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 } }