Пример #1
0
        /// <summary>
        /// 发布(提交)
        /// </summary>
        /// <param name="id"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public bool ReleaseInfos(List <string> rowsKeyValues, string loginUser)
        {
            ///入库单
            List <VmiReceiveInfo> vmiReceiveInfos = dal.GetList("[ID] in (" + string.Join(",", rowsKeyValues.ToArray()) + ")", "[ID]");

            if (vmiReceiveInfos.Count == 0)
            {
                throw new Exception("MC:0x00000084");///数据错误
            }
            ///入库单明细
            List <VmiReceiveDetailInfo> vmiReceiveDetailInfos = new VmiReceiveDetailDAL().GetList("[RECEIVE_FID] in ('" + string.Join("','", vmiReceiveInfos.Select(d => d.Fid.GetValueOrDefault()).ToArray()) + "')", "[ID]");

            if (vmiReceiveDetailInfos.Count == 0)
            {
                throw new Exception("MC:0x00000367");///入库单没有明细
            }
            ///获取系统配置
            Dictionary <string, string> configs = new ConfigDAL().GetValuesByCodes(new string[] {
                "RELEASE_VMI_RECEIVE_ACTUAL_QTY_EQUALS_REQUIRED",
                "MANUAL_VMI_RECEIVE_ORDER_RELEASE_CREATE_BARCODE",
                "RELEASE_VMI_RECEIVE_LOAD_PART_INSPECTION_MODE"
            });
            ///已生成的标签
            List <BarcodeInfo> barcodeInfos = new BarcodeDAL().GetList("" +
                                                                       "[BARCODE_STATUS] = " + (int)BarcodeStatusConstants.Created + " and " +
                                                                       "[CREATE_SOURCE_FID] in ('" + string.Join("','", vmiReceiveDetailInfos.Select(d => d.Fid.GetValueOrDefault()).ToArray()) + "')", string.Empty);

            ///执行语句
            StringBuilder @string = new StringBuilder();

            foreach (var vmiReceiveInfo in vmiReceiveInfos)
            {
                ///一般手工创建入库单会用到此功能,入库单必须为10.已创建状态⑫
                if (vmiReceiveInfo.Status.GetValueOrDefault() != (int)WmmOrderStatusConstants.Created)
                {
                    throw new Exception("MC:0x00000683");///状态必须为已创建
                }
                ///VMI入库单明细
                List <VmiReceiveDetailInfo> vmiReceiveDetails = vmiReceiveDetailInfos.Where(d => d.ReceiveFid.GetValueOrDefault() == vmiReceiveInfo.Fid.GetValueOrDefault()).ToList();
                ///VMI入库单对应的标签数据
                List <BarcodeInfo> barcodes = barcodeInfos.Where(d => vmiReceiveDetails.Select(f => f.Fid.GetValueOrDefault()).Contains(d.CreateSourceFid.GetValueOrDefault())).ToList();
                ///将VMI入库单明细对象转换为普通入库单对象,方便后续函数处理
                List <ReceiveDetailInfo> receiveDetailInfos = ReceiveDetailBLL.GetReceiveDetailInfos(vmiReceiveDetails);
                ///手工创建VMI入库单时创建条码标签
                configs.TryGetValue("MANUAL_VMI_RECEIVE_ORDER_RELEASE_CREATE_BARCODE", out string manual_vmi_receive_order_release_create_barcode);
                if (!string.IsNullOrEmpty(manual_vmi_receive_order_release_create_barcode) && manual_vmi_receive_order_release_create_barcode.ToLower() == "true")
                {
                    @string.AppendLine(MaterialPullingCommonBLL.GetCreateBarcodesSql(receiveDetailInfos, barcodes, loginUser));
                }
                ///
                ReceiveInfo receiveInfo = ReceiveBLL.CreateReceiveInfo(loginUser);
                ///VmiReceiveInfo -> ReceiveInfo
                ReceiveBLL.GetReceiveInfo(vmiReceiveInfo, ref receiveInfo);
                ///VMI入库单发布时是否加载物料检验模式,TODO:此处函数内有与入库单共用的系统配置
                configs.TryGetValue("RELEASE_VMI_RECEIVE_LOAD_PART_INSPECTION_MODE", out string release_vmi_receive_load_part_inspection_mode);
                if (!string.IsNullOrEmpty(release_vmi_receive_load_part_inspection_mode) && release_vmi_receive_load_part_inspection_mode.ToLower() == "true")
                {
                    @string.AppendLine(PartInspectionModeBLL.LoadInspectionMode(ref receiveInfo, ref receiveDetailInfos, loginUser));
                }
                ///行号更新
                int rowNo = 0;
                ///发布VMI入库单时实收数量默认等于需求数量
                configs.TryGetValue("RELEASE_VMI_RECEIVE_ACTUAL_QTY_EQUALS_REQUIRED", out string release_vmi_receive_actual_qty_equals_required);
                foreach (var receiveDetailInfo in receiveDetailInfos)
                {
                    if (!string.IsNullOrEmpty(release_vmi_receive_actual_qty_equals_required) && release_vmi_receive_actual_qty_equals_required.ToLower() == "true")
                    {
                        if (receiveDetailInfo.ActualBoxNum == null)
                        {
                            receiveDetailInfo.ActualBoxNum = receiveDetailInfo.RequiredBoxNum;
                        }
                        if (receiveDetailInfo.ActualQty == null)
                        {
                            receiveDetailInfo.ActualQty = receiveDetailInfo.RequiredQty;
                        }
                    }
                    ///更新入库单明细需要注意不能覆盖明细中原内容
                    @string.AppendLine("update [LES].[TT_WMM_VMI_RECEIVE_DETAIL] set " +
                                       "[ROW_NO] = " + ++rowNo + "," +
                                       (receiveDetailInfo.ActualBoxNum == null ? string.Empty : "[ACTUAL_BOX_NUM] = " + receiveDetailInfo.ActualBoxNum.GetValueOrDefault() + ",") +
                                       (receiveDetailInfo.ActualQty == null ? string.Empty : "[ACTUAL_QTY] = " + receiveDetailInfo.ActualQty.GetValueOrDefault() + ",") +
                                       (receiveDetailInfo.InspectionMode == null ? string.Empty : "[INSPECTION_MODE] = " + receiveDetailInfo.InspectionMode.GetValueOrDefault() + ",") +
                                       (string.IsNullOrEmpty(receiveDetailInfo.SupplierNum) ? "[SUPPLIER_NUM] = N'" + receiveInfo.SupplierNum + "'," : string.Empty) +
                                       "[WM_NO] = N'" + receiveInfo.WmNo + "'," +
                                       "[ZONE_NO] = N'" + receiveInfo.ZoneName + "'," +
                                       "[TARGET_WM] = N'" + receiveInfo.WmNo + "'," +
                                       "[TARGET_ZONE] = N'" + receiveInfo.ZoneNo + "'," +
                                       (string.IsNullOrEmpty(receiveDetailInfo.RunsheetNo) ? "[RUNSHEET_NO] = N'" + receiveInfo.RunsheetNo + "'," : string.Empty) +
                                       "[MODIFY_DATE] = GETDATE()," +
                                       "[MODIFY_USER] = N'" + loginUser + "' where " +
                                       "[ID] = " + receiveDetailInfo.Id + ";");
                }
                ///更新入库单
                @string.AppendLine("update [LES].[TT_WMM_VMI_RECEIVE] set " +
                                   "[SUM_PART_QTY] = " + vmiReceiveDetails.Sum(d => d.RequiredQty.GetValueOrDefault()) + "," +
                                   "[SUM_OF_PRICE] = " + vmiReceiveDetails.Sum(d => d.PartPrice.GetValueOrDefault()) + "," +
                                   "[SUM_WEIGHT] = " + vmiReceiveDetails.Sum(d => d.SumWeight.GetValueOrDefault()) + "," +
                                   "[SUM_VOLUME] = " + vmiReceiveDetails.Sum(d => d.SumVolume.GetValueOrDefault()) + "," +
                                   "[SUM_PACKAGE_QTY] = " + vmiReceiveDetails.Sum(d => d.RequiredBoxNum.GetValueOrDefault()) + "," +
                                   //"[INSPECTION_FLAG] = " + (receiveInfo.InspectionFlag.GetValueOrDefault() ? 1 : 0) + "," +
                                   "[STATUS] = " + (int)WmmOrderStatusConstants.Published + "," +
                                   "[MODIFY_USER] = N'" + loginUser + "' ," +
                                   "[MODIFY_DATE] = GETDATE() where " +
                                   "[ID] = " + vmiReceiveInfo.Id + ";");
            }
            ///删除已删除VMI入库单明细的标签
            @string.AppendLine("update [LES].[TT_WMM_BARCODE] " +
                               "set [VALID_FLAG] = 0 " +
                               "where [CREATE_SOURCE_FID] in (select [FID] from [LES].[TT_WMM_VMI_RECEIVE_DETAIL] with(nolock) " +
                               "where [VALID_FLAG] = 0 and [RECEIVE_FID] in ('" + string.Join("','", vmiReceiveInfos.Select(d => d.Fid.GetValueOrDefault()).ToArray()) + "'));");
            ///执行
            using (TransactionScope trans = new TransactionScope())
            {
                if (@string.Length > 0)
                {
                    CommonDAL.ExecuteNonQueryBySql(@string.ToString());
                }
                trans.Complete();
            }
            return(true);
        }