Ejemplo n.º 1
0
        public RDataBom ImportToBom([FromBody] RDataBom RDataBom)
        {
            var dtBoms = RDataBom.boms;

            Debug.WriteLine(RDataBom.boms.Rows.Count);

            if (dtBoms == null || dtBoms.Rows.Count <= 0)
            {
                throw new Exception("表格没有记录");
            }

            var excelFormat = Service.FetchExcelFormat(RDataBom.format_no);

            if (excelFormat == null)
            {
                throw new Exception("导入格式 不存在!");
            }
            var excelFormatDtls = Service.GetDtls(excelFormat.Id);

            //检查Bom阶级
            ImportBomFormExcel importTool = new ImportBomFormExcel();
            var headBomRow = dtBoms.NewRow();

            headBomRow["prd_no"] = RDataBom.prd_no;
            headBomRow["dep"]    = RDataBom.dep_no;
            headBomRow["name"]   = RDataBom.prd_name;

            //dtBoms.Rows.InsertAt(headBomRow, 0);
            if (dtBoms.Columns.IndexOf("id_no") < 0)
            {
                dtBoms.Columns.Add(new DataColumn("id_no"));
            }
            if (dtBoms.Columns.IndexOf("wh_no") < 0)
            {
                dtBoms.Columns.Add(new DataColumn("wh_no"));
            }

            ///清空之前的检测结果
            foreach (DataRow row in dtBoms.Rows)
            {
                row["Check_Result"]   = "";
                row["check_err_code"] = "";
            }

            BomInfo bomInfo = importTool.DoCheckBomLevel(dtBoms, dtBoms.Rows[0], headBomRow, "", BomLevelType: "Split");

            bool hitError = false;
            //检测ERP中字段是否存在
            var checkFields = excelFormatDtls.Where(o => o.check_exist.IsNotEmpty()).ToList();

            foreach (DataRow item in dtBoms.Rows)
            {
                foreach (var item2 in checkFields)
                {
                    string value = item[item2.field_no].ObjToString();
                    if (value.IsNotEmpty() && Service.CheckValueExsistInTable(item2.check_exist, value) == false)
                    {
                        item["Check_Result"] = "不存在:" + item2.check_exist + " 值:" + value;
                        if (item2.field_no == "prd_no")
                        {
                            item["check_err_code"] = "MISS_PRDT";
                        }

                        hitError = true;
                        break;
                    }
                }
            }

            if (hitError == false)
            {
                hitError = !Service.ValidateSubBom(bomInfo, true, RDataBom.is_check);
            }

            if (hitError == false)
            {
                hitError = !Service.ValidateInNoBomConflit(bomInfo);
            }

            if (hitError == false)
            {
                Service.SetDefaultWh(bomInfo);
            }

            if (hitError == false && RDataBom.is_check == false)
            {
                var cmds = DoImportToBom(bomInfo, excelFormatDtls, true);
                foreach (var item in cmds)
                {
                    Debug.WriteLine(item.CommandText);
                }
                Service.ExeCmds(cmds);
            }

            if (RDataBom.is_check == false && hitError == true)
            {
                throw new Exception("检测失败不允许导入Bom");
            }

            return(RDataBom);
        }