Beispiel #1
0
        void OnCheckedItemsChanged(object sender, ListChangedEventArgs e)
        {
            foreach (string item in CheckedItems)
            {
                if (CurveList.IndexOfTag(item) < 0)
                {
                    AddItem(item);
                }
            }

            List <string> itemsToRemove = new List <string>();

            foreach (LogGraphCurveItem item in CurveList)
            {
                if (!CheckedItems.Contains(item.ItemID))
                {
                    itemsToRemove.Add(item.ItemID);
                }
            }

            foreach (string item in itemsToRemove)
            {
                RemoveItem(item);
            }
        }
Beispiel #2
0
        internal void LoadSettings(PaneSettings ps)
        {
            ps.GridLineItem = m_MappedItem;
            LoadAxisSettings(ps.XAxis, XAxis);
            LoadAxisSettings(ps.X2Axis, X2Axis);
            LoadAxisSettings(ps.YAxis, YAxis);
            LoadAxisSettings(ps.Y2Axis, Y2Axis);

            foreach (ItemSettings item in ps.Items)
            {
                item.ID = FixItemID(item.ID);
                CheckedItems.RaiseListChangedEvents = false;
                CheckedItems.Add(item.ID);
                CheckedItems.RaiseListChangedEvents = true;
                LogGraphCurveItem logitem = AddCuveItem(item.ID, Color.FromArgb(item.Color));

                logitem.IsX2Axis         = item.AssignedToX2Axis;
                logitem.IsY2Axis         = item.AssignedToY2Axis;
                logitem.Symbol.IsVisible = item.ShowSymbol;
                logitem.DrawInfinitely   = item.DrawInfinitely;
            }

            SetThreshold((string.IsNullOrWhiteSpace(ps.Threshold) ? null : (double?)double.Parse(ps.Threshold)));

            m_HasChanged = false;
            AxisChange();
        }
 public void SwitchSelectedActions()
 {
     if (BreakCrossingObjects)
     {
         BreakCrossingObjects = false;
         foreach (var checkWrapper in Items)
         {
             checkWrapper.IsChecked = true;
         }
     }
     else
     {
         if (CheckedItems.Count() != Items.Count)
         {
             foreach (var checkWrapper in Items)
             {
                 checkWrapper.IsChecked = !checkWrapper.IsChecked;
             }
         }
         else
         {
             BreakCrossingObjects = true;
         }
     }
 }
        void OrderList_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue != CheckState.Checked || _suspendCheckEvent)
            {
                return;
            }

            _suspendCheckEvent = true;

            var item = Items[e.Index];

            //取消其它订单的选择
            CheckedItems.Cast <OrderTicketListViewItem>()
            .Where(s => s.Group != item.Group)
            .ToArray().ForEach(s => s.Checked = false);
            //如果是未完成订单,则同时选择
            var titem = (item as OrderTicketListViewItem).Ticket;

            if (titem.OrderStatus == OrderStatus.NotPay || titem.OrderStatus == OrderStatus.ResignNotPaid || titem.OrderStatus == OrderStatus.Queue)
            {
                Items.Cast <OrderTicketListViewItem>()
                .Where(s => s != item && s.Group == item.Group)
                .ForEach(s => s.Checked = true);
            }
            _suspendCheckEvent = false;
        }
Beispiel #5
0
 public long sumChecked()
 {
     return(
         CheckedItems
         .Cast <ListViewItem>()
         .Select(i => ((KeyValuePair <String, List <IDownloadableResourceFile> >)(i.Tag)).Value[0].size)
         .Sum()
         );
 }
Beispiel #6
0
        private void CheckBoxTreeViewItem_Unchecked(object sender, RoutedEventArgs e)
        {
            TViewItem checkBoxTreeViewItem = sender as TViewItem;
            Action    action = () =>
            {
                CheckedItems.Remove((TreeViewItemViewModel)checkBoxTreeViewItem.Header);
            };

            this.Dispatcher.BeginInvoke(action, DispatcherPriority.ContextIdle);
        }
Beispiel #7
0
 private void UpdateCollections()
 {
     if (CheckedItems != null)
     {
         CheckedItems.Refresh();
     }
     if (CheckedIndices != null)
     {
         CheckedIndices.Refresh();
     }
 }
