Example #1
0
        public async Task GetAllTimeCards_ShouldAddEventsToCreatedAttendances_WhenUpdatedWithEndOfWork()
        {
            var userId     = Guid.NewGuid();
            var timeCardId = Guid.NewGuid();

            var card = new TimeCard {
                Id = timeCardId, UserId = userId,
            };

            TheSession.Store(card);

            var date1  = DateTime.Now;
            var start1 = new GettingWorkStarted(attendanceId1, userId, date1);
            var end1   = new EndOfWork(attendanceId2, userId, date1.AddHours(1));
            var start2 = new GettingWorkStarted(attendanceId3, userId, date1.AddHours(2));
            var end2   = new EndOfWork(attendanceId4, userId, date1.AddHours(3));

            TheSession.Events.Append(timeCardId, start1, end1, start2, end2);
            TheSession.SaveChanges();

            var repo      = new TimeCardsRepository(TheStore);
            var timeCards = await repo.GetAllTimeCards(userId, default);

            timeCards.Should().HaveCount(1);
        }
Example #2
0
        public ActionResult Update(string counterPartyGroup, long counterPartyId, string cifCounterParty, int isInau)
        {
            TheSession.Remove(_strSectionProduct); //xóa section list product
            CPProductGetDetailViewModel input = new CPProductGetDetailViewModel();

            input.cifCounterParty   = cifCounterParty;
            input.counterPartyGroup = counterPartyGroup;
            input.counterPartyId    = counterPartyId;
            input.isInau            = isInau;
            input.userId            = RDAuthorize.UserId;
            var result = _cPProductService.getDetailCpProdCommis(input);

            #region
            CPProductViewModel model = new CPProductViewModel();
            List <CPProductImportProductModel>       productList   = new List <CPProductImportProductModel>();
            List <CPProductImportCommisionListModel> commisionList = new List <CPProductImportCommisionListModel>();
            List <AttachmentViewModel> fileList = new List <AttachmentViewModel>();

            if (result != null)
            {
                Library.TransferData(result, ref model);//main
            }

            if (result.fileList != null && result.fileList.Any())
            {
                Library.TransferData(result.fileList, ref fileList);
            }

            if (result.productList != null && result.productList.Any())
            {
                Library.TransferData(result.productList, ref productList);
                foreach (var item in result.productList)
                {
                    if (item.commisionList != null && item.commisionList.Any())
                    {
                        foreach (var item1 in item.commisionList)
                        {
                            CPProductImportCommisionListModel tempModel = new CPProductImportCommisionListModel();
                            Library.TransferData(item1, ref tempModel);
                            tempModel.SelectList  = productList;
                            tempModel.productCode = productList.SingleOrDefault(x => x.productId == tempModel.productId).productCode;
                            commisionList.Add(tempModel);
                        }
                    }
                }
            }
            model.commisionList = commisionList;
            model.productList   = productList;
            model.viewMode      = ViewModeCons.UPDATE;
            ViewBag.viewMode    = ViewModeCons.UPDATE;
            ViewBag.fileList    = fileList;
            #endregion
            return(View("Create", model));
        }
Example #3
0
        protected async Task InitAsync(CancellationToken token)
        {
            if (QueryOperation != null)
            {
                return;
            }

            var beforeQueryExecutedEventArgs = new BeforeQueryExecutedEventArgs(TheSession, this);

            TheSession.OnBeforeQueryExecutedInvoke(beforeQueryExecutedEventArgs);

            QueryOperation = InitializeQueryOperation();
            await ExecuteActualQueryAsync(token).ConfigureAwait(false);
        }
Example #4
0
        protected void InitSync()
        {
            if (QueryOperation != null)
            {
                return;
            }

            var beforeQueryExecutedEventArgs = new BeforeQueryExecutedEventArgs(TheSession, this);

            TheSession.OnBeforeQueryExecutedInvoke(beforeQueryExecutedEventArgs);

            QueryOperation = InitializeQueryOperation();
            ExecuteActualQuery();
        }
