Beispiel #1
0
        public JsonResult Delete(string id)
        {
            MyJsonResult mjr = new MyJsonResult();

            using (DbAccessor dba = DbAccessor.Create())
            {
                try
                {
                    dba.BeginTran();

                    _menuService.DeleteRecursive(id, dba);

                    dba.CommitTran();

                    mjr.Success = true;
                }
                catch (Exception ex)
                {
                    dba.RollbackTran();

                    mjr.Success = false;
                    mjr.Message = ex.Message;
                }
            }

            return(Json(mjr));
        }
 public void BeginTran()
 {
     using (DbAccessor dba = DbAccessor.Create())
     {
         dba.BeginTran();
         dba.ExecuteNonQuery("update sys_product set ProductName='abc' where ProductId=#ProductId#", new { ProductId = 1 });
         dba.RollbackTran();
     }
 }
        public JsonResult Save(SecUser model)
        {
            MyJsonResult mjr = new MyJsonResult();

            using (var dba = DbAccessor.Create())
            {
                try
                {
                    dba.BeginTran();

                    model.ModifiedById = SecurityContext.Current.User.UserId;
                    model.ModifiedDate = DateTime.Now;

                    if (model.UserId == null)
                    {
                        #region 校验数据
                        dynamic count = _dba.ExecuteScalar <dynamic>("SecuritySettings.User.CountByLoginName",
                                                                     new { LoginName = model.LoginName, Status = (int)StatusType.Enabled });

                        if (count > 0)
                        {
                            mjr.Success = false;
                            mjr.Message = "登录名已存在!";
                            goto End;
                        }
                        #endregion

                        model.UserId      = Guid.NewGuid().ToString();
                        model.Status      = (int)StatusType.Enabled;
                        model.CreatedById = SecurityContext.Current.User.UserId;
                        model.CreatedDate = DateTime.Now;
                        dba.Insert <SecUser>(model);
                    }
                    else
                    {
                        dba.UpdateFields(model, "LoginName", "Password", "Name", "Sex", "Birthday",
                                         "MobilePhone", "OrganizationId",
                                         "ModifiedById", "ModifiedDate");
                    }

                    dba.CommitTran();
                    mjr.Success = true;
                    mjr.Message = "保存成功!";
                }
                catch (Exception ex)
                {
                    dba.RollbackTran();
                    mjr.Success = false;
                    mjr.Message = ex.Message;
                }
            }

End:

            return(Json(mjr));
        }
        public void Trace()
        {
            DbAccessor dba = DbAccessor.Create();

            dba.PreCommandExecute += new TraceHandler().PrintSqlByConsole;

            var dt = _dba.QueryDataTable("select top 10 * from sys_product");

            Console.WriteLine(DataTableUtil.ToString(dt));
        }
Beispiel #5
0
        public void SetConnectionString(string connectionString)
        {
            Accessor         = DbAccessor.Create(Provider, connectionString);
            StructureGateway = new DbStructureGateway(Accessor);

            if (!Accessor.CanConnect)
            {
                throw new NdbException(string.Format(
                                           "Can't connect to \"{0}\" using {1} provider", connectionString, Provider));
            }
        }
        public JsonResult Save(SecOrganization model)
        {
            MyJsonResult mjr = new MyJsonResult();

            using (var dba = DbAccessor.Create())
            {
                try
                {
                    dba.BeginTran();

                    model.ModifiedById = SecurityContext.Current.User.UserId;
                    model.ModifiedDate = DateTime.Now;

                    if (model.OrganizationId == null)
                    {
                        model.OrganizationId = Guid.NewGuid().ToString();
                        model.Status         = (int)StatusType.Enabled;
                        model.CreatedById    = SecurityContext.Current.User.UserId;
                        model.CreatedDate    = DateTime.Now;
                        dba.ExecuteNonQuery("Security.Organization.Insert", model);
                    }
                    else
                    {
                        dba.UpdateFields(model, "Name", "Code",
                                         "MobilePhone",
                                         "ModifiedById", "ModifiedDate");
                    }

                    dba.CommitTran();
                    mjr.Success = true;
                    mjr.Message = "保存成功!";
                }
                catch (Exception ex)
                {
                    dba.RollbackTran();
                    mjr.Success = false;
                    mjr.Message = ex.Message;
                }
            }

            return(Json(mjr));
        }
Beispiel #7
0
        public void ImportFromExcel(string [] args)
        {
            if (args.Length > 4)
            {
                string SourceFileConnectionString = args[3];
                string assemblyName = args[4];

                var    assembly = Assembly.LoadFrom(assemblyName);
                Type[] types    = DbAttributesManager.LoadDbRecordTypes(assembly);

                var Source = (ExcelAccessor)DbAccessor.Create(DbProvider.Excel, SourceFileConnectionString);
                Accessor.ShareConnection = true;
                var Target = new DbGateway(Accessor);

                DbExcelExport export = new DbExcelExport(Source, Target);
                export.Export(types, true);
                ExitCode = ExitCode.Success;
            }
            else
            {
                ExitCode = ExitCode.Exception;
            }
        }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DbExcelExport"/> class.
 /// </summary>
 /// <param name="sourceConnectionStringName">Name of the source connection string.</param>
 /// <param name="targetConnectionStringName">Name of the target connection string.</param>
 public DbExcelExport(string sourceConnectionStringName, string targetConnectionStringName)
 {
     Source = (ExcelAccessor)DbAccessor.Create(sourceConnectionStringName);
     Target = new DbGateway(DbAccessor.Create(targetConnectionStringName));
 }
Beispiel #9
0
 public MsSqlCeDbStructureGatewayTests() : base(DbAccessor.Create("MsSqlCe"))
 {
 }
Beispiel #10
0
 public PostgreDbGatewayTests() : base(DbAccessor.Create("Postgre"))
 {
 }
Beispiel #11
0
 public SqLiteDbGatewayTests() : base(DbAccessor.Create("SqLite"))
 {
 }
Beispiel #12
0
 public MsSqlDbGatewayTests() : base(DbAccessor.Create("MsSql"))
 {
 }