コード例 #1
0
        public static void FillTransfersLVPreview(IListView listView, IModel model, Entity item, bool ftAquariums = true)
        {
            try {
                ItemType itemType;
                switch (item.EntityType)
                {
                case EntityType.Aquarium:
                    itemType = ItemType.Aquarium;
                    break;

                case EntityType.Inhabitant:
                    var         hItem       = item as Inhabitant;
                    SpeciesType speciesType = model.GetSpeciesType(hItem.SpeciesId);
                    itemType = ALCore.GetItemType(speciesType);
                    break;

                case EntityType.Nutrition:
                    itemType = ItemType.Nutrition;
                    break;

                case EntityType.Device:
                    itemType = ItemType.Device;
                    break;

                case EntityType.Inventory:
                    var invItem = item as Inventory;
                    itemType = ALCore.GetItemType(invItem.Type);
                    break;

                default:
                    itemType = ItemType.None;
                    break;
                }

                int itemId = item.Id;

                listView.BeginUpdate();

                listView.Clear();
                listView.AddColumn(Localizer.LS(LSID.Date), 80, true, BSDTypes.HorizontalAlignment.Left);
                listView.AddColumn(Localizer.LS(LSID.Type), 80, true, BSDTypes.HorizontalAlignment.Left);
                if (ftAquariums)
                {
                    listView.AddColumn(Localizer.LS(LSID.SourceTank), 80, true, BSDTypes.HorizontalAlignment.Left);
                    listView.AddColumn(Localizer.LS(LSID.TargetTank), 80, true, BSDTypes.HorizontalAlignment.Left);
                }
                listView.AddColumn(Localizer.LS(LSID.Quantity), 80, true, BSDTypes.HorizontalAlignment.Right);
                listView.AddColumn(Localizer.LS(LSID.UnitPrice), 80, true, BSDTypes.HorizontalAlignment.Right);
                listView.AddColumn(Localizer.LS(LSID.Shop), 180, true, BSDTypes.HorizontalAlignment.Left);
                listView.AddColumn(Localizer.LS(LSID.Cause), 80, true, BSDTypes.HorizontalAlignment.Left);

                //Font defFont = listView.Font;
                //Font boldFont = new Font(defFont, FontStyle.Bold);

                var records = model.QueryTransfers(itemId, (int)itemType);
                foreach (Transfer rec in records)
                {
                    var    itemRec = model.GetRecord(rec.ItemType, rec.ItemId);
                    string itName  = (itemRec == null) ? string.Empty : itemRec.ToString();
                    string strType = Localizer.LS(ALData.TransferTypes[(int)rec.Type]);

                    IListItem listItem;
                    if (ftAquariums)
                    {
                        Aquarium aqmSour = model.Cache.Get <Aquarium>(ItemType.Aquarium, rec.SourceId);
                        Aquarium aqmTarg = model.Cache.Get <Aquarium>(ItemType.Aquarium, rec.TargetId);

                        listItem = listView.AddItem(rec,
                                                    ALCore.GetDateStr(rec.Timestamp),
                                                    strType,
                                                    (aqmSour == null) ? string.Empty : aqmSour.Name,
                                                    (aqmTarg == null) ? string.Empty : aqmTarg.Name,
                                                    rec.Quantity.ToString(),
                                                    ALCore.GetDecimalStr(rec.UnitPrice),
                                                    rec.Shop,
                                                    rec.Cause
                                                    );
                    }
                    else
                    {
                        listItem = listView.AddItem(rec,
                                                    ALCore.GetDateStr(rec.Timestamp),
                                                    strType,
                                                    rec.Quantity.ToString(),
                                                    ALCore.GetDecimalStr(rec.UnitPrice),
                                                    rec.Shop,
                                                    rec.Cause
                                                    );
                    }

                    if (itemType == ItemType.Aquarium)
                    {
                        //listItem.Font = boldFont;
                    }

                    switch (rec.Type)
                    {
                    case TransferType.Sale:
                        listItem.SetForeColor(BSDConsts.Colors.DimGray);
                        break;

                    case TransferType.Death:
                    case TransferType.Exclusion:
                        listItem.SetForeColor(BSDConsts.Colors.Gray);
                        break;
                    }
                }

                listView.EndUpdate();
            } catch (Exception ex) {
                fLogger.WriteError("FillTransfersLV()", ex);
            }
        }