Beispiel #1
0
        /// <summary>
        /// Valida antes de iniciar la edición
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 12/07/2016
        /// </history>
        private void dgr_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
        {
            var grid = (DataGrid)sender;

            if (!GridHelper.IsInEditMode(sender as DataGrid))
            {
                switch (e.Column.SortMemberPath)
                {
                case "GiftItem.giN":
                {
                    GiftPackageItem giftPackageItem = (GiftPackageItem)e.Row.Item;
                    if (giftPackageItem.gpQty < 1)
                    {
                        e.Cancel = true;
                        UIHelper.ShowMessage("Quantity can not be lower than 1.");
                        grid.CurrentCell    = new DataGridCellInfo(grid.SelectedItem, grid.Columns[0]);
                        grid.BeginningEdit -= dgr_BeginningEdit;
                        grid.BeginEdit();
                        grid.BeginningEdit += dgr_BeginningEdit;
                    }
                    break;
                }
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Obtiene los paquetes de gifts
        /// </summary>
        /// <returns></returns>
        /// <history>
        /// [vipacheco] 07/Julio/2016 Created
        /// [emoguel] modified 18/07/2016
        /// </history>
        public async static Task <List <GiftPackageItem> > GetGiftsPacks(GiftPackageItem giftPackageItem = null, bool blnIncludeGift = false)
        {
            return(await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    var query = from gp in dbContext.GiftsPackagesItems
                                select gp;

                    if (blnIncludeGift)
                    {
                        query = query.Include(gp => gp.GiftItem);
                    }
                    if (giftPackageItem != null)
                    {
                        if (!string.IsNullOrWhiteSpace(giftPackageItem.gpPack))
                        {
                            query = query.Where(gp => gp.gpPack == giftPackageItem.gpPack);
                        }
                    }

                    return query.OrderBy(gp => gp.gpgi).ToList();
                }
            }));
        }
Beispiel #3
0
        /// <summary>
        /// Cancela o finalizá la edicion de un registro
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 09/07/2016
        /// </history>
        private void dgr_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            DataGrid dgr = sender as DataGrid;

            if (e.EditAction == DataGridEditAction.Commit)
            {
                if (dgr.CurrentColumn != null)
                {
                    switch (dgr.CurrentColumn.SortMemberPath)
                    {
                    case "gpQty":
                    {
                        GiftPackageItem giftInPack = (GiftPackageItem)e.Row.Item;
                        if (giftInPack.gpQty < 1)
                        {
                            e.Cancel = true;
                            UIHelper.ShowMessage("Quantity can no be lower than 1.");
                        }
                        else if (string.IsNullOrWhiteSpace(giftInPack.gpgi))
                        {
                            e.Cancel = true;
                            UIHelper.ShowMessage("Please Select a Gift.");
                        }
                        break;
                    }

                    case "GiftItem.giN":
                    {
                        GiftPackageItem giftPackage = (GiftPackageItem)e.Row.Item;
                        if (giftPackage.GiftItem == null)
                        {
                            UIHelper.ShowMessage("Please select a Gift");
                            e.Cancel = true;
                        }
                        break;
                    }

                    default:
                    {
                        dgr.RowEditEnding -= dgr_RowEditEnding;
                        if (_isCellCancel)
                        {
                            dgr.CancelEdit();
                        }
                        else
                        {
                            dgr.CommitEdit();
                            dgr.Items.Refresh();
                            GridHelper.SelectRow(dgr, dgr.SelectedIndex);
                        }
                        dgr.RowEditEnding += dgr_RowEditEnding;
                        _isCellCancel      = false;
                        break;
                    }
                    }
                }
                else if (dgr.Name == "dgrGiftInPack")
                {
                    GiftPackageItem giftPackage = (GiftPackageItem)e.Row.Item;
                    if (giftPackage.GiftItem == null)
                    {
                        e.Cancel = true;
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Verifica que no se repitam registros en la lista
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 09/07/2016
        /// </history>
        private void dgr_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                DataGrid dgr = sender as DataGrid;
                switch (e.Column.SortMemberPath)
                {
                case "loN":
                {
                    _isCellCancel = false;
                    var  cp          = (ContentPresenter)e.EditingElement;
                    var  combo       = (ComboBox)cp.ContentTemplate.FindName("cmbLocations", cp);
                    bool blnIsRepeat = GridHelper.HasRepeatItem(combo, dgr, true);
                    if (!blnIsRepeat)
                    {
                        dtcLocations.Header = "Locations (" + (dgr.Items.Count - 1) + ")";
                    }
                    e.Cancel = blnIsRepeat;
                    break;
                }

                case "agID":
                {
                    _isCellCancel = false;
                    bool blnIsRepeat = GridHelper.HasRepeatItem((Control)e.EditingElement, dgr);
                    if (!blnIsRepeat)
                    {
                        cmbAgencies.Header = "Agencies (" + (dgr.Items.Count - 1) + ")";
                    }
                    e.Cancel = blnIsRepeat;
                    break;
                }

                case "GiftItem.giN":
                {
                    dgr.RowEditEnding -= dgr_RowEditEnding;
                    var  cp          = (ContentPresenter)e.EditingElement;
                    var  combo       = (ComboBox)cp.ContentTemplate.FindName("cmbGiftPack", cp);
                    bool blnIsRepeat = GridHelper.HasRepeatItem(combo, dgrGiftInPack, false, "gpgi");
                    if (!blnIsRepeat)
                    {
                        GiftPackageItem giftPackage = (GiftPackageItem)e.Row.Item;
                        giftPackage.GiftItem = new Gift();
                        Gift giftSelected = (Gift)combo.SelectedItem;
                        ObjectHelper.CopyProperties(giftPackage.GiftItem, giftSelected);
                        giftPackage.gpgi   = giftSelected.giID;
                        dtcGiftPack.Header = "Gift In Pack (" + (dgr.Items.Count - 1) + ")";
                    }
                    else
                    {
                        dgr.Focus();
                        combo.Focus();
                    }
                    e.Cancel           = blnIsRepeat;
                    dgr.RowEditEnding += dgr_RowEditEnding;
                    break;
                }

                case "gpQty":
                {
                    TextBox txt = (TextBox)e.EditingElement;
                    if (string.IsNullOrWhiteSpace(txt.Text) || Convert.ToInt32(txt.Text) < 1)
                    {
                        if (!Keyboard.IsKeyDown(Key.Tab))
                        {
                            UIHelper.ShowMessage("Quantity can no be lower than 1.");
                            e.Cancel = true;
                        }
                    }
                    else
                    {
                        GiftPackageItem giftPackageItem = (GiftPackageItem)e.Row.Item;
                        giftPackageItem.gpQty = Convert.ToInt32(txt.Text);
                    }
                    break;
                }
                }
            }
            else
            {
                _isCellCancel = true;
            }
        }