Пример #1
0
 private void grvBudget_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
 {
     try
     {
         if (e.Column.FieldName == "Total" && e.IsGetData)
         {
             DB.VW_Account row = e.Row as DB.VW_Account;
             e.Value = budgets.Where(n => n.EntityId == row.Id).Sum(n => n.Amount);
         }
         else if (e.Column.FieldName != "Title" && e.IsGetData)
         {
             DB.VW_Account row  = e.Row as DB.VW_Account;
             DB.GLX_Budget budg = budgets.FirstOrDefault(n => n.PeriodId == (Int64)e.Column.Tag && n.EntityId == row.Id);
             if (budg != null)
             {
                 e.Value = budg.Amount;
             }
             //e.Value = (budg == null) ? 0 : budg.Amount;
         }
         else if (e.Column.FieldName != "Title" && e.IsSetData)
         {
             DB.VW_Account row  = e.Row as DB.VW_Account;
             DB.GLX_Budget budg = budgets.FirstOrDefault(n => n.PeriodId == (Int64)e.Column.Tag && n.EntityId == row.Id);
             if (budg == null)
             {
                 budg          = BL.GLX.GLX_Budget.New;
                 budg.PeriodId = (Int64)e.Column.Tag;
                 budg.EntityId = row.Id;
                 budg.Amount   = (decimal)e.Value;
                 budgets.Add(budg);
             }
             else
             {
                 budg.Amount = (decimal?)e.Value;
             }
         }
     }
     catch (Exception ex)
     {
         if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
         {
             throw ex;
         }
     }
 }
Пример #2
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;
                }
            }
        }