コード例 #1
0
        public static IQueryable AppendWhere(IQueryable src, CriteriaOperator op)
        {
            var converter = new CriteriaToExpressionConverter();

            if (object.ReferenceEquals((object)op, (object)null))
            {
                return(src);
            }
            ParameterExpression thisExpression = Expression.Parameter(src.ElementType, "");
            Expression          expression     =
                Expression.Quote(Expression.Lambda(converter.Convert(thisExpression, op),
                                                   new ParameterExpression[1] {
                thisExpression
            }));
            MethodCallExpression methodCallExpression =
                Expression.Call(typeof(Queryable), "Where",
                                new Type[1] {
                src.ElementType
            }, new Expression[2]
            {
                src.Expression, expression
            });

            return(src.Provider.CreateQuery(methodCallExpression));
        }
コード例 #2
0
 protected override Expression VisitMethodCall(MethodCallExpression node)
 {
     if (node.Method.Name == "Where")
     {
         var converter   = new CriteriaToExpressionConverter();
         var elementType = node.Method.ReturnType.GetGenericArguments()[0];
         ParameterExpression thisExpression = Expression.Parameter(elementType);
         var criteria = DataServiceQueryCriteriaVisitor.Prepare(_filter);
         if (criteria is FunctionOperator && criteria.ToString().Contains("IsPriorDays"))
         {
             var            priorDays    = (FunctionOperator)criteria;
             BinaryOperator prirOperator = new BinaryOperator();
             prirOperator.LeftOperand = priorDays.Operands[1];
             int timeSpan = int.Parse(priorDays.Operands[2].ToString()) * (-1);
             prirOperator.RightOperand = new ConstantValue(DateTime.Now.AddDays(timeSpan));
             prirOperator.OperatorType = BinaryOperatorType.Less;
             criteria = prirOperator;
         }
         else if (criteria is GroupOperator && criteria.ToString().Contains("IsPriorDays"))
         {
             var            groupOperator = (GroupOperator)criteria;
             var            priorDays     = (FunctionOperator)groupOperator.Operands[0];
             BinaryOperator prirOperator  = new BinaryOperator();
             prirOperator.LeftOperand = priorDays.Operands[1];
             int timeSpan = int.Parse(priorDays.Operands[2].ToString()) * (-1);
             prirOperator.RightOperand = new ConstantValue(DateTime.Now.AddDays(timeSpan));
             prirOperator.OperatorType = BinaryOperatorType.Less;
             criteria = prirOperator;
         }
         var        expression       = Expression.Lambda(converter.Convert(thisExpression, criteria), thisExpression);
         Expression filterExpression = Expression.Quote(expression);
         return(Expression.Call(node.Method, node, filterExpression));
     }
     return(base.VisitMethodCall(node));
 }
コード例 #3
0
        public Expression Convert(ParameterExpression thisExpression, DevExpress.Data.Filtering.CriteriaOperator op)
        {
            var        converter  = new CriteriaToExpressionConverter();
            Expression expression = converter.Convert(thisExpression, op);

            var visitor = new NullPropagationEraseViistor();

            return(visitor.Visit(expression));
        }
        public static IList <Email> GetEmailsByFilter(CriteriaOperator filterCriteria)
        {
            CriteriaToExpressionConverter converter = new CriteriaToExpressionConverter();

            IQueryable <Email> source = from product in DB.Emails
                                        select product;
            IQueryable <Email> filteredData = source.AppendWhere(converter, filterCriteria) as IQueryable <Email>;

            return(filteredData.ToList <Email>());
        }
 private void OnUpdateFilter(object sender, EventArgs e)
 {
     gridControl1.BeginUpdate();
     try
     {
         CriteriaToExpressionConverter converter    = new CriteriaToExpressionConverter();
         IQueryable <Products>         filteredData = source.AppendWhere(converter, filterControl1.FilterCriteria) as IQueryable <Products>;
         gridControl1.DataSource = null;
         gridControl1.DataSource = filteredData.ToList();
     }
     finally
     {
         gridControl1.EndUpdate();
     }
 }
