예제 #1
0
        private bool Load(CINI ini, string section)
        {
            if (ini != null)
            {
                //load the section contain only if the
                if (_settings.ContainsKey(section))
                {
                    _settings[section] = new DictionaryFx <string, string>();

                    string[] entries = ini.GetEntryNames(section);
                    if (entries != null && entries.Length > 0)
                    {
                        foreach (string key in entries)
                        {
                            string lkey = key;
                            if (_isKeyCaseSensetive)
                            {
                                lkey = key.ToLower();
                            }

                            _settings[section][lkey] = ini.GetValue(section, key).ToString();
                        }
                    }
                }
            }

            return(true);
        }
예제 #2
0
        public void SetValue(string section, string key, string value)
        {
            DictionaryFx <string, string> dic = _settings[section];

            if (dic != null)
            {
                dic[key] = value;
            }
        }
예제 #3
0
        /// <summary>
        /// Performs validation of unique-constraints. Detail on the failure are stored in UniqueErrors Property
        /// It will use the help of TModel for performing the unique-constraint check.
        /// </summary>
        /// <param name="item"></param>
        /// <returns>Returns the status of the validation.</returns>
        public virtual bool ValidateUniqueValue(DbConnect con, DynamicDictionary item, IModel validatorModel, bool skipFieldsNotProvided = false)
        {
            /**
             * TODO
             * 1) disable null check or check if unique constraint is not composite constraint
             * 2) check unique constraint in edit mode, load all data
             **/
            PropertyInfo key = validatorModel.GetKeyPropertyInfo();
            TKey         id  = item.GetValue <TKey>(key.Name);

            //if (Conversion.ToInt32(id.ToString()) > 0)
            //    skipFieldsNotProvided = false; //if edit mode checke

            if (validatorModel.GetType().GetProperty("deleted_uq_code") != null) //tod not equal..
            {
                item["deleted_uq_code"] = 1;
            }
            BangoCommand cmd   = new BangoCommand(commandType: MyroCommandTypes.StringBuilder);
            string       union = string.Empty;
            //List<PropertyInfo> uniqueFields = new List<PropertyInfo>();
            DictionaryFx <string, PropertyInfo> uniqueFields = new DictionaryFx <string, PropertyInfo>();
            //preparing sql
            DynamicDictionary data_param = null;

            Bango.Models.Attributes.TableDetailAttribute tabelDetail = validatorModel.GetTableDetail();

            foreach (KeyValuePair <string, UniqueConstraint> unique in validatorModel.UniqueFields)
            {
                if (unique.Value.Fields.Count == 0)
                {
                    continue;
                }

                bool value_not_provided = false;

                foreach (string fld in unique.Value.Fields)
                {
                    if (!item.ContainsKey(fld))
                    {
                        //1) disable null check or check if unique constraint is not composite constraint
                        ///if (unique.Value.Fields.Count <= 1)
                        if (unique.Value.Fields.Count <= 1) //TODO:Shivashwor modify... for client duplicate data insert OFF...
                        {
                            value_not_provided = true;
                            break;
                        }

                        if (!skipFieldsNotProvided)
                        {
                            //If fld name not exists in validatorModel then
                            if (validatorModel.GetValue(fld) == null)
                            {
                                ///item.Add(fld, null);
                                value_not_provided = true;
                            }
                            else
                            {
                                Type t = validatorModel.GetType().GetProperty(fld).PropertyType;

                                if (t.IsValueType)
                                {
                                    item.Add(fld, Activator.CreateInstance(t));
                                }
                                else
                                {
                                    item.Add(fld, null);
                                }
                            }
                        }
                        else
                        {
                            //TODO:Shivashwor modify... for client duplicate data insert OFF...
                            value_not_provided = true;
                        }
                        break;
                    }
                }
                if (value_not_provided)
                {
                    continue;
                }

                data_param = (DynamicDictionary)item.Clone();
                ///TODO:SHIVASHWOR 15 nov 2015 for Unique value is empty or not...
                object data_val = data_param.GetValue(unique.Key);
                if (data_val != null)
                {
                    if (data_val.ToString().Trim().Length == 0)
                    {
                        continue;
                    }
                }

                if (union.Length > 0)
                {
                    cmd.SqlString.AppendLine(union);
                }
                string and = string.Empty;
                cmd.SqlString.AppendLine(String.Format("SELECT distinct '{0}' unique_constraint, '{2}' error_message FROM {1} {3} WHERE 1=1 "
                                                       , DbServiceUtility.SafeDBString(unique.Value.Name), tabelDetail.Name
                                                       , DbServiceUtility.SafeDBString(unique.Value.ErrorMessage)
                                                       , tabelDetail.Alias));
                //CHECKING In if client_id exists in the model for adding the client_id in unique contraint check if the developer has forgot to added
                PropertyInfo prop_client_id = validatorModel.GetType().GetProperty("client_id");
                if (prop_client_id != null)
                {
                    if (!unique.Value.Fields.Contains("client_id"))
                    {
                        unique.Value.Fields.Add("client_id");
                    }
                }
                foreach (string fld in unique.Value.Fields)
                {
                    if (validatorModel.GetType().GetProperty(fld) != null)
                    {
                        DbServiceUtility.BindParameter(cmd, fld, data_param, validatorModel.GetType().GetProperty(fld).PropertyType, tabelDetail.Alias, SearchTypes.Equal | SearchTypes.CaseSensetive, string.Empty, true, validatorModel.GetType().GetProperty(fld));
                    }
                    //cmd.SqlString.AppendFormat(" {1} {0} = @{0}", fld, and);//uniqueFields[fld] = validatorModel.GetType().GetProperty(fld);
                }


                if (key.Name.Trim().Length > 0)//PRIMARY KEY Check if n
                {
                    if (id != null)
                    {
                        //var obj_updateBy = data_param.GetValue("updated_by");

                        //if (obj_updateBy!= null)
                        DbServiceUtility.BindParameter(cmd, key.Name, data_param, System.Data.DbType.Int32, tabelDetail.Alias, SearchTypes.NotEqual, string.Empty, true, key);
                    }
                }

                union = " UNION ALL";
            }

            string finalSql           = cmd.FinalSql;
            IEnumerable <dynamic> lst = null;

            if (finalSql.Length > 0)
            {
                try
                {
                    lst = con.DB.Query <dynamic>(finalSql, cmd.FinalParameters);
                }
                catch (NpgsqlException ex)
                {
                    Errors.Add(ex.ToString());
                    LogTrace.WriteErrorLog(ex.ToString());
                    LogTrace.WriteDebugLog(string.Format("sql which gave exception:\r{0}", ex.Routine));
                    return(false);
                }
                catch (Exception ex)
                {
                }



                //checking for the unique constraint
                if (lst.Count() > 0)
                {
                    foreach (DapperRow dr in lst)
                    {
                        DynamicDictionary dic = Conversion.ToDynamicDictionary(dr);
                        DynamicDictionary err = new DynamicDictionary();
                        err.Add(dic.GetValueAsString("unique_constraint"), dic.GetValue("error_message"));
                        ModelService.PushValidationErros(err, ValidationErrors);
                    }
                    return(false);
                }
            }
            else
            {
                //TODO:Shivashwor 01 Nov 2015/
                //if edit mode nothing changed after save data occurs
                //  throw new NoSqlStringProvidedException();
            }
            return(true);
        }