public List <WWBCBZ> GetBc()
        {
            // 传入外委物料代码决定工序,获取ERP代码

            var mod_TB_STA = dalTbSta.GetModelByCODE(GetStaCode(""));

            var table = dalBcBz.GetNCBCList(mod_TB_STA.C_STA_ERPCODE, "").Tables[0];

            var current       = dalBcBz.GetList(mod_TB_STA.C_PRO_ID, DateTime.Now).Tables[0];
            var currentBCName = current.Rows[0]["C_BC_NAME"].ToString();

            var list = table.DataTableToList2 <WWBCBZ>();

            var currentItem = list.FirstOrDefault(w => w.BCNAME == currentBCName);

            if (currentItem != null)
            {
                currentItem.Selected = true;
            }

            return(list);
        }
        /// <summary>
        /// 上传NC
        /// </summary>
        /// <param name="list">委外组批计划ID(组批计划包含完工信息)</param>
        public void SendToNC(List <string> list)
        {
            if (list.Any() == false)
            {
                throw new Exception("请选择后再上传");
            }

            var ids        = "('" + string.Join("','", list) + "')";
            var updateMods = dalWWMain.GetList($"C_ID IN {ids}").Tables[0].DataTableToList2 <Mod_TRC_ROLL_WW_MAIN>();

            if (updateMods.Any() == false)
            {
                throw new Exception("没有需要上传NC的数据");
            }

            if (updateMods.Any(w => w.N_STATUS < 1 || w.N_STATUS == 30))
            {
                throw new Exception("只有状态为已完工或未上传完毕的,才能上传NC");
            }

            foreach (var item in updateMods)
            {
                if (string.IsNullOrEmpty(item.C_PRODUCE_EMP_ID))
                {
                    item.C_PRODUCE_EMP_ID = "1001NC100000002SS9XB";
                }

                if (string.IsNullOrEmpty(item.C_EMP_ID))
                {
                    item.C_EMP_ID = "1001NC100000002SS9XB";
                }

                // 获取用户信息
                var planUser    = dalUser.GetModel(item.C_EMP_ID);         // 组批计划员
                var productUser = dalUser.GetModel(item.C_PRODUCE_EMP_ID); // 生产人员

                // 合同信息
                var contractInfo = dalOrder.GetModel(item.C_ORD_ID);

                if (contractInfo == null)
                {
                    continue;
                }

                // 订单物料信息
                var ordMatrl = bll_TB_MATRL_MAIN.GetModel(contractInfo.C_MAT_CODE);

                if (contractInfo == null)
                {
                    continue;
                }

                // 耗用线材物料信息
                var consumeMatrl = bll_TB_MATRL_MAIN.GetModel(item.C_MAT_XC_CODE);

                if (consumeMatrl == null)
                {
                    continue;
                }
                // 线材批次信息
                var xcBatchInfo = dalWWMain.GetItemList(item.C_ID).FirstOrDefault();
                if (xcBatchInfo == null)
                {
                    continue;
                }

                if (contractInfo == null || ordMatrl == null)
                {
                    continue;
                }

                // 传入外委物料代码决定工序,获取ERP代码
                var mod_TB_STA = dalTbSta.GetModelByCODE(Bll_TRC_ROLL_PRODCUT.GetStaCode(contractInfo.C_MAT_CODE));

                if (item.N_STATUS == 1)
                {
                    // 上传NC
                    var itemA1   = GetA1(contractInfo, ordMatrl, item, mod_TB_STA, planUser);
                    var a1Result = dalA1.SendXml_ROLL_A1(item.C_ID, string.Empty, "A1.xml", itemA1, AppDomain.CurrentDomain.BaseDirectory);

                    if (NCInterface.NCConfig.IsSendToNC)
                    {
                        // 状态0创建,10完工,21已传NC_A1,22已传NC_A2,23已传NC_A3,24已传NC_A4,25已传NC_A46,30上传NC完毕,
                        if (a1Result[0] == "1")
                        {
                            // 上传成功,更新状态
                            item.N_STATUS = 21;
                            dalWWMain.SetStatu(item);
                        }
                        else
                        {
                            throw new Exception(GetNCError(a1Result));
                        }
                    }
                }

                if (item.N_STATUS == 21)
                {
                    // 上传NC
                    var itemA2   = GetA2(contractInfo, ordMatrl, item, mod_TB_STA, planUser);
                    var a2Result = dalA2.SendXml_ROLL_A2(item.C_ID, string.Empty, "A2.xml", itemA2, AppDomain.CurrentDomain.BaseDirectory);

                    if (NCInterface.NCConfig.IsSendToNC)
                    {
                        if (a2Result[0] == "1")
                        {
                            item.N_STATUS = 22;
                            // 上传成功,更新状态
                            dalWWMain.SetStatu(item);
                        }
                        else
                        {
                            throw new Exception(GetNCError(a2Result));
                        }
                    }
                }

                if (item.N_STATUS == 22)
                {
                    // 上传NC
                    var itemA3   = GetA3(contractInfo, ordMatrl, consumeMatrl, item, mod_TB_STA, xcBatchInfo);
                    var a3Result = dalA3.SendXml_ROLL_A3(item.C_ID, string.Empty, "A3.xml", itemA3, AppDomain.CurrentDomain.BaseDirectory);

                    if (NCInterface.NCConfig.IsSendToNC)
                    {
                        if (a3Result[0] == "1")
                        {
                            // 上传成功,更新状态
                            item.N_STATUS = 23;
                            dalWWMain.SetStatu(item);
                        }
                        else
                        {
                            throw new Exception(GetNCError(a3Result));
                        }
                    }
                }

                if (item.N_STATUS == 23)
                {
                    // 上传NC
                    var itemA4   = GetA4(contractInfo, ordMatrl, item, mod_TB_STA, productUser);
                    var a4Result = dalA4.SendXml_ROLL_A4(item.C_ID, string.Empty, item.C_ID + "A4.xml", itemA4, AppDomain.CurrentDomain.BaseDirectory);

                    if (NCInterface.NCConfig.IsSendToNC)
                    {
                        if (a4Result[0] == "1")
                        {
                            item.N_STATUS = 24;
                            // 上传成功,更新状态
                            dalWWMain.SetStatu(item);
                        }
                        else
                        {
                            throw new Exception(GetNCError(a4Result));
                        }
                    }
                }

                if (item.N_STATUS == 24)
                {
                    // 上传NC
                    var item46    = Get46(contractInfo, ordMatrl, item, mod_TB_STA, productUser);
                    var a46Result = dal46.SendXml_ROLL_46(item.C_ID, string.Empty, "A46.xml", new List <NcRoll46> {
                        item46
                    }, AppDomain.CurrentDomain.BaseDirectory);

                    if (NCInterface.NCConfig.IsSendToNC)
                    {
                        if (a46Result[0] == "1")
                        {
                            item.N_STATUS = 25;
                            dalWWMain.SetStatu(item);
                        }
                        else
                        {
                            throw new Exception(GetNCError(a46Result));
                        }
                    }
                }
                if (item.N_STATUS == 25)
                {
                    // 入库操作
                    RuKu(item, mod_TB_STA, contractInfo);
                    // 更新状态
                    item.N_STATUS = 30;
                    dalWWMain.SetStatu(item);

                    dalWWMain.SetDesignNo(item);
                }
                else
                {
                    throw new Exception("上传NC失败");
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Mod_TB_STA GetModelByCODE(string C_STA_CODE)
 {
     return(dal.GetModelByCODE(C_STA_CODE));
 }