Ejemplo n.º 1
0
        /// <summary>
        /// 新建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ob"></param>
        private void Create <T>(T ob, bool Submit)
        {
            var sqlCon = ConnectionString;

            if (string.IsNullOrEmpty(sqlCon))
            {
                sqlCon = GlobalSqlContext.GetConStr(typeof(T), "");
            }


            ConnectionString
                = sqlCon;
            var gernerater = new MSSQL.MSSSqlCommandGenerater();
            var command    = gernerater.GenerateCreateSql <T>(ob, this);

            //    var UpdateSqlCommand = gernerater.GenerateSeletedAutoGernerateSql<T>(ob);
            this.TransmitCommands.Enqueue(new SqlTransAutoMic()
            {
                ob = ob, command = command, Operation = SqlOperation.insert
            });
            var UpdateSqlCommand = gernerater.GenerateSeletedAutoGernerateSql <T>(ob);

            if (UpdateSqlCommand != null)
            {
                this.TransmitCommands.Enqueue(new SqlTransAutoMic()
                {
                    ob        = ob,
                    command   = UpdateSqlCommand,
                    Operation = SqlOperation.updateafterinsert
                });
            }

            if (Submit)
            {
                this.SubmitChanges();
            }
        }
Ejemplo n.º 2
0
        public void Attatch <T>(T ob, OperationType SubmitType)
        {
            var gernerater = new MSSQL.MSSSqlCommandGenerater();

            switch (SubmitType)
            {
            case OperationType.Create:
                this.TransmitCommands.Enqueue(new SqlTransAutoMic()
                {
                    command =
                        gernerater.GenerateCreateSql <T>(ob, this) as SqlCommand,
                    ob        = ob,
                    Operation = SqlOperation.insert
                });
                var UpdateSqlCommand = gernerater.GenerateSeletedAutoGernerateSql <T>(ob);

                if (UpdateSqlCommand != null)
                {
                    this.TransmitCommands.Enqueue(new SqlTransAutoMic()
                    {
                        ob        = ob,
                        command   = UpdateSqlCommand,
                        Operation = SqlOperation.updateafterinsert
                    });
                }

                break;

            case OperationType.Save:
                this.TransmitCommands.Enqueue(new SqlTransAutoMic()
                {
                    command =
                        gernerater.GenerateSaveSql <T>(ob) as SqlCommand,
                    ob        = ob,
                    Operation = SqlOperation.update
                });
                break;

            case OperationType.Delete:
                this.TransmitCommands.Enqueue(new SqlTransAutoMic()
                {
                    command =
                        gernerater.GenerateDeleteSql <T>(ob) as SqlCommand,
                    ob        = ob,
                    Operation = SqlOperation.delete
                });
                break;

            case OperationType.DynamicUpdate:
                this.TransmitCommands.Enqueue(new SqlTransAutoMic()
                {
                    command   = gernerater.GenerateDynamicUpateSql <T>(ob),
                    ob        = ob,
                    Operation = SqlOperation.updateafterupdate
                });;
                break;

            default:
                break;
            }
        }