IList <IWHTransLine> IWHTransHead.GetLines(ISession session) { IList <ReturnLine> lines = session.CreateEntityQuery <ReturnLine>() .Where(Exp.Eq("OrderNumber", this.OrderNumber)) .OrderBy("SKUID").OrderBy("RefOrderLineID") .List <ReturnLine>(); this._lines = lines; IList <IWHTransLine> whLines = new List <IWHTransLine>(lines.Count); foreach (ReturnLine line in lines) { if (this.OrderTypeCode != ReturnHead.ORDER_TYPE_EXCHANGE_RTN) { line.LocationCode = this.LocationCode; } else { WHArea area = WHArea.Retrieve(session, line.AreaCode); line.LocationCode = area.LocationCode; } whLines.Add(line); } return(whLines); }
/// <summary> /// 插入信息(单表) /// </summary> /// <param name="">信息</param> /// <returns>插入行数</returns> public DataResult <int> Insert(WHArea model) { DataResult <int> result = new DataResult <int>(); try { //基本信息 model.ID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATETIME = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATETIME = model.CREATETIME; if (ExistsWHArea(model)) { result.Msg = "编号或名称已存在"; result.Result = -1; return(result); } result.Result = new WHAreaDAL().Insert(model); result.IsSuccess = true; return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取列表 /// </summary> /// <param name="condition">条件</param> /// <param name="page">数据页</param> /// <returns>数据页</returns> public DataPage GetList(WHArea condition, DataPage page) { string sql = null; List <DataParameter> parameters = new List <DataParameter>(); try { sql = this.GetQuerySql(condition, ref parameters); //分页关键字段及排序 page.KeyName = "ID"; if (string.IsNullOrEmpty(page.SortExpression)) { page.SortExpression = "UPDATETIME DESC"; } using (IDataSession session = AppDataFactory.CreateMainSession()) { page = session.GetDataPage <WHArea>(sql, parameters.ToArray(), page); } return(page); } catch (Exception ex) { throw ex; } }
/// <summary> /// 判断名称是否存在 /// </summary> /// <param name="info"></param> /// <returns>true:已存在;fasel:不存在。</returns> public bool ExistsWHArea(WHArea model) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List <DataParameter> parameters = new List <DataParameter>(); int count = 0; try { sqlBuilder.Append("SELECT COUNT(0) FROM T_WH_AREA"); sqlBuilder.Append(" WHERE ID <> @ID AND WHID = @WHID AND (Code = @Code or Description = @Description)"); parameters.Add(new DataParameter { ParameterName = "ID", DataType = DbType.String, Value = model.ID }); parameters.Add(new DataParameter { ParameterName = "WHID", DataType = DbType.String, Value = model.WHID }); parameters.Add(new DataParameter { ParameterName = "Code", DataType = DbType.String, Value = model.Code }); parameters.Add(new DataParameter { ParameterName = "Description", DataType = DbType.String, Value = model.Description }); using (IDataSession session = AppDataFactory.CreateMainSession()) { count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray())); } return(count > 0); } catch (Exception ex) { throw ex; } }
private void BindData() { WHAreaBLL bll = null; DataPage dp = new DataPage(); WHArea condition = new WHArea(); string whID = Request.QueryString["whID"]; try { bll = BLLFactory.CreateBLL <WHAreaBLL>(); this.hiWHID.Value = whID; condition.Code = this.Code.Text.Trim(); condition.WHID = whID; condition.Description = this.Description.Text.Trim(); PagerHelper.InitPageControl(this.AspNetPager1, dp, true); dp = bll.GetList(condition, dp); List <WHArea> list = dp.Result as List <WHArea>; this.GvList.DataSource = list; this.GvList.DataBind(); for (int i = 0; i < this.GvList.Rows.Count; i++) { string click = string.Format("return edit('{0}');", this.GvList.DataKeys[i]["ID"].ToString()); (this.GvList.Rows[i].Cells[5].Controls[0] as WebControl).Attributes.Add("onclick", click); } PagerHelper.SetPageControl(AspNetPager1, dp, true); } catch (Exception ex) { throw ex; } }
/// <summary> /// 删除信息 /// </summary> /// <param name="">信息</param> /// <returns>删除个数</returns> public int DeleteWHArea(WHArea model) { try { return(new WHAreaDAL().Delete(model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 判断名称是否存在 /// </summary> /// <param name="">信息</param> /// <returns>true:已存在;fasel:不存在。</returns> public bool ExistsWHArea(WHArea model) { try { return(new WHAreaDAL().ExistsWHArea(model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取信息 /// </summary> /// <param name="">条件</param> /// <returns>信息</returns> public WHArea Get(WHArea model) { try { return(new WHAreaDAL().Get(model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取列表 /// </summary> /// <param name="condition">条件</param> /// <param name="page">数据页</param> /// <returns>数据页</returns> public DataPage GetList(WHArea condition, DataPage page) { try { return(new WHAreaDAL().GetList(condition, page)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取导出的数据 /// </summary> /// <param name="">查询条件</param> /// <returns>数据</returns> public DataTable GetExportData(WHArea model) { try { return(new WHAreaDAL().GetExportData(model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取信息 /// </summary> /// <param name="">条件</param> /// <returns>*信息</returns> public WHArea Get(WHArea model) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 model = session.Get <WHArea>(model); } return(model); } catch (Exception ex) { throw ex; } }
/// <summary> /// 删除信息 /// </summary> /// <param name=""></param> /// <returns>删除个数</returns> public int Delete(WHArea model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //删除基本信息 count = session.Delete <WHArea>(model); } return(count); } catch (Exception ex) { throw ex; } }
private void BindData() { string id = Request.QueryString["id"]; WHAreaBLL bll = null; WHArea info = new WHArea(); string whID = Request.QueryString["whID"]; try { if (string.IsNullOrEmpty(whID) == false) { this.Warehourse.Enabled = false; } else { this.Warehourse.Enabled = true; } bll = BLLFactory.CreateBLL <WHAreaBLL>(); if (string.IsNullOrEmpty(id) == false) { info.ID = id; info = bll.Get(info); UIBindHelper.BindForm(this.Page, info); this.Warehourse.SelectedValue = info.WHID; this.hiID.Value = info.ID; this.HiCREATEUSER.Value = info.CREATEUSER; this.HiCREATETIME.Value = info.CREATETIME.ToString(); this.Warehourse.Enabled = false; } else { info = new WHArea(); this.Warehourse.SelectedValue = whID; } } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取查询语句 /// </summary> /// <param name="user">查询条件</param> /// <param name="parameters">参数</param> /// <returns>查询语句</returns> private string GetQuerySql(WHArea condition, ref List <DataParameter> parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.Append(@"SELECT t1.ID,t1.Code,t1.Description,t1.WHID,t2.Description as WarehourseName,t1.Remark,t1.CREATEUSER,t1.CREATETIME,t1.UPDATEUSER,t1.UPDATETIME FROM T_WH_AREA t1 Inner join T_WH_Warehouse t2 on t1.WHID=t2.ID"); if (string.IsNullOrEmpty(condition.WHID) == false) { whereBuilder.Append(" AND t1.WHID = @WHID"); parameters.Add(new DataParameter("WHID", condition.WHID)); } if (string.IsNullOrEmpty(condition.Code) == false) { whereBuilder.Append(" AND t1.Code like @Code"); parameters.Add(new DataParameter("Code", "%" + condition.Code + "%")); } if (string.IsNullOrEmpty(condition.Description) == false) { whereBuilder.Append(" AND t1.Description like @Description"); parameters.Add(new DataParameter("Description", "%" + condition.Description + "%")); } //查询条件 if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return(sqlBuilder.ToString()); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取导出的数据 /// </summary> /// <param name="user">查询条件</param> /// <returns>数据</returns> public DataTable GetExportData(WHArea model) { DataTable dt = null; string sql = null; List <DataParameter> parameters = new List <DataParameter>(); try { //构成查询语句 sql = this.GetQuerySql(model, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(sql, parameters.ToArray()); dt.TableName = "WHArea"; } return(dt); } catch (Exception ex) { throw ex; } }
/// <summary> /// 更新信息 /// </summary> /// <param name="">信息</param> /// <returns>更新行数</returns> public DataResult <int> Update(WHArea model) { DataResult <int> result = new DataResult <int>(); try { if (ExistsWHArea(model)) { result.Msg = "编号或名称已存在"; result.Result = -1; return(result); } model.UPDATEUSER = this.LoginUser.UserID; result.Result = new WHAreaDAL().Update(model); result.IsSuccess = true; return(result); } catch (Exception ex) { throw ex; } }
protected void btSave_Click(object sender, EventArgs e) { WHArea info = new WHArea(); WHAreaBLL bll = null; DataResult <int> result = null; try { UIBindHelper.BindModelByControls(this.Page, info); bll = BLLFactory.CreateBLL <WHAreaBLL>(); info.WHID = this.Warehourse.SelectedValue; if (this.hiID.Value == "") { result = bll.Insert(info); } else { info.CREATEUSER = this.HiCREATEUSER.Value; info.CREATETIME = DateTime.Parse(this.HiCREATETIME.Value); info.ID = this.hiID.Value; result = bll.Update(info); } if (string.IsNullOrEmpty(result.Msg) == false) { ClientScript.RegisterStartupScript(this.GetType(), "myjs", "MSI('提示','" + result.Msg + "')", true); } else { ClientScript.RegisterStartupScript(this.GetType(), "myjs", "parent.refreshData();parent.closeAppWindow1();", true); } } catch (Exception ex) { throw ex; } }
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 int UpdateLines(ISession session, IList <RCVLine> linesValue) { if (linesValue == null || linesValue.Count <= 0) { return(0); } #region 检查 IList <RCVLine> lines = new List <RCVLine>(linesValue.Count); bool error = false, errorHead = false; System.Text.StringBuilder builder = new System.Text.StringBuilder(); bool hasSection = false; foreach (RCVLine lv in linesValue) { errorHead = false; //收货数量是否有效 if (lv.RCVTotalQty <= 0M) { error = true; if (!errorHead) { builder.Append("行号").Append(lv.LineNumber).Append(": "); } errorHead = true; builder.Append("收货数量小于0; "); continue; } RCVLine l = RCVLine.Retrieve(session, lv.OrderNumber, lv.LineNumber); //可以不填写货架,但如果填写了,则检查货架有效性 WHSection section = null; hasSection = false; //库位、货架容量检查 WHArea area = WHArea.Retrieve(session, l.AreaCode); if (!string.IsNullOrEmpty(l.SectionCode) && l.SectionCode.Trim().Length > 0) { hasSection = true; section = WHSection.Retrieve(session, l.AreaCode, l.SectionCode); } decimal capacityFree = 0M; //取库位、货架容量 if (hasSection) { capacityFree = section.SectionCapacity; } else { capacityFree = area.AreaCapacity; } //库位容量扣减当前已存放量 if (hasSection) { capacityFree = capacityFree - Cast.Decimal(session.CreateObjectQuery(@" select sum(StockQty) from StockDetail where AreaCode=?area and SectionCode=?section") .Attach(typeof(StockDetail)) .SetValue("?area", area.AreaCode, "AreaCode") .SetValue("?section", section.SectionCode, "SectionCode") .Scalar(), 0M); } else { capacityFree = capacityFree - Cast.Decimal(session.CreateObjectQuery(@"select sum(StockQty) from StockDetail where AreaCode=?area") .Attach(typeof(StockDetail)) .SetValue("?area", area.AreaCode, "AreaCode") .Scalar(), 0M); } //剩余容量和本次入库量比较 if (capacityFree < lv.QualifiedQty) { builder.Append("行号").Append(lv.LineNumber).Append(": "); error = true; builder.Append("入库量").Append(lv.QualifiedQty).Append("大于剩余容量").Append(capacityFree); } if (!error) { lines.Add(l); } } if (error) { throw new Exception(builder.ToString()); } #endregion int count = 0; DbSession dbsession = session.DbSession as DbSession; session.BeginTransaction(); for (int i = 0; i < lines.Count; i++) { RCVLine line = lines[i]; POLine poLine = null; if (!string.IsNullOrEmpty(this._refOrderNumber) && this._refOrderNumber.Trim().Length > 0 && !string.IsNullOrEmpty(line.RefOrderLine) && line.RefOrderLine.Trim().Length > 0) { poLine = POLine.Retrieve(session, this._refOrderNumber, line.RefOrderLine); } if (poLine != null) { IDbCommand cmd = dbsession.CreateStoredProcCommand("F_PUR_RCV_TOLERANCE_RATIO", new object[] { 0, poLine.OrderNumber }); dbsession.ExecuteNonQuery(cmd); IDbDataParameter p = cmd.Parameters[0] as IDbDataParameter; decimal ration = Cast.Decimal(p.Value); if (poLine.PurchaseQty * (1 + ration) - poLine.ReceiveQty - poLine.UnfinishedReceiveQty - linesValue[i].QualifiedQty + line.QualifiedQty < 0) { error = true; builder.Append("行号").Append(line.LineNumber).Append("收货数量").Append(linesValue[i].QualifiedQty) .Append("超过PO最大可收货数量").Append(Math.Floor(poLine.PurchaseQty * (1 + ration)) - poLine.ReceiveQty - poLine.UnfinishedReceiveQty + line.QualifiedQty); break; } poLine.UnfinishedReceiveQtyChange(session, linesValue[i].QualifiedQty - line.QualifiedQty); } line.RCVTotalQty = linesValue[i].RCVTotalQty; line.QualifiedQty = linesValue[i].QualifiedQty; line.Update(session, "RCVTotalQty", "QualifiedQty"); count++; } if (error) { session.Rollback(); throw new Exception(builder.ToString()); } else { session.Commit(); } return(count); }