コード例 #1
0
        public void SaveAdmin()
        {
            Admin admin = new Admin();

            admin.Username      = AdminOriginal;
            admin.Realname      = AdminOriginal;
            admin.Department_ID = 1;
            admin.Password      = Password;
            admin.Seescope      = EnumSeescope.All.ToString();
            admin.Roletype      = EnumRoletype.Superadmin.ToString();
            admin.LoginTimes    = 0;
            admin.CommitTime    = DateTime.Now;
            admin.UpdateTime    = DateTime.Now;
            //admin.ID = Guid.NewGuid();
            db.Admin.Add(admin);
            db.SaveChanges();

            // Test 1
            Assert.IsNotNull(admin.ID);

            //Test 2
            var newPersonFound = db.Admin.FirstOrDefault(
                person => person.Username == AdminOriginal);

            Assert.IsNotNull(newPersonFound);
        }
コード例 #2
0
        public void importAdmin()
        {
            string fileName = "admin20140611084350.xls";

            fileName = Path.Combine(Gc.UploadPath, "attachment", "admin", fileName);
            //Excel导出入到DataTable
            DataTable dt = UtilExcelOle.ExcelToDataTableBySheet(fileName, "Admin");

            if (dt != null)
            {
                Dictionary <string, string> dic = new Dictionary <string, string>()
                {
                    { "编号", "ID" },
                    { "部门名称", "Department_Name" },
                    { "用户名称", "Username" },
                    { "密码", "Password" },
                    { "真实姓名", "Realname" },
                    { "扮演角色", "RoletypeShow" },
                    { "视野", "SeescopeShow" },
                    { "登录次数", "LoginTimes" },
                    { "创建时间", "CommitTime" },
                    { "更新时间", "UpdateTime" }
                };

                UtilDataTable.ReplaceColumnName(dt, dic);

                //检查数据格式是否正确
                //1、检查Excel中是否有用户名重复数据
                if (UtilDataTable.HasRepeat(dt, "Username"))
                {
                    Console.WriteLine("Excel中有重复用户名");
                    return;
                }
                //2、检查Excel中用户名是否存在与数据中相同数据
                List <Admin> admins  = db.Admin.ToList();
                DataTable    tableDt = UtilDataTable.ToDataTable <Admin>(admins);
                if (UtilDataTable.HasRepeat(tableDt, dt, "Username"))
                {
                    Console.WriteLine("Excel中与数据库有重复用户名");
                    //return;
                }
                //循环插入数据
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Admin admin = new Admin();
                    UtilDataTable.ToObject(admin, dt.Rows[i], dt.Columns);
                    Department dep = db.Department.Where(e => e.Department_Name.Equals(admin.Department_Name)).SingleOrDefault();
                    admin.Department_ID = dep.ID;
                    admin.Seescope      = EnumSeescope.SeescopeByShow(admin.SeescopeShow);
                    admin.Roletype      = EnumRoletype.RoletypeByShow(admin.RoletypeShow);
                    //admin.CommitTime = DateTime.Now;
                    //admin.UpdateTime = DateTime.Now;
                    db.Admin.Add(admin);
                }
                db.SaveChanges();
            }
        }
コード例 #3
0
        public void SaveLogsystem()
        {
            Logsystem logsystem = new Logsystem();

            logsystem.ID       = new Guid(originalLogID);
            logsystem.Message  = originalMessage;
            logsystem.Ident    = "4";
            logsystem.Priority = "4";
            logsystem.Logtime  = DateTime.Now;
            db.Logsystem.Add(logsystem);
            db.SaveChanges();

            // Test 1
            Assert.IsNotNull(logsystem.ID);

            //Test 2
            var newFound = db.Logsystem.Find(logsystem.ID);

            Assert.IsNotNull(newFound);
        }