Beispiel #1
0
        public virtual int Delete()
        {
            List <MyField> paramsfileds = new List <MyField>();

            Type t = this.GetType();

            PropertyInfo[] props = t.GetProperties();

            DataTable schema = SchemaBuffer.getTableDef(this.GetTableName());

            foreach (PropertyInfo p in props)
            {
                string fName = p.Name.ToUpper();
                Object val   = p.GetGetMethod().Invoke(this, new Object[] { });

                foreach (DataColumn dc in schema.PrimaryKey)
                {
                    if (dc.ColumnName.ToUpper() == fName)
                    {
                        paramsfileds.Add(new MyField(fName, val));
                        continue;
                    }
                }
            }

            return(TableManager.Delete(this.GetTableName(), paramsfileds.ToArray()));
        }
Beispiel #2
0
        public virtual int Update()
        {
            List <MyField> datafields   = new List <MyField>();
            List <MyField> paramsfileds = new List <MyField>();

            Type t = this.GetType();

            PropertyInfo[] props = t.GetProperties();

            DataTable schema = SchemaBuffer.getTableDef(this.GetTableName());

            foreach (PropertyInfo p in props)
            {
                string fName = p.Name.ToUpper();
                Object val   = p.GetGetMethod().Invoke(this, new Object[] { });

                foreach (DataColumn dc in schema.PrimaryKey)
                {
                    if (dc.ColumnName.ToUpper() == fName)
                    {
                        paramsfileds.Add(new MyField(fName, val, p.PropertyType));
                        continue;
                    }
                }

                if (!this.IsReadOnlyField(fName))
                {
                    if (fName.ToLower() == "updatetime")
                    {
                        datafields.Add(new MyField(fName, TableManager.DBServerTime(), p.PropertyType));
                    }
                    else if (fName.ToLower() == "updateuser")
                    {
                        datafields.Add(new MyField(fName, Global.g_username, p.PropertyType));
                    }
                    else
                    {
                        if (val == null)
                        {
                            datafields.Add(new MyField(fName, DBNull.Value, p.PropertyType));
                        }
                        else
                        {
                            datafields.Add(new MyField(fName, val, p.PropertyType));
                        }
                    }
                }
            }

            return(TableManager.Update(this.GetTableName(), datafields.ToArray(), paramsfileds.ToArray()));
        }