Exemple #1
0
        private bool UsedWithAnotherItem(int row)
        {
            ItemShortcut itemShortcut = itemShortcuts.Find(i => i.Shortcut.Key == currentKey.Key && i.Shortcut.AccelMods == currentKey.AccelMods);

            if (itemShortcut != null && itemShortcut != itemShortcuts [row] && currentKey.Key > 0)
            {
                string title       = Translator.GetString("Warning!");
                string translation = Translator.GetString("The selected shortcut is already used for the \"{0}\" quick item. " +
                                                          "Do you want to remove the shortcut for \"{0}\" and assign it to \"{1}\"?");
                string message = string.Format(translation, itemShortcut.ItemName, itemShortcuts [row].ItemName);
                if (Message.ShowDialog(title, string.Empty, message, "Icons.Question32.png",
                                       MessageButtons.YesNo) != ResponseType.Yes)
                {
                    return(false);
                }

                itemShortcut.Shortcut = AccelKey.Zero;
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 条件查找实体类
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="gridView">DataGridView</param>
        /// <param name="match">Predicate</param>
        /// <returns>没有查到返回NULL</returns>
        public static T Find <T>(this DataGridView gridView, Predicate <T> match)
            where T : class
        {
            BindList <T> _source = gridView.ToBindList <T>();

            if (_source != null)
            {
                return(_source.Find(match));
            }

            return(null);
        }
Exemple #3
0
        /// <summary>
        /// 判断某列等于某个值是否存在
        /// </summary>
        /// <param name="gridView">DataGridView</param>
        /// <param name="columnName">列名称</param>
        /// <param name="key">列值</param>
        /// <returns>存在返回True;不存在返回FASLE</returns>
        public static bool Exist <T>(this DataGridView gridView, string columnName, Object key)
        {
            bool         _result = false;
            BindList <T> _source = gridView.ToBindList <T>();

            if (_source != null)
            {
                int _index = _source.Find(-1, columnName, key);
                _result = _index > 0;
            }

            return(_result);
        }
Exemple #4
0
        private void AddMoney(double amount, int quantity, bool refreshGrid = true)
        {
            MoneyContainer mc = list.Find(m => m.Amount.IsEqualTo(amount));

            if (mc != null)
            {
                mc.Quantity += quantity;
            }
            else
            {
                list.Add(new MoneyContainer(amount, quantity));
            }

            if (refreshGrid)
            {
                RefreshGrid();
            }
        }
Exemple #5
0
        /// <summary>
        /// 根据字段名称以及值查找对应的实体类
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="gridView">DataGridView</param>
        /// <param name="columnName">列名称</param>
        /// <param name="key">列值</param>
        /// <returns>没有查到返回NULL</returns>
        public static T Find <T>(this DataGridView gridView, string columnName, object key)
            where T : class
        {
            if (!string.IsNullOrEmpty(columnName))
            {
                BindList <T> _source = gridView.ToBindList <T>();

                if (_source != null)
                {
                    int _index = _source.Find(-1, columnName, key);

                    if (_index != -1)
                    {
                        return(_source[_index]);
                    }
                }
            }

            return(null);
        }
Exemple #6
0
        protected void btnOK_Clicked(object o, EventArgs args)
        {
            if (!Validate())
            {
                return;
            }

            // Mark payments in the operation for deletion
            foreach (Payment payment in operation.Payments
                     .Where(payment => payment.Mode == PaymentMode.Paid && !payments.Any(p => p.Id >= 0 && p.Id == payment.Id)))
            {
                payment.Quantity = 0;
            }

            // Add the new payments
            foreach (Payment payment in payments)
            {
                if (payment.OperationType == (int)OperationType.AdvancePayment)
                {
                    double remainder = payment.Quantity;
                    foreach (var id in usedAdvances[payment])
                    {
                        long    id1     = id;
                        Payment advance = advances.Find(p => p.Id == id1);
                        double  sum     = Math.Min(remainder, advance.Quantity);
                        advance.Quantity -= sum;

                        // Make sure credit card transactions made for advances are not annulled
                        if (advance.Quantity.IsZero())
                        {
                            advance.TransactionNumber = null;
                        }

                        remainder -= sum;
                        if (remainder.IsZero())
                        {
                            break;
                        }
                    }
                    // mark as new
                    payment.Id            = -1;
                    payment.OperationType = (int)operation.OperationType;
                }

                // Add the payment to the operation if new
                if (payment.Id < 0)
                {
                    operation.Payments.Add((Payment)payment.Clone());
                    continue;
                }

                // Replace the payment if already used in the operation
                Payment currentPayment  = payment;
                Payment existingPayment = operation.Payments.Find(p => p.Id == currentPayment.Id);
                if (existingPayment != null)
                {
                    operation.Payments [operation.Payments.IndexOf(existingPayment)] = (Payment)payment.Clone();
                }
            }

            double subtractedChange = 0d;

            if (chkChangeIsReturned.Active)
            {
                subtractedChange = TotalReceived - Total;
            }

            if (subtractedChange > 0)
            {
                foreach (Payment payment in operation.Payments)
                {
                    if (payment.Mode != PaymentMode.Paid)
                    {
                        continue;
                    }

                    if (payment.Type.BaseType != BasePaymentType.Cash)
                    {
                        continue;
                    }

                    double newQtty = Math.Max(0, payment.Quantity - subtractedChange);
                    subtractedChange -= payment.Quantity - newQtty;
                    payment.Quantity  = newQtty;
                    if (subtractedChange <= 0)
                    {
                        break;
                    }
                }
            }

            if (subtractedChange > 0)
            {
                foreach (Payment payment in operation.Payments)
                {
                    if (payment.Mode != PaymentMode.Paid)
                    {
                        continue;
                    }

                    if (payment.Type.BaseType == BasePaymentType.Cash)
                    {
                        continue;
                    }

                    double newQtty = Math.Max(0, payment.Quantity - subtractedChange);
                    subtractedChange -= payment.Quantity - newQtty;
                    payment.Quantity  = newQtty;
                    if (subtractedChange <= 0)
                    {
                        break;
                    }
                }
            }

            DateTime endDate = BusinessDomain.GetDateValue(txtDueDate.Text.Trim());

            if (operation.Debt != null)
            {
                operation.Debt.EndDate = endDate;
            }

            foreach (Payment payment in operation.Payments)
            {
                payment.EndDate = endDate;

                if (!BusinessDomain.OnPaymentProcessed(payment))
                {
                    paymentWidget.Received = 0;
                    paymentWidget.FocusReceived();
                    return;
                }
            }

            BusinessDomain.AppConfiguration.LastPaymentMethod = (BasePaymentType)paymentWidget.GetPaymentTypeId();
            dlgEditNewPayment.Respond(ResponseType.Ok);
        }