コード例 #6
0
        public static void DoInventoryAction(List <BusinessObject> lstObjects, bool isCalcInventoryReport)
        {
            #region Init
            Dictionary <String, List <BusinessObject> > lstDictObjects = new Dictionary <string, List <BusinessObject> >();
            foreach (BusinessObject obj in lstObjects)
            {
                if (lstDictObjects.ContainsKey(obj.AATableName) == false)
                {
                    lstDictObjects.Add(obj.AATableName, new List <BusinessObject>()
                    {
                        obj
                    });
                }
                else
                {
                    lstDictObjects[obj.AATableName].Add(obj);
                }
            }
            #endregion

            Dictionary <Guid, List <Guid> > lstProductIDs = new Dictionary <Guid, List <Guid> >();

            CriteriaToExpressionConverter converter = new CriteriaToExpressionConverter();
            foreach (String strTableName in lstDictObjects.Keys)
            {
                if (IsNeedCalculateInventory(strTableName))
                {
                    #region Calculate Inventory

                    foreach (ICInventoryConfigsInfo config in GetConfigs(strTableName))
                    {
                        if (!config.IsShipment || !config.IsLost || !config.IsReceive)
                        {
                            continue;
                        }

                        DevExpress.Data.Filtering.CriteriaOperator operatorConvert = DevExpress.Data.Filtering.CriteriaOperator.Parse(config.VoucherConditionString);
                        List <BusinessObject> lstFilteredObjects = ((IQueryable <BusinessObject>)lstDictObjects[strTableName].AsQueryable().AppendWhere(converter, operatorConvert)).ToList();
                        foreach (BusinessObject obj in lstFilteredObjects)
                        {
                            #region companyUnitID

                            Guid companyUnitID = Guid.Empty;
                            if (!String.IsNullOrWhiteSpace(config.VoucherComUnitIDField))
                            {
                                companyUnitID = ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(obj, config.VoucherComUnitIDField));
                            }
                            else if (!String.IsNullOrWhiteSpace(config.VoucherRealComUnitIDField) && !String.IsNullOrWhiteSpace(config.VoucherTableName))
                            {
                                companyUnitID = ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(obj, config.VoucherRealComUnitIDField));
                                companyUnitID = CompanyUnitProvider.GetCompanyUnitID(config.VoucherTableName, companyUnitID);
                            }
                            if (companyUnitID == Guid.Empty)
                            {
                                continue;
                            }
                            #endregion

                            Guid     productID = ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(obj, config.ProductIDField));
                            String   strSKU    = ABCDynamicInvoker.GetValue(obj, config.SKUField).ToString();
                            double   qty       = Convert.ToDouble(ABCDynamicInvoker.GetValue(obj, config.QtyField));
                            DateTime date      = Convert.ToDateTime(ABCDynamicInvoker.GetValue(obj, config.DateField));

                            if (productID != Guid.Empty && qty != 0 && date != null && date != DateTime.MinValue && date != DateTime.MaxValue)
                            {
                                if (config.IsShipment || config.IsLost)
                                {
                                    DoShipment(companyUnitID, productID, strSKU, qty, date);
                                }
                                else if (config.IsReceive)
                                {
                                    DoReceipt(companyUnitID, productID, strSKU, qty, date);
                                }

                                if (lstProductIDs.ContainsKey(companyUnitID) == false)
                                {
                                    lstProductIDs.Add(companyUnitID, new List <Guid>()
                                    {
                                        productID
                                    });
                                }
                                else
                                {
                                    lstProductIDs[companyUnitID].Add(productID);
                                }
                            }
                        }
                    }
                    #endregion
                }
            }

            if (isCalcInventoryReport)
            {
                //foreach ( Guid comUnitID in lstProductIDs.Keys )
                //{
                //    foreach(Guid productID in lstProductIDs[comUnitID])
                //        InventoryReportCalculate(comUnitID,productID,
                //}
            }
        }
