Exemplo n.º 1
0
		public Box(BoxViewModel viewModel, Caret caretPerTree)
		{
			this.DataContext = viewModel;

			this.CaretPerTree = caretPerTree;

			this.Focusable = true;
			this.Width = double.NaN;
			this.ShowGridLines = false;
			//this.SizeChanged += (sender, e) => { if (this.BoxParent != null) this.BoxParent.InvalidateMeasure(); throw new NotImplementedException("You'd think this is automated in WPF"); };

			this.viewModel.CaretPerTree.CaretChangedFocus += OnCaretChanged;
			OnCaretChanged(this.viewModel.Caret, new PropertyChangedEventArgs(nameof(BoxViewModel.Caret)));

			this.viewModel.Elements.CollectionChangedElementWise += OnElementsChanged;
			//trigger adding the initial elements. THe viewModel argument may already have some elements set
			if (viewModel.Elements.Count != 0)
			{
				var e = new NotifyBoxElementsChangedEventArgs(viewModel.Elements, NotifyCollectionChangedAction.Add, viewModel.Elements, 0);
				OnElementsChanged(viewModel.Elements, e);
			}

			this.viewModel.PropertyChanged += OnFocusableChanged;
			OnFocusableChanged(this.viewModel, new PropertyChangedEventArgs(nameof(BoxViewModel.Modifiable)));

			this.viewModel.Selections.CollectionChanged += OnSelectionsChanged;
			if (this.viewModel.Selections.Count != 0)
				OnSelectionsChanged(this.viewModel.Selections, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, this.viewModel.Selections, 0));
		}
Exemplo n.º 2
0
 public BoxViewModelConnectTest()
 {
     _repo   = new Mock <ISaveRepository>();
     _monik  = new Mock <ILogger>();
     _mapper = new MapperConfiguration(cfg => { cfg.AddProfile <MapperProfile>(); }).CreateMapper();
     _box    = new BoxViewModel(_monik.Object, _mapper);
 }
Exemplo n.º 3
0
        public void Initialize(ViewRequest viewRequest)
        {
            var request = viewRequest as CardViewRequest;

            if (request == null)
            {
                return;
            }

            box  = request.Box;
            card = request.Card;

            AvailableBoards = box.Boards.Items.ToList();
            SelectedBoard   = AvailableBoards.First();

            var str    = request.Card.Header;
            var maxLen = str.Length >= 22 ? 22 : str.Length;

            CardHeader = "Select destination board and cell to make move \"" +
                         request.Card.Header.Substring(0, maxLen) +
                         (str.Length > 22 ? "..." : "") + "\"";

            Title    = $"Move card {card.Header} to";
            IsOpened = true;
        }
Exemplo n.º 4
0
        public void Initialize(ViewRequest viewRequest)
        {
            HeaderPropertyViewRequest request = viewRequest as HeaderPropertyViewRequest;

            if (request == null)
            {
                return;
            }

            Header = request.Header;
            Box    = request.Box;
            board  = request.Board;

            if (Header == null)
            {
                return;
            }

            OldLimitSet         = Header.LimitSet;
            OldMaxNumberOfCards = HeaderMaxNumber;
            OldName             = Header.Name;

            TitleText = Header is ColumnViewModel ? "Column Properties" : "Row Properties";

            this.RaisePropertyChanged("TitleText");
            this.RaisePropertyChanged("HeaderName");
            this.RaisePropertyChanged("HeaderLimitSet");
            this.RaisePropertyChanged("HeaderMaxNumber");

            IsOpened = true;
        }
Exemplo n.º 5
0
		public void CreateText()
		{
			var root = new BoxViewModel();
			root.Elements.Add(new TextConstructionSpecifier("abc"));

			Contract.Assert(root.CaretPerTree.Box == null);
		}
Exemplo n.º 6
0
		/// <summary> Gets the box corresponding to the specified box view model. </summary>
		internal static Box GetViewModelBox(BoxViewModel model, Box anyBox)
		{
			//TODO: change this ugly method of getting the box corresponding to a box model
			Box root = GetRootBox(anyBox);
			var result = root.TransitiveSelect(b => b.Children.OfType<BoxComposition>().SelectMany(boxComposition => boxComposition.Children.Cast<Box>()))
							 .First(b => b.viewModel == model);
			return result;
		}
Exemplo n.º 7
0
		/// <summary> Gets the default placeholder for when the specified box has no elements. </summary>
		internal static GlyphRunViewModel GetDefault(BoxViewModel box)
		{
			return new GlyphRunViewModel(box, DefaultGlyphIndex.ToSingleton(), box.FontSize, placeholderGlyphCharacter.ToSingleton(), new Markup(PlaceholderForeground).ToSingleton())
			{
				//Modifiable = true,
				IsPlaceholder = true,
			};
		}
Exemplo n.º 8
0
		public void CreateBoxComposition()
		{
			var root = new BoxViewModel();

			root.Elements.Add(new CompositionConstructionSpecifier(boxes => new MatrixNotation.MatrixViewModel(boxes, 1, 1),
																   new BoxConstructionSpecifier(new TextConstructionSpecifier("abs").ToSingletonReadOnlyList())));

			Contract.Assert(root.CaretPerTree.Box == null);
		}
Exemplo n.º 9
0
        public void TestsCleanup()
        {
            this.postService       = null;
            this.boxService        = null;
            this.navigationService = null;
            this.storageService    = null;
            this.dialogService     = null;

            this.boxViewModel = null;
        }
