コード例 #1
0
        public void SaveAscmDeliBatSumAllDetail(AscmDeliBatSumAllDetail ascmDeliBatSumAllDetail)
        {
            try
            {
                if (ascmDeliBatSumAllDetail != null)
                {
                    #region 容器备料
                    List<AscmContainerDelivery> listAscmContainerDelivery = ascmDeliBatSumAllDetail.listAscmContainerDelivery;
                    List<AscmContainerDelivery> listAscmContainerDeliverySave = null;
                    List<AscmContainerDelivery> listAscmContainerDeliveryUpdate = null;
                    List<AscmContainerDelivery> listAscmContainerDeliveryDelete = null;
                    if (listAscmContainerDelivery != null)
                    {
                        listAscmContainerDeliverySave = new List<AscmContainerDelivery>();
                        listAscmContainerDeliveryUpdate = new List<AscmContainerDelivery>();
                        listAscmContainerDeliveryDelete = new List<AscmContainerDelivery>();

                        List<AscmContainerDelivery> _listAscmContainerDelivery = null;
                        string sql = "from AscmContainerDelivery where batSumMainId=" + ascmDeliBatSumAllDetail.sumMainId;
                        IList<AscmContainerDelivery> ilistAscmContainerDelivery = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmContainerDelivery>(sql);
                        if (ilistAscmContainerDelivery != null && ilistAscmContainerDelivery.Count > 0)
                            _listAscmContainerDelivery = YnBaseClass2.Helper.ConvertHelper.ConvertIListToList<AscmContainerDelivery>(ilistAscmContainerDelivery);
                        int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmContainerDelivery");

                        foreach (AscmContainerDelivery ascmContainerDelivery in listAscmContainerDelivery)
                        {
                            AscmContainerDelivery findAscmContainerDelivery = null;
                            if (_listAscmContainerDelivery != null)
                                findAscmContainerDelivery = _listAscmContainerDelivery.Find(P => P.id == ascmContainerDelivery.id);
                            if (findAscmContainerDelivery == null)
                            {
                                ascmContainerDelivery.id = ++maxId;
                                ascmContainerDelivery.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                ascmContainerDelivery.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                listAscmContainerDeliverySave.Add(ascmContainerDelivery);
                            }
                            else
                            {
                                findAscmContainerDelivery.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                findAscmContainerDelivery.quantity = ascmContainerDelivery.quantity;
                                listAscmContainerDeliveryUpdate.Add(findAscmContainerDelivery);
                            }
                        }
                        if (_listAscmContainerDelivery != null)
                        {
                            foreach (AscmContainerDelivery ascmContainerDelivery in _listAscmContainerDelivery)
                            {
                                AscmContainerDelivery findAscmContainerDelivery = listAscmContainerDelivery.Find(P => P.id == ascmContainerDelivery.id);
                                if (findAscmContainerDelivery == null)
                                    listAscmContainerDeliveryDelete.Add(ascmContainerDelivery);
                            }
                        }
                    }
                    #endregion

                    #region 托盘备料
                    List<AscmPalletDelivery> listAscmPalletDelivery = ascmDeliBatSumAllDetail.listAscmPalletDelivery;
                    List<AscmPalletDelivery> listAscmPalletDeliverySaveOrUpdate = null;
                    List<AscmPalletDelivery> listAscmPalletDeliveryDelete = null;
                    if (listAscmPalletDelivery != null)
                    {
                        listAscmPalletDeliverySaveOrUpdate = new List<AscmPalletDelivery>();
                        listAscmPalletDeliveryDelete = new List<AscmPalletDelivery>();

                        List<AscmPalletDelivery> _listAscmPalletDelivery = null;
                        string sql = "from AscmPalletDelivery where batSumMainId=" + ascmDeliBatSumAllDetail.sumMainId;
                        IList<AscmPalletDelivery> ilistAscmPalletDelivery = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmPalletDelivery>(sql);
                        if (ilistAscmPalletDelivery != null && ilistAscmPalletDelivery.Count > 0)
                            _listAscmPalletDelivery = YnBaseClass2.Helper.ConvertHelper.ConvertIListToList<AscmPalletDelivery>(ilistAscmPalletDelivery);
                        int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmPalletDelivery");
                        foreach (AscmPalletDelivery ascmPalletDelivery in listAscmPalletDelivery)
                        {
                            AscmPalletDelivery findAscmPalletDelivery = null;
                            if (_listAscmPalletDelivery != null)
                                findAscmPalletDelivery = _listAscmPalletDelivery.Find(P => P.id == ascmPalletDelivery.id);
                            //if (findAscmPalletDelivery == null)
                            //    ascmPalletDelivery.id = ++maxId;
                            //listAscmPalletDeliverySaveOrUpdate.Add(ascmPalletDelivery);
                            if (findAscmPalletDelivery == null)
                            {
                                ascmPalletDelivery.id = ++maxId;
                                ascmPalletDelivery.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                ascmPalletDelivery.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                listAscmPalletDeliverySaveOrUpdate.Add(ascmPalletDelivery);
                            }
                            else
                            {
                                findAscmPalletDelivery.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                findAscmPalletDelivery.quantity = findAscmPalletDelivery.quantity;
                                listAscmPalletDeliverySaveOrUpdate.Add(findAscmPalletDelivery);
                            }

                        }
                        if (_listAscmPalletDelivery != null)
                        {
                            foreach (AscmPalletDelivery ascmPalletDelivery in _listAscmPalletDelivery)
                            {
                                AscmPalletDelivery findAscmPalletDelivery = listAscmPalletDelivery.Find(P => P.id == ascmPalletDelivery.id);
                                if (findAscmPalletDelivery == null)
                                    listAscmPalletDeliveryDelete.Add(ascmPalletDelivery);
                            }
                        }
                    }
                    #endregion

                    using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
                    {
                        try
                        {
                            if (listAscmContainerDeliverySave != null)
                                YnDaoHelper.GetInstance().nHibernateHelper.SaveList(listAscmContainerDeliverySave);
                            if (listAscmContainerDeliveryUpdate != null)
                                YnDaoHelper.GetInstance().nHibernateHelper.UpdateList(listAscmContainerDeliveryUpdate);
                            if (listAscmContainerDeliveryDelete != null)
                                YnDaoHelper.GetInstance().nHibernateHelper.DeleteList(listAscmContainerDeliveryDelete);

                            if (listAscmPalletDeliverySaveOrUpdate != null)
                                YnDaoHelper.GetInstance().nHibernateHelper.SaveOrUpdateList(listAscmPalletDeliverySaveOrUpdate);
                            if (listAscmPalletDeliveryDelete != null)
                                YnDaoHelper.GetInstance().nHibernateHelper.DeleteList(listAscmPalletDeliveryDelete);

                            tx.Commit();//正确执行提交
                        }
                        catch (Exception ex)
                        {
                            tx.Rollback();//回滚
                            throw ex;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                YnBaseClass2.Helper.LogHelper.GetLog().Error("保存失败(Save AscmDeliBatSumAllDetail)", ex);
                throw ex;
            }
        }
コード例 #2
0
        public AscmDeliBatSumAllDetail GetAscmDeliBatSumAllDetail(int sumMainId)
        {
            AscmDeliBatSumAllDetail ascmDeliBatSumAllDetail = new AscmDeliBatSumAllDetail();
            try
            {
                string sql = "from AscmDeliBatSumDetail where mainId=" + sumMainId;
                IList<AscmDeliBatSumDetail> ilistAscmDeliBatSumDetail = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmDeliBatSumDetail>(sql);
                if (ilistAscmDeliBatSumDetail != null && ilistAscmDeliBatSumDetail.Count > 0)
                {
                    ascmDeliBatSumAllDetail.listAscmDeliBatSumDetail = ilistAscmDeliBatSumDetail.ToList();

                    sql = "from AscmContainerDelivery where batSumMainId=" + sumMainId;
                    IList<AscmContainerDelivery> ilistAscmContainerDelivery = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmContainerDelivery>(sql);
                    if (ilistAscmContainerDelivery != null)
                    {
                        ascmDeliBatSumAllDetail.listAscmContainerDelivery = ilistAscmContainerDelivery.ToList();
                    }

                    sql = "from AscmPalletDelivery where batSumMainId=" + sumMainId;
                    IList<AscmPalletDelivery> ilistAscmPalletDelivery = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmPalletDelivery>(sql);
                    if (ilistAscmPalletDelivery != null)
                    {
                        ascmDeliBatSumAllDetail.listAscmPalletDelivery = ilistAscmPalletDelivery.ToList();
                    }

                    sql = "select new AscmMaterialItem(a.id,a.docNumber,a.description) from AscmMaterialItem a,AscmDeliBatSumDetail b where a.id=b.materialId and b.mainId=" + sumMainId;
                    IList<AscmMaterialItem> ilistAscmMaterialItem = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmMaterialItem>(sql);
                    if (ilistAscmMaterialItem != null)
                    {
                        ascmDeliBatSumAllDetail.listAscmMaterialItem = ilistAscmMaterialItem.Distinct(new AscmMaterialItemComparer()).ToList();
                    }

                    sql = "select new AscmDeliveryOrderBatch(a,b.materialId) from AscmDeliveryOrderBatch a,AscmDeliBatSumDetail b where a.id=b.batchId and b.mainId=" + sumMainId;
                    IList<AscmDeliveryOrderBatch> ilistAscmDeliveryOrderBatch = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmDeliveryOrderBatch>(sql);
                    if (ilistAscmDeliveryOrderBatch != null)
                    {
                        ascmDeliBatSumAllDetail.listAscmDeliveryOrderBatch = ilistAscmDeliveryOrderBatch.ToList();
                    }

                    ascmDeliBatSumAllDetail.sumMainId = sumMainId;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ascmDeliBatSumAllDetail;
        }