Esempio n. 1
0
        OleDbParameter[] CreateParameters(T entity)
        {
            var DI  = ClassPropertyHelper.GetPropertyNameAndValue <T>(entity);
            var DIT = ClassPropertyHelper.GetPropertyNameAndType <T>(entity);

            OleDbParameter[] parameters = new OleDbParameter[DI.Count - 1];
            for (int i = 0; i < DI.Count - 1; i++)
            {
                OleDbParameter para = new OleDbParameter();
                para.OleDbType     = ConverOleType(DIT.ElementAt(i + 1).Value);
                para.ParameterName = DI.ElementAt(i + 1).Key;
                para.Value         = StingToSysType(DIT.ElementAt(i + 1).Value, DI.ElementAt(i + 1).Value);
                parameters[i]      = para;
            }
            return(parameters);
        }
Esempio n. 2
0
        void CreateTable(T entity, Catalog catalog)
        {
            ADODB.Connection cn = new ADODB.Connection();
            cn.Open(strConnection, null, null, -1);
            catalog.ActiveConnection = cn;
            Table table = new Table();

            var DI  = ClassPropertyHelper.GetPropertyNameAndValue <T>(entity);
            var DIT = ClassPropertyHelper.GetPropertyNameAndType <T>(entity);

            table.Name = ClassPropertyHelper.GetClassName <T>(entity);
            for (int i = 0; i < DI.Count; i++)
            {
                if (DI.ElementAt(i).Key == "ID")
                {
                    ADOX.Column column = new ADOX.Column();
                    column.ParentCatalog = catalog;
                    column.Name          = "ID";
                    column.Type          = DataTypeEnum.adInteger;
                    column.DefinedSize   = 32;
                    column.Properties["AutoIncrement"].Value = true;
                    table.Columns.Append(column, DataTypeEnum.adInteger, 32);
                    table.Keys.Append("PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "ID", "", "");
                }
                else
                {
                    table.Columns.Append(DI.ElementAt(i).Key, ConverType(DIT.ElementAt(i).Value), 64);
                }
            }
            try {
                catalog.Tables.Append(table);
            }
            catch (Exception ex) {
                //MessageBox.Show("OleHelper行号92:" + ex.Message);
            }
            finally {
                cn.Close();
            }
        }
Esempio n. 3
0
        public void Update(T entity, int Id)
        {
            try {
                var DI  = ClassPropertyHelper.GetPropertyNameAndValue <T>(entity);
                var DIT = ClassPropertyHelper.GetPropertyNameAndType <T>(entity);
                OleDbParameter[] parameters = new OleDbParameter[DI.Count];
                var temp = CreateParameters(entity);
                for (int i = 0; i < DI.Count - 1; i++)
                {
                    parameters[i] = temp[i];
                }
                OleDbParameter para = new OleDbParameter();
                para.OleDbType           = OleDbType.Integer;
                para.ParameterName       = "ID";
                para.Value               = Id;
                parameters[DI.Count - 1] = para;

                ExecuteNonQuery(Create_CMD_Update(entity, Id), parameters);
            }
            catch (Exception error) {
                MessageBox.Show(error.Message);
            }
        }