Exemplo n.º 10
0
		/// <summary> Puts this box into special-box-state, which may only be entered if no elements are present. </summary>
		internal static void Ιnstantiate(BoxViewModel box)
		{
			Contract.Requires(box.Elements.ElementCount == 0);
			//Contract.Requires(box.Elements.InstantiatePlaceholder);

			GlyphRunViewModel placeholder = GetDefault(box);
			box.Elements.Insert(placeholder, ElementIndex.First);//cannot use Add
			box.IsPlaceholder = true;
			placeholder.PropertyChanged += OnPlaceholderDemoted;
		}
Exemplo n.º 11
0
        public void TestsInitialize()
        {
            this.postService       = new FakePostService();
            this.boxService        = new FakeBoxService();
            this.navigationService = new FakeNavigationService();
            this.storageService    = new FakeStorageService();
            this.dialogService     = new FakeDialogService();

            this.boxViewModel = new BoxViewModel(this.postService, this.boxService,
                                                 this.navigationService, this.storageService, this.dialogService);
        }
Exemplo n.º 12
0
		public void CreateVector()
		{
			var root = new BoxViewModel();

			root.Elements.Add(new CompositionConstructionSpecifier(boxes => new MatrixNotation.MatrixViewModel(boxes, 1, 2),
																   new BoxConstructionSpecifier(new TextConstructionSpecifier("e1").ToSingletonReadOnlyList()),
																   new BoxConstructionSpecifier(new TextConstructionSpecifier("e2").ToSingletonReadOnlyList(), 1)));

			Contract.Assert(root.CaretPerTree.Box == ((BoxCompositionViewModel)root.Elements[0]).Boxes[1]);
			Contract.Assert(root.CaretPerTree.Position == 1);
		}
Exemplo n.º 13
0
		//SPEC: A character is an atomic name instance. A box composition is a composite name instance with one element per box. 
		//SPEC: A box contains one name binding per element in that box, which may be a character or box composition. 
		//SPEC: A box is thus a composite name instance, unless it contains a single character or is placeholder, in which case those are directly represented in the containing Box Composition. 

		/// <summary> Gets all NameInstances in the specified box that hasn't bound at all yet. </summary>
		public NameInstanceBinding(BoxViewModel rootViewModel)
		{
			Contract.Requires(rootViewModel != null);

			this.rootViewModel = rootViewModel;
			this.mutations = new Dictionary<NameInstance, MutationCollection>(ReferenceEqualityComparer);
			this.root = new CompositeNameInstance(new List<NameInstance>(), RootPosition.Instance);

			this.rootViewModel.Elements.CollectionChanged += onBoxElementsCollectionChanged;
			if (this.rootViewModel.Elements.Count != 0)
				onBoxElementsCollectionChanged(rootViewModel.Elements, NotifyBoxElementsChangedEventArgs.Create(this.rootViewModel.Elements, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, this.rootViewModel.Elements)));
		}
Exemplo n.º 14
0
		public void RootWithTextTest()
		{
			var root = new BoxViewModel(new Boxctor(new Textctor("b").ToSingletonReadOnlyList(), getFontSize: @null => 30));

			var binding = new NameInstanceBinding(root);
			var rootContainingb = binding.GetRoot();

			Contract.Assert(rootContainingb.Elements.Count == 1);
			Contract.Assert((rootContainingb.Elements[0] as AtomicNameInstance).Value == 'b');

			root.Elements.Insert(1, new Textctor("a"));//binding.WithText("a", 1, root);
			var rootContainingba = binding.GetRoot();
			Contract.Assert(rootContainingba.Elements.Count == 2);
			Contract.Assert((rootContainingba.Elements[0] as AtomicNameInstance).Value == 'b');
			Contract.Assert((rootContainingba.Elements[1] as AtomicNameInstance).Value == 'a');

			root.Elements.RemoveAt(0);//binding.Without(root, 0, 1);
			var rootContaininga = binding.GetRoot();
			Contract.Assert(rootContaininga.Elements.Count == 1);
			Contract.Assert((rootContaininga.Elements[0] as AtomicNameInstance).Value == 'a');

			root.Elements.Insert(0, new Textctor("c"));//binding.WithText("c", 0, root);
			var rootContainingca = binding.GetRoot();
			Contract.Assert(rootContainingca.Elements.Count == 2);
			Contract.Assert((rootContainingca.Elements[0] as AtomicNameInstance).Value == 'c');
			Contract.Assert((rootContainingca.Elements[1] as AtomicNameInstance).Value == 'a');

			root.Elements.Insert(0, new Textctor("d"));//binding.WithText("d", 0, root);
			root.Elements.RemoveAt(1);//binding.Without(root, 1, "c".Length);
			var rootContainingda = binding.GetRoot();
			Contract.Assert(rootContainingda.Elements.Count == 2);
			Contract.Assert((rootContainingda.Elements[0] as AtomicNameInstance).Value == 'd');
			Contract.Assert((rootContainingda.Elements[1] as AtomicNameInstance).Value == 'a');


			root.Elements.RemoveAt(0);//binding.Without(root, 0, "d".Length);
			rootContaininga = binding.GetRoot();
			Contract.Assert(rootContaininga.Elements.Count == 1);
			Contract.Assert((rootContaininga.Elements[0] as AtomicNameInstance).Value == 'a');

			root.Elements.Insert(0, new Textctor("e"));//binding.WithText("e", 0, root);
			root.Elements.RemoveAt(1);//binding.Without(root, 1, "a".Length);
			var rootContaininge = binding.GetRoot();
			Contract.Assert(rootContaininge.Elements.Count == 1);
			Contract.Assert((rootContaininge.Elements[0] as AtomicNameInstance).Value == 'e');

			root.Elements.Insert(1, new Textctor("fh"));//binding.WithText("fh", 1, root);
			root.Elements.Insert(2, new Textctor("g"));//binding.WithText("g", 2, root);
			var rootContainingefgh = binding.GetRoot();
			Contract.Assert(rootContainingefgh.Elements.Count == 4);
			Contract.Assert("efgh".SequenceEqual((rootContainingefgh.Elements.Select(element => ((AtomicNameInstance)element).Value))));

		}
Exemplo n.º 15
0
		public void CreateTextAndPlaceCaret()
		{
			var root = new BoxViewModel(new BoxConstructionSpecifier(initialCaretPosition: 0, getFontSize: nan => 30));
			Contract.Assert(root.CaretPerTree.Box == root);
			Contract.Assert(root.Caret.Position == 0);
			Contract.Assert(root.IsPlaceholder);

			root.Elements.Add(new TextConstructionSpecifier("abc"));

			Contract.Assert(root.CaretPerTree.Box == root);
			Contract.Assert(root.Caret.Position == 3);
			Contract.Assert(!root.IsPlaceholder);
		}
Exemplo n.º 16
0
        public ActionResult Pay(OrderPayment order)
        {
            var box = new BoxViewModel()
            {
                Cost    = order.Cost,
                OrderId = order.Id,
                UserId  = order.UserId
            };

            return(new ViewResult()
            {
                ViewName = "~/Views/Payments/IBox.cshtml",
                ViewData = new ViewDataDictionary(box)
            });
        }
Exemplo n.º 17
0
    void Start()
    {
        var boxViews = FindObjectsOfType <BoxView>();

        _inputManager = new InputManager();

        var playerModel     = new PlayerModel();
        var playerViewModel = new PlayerViewModel(playerModel);

        foreach (var box in boxViews)
        {
            var boxModel     = new BoxModel();
            var boxViewModel = new BoxViewModel(boxModel);
            box.Initialize(boxViewModel);
        }

        playerView.Initialize(playerViewModel);
    }
Exemplo n.º 18
0
        public void Initialize(ViewRequest viewRequest)
        {
            var request = viewRequest as CardViewRequest;

            if (request == null)
            {
                return;
            }

            box   = request.Box;
            board = request.Board;
            Card  = request.Card;

            requestedColumnId = request.ColumnId;
            requestedRowId    = request.RowId;

            UpdateViewModel();

            Title    = $"Edit {Head}";
            IsOpened = true;
        }
Exemplo n.º 19
0
        public ActionResult Print(BoxViewModel model)
        {
            MethodReturnResult result = new MethodReturnResult();

            try
            {
                result = PrintPrivate(model);
                if (result.Code == 0)
                {
                    result.Message = string.Format("打印箱 {0} 标签成功。", model.BoxNo);
                }
                return(Json(result));
            }
            catch (Exception ex)
            {
                result.Code    = 1000;
                result.Message = ex.Message;
                result.Detail  = ex.ToString();
            }
            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(Json(result));
        }
Exemplo n.º 20
0
        /// <summary>
        /// 装箱作业。
        /// </summary>
        /// <param name="model">装箱模型对象。</param>
        /// <returns>返回结果。</returns>
        private MethodReturnResult Box(BoxViewModel model)
        {
            MethodReturnResult result = new MethodReturnResult();
            //进行装箱作业。
            BoxParameter p = new BoxParameter()
            {
                Creator   = User.Identity.Name,
                PackageNo = model.PackageNo.ToUpper(),
                BoxNo     = model.BoxNo
            };

            using (BoxServiceClient client = new BoxServiceClient())
            {
                result = client.Box(p);

                if (result.Code == 0)
                {
                    result.Message = string.Format("电池小包 {0} 成功装箱到({1})。"
                                                   , model.PackageNo.ToUpper()
                                                   , model.BoxNo);
                }
            }
            return(result);
        }
Exemplo n.º 21
0
		/// <summary> Handles the removal of boxes. </summary>
		public void Without(BoxViewModel removedBox, int indexOfRemovedBox)
		{
			//might as well remove the event handler here already (as opposed to when executing the mutation) since it's not going to be triggered any more
			removedBox.Elements.CollectionChanged -= onBoxElementsCollectionChanged;
#if DEBUG
			removedBox.Elements.CollectionChanged += (sender, e) => { throw new Exception("Just checking that the removed box isnt' triggering events anymore"); };
#endif
			GetCollectionToAddTo(GetRoute(removedBox.BoxParent)).Remove(indexOfRemovedBox, 1);
		}
Exemplo n.º 22
0
		/// <summary> Handles the removal of both characters and box compositions in the specified range from the specified box.  </summary>
		public void Without(BoxViewModel boxInWhichTextOrBCsAreRemoved, int palpableIndex, IList removedItems)
		{
			Contract.AssertForAll(removedItems.Cast<object>(), removedItem => removedItem.HasAnyTypeOf(typeof(Glyph), typeof(BoxCompositionViewModel)));

			GetCollectionToAddTo(GetRoute(boxInWhichTextOrBCsAreRemoved)).Remove(palpableIndex, removedItems.Count,
																				 () =>
																				 {
																					 foreach (var bcToUnregister in removedItems.OfType<BoxCompositionViewModel>())
																						 bcToUnregister.Boxes.CollectionChanged -= this.onBoxCompositionCollectionChanged;
																				 });
		}
Exemplo n.º 23
0
		public void ComplexTest()
		{
			var root = new BoxViewModel(new Boxctor(new Textctor("a").ToSingletonReadOnlyList(), getFontSize: @null => 30));
			var bindingBefore = new NameInstanceBinding(root);
			var untouchedBinding = new NameInstanceBinding(root);

			var boxWithTextte = new Boxctor(new Textctor("té").ToSingletonReadOnlyList());
			var bc1 = new Compositionctor(boxes => new NaryOperatorViewModel(boxes, false), new Boxctor(), new Boxctor(), boxWithTextte);

			root.Elements.Insert(1, bc1);
			root.Elements.Insert(0, bc1);

			var bindingInCtor = new NameInstanceBinding(root);

			foreach (var bindingRoot in new[] { bindingInCtor, bindingBefore }.Select(binding => binding.GetRoot()))
			{
				Contract.Assert(bindingRoot.Elements.Count == 3);
				Contract.Assert(bindingRoot.Elements.Select(e => e.GetType()).SequenceEqual(new[] { typeof(CompositeNameInstance), typeof(AtomicNameInstance), typeof(CompositeNameInstance) }));

				Contract.Assert(((CompositeNameInstance)bindingRoot.Elements[0]).Elements.Count == 3);
				Contract.Assert(((AtomicNameInstance)bindingRoot.Elements[1]).Value == 'a');
				Contract.Assert(((CompositeNameInstance)bindingRoot.Elements[2]).Elements.Count == 3);

				Contract.Assert(((CompositeNameInstance)((CompositeNameInstance)bindingRoot.Elements[0]).Elements[0]).Elements.Count == 0);
				Contract.Assert(((CompositeNameInstance)((CompositeNameInstance)bindingRoot.Elements[0]).Elements[1]).Elements.Count == 0);

				var boxContainingte = (CompositeNameInstance)((CompositeNameInstance)bindingRoot.Elements[0]).Elements[2];
				Contract.Assert(boxContainingte.Elements.Count == 2);
				Contract.Assert(boxContainingte.Elements[0] is AtomicNameInstance);
				Contract.Assert(boxContainingte.Elements[1] is CompositeNameInstance);
				Contract.Assert(((CompositeNameInstance)boxContainingte.Elements[1]).Elements[0].Position is DiacriticPosition);
				Contract.Assert(((CompositeNameInstance)((CompositeNameInstance)boxContainingte.Elements[1]).Elements[0]).Elements[0].Position.Equals(new LinearPosition(0)));
			}

			((BoxCompositionViewModel)root.Elements[0]).RemoveAt(0);//removes empty box in first bc
			((BoxCompositionViewModel)root.Elements[2]).Boxes[2].Elements.RemoveAt(0);//removes t in second bc's third box


			var boxCompositionOfWhichOneBoxIsRemoved = (CompositeNameInstance)untouchedBinding.GetRoot().Elements[0];
			Contract.Assert(((CompositeNameInstance)boxCompositionOfWhichOneBoxIsRemoved.Elements[0]).Elements.Count == 0);
			Contract.Assert(((CompositeNameInstance)boxCompositionOfWhichOneBoxIsRemoved.Elements[1]).Elements.Count == 2);

			var boxCompositionWhoseThirdBoxLost_t = (CompositeNameInstance)untouchedBinding.GetRoot().Elements[2];
			var boxWhoLost_t = (CompositeNameInstance)boxCompositionWhoseThirdBoxLost_t.Elements[2];
			Contract.Assert(boxWhoLost_t.Position is NaryPosition);
			var boxCompositionDiacritic = (CompositeNameInstance)boxWhoLost_t.Elements[0];
			Contract.Assert(boxCompositionDiacritic.Position is LinearPosition);//the box composition that is the diacritic has linear position, as it is positioned in a box (at lienar pos 1)
			Contract.Assert(boxCompositionDiacritic.Elements.Count == 1);
			var diacritic = (CompositeNameInstance)boxCompositionDiacritic.Elements[0];
			Contract.Assert(diacritic.Position is DiacriticPosition);
			Contract.Assert((diacritic.Elements[0] as AtomicNameInstance)?.Value == 'e');
		}
Exemplo n.º 24
0
		public void DiacriticTest()
		{
			//new BoxViewModel(new BoxCtor(new BoxCompCtor(boxes => DiacriticArranger(boxes), new BoxCtor()), getFontSize: getFontSize));
			var boxRoot = new BoxViewModel(new BoxCtor(new TextCtor("é").ToSingletonList(), getFontSize: getFontSize));
			CompositeNameInstance root = new NameInstanceBinding(boxRoot).GetRoot();

			var result = inferrer.Match(root).ToList();

		}
Exemplo n.º 25
0
		internal void Set(BoxViewModel box, int position)
		{
			Set(box, new ExplicitIndex(position, box.Elements, IndexRoundingBehavior.ToText));
		}
Exemplo n.º 26
0
		/// <summary> Gets whether this explicit index will not throw an IndexOutOfRangeException in the specified box. </summary>
		/// <param name="box"> The box in which this index may point. </param>
		public bool IsInRange(BoxViewModel box)
		{
			return IsInRange(box.Elements);
		}
Exemplo n.º 27
0
		internal static bool IsInRange(int position, BoxViewModel box)
		{
			return IsInRange(position, box.Elements);
		}
Exemplo n.º 28
0
        private MethodReturnResult PrintPrivate(BoxViewModel model)
        {
            MethodReturnResult result = new MethodReturnResult();

            //不需要进行标签打印。
            if (model.PrintQty <= 0 ||
                string.IsNullOrEmpty(model.PrinterName) ||
                string.IsNullOrEmpty(model.PrintLabelCode))
            {
                return(result);
            }
            //获取打印机名称
            ClientConfig printer = null;

            using (ClientConfigServiceClient client = new ClientConfigServiceClient())
            {
                MethodReturnResult <ClientConfig> rst = client.Get(model.PrinterName);
                if (rst.Code > 0)
                {
                    return(rst);
                }
                printer = rst.Data;
            }
            //获取打印条码内容
            PrintLabel label = null;

            using (PrintLabelServiceClient client = new PrintLabelServiceClient())
            {
                MethodReturnResult <PrintLabel> rst = client.Get(model.PrintLabelCode);
                if (rst.Code > 0)
                {
                    return(rst);
                }
                label = rst.Data;
            }
            //获取箱数据
            Package box = new Package();

            using (PackageQueryServiceClient client = new PackageQueryServiceClient())
            {
                MethodReturnResult <Package> rst = client.Get(model.BoxNo);
                if (rst.Code <= 0 && rst.Data != null)
                {
                    box = rst.Data;
                }
                else
                {
                    result = rst;
                    if (result.Code == 1002)
                    {
                        result.Message = string.Format("箱 {0} 数据不存在。", model.BoxNo);
                    }
                    return(result);
                }
            }
            if (box.Quantity <= 0)
            {
                result.Code    = 2001;
                result.Message = string.Format("箱 {0} 中数量为零,请确认。", model.BoxNo);
                return(result);
            }
            //获取箱第一包的数据
            string      packageNo = string.Empty;
            PackageInfo obj       = new PackageInfo();

            using (PackageQueryServiceClient client = new PackageQueryServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    PageNo   = 0,
                    PageSize = 1,
                    Where    = string.Format("Key.PackageNo='{0}' AND Key.ObjectType='{1}'"
                                             , model.BoxNo
                                             , Convert.ToInt32(EnumPackageObjectType.Packet)),
                    OrderBy = "ItemNo"
                };
                MethodReturnResult <IList <PackageDetail> > rst = client.GetDetail(ref cfg);
                if (rst.Code <= 0 && rst.Data != null && rst.Data.Count > 0)
                {
                    packageNo = rst.Data[0].Key.ObjectNumber;
                }
            }
            if (!string.IsNullOrEmpty(packageNo))
            {
                using (PackageInfoServiceClient client = new PackageInfoServiceClient())
                {
                    MethodReturnResult <PackageInfo> rst = client.Get(packageNo);
                    if (rst.Code <= 0 && rst.Data != null)
                    {
                        obj = rst.Data;
                    }
                    else
                    {
                        result = rst;
                        return(result);
                    }
                }
            }
            //根据打印数量设置打印机模板。
            using (IPrintHelper helper = PrintHelperFactory.CreatePrintHelper(label.Content))
            {
                //打印动态内容。
                dynamic d = new ExpandoObject();
                d.CartonNo = model.BoxNo.ToUpper();
                d.Color    = obj.Color;
                d.Date     = box.CreateTime.Value.ToString("yyyy.MM.dd");
                d.Eff      = obj.EfficiencyName;
                d.Grade    = obj.Grade;
                d.PartNo   = obj.ConfigCode;
                d.PNType   = obj.PNType;
                d.ProdID   = obj.ProductId;
                d.Qty      = string.Format("{0}PCS", box.Quantity);
                d.PrintQty = model.PrintQty;
                bool bSuccess = false;
                //根据打印机类型,调用不同的打印方法。
                if (printer.ClientType == EnumClientType.NetworkPrinter)
                {
                    string[] vals = printer.IPAddress.Split(':');
                    string   port = "9100";
                    if (vals.Length > 1)
                    {
                        port = vals[1];
                    }
                    bSuccess = helper.NetworkPrint(vals[0], port, label.Content, d);
                }
                else if (printer.ClientType == EnumClientType.RawPrinter)
                {
                    bSuccess = helper.RAWPrint(printer.IPAddress, label.Content, d);
                }
                else
                {
                    result.Code    = 1001;
                    result.Message = "打印失败,打印机类型不正确。";
                    return(result);
                }
                //返回打印结果。
                if (bSuccess == false)
                {
                    result.Code    = 1001;
                    result.Message = "箱标签打印失败。";
                    return(result);
                }
            }
            return(result);
        }
Exemplo n.º 29
0
        public ActionResult Save(BoxViewModel model)
        {
            MethodReturnResult result = new MethodReturnResult();

            try
            {
                if (!string.IsNullOrEmpty(model.PackageNo))
                {
                    model.PackageNo = model.PackageNo.Trim().ToUpper();
                }
                if (!string.IsNullOrEmpty(model.BoxNo))
                {
                    model.BoxNo = model.BoxNo.Trim().ToUpper();
                }
                //获取电池小包数据。
                string packageNo = model.PackageNo.ToUpper();
                result = GetPackage(packageNo);
                if (result.Code > 0)
                {
                    if (result.Code == 1002)
                    {
                        result.Message = string.Format("电池小包 {0} 数据不存在。", packageNo);
                    }
                    return(Json(result));
                }
                MethodReturnResult <Package> rst = result as MethodReturnResult <Package>;
                Package obj = rst.Data;

                //如果装箱号为空。生成装箱号。
                if (string.IsNullOrEmpty(model.BoxNo))
                {
                    string prefix = string.Format("JNC{0:yyMMdd}", DateTime.Now);
                    int    itemNo = 0;
                    using (PackageQueryServiceClient client = new PackageQueryServiceClient())
                    {
                        PagingConfig cfg = new PagingConfig()
                        {
                            PageNo   = 0,
                            PageSize = 1,
                            Where    = string.Format("Key LIKE '{0}%' AND PackageType='{1}'"
                                                     , prefix
                                                     , Convert.ToInt32(EnumPackageType.Box)),
                            OrderBy = "Key Desc"
                        };
                        MethodReturnResult <IList <Package> > rst1 = client.Get(ref cfg);
                        if (rst1.Code <= 0 && rst1.Data.Count > 0)
                        {
                            string maxBoxNo = rst1.Data[0].Key.Replace(prefix, "");
                            int.TryParse(maxBoxNo, out itemNo);
                        }
                        itemNo++;
                    }
                    model.BoxNo = prefix + itemNo.ToString("000");
                }
                model.BoxNo = model.BoxNo.ToUpper();
                //重新获取当前数量。
                using (PackageQueryServiceClient client = new PackageQueryServiceClient())
                {
                    MethodReturnResult <Package> rst2 = client.Get(model.BoxNo);
                    if (rst2.Code == 1000)
                    {
                        return(Json(rst2));
                    }
                    //检查装箱状态
                    if (rst2.Data != null && rst2.Data.PackageState != EnumPackageState.Packaging)
                    {
                        result.Code    = 1001;
                        result.Message = string.Format("箱 {0} 非 [{1}] 状态,不能装箱。"
                                                       , model.BoxNo.ToUpper()
                                                       , EnumPackageState.Packaging.GetDisplayName());
                        return(Json(result));
                    }
                    //设置当前数量。
                    if (rst2.Code <= 0 && rst2.Data != null)
                    {
                        model.CurrentQuantity = rst2.Data.Quantity;
                    }
                }

                double newCurrentQuantity = model.CurrentQuantity + obj.Quantity;
                //当前数量超过满箱数量,不能继续装箱。
                if (newCurrentQuantity > model.FullQuantity)
                {
                    result.Code    = 1;
                    result.Message = string.Format("箱({0}) 当前数量({1})加上小包({2})数量({3}),超过满箱数量。"
                                                   , model.BoxNo.ToUpper()
                                                   , model.CurrentQuantity
                                                   , obj.Key
                                                   , obj.Quantity);
                    return(Json(result));
                }
                model.CurrentQuantity = newCurrentQuantity;

                result = Box(model);
                //返回装箱结果。
                if (result.Code <= 0)
                {
                    if (model.CurrentQuantity == model.FullQuantity)
                    {
                        MethodReturnResult result1 = PrintPrivate(model);
                        result.Message += result1.Message;
                        result.Code     = result1.Code;
                    }

                    MethodReturnResult <BoxViewModel> rstFinal = new MethodReturnResult <BoxViewModel>()
                    {
                        Code     = result.Code,
                        Data     = model,
                        Detail   = result.Detail,
                        HelpLink = result.HelpLink,
                        Message  = result.Message
                    };

                    return(Json(rstFinal));
                }
            }
            catch (Exception ex)
            {
                result.Code    = 1000;
                result.Message = ex.Message;
                result.Detail  = ex.ToString();
            }
            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(Json(result));
        }
Exemplo n.º 30
0
		public void RootWithBCTest()
		{
			var root = new BoxViewModel(new Boxctor(new Compositionctor(boxes => new NaryOperatorViewModel(boxes, false), new Boxctor(new Textctor("t").ToSingletonReadOnlyList()), new Boxctor()).ToSingletonReadOnlyList()
																	 , getFontSize: @null => 30));

			var main = ((BoxCompositionViewModel)root.Elements[0]).Boxes[0];
			var limit = ((BoxCompositionViewModel)root.Elements[0]).Boxes[1];


			var binding = new NameInstanceBinding(root);
			dynamic getRoot = binding.GetRoot();

			Contract.DynamicAssert(getRoot.Elements.Count == 1);
			Contract.DynamicAssert(getRoot.Elements[0].Elements.Count == 2);
			Contract.DynamicAssert(getRoot.Elements[0].Elements[0].Elements.Count == 1);
			Contract.DynamicAssert(getRoot.Elements[0].Elements[0].Elements[0].Value == 't');
			Contract.DynamicAssert(getRoot.Elements[0].Elements[1].Elements.Count == 0);
			//							  .root box   .Nary       .Nary box
			//										   boxes	   elements 
		}
Exemplo n.º 31
0
		public void RootWithBCInBCTest()
		{
			var root = new BoxViewModel(new Boxctor(new Compositionctor(boxes => new NaryOperatorViewModel(boxes, false), new Boxctor(new Compositionctor(boxes => new NaryOperatorViewModel(boxes, false), new Boxctor(), new Boxctor()).ToSingletonReadOnlyList()), new Boxctor()).ToSingletonReadOnlyList()
																	 , getFontSize: @null => 30));


			//the root is a box with a Nary where the second box is empty but the first contains a Nary with two empty boxes
			var binding = new NameInstanceBinding(root);
			Contract.Assert(binding.GetRoot().Elements.Count == 1);
			var bc1 = (CompositeNameInstance)binding.GetRoot().Elements[0];
			Contract.Assert(bc1.Elements.Count == 2);
			var boxInBc1 = (CompositeNameInstance)bc1.Elements[0];
			Contract.Assert(boxInBc1.Elements.Count == 1);
			var bc2 = (CompositeNameInstance)boxInBc1.Elements[0];
			Contract.Assert(bc2.Elements.Count == 2);
			Contract.Assert(((CompositeNameInstance)bc2.Elements[0]).Elements.Count == 0);
			Contract.Assert(((CompositeNameInstance)bc2.Elements[1]).Elements.Count == 0);

			var box2InBc1 = (CompositeNameInstance)bc1.Elements[1];
			Contract.Assert(box2InBc1.Elements.Count == 0);
		}
Exemplo n.º 32
0
		private Stack<int> GetRoute(BoxViewModel box)
		{
			var originalBox = box;
			Stack<int> result = new Stack<int>();
			for (BoxViewModel b = box; b.BoxParent != null/*i.e. while b isn't root*/; b = b.BoxParent.Box)
			{
				BoxCompositionViewModel parent = b.BoxParent;
				int i = parent.Boxes.IndexOf(b);
				Contract.Assert(i >= 0);
				result.Push(i);

				i = parent.Box.IndividualElements.IndexOf(parent);
				Contract.Assert(i >= 0);
				result.Push(i);
			}
			return result;
		}
Exemplo n.º 33
0
		public IEnumerable<NameInstance> GetNameInstancesAlongRouteFromRootTo(BoxViewModel box)
		{
			var route = GetRoute(box);
			return GetNameInstancesAlongRoute(route);
		}
Exemplo n.º 34
0
		/// <summary> Handles creating a new box. </summary>
		private void AddNewBoxMutation(BoxViewModel newBox, int boxIndex)
		{
			//GetCollectionToAddTo(GetPosition(newBox.BoxParent)).Add(palpableIndex, () => Bind(newBox).ToReadOnlyList());
			IPosition boxPosition = newBox.BoxParent.Arranger.Positions[boxIndex];//fetching now, since the box may not be at index 'boxIndex' any more when processing the mutation
			Func<IEnumerable<NameInstance>> mutation = () => GetMutation(newBox, boxPosition).ToSingleton();
			GetCollectionToAddTo(GetRoute(newBox.BoxParent)).Add(boxIndex, mutation, false);
		}
Exemplo n.º 35
0
		protected internal abstract IBoxElement Create(BoxViewModel parent);
Exemplo n.º 36
0
		private NameInstance GetMutation(BoxViewModel newBox, IPosition newBoxPosition)
		{
			//register the box for subsequent changes to it
			newBox.Elements.CollectionChanged += this.onBoxElementsCollectionChanged;

			//create the box in the name instance model
			var result = ToNameInstance(newBox, newBoxPosition);

			//associate the box with its name instance model
			newBox.Model = result;

			return result;
		}
Exemplo n.º 37
0
 public BoxView()
 {
     InitializeComponent();
     DataContext = new BoxViewModel();
 }
Exemplo n.º 38
0
		/// <summary> Creates an AtomicNameInstance for the specified box when it contains a single character or when it is a placeholder; otherwise it creates its CompositeNameInstance. </summary>
		/// <param name="newBox"> The box to get the name instance for. </param>
		/// <param name="newBoxPosition"> The position of the box attributed by the containing BoxComposition. </param>
		private NameInstance ToNameInstance(BoxViewModel newBox, IPosition newBoxPosition)
		{
			Contract.Requires(newBox != null);
			Contract.Requires(newBoxPosition != null);

			if (newBox.IsPlaceholder)
			{
				return new CompositeNameInstance(new List<NameInstance>(), newBoxPosition);
				//return new AtomicNameInstance(((GlyphRunViewModel)newBox.Elements[0]).Glyphs[0].Character, newBoxPosition);
			}

			//uncommenting this would have boxes that only contained a single character be reprented by a name instance nested one less deep. I don't think I want it for now.
			//if (newBox.Elements.Count == 1 && ((GlyphRunViewModel)newBox.Elements[0]).Count == 1)//assumed the cast cannot throw single a box cannot contain just a single BoxComposition
			//{
			//	return GetMutationEffectNewGlyph(((GlyphRunViewModel) newBox.Elements[0])[0], newBoxPosition);
			//}

			Contract.AssertForAll(newBox.IndividualElements, element => element.GetType().IsAnyOf(typeof(BoxCompositionViewModel), typeof(Glyph)));
			return new CompositeNameInstance(newBox.IndividualElements.VirtualSelect<object, BoxCompositionViewModel, Glyph, NameInstance>(GetMutation, GetMutation).ToList(), newBoxPosition);
		}
Exemplo n.º 39
0
		internal void Set(BoxViewModel box, ExplicitIndex position)
		{
			if (box != null) Contract.Requires(box.Modifiable, "Boxes that may not be modified may not contain the caret");
			if (box == this.Box && position == this.position)
				return;

			//remove caret from previous box if necessary:
			if (this.Box != null)
			{
				this.Box.PropertyChanged -= OnBoxIsPlaceholderChanged;
				//this.Box.Caret = null;
			}

			this.Box = box;


			if (box != null)
			{
				position = ToPosition(position); //makes last explicit and rounds to text. Otherwise the result equality comparison later on might not be identical to the equality test performed when triggering the caret changed event

				//set the caret at the correct position in the box and resets the animation
				//box.Caret = this;
				box.PropertyChanged += OnBoxIsPlaceholderChanged;

				if (this.position == position)
					CaretChanged?.Invoke(this, new EventArgs());
				else
					this.position = position; //triggers caret changed event
											  //OnBoxIsPlaceholderChanged(box, new PropertyChangedEventArgs(nameof(BoxViewModel.IsPlaceholder)));
				IsVisible = !this.Box.IsPlaceholder;
			}
			else
			{
				throw new NotImplementedException("what to do with the position argument?");
				IsVisible = false;
			}
		}
Exemplo n.º 40
0
		/// <summary> Handles adding a new glyph. </summary>
		private void AddNewGlyphsMutation(Glyph newGlyph, int palpableIndex, BoxViewModel glyphReceiver)
		{
			Func<IEnumerable<NameInstance>> mutation = () => GetMutation(newGlyph, palpableIndex).ToSingleton();
			GetCollectionToAddTo(GetRoute(glyphReceiver)).Add(palpableIndex, mutation, true);
			//() => EnumerableExtensions.Zip(newGlyphs.Select(glyph => glyph.Character),newGlyphs.Select(glyph => glyph.Markup),Enumerable.Range(0, int.MaxValue).Select(i => new LinearPosition(palpableIndex + i)),ToNameInstance),true);
		}
Exemplo n.º 41
0
		/// <summary> This ctor serves as intermediate ctor to access the box constructed in the public root-constructing ctor. </summary>
		private Box(BoxViewModel boxVM) : this(boxVM, new Caret(boxVM.CaretPerTree))
		{
			this.Children.Add(this.CaretPerTree);
			this.Loaded += (sender, e) => this.Children.Remove(this.CaretPerTree);
		}
Exemplo n.º 42
0
		public void DiacriticTest()
		{
			var root = new BoxViewModel(new Boxctor(new Textctor("é").ToSingletonReadOnlyList(), getFontSize: @null => 30));
			var binding = new NameInstanceBinding(root);
			Contract.Assert(binding.GetRoot().Elements.Count == 1);
			Contract.Assert(binding.GetRoot().Elements[0] is CompositeNameInstance);
			var eAcuteBC = (CompositeNameInstance)binding.GetRoot().Elements[0];
			Contract.Assert(eAcuteBC.Elements.Count == 1);
			Contract.Assert(eAcuteBC.Position is LinearPosition);
			Contract.Assert(eAcuteBC.Elements[0] is CompositeNameInstance);
			var eAcuteBox = (CompositeNameInstance)eAcuteBC.Elements[0];
			Contract.Assert(eAcuteBox.Elements.Count == 1);
			Contract.Assert(eAcuteBox.Position is DiacriticPosition);
			Contract.Assert(eAcuteBox.Elements[0] is AtomicNameInstance);
			var eAcuteGlyph = (AtomicNameInstance)eAcuteBox.Elements[0];
			Contract.Assert(eAcuteGlyph.Value == 'e');//stripped from acute

			root.Elements.Insert(1, new Textctor("ä"));//binding.WithText("ä", 1, root);
			Contract.Assert(binding.GetRoot().Elements.Count == 2);
			Contract.Assert(binding.GetRoot().Elements[0] is CompositeNameInstance);
			eAcuteBC = (CompositeNameInstance)binding.GetRoot().Elements[0];
			Contract.Assert(eAcuteBC.Elements.Count == 1);
			Contract.Assert(eAcuteBC.Position is LinearPosition);
			Contract.Assert(eAcuteBC.Elements[0] is CompositeNameInstance);
			eAcuteBox = (CompositeNameInstance)eAcuteBC.Elements[0];
			Contract.Assert(eAcuteBox.Elements.Count == 1);
			Contract.Assert(eAcuteBox.Position is DiacriticPosition);
			Contract.Assert(eAcuteBox.Elements[0] is AtomicNameInstance);
			eAcuteGlyph = (AtomicNameInstance)eAcuteBox.Elements[0];
			Contract.Assert(eAcuteGlyph.Value == 'e');//stripped from acute

			Contract.Assert(binding.GetRoot().Elements[1] is CompositeNameInstance);
			var aTremaBC = (CompositeNameInstance)binding.GetRoot().Elements[1];
			Contract.Assert(aTremaBC.Elements.Count == 1);
			Contract.Assert(aTremaBC.Position is LinearPosition);
			Contract.Assert(aTremaBC.Elements[0] is CompositeNameInstance);
			var aTremaBox = (CompositeNameInstance)aTremaBC.Elements[0];
			Contract.Assert(aTremaBox.Elements.Count == 1);
			Contract.Assert(aTremaBox.Position is DiacriticPosition);
			Contract.Assert(aTremaBox.Elements[0] is AtomicNameInstance);
			eAcuteGlyph = (AtomicNameInstance)aTremaBox.Elements[0];
			Contract.Assert(eAcuteGlyph.Value == 'a');//stripped from trema
		}
Exemplo n.º 43
0
 public void Initialize(BoxViewModel viewModel)
 {
     _viewModel = viewModel;
     _viewModel.GetPosition(transform.position);
 }
Exemplo n.º 44
0
		public ExplicitIndex(int palpableIndex, BoxViewModel box, IndexRoundingBehavior roundingBehavior)
			: this(palpableIndex, box.Elements, roundingBehavior)
		{
		}