Ejemplo n.º 1
0
        public void Update(object o)
        {
            //NextSeq(o);

            var type = o.GetType();

            var mem = loadedTypes[type];

            string tableName = mem.TableName;

            string upd = "update " + tableName + " set ";

            List <object> pps = new List <object>();
            int           k   = 0;

            foreach (var c in mem.fields)
            {
                string ctype = GetSqlTypeByMem(c.Mem);

                var cl = GetTypeClassByMem(c.Mem);

                string name = c.colName;

                upd += name + " = " + conf.parPre + "p" + k++ + ",";

                switch (cl)
                {
                case HidTypeInfo.HibTypeClass.Def:
                    pps.Add(c.GetValue(o));
                    break;

                case HidTypeInfo.HibTypeClass.External:
                    var idb = loadedTypes[c.type].idInfo.GetValue(c.GetValue(o));
                    if (InBase(idb, c.type))
                    {
                        pps.Add(idb);
                    }
                    else
                    {
                        throw new NonLoadedExternalDate();
                    }
                    break;

                case HidTypeInfo.HibTypeClass.Xml:
                    pps.Add(XmlSer.ToXmlString(c.GetValue(o), c.type));
                    break;

                default:
                    throw new HidException();
                }
            }

            upd  = upd.TrimEnd(',');
            upd += " where " + mem.idInfo.colName + " = " + conf.parPre + "pid";

            using (var com = m_connection.CreateCommand())
            {
                DbParameter p;

                com.Transaction = m_tranaction;
                com.CommandText = upd;
                for (int i = 0; i < k; i++)
                {
                    p = com.CreateParameter();
                    p.ParameterName = "p" + i;
                    p.Value         = pps[i];

                    com.Parameters.Add(p);
                }

                p = com.CreateParameter();
                p.ParameterName = "pid";
                p.Value         = mem.idInfo.GetValue(o);
                com.Parameters.Add(p);

                com.ExecuteNonQuery();
            }
        }
Ejemplo n.º 2
0
        public void Save(object o)
        {
            NextSeq(o);

            var type = o.GetType();

            var mem = loadedTypes[type];

            string tableName = mem.TableName;

            string        inst  = "insert into " + tableName + " (";
            string        inst2 = " VALUES ( ";
            List <object> pps   = new List <object>();
            int           k     = 0;

            foreach (var c in mem.fields)
            {
                string ctype = GetSqlTypeByMem(c.Mem);

                var cl = GetTypeClassByMem(c.Mem);

                string name = c.colName;

                inst  += name + ",";
                inst2 += conf.parPre + "p" + k++ + ",";

                switch (cl)
                {
                case HidTypeInfo.HibTypeClass.Def:
                    pps.Add(c.GetValue(o));
                    break;

                case HidTypeInfo.HibTypeClass.External:
                    var idb = loadedTypes[c.type].idInfo.GetValue(c.GetValue(o));
                    if (InBase(idb, c.type))
                    {
                        pps.Add(idb);
                    }
                    else
                    {
                        throw new NonLoadedExternalDate();
                    }
                    break;

                case HidTypeInfo.HibTypeClass.Xml:
                    pps.Add(XmlSer.ToXmlString(c.GetValue(o), c.type));
                    break;

                default:
                    throw new HidException();
                }
            }

            inst  = inst.TrimEnd(',');
            inst2 = inst2.TrimEnd(',');

            inst += ") " + inst2 + ")";


            using (var com = m_connection.CreateCommand())
            {
                com.Transaction = m_tranaction;
                com.CommandText = inst;
                for (int i = 0; i < k; i++)
                {
                    var p = com.CreateParameter();
                    p.ParameterName = "p" + i;
                    p.Value         = pps[i];

                    com.Parameters.Add(p);
                }
                com.ExecuteNonQuery();
            }
        }