Пример #1
0
 protected object GetValue(TranslationRule rule, IComWrapper com_object)
 {
     object value = com_object.Get(rule.Field);
     if (value == DBNull.Value) return value;
     if (rule.SourceType == SqlDbType.VarChar)
     {
         return (string)value;
     }
     else if (rule.SourceType == SqlDbType.Int)
     {
         return (int)value;
     }
     else if (rule.SourceType == SqlDbType.DateTime)
     {
         DateTime test = (DateTime)value;
         return test < CONST_min_date ?
             CONST_min_date :
             test > CONST_max_date ?
                 CONST_max_date :
                 test;
     }
     else if (rule.SourceType == SqlDbType.Money)
     {
         return Convert.ToDecimal(value);
     }
     else if (rule.SourceType == SqlDbType.Bit && rule.TargetType == SqlDbType.Int)
     {
         return (bool)value ? 1 : 0;
     }
     return value;
 }
Пример #2
0
 public override void Translate(IComWrapper com_object, SqlCommand command)
 {
     command.CommandText = _InsertCommand;
     command.CommandType = CommandType.Text;
     if (command.Parameters.Count > 0) command.Parameters.Clear();
     foreach (TranslationRule rule in _Rules)
     {
         AddParameter(command, rule.Field, rule.TargetType, GetValue(rule, com_object));
     }
 }
Пример #3
0
        internal static T TryGetManagedObject <T>(IComWrapper comWrapper) where T : class
        {
            if (comWrapper == null)
            {
                return(null);
            }

            var handle = GCHandle.FromIntPtr((IntPtr)comWrapper.GCHandlePtr);

            return(handle.Target as T);
        }
Пример #4
0
        internal static T GetManagedObject <T>(IComWrapper comWrapper) where T : class
        {
            Contract.ThrowIfNull(comWrapper, "comWrapper");

            var handle = GCHandle.FromIntPtr((IntPtr)comWrapper.GCHandlePtr);
            var target = handle.Target;

            Contract.ThrowIfNull(target, "target");
            Debug.Assert(target is T, "Why are you casting an object to an reference type it doesn't support?");
            return((T)target);
        }
 public override void Translate(IComWrapper com_object, SqlCommand command)
 {
     command.CommandText = _InsertCommand;
     command.CommandType = CommandType.Text;
     if (command.Parameters.Count > 0) command.Parameters.Clear();
     foreach (TranslationRule rule in _Rules)
     {
         AddParameter(command, rule.Field, rule.TargetType, GetValue(rule, com_object));
     }
     AddParameter(command, "Auth_code", SqlDbType.VarChar, DBNull.Value);
     AddParameter(command, "otw_code",  SqlDbType.VarChar, DBNull.Value);
     AddParameter(command, "sost_int",  SqlDbType.Int,     DBNull.Value);
     AddParameter(command, "grif_code", SqlDbType.Int,     DBNull.Value);
     AddParameter(command, "wid_code",  SqlDbType.VarChar, DBNull.Value);
 }
Пример #6
0
        public IComWrapper GetCursor()
        {
            IComWrapper query = connector.NewObject("Запрос");
            query.Set("Текст", GetQueryText());
            //query.Call("УстановитьПараметр", "Дата1", new DateTime(2010, 3, 1, 0, 0, 0));
            //query.Call("УстановитьПараметр", "Дата2", new DateTime(2010, 10, 1, 0, 0, 0));
            IComWrapper result = query.CallAndWrap("Выполнить");
            if ((bool)result.Call("Пустой"))
            {
                result.Dispose();
                query.Dispose();
                return null;
            }
            cursor = result.CallAndWrap("Выбрать");

            result.Dispose();
            query.Dispose();

            return cursor;
        }
Пример #7
0
 public abstract void Translate(IComWrapper com_object, SqlCommand sql_command);