Beispiel #8
0
 public IList <Tuple <IDownloadableResourceFile, String> > listChecked()
 {
     return(
         CheckedItems
         .Cast <ListViewItem>()
         .Select(
             (i) => {
         KeyValuePair <String, List <IDownloadableResourceFile> > kvp = (KeyValuePair <String, List <IDownloadableResourceFile> >)(i.Tag);
         return (new Tuple <IDownloadableResourceFile, String>(kvp.Value[0], kvp.Key));
     }
             )
         .ToList()
         );
 }
Beispiel #9
0
        private void CheckedListBoxOnItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue == CheckState.Checked)
            {
                _checkedIndices.Add(e.Index);
                CheckedItems.Add(_checkedListBox.Items[e.Index]);
            }
            else
            {
                _checkedIndices.Remove(e.Index);
                CheckedItems.Remove(_checkedListBox.Items[e.Index]);
            }

            ItemChecked?.Invoke(this, EventArgs.Empty);

            Invalidate();
        }
        public TodoListViewModel(IEnumerable <TodoItem> _items)
        {
            this.items = _items;
            // Items = new ReactiveList<TodoItem>(items);
            // CheckedItems =
            //Items = new ObservableCollection<TodoItem>(items);

            //CheckedItems = new ObservableCollection<TodoItem>(
            //    Items.Where((todoItem) => todoItem.IsChecked)
            //);

            foreach (var item in Items)
            {
                item.Changed.Subscribe((model) => {
                    CheckedItems.Clear();
                    CheckedItems.AddRange(Items.Where((todoItem) => todoItem.IsChecked));
                });
            }
        }
Beispiel #11
0
        private void DeletedAssets_ItemPropertyChanged(object sender, ItemPropertyChangedEventArgs e)
        {
            TVDeletedAssetViewModel _asset = DeletedAssets[e.CollectionIndex];

            if (CheckedItems.Contains(_asset.Asset))
            {
                if (_asset.IsChecked == false)
                {
                    CheckedItems.Remove(_asset.Asset);
                }
            }
            else
            {
                if (_asset.IsChecked == true)
                {
                    CheckedItems.Add(_asset.Asset);
                }
            }
        }
        void CheckBoxTreeViewItemChecked(object sender, RoutedEventArgs e)
        {
            CheckBoxTreeViewItem checkBoxTreeViewItem = sender as CheckBoxTreeViewItem;
            Action action = () =>
            {
                if (checkBoxTreeViewItem == null)
                {
                    return;
                }

                var checkedItem = checkBoxTreeViewItem.Header;
                if (!checkedItem.GetType().Name.Equals("NamedObject"))
                {
                    CheckedItems.Add(checkedItem);
                }
            };

            Dispatcher.BeginInvoke(action, DispatcherPriority.ContextIdle);
        }
Beispiel #13
0
        private void ListView_KeyDown(object sender, KeyEventArgs e)
        {
            FocusedItemKeyDown = FocusedItem;

            // Check selected items when Shift Up/Down
            if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
            {
                if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up)
                {
                    FocusedItem.Checked = !FocusedItem.Checked;
                }
            }

            //Check all items
            if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
            {
                if (e.KeyCode == Keys.A || e.KeyCode == Keys.Add)
                {
                    foreach (ListViewItem item in Items.Cast <ListViewItem>())
                    {
                        item.Checked = true;
                    }
                }
                //Uncheck all items
                if (e.KeyCode == Keys.Subtract)
                {
                    foreach (ListViewItem item in CheckedItems.Cast <ListViewItem>())
                    {
                        item.Checked = false;
                    }
                }
                //Invert all items
                if (e.KeyCode == Keys.Multiply)
                {
                    foreach (ListViewItem item in Items.Cast <ListViewItem>())
                    {
                        item.Checked = !item.Checked;
                    }
                }
            }
        }