Example #5
0
        public ActionResult Create(string counterPartyGroup, long counterPartyId, string cifCounterParty)
        {
            CounterPartyGetDetailModel input = new CounterPartyGetDetailModel();

            input.counterPartyId  = counterPartyId;
            input.cifCounterParty = cifCounterParty;
            input.userId          = RDAuthorize.UserId;
            var result = _counterPartyService.getDetailCounterParty(input);
            CPProductViewModel model = new CPProductViewModel();

            Library.TransferData(result, ref model);
            TheSession.Remove(_strSectionProduct); //xóa section truoc
            return(View(model));
        }
Example #6
0
        public ActionResult ExportCommisionList()
        {
            try
            {
                using (XLWorkbook wb = new XLWorkbook())
                {
                    List <CPProductImportCommisionListModel> lsImport = new List <CPProductImportCommisionListModel>();
                    object temp;
                    TheSession.TryGet(_strSectionCommisionList, out temp);
                    if (temp != null)
                    {
                        lsImport = (List <CPProductImportCommisionListModel>)temp;
                    }
                    if (lsImport.Any())
                    {
                        wb.Worksheets.Add(MapModelToNewTableCommision(lsImport), "CommisionListTemplate");

                        Response.Clear();
                        Response.Buffer      = true;
                        Response.Charset     = "";
                        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                        Response.AddHeader("content-disposition", $"attachment;filename={DateTime.Now:yyyyMMdd}_CounterPartyTemplate.xlsx");
                        using (MemoryStream myMemoryStream = new MemoryStream())
                        {
                            wb.SaveAs(myMemoryStream);
                            myMemoryStream.WriteTo(Response.OutputStream);
                            Response.End();
                            return(Content("Success"));
                        }
                    }
                    return(Content("No Data"));
                }
            }
            catch (Exception ex)
            {
                HDBH.Log.WriteLog.Error("ManagerController => ExportCommisionList", ex);
                return(Content("No Data"));
            }
        }
Example #7
0
        public JsonResult ImportCommisionList(HttpPostedFileBase importCommisionList)
        {
            string fileName = "";
            object ls;
            object retList = null;

            try
            {
                var file = importCommisionList;
                if (file != null)
                {
                    string[] extFile = new string[] { "xlsx" };
                    fileName = string.Format("{0}\\{1}{2}", Server.MapPath("~/Content/Uploads"), DateTime.Now.ToString("yyyyMMddHHmmss"), System.IO.Path.GetExtension(file.FileName));
                    if (fileName.EndsWith(".xlsx", StringComparison.CurrentCultureIgnoreCase))
                    {
                        file.SaveAs(fileName);
                    }

                    Reader           reader = new Reader(fileName);
                    IDataTransformer podata = new DataTransformer();
                    ls = reader.GetData <CPProductImportTempCommisionListModel>(podata);
                    if (ls != null)
                    {
                        int idx = 1;
                        List <CPProductImportCommisionListModel> lsImport  = new List <CPProductImportCommisionListModel>();
                        List <CPProductImportProductModel>       lsProduct = new List <CPProductImportProductModel>();
                        object temp;
                        TheSession.TryGet(_strSectionProduct, out temp);
                        if (temp != null)
                        {
                            lsProduct = (List <CPProductImportProductModel>)temp;
                        }
                        if (lsProduct != null && lsProduct.Any())
                        {
                            foreach (var itx in ls as List <CPProductImportTempCommisionListModel> )
                            {
                                if (!string.IsNullOrEmpty(itx.productCode))
                                {
                                    string strProductCode = itx.productCode.FilterSpecial();
                                    string strMessage     = string.Empty;
                                    bool   isExists       = false;

                                    if (lsProduct != null && lsProduct.Any())
                                    {
                                        lsProduct = lsProduct.Where(x => string.IsNullOrEmpty(x.errorMessage)).ToList();
                                        isExists  = lsProduct.Any(x => x.productCode.ToUpper().Trim().Equals(strProductCode.ToUpper().Trim()));
                                    }
                                    else
                                    {
                                        strMessage += " Không tìm thấy danh sách mã sản phẩm";
                                    }
                                    if (!isExists)
                                    {
                                        strMessage += " Mã sản phẩm không tồn tại";
                                    }

                                    if (itx.effectedFromDate == null)
                                    {
                                        strMessage += " Thiếu trường hiệu lực từ ngày";
                                    }
                                    else
                                    {
                                        if (DateTime.Parse(itx.effectedFromDate.ToString()).Ticks < DateTime.Now.Date.Ticks)
                                        {
                                            strMessage += " Ngày hiệu lực từ ngày phải lớn hơn ngày hiện tại";
                                        }
                                    }
                                    if (itx.effectedToDate == null)
                                    {
                                        strMessage += " Thiếu trường hiệu lực đến ngày";
                                    }
                                    else
                                    {
                                        if (DateTime.Parse(itx.effectedToDate.ToString()).Ticks < DateTime.Now.Date.Ticks)
                                        {
                                            strMessage += " Ngày hiệu lực đến ngày phải lớn hơn ngày hiện tại";
                                        }
                                    }
                                    var item = new CPProductImportCommisionListModel
                                    {
                                        productCode      = strProductCode,
                                        productName      = itx.productName,
                                        effectedFromDate = itx.effectedFromDate != null?DateTime.Parse(itx.effectedFromDate.ToString()) : new DateTime(),
                                                               effectedToDate = itx.effectedToDate != null?DateTime.Parse(itx.effectedToDate.ToString()) : new DateTime(),
                                                                                    totalCommisRate   = (itx.agencyCommisRate ?? 0) + (itx.supportCommisRate ?? 0) + (itx.serviceCostRate ?? 0),
                                                                                    agencyCommisRate  = (itx.agencyCommisRate ?? 0),
                                                                                    supportCommisRate = (itx.supportCommisRate ?? 0),
                                                                                    serviceCostRate   = (itx.serviceCostRate ?? 0),
                                                                                    commisRate        = (itx.commisRate ?? 0),
                                                                                    errorMessage      = strMessage
                                    };
                                    item.remainRate = item.totalCommisRate - item.commisRate;
                                    item.SelectList = new List <SelectListItem>();
                                    item.SelectList = lsProduct;
                                    lsImport.Add(item);
                                    idx++;
                                }
                            }
                            retList = lsImport;
                            TheSession.TrySet(_strSectionCommisionList, retList);
                            return(Json(new { Code = 0, Message = RenderPartialViewToString("~/Areas/CPProduct/Views/Shared/_templateCommissionListImport.cshtml", retList) }));
                        }
                        else
                        {
                            return(Json(new { Code = -1, Message = "Không tìm thấy danh sách sản phẩm" }));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                HDBH.Log.WriteLog.Error("ManagerController => ImportCommisionList", ex);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    System.IO.File.Delete(fileName);
                }
            }
            return(Json(new { Code = -1, Message = "Không tìm thấy danh sách sản phẩm" }));
        }
Example #8
0
        public JsonResult ImportProduct(HttpPostedFileBase importProduct)
        {
            string fileName = "";
            object ls;
            object retList = null;

            try
            {
                var file = importProduct;
                if (file != null)
                {
                    string[] extFile = new string[] { "xlsx" };
                    fileName = string.Format("{0}\\{1}{2}", Server.MapPath("~/Content/Uploads"), DateTime.Now.ToString("yyyyMMddHHmmss"), System.IO.Path.GetExtension(file.FileName));
                    if (fileName.EndsWith(".xlsx", StringComparison.CurrentCultureIgnoreCase))
                    {
                        file.SaveAs(fileName);
                    }

                    Reader           reader = new Reader(fileName);
                    IDataTransformer podata = new DataTransformer();
                    ls = reader.GetData <CPProductImportTempProductModel>(podata);
                    if (ls != null)
                    {
                        int idx = 1;
                        List <CPProductImportProductModel> lsImport = new List <CPProductImportProductModel>();
                        foreach (var itx in ls as List <CPProductImportTempProductModel> )
                        {
                            if (!string.IsNullOrEmpty(itx.productCode))
                            {
                                string strProductCode = itx.productCode.FilterSpecial();
                                string strProductName = itx.productName.FilterSpecial();
                                string strMessage     = string.Empty;

                                if (string.IsNullOrEmpty(strProductCode))
                                {
                                    strMessage += " Chưa nhập Product Code";
                                }
                                else
                                {
                                    if (HasSpecialChars(strProductCode))
                                    {
                                        strMessage += " Lỗi ký tự đặc biệt";
                                    }
                                    if (HasUnicode(strProductCode))
                                    {
                                        strMessage += " Lỗi ký unicode";
                                    }
                                    if (HasSpace(strProductCode))
                                    {
                                        strMessage += " Lỗi khoảng trắng";
                                    }
                                }

                                var item = new CPProductImportProductModel
                                {
                                    productCode  = strProductCode,
                                    productName  = strProductName,
                                    errorMessage = strMessage
                                };

                                lsImport.Add(item);
                                idx++;
                            }
                        }
                        retList = lsImport;
                    }
                    TheSession.TrySet(_strSectionProduct, retList);
                }
            }
            catch (Exception ex)
            {
                HDBH.Log.WriteLog.Error("ManagerController => ImportProduct", ex);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    System.IO.File.Delete(fileName);
                }
            }
            return(Json(RenderPartialViewToString("~/Areas/CPProduct/Views/Shared/_templateProductImport.cshtml", retList)));
        }
Example #9
0
        static RevSurface ToRhinoRevSurface(NXOpen.Face face, FaceEx.FaceData faceData)
        {
            var bodyFeatures = face.GetBody().GetFeatures();

            var revolveFeature = bodyFeatures.FirstOrDefault(obj => obj is NXOpen.Features.Revolve);

            Curve  faceSectionCurve = default;
            double startRadian      = 0.0;
            double endRadian        = Math.PI * 2;

            if (revolveFeature != null)
            {
                NXOpen.Features.RevolveBuilder revolveBuilder = WorkPart.Features.CreateRevolveBuilder(revolveFeature);
                revolveBuilder.Section.GetOutputCurves(out var sectionCurves);

                startRadian = revolveBuilder.Limits.StartExtend.Value.Value * Math.PI / 180.0;

                endRadian = revolveBuilder.Limits.EndExtend.Value.Value * Math.PI / 180.0;

                revolveBuilder.Destroy();

                for (int i = 0; i < sectionCurves.Length; i++)
                {
                    var baseCurve = sectionCurves[i] as NXOpen.IBaseCurve;

                    var curveMidPt = baseCurve.GetPoint(0.5);
                    if (curveMidPt.DistanceTo(face.Tag).Distance < DistanceTolerance)
                    {
                        faceSectionCurve = baseCurve.ToRhinoCurve();
                        break;
                    }
                }
            }
            else
            {
                var faceBoundingBox = face.GetAlignedBoundingBox(faceData.Direction);

                var point1 = faceData.Point.Move(faceData.Direction, faceBoundingBox.Height * 1.5);

                var faceMidPoint = face.GetPoint();

                // 求与旋转方向垂直,并且位于面上的方向
                var verticalDirection = faceData.Direction.CrossProduct(faceMidPoint.Subtract(faceData.Point)).CrossProduct(faceData.Direction);

                var point2 = point1.Move(verticalDirection, faceBoundingBox.Length * 1.5);

                var point3 = point2.Move(faceData.Direction.Reverse(), faceBoundingBox.Height * 3);

                var point4 = point3.Move(verticalDirection.Reverse(), faceBoundingBox.Length * 1.5);

                NXOpen.Session.UndoMarkId undoMarkId = TheSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Calc Rev Profile");

                NXOpen.Body fourPointSurface = WorkPart.Features.CreateFourPointSurface(point1, point2, point3, point4);

                try
                {
                    NXOpen.Features.IntersectionCurve intersectionCurveFeature = WorkPart.Features.CreateIntersectionCurve(fourPointSurface.GetFaces(), face);

                    faceSectionCurve = (intersectionCurveFeature.GetEntities()[0] as NXOpen.Curve).ToRhino();

                    intersectionCurveFeature.Delete();

                    fourPointSurface.Delete();
                }
                catch (Exception)
                {
                    TheSession.UndoToMark(undoMarkId, "Calc Rev Profile");

                    Console.WriteLine($"无法创建面 {face.Tag} 的交线");

                    return(null);
                }
                finally
                {
                    TheSession.DeleteUndoMark(undoMarkId, "Calc Rev Profile");
                }
            }

            return(RevSurface.Create(faceSectionCurve, new Line(faceData.Point.ToRhino(), faceData.Point.Move(faceData.Direction, 10.0).ToRhino()), startRadian, endRadian));
        }