private void AssignControlDatasource(FilterEditorControl filterEditorControl) { filterEditorControl.SourceControl = CriteriaPropertyEditorHelper.CreateFilterControlDataSource(View.ObjectTypeInfo.Type, Application.ObjectSpaceProvider); if (View.ObjectTypeInfo.DefaultMember != null) { foreach (FilterColumn filterColumn in filterEditorControl.FilterColumns) { if (View.ObjectTypeInfo.DefaultMember.Name == filterColumn.FieldName) { filterEditorControl.SetDefaultColumn(filterColumn); } } } }
private void AssignControlDatasource(FilterEditorControl filterEditorControl) { filterEditorControl.SourceControl = View.CollectionSource.Collection; if (View.ObjectTypeInfo.DefaultMember != null) { foreach (FilterColumn filterColumn in filterEditorControl.FilterColumns) { if (View.ObjectTypeInfo.DefaultMember.Name == filterColumn.FieldName) { filterEditorControl.SetDefaultColumn(filterColumn); break; } } } }
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; } } }
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; } } }