Exemplo n.º 1
0
        private Dictionary <string, string[]> GetAllChanges(MASTER_FINANCIAL_RATIO old, MASTER_FINANCIAL_RATIO updated)
        {
            try
            {
                var changes = new Dictionary <string, string[]>();
                var columns = new string[]
                {
                    "COMPANY",
                    "YEAR_PERIOD",
                    "CURRENT_ASSETS",
                    "CURRENT_DEBTS",
                    "LIQUIDITY_RATIO",
                    "TOTAL_ASSETS",
                    "TOTAL_DEBTS",
                    "RENTABLE_RATIO",
                    "TOTAL_CAPITAL",
                    "NET_PROFIT",
                    "SOLVENCY_RATIO",
                    "APPROVALSTATUS"
                };
                var oldProps = new Dictionary <string, object>();
                var props    = new Dictionary <string, object>();

                foreach (var prop in updated.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
                {
                    props.Add(prop.Name, prop.GetValue(updated, null));
                    if (old != null)
                    {
                        oldProps.Add(prop.Name, prop.GetValue(old, null));
                    }
                    else
                    {
                        oldProps.Add(prop.Name, null);
                    }
                }
                foreach (var item in props)
                {
                    var oldValue = (oldProps[item.Key] != null) ? oldProps[item.Key].ToString() : "N/A";
                    var newValue = (item.Value != null) ? item.ToString() :  "N/A";
                    if (!columns.Contains(item.Key))
                    {
                        continue;
                    }

                    if (item.Key == "COMPANY")
                    {
                        if (item.Value != null)
                        {
                            newValue = ((T001)item.Value).BUTXT;
                        }

                        if (oldProps[item.Key] != null)
                        {
                            oldValue = ((T001)oldProps[item.Key]).BUTXT;
                        }
                        if (oldValue.Trim().ToUpper() != newValue.Trim().ToUpper())
                        {
                            changes.Add(item.Key, new string[] { oldValue, newValue });
                        }
                        continue;
                    }

                    if (item.Key == "APPROVALSTATUS")
                    {
                        if (item.Value != null)
                        {
                            newValue = ((SYS_REFFERENCES)item.Value).REFF_VALUE;
                        }

                        if (oldProps[item.Key] != null)
                        {
                            oldValue = ((SYS_REFFERENCES)oldProps[item.Key]).REFF_VALUE;
                        }
                        if (oldValue.Trim().ToUpper() != newValue.Trim().ToUpper())
                        {
                            changes.Add(item.Key, new string[] { oldValue, newValue });
                        }
                        continue;
                    }
                    if (item.Value != null)
                    {
                        if (item.Value is decimal)
                        {
                            newValue = ((decimal)item.Value).ToString("N");
                        }
                        else if (item.Value is DateTime)
                        {
                            newValue = ((DateTime)item.Value).ToString("dd MMMM yyyy HH:mm:ss");
                        }
                        else
                        {
                            newValue = item.Value.ToString();
                        }
                    }

                    if (oldProps[item.Key] != null)
                    {
                        if (oldProps[item.Key] is decimal)
                        {
                            oldValue = ((decimal)oldProps[item.Key]).ToString("N");
                        }
                        else if (item.Value is DateTime)
                        {
                            oldValue = ((DateTime)item.Value).ToString("dd MMMM yyyy HH:mm:ss");
                        }
                        else
                        {
                            oldValue = oldProps[item.Key].ToString();
                        }
                    }
                    if (oldValue.Trim().ToUpper() != newValue.Trim().ToUpper())
                    {
                        changes.Add(item.Key, new string[] { oldValue, newValue });
                    }
                }
                return(changes);
            }
            catch (Exception ex)
            {
                throw this.HandleException("Exception occured on FinanceRatioManagementService. See Inner Exception property to see details", ex);
            }
        }