Пример #1
0
        private ItemLine DeserializeLine(string[] m)
        {
            var lineItem = new ItemLine();

            lineItem.Id     = int.Parse(m[1]);
            lineItem.X1     = double.Parse(m[2]);
            lineItem.Y1     = double.Parse(m[3]);
            lineItem.X2     = double.Parse(m[4]);
            lineItem.Y2     = double.Parse(m[5]);
            lineItem.Stroke = new ArgbColor(
                byte.Parse(m[6]),
                byte.Parse(m[7]),
                byte.Parse(m[8]),
                byte.Parse(m[9]));
            if (m.Length == 12)
            {
                lineItem.StartId = int.Parse(m[10]);
                lineItem.EndId   = int.Parse(m[11]);
            }
            else
            {
                lineItem.StartId = -1;
                lineItem.EndId   = -1;
            }
            return(lineItem);
        }
Пример #2
0
    /**
     * Change the current action
     * @return bool
     */
    public bool ChangeCurrentAction(char action)
    {
        if (!_inventory.ContainsKey(action))
        {
            return(false);
        }

        if (currentAction)
        {
            currentAction.Disable();
        }

        ItemLine itemLine = null;

        _inventory.TryGetValue(action, out itemLine);
        // retrieve action bound to item
        Action changeAction = itemLine.item.ActionBound;

        // if equals => cancellation
        if (currentAction != null && currentAction.Equals(changeAction))
        {
            currentAction = null;
            return(false);
        }
        currentAction = changeAction;
        if (currentAction != null)
        {
            currentAction.Enable(gameObject);
        }
        return(true);
    }
Пример #3
0
    /*
     * Add an item in the entity inventory
     * @return bool
     */
    public bool AddItemInInventory(Item item)
    {
        Action action = item.ActionBound;
        // choose an key to store
        char key = Action.ACTION_KEY [(int)action.DefaultCategory];

        if (this._inventory.ContainsKey(key))
        {
            // Increment quantity in the inventory
            ItemLine itemLine = this._inventory [key];
            if (itemLine.item.Equals(item) && itemLine.item.IsConsumable)
            {
                itemLine.quantity++;
                this._inventory [key] = itemLine;
                return(true);
            }
        }
        else
        {
            ItemLine newItemLine = new ItemLine();
            newItemLine.item     = item;
            newItemLine.quantity = 1;
            this._inventory.Add(key, newItemLine);
            return(true);
        }
        // inventory slot full
        Debug.Log("Inventory slot : " + key + " full");
        return(false);
    }
Пример #4
0
        private void ReserveItem()
        {
            Console.Write("Product name: ");
            string name     = Console.ReadLine();
            int    quantity = -1;

            do
            {
                Console.Write("Quantity: ");
            }while (!Int32.TryParse(Console.ReadLine(), out quantity) && quantity < 1);
            ItemLine reservedItem = (new StockManager()).ReserveItem(quantity, name);

            if (reservedItem != null)
            {
                AddProductToCart(reservedItem);
                if (reservedItem.Quantity != quantity)
                {
                    Console.WriteLine($"Product {name} add to the cart ({reservedItem.Quantity} pieces instead of {quantity})");
                }
                else
                {
                    Console.WriteLine($"Product {name} add to the cart");
                }
            }
            else
            {
                Console.WriteLine($"Product {name} could not be found");
            }
        }
Пример #5
0
 public void Move(ItemLine line, double x, double y)
 {
     line.X1 += x;
     line.Y1 += y;
     line.X2 += x;
     line.Y2 += y;
 }
Пример #6
0
    /*
     * Consume an item in the entity inventory
     * @return bool
     */
    public bool ConsumeItemInInventory(char key)
    {
        if (!this._inventory.ContainsKey(key))
        {
            Debug.LogError("L'item n'est pas présent dans l'inventaire");
            return(false);
        }

        ItemLine itemLine = this._inventory [key];

        // decrement quantity in the inventory
        if (itemLine.item.IsConsumable)
        {
            itemLine.quantity--;
            Debug.Log(this.name + " utilise 1 " + itemLine.item.name);
            if (itemLine.quantity <= 0)
            {
                this._inventory.Remove(key);
                return(true);
            }
            this._inventory [key] = itemLine;
            return(true);
        }
        return(false);
    }
Пример #7
0
        public void ItemLineCreate()
        {
            ItemLine sut;
            string   itemDesc = "TestLineItem";

            sut = new ItemLine(itemDesc, ItemLineType.Product);

            sut.ShouldNotBeNull();
            sut.Description.ShouldBe(itemDesc);
            sut.Type.ShouldBe(ItemLineType.Product);
        }
Пример #8
0
    public void UpdateMove()
    {
        //if (GameplayController.Instance.isEndGame) return;
        deltaTime = Time.deltaTime;
        posCur   += dirMove * velocity * deltaTime;

        dist = (posCur - posOld).magnitude;
        int result = Physics2D.CircleCastNonAlloc(posOld, radius, dirMove, hits, dist, layerMask);

        //Debug.Log("name:" + name + " dirMove:" + dirMove + " posOld:" + posOld + " posCur:" + posCur + " normal:" + hit.normal + " hit:" + hit.point + " radius:" + radius);

        for (int i = 0; i < result; i++)
        {
            hit = hits[i];
            //Debug.Log("name:" + name + " dirMove:" + dirMove + " posOld:" + posOld + " posCur:" + posCur + " normal:" + hit.normal + " hit:" + hit.point);
            if (hit.collider != null)
            {
                if (hit.collider.gameObject != gameObject)
                {
                    if (hit.collider.tag == "ItemLine")
                    {
                        ItemLine itemLine = hit.collider.GetComponent <ItemLine>();

                        if (itemLine != null)
                        {
                            if (itemLine.isCompleteSketching == false)
                            {
                                GameplayController.Instance.EndGame(false);
                            }
                            else
                            {
                                Vector3 reflectVec = Vector3.Reflect(dirMove, hit.normal);
                                pointHit = hit.point;
                                posCur.x = hit.point.x + hit.normal.x * (radius + radius * deltaTime);
                                posCur.y = hit.point.y + hit.normal.y * (radius + radius * deltaTime);
                                dirMove  = reflectVec;
                            }
                        }
                        else
                        {
                            Vector3 reflectVec = Vector3.Reflect(dirMove, hit.normal);
                            pointHit = hit.point;
                            posCur.x = hit.point.x + hit.normal.x * (radius + radius * deltaTime);
                            posCur.y = hit.point.y + hit.normal.y * (radius + radius * deltaTime);
                            dirMove  = reflectVec;
                        }
                        break;
                    }
                }
            }
        }
        transform.position = posCur;
        posOld             = posCur;
    }
Пример #9
0
 public void ReleaseItem(ItemLine line)
 {
     foreach (ItemLine itemline in listItemsCurrent)
     {
         if (itemline.getName().Equals(line.getName()))
         {
             int currentQuantity = itemline.getQuantiy();
             itemline.setQuantity(currentQuantity + line.getQuantiy());
         }
     }
 }
Пример #10
0
        public ActionResult Remove(int id)
        {
            if (Session["cart"] != null)
            {
                Cart     cart     = (Cart)Session["cart"];
                ItemLine itemLine = cart.GetItemLineById(id);
                cart.listItemsLine.Remove(itemLine);
            }


            return(Redirect("~/Cart/index"));
        }