Beispiel #14
0
        private void checkedListBoxSeries_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            int      index = e.Index;
            DBSeries item  = (DBSeries)checkedListBoxSeries.Items[index];

            // Add/Remove items from list
            if (item != null)
            {
                // Item state before item was clicked
                if (checkedListBoxSeries.GetItemChecked(index))
                {
                    // Store items changes
                    if (!UnCheckedItems.Contains(item))
                    {
                        UnCheckedItems.Add(item);
                    }
                    if (CheckedItems.Contains(item))
                    {
                        CheckedItems.Remove(item);
                    }

                    CheckedCount            -= 1;
                    labelSeriesSelected.Text = (CheckedCount).ToString() + " Series Selected";
                }
                else
                {
                    // Store items changes
                    if (!CheckedItems.Contains(item))
                    {
                        CheckedItems.Add(item);
                    }
                    if (UnCheckedItems.Contains(item))
                    {
                        UnCheckedItems.Remove(item);
                    }

                    CheckedCount            += 1;
                    labelSeriesSelected.Text = (CheckedCount).ToString() + " Series Selected";
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// 将一个数据对象绑定到 <see cref="TreeList"/>
        /// </summary>
        /// <param name="dataSource"></param>
        public void DataBind(object dataSource)
        {
            this.dataSource = dataSource;

            BeginUpdate();

            var selectKeyValues = GetSelectedItems();

            Items.Clear();
            SelectedItems.InternalClear();
            CheckedItems.InternalClear();

            if (dataSource == null)
            {
                EndUpdate();
                return;
            }

            if (dataSource is DataSet)
            {
                var ds = (DataSet)dataSource;
                if (ds.Tables.Count > 0)
                {
                    BindDataTable(ds.Tables[0]);
                }
            }
            if (dataSource is DataTable)
            {
                BindDataTable((DataTable)dataSource);
            }
            else if (dataSource is IEnumerable)
            {
                BindEnumerable((IEnumerable)dataSource);
            }

            EndUpdate();

            ReSelectItems(selectKeyValues);
        }
        private void AtualizaChecked(GIInputCheckbox item)
        {
            var codInt = item.Tag.ToString();
            var split  = CheckedItems.Split(',');

            if (item.IsChecked == true)
            {
                var teste = split.FirstOrDefault(p => p.Trim().Equals(codInt));
                if (teste == null)
                {
                    CheckedItems += ", " + codInt;
                }
            }
            else
            {
                var teste = split.FirstOrDefault(p => p.Trim().Equals(codInt));
                if (teste != null)
                {
                    CheckedItems = CheckedItems.Replace(teste.ToString(), "");
                    CheckedItems = CheckedItems.Replace(",,", ",");
                    CheckedItems = CheckedItems.Replace("  ", " ");
                    CheckedItems = CheckedItems.Replace(" ,", ",");
                    CheckedItems = CheckedItems.Trim();

                    if (CheckedItems.Trim().StartsWith(","))
                    {
                        CheckedItems = CheckedItems.Remove(CheckedItems.IndexOf(","), 1);
                    }


                    if (CheckedItems.Trim().EndsWith(","))
                    {
                        CheckedItems = CheckedItems.Remove(CheckedItems.LastIndexOf(","));
                    }
                }
            }
        }
        public async Task <bool> IsDirty()
        {
            bool res = false;

            if (CheckedItems != null && SavedItems != null)
            {
                int checkedItems = CheckedItems.Where(i => i.IsChecked == true).Count();
                int savedItems   = SavedItems.Count(i => i.IsChecked == true);
                if (checkedItems > savedItems)
                {
                    res = true;
                }
                else
                {
                    foreach (ProcessAction pa in CheckedItems.Where(i => i.IsChecked == true))
                    {
                        if (pa.ProcessActionId == 0)
                        {
                            //it's action user checked voluntarily
                            //on the whole, items without id definitely haven't been saved yet
                            res = true;
                            break;
                        }
                        else if (SavedItems.Any(i => i.ProcessActionId == pa.ProcessActionId && i.IsChecked == false))
                        {
                            //there's at least 1 item that IsChecked=true in CheckedItems that wasn't checked in saved items

                            res = true;
                            break;
                        }
                    }
                }
            }

            return(res);
        }
Beispiel #18
0
 private void UpdateCollections()
 {
     CheckedItems.Refresh();
     CheckedIndices.Refresh();
 }
Beispiel #19
0
 public void UpdateCheckedItemsDescription()
 {
     CheckedItemsDescription = string.Join(", ", CheckedItems.Select(i => i.ToString()));
 }
 /// --------------------------------------------------------------------------------------------
 public IEnumerable <string> GetTextsOfCheckedItems()
 {
     return(CheckedItems.Select(i => i.Text.Replace(App.DottedCircle, string.Empty)));
 }
Beispiel #21
0
        public void GeneratorCode()
        {
            var webApiCode = string.Empty;
            var @class     = EntityName.ToLower();
            var Class      = EntityName;

            webApiCode += $"var {ProjectName};\r\n";
            webApiCode += $"(function ({ProjectName}) {{\r\n";
            webApiCode += $"\t'use strict';\r\n";
            webApiCode += $"\t{ProjectName}.{Class}Api = function (e) {{\r\n";
            webApiCode += $"\t\tvar EMPTY_STRING = '';\r\n";
            webApiCode += $"\t\tvar f = '@OData.Community.Display.V1.FormattedValue';\r\n";
            var webapi = Utility.ReadEmbeddedResource("DynamicsCrm.DevKit.Resources.WebApi.js");

            webApiCode += webapi;
            webApiCode += $"\t\tvar {@class} = {{\r\n";
            foreach (var crmAttribute in Fields)
            {
                if (crmAttribute.IsDeprecated)
                {
                    continue;
                }
                if (crmAttribute.AttributeOf != null && crmAttribute.FieldType == AttributeTypeCode.Virtual && crmAttribute.LogicalName != "entityimage")
                {
                    continue;
                }
                if (crmAttribute.FieldType == AttributeTypeCode.EntityName || crmAttribute.FieldType == AttributeTypeCode.PartyList)
                {
                    continue;
                }
                if (crmAttribute.AttributeOf != null && crmAttribute.AttributeOf.ToLower() + "name" == crmAttribute.LogicalName)
                {
                    continue;
                }
                if (crmAttribute.AttributeOf != null && crmAttribute.LogicalName.EndsWith("yominame") && !crmAttribute.IsValidForCreate && !crmAttribute.IsValidForUpdate)
                {
                    continue;
                }
                if (crmAttribute.FieldType == AttributeTypeCode.Memo ||
                    crmAttribute.FieldType == AttributeTypeCode.String ||
                    crmAttribute.FieldType == AttributeTypeCode.Picklist ||
                    crmAttribute.FieldType == AttributeTypeCode.State ||
                    crmAttribute.FieldType == AttributeTypeCode.Status ||
                    crmAttribute.FieldType == AttributeTypeCode.Uniqueidentifier ||
                    crmAttribute.FieldType == AttributeTypeCode.Boolean ||
                    crmAttribute.FieldType == AttributeTypeCode.Integer ||
                    crmAttribute.FieldType == AttributeTypeCode.BigInt ||
                    crmAttribute.FieldType == AttributeTypeCode.Double ||
                    crmAttribute.FieldType == AttributeTypeCode.Decimal ||
                    crmAttribute.FieldType == AttributeTypeCode.Money
                    )
                {
                    webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                }
                else if (crmAttribute.IsMultiSelectPicklist)
                {
                    webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: \"{crmAttribute.LogicalName}\", g: true }},\r\n";
                }
                else if (crmAttribute.FieldType == AttributeTypeCode.DateTime)
                {
                    if (crmAttribute.DateTimeBehavior == DateTimeBehavior.DateOnly)
                    {
                        webApiCode += $"\t\t\t{crmAttribute.SchemaName}_DateOnly: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                    }
                    else if (crmAttribute.DateTimeBehavior == DateTimeBehavior.TimeZoneIndependent)
                    {
                        if (crmAttribute.DateTimeFormat == DateTimeFormat.DateOnly)
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}_TimezoneDateOnly: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                        }
                        else
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}_TimezoneDateAndTime: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                        }
                    }
                    else if (crmAttribute.DateTimeBehavior == DateTimeBehavior.UserLocal)
                    {
                        if (crmAttribute.DateTimeFormat == DateTimeFormat.DateOnly)
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}_UtcDateOnly: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                        }
                        else
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}_UtcDateAndTime: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                        }
                    }
                }
                else if (crmAttribute.FieldType == AttributeTypeCode.Lookup ||
                         crmAttribute.FieldType == AttributeTypeCode.Customer)
                {
                    var entities = crmAttribute.EntityReferenceLogicalName.Split(";".ToCharArray());
                    crmAttribute.LogicalCollectionName  = GetLogicalCollectionName(crmAttribute);
                    crmAttribute.NavigationPropertyName = GetNavigationPropertyName(crmAttribute);
                    var collections = crmAttribute.LogicalCollectionName.Split(";".ToCharArray());
                    var navigations = crmAttribute.NavigationPropertyName.Split(";".ToCharArray());
                    if (entities.Length == 1)
                    {
                        if (crmAttribute.IsCustomAttribute)
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ b: \"{crmAttribute.SchemaName}\", a: \"_{crmAttribute.LogicalName}_value\", c: \"{collections[0]}\", d: \"{entities[0]}\" }},\r\n";
                        }
                        else
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ b: \"{crmAttribute.LogicalName}\", a: \"_{crmAttribute.LogicalName}_value\", c: \"{collections[0]}\", d: \"{entities[0]}\" }},\r\n";
                        }
                    }
                    else
                    {
                        if (entities.Length != collections.Length ||
                            entities.Length != navigations.Length ||
                            collections.Length != navigations.Length)
                        {
                            continue;
                        }
                        var j = 0;
                        foreach (var e in entities)
                        {
                            if (crmAttribute.EntityName == "audit" && e == "externalparty")
                            {
                                continue;
                            }
                            webApiCode += $"\t\t\t{navigations[j]}: {{ b: \"{navigations[j]}\", a: \"_{crmAttribute.LogicalName}_value\", c: \"{collections[j]}\", d: \"{entities[j]}\" }},\r\n";
                            j++;
                        }
                    }
                }
                else if (crmAttribute.FieldType == AttributeTypeCode.Owner)
                {
                    webApiCode += $"\t\t\tOwnerId_systemuser: {{ b: \"ownerid\", a: \"_ownerid_value\", c: \"systemusers\", d: \"systemuser\" }},\r\n";
                    webApiCode += $"\t\t\tOwnerId_team: {{ b: \"ownerid\", a: \"_ownerid_value\", c: \"teams\", d: \"team\" }},\r\n";
                }
                else if (crmAttribute.FieldType == AttributeTypeCode.ManagedProperty)
                {
                    webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                }
                else
                {
                    if (crmAttribute.SchemaName == "EntityImage" ||
                        crmAttribute.SchemaName == "FullImageData" ||
                        crmAttribute.SchemaName == "ImageData")
                    {
                        webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                    }
                    else
                    {
                        webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: ?????????? }},\r\n";
                    }
                }
                if (!(crmAttribute.IsValidForCreate || crmAttribute.IsValidForUpdate))
                {
                    webApiCode  = webApiCode.TrimEnd(" },\r\n".ToCharArray());
                    webApiCode += $", r: true }},\r\n";
                }
            }
            webApiCode  = webApiCode.TrimEnd(",\r\n".ToCharArray()) + "\r\n";
            webApiCode += $"\t\t}};\r\n";
            webApiCode += $"\t\tif (e === undefined) e = {{}};\r\n";
            webApiCode += $"\t\tvar u = {{}};\r\n";
            webApiCode += $"\t\tfor (var field in {@class}) {{\r\n";
            webApiCode += $"\t\t\tvar a = {@class}[field].a;\r\n";
            webApiCode += $"\t\t\tvar b = {@class}[field].b;\r\n";
            webApiCode += $"\t\t\tvar c = {@class}[field].c;\r\n";
            webApiCode += $"\t\t\tvar d = {@class}[field].d;\r\n";
            webApiCode += $"\t\t\tvar g = {@class}[field].g;\r\n";
            webApiCode += $"\t\t\tvar r = {@class}[field].r;\r\n";
            webApiCode += $"\t\t\t{@class}[field] = webApiField(e, a, b, c, d, r, u, g);\r\n";
            webApiCode += $"\t\t}}\r\n";
            var hasPartyList = Fields.Where(f => f.FieldType == AttributeTypeCode.PartyList).Any();

            if (hasPartyList)
            {
                var logicalName = IsCustomEntity ? $"{Class}_activity_parties" : $"{@class}_activity_parties";
                webApiCode += $"\t\tObject.defineProperty({@class}, 'ActivityParties', {{\r\n";
                webApiCode += $"\t\t\tget: function () {{ return e['{logicalName}']; }},\r\n";
                webApiCode += $"\t\t\tset: function (value) {{\r\n";
                webApiCode += $"\t\t\t\te['{logicalName}'] = value;\r\n";
                webApiCode += $"\t\t\t\tu['{logicalName}'] = value;\r\n";
                webApiCode += $"\t\t\t}}\r\n";
                webApiCode += $"\t\t}});\r\n";
            }
            webApiCode += $"\t\t{@class}.Entity = u;\r\n";
            webApiCode += $"\t\t{@class}.EntityName = \"{@class}\";\r\n";
            webApiCode += $"\t\t{@class}.EntityCollectionName = \"{GetLogicalCollectionName(@class)}\";\r\n";
            webApiCode += $"\t\t{@class}[\"@odata.etag\"] = e[\"@odata.etag\"];\r\n";
            //webApiCode += JsOptionSetFormCode;
            //webApiCode += $"\t\t{@class}.OptionSet = optionSet;\r\n";
            webApiCode += $"\t\t{@class}.getAliasedValue = function (alias, isMultiOptionSet) {{\r\n";
            webApiCode += $"\t\t\tif (e[alias] === undefined || e[alias] === null) {{\r\n";
            webApiCode += $"\t\t\t\treturn null;\r\n";
            webApiCode += $"\t\t\t}}\r\n";
            webApiCode += $"\t\t\tif (isMultiOptionSet) {{\r\n";
            webApiCode += $"\t\t\t\treturn e[alias].toString().split(',').map(function (item) {{ return parseInt(item, 10); }});\r\n";
            webApiCode += $"\t\t\t}}\r\n";
            webApiCode += $"\t\t\treturn e[alias];\r\n";
            webApiCode += $"\t\t}}\r\n";
            webApiCode += $"\t\t{@class}.getAliasedFormattedValue = function (alias, isMultiOptionSet) {{\r\n";
            webApiCode += $"\t\t\tif (e[alias + f] === undefined || e[alias + f] === null) {{\r\n";
            webApiCode += $"\t\t\t\treturn EMPTY_STRING;\r\n";
            webApiCode += $"\t\t\t}}\r\n";
            webApiCode += $"\t\t\tif (isMultiOptionSet) {{\r\n";
            webApiCode += $"\t\t\t\treturn e[alias + f].toString().split(';').map(function (item) {{ return item.trim(); }});\r\n";
            webApiCode += $"\t\t\t}}\r\n";
            webApiCode += $"\t\t\treturn e[alias + f];\r\n";
            webApiCode += $"\t\t}}\r\n";
            webApiCode += $"\t\treturn {@class};\r\n";
            webApiCode += $"\t}};\r\n";
            webApiCode += $"}})({ProjectName} || ({ProjectName} = {{}}));";
            webApiCode  = webApiCode.Replace("\"", "'");
            webApiCode  = webApiCode.Replace("'*'", "\"*\"");
            if (!IsDebugWebApi)
            {
                webApiCode = Uglify.Js(webApiCode).Code;
                webApiCode = webApiCode.Replace("\"", "'");
                webApiCode = webApiCode.Replace("'*'", "\"*\"");
            }
            var code = string.Empty;

            code += $"'use strict';\r\n";
            code += $"/** @namespace {ProjectName} */\r\n";
            code += webApiCode;
            code  = code + "\r\n";
            var optionSet = Utility.ReadEmbeddedResource("DynamicsCrm.DevKit.Resources.OptionSet.js");

            optionSet = optionSet.Replace("[[EntityOptionSet]]", OptionSet_For_d_ts);
            var optionSetMin = optionSet;

            if (!IsDebugWebApi)
            {
                optionSetMin = Uglify.Js(optionSet).Code;
            }
            code      += $"/** @namespace OptionSet */\r\n";
            code      += optionSetMin;
            WebApiCode = code;
            var processForms = new List <SystemForm>();

            foreach (var form in Forms)
            {
                if (CheckedItems.Contains($"{form.Name}"))
                {
                    processForms.Add(form);
                }
            }
            WebApiCodeTypeScriptDeclaration = GetWebApiCodeTypeScriptDeclaration(processForms, IsDebugForm, true, IsDebugWebApi);
        }
        public async Task <string> Save(int handlingId, int processId, int?abandonReason = null)
        {
            try
            {
                Logger.Info("ActionListViewModel is starting. HandlingId={handlingId}, ProcessId={processId}, AbandonReason={abandonReason}", handlingId, processId, abandonReason);

                List <Task <string> > listOfTask = new List <Task <string> >();
                foreach (ProcessAction pa in CheckedItems.Where(i => i.IsMutable == true))
                {
                    Logger.Info("ProcessAction: ID={ProcessActionId}, IsChecked={IsChecked}, IsMutable={IsMutable}", pa.ProcessActionId, pa.IsChecked, pa.IsMutable);
                    pa.HandlingId = handlingId;
                    pa.ProcessId  = processId;
                    if (pa.IsChecked == false || pa.IsChecked == null)
                    {
                        pa.AbandonReasonId = abandonReason;
                    }

                    if (pa.IsMutable == true && (pa.IsChecked == true || (pa.IsChecked == false && abandonReason != null)))
                    {
                        //save changes to process action only when it's mutable and:
                        //- it's checked
                        //- it's not checked and the user provided a reason why he abandoned it

                        if (pa.ProcessActionId == 0)
                        {
                            listOfTask.Add(pa.Add());
                        }
                        else
                        {
                            listOfTask.Add(pa.Edit());
                        }
                    }
                }

                IEnumerable <string> results = await Task.WhenAll <string>(listOfTask);

                Task.Run(() => TakeSnapshot());
                if (results.Where(r => r != "OK").Any())
                {
                    return(string.Join("; ", results.Where(r => r != "OK")));
                }
                else
                {
                    return("OK");
                }
            }
            catch (InvalidCastException ex)
            {
                Logger.Error(ex);
                string additionalInfo = $"handlingId={handlingId}, processId={processId}, abandonReason={abandonReason}";
                Static.Functions.CreateError(ex, "InvalidCast", nameof(this.Save), this.GetType().Name, additionalInfo);
                return(ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                string additionalInfo = $"handlingId={handlingId}, processId={processId}, abandonReason={abandonReason}";
                Static.Functions.CreateError(ex, "No connection", nameof(this.Save), this.GetType().Name, additionalInfo);
                return(ex.Message);
            }
        }
        public async Task <bool> Initialize()
        {
            //get all the placeActions of this placeId and processActions for this process
            //and fill the list in

            try
            {
                CheckedItems = new ObservableCollection <ProcessAction>();
                Items        = new ObservableCollection <IActionKeeper>();

                if (ProcessId != 0)
                {
                    var processReload = Task.Run(() => ProcessActionKeeper.Reload($"ProcessId={ProcessId}"));
                    var placeReload   = Task.Run(() => PlaceActionKeeper.Reload($"PlaceId={PlaceId}"));

                    //go no further till both tasks complete
                    await Task.WhenAll(processReload, placeReload);

                    CheckedItems = new ObservableCollection <ProcessAction>(ProcessActionKeeper.Items);
                    Items        = new ObservableCollection <IActionKeeper>(CheckedItems);
                    foreach (var item in Items)
                    {
                        if ((bool)item.IsChecked)
                        {
                            //if item has been saved as checked, don't let anyone change it
                            item.IsMutable = false;
                        }
                    }
                }
                else
                {
                    var placeReload = Task.Run(() => PlaceActionKeeper.Reload($"PlaceId={PlaceId}"));

                    //go no further till task complete
                    await Task.WhenAll(placeReload);
                }


                foreach (PlaceAction p in PlaceActionKeeper.Items)
                {
                    if (!CheckedItems.Any(i => i.ActionId == p.ActionId))
                    {
                        Items.Add(p);
                    }
                }
                IsInitialized = true;
                Task.Run(() => TakeSnapshot());
                if (Items.Any())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #24
0
 public IEnumerable <T> GetCheckedItemsAsIEnumerable()
 {
     return(CheckedItems.Cast <T>().ToList());
 }