コード例 #7
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (!ValidationProvider.Validate())
            {
                return;
            }

            try
            {
                bulkentries.Clear();

                using (CsvReader csv = new CsvReader(new StreamReader((String)txtFile.EditValue), true, ddlSeperator.Text[0], CsvReader.DefaultQuote, CsvReader.DefaultEscape, CsvReader.DefaultComment, true))
                {
                    while (csv.ReadNextRecord())
                    {
                        try
                        {
                            DB.VW_Account Account = DataContext.ReadonlyContext.VW_Account
                                                    .Where(n => n.Archived.Equals(false) &&
                                                           n.CodeSub.Equals(tblFields.Rows[1][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[1][1].ToString()]) : "")).FirstOrDefault();

                            DB.GLX_Aging aging = DataContext.EntityAccountingContext.GLX_Aging
                                                 .Where(n => n.Code.Contains(tblFields.Rows[4][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[4][1].ToString()]) : "")).OrderBy(o => o.Id)
                                                 .FirstOrDefault();

                            //TODO : Need to make this so that you can choose account on Payment/Receipt screens
                            if (Account == null)
                            {
                                skippedAccounts.Add(tblFields.Rows[1][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[1][1].ToString()]) : "");
                                continue;
                            }

                            bulkentries.Add(new BulkPaymentEntry()
                            {
                                //PeriodId = DB.SYS_PeriodGetCurrentPeriod().Id,
                                PeriodId    = Convert.ToInt64(ddlPeriod.EditValue),
                                Date        = tblFields.Rows[0][1].ToString() != "<NOT MAPPED>" ? ParseDate(csv[tblFields.Rows[0][1].ToString()]) : DateTime.Now,
                                AccountId   = Account != null ? (Int64?)Account.Id : null,
                                Reference   = tblFields.Rows[2][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[2][1].ToString()]) : "",
                                Description = tblFields.Rows[3][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[3][1].ToString()]) : "",
                                AgingId     = aging != null ? aging.Id : (Int16)1,
                                Settlement  = 0,
                                Amount      = tblFields.Rows[5][1].ToString() != "<NOT MAPPED>" ? ParseDecimal(csv[tblFields.Rows[5][1].ToString()]) * (chkReverseAmounts.Checked ? -1 : 1) : 0
                            });
                        }
                        catch (Exception)
                        {
                            String [] rowdata = new string[csv.FieldCount];
                            csv.CopyCurrentRecordTo(rowdata);
                            CDS.Client.Desktop.Essential.BaseAlert.ShowAlert("Parsing Error", String.Format("There was a problem reading a value from the row and the import will not continue. The row data provided: \n{0}.", String.Join(ddlSeperator.Text, rowdata)), Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Warning);
                            return;
                        }
                    }
                }

                CriteriaToExpressionConverter converter = new CriteriaToExpressionConverter();
                DevExpress.XtraFilterEditor.FilterEditorControl filRule = new DevExpress.XtraFilterEditor.FilterEditorControl();
                foreach (DB.GLX_BulkEntryRule rule in DataContext.EntityAccountingContext.GLX_BulkEntryRule.Where(n => n.EntityId == (Int64)ddlAccount.EditValue))
                {
                    filRule.FilterString = rule.EntryRule;
                    filRule.ApplyFilter();

                    //http://www.devexpress.com/Support/Center/p/Q357031.aspx
                    var qry = ((IQueryable <BulkPaymentEntry>)bulkentries.AsQueryable().AppendWhere(converter, filRule.FilterCriteria)).ToList();

                    if (rule.EntryAction == "N")
                    {
                        // Do not import
                        foreach (BulkPaymentEntry row in qry)
                        {
                            bulkentries.Remove(row);
                        }
                    }
                    else if (rule.EntryAction == "Y")
                    {
                        // Import
                        foreach (BulkPaymentEntry row in qry)
                        {
                            row.AccountId = rule.EntityContraId;
                        }
                    }
                }

                // Get taxes
                List <DB.GLX_Tax> taxes = DataContext.EntityAccountingContext.GLX_Tax.ToList();

                // Populate periods
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
コード例 #8
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (!ValidationProvider.Validate())
            {
                return;
            }

            try
            {
                using (CsvReader csv = new CsvReader(new StreamReader((String)txtFile.EditValue), true, ddlSeperator.Text[0], CsvReader.DefaultQuote, CsvReader.DefaultEscape, CsvReader.DefaultComment, true))
                {
                    while (csv.ReadNextRecord())
                    {
                        try
                        {
                            bulkentries.Add(new BulkEntry()
                            {
                                //PeriodId = DB.VW_PeriodGetCurrentPeriod().Id,
                                PeriodId    = Convert.ToInt64(ddlPeriod.EditValue),
                                Date        = tblFields.Rows[0][1].ToString() != "<NOT MAPPED>" ? ParseDate(csv[tblFields.Rows[0][1].ToString()]) : DateTime.Now,
                                AccountId   = null,
                                AgingId     = 1,
                                Reference   = tblFields.Rows[1][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[1][1].ToString()]) : "",
                                Description = tblFields.Rows[2][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[2][1].ToString()]) : "",
                                TaxId       = 1,
                                Exclusive   = 0,
                                Inclusive   = tblFields.Rows[3][1].ToString() != "<NOT MAPPED>" ? ParseDecimal(csv[tblFields.Rows[3][1].ToString()]) * (chkReverseAmounts.Checked ? -1 : 1) : 0
                            });
                        }
                        catch (Exception)
                        {
                            String [] rowdata = new string[csv.FieldCount];
                            csv.CopyCurrentRecordTo(rowdata);
                            CDS.Client.Desktop.Essential.BaseAlert.ShowAlert("Parsing Error", String.Format("There was a problem reading a value from the row and the import will not continue. The row data provided: \n{0}.", String.Join(ddlSeperator.Text, rowdata)), Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Warning);
                            return;
                        }
                    }
                }

                CriteriaToExpressionConverter converter = new CriteriaToExpressionConverter();
                DevExpress.XtraFilterEditor.FilterEditorControl filRule = new DevExpress.XtraFilterEditor.FilterEditorControl();
                foreach (DB.GLX_BulkEntryRule rule in DataContext.EntityAccountingContext.GLX_BulkEntryRule.Where(n => n.EntityId == (Int64)ddlAccount.EditValue))
                {
                    filRule.FilterString = rule.EntryRule;
                    filRule.ApplyFilter();

                    //http://www.devexpress.com/Support/Center/p/Q357031.aspx
                    var qry = ((IQueryable <BulkEntry>)bulkentries.AsQueryable().AppendWhere(converter, filRule.FilterCriteria)).ToList();

                    if (rule.EntryAction == "N")
                    {
                        // Do not import
                        foreach (BulkEntry row in qry)
                        {
                            bulkentries.Remove(row);
                        }
                    }
                    else if (rule.EntryAction == "N")
                    {
                        // Import
                        foreach (BulkEntry row in qry)
                        {
                            row.AccountId = rule.EntityContraId;
                            row.TaxId     = rule.TaxId;
                        }
                    }
                }

                // Get taxes
                List <DB.GLX_Tax> taxes = DataContext.EntityAccountingContext.GLX_Tax.ToList();

                // Populate inclusive/exclusive amounts
                if (!chkExclusive.Checked)
                {
                    // Amounts include tax
                    //exclusive = inclusive * 100/114
                    //exclusive = inclusive * 100/100+percentage
                    //                      * 1 / 1+percentage
                    foreach (BulkEntry row in bulkentries)
                    {
                        row.Exclusive = Math.Round(row.Inclusive.Value * 1.0m / (1.0m + taxes.FirstOrDefault(n => n.Id == row.TaxId).Percentage), 2, MidpointRounding.AwayFromZero);
                    }
                }
                else
                {
                    // Amounts exclude tax
                    //inclusive = exclusive * 114
                    //inclusive = exclusive * 100+percentage
                    //                      * 1+percentage
                    foreach (BulkEntry row in bulkentries)
                    {
                        row.Exclusive = row.Inclusive;
                        row.Inclusive = Math.Round(row.Exclusive.Value * (1.0m + taxes.FirstOrDefault(n => n.Id == row.TaxId).Percentage), 2, MidpointRounding.AwayFromZero);
                    }
                }

                // Populate periods
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }