public ProcessMsg CompleteStore(List<string> packageIds, string whouse, string posi)
        {
            using (TransactionScope trans = new TransactionScope())
            {
                using (IUnitOfWork unit = MSSqlHelper.DataContext())
                {
                    ProcessMsg msg = new ProcessMsg();
                    try
                    {
                        string trayId = "T" + DateTime.Now.ToString("yyyyMMddHHmmssfff");

                        ITraysRep tr = new TraysRep(unit);
                        ITrayItemRep tir = new TrayItemRep(unit);
                        ISinglePackageRep spr = new SinglePackageRep(unit);

                        Trays ts = new Trays()
                        {
                            trayId = trayId,
                            createTime = DateTime.Now,
                            warehouse = whouse,
                            position = posi,
                            status = (int)TrayStatus.Stored,
                            rowguid = Guid.NewGuid()
                        };

                        List<TrayItem> tis = new List<TrayItem>();
                        foreach (string pid in packageIds)
                        {
                            tis.Add(new TrayItem()
                            {
                                itemId = Guid.NewGuid(),
                                trayId = ts.trayId,
                                packageId = pid,
                                rowguid = Guid.NewGuid()
                            });
                        }
                        bool synced = false;
                        // sync container data
                        try
                        {
                            List<SinglePackage> singlePackages = spr.GetListByIds(packageIds);
                            synced = new ApiService().SyncStoreContainer(GenContainers(ts, singlePackages, GetWhouse()));

                        }
                        catch (ApiException ae)
                        {
                            msg.AddMessage(ReturnCode.Warning, ae.Message);
                            synced = false;
                        }
                        catch {
                            synced = false;
                        }
                        ts.sync = synced;

                        tr.AddSingle(ts);
                        tir.AddMuti(tis);
                        unit.Submit();
                        trans.Complete();
                        msg.result = true;
                        if (synced)
                        {
                            msg.AddMessage(ReturnCode.OK, ts.trayId);
                        }
                        else
                        {
                            msg.AddMessage(ReturnCode.OK, ts.trayId);
                            msg.AddMessage(ReturnCode.Warning, "托盘生成成功,但WMS同步失败,请检查网络,稍候重新同步!");
                        }
                    }
                    catch (Exception e)
                    {
                        msg.result = false;
                        msg.AddMessage(ReturnCode.Error, "错误:" + e.Message + "\n请联系程序管理员!");
                    }
                    finally
                    {
                        trans.Dispose();
                    }
                    return msg;
                }
            }
        }
 public ValidateMsg<SinglePackage> SingleCheckStore(string packageId)
 {
     using (IUnitOfWork unit = MSSqlHelper.DataContext())
     {
         ValidateMsg<SinglePackage> msg = new ValidateMsg<SinglePackage>() { Valid = true };
         try
         {
             ISinglePackageRep spr = new SinglePackageRep(unit);
             SinglePackage sp = spr.GetSingleById(packageId);
             msg.Target = sp;
             if (sp == null)
             {
                 msg.Valid = false;
                 msg.Message.Add("包装箱:" + packageId + " 不存在");
             }
             else
                 if (!PackageStatusHelper.CanStoredStatus(sp.status))
                 {
                     msg.Valid = false;
                     msg.Message.Add("包装箱:" + packageId + " 还未结束包装或标签为开箱标签!");
                 }
                 else
                     if (!spr.Valid(sp.packageID))
                     {
                         msg.Valid = false;
                         msg.Message.Add("包装箱:" + packageId + " 已经入库!");
                     }
         }
         catch (Exception e)
         {
             msg.Valid = false;
             msg.Message.Add("错误:" + e.Message);
         }
         return msg;
     }
 }