Esempio n. 1
0
        public List <dynamic> GetBoomTree(string PartCode, string ContractCode, string ProductName)
        {
            var list        = new PMS_BN_PartFileService().GetBom(PartCode);
            var notShowList = new MES_BN_MatchingTableDetailService().GetNotShowBom(PartCode, ContractCode, ProductName, "1");

            foreach (var item in notShowList)
            {
                var part = (from p in list where p.PartCode == item select p).FirstOrDefault();
                if (part != null)
                {
                    list.Remove(part);
                }
            }
            List <dynamic> list2 = new List <dynamic>();

            foreach (var item in list)
            {
                list2.Add(new { id = item.PartCode, pid = item.ParentCode, text = item.PartCode + " " + item.PartName });
            }
            return(list2);
        }
Esempio n. 2
0
        public void Cover_MES_BN_MatchingTableDetail(List <MES_BN_MatchingTableDetail> MES_BN_MatchingTableDetailList, List <PRS_Process_BOM> ProcessBomList)
        {
            try
            {
                db.UseTransaction(true);

                var MaxID = new MES_BN_MatchingTableDetailService().GetField <int>(ParamQuery.Instance().Select("max(ID) as ID").From("MES_BN_MatchingTableDetail"));

                string MES_BN_MatchingTableDetailListStr = string.Join(",", MES_BN_MatchingTableDetailList.Select(a => a.ID));
                db.Sql($"update MES_BN_MatchingTableDetail set IsEnable=0 where ID in({MES_BN_MatchingTableDetailListStr})").Execute();

                var PMS_BN_ProjectList       = new PMS_BN_ProjectService().GetModelList();
                var PMS_BN_ProjectDetailList = new PMS_BN_ProjectDetailService().GetModelList();

                var UpdateList = new List <int>();
                ProcessBomList.ForEach(item =>
                {
                    var PartCode   = item.PartCode;
                    var ParentCode = item.ParentCode;
                    var IsExist    = MES_BN_MatchingTableDetailList.Where(a => a.PartCode == PartCode && a.PPartCode == ParentCode).Select(a => a.ID);
                    if (IsExist.Count() > 0)
                    {
                        UpdateList.Add(IsExist.FirstOrDefault());
                    }
                    else
                    {
                        MES_BN_MatchingTableDetail model = new MES_BN_MatchingTableDetail();
                        model.ID              = ++MaxID;
                        model.PartCode        = PartCode;
                        model.PartName        = item.PartName;
                        model.PPartCode       = item.ParentCode;
                        model.ContractCode    = item.ContractCode;
                        model.ProjectDetailID = item.ProductID;
                        model.ProjectName     = PMS_BN_ProjectDetailList.Where(a => a.ID == item.ProductID).FirstOrDefault().ProductName;
                        model.NeedQuantity    = item.PartQuantity ?? 0 * PMS_BN_ProjectDetailList.Where(a => a.ID == item.ProductID).FirstOrDefault().Quantity ?? 0;
                        model.Type            = item.IsSelfMade;
                        model.TypeName        = item.IsSelfMade == "0" ? "成品件" : "加工件";
                        model.BomQuantity     = item.PartQuantity ?? 0;
                        model.IsMaterial      = 0;
                        model.IsEnable        = 1;
                        model.ApproveState    = "1";
                        model.CreatePerson    = MmsHelper.GetUserName();
                        model.CreateTime      = DateTime.Now;
                        //db.Insert<MES_BN_MatchingTableDetail>("MES_BN_MatchingTableDetail", model).AutoMap(a => a.ID).ExecuteReturnLastId<int>();
                        string sql = WinFormClientService.GetInsertSQL <MES_BN_MatchingTableDetail>(model);
                        db.Sql(sql).Execute();
                    }
                });

                if (UpdateList.Count > 0)
                {
                    db.Sql($"update MES_BN_MatchingTableDetail set IsEnable=1 where ID in({string.Join(",", UpdateList)})").Execute();
                }

                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
            }
        }
        public int AuditBillCode(string mainID, out string msg)
        {
            msg = string.Empty;
            var    rowsAffected = 0;
            string sql          = String.Format(@"  select * FROM MES_PurchaseOrderMain t1 left join MES_PurchaseOrderDetail t2 on t1.ID=t2.MainID where t1.ID='{0}'", mainID);
            //if sql.Contains
            var resList = db.Sql(sql).QueryMany <dynamic>();

            if (resList[0].BillState == 2)
            {
                msg = "单据已审核";
                return(0);
            }
            else if (resList.Count == 0)
            {
                msg = "请先保存数据再审核";
                return(0);
            }
            else
            {
                int isFalse = 0;
                int res     = 0;
                try
                {
                    db.UseTransaction(true);
                    sql          = string.Format(@"update MES_PurchaseOrderMain set BillState=2 where BillCode='{0}'", resList[0].BillCode);
                    rowsAffected = db.Sql(sql).Execute();
                    if (rowsAffected > 0)
                    {
                        msg = "采购订单审核成功";
                        sql = String.Format(@"   select t2.ID as id from MES_PurchaseOrderMain t1 left join APS_ProductPurchaseMain t2 on t1.ProductPurchaseCode=t2.PurchaseDocumentCode 
 where t1.ID='{0}'", mainID);
                        string mID = db.Sql(sql).QuerySingle <string>();
                        sql = "";
                        foreach (var item in resList)
                        {
                            res++;
                            sql = sql + string.Format(@" update APS_ProductPurchaseDetail set PurchaseState=2 where MainID='{0}' and InventoryCode='{1}' ", mID, item.InventoryCode);
                        }
                        rowsAffected = db.Sql(sql).Execute();

                        //遍历采购订单明细表,生成采购过程数据

                        foreach (var item in resList)
                        {
                            //item.MatchTableID
                            MES_BN_MatchingTableDetail MatchingTable = new MES_BN_MatchingTableDetailService().GetModel(ParamQuery.Instance().AndWhere("IsEnable", 1).AndWhere("ID", item.MatchTableID));
                            MatchingTable = MatchingTable ?? new MES_BN_MatchingTableDetail();
                            string sqlMaterial          = string.Format(@" SELECT MaterialCode from dbo.PRS_Process_BOM WHERE InventoryCode='{0}' AND IsEnable=1", item.InventoryCode);
                            Mes_PurchaseProcess process = new Mes_PurchaseProcess();
                            process.ContractCode = item.ContractCode;
                            //process.ProductID = MatchingTable.ID ?? 0;
                            //process.ProductID = item.ProcessCode;
                            process.UserCode = item.UserCode;
                            if (MatchingTable.ProjectDetailID != null)
                            {
                                process.ProductID = MatchingTable.ProjectDetailID;
                            }
                            process.SaleMan         = item.SaleMan;
                            process.InventoryCode   = item.InventoryCode;
                            process.InventoryName   = item.InventoryName;
                            process.Model           = item.Model;
                            process.MaterialCode    = db.Sql(sqlMaterial).QuerySingle <string>();
                            process.SupplierCode    = item.SupplierCode;
                            process.Quantity        = item.OrderQuantity;
                            process.PurchaseCode    = item.BillCode;
                            process.PrchaseDate     = item.OrderDate;
                            process.IsEnable        = 1;
                            process.PlanArrivelDate = item.PlanArrivelDate;
                            process.CreatePerson    = MmsHelper.GetUserName();
                            process.CreateTime      = DateTime.Now;
                            process.ModifyPerson    = MmsHelper.GetUserName();
                            process.ModifyTime      = DateTime.Now;
                            var detailID = db.Insert <Mes_PurchaseProcess>("Mes_PurchaseProcess", process)
                                           .AutoMap(x => x.ID).ExecuteReturnLastId <int>();
                        }

                        if (rowsAffected == res)
                        {
                            msg = "操作成功";
                            db.Commit();
                            return(1);
                        }
                        else
                        {
                            isFalse++;
                            return(0);
                        }



                        //return rowsAffected;
                    }
                    else
                    {
                        msg = "采购订单审核失败";
                        db.Rollback();
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    msg = "采购订单审核失败";
                    db.Rollback();
                    return(0);
                }

                //sql = string.Format(@"update APS_ProductPurchaseMain set BillState=2 where PurchaseDocumentCode='{0}'", res.ProductPurchaseCode);
            }
        }