Пример #11
0
        public void ProductItemProcessorHandleProductItemLine()
        {
            int      customerId      = 4567890;
            ItemLine productItemLine = new ItemLine {
                Description = "The Gril on the Train", Type = ItemLineType.Product
            };
            SpyShippingService   shippingService = new SpyShippingService();
            ProductItemProcessor itemProcessor   = new ProductItemProcessor(shippingService);

            itemProcessor.HandlePurchaseOrderItem(customerId, productItemLine);
            shippingService.ProcessedItems.Any(pi => pi.Contains(productItemLine.Description)).ShouldBeTrue();
        }
        public void MembershipItemProcessorHandleMembershipItemLine()
        {
            int      customerId         = 4567890;
            ItemLine membershipItemLine = new ItemLine {
                Description = "The Gril on the Train", Type = ItemLineType.Membership
            };
            SpyMembershipService    membershipService = new SpyMembershipService();
            MembershipItemProcessor itemProcessor     = new MembershipItemProcessor(membershipService);

            itemProcessor.HandlePurchaseOrderItem(customerId, membershipItemLine);
            membershipService.ProcessedItems.Any(pi => pi.Contains(membershipItemLine.Description)).ShouldBeTrue();
        }
Пример #13
0
            public XElement GenerateModRq(BaseRef OverrideItemAccountRef = null)
            {
                XElement xElement = new XElement(nameof(ItemLine) + "Mod");

                xElement.Add(TxnLineID.ToQBXML(nameof(TxnLineID)));
                xElement.Add(ItemGroupRef.ToQBXML(nameof(ItemGroupRef)));
                xElement.Add(Quantity.ToQBXML(nameof(Quantity)));
                xElement.Add(UnitOfMeasure.ToQBXML(nameof(UnitOfMeasure)));
                xElement.Add(OverrideUOMSetRef.ToQBXML(nameof(OverrideUOMSetRef)));
                xElement.Add(ItemLine.ToQBXML(nameof(ItemLine) + "Mod"));
                return(xElement);
            }
Пример #14
0
        public XLine Deserialize(ISheet sheet, XBlock parent, ItemLine lineItem, double thickness)
        {
            var line = _blockFactory.CreateLine(thickness, lineItem.X1, lineItem.Y1, lineItem.X2, lineItem.Y2, lineItem.Stroke);

            line.Id      = lineItem.Id;
            line.StartId = lineItem.StartId;
            line.EndId   = lineItem.EndId;

            parent.Lines.Add(line);
            sheet.Add(line);

            return(line);
        }
Пример #15
0
        private void AddProductToCart(ItemLine product)
        {
            ItemLine existingProduct = cart.Find(item => item.Item.Name == product.Item.Name);

            if (existingProduct == null)
            {
                cart.Add(product);
            }
            else
            {
                existingProduct.Quantity += product.Quantity;
            }
        }
    public static void AllStockFromJson()
    {
        JArray o1 = JArray.Parse(File.ReadAllText(@"stock.json"));

        foreach (JToken token in o1)
        {
            ItemLine line = new ItemLine();
            line.item.nom_item  = token["nom"].ToString();
            line.item.prix_item = Double.Parse(token["prixHT"].ToString());
            line.quantite_item  = int.Parse(token["quantite"].ToString());

            test.AllLines.Add(line);
        }
    }
        public void MembershipItemProcessorHandleProductItemLine()
        {
            int      customerId         = 4567890;
            ItemLine membershipItemLine = new ItemLine {
                Description = "Book Club Membership", Type = ItemLineType.Product
            };
            SpyMembershipService    membershipService = new SpyMembershipService();
            MembershipItemProcessor itemProcessor     = new MembershipItemProcessor(membershipService);
            Exception result = null;

            result = Assert.Throws <Exception>(() => itemProcessor.HandlePurchaseOrderItem(customerId, membershipItemLine));

            result.ShouldNotBeNull();
            result.Message.ShouldBe("Item must be ItemLineType.Membership");
        }
