public static List <InvoiceCatalogModel> FindInvoices(DSModel db, InvoiceCatalogFilter filter)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            string sql = SqlCache.Get(db, "invoice catalog load");

            List <MySqlParameter> par = new List <MySqlParameter>();

            if (!string.IsNullOrWhiteSpace(filter.InvoiceNumber))
            {
                sql = sql.Replace("#InvoiceNumber", string.Empty);
                par.Add(new MySqlParameter("InvoiceNumber", filter.InvoiceNumber + "%"));
            }
            if (filter.IssuedFrom.HasValue && filter.IssuedFrom.Value != DateTime.MinValue)
            {
                sql = sql.Replace("#IssuedFrom", string.Empty);
                par.Add(new MySqlParameter("IssuedFrom", filter.IssuedFrom.Value.Date));
            }
            if (filter.IssuedTo.HasValue && filter.IssuedTo.Value != DateTime.MinValue)
            {
                sql = sql.Replace("#IssuedTo", string.Empty);
                par.Add(new MySqlParameter("IssuedTo", filter.IssuedTo.Value.Date));
            }
            if (filter.PeriodFrom.HasValue && filter.PeriodFrom.Value != DateTime.MinValue)
            {
                sql = sql.Replace("#PeriodFrom", string.Empty);
                par.Add(new MySqlParameter("PeriodFrom", filter.PeriodFrom.Value.Date));
            }
            if (filter.PeriodTo.HasValue && filter.PeriodTo.Value != DateTime.MinValue)
            {
                sql = sql.Replace("#PeriodTo", string.Empty);
                par.Add(new MySqlParameter("PeriodTo", filter.PeriodTo.Value.Date));
            }


            if (!string.IsNullOrWhiteSpace(filter.CompanyID))
            {
                sql = sql.Replace("#CompanyID", string.Empty);
                sql = sql.Replace("@CompanyID", filter.CompanyID);
            }
            if (!string.IsNullOrWhiteSpace(filter.LocationID))
            {
                sql = sql.Replace("#LocationID", string.Empty);
                sql = sql.Replace("@LocationID", filter.LocationID);
            }

            return(db.ExecuteQuery <InvoiceCatalogModel>(sql, par.ToArray()).ToList());
        }
        public void LoadInvoices(InvoiceCatalogFilter filter)
        {
            using (var db = DB.GetContext())
            {
                var invoices = InvoiceRepository.FindInvoices(db, filter);
                foreach (var inv in this.ActiveModel)
                {
                    var find = invoices.Where(i => i.InvoiceID == inv.InvoiceID).FirstOrDefault();
                    if (find != null)
                    {
                        find.IsMarked = inv.IsMarked;
                    }
                }

                this.ActiveModel.Clear();
                this.ActiveModel.AddRange(invoices);
            }
        }