Exemple #1
0
        //插入命令创建
        string Create_CMD_Insert(T entity)
        {
            strCmd_Insert.Clear();
            strCmd_Insert.Append("insert into [" + ClassPropertyHelper.GetClassName <T>(entity) + "]([");
            var DI = ClassPropertyHelper.GetPropertyNameAndValue <T>(entity);

            for (int i = 0; i < DI.Count; i++)
            {
                if (DI.ElementAt(i).Key == "ID")
                {
                    continue;
                }
                if (i == DI.Count - 1)
                {
                    strCmd_Insert.Append(DI.ElementAt(i).Key + "])");
                    break;
                }
                strCmd_Insert.Append(DI.ElementAt(i).Key + "],[");
            }
            strCmd_Insert.Append(" values(");
            for (int i = 0; i < DI.Count; i++)
            {
                if (DI.ElementAt(i).Key == "ID")
                {
                    continue;
                }
                if (i == DI.Count - 1)
                {
                    strCmd_Insert.Append("@" + DI.ElementAt(i).Key + ")");
                    break;
                }
                strCmd_Insert.Append("@" + DI.ElementAt(i).Key + ",");
            }
            return(strCmd_Insert.ToString());
        }
Exemple #2
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);
        }
Exemple #3
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();
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        //Update命令创建
        string Create_CMD_Update(T entity, int Id)
        {
            strCmd_Update.Clear();
            strCmd_Update.Append("update  [" + ClassPropertyHelper.GetClassName <T>(entity) + "]  set  ");

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

            for (int j = 0; j < DI.Count; j++)
            {
                if (DI.ElementAt(j).Key == "ID")
                {
                    continue;
                }
                if (j == DI.Count - 1)
                {
                    strCmd_Update.Append("[" + DI.ElementAt(j).Key + "]=@" + DI.ElementAt(j).Key + "");
                    break;
                }
                strCmd_Update.Append("[" + DI.ElementAt(j).Key + "]=@" + DI.ElementAt(j).Key + ", ");
            }
            strCmd_Update.Append("   where  [ID]=@ID");
            return(strCmd_Update.ToString());
        }