Unit of Measurements
        public async Task ReadItemAsync()
        {
            var expectedUom = new Uom().WithId(1001);
            var url         = "http://qtb3.com/a/b";
            HttpRequestMessage sentMessage = null;
            var httpResponseMessage        =
                new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("stringContent")
            };
            var httpService  = new Mock <IHttpReadService>(MockBehavior.Strict);
            var deserializer = new Mock <IContentDeserializer>(MockBehavior.Strict);
            var sequence     = new MockSequence();

            httpService
            .InSequence(sequence)
            .Setup(h => h.SendAsync(It.IsAny <HttpRequestMessage>()))
            .ReturnsAsync(httpResponseMessage)
            .Callback <HttpRequestMessage>((request) => sentMessage = request);
            deserializer
            .InSequence(sequence)
            .Setup(d => d.DeserializeAsync <Uom>(httpResponseMessage.Content))
            .ReturnsAsync(expectedUom);

            var uut       = new ReadItemServiceBuildRequest <Uom>(httpService.Object, deserializer.Object);
            var actualUom = await uut.ReadItemAsync(url);

            Assert.NotNull(sentMessage);
            Assert.AreEqual(url, sentMessage.RequestUri.ToString());
            Assert.AreEqual(sentMessage.Method, HttpMethod.Get);
            Assert.AreEqual(expectedUom, actualUom);
        }
Beispiel #2
0
        public async Task PostUomGoodClaimsList()
        {
            var connection = new SqliteConnection("DataSource=devicedb;Mode=Memory;Cache=Shared");

            try
            {
                new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData());
                var testWriteClient = GetTestWriteClient();
                var httpMessage     = GetRequestWithToken(HttpMethod.Post, $"{EndpointBase}/lrp/uoms", GoodClaimsList);
                var uomToPost       = new Uom(0, "NewName", "New Description");
                httpMessage.Content = GetWriteContent(uomToPost);
                var response = await testWriteClient.SendAsync(httpMessage);

                Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
                using (var context = GetPropertyContext(connection))
                {
                    var uoms = await context.Uoms.Where(u => u.Name == "NewName").ToListAsync();

                    Assert.NotNull(uoms);
                    Assert.AreEqual(1, uoms.Count);
                    Assert.True(UomEqual.CheckExceptId(uomToPost, uoms[0]));
                }
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #3
0
        public async Task PostInvalidUom()
        {
            var connection = new SqliteConnection("DataSource=devicedb;Mode=Memory;Cache=Shared");

            try
            {
                new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData());
                var testWriteClient = GetTestWriteClient();
                var httpMessage     = GetRequestWithToken(HttpMethod.Post, $"{EndpointBase}/lrp/uoms", GoodClaimsList);
                var uomToPost       = new Uom
                                      (
                    id: 0,
                    name: "N_0123456789_0123456789_0123456789_0123456789_0123456789",
                    description: "Some Description"
                                      );
                httpMessage.Content = GetWriteContent(uomToPost);
                var response = await testWriteClient.SendAsync(httpMessage);

                Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
                var jsonString = await response.Content.ReadAsStringAsync();

                var errorDictionary = JsonConvert.DeserializeObject <Dictionary <string, ReadOnlyCollection <string> > >(jsonString);
                Assert.AreEqual(1, errorDictionary.Count);
                errorDictionary.TryGetValue("Name", out var value);
                Assert.NotNull(value);
                Assert.AreEqual(1, value.Count);
                Assert.AreEqual("The field Name must be a string with a minimum length of 1 and a maximum length of 30.", value[0]);
            }
            finally
            {
                connection.Close();
            }
        }
        public void SaveItemAsync_Status500()
        {
            var url = "http://qtb3.com/a/b";
            var uom = new Uom();
            HttpRequestMessage sentMessage = null;
            var response   = new HttpResponseMessage(HttpStatusCode.InternalServerError);
            var sequence   = new MockSequence();
            var serializer = new Mock <IContentSerializer>();

            serializer
            .InSequence(sequence)
            .Setup(s => s.Serialize(It.IsAny <HttpRequestMessage>(), uom));
            var httpService = new Mock <IHttpWriteService>();

            httpService
            .InSequence(sequence)
            .Setup(h => h.SendAsync(It.IsAny <HttpRequestMessage>()))
            .ReturnsAsync(response)
            .Callback <HttpRequestMessage>((request) => sentMessage = request);
            var uut       = new SaveItemServiceBuildRequest <Uom>(httpService.Object, serializer.Object);
            var exception = Assert.ThrowsAsync <FailedRequestException>(
                async() => await uut.SaveItemAsync(url, uom)
                );

            Assert.AreEqual(HttpStatusCode.InternalServerError, exception.StatusCode);
            Assert.AreEqual(HttpMethod.Post, sentMessage.Method);
            Assert.AreEqual(url, sentMessage.RequestUri.ToString());
        }
Beispiel #5
0
        public IHttpActionResult Update(Uom uom)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var IsNotDuplicate = _uomService.Update(uom);
                if (IsNotDuplicate == true)
                {
                    Log.Info($"{typeof(UomController).FullName}||{UserEnvironment}||Update record successful.");
                    return(Content(HttpStatusCode.OK, "Uom updated successfully"));
                }
                else
                {
                    Log.Info($"{typeof(UomController).FullName}||{UserEnvironment}||Update record not successful, Uom Code is duplicate.");
                    return(Content(HttpStatusCode.Forbidden, "Uom Code is Duplicate"));
                }
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Beispiel #6
0
        public IHttpActionResult Add(Uom model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var retId = _uomService.Add(model);

                if (retId == 0)
                {
                    Log.Info($"{typeof(UomController).FullName}||{UserEnvironment}||Add record not successful, Uom Code is duplicate.");
                    return(Content(HttpStatusCode.Forbidden, "Uom Code is Duplicate"));
                }
                else
                {
                    var response = Request.CreateResponse(HttpStatusCode.Created);
                    var test     = JsonConvert.SerializeObject(new
                    {
                        id      = retId,
                        message = "Unit of measure added"
                    });
                    Log.Info($"{typeof(UomController).FullName}||{UserEnvironment}||Add record successful.");
                    response.Content = new StringContent(test, Encoding.UTF8, "appliation/json");
                    return(ResponseMessage(response));
                }
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Beispiel #7
0
        public long Add(Uom obj)
        {
            if (IsDuplicate(obj.Code, obj.Id, obj.CustomerId) == false)
            {
                return(_uomRepository.Add(obj));
            }
            else
            {
                Expression <Func <Uom, bool> > res = x => x.Code == obj.Code && x.CustomerId == obj.CustomerId && x.IsActive == false;
                var model = _uomRepository.Get(res);

                if (model != null)
                {
                    obj.Id       = model.Id;
                    obj.IsActive = true;

                    _uomRepository.Detach(model);

                    _uomRepository.Update(obj);
                    return(obj.Id);
                }
                else
                {
                    return(0);
                }
            }
        }
    protected void btnRemove_Click(object sender, EventArgs e)
    {
        try
        {
            int    id  = -1;
            string _id = Request.QueryString["id"].ToString();
            int.TryParse(_id, out id);
            int userId = CurrentEnvironment.LoggedUser.Id;

            int i = Uom.Delete(id);

            if (i > 0)
            {
                lblSuccess.Visible = true;
                lblWarning.Visible = false;
                lblError.Visible   = false;

                gvUom.DataSource = Uom.GetUomList();
                gvUom.DataBind();
                ClearControls(this);
            }
            else
            {
                lblSuccess.Visible = false;
                lblWarning.Visible = true;
                lblError.Visible   = false;
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
Beispiel #9
0
    protected void ODS_Uom_Inserting(object source, ObjectDataSourceMethodEventArgs e)
    {
        Uom uom = (Uom)e.InputParameters[0];

        uom.Description = uom.Description.Trim();
        uom.Name        = uom.Name.Trim();

        if (uom.Code == null || uom.Code.Trim() == string.Empty)
        {
            ShowWarningMessage("MasterData.Uom.Code.Empty", "");
            e.Cancel = true;
            return;
        }
        else
        {
            uom.Code = uom.Code.Trim();
        }

        if (TheUomMgr.LoadUom(uom.Code) == null)
        {
            ShowSuccessMessage("MasterData.Uom.AddUom.Successfully", uom.Code);
        }
        else
        {
            e.Cancel = true;
            ShowErrorMessage("MasterData.Uom.AddUom.Error", uom.Code);
        }
    }
Beispiel #10
0
        public async Task PostItem()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            try
            {
                new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData());
                using (var context = GetPropertyContext(connection))
                {
                    var uomRepository = new UomWriteRepository(context);
                    var newUom        = new Uom(0, "Cubits", "The description");
                    var postedItem    = await uomRepository.PostAsync(newUom);

                    Assert.NotNull(postedItem);
                    Assert.True(UomEqual.Check(newUom, postedItem));

                    var uoms = await context.Uoms.ToListAsync();

                    Assert.NotNull(uoms);
                    Assert.AreEqual(UomTestData.GetUomsArray().Length + 1, uoms.Count);

                    var resultUoms = await context.Uoms.Where(u => u.Name == "Cubits").ToListAsync();

                    Assert.NotNull(resultUoms);
                    Assert.AreEqual(1, resultUoms.Count);
                    Assert.True(UomEqual.Check(postedItem, resultUoms[0]));
                }
            }
            finally
            {
                connection.Close();
            }
        }
 public static bool Check(Uom expected, Uom actual)
 {
     return
         (expected.Id == actual.Id &&
          expected.Name == actual.Name &&
          expected.Description == actual.Description);
 }
        public void InvalidTwoErrorsInDictionary()
        {
            var uom = new Uom();

            new Validator().Validate(uom, out var errorDictionary);
            Assert.AreEqual(2, errorDictionary.Count);
        }
Beispiel #13
0
        public Uom BuildFromRow(DataRow row)
        {
            var returnRecord = Uom.BuildUomFromRow(row);

            returnRecord = this.BuildExtraFromRow <Uom>(returnRecord, row);
            return(returnRecord);
        }
Beispiel #14
0
        public IActionResult UomDelete(int uomSk)
        {
            System.Console.WriteLine("-----------------------------------UomDelete--------------------------------------");
            if (HttpContext.Session.GetInt32("LoggedIn") != 1)
            {
                return(RedirectToAction("Login", "Login"));
            }

            bool isDeleteOk = true;
            Uom  uomInDb    = uomHelper.GetUomBySk(uomSk);

            if (uomInDb == null)
            {
                // Uom not found in Db.  This is an exception...
                isDeleteOk = false;
            }

            if (isDeleteOk)
            {
                System.Console.WriteLine("-----------------------------------UomDelete-IsDeleteId=true-------------------------------------");

                // Delete Uom
                dbContext.Uom.Remove(uomInDb);
                dbContext.SaveChanges();
            }
            else
            {
                System.Console.WriteLine("-----------------------------------UomDelete-IsDeleteId=false-------------------------------------");
            }
            // return Json(true, JsonRequestBehavior.AllowGet);
            return(RedirectToAction("UomNewListView"));
        }
        public void InvalidOneErrorInDictionary()
        {
            var uom = new Uom(0, "", "AllOfIt");

            Assert.IsFalse(new Validator().Validate(uom, out var errorDictionary));
            Assert.AreEqual(1, errorDictionary.Count);
        }
        public async Task SaveItemAsync_GoodPost()
        {
            var url = "http://qtb3.com/a/b";
            var uom = new Uom();
            HttpRequestMessage sentMessage = null;
            var response   = new HttpResponseMessage(HttpStatusCode.OK);
            var sequence   = new MockSequence();
            var serializer = new Mock <IContentSerializer>();

            serializer
            .InSequence(sequence)
            .Setup(s => s.Serialize(It.IsAny <HttpRequestMessage>(), uom));
            var httpService = new Mock <IHttpWriteService>();

            httpService
            .InSequence(sequence)
            .Setup(h => h.SendAsync(It.IsAny <HttpRequestMessage>()))
            .ReturnsAsync(response)
            .Callback <HttpRequestMessage>((request) => sentMessage = request);
            var uut = new SaveItemServiceBuildRequest <Uom>(httpService.Object, serializer.Object);
            await uut.SaveItemAsync(url, uom);

            Assert.AreEqual(HttpMethod.Post, sentMessage.Method);
            Assert.AreEqual(url, sentMessage.RequestUri.ToString());
        }
Beispiel #17
0
        public async Task <IActionResult> AddorEdit([Bind("UomId,Name,Code,Description,Status,CompanyID,CreatedOn,CreatedBy,ModifiedBy,ModifiedOn,IP")] Uom uom)
        {
            if (ModelState.IsValid)
            {
                if (uom.UomId == 0)
                {
                    uom.Status = AppConstant.Active;
                    // department.CreatedBy = userId;
                    uom.CreatedOn  = System.DateTime.Now;
                    uom.ModifiedOn = System.DateTime.Now;
                    uom.IP         = ipmodel.GetIp();
                    uom.CompanyID  = AppConstant.CompanyID;
                    context.Add(uom);
                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    uom.Status     = AppConstant.Active;
                    uom.ModifiedOn = System.DateTime.Now;
                    uom.IP         = ipmodel.GetIp();
                    uom.CompanyID  = AppConstant.CompanyID;
                    context.Update(uom);
                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(uom));
        }
Beispiel #18
0
        public async Task PutItem()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            try
            {
                new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData());
                using (var context = GetPropertyContext(connection))
                {
                    var uomRepository = new UomWriteRepository(context);
                    var itemToPut     = new Uom(3, "cubits", "The description");
                    await uomRepository.PutAsync(itemToPut);

                    var uoms = await context.Uoms.OrderBy(u => u.Name).ToListAsync();

                    Assert.NotNull(uoms);
                    Assert.AreEqual(UomTestData.GetUomsArray().Length, uoms.Count);
                    Assert.True(UomEqual.Check(itemToPut, uoms[0]));
                }
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #19
0
        public async Task SaveItemAsync_SaveServiceThrows_BadRequest_NameError()
        {
            var initialUom      = new Uom(1001, "in", "inch");
            var savedUom        = new Uom(1001, "", "inchy");
            var errorDictionary = new Dictionary <string, ReadOnlyCollection <string> >
            {
                ["Name"] = new ReadOnlyCollection <string>(new List <string> {
                    "Error1", "Error2"
                })
            };
            var exception = new BadRequestHttpException(errorDictionary);
            UomItemViewModel viewModel = new ViewModelTestBuilder <Uom>()
                                         .Then_ReadItemService_ReadItemAsync(initialUom)
                                         .Then_SaveItemService_SaveItemAsync_Throws(savedUom, UomEqual.Check, exception);
            await viewModel.GetItemAsync(1001);

            viewModel.Name        = "";
            viewModel.Description = "inchy";
            Assert.ThrowsAsync <BadRequestHttpException>
            (
                async() => await viewModel.SaveAsync()
            );
            Assert.True(UomItemViewModelEqual.Check
                        (
                            expected: savedUom,
                            expectedNameErrors: "Error1 Error2",
                            expectedDescriptionErrors: null,
                            actual: viewModel
                        ));
        }
Beispiel #20
0
        public async Task SaveItemAsync_SaveServiceThrows_EmptyBadRequest()
        {
            var initialUom      = new Uom(1001, "in", "inch");
            var savedUom        = new Uom(1001, "in.", "");
            var errorDictionary = new Dictionary <string, ReadOnlyCollection <string> >
            {
                ["Description"] = new ReadOnlyCollection <string>(new List <string> {
                    ""
                })
            };
            var exception = new BadRequestHttpException(errorDictionary);
            UomItemViewModel viewModel = new ViewModelTestBuilder <Uom>()
                                         .Then_ReadItemService_ReadItemAsync(initialUom)
                                         .Then_SaveItemService_SaveItemAsync_Throws(savedUom, UomEqual.Check, exception);
            await viewModel.GetItemAsync(1001);

            viewModel.Name        = "in.";
            viewModel.Description = "";
            var actualException = Assert.ThrowsAsync <Exception>
                                  (
                async() => await viewModel.SaveAsync()
                                  );

            Assert.AreEqual(LrpConstants.NotSavedValidationProblem, actualException.Message);
        }
 protected override void OnAddToolBarItem()
 {
     _activeUom = new Uom {
         IsActive = true
     };
     FillData(_activeUom);
     IsAdding();
 }
 public GarmentSewingOutDetailDto(GarmentSewingOutDetail garmentSewingOutDetail)
 {
     Id = garmentSewingOutDetail.Identity;
     SewingOutItemId = garmentSewingOutDetail.SewingOutItemId;
     Size            = new SizeValueObject(garmentSewingOutDetail.SizeId.Value, garmentSewingOutDetail.SizeName);
     Quantity        = garmentSewingOutDetail.Quantity;
     Uom             = new Uom(garmentSewingOutDetail.UomId.Value, garmentSewingOutDetail.UomUnit);
 }
Beispiel #23
0
        public async Task <IHttpActionResult> Put([FromODataUri] System.Guid key, [FromBody] Uom entity)
        {
            logger.Trace("Call UomController Put");

            var record = await uomRepository.UpdateAsync(entity);

            return(Updated(record));
        }
Beispiel #24
0
        public async Task <IHttpActionResult> Post([FromBody] Uom entity)
        {
            logger.Trace("Call UomController Post");

            var record = await uomRepository.CreateAsync(entity);

            return(Created(record));
        }
        public IHttpActionResult Post([FromBody] Uom entity)
        {
            logger.Trace("Call UomController Post");

            var record = uomRepository.Create(entity);

            return(Created(record));
        }
Beispiel #26
0
        public ActionResult DeleteConfirmed(int id)
        {
            Uom uom = db.Uoms.Find(id);

            db.Uoms.Remove(uom);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 /// <summary>
 /// add or update uom
 /// </summary>
 /// <param name="uom"></param>
 /// <returns></returns>
 public async Task <int> AddOrUpdate(Uom uom)
 {
     using (DatanetCMSWebEntities context = new DatanetCMSWebEntities())
     {
         context.Uoms.AddOrUpdate(uom);
         return(await context.SaveChangesAsync());
     }
 }
        public async Task Delete()
        {
            Uom Uom = await DataUtil.GetTestDataAsync();

            UomViewModel VM       = Service.MapToViewModel(Uom);
            var          response = await this.Client.DeleteAsync(string.Concat(URI, "/", VM.Id));

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
        }
 /// <summary>
 /// soft delete uom
 /// </summary>
 /// <param name="uom"></param>
 /// <returns></returns>
 public async Task <int> Delete(Uom uom)
 {
     using (DatanetCMSWebEntities context = new DatanetCMSWebEntities())
     {
         uom.ExpireTime = DateTime.UtcNow;
         context.Uoms.AddOrUpdate(uom);
         return(await context.SaveChangesAsync());
     }
 }
        public async Task Update()
        {
            Uom Uom = await DataUtil.GetTestDataAsync();

            UomViewModel VM       = Service.MapToViewModel(Uom);
            var          response = await this.Client.PutAsync(string.Concat(URI, "/", VM.Id), new StringContent(JsonConvert.SerializeObject(VM).ToString(), Encoding.UTF8, "application/json"));

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
        }
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            string key = dssImportHistory[1]; //代码

            //计量单位
            if (key.Trim().ToUpper() == "PT_UM")
            {
                Uom uom = new Uom();
                uom.Code = dssImportHistory[2];//计量单位
                if (isUpdate)
                {
                    uom.Name = dssImportHistory[3];//名称
                    uom.Description = dssImportHistory[3];//描述
                }
                return uom;
            }
            else
            {
                throw new BusinessErrorException("Common.Business.Error.EntityNotExist", key);
            }
        }
Beispiel #32
0
        public IList<HuOdd> GetHuOdd(Item item, decimal unitCount, Uom uom, Location locFrom, Location locTo, string status)
        {
            DetachedCriteria criteria = DetachedCriteria.For<HuOdd>();
            criteria.CreateAlias("OrderDetail", "od");
            criteria.CreateAlias("od.Item", "item");
            criteria.CreateAlias("od.Uom", "uom");
            criteria.CreateAlias("LocationLotDetail", "lld");
            criteria.CreateAlias("lld.Location", "locTo");

            criteria.Add(Expression.Eq("item.Code", item.Code));
            criteria.Add(Expression.Eq("od.UnitCount", unitCount));
            criteria.Add(Expression.Eq("uom.Code", uom.Code));
            criteria.Add(Expression.Eq("locTo.Code", locTo.Code));
            criteria.Add(Expression.Eq("Status", status));

            criteria.AddOrder(Order.Asc("CreateDate"));

            IList<HuOdd> huOddList = this.criteriaMgr.FindAll<HuOdd>(criteria);

            if (huOddList != null && huOddList.Count > 0)
            {
                //������Դ��λ
                IList<HuOdd> filteredHuOddList = new List<HuOdd>();

                foreach (HuOdd huOdd in huOddList)
                {
                    if (LocationHelper.IsLocationEqual(huOdd.OrderDetail.DefaultLocationFrom, locFrom))
                    {
                        filteredHuOddList.Add(huOdd);
                    }
                }

                return filteredHuOddList;
            }

            return null;
        }
        public decimal ConvertUomQty(string itemCode, Uom sourceUom, decimal sourceQty, Uom targetUom)
        {
            UomConversion uomConversion = this.LoadUomConversion(itemCode, sourceUom.Code, targetUom.Code);
            if (uomConversion != null)
            {
                return (sourceQty * uomConversion.BaseQty / uomConversion.AlterQty);
            }
            else
            {
                uomConversion = this.LoadUomConversion(itemCode, targetUom.Code, sourceUom.Code);
                if (uomConversion != null)
                {
                    return (sourceQty * uomConversion.AlterQty / uomConversion.BaseQty);
                }
                else
                {
                    uomConversion = this.LoadUomConversion(null, sourceUom.Code, targetUom.Code);
                    if (uomConversion != null)
                    {
                        return (sourceQty * uomConversion.BaseQty / uomConversion.AlterQty);
                    }
                    else
                    {
                        uomConversion = this.LoadUomConversion(null, targetUom.Code, sourceUom.Code);
                        if (uomConversion != null)
                        {
                            return (sourceQty * uomConversion.AlterQty / uomConversion.BaseQty);
                        }
                        else
                        {
                            throw new BusinessErrorException("UomConversion.Error.NotFound", itemCode, sourceUom.Code, targetUom.Code);
                        }
                    }

                }
            }
        }
Beispiel #34
0
        private Hu ResolveHu(string antiResolveHuOption, string huId, Uom uom, Party manufactureParty)
        {
            Hu hu = null;
            if (antiResolveHuOption == BusinessConstants.CODE_MASTER_ANTI_RESOLVE_HU_VALUE_NOT_RESOLVE
                || antiResolveHuOption == null || antiResolveHuOption.Trim() == string.Empty)
            {
                hu = huMgr.CheckAndLoadHu(huId);
            }
            else
            {
                #region 自动解析HuId,生成Hu
                hu = huMgr.LoadHu(huId);

                if (hu == null)
                {
                    hu = this.ResolveAndCreateHu(huId, uom, manufactureParty);
                }
                #endregion
            }

            return hu;
        }
        public OrderLocationTransaction GenerateOrderLocationTransaction(
            OrderDetail orderDetail, Item item, BomDetail bomDetail, Uom uom, int operation,
            string ioType, string transactionType, decimal unitQty, Location loc,
            bool isShipScanHu, int? huLotSize, bool needPrint, string backFlushMethod, string itemVersion, Location rejectLocation)
        {
            OrderLocationTransaction orderLocationTransaction = new OrderLocationTransaction();
            orderLocationTransaction.OrderDetail = orderDetail;
            orderLocationTransaction.Item = item;
            orderLocationTransaction.OrderedQty = unitQty * orderDetail.OrderedQty;   //根据unitQty计算实际的订单量
            orderLocationTransaction.Uom = uom;
            orderLocationTransaction.Operation = operation;
            orderLocationTransaction.IOType = ioType;
            orderLocationTransaction.TransactionType = transactionType;
            orderLocationTransaction.UnitQty = unitQty;
            orderLocationTransaction.Location = loc;
            orderLocationTransaction.RejectLocation = rejectLocation;
            orderLocationTransaction.IsShipScanHu = isShipScanHu;  //仅生产有效
            orderLocationTransaction.BackFlushMethod = backFlushMethod;  //生产回冲物料方式
            orderLocationTransaction.ItemVersion = itemVersion;
            if (huLotSize.HasValue)
            {
                orderLocationTransaction.HuLotSize = int.Parse(Math.Round(huLotSize.Value * unitQty).ToString("#"));
            }
            orderLocationTransaction.NeedPrint = needPrint;
            orderLocationTransaction.IsAssemble = true;   //默认都安装
            if (bomDetail != null)
            {
                orderLocationTransaction.BomDetail = bomDetail;
                if (bomDetail.StructureType == BusinessConstants.CODE_MASTER_BOM_DETAIL_TYPE_VALUE_O)
                {
                    //如果是选装件,取bomDetail.Priority作为选装件的默认值,0代表默认不装,1代表默认安装
                    orderLocationTransaction.IsAssemble = (bomDetail.Priority != 0);
                }
            }

            if (uom.Code != item.Uom.Code)   //和库存单位不一致,需要进行转化
            {
                //单位转化,更改UnitQty和OrderedQty值
                orderLocationTransaction.Uom = item.Uom;
                orderLocationTransaction.UnitQty = this.uomConversionMgrE.ConvertUomQty(item, uom, unitQty, item.Uom);
                orderLocationTransaction.OrderedQty = this.uomConversionMgrE.ConvertUomQty(item, uom, orderLocationTransaction.OrderedQty, item.Uom);

                if (orderLocationTransaction.HuLotSize.HasValue)
                {
                    orderLocationTransaction.HuLotSize = int.Parse(Math.Round(orderLocationTransaction.HuLotSize.Value * orderLocationTransaction.UnitQty).ToString("#"));
                }
            }

            orderDetail.AddOrderLocationTransaction(orderLocationTransaction);
            return orderLocationTransaction;
        }
 public decimal ConvertUomQty(Item item, Uom sourceUom, decimal sourceQty, Uom targetUom)
 {
     return ConvertUomQty(item.Code, sourceUom, sourceQty, targetUom);
 }
 public decimal ConvertUomQty(string itemCode, Uom sourceUom, decimal sourceQty, Uom targetUom)
 {
     return ConvertUomQty(itemCode, sourceUom.Code, sourceQty, targetUom.Code);
 }
        public OrderLocationTransaction GenerateOrderLocationTransaction(
            OrderDetail orderDetail, Item item, BomDetail bomDetail, Uom uom, int operation,
            string ioType, string transactionType, decimal unitQty, Location loc,
            bool isShipScanHu, int? huLotSize, bool needPrint, string backFlushMethod, string itemVersion, Location rejectLocation)
        {
            OrderLocationTransaction orderLocationTransaction = new OrderLocationTransaction();
            orderLocationTransaction.OrderDetail = orderDetail;
            orderLocationTransaction.Item = item;
            orderLocationTransaction.OrderedQty = unitQty * orderDetail.OrderedQty;   //����unitQty����ʵ�ʵĶ�����
            orderLocationTransaction.Uom = uom;
            orderLocationTransaction.Operation = operation;
            orderLocationTransaction.IOType = ioType;
            orderLocationTransaction.TransactionType = transactionType;
            orderLocationTransaction.UnitQty = unitQty;
            orderLocationTransaction.Location = loc;
            orderLocationTransaction.RejectLocation = rejectLocation;
            orderLocationTransaction.IsShipScanHu = isShipScanHu;  //��������Ч
            orderLocationTransaction.BackFlushMethod = backFlushMethod;  //�����س����Ϸ�ʽ
            orderLocationTransaction.ItemVersion = itemVersion;
            if (huLotSize.HasValue)
            {
                orderLocationTransaction.HuLotSize = int.Parse(Math.Round(huLotSize.Value * unitQty).ToString("0.#########"));

            }
            orderLocationTransaction.NeedPrint = needPrint;
            orderLocationTransaction.IsAssemble = true;   //Ĭ�϶���װ
            if (bomDetail != null)
            {
                orderLocationTransaction.BomDetail = bomDetail;
                if (bomDetail.StructureType == BusinessConstants.CODE_MASTER_BOM_DETAIL_TYPE_VALUE_O)
                {
                    //�����ѡװ����ȡbomDetail.Priority��Ϊѡװ����Ĭ��ֵ��0����Ĭ�ϲ�װ��1����Ĭ�ϰ�װ
                    orderLocationTransaction.IsAssemble = (bomDetail.Priority != 0);
                }
                #region ȡ��λ�ͻ���

                DetachedCriteria criteria = DetachedCriteria.For(typeof(Flow));
                criteria.Add(Expression.Eq("Code", orderDetail.OrderHead.Flow));

                IList<Flow> flowList = criteriaMgr.FindAll<Flow>(criteria);
                if (flowList != null && flowList.Count > 0)
                {
                    if (flowList[0].Routing != null)
                    {
                        #region ��routingdet
                        DetachedCriteria rcriteria = DetachedCriteria.For(typeof(RoutingDetail));
                        rcriteria.Add(Expression.Eq("Routing.Code", flowList[0].Routing.Code));
                        rcriteria.Add(Expression.Eq("Operation", bomDetail.Operation));

                        IList<RoutingDetail> routingDetailList = criteriaMgr.FindAll<RoutingDetail>(rcriteria);
                        if (routingDetailList != null && routingDetailList.Count > 0)
                        {
                            if (routingDetailList[0].TagNo != null && routingDetailList[0].TagNo != string.Empty)
                            {
                                orderLocationTransaction.TagNo = routingDetailList[0].TagNo;

                                #region �Ҷ�Ӧ�Ĺ�λ����
                                DetachedCriteria scriteria = DetachedCriteria.For(typeof(ShelfItem));
                                scriteria.CreateAlias("Shelf", "s");
                                scriteria.Add(Expression.Eq("s.TagNo", orderLocationTransaction.TagNo));
                                scriteria.Add(Expression.Eq("IsActive", true));
                                scriteria.Add(Expression.Eq("Item.Code", orderLocationTransaction.Item.Code));
                                IList<ShelfItem> shelfItemDetailList = criteriaMgr.FindAll<ShelfItem>(scriteria);
                                if (shelfItemDetailList != null && shelfItemDetailList.Count > 0)
                                {
                                    orderLocationTransaction.Shelf = shelfItemDetailList[0].Shelf.Code;
                                }
                                #endregion
                            }
                        }
                        #endregion
                    }
                }
                #endregion
            }
            //����
            orderLocationTransaction.Cartons = Convert.ToInt32(orderLocationTransaction.OrderedQty / orderLocationTransaction.Item.UnitCount);

            if (uom.Code != item.Uom.Code)   //�Ϳ�浥λ��һ�£���Ҫ����ת��
            {
                //��λת��������UnitQty��OrderedQtyֵ
                orderLocationTransaction.Uom = item.Uom;
                orderLocationTransaction.UnitQty = this.uomConversionMgr.ConvertUomQty(item, uom, unitQty, item.Uom);
                orderLocationTransaction.OrderedQty = this.uomConversionMgr.ConvertUomQty(item, uom, orderLocationTransaction.OrderedQty, item.Uom);

                if (orderLocationTransaction.HuLotSize.HasValue)
                {
                    orderLocationTransaction.HuLotSize = int.Parse(Math.Round(orderLocationTransaction.HuLotSize.Value * orderLocationTransaction.UnitQty).ToString("#"));
                }
            }

            orderDetail.AddOrderLocationTransaction(orderLocationTransaction);
            return orderLocationTransaction;
        }
Beispiel #39
0
        public IList<Hu> CreateHu(Item item, decimal qty, string lotNo, Uom uom, decimal unitCount, int? huLotSize,
            string orderNo, string recNo, DateTime? manufactureDate, Party manufactureParty, string qualityLevel, User user, Object obj, string shiftCode, string itemVersion, string idMark,string customerItemCode)
        {
            IList<Hu> huList = new List<Hu>();

            #region 根据Hu批量创建Hu
            decimal remainHuQty = qty;                                        //剩余量
            decimal currentHuQty = GetNextHuQty(ref remainHuQty, huLotSize);  //本次量
            DateTime dateTimeNow = DateTime.Now;

            while (currentHuQty > 0)
            {
                #region 创建Hu
                Hu hu = new Hu();
                #region HuId生成
                if (obj.GetType() == typeof(FlowDetail))
                {
                    FlowDetail flowDetail = (FlowDetail)obj;
                    if (flowDetail.Flow.Type != BusinessConstants.CODE_MASTER_FLOW_TYPE_VALUE_PRODUCTION)
                    {
                        lotNo = lotNo != null ? lotNo : LotNoHelper.GenerateLotNo();
                        hu.HuId = this.numberControlMgrE.GenerateRMHuId(flowDetail, lotNo, currentHuQty, idMark);
                    }
                    else
                    {
                        if (shiftCode != null && shiftCode.Trim().Length != 0)
                        {
                            lotNo = lotNo != null ? lotNo : LotNoHelper.GenerateLotNo();
                            hu.HuId = this.numberControlMgrE.GenerateFGHuId(flowDetail, shiftCode, currentHuQty, idMark);
                        }
                        else
                        {
                            throw new TechnicalException("ShiftCode can't be null when create fg huId by flowdetail");
                        }
                    }
                }
                else if (obj.GetType() == typeof(OrderDetail))
                {
                    OrderDetail orderDetail = (OrderDetail)obj;
                    if (orderDetail.OrderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                    {
                        lotNo = lotNo != null ? lotNo : LotNoHelper.GenerateLotNo(orderDetail.OrderHead.WindowTime);
                        hu.HuId = this.numberControlMgrE.GenerateRMHuId(orderDetail, lotNo, currentHuQty, idMark);
                    }
                    else
                    {
                        lotNo = lotNo != null ? lotNo : LotNoHelper.GenerateLotNo(orderDetail.OrderHead.WindowTime);
                        hu.HuId = this.numberControlMgrE.GenerateFGHuId(orderDetail, currentHuQty, idMark);
                    }
                }
                else if (obj.GetType() == typeof(InProcessLocationDetail))
                {
                    InProcessLocationDetail inProcessLocationDetail = (InProcessLocationDetail)obj;
                    if (inProcessLocationDetail.OrderLocationTransaction.OrderDetail.OrderHead.Type
                        != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                    {
                        lotNo = lotNo != null ? lotNo : LotNoHelper.GenerateLotNo();
                        hu.HuId = this.numberControlMgrE.GenerateRMHuId(inProcessLocationDetail, lotNo, currentHuQty);
                    }
                    else
                    {
                        throw new TechnicalException("Can't create fg huid by InProcessLocationDetail");
                    }
                }
                else if (obj.GetType() == typeof(ReceiptDetail))
                {
                    ReceiptDetail receiptDetail = (ReceiptDetail)obj;
                    if (receiptDetail.OrderLocationTransaction.OrderDetail.OrderHead.Type
                        != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                    {
                        lotNo = lotNo != null ? lotNo : LotNoHelper.GenerateLotNo();
                        hu.HuId = this.numberControlMgrE.GenerateRMHuId(receiptDetail, lotNo, currentHuQty);
                    }
                    else
                    {
                        lotNo = lotNo != null ? lotNo : LotNoHelper.GenerateLotNo();
                        hu.HuId = this.numberControlMgrE.GenerateFGHuId(receiptDetail, currentHuQty);
                    }
                }
                else
                {
                    throw new TechnicalException("Parameter obj only accept type: FlowDetail, OrderDetail, InProcessLocationDetail, ReceiptDetail");
                }
                #endregion
                hu.Item = item;
                hu.OrderNo = orderNo;
                hu.ReceiptNo = recNo;
                hu.Uom = uom;   //用订单单位
                hu.UnitCount = unitCount;
                #region 单位用量
                //如果是OrderDetail,应该等于inOrderLocationTransaction.UnitQty,现在暂时直接用单位换算
                if (item.Uom.Code != uom.Code)
                {
                    hu.UnitQty = this.uomConversionMgrE.ConvertUomQty(item, uom, 1, item.Uom);   //单位用量
                }
                else
                {
                    hu.UnitQty = 1;
                }
                #endregion
                hu.QualityLevel = qualityLevel;
                hu.Qty = currentHuQty;
                hu.LotNo = lotNo;
                hu.ManufactureDate = manufactureDate.HasValue ? manufactureDate.Value : LotNoHelper.ResolveLotNo(hu.LotNo);
                hu.ManufactureParty = manufactureParty;
                hu.CreateUser = user;
                hu.CreateDate = dateTimeNow;
                hu.LotSize = huLotSize.HasValue ? huLotSize.Value : currentHuQty;
                hu.Version = itemVersion;
                hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_CREATE;
                hu.CustomerItemCode = customerItemCode;

                this.CreateHu(hu);
                #endregion

                huList.Add(hu);
                currentHuQty = GetNextHuQty(ref remainHuQty, huLotSize);
            }
            #endregion

            return huList;
        }
Beispiel #40
0
        private Hu ResolveAndCreateHu(string barCode, Uom uom, Party manufactureParty)
        {
            object[] result = ResolveBarCode(barCode);
            Item item = (Item)result[0];
            string supMark = (string)result[1];
            string lotNo = (string)result[2];
            decimal qty = (decimal)result[3];
            int seq = (int)result[4];
            DateTime manufactureDate = (DateTime)result[5];

            Hu hu = new Hu();
            hu.HuId = barCode;
            hu.Item = item;
            hu.Uom = uom;
            #region 单位用量
            if (item.Uom.Code != uom.Code)
            {
                hu.UnitQty = this.uomConversionMgr.ConvertUomQty(item, uom, 1, item.Uom);   //单位用量
            }
            else
            {
                hu.UnitQty = 1;
            }
            #endregion
            hu.QualityLevel = BusinessConstants.CODE_MASTER_ITEM_QUALITY_LEVEL_VALUE_1;
            hu.Qty = qty / hu.UnitQty;
            hu.UnitCount = qty;
            hu.LotNo = lotNo;
            hu.ManufactureDate = manufactureDate;
            hu.ManufactureParty = manufactureParty;
            hu.CreateUser = this.userMgr.GetMonitorUser();
            hu.CreateDate = DateTime.Now;
            hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_CREATE;
            hu.LotSize = hu.Qty;

            this.huMgr.CreateHu(hu);
            this.numberControlMgr.ReverseUpdateHuId(barCode);

            return hu;
        }
Beispiel #41
0
 public void CreateUom(Uom location)
 {
     UomMgr.CreateUom(location);
 }
Beispiel #42
0
 public void DeleteUom(Uom location)
 {
     UomMgr.DeleteUom(location);
 }
Beispiel #43
0
 public void UpdateUom(Uom location)
 {
     UomMgr.UpdateUom(location);
 }
Beispiel #44
0
 public virtual void CreateUom(Uom entity)
 {
     entityDao.CreateUom(entity);
 }
 public PriceListDetail GetLastestPriceListDetail(PriceList priceList, Item item, DateTime effectiveDate, Currency currency, Uom uom)
 {
     return GetLastestPriceListDetail(priceList.Code, item.Code, effectiveDate, currency.Code, uom.Code);
 }
Beispiel #46
0
 public virtual void DeleteUom(Uom entity)
 {
     entityDao.DeleteUom(entity);
 }
 public TransportPriceListDetail GetLastestTransportPriceListDetail(TransportPriceList priceList, Item item, DateTime effectiveDate, Currency currency, Uom uom, string priceListType, string billingMethod)
 {
     return GetLastestTransportPriceListDetail(priceList, item, effectiveDate, currency, uom, null, null, null, priceListType, billingMethod,null,null);
 }
        public TransportPriceListDetail GetLastestTransportPriceListDetail(TransportPriceList priceList, Item item, DateTime effectiveDate, Currency currency, Uom uom, string pricingMethod, TransportationAddress shipFrom, TransportationAddress shipTo, string priceListType, string billingMethod, string vehicleType, string transportMethod)
        {
            DetachedCriteria detachedCriteria = DetachedCriteria.For<TransportPriceListDetail>();
            detachedCriteria.Add(Expression.Eq("TransportPriceList.Code", priceList.Code));
            if (item != null )
            {
                detachedCriteria.Add(Expression.Eq("Item.Code", item.Code));
            }
            detachedCriteria.Add(Expression.Eq("Currency.Code", currency.Code));
            if (uom != null )
            {
                detachedCriteria.Add(Expression.Eq("Uom.Code", uom.Code));
            }
            detachedCriteria.Add(Expression.Le("StartDate", effectiveDate));
            detachedCriteria.Add(Expression.Or(Expression.Ge("EndDate", effectiveDate.Date), Expression.IsNull("EndDate")));

            if (pricingMethod != null && pricingMethod != string.Empty)
            {
                detachedCriteria.Add(Expression.Eq("PricingMethod", pricingMethod));
            }
            if (shipFrom != null)
            {
                detachedCriteria.Add(Expression.Eq("ShipFrom.Id", shipFrom.Id));
            }
            if (shipTo != null)
            {
                detachedCriteria.Add(Expression.Eq("ShipTo.Id", shipTo.Id));
            }

            if (billingMethod != null && billingMethod != string.Empty)
            {
                detachedCriteria.Add(Expression.Eq("BillingMethod", billingMethod));
            }

            if (vehicleType != null && vehicleType != string.Empty)
            {
                detachedCriteria.Add(Expression.Eq("VehicleType", vehicleType));
            }
            detachedCriteria.Add(Expression.Eq("Type", priceListType));

            if (transportMethod != null && transportMethod != string.Empty)
            {
                detachedCriteria.Add(Expression.Eq("TransportMethod", transportMethod));
            }

            detachedCriteria.AddOrder(Order.Desc("StartDate")); //��StartDate����ȡ���µļ۸�
            IList<TransportPriceListDetail> priceListDetailList = criteriaMgr.FindAll<TransportPriceListDetail>(detachedCriteria);
            if (priceListDetailList != null && priceListDetailList.Count > 0)
            {
                return priceListDetailList[0];
            }
            else
            {
                return null;
            }
        }
Beispiel #49
0
 public virtual void UpdateUom(Uom entity)
 {
     entityDao.UpdateUom(entity);
 }
        public TransportPriceListDetail GetLastestLadderStereTransportPriceListDetail(TransportPriceList priceList, Item item, DateTime effectiveDate, Currency currency, Uom uom, string pricingMethod, TransportationAddress shipFrom, TransportationAddress shipTo, string priceListType, string billingMethod, string vehicleType,decimal qty)
        {
            TransportPriceListDetail priceListDetail = null;
            DetachedCriteria detachedCriteria = DetachedCriteria.For<TransportPriceListDetail>();
            detachedCriteria.Add(Expression.Eq("TransportPriceList.Code", priceList.Code));
            if (item != null)
            {
                detachedCriteria.Add(Expression.Eq("Item.Code", item.Code));
            }
            detachedCriteria.Add(Expression.Eq("Currency.Code", currency.Code));
            if (uom != null)
            {
                detachedCriteria.Add(Expression.Eq("Uom.Code", uom.Code));
            }
            detachedCriteria.Add(Expression.Le("StartDate", effectiveDate));
            detachedCriteria.Add(Expression.Or(Expression.Ge("EndDate", effectiveDate.Date), Expression.IsNull("EndDate")));

            if (pricingMethod != null && pricingMethod != string.Empty)
            {
                detachedCriteria.Add(Expression.Eq("PricingMethod", pricingMethod));
            }
            if (shipFrom != null)
            {
                detachedCriteria.Add(Expression.Eq("ShipFrom.Id", shipFrom.Id));
            }
            if (shipTo != null)
            {
                detachedCriteria.Add(Expression.Eq("ShipTo.Id", shipTo.Id));
            }

            if (billingMethod != null && billingMethod != string.Empty)
            {
                detachedCriteria.Add(Expression.Eq("BillingMethod", billingMethod));
            }

            if (vehicleType != null && vehicleType != string.Empty)
            {
                detachedCriteria.Add(Expression.Eq("VehicleType", vehicleType));
            }
            detachedCriteria.Add(Expression.Eq("Type", priceListType));
            detachedCriteria.Add(Expression.IsNotNull("StartQty"));
               // detachedCriteria.Add(Expression.IsNotNull("EndQty"));

            detachedCriteria.AddOrder(Order.Desc("StartDate")); //��StartDate����ȡ���µļ۸�
            IList<TransportPriceListDetail> priceListDetailList = criteriaMgr.FindAll<TransportPriceListDetail>(detachedCriteria);
            if (priceListDetailList != null && priceListDetailList.Count > 0)
            {
                priceListDetail = priceListDetailList.Where(p => p.StartQty.Value < qty && (p.EndQty == null || p.EndQty.Value >= qty)).FirstOrDefault();

                if (priceListDetail == null)
                {
                    priceListDetail = priceListDetailList.OrderBy(p => p.StartQty.Value).FirstOrDefault();
                }
            }
               return priceListDetail;
        }