public FRBOGenericCollection(string pFilter, string pGroup, string pOrder, string pFields, int pLimit)
        {
            //Assign Attributes Defined
            _objectHaveAttributes = ((typeof(T).GetCustomAttribute(typeof(FRBOAttribute)) as FRBOAttribute) != null) ? true : false;

            //Attributes: Sql
            string sqlQuery = (_objectHaveAttributes && (typeof(T).GetCustomAttribute(typeof(FRBOAttribute)) as FRBOAttribute).Sql != null)
                ? (typeof(T).GetCustomAttribute(typeof(FRBOAttribute)) as FRBOAttribute).Sql
                              //If not SqlQuery Defined from Attributes, Create it From Reflection and FRBO Object Attributes
                : GenQueryFromFRBOObject(pFilter, pGroup, pOrder, pFields);

            //Atributes: Limit
            int sqlLimit = 0;

            //Get Order From Parameters
            if (pLimit > 0)
            {
                sqlLimit = pLimit;
            }
            //Limit: Get Order From LimitAttribute else Bypass it With 0
            else if (_objectHaveAttributes && (typeof(T).GetCustomAttribute(typeof(FRBOAttribute)) as FRBOAttribute).Limit > 0)
            {
                sqlLimit = (typeof(T).GetCustomAttribute(typeof(FRBOAttribute)) as FRBOAttribute).Limit;
            }

            try
            {
                //Start Process Collection

                //Temporary GenericTypeObject to Add to Collection
                T            genericTypeObject;
                XPSelectData xPSelectData;

                xPSelectData = FrameworkUtils.GetSelectedDataFromQuery(sqlQuery);

                PropertyInfo propertyInfo;
                //Fields Props
                string fieldName   = String.Empty;
                string fieldType   = String.Empty;
                string fieldTypeDB = String.Empty;
                Object fieldValue;
                int    fieldIndex;

                int i = 0;
                foreach (SelectStatementResultRow rowData in xPSelectData.Data)
                {
                    i++;
                    //If sqlLimit Defined and is Greater Break Loop
                    if (sqlLimit > 0 && i > sqlLimit)
                    {
                        break;
                    }

                    //Create a new Fresh T Object to Insert into Collection
                    //Cannot create an instance of the variable type 'T' because it does not have the new() constraint
                    //Require Constrain new()
                    genericTypeObject = new T();
                    foreach (SelectStatementResultRow rowMeta in xPSelectData.Meta)
                    {
                        fieldName   = rowMeta.Values[0].ToString();
                        fieldTypeDB = rowMeta.Values[1].ToString();;
                        fieldType   = rowMeta.Values[2].ToString();;
                        fieldIndex  = xPSelectData.GetFieldIndex(fieldName);

                        //Convert DB Types, Else working on Diferent DBs occur Conversion Exceptions
                        switch (fieldType)
                        {
                        case "Int64":
                        case "UInt32":
                            //case "UInt64":
                            fieldValue = Convert.ToInt32(rowData.Values[fieldIndex]);
                            break;

                        case "UInt64":
                            fieldValue = Convert.ToBoolean(rowData.Values[fieldIndex]);
                            break;

                        case "Boolean":
                            fieldValue = Convert.ToBoolean(rowData.Values[fieldIndex]);
                            break;

                        case "Guid":
                            fieldValue = Convert.ToString(rowData.Values[fieldIndex]);
                            break;

                        case "Decimal":    //Added to fix MsSql Errors
                        case "Double":
                            fieldValue = Convert.ToDecimal(rowData.Values[fieldIndex]);
                            break;

                        default:
                            fieldValue = rowData.Values[fieldIndex];
                            break;
                        }

                        try
                        {
                            //If Property Exist in genericTypeObject Assign it from Data
                            propertyInfo = typeof(T).GetProperty(fieldName);

                            //if (fieldName.Equals("SourceOrderMain") && string.IsNullOrEmpty(fieldValue.ToString()))
                            //{
                            //    _log.Debug(String.Format("fieldName: [{0}], fieldValue: [{1}]", fieldName, fieldValue));
                            //}

                            //Fix for MSSqlServer that detects UInt32 has Decimal, this way we convert it into UInt32 before above SetValue
                            if (propertyInfo.PropertyType == typeof(UInt32))
                            {
                                fieldValue = Convert.ToUInt32(rowData.Values[fieldIndex]);
                            }
                            //Fix for SQLite that detects UInt64 has Decimal, this way we convert it into Decimal before above SetValue
                            else if (propertyInfo.PropertyType == typeof(decimal))
                            {
                                fieldValue = Convert.ToDecimal(rowData.Values[fieldIndex]);
                            }
                            // Fix FRBO Object Field od type Guid
                            else if (propertyInfo.PropertyType == typeof(Guid))
                            {
                                fieldValue = new Guid(rowData.Values[fieldIndex].ToString());
                            }
                            // Check id is a Subclass of XPGuidObject and Get its value
                            else if (propertyInfo.PropertyType.IsSubclassOf(typeof(XPGuidObject)))
                            {
                                // Protection to prevent assign string value to Guid/unique identifier
                                if (fieldValue != null && string.IsNullOrEmpty(fieldValue.ToString()))
                                {
                                    fieldValue = null;
                                }
                                else
                                {
                                    fieldValue = FrameworkUtils.GetXPGuidObjectFromCriteria(propertyInfo.PropertyType, string.Format("Oid = '{0}'", fieldValue));
                                }
                                // Debug purpose helper
                                //if(propertyInfo.PropertyType == typeof(sys_userdetail) || propertyInfo.PropertyType == typeof(pos_configurationplaceterminal))
                                //{
                                //    _log.Debug(String.Format("fieldName: [{0}], fieldValue: [{1}]", fieldName, fieldValue));
                                //}
                            }

                            // Try to Setvalue
                            if (propertyInfo != null)
                            {
                                propertyInfo.SetValue(genericTypeObject, fieldValue);
                            }
                        }
                        catch (Exception)
                        {
                            // Intentionnaly Commented ex
                            // Prevent Showing Conversion Error, Only Occur in Sales Per Day(Detailled/Group) Report, Minor problem, it Show Good Values
                            //_log.Error(string.Format("fieldName: [{0}], fieldType: [{1}], fieldTypeDB: [{2}], fieldValue: [{3}]", fieldName, fieldType, fieldTypeDB, fieldValue));
                            //_log.Error(ex.Message, ex);
                        }
                    }
                    //Add genericTypeObject to Collection :)
                    Add(genericTypeObject);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                _log.Error(string.Format("Error sqlQuery: [{0}]", sqlQuery));
            }
        }
Exemple #2
0
        protected override void OnResponse(ResponseType pResponse)
        {
            try
            {
                if (pResponse == ResponseType.Ok)
                {
                    bool changed = false;

                    foreach (var item in _dictionaryObjectBag)
                    {
                        changed = Utils.CheckIfFieldChanged(item.Key.Value, item.Value.EntryValidation.Text);
                        //_log.Debug(string.Format("FieldDb:[{0}], FieldInput:[{1}], changed: [{2}]", item.Key.Value, item.Value.EntryValidation.Text, changed));
                        if (changed)
                        {
                            item.Key.Value = item.Value.EntryValidation.Text;
                            item.Key.Save();
                        }
                    }

                    //entryBoxSelect: COMPANY_COUNTRY
                    //Assign and Save Country and Country Code 2 From entryBoxSelectCustomerCountry
                    cfg_configurationpreferenceparameter configurationPreferenceParameterCompanyCountry = (FrameworkUtils.GetXPGuidObjectFromCriteria(typeof(cfg_configurationpreferenceparameter), string.Format("(Disabled IS NULL OR Disabled  <> 1) AND (Token = '{0}')", "COMPANY_COUNTRY")) as cfg_configurationpreferenceparameter);
                    configurationPreferenceParameterCompanyCountry.Value = _entryBoxSelectSystemCountry.Value.Designation;
                    configurationPreferenceParameterCompanyCountry.Save();
                    //entryBoxSelect: COMPANY_COUNTRY_CODE2
                    cfg_configurationpreferenceparameter configurationPreferenceParameterCompanyCountryCode2 = (FrameworkUtils.GetXPGuidObjectFromCriteria(typeof(cfg_configurationpreferenceparameter), string.Format("(Disabled IS NULL OR Disabled  <> 1) AND (Token = '{0}')", "COMPANY_COUNTRY_CODE2")) as cfg_configurationpreferenceparameter);
                    configurationPreferenceParameterCompanyCountryCode2.Value = _entryBoxSelectSystemCountry.Value.Code2;
                    configurationPreferenceParameterCompanyCountryCode2.Save();
                    //entryBoxSelect: SYSTEM_CURRENCY
                    cfg_configurationpreferenceparameter configurationPreferenceParameterSystemCurrency = (FrameworkUtils.GetXPGuidObjectFromCriteria(typeof(cfg_configurationpreferenceparameter), string.Format("(Disabled IS NULL OR Disabled  <> 1) AND (Token = '{0}')", "SYSTEM_CURRENCY")) as cfg_configurationpreferenceparameter);
                    configurationPreferenceParameterSystemCurrency.Value = _entryBoxSelectSystemCurrency.Value.Acronym;
                    configurationPreferenceParameterSystemCurrency.Save();
                    //entryBoxSelect: COMPANY_COUNTRY_OID
                    cfg_configurationpreferenceparameter configurationPreferenceParameterCompanyCountryOid = (FrameworkUtils.GetXPGuidObjectFromCriteria(typeof(cfg_configurationpreferenceparameter), string.Format("(Disabled IS NULL OR Disabled  <> 1) AND (Token = '{0}')", "COMPANY_COUNTRY_OID")) as cfg_configurationpreferenceparameter);
                    configurationPreferenceParameterCompanyCountryOid.Value = _entryBoxSelectSystemCountry.Value.Oid.ToString();
                    configurationPreferenceParameterCompanyCountryOid.Save();
                    //entryBoxSelect: SYSTEM_CURRENCY_OID
                    cfg_configurationpreferenceparameter configurationPreferenceParameterSystemCurrencyOid = (FrameworkUtils.GetXPGuidObjectFromCriteria(typeof(cfg_configurationpreferenceparameter), string.Format("(Disabled IS NULL OR Disabled  <> 1) AND (Token = '{0}')", "SYSTEM_CURRENCY_OID")) as cfg_configurationpreferenceparameter);
                    configurationPreferenceParameterSystemCurrencyOid.Value = _entryBoxSelectSystemCurrency.Value.Oid.ToString();
                    configurationPreferenceParameterSystemCurrencyOid.Save();

                    //Proccess Country Scripts
                    string commandSeparator = ";";
                    Dictionary <string, string> replaceables = logicpos.DataLayer.GetReplaceables(GlobalFramework.DatabaseType);
                    string directoryCountry = FrameworkUtils.OSSlash(string.Format(@"{0}/{1}", SettingsApp.FileDatabaseOtherCommonCountry, _entryBoxSelectSystemCountry.Value.Code2));
                    logicpos.DataLayer.ProcessDumpDirectory(GlobalFramework.SessionXpo, directoryCountry, commandSeparator, replaceables);
                    //Proccess Country Plugin Scripts
                    directoryCountry = FrameworkUtils.OSSlash(string.Format(@"{0}/{1}", SettingsApp.FileDatabaseOtherCommonPluginsSoftwareVendorOtherCommonCountry, _entryBoxSelectSystemCountry.Value.Code2));
                    logicpos.DataLayer.ProcessDumpDirectory(GlobalFramework.SessionXpo, directoryCountry, commandSeparator, replaceables);

                    //Change Configuration : Currently only working outside Debugger, to prevent errors changing config with VS using app.config
                    //System.ArgumentException: O nome de ficheiro 'c:\svn\logicpos\trunk\src\logicpos\bin\debug\logicpos.exe.config' é inválido porque o mesmo nome de ficheiro já é referido pela hierarquia de configuração aberta
                    Dictionary <string, string> configurationValues = new Dictionary <string, string>();
                    configurationValues.Add("xpoOidConfigurationCountrySystemCountry", _entryBoxSelectSystemCountry.Value.Oid.ToString());
                    configurationValues.Add("xpoOidConfigurationCountrySystemCountryCountryCode2", _entryBoxSelectSystemCountry.Value.Code2);
                    configurationValues.Add("xpoOidConfigurationCurrencySystemCurrency", _entryBoxSelectSystemCurrency.Value.Oid.ToString());
                    Utils.AddUpdateSettings(configurationValues);

                    //Require to assign to SettingsApp Singleton : Now Working in InitPlataformParameters() to prevent save to config catch and this code is never be executed
                    //SettingsApp.ConfigurationSystemCountry = _entryBoxSelectSystemCountry.Value;
                    //SettingsApp.ConfigurationSystemCurrency = _entryBoxSelectSystemCurrency.Value;

                    //UNDER CONSTRUCTION
                    //Call SaveSystemProtection() Here
                    //Utils.SaveSystemProtection();
                }
                else if (pResponse == ResponseType.Apply)
                {
                    this.Destroy();
                    PosEditCompanyDetails dialog   = new PosEditCompanyDetails(this, DialogFlags.DestroyWithParent | DialogFlags.Modal, true);
                    ResponseType          response = (ResponseType)dialog.Run();
                    dialog.Destroy();
                }
                else
                {
                    //Prevent ESC
                    this.Run();
                }
            }
            catch (Exception ex)
            {
                // This Error Occurs only id Debugger is Attached
                _log.Error(ex.Message, ex);
            }
        }