Пример #18
0
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <returns></returns>
        public ActionResult DeleteData()
        {
            string res = "";

            if (Request["DeleteItem"] == null)
            {
                res = "参数错误!";
            }
            else
            {
                string   item     = Request["DeleteItem"].ToString();
                ItemLine itemLine = JsonConvert.DeserializeObject <ItemLine>(item);
                res = ItemLineService.DeleteEntity(itemLine) ? "删除成功": "删除失败";
            }
            return(Content(res));
        }
Пример #19
0
 void Awake()
 {
     ENTITY_ID++;
     this.Id = ENTITY_ID;
     // load actions
     foreach (ItemLine line in listItems.map)
     {
         // copying the itemline to avoid modifying the entity's original inventory
         ItemLine itemLine = new ItemLine();
         itemLine.item     = line.item;
         itemLine.quantity = line.quantity;
         _inventory.Add(Action.ACTION_KEY[(int)line.item.ActionBound.DefaultCategory], itemLine);
     }
     stats = initialStats;
     life  = stats.maxLife;
 }
Пример #20
0
        public void ItemLineEqualityIsEqual()
        {
            string   itemDesc = "TestLineItem";
            ItemLine sut;
            ItemLine compareSut;
            bool     areEqual;
            bool     equalsAreEqual;

            sut        = new ItemLine(itemDesc, ItemLineType.Product);
            compareSut = new ItemLine(itemDesc, ItemLineType.Product);

            areEqual       = sut == compareSut;
            equalsAreEqual = sut.Equals(compareSut);

            areEqual.ShouldBeTrue();
            equalsAreEqual.ShouldBeTrue();
        }
Пример #21
0
        public ActionResult Add(int id)
        {
            if (Session["cart"] == null)
            {
                Session["cart"] = new Cart()
                {
                    listItemsLine = new List <ItemLine>()
                };
            }

            Cart cart = (Cart)Session["cart"];


            ItemLine itemLine = cart.GetItemLineById(id);

            itemLine.quantity++;
            return(Redirect("~/Cart/index"));
        }
 private void PrintHeader()
 {
     Console.WriteLine($"\nUSER: {_user}");
     Console.WriteLine("\nPRODUCTS:");
     foreach (var item in _catalog)
     {
         Console.WriteLine(item);
     }
     Console.WriteLine("\nCARD:");
     if (_card.Count > 0)
     {
         Console.WriteLine(ItemLine.ToStringHeader());
         _card.Values.ToList().ForEach(Console.WriteLine);
     }
     else
     {
         Console.WriteLine("Empty card");
     }
 }
Пример #23
0
        public void ItemLineNotEqualityIsNotEqual()
        {
            string   itemDesc = "TestLineItem";
            ItemLine sut;
            ItemLine compareSut1;
            ItemLine compareSut2;
            bool     areNotEqual1;
            bool     areNotEqual2;

            sut         = new ItemLine(itemDesc, ItemLineType.Product);
            compareSut1 = new ItemLine("New Item", ItemLineType.Product);
            compareSut2 = new ItemLine(itemDesc, ItemLineType.Membership);

            areNotEqual1 = sut != compareSut1;
            areNotEqual2 = sut != compareSut2;

            areNotEqual1.ShouldBeTrue();
            areNotEqual2.ShouldBeTrue();
        }
Пример #24
0
        public ActionResult Minus(int id)
        {
            if (Session["cart"] == null)
            {
                Session["cart"] = new Cart()
                {
                    listItemsLine = new List <ItemLine>()
                };
            }

            Cart     cart     = (Cart)Session["cart"];
            ItemLine itemLine = cart.GetItemLineById(id);

            itemLine.quantity--;
            if (itemLine.quantity == 0)
            {
                cart.listItemsLine.Remove(itemLine);
            }
            return(Redirect("~/Cart/index"));
        }
Пример #25
0
 private void ReleaseItem()
 {
     if (cart.Count > 0)
     {
         ItemLine item = null;
         while (item == null)
         {
             Console.Write("Product name: ");
             string name = Console.ReadLine();
             item = cart.Find(item => item.Item.Name == name);
         }
         if ((new StockManager()).ReleaseItem(item))
         {
             cart.Remove(item);
             Console.WriteLine($"Product {item.Item.Name} release from the cart");
         }
     }
     else
     {
         Console.WriteLine("The cart is empty");
     }
 }
Пример #26
0
 public void Serialize(StringBuilder sb, ItemLine line, string indent, ItemSerializeOptions options)
 {
     sb.Append(indent);
     sb.Append("LINE");
     sb.Append(options.ModelSeparator);
     sb.Append(line.Id);
     sb.Append(options.ModelSeparator);
     sb.Append(line.X1);
     sb.Append(options.ModelSeparator);
     sb.Append(line.Y1);
     sb.Append(options.ModelSeparator);
     sb.Append(line.X2);
     sb.Append(options.ModelSeparator);
     sb.Append(line.Y2);
     sb.Append(options.ModelSeparator);
     Serialize(sb, line.Stroke, options);
     sb.Append(options.ModelSeparator);
     sb.Append(line.StartId);
     sb.Append(options.ModelSeparator);
     sb.Append(line.EndId);
     sb.Append(options.LineSeparator);
 }
Пример #27
0
        public ActionResult Create(FormViewModel formViewModel)
        {
            var itemLines  = formViewModel.ItemLines;
            var totalPrice = itemLines.Sum(x => Convert.ToDecimal(x.SinglePrice) * Convert.ToInt32(x.Amount));

            // Invoice to Db
            var invoice = new Invoice()
            {
                ApplicationUser    = GetCurrentUser(),
                BuyerName          = formViewModel.Invoice.BuyerName,
                DateCreated        = DateTime.Today,
                DateDue            = formViewModel.Invoice.DateDue,
                TotalPrice         = itemLines.Sum(x => Convert.ToDecimal(x.SinglePrice) * Convert.ToInt32(x.Amount)),
                TotalPriceAfterTax = Core.CalculateTax(totalPrice, formViewModel.TaxCountries[formViewModel.TaxCountriesValue].Text)
            };

            _invoiceRepository.InsertInvoice(invoice);
            _invoiceRepository.Save();


            foreach (var current in itemLines)
            {
                var itemLine = new ItemLine()
                {
                    Description = current.Description,
                    Amount      = current.Amount,
                    SinglePrice = current.SinglePrice,
                    TotalPrice  = current.SinglePrice * current.Amount,
                    Invoice     = invoice
                };

                _itemLineRepository.InsertItemLine(itemLine);
            }

            _itemLineRepository.Save();

            return(RedirectToAction("Index"));
        }
Пример #28
0
        public ItemLine ReserveItem(int quantity, string name)
        {
            ItemLine itemLine = new ItemLine();

            foreach (ItemLine itemline in listItemsCurrent)
            {
                if (itemline.getName().Equals(name))
                {
                    int currentQuantity = itemline.getQuantiy();
                    itemLine = itemline;

                    if (quantity >= currentQuantity)
                    {
                        itemline.setQuantity(0);
                    }
                    else
                    {
                        itemline.setQuantity(currentQuantity - quantity);
                    }
                }
            }
            return(itemLine);
        }
Пример #29
0
    // AI of monster
    #region implemented abstract members of Entity
    public override bool Play(Cell cell)
    {
        Deplacable dep = gameObject.GetComponent <Deplacable> ();

        if (!dep)
        {
            return(false);
        }
        List <Cell> cells = new List <Cell> ();

        // IA heal : if life < 50% of Max life
        if (this.Life < this.MaxLife && this.MaxLife / this.Life > 2)
        {
            foreach (char key in this.Inventory.Keys)
            {
                ItemLine il = this.Inventory [key];
                // if it's a heal action
                if (il.item.ActionBound.GetType().Equals(typeof(HealthAction)))
                {
                    ChangeCurrentAction(key);
                    cells.Add(dep.Cell);
                    return(ExecuteAction(cells));
                }
            }
        }

        // IA Attack
        cells.Add(cell);
        if (CanAttack(cells))
        {
            return(ExecuteAction(cells));
        }

        cells = dep.PathfindingAlgorithm.getPath(dep.Cell, cell);
        ChangeCurrentAction('M');
        return(ExecuteAction(cells));
    }
Пример #30
0
        public ActionResult SaveData()
        {
            string res = "";

            if (Request["SaveItem"] == null || Request["state"] == null)
            {
                res = "缺少参数";
            }
            else
            {
                string   state    = Request["state"].ToString();
                string   item     = Request["SaveItem"].ToString();
                ItemLine itemLine = JsonConvert.DeserializeObject <ItemLine>(item);
                if (state == "add")
                {
                    res = ItemLineService.AddEntity(itemLine) != null ? "添加成功" : "添加失败";
                }
                else if (state == "edit")//修改
                {
                    res = ItemLineService.EditEntity(itemLine) ? "修改成功" : "修改失败";
                }
            }
            return(Content(res));
        }
Пример #31
0
 public unsafe void Load(byte[] buffer)
 {
     if (buffer == null)
     {
         return;
     }
     string theString;
     fixed (byte* pBuffer = &buffer[0])
     {
         theString = BufferReader.ReadString(pBuffer, buffer.Length);
     }
     Tokenizer tokenizer = new Tokenizer(theString, _geometryExpressions, addNewLine: true);
     tokenizer.First();
     Tokenizer.Token token;
     Character currentCharacter;
     while (tokenizer.Current() != null)
     {
         if (tokenizer.Current().Type != EXPRESSION_CHARACTER)
         {
             throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", tokenizer.Current());
         }
         currentCharacter = new Character();
         tokenizer.Next();
         CommonParser.GoToValue(tokenizer);
         if (tokenizer.Current().Type != EXPRESSION_SHAPE)
         {
             throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", tokenizer.Current());
         }
         IShape shape = null;
         token = tokenizer.Next();
         switch (token.Type)
         {
             case EXPRESSION_SHAPE_SOLID:
                 ShapeSolid shapeSolid = new ShapeSolid();
                 shapeSolid.Color = new Color(
                     byte.Parse(token.Match.Groups["C"].Captures[0].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[1].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[2].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[3].Value));
                 shape = shapeSolid;
                 break;
             case EXPRESSION_SHAPE_LINE:
                 ShapeLine shapeLine = new ShapeLine();
                 shapeLine.Width = float.Parse(token.Match.Groups["Width"].Value);
                 shapeLine.Color = new Color(
                     byte.Parse(token.Match.Groups["C"].Captures[0].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[1].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[2].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[3].Value));
                 shape = shapeLine;
                 break;
             case EXPRESSION_SHAPE_TEXTURE:
                 ShapeTexture shapeTexture = new ShapeTexture();
                 shapeTexture.Color = new Color(
                     byte.Parse(token.Match.Groups["C"].Captures[0].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[1].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[2].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[3].Value));
                 shapeTexture.TextureId = uint.Parse(token.Match.Groups["TextureId"].Value);
                 shapeTexture.Rotation = new Matrix2x2(
                     float.Parse(token.Match.Groups["R"].Captures[0].Value),
                     float.Parse(token.Match.Groups["R"].Captures[1].Value),
                     float.Parse(token.Match.Groups["R"].Captures[2].Value),
                     float.Parse(token.Match.Groups["R"].Captures[3].Value));
                 shapeTexture.Translation = new Vector2(
                     float.Parse(token.Match.Groups["T"].Captures[0].Value),
                     float.Parse(token.Match.Groups["T"].Captures[1].Value));
                 shape = shapeTexture;
                 break;
         }
         currentCharacter.TheShape.Type = shape;
         tokenizer.Next();
         CommonParser.GoToValue(tokenizer);
         while ((token = tokenizer.Current()) != null && token.Type != EXPRESSION_CHARACTER)
         {
             IShapeItem item = null;
             switch (token.Type)
             {
                 case EXPRESSION_LINE:
                     ItemLine itemLine = new ItemLine();
                     itemLine.Start = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[0].Value),
                         float.Parse(token.Match.Groups["V"].Captures[1].Value));
                     itemLine.End = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[2].Value),
                         float.Parse(token.Match.Groups["V"].Captures[3].Value));
                     item = itemLine;
                     break;
                 case EXPRESSION_TRIANGLE:
                     ItemTriangle itemTriangle = new ItemTriangle();
                     itemTriangle.V0 = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[0].Value),
                         float.Parse(token.Match.Groups["V"].Captures[1].Value));
                     itemTriangle.V1 = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[2].Value),
                         float.Parse(token.Match.Groups["V"].Captures[3].Value));
                     itemTriangle.V2 = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[4].Value),
                         float.Parse(token.Match.Groups["V"].Captures[5].Value));
                     item = itemTriangle;
                     break;
             }
             currentCharacter.TheShape.Items.Add(item);
             tokenizer.Next();
             CommonParser.GoToValue(tokenizer);
         }
         _characters.Add(currentCharacter);
     }
 }
Пример #32
0
        // 复制册记录
        // parameters:
        //      lIndex  [in] 起点 index
        //              [out] 返回中断位置的 index
        int BuildItemRecords(
            string strItemDbNameParam,
            long lOldCount,
            ref long lProgress,
            ref long lIndex,
            out string strError)
        {
            strError = "";

            int nRet = 0;
            lProgress += lIndex;

            using (SQLiteConnection connection = new SQLiteConnection(this._connectionString))
            {
                connection.Open();

                long lRet = this.Channel.SearchItem(stop,
                    strItemDbNameParam,
                    "", // (lIndex+1).ToString() + "-", // 
                    -1,
                    "__id",
                    "left", // this.textBox_queryWord.Text == "" ? "left" : "exact",    // 原来为left 2007/10/18 changed
                    "zh",
                    null,   // strResultSetName
                    "",    // strSearchStyle
                    "", //strOutputStyle, // (bOutputKeyCount == true ? "keycount" : ""),
                    out strError);
                if (lRet == -1)
                    return -1;
                if (lRet == 0)
                    return 0; 
                
                long lHitCount = lRet;

                AdjustProgressRange(lOldCount, lHitCount);

                long lStart = lIndex;
                long lCount = lHitCount - lIndex;
                DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                // bool bOutputBiblioRecPath = false;
                // bool bOutputItemRecPath = false;
                string strStyle = "";

                {
                    // bOutputBiblioRecPath = true;
                    strStyle = "id,cols,format:@coldef:*/barcode|*/location|*/accessNo|*/parent|*/state|*/operations/operation[@name='create']/@time|*/borrower|*/borrowDate|*/borrowPeriod|*/returningDate|*/price";
                }

                // 实体库名 --> 书目库名
                Hashtable dbname_table = new Hashtable();

                List<ItemLine> lines = new List<ItemLine>();

                // 装入浏览格式
                for (; ; )
                {
                    Application.DoEvents();	// 出让界面控制权

                    if (stop != null && stop.State != 0)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条,用户中断...";
                        return -1;
                    }

                    lRet = this.Channel.GetSearchResult(
                        stop,
                        null,   // strResultSetName
                        lStart,
                        lCount,
                        strStyle, // bOutputKeyCount == true ? "keycount" : "id,cols",
                        "zh",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条," + strError;
                        return -1;
                    }

                    if (lRet == 0)
                    {
                        return 0;
                    }

                    // 处理浏览结果
                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        DigitalPlatform.CirculationClient.localhost.Record searchresult = searchresults[i];

                        ItemLine line = new ItemLine();
                        line.ItemRecPath = searchresult.Path;
                        line.ItemBarcode = searchresult.Cols[0];
                        line.Location = searchresult.Cols[1];
                        line.AccessNo = searchresult.Cols[2];

                        line.State = searchresult.Cols[4];
#if NO
                        try
                        {
                            line.CreateTime = DateTimeUtil.Rfc1123DateTimeStringToLocal(
                                searchresult.Cols[5], "u");
                        }
                        catch
                        {
                        }
#endif
                        line.CreateTime = SQLiteUtil.GetLocalTime(searchresult.Cols[5]);

                        line.Borrower = searchresult.Cols[6];
                        line.BorrowTime = SQLiteUtil.GetLocalTime(searchresult.Cols[7]);
                        line.BorrowPeriod = searchresult.Cols[8];
                        // line.ReturningTime = ItemLine.GetLocalTime(searchresult.Cols[9]);

                        if (string.IsNullOrEmpty(line.BorrowTime) == false)
                        {
                            string strReturningTime = "";
                            // parameters:
                            //      strBorrowTime   借阅起点时间。u 格式
                            //      strReturningTime    返回应还时间。 u 格式
                            nRet = AmerceOperLogLine.BuildReturingTimeString(line.BorrowTime,
                line.BorrowPeriod,
                out strReturningTime,
                out strError);
                            if (nRet == -1)
                            {
                                line.ReturningTime = "";
                            }
                            else
                                line.ReturningTime = strReturningTime;
                        }
                        else
                            line.ReturningTime = "";

                        string strPrice = searchresult.Cols[10];
                        long value = 0;
                        string strUnit = "";
                        nRet = AmerceOperLogLine.ParsePriceString(strPrice,
                out value,
                out strUnit,
                out strError);
                        if (nRet == -1)
                        {
                            line.Price = 0;
                            line.Unit = "";
                        }
                        else
                        {
                            line.Price = value;
                            line.Unit = strUnit;
                        }

                        string strItemDbName = Global.GetDbName(searchresult.Path);
                        string strBiblioDbName = (string)dbname_table[strItemDbName];
                        if (string.IsNullOrEmpty(strBiblioDbName) == true)
                        {
                            strBiblioDbName = this.MainForm.GetBiblioDbNameFromItemDbName(strItemDbName);
                            dbname_table[strItemDbName] = strBiblioDbName;
                        }

                        string strBiblioRecPath = strBiblioDbName + "/" + searchresult.Cols[3];

                        line.BiblioRecPath = strBiblioRecPath;
                        lines.Add(line);
                    }

                    if (true)
                    {
#if NO
                        int nStart = 0;
                        for (;; )
                        {
                            List<ItemLine> lines1 = new List<ItemLine>();
                            int nLength = Math.Min(100, lines.Count - nStart);
                            if (nLength <= 0)
                                break;
                            lines1.AddRange(lines.GetRange(nStart, nLength));
                            // 插入一批记录
                            nRet = ItemLine.AppendItemLines(
                                connection,
                                lines1,
                                true,   // 用 false 可以在测试阶段帮助发现重叠插入问题
                                out strError);
                            if (nRet == -1)
                                return -1;
                            nStart += nLength;
                        }
#endif

                        // 插入一批记录
                        nRet = ItemLine.AppendItemLines(
                            connection,
                            lines,
                            true,   // 用 false 可以在测试阶段帮助发现重叠插入问题
                            out strError);
                        if (nRet == -1)
                            return -1;
                        lIndex += lines.Count;
                        lines.Clear();
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    lProgress += searchresults.Length;
                    // stop.SetProgressValue(lProgress);
                    SetProgress(lProgress);

                    stop.SetMessage(strItemDbNameParam + " " + lStart.ToString() + "/" + lHitCount.ToString() + " "
                        + GetProgressTimeString(lProgress));

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }

                if (lines.Count > 0)
                {
                    Debug.Assert(false, "");
                } 

                return 0;
            }
        }