本文整理汇总了C#中User.Create方法的典型用法代码示例。如果您正苦于以下问题:C# User.Create方法的具体用法?C# User.Create怎么用?C# User.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GrantDbPermissions
public static void GrantDbPermissions(Database db, string username)
{
var server = db.Parent;
Login login;
if (!(server.Logins.Contains(username)))
{
login = new Login(server, username);
login.LoginType = LoginType.WindowsUser;
login.DefaultDatabase = db.Name;
login.Create();
}
else
{
login = server.Logins[username];
}
User newUser;
if (!(db.Users.Contains(username)))
{
newUser = new User(db, username);
newUser.Login = username;
newUser.UserType = UserType.SqlLogin;
newUser.Create();
}
else
{
newUser = db.Users[username];
}
AddUserToRoles(newUser, "db_datareader", "db_datawriter", "db_ddladmin");
}
示例2: TestInsert
public void TestInsert()
{
var user = new User() { Name = "n1" };
var result = user.Create(Guid.Empty);
Assert.AreEqual(1, result);
Assert.AreEqual(1, result);
}
示例3: Main
public static void Main()
{
// 1. Step Configure and Initialize ActiveRecord:
// If you want to use the InPlaceConfigurationSource:
// Hashtable properties = new Hashtable();
// properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
// properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect");
// properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
// properties.Add("hibernate.connection.connection_string", "Data Source=.;Initial Catalog=test;Integrated Security=SSPI");
// InPlaceConfigurationSource source = new InPlaceConfigurationSource();
// source.Add(typeof(ActiveRecordBase), properties);
// We are using XmlConfigurationSource:
XmlConfigurationSource source = new XmlConfigurationSource("../appconfig.xml");
ActiveRecordStarter.Initialize( source, typeof(Blog), typeof(Post), typeof(User) );
// 2. Create the schema
// If you want to let AR to create the schema
if (MessageBox.Show("Do you want to let ActiveRecord create the database tables?", "Schema", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
ActiveRecordStarter.CreateSchema();
}
// 3. Create the first user (so you can log in)
if (User.GetUsersCount()== 0)
{
User user = new User("admin", "123");
user.Create();
}
// 4. Bring the Login Form
using(LoginForm login = new LoginForm())
{
if (login.ShowDialog() != DialogResult.OK)
{
return;
}
}
// 5. Show the main form
using(BlogManagement mainForm = new BlogManagement())
{
Application.Run(mainForm);
}
}
示例4: EnableDatabaseRoleForLogin
/// <summary>
/// Enables the database role for login.
/// </summary>
/// <param name="connectionString">The connection string.</param>
/// <param name="loginUsername">The login username.</param>
/// <param name="role">The role.</param>
public static void EnableDatabaseRoleForLogin(string connectionString, string loginUsername, string role)
{
EnableServerLoginForWindowsUser(connectionString, loginUsername);
var builder = new SqlConnectionStringBuilder(connectionString);
var server = new Server(builder.DataSource);
var database = new Database(server, builder.InitialCatalog);
var user = new User(database, loginUsername);
if (database.Users.Contains(loginUsername))
{
user.Login = loginUsername;
user.Create();
}
user.AddToRole(role);
}
示例5: btnAdd_Click
protected void btnAdd_Click(object sender, System.EventArgs e)
{
User newUser = new User();
string strErr="";
// if(this.Dropdepart.SelectedIndex==0)
// {
// strErr+="��ѡ����!";
// }
if(newUser.HasUser(txtUserName.Text))
{
strErr+="���û����Ѵ��ڣ�";
}
if(strErr!="")
{
LTP.Common.MessageBox.Show(this,strErr);
return;
}
newUser.UserName=txtUserName.Text;
//newUser.Password=AccountsPrincipal.EncryptPassword(txtPassword.Text);
newUser.NonEncryptPasswordPassword = txtPassword.Text;
newUser.TrueName=txtTrueName.Text;
if(RadioButton1.Checked)
newUser.Sex="��";
else
newUser.Sex="Ů";
newUser.Phone=this.txtPhone.Text.Trim();
newUser.Email=txtEmail.Text;
newUser.EmployeeID=0;
//newUser.DepartmentID=this.Dropdepart.SelectedValue;
newUser.Activity=true;
newUser.UserType = ((int)UserType.Type.Admin).ToString();
newUser.Style=1;
int userid=newUser.Create();
if (userid == -100)
{
this.lblMsg.Text = "���û����Ѵ��ڣ�";
this.lblMsg.Visible = true;
}
else
{
Response.Redirect("Admin/RoleAssignment.aspx?UserID="+userid);
}
}
示例6: button1_Click
//add db
private void button1_Click(object sender, EventArgs e)
{
var dbName = textBoxDB.Text;
string userName = textBoxUser.Text;
var serverName = "."; // SQL Server Instance name
Server svr = new Server(serverName);
var db = new Database(svr, dbName);
db.Create();
if (db != null)
{
// In case I need to add a login to sql
//Login login = new Login(svr, "beacon");
//login.DefaultDatabase = "master"; // Logins typically have master as default database
//login.LoginType = LoginType.SqlLogin;
//login.Create("foobar", LoginCreateOptions.None); // Enter a suitable password
//login.Enable();
if(userName != "")
{
User user = new User(db, userName);
user.UserType = UserType.SqlLogin;
user.Login = userName;
user.Create();
List<object> listOfPermissions = checkedListBoxPermissions.CheckedItems.OfType<object>().ToList();
foreach(var p in listOfPermissions)
{
user.AddToRole(p.ToString());
}
}
}
comboBoxDatabases.Items.Clear();
populateDatabases();
}
示例7: btn_Register_Click
protected void btn_Register_Click(object sender, EventArgs e)
{
if (txt_Address.Text != "" && txt_Birthday_Day.Text != "" && txt_Birthday_Year.Text != ""
&& txt_City.Text != "" && txt_Email.Text != "" && txt_LastName.Text != "" && txt_Mobile.Text != ""
&& txt_Name.Text != "" && txt_Password.Text != "" && txt_Password_retype.Text != ""
&& txt_Security_Question.Text!="" && txt_UserName.Text!="" && DropDownList_Birthday_Month.Text!=""
&& DropDownList_Gender.Text!="" && DropDownList_Security_Question.Text!="" && DropDownList_State.Text!="")
{
if (User.UserExistCheck(txt_UserName.Text)==null)
{
if (txt_Password.Text==txt_Password_retype.Text)
{
User newuser = new User();
newuser.Address = txt_Address.Text;
newuser.Name = txt_Name.Text;
newuser.LastName = txt_LastName.Text;
newuser.UserName = txt_UserName.Text;
newuser.Tell = txt_Telephone.Text;
newuser.PostalCode = txt_PostalCode.Text;
newuser.Password = txt_Password.Text;
newuser.Answer_Secret_Question = txt_Security_Question.Text.Trim();
newuser.BirthDay = txt_Birthday_Day.Text;
newuser.Cell = txt_Mobile.Text;
newuser.City = txt_City.Text;
newuser.Email = txt_Email.Text;
newuser.BirthMonth = DropDownList_Birthday_Month.Text;
newuser.Secret_Question = DropDownList_Security_Question.Text;
newuser.State = DropDownList_State.Text;
newuser.BirthYear = txt_Birthday_Year.Text;
if (DropDownList_Gender.SelectedValue == "0")
{
newuser.Sex = false;
}
else
{
newuser.Sex = true;
}
newuser.Admin = 0;
newuser.Date_reg_day = DateTime.Now.Day.ToString();
newuser.Date_reg_month = DateTime.Now.Month.ToString();
newuser.Date_reg_year = DateTime.Now.Year.ToString();
newuser.Create();
newuser = User.LoginCheck(txt_UserName.Text, txt_Password.Text);
Session["User"] = newuser;
Response.Redirect("Default.aspx");
}
else
{
lbl_Erorr.Text = "خطا:گذرواژه را مجددا وارد نمایید";
}
}
else
{
lbl_Error_UserName.Text = "خطا:این نام کاربری قبلا ثبت شده است";
}
}
else
{
lbl_Erorr.Text = "خطا: لطفا فیلدهای خالی را پر نمایید";
}
}
示例8: SaveUser4Page
private void SaveUser4Page()
{
using (Session session = new Session())
{
try
{
User user = new User();
user.UserName = this.txtUserName.Text.Trim();
user.Password = this.txtPassword.Text;
user.Email = txtEmail.Text.Trim();
user.Ext = txtExt.Text.Trim();
user.FullName = txtFullName.Text.Trim();
if(Org.UseDefaultOrg(session))
user.OrgId = Org.DefaultOrg(session);
else
user.OrgId = Cast.Int(this.txtOrgId.Text, -1);
user.Status = Cast.Enum<UserStatus>(this.rblStatus.SelectedValue);
user.UserType = Cast.Enum<OrgType>(this.ddlUserType.SelectedValue);
user.ModifyBy = SecuritySession.CurrentUser.UserId;
user.ModifyTime = DateTime.Now;
if (IsAddNew())
{
//检查帐号是否重复
int existsUserCount = session.CreateEntityQuery<Magic.Sys.User>()
.Where(Magic.Framework.ORM.Query.Exp.Eq("UserName", user.UserName))
.Count();
if (existsUserCount > 0)
{
WebUtil.ShowMsg(this, string.Format("用户帐号{0}已经存在", user.UserName), "错误");
return; //这里的return语句,using会保证session释放
}
//UserId是自增长主键,新增时不要设置它的值,新增完毕后框架会自动设置好这个值
user.CreateBy = SecuritySession.CurrentUser.UserId;
user.CreateTime = DateTime.Now;
user.Create(session);
}
else
{
user.UserId = Cast.Int(this.txtUserId.Value, -1); //UserId是主键,更新时需要设置
user.Update(session, "Email", "Ext", "FullName", "OrgId", "Password", "Status", "UserType", "ModifyBy", "ModifyTime");
}
this.txtUserId.Value = user.UserId.ToString(); //如果是新增用户,新增完毕后将用户ID设置到以页面隐藏控件(新增后UserId已经被赋值了)
WebUtil.ShowMsg(this, "用户保存成功", "操作成功");
}
catch (Exception ex)
{
logger.Info("保存User", ex);
WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员");
}
}
}
示例9: CreateUser
private static void CreateUser(Database db, string login, string userName)
{
var user = new User(db, userName) { Login = login };
user.Create();
}
示例10: CreateUser
public void CreateUser(string name, string database, string defaultSchema, string login, string[] roles)
{
Database db = _server.Databases[database];
User user = new User(db, name) {Login = login, DefaultSchema = defaultSchema};
user.Create();
for (int i = 0; i < roles.Length; i++)
user.AddToRole(roles[i]);
user.Alter();
}
示例11: Main
//.........这里部分代码省略.........
foreach (Table t in newDB.Tables) if (!t.IsSystemObject) oldTables.Add(t);
List<Trigger> oldTriggers = new List<Trigger>();
foreach (Trigger t in newDB.Triggers) if (!t.IsSystemObject) oldTriggers.Add(t);
//delete 'em
foreach (Trigger t in oldTriggers) t.Drop();
foreach (View v in oldViews) v.Drop();
foreach (Table t in oldTables) t.Drop();
}
else
{
WriteLine(string.Format("Creating new database \"{0}\" ", newDatabase), OutputKind.Info);
newDB = new Database(svr, newDatabase);
newDB.Collation = db.Collation;
newDB.DefaultSchema = db.DefaultSchema; //should it be "sysdba"?
FileGroup dbFG = new FileGroup(newDB, "PRIMARY");
newDB.FileGroups.Add(dbFG);
//Now add primary db file to file group
if (string.IsNullOrEmpty(databaseFileName))
{
string oldDatabaseFilename = db.FileGroups[0].Files[0].FileName;
string directory = Path.GetDirectoryName(oldDatabaseFilename);
databaseFileName = directory + @"\" + newDatabase + ".mdf";
}
DataFile df1 = new DataFile(dbFG, "SalesLogix_Data");
dbFG.Files.Add(df1);
df1.FileName = databaseFileName;
df1.Size = 10.0*1024.0;
df1.GrowthType = FileGrowthType.Percent;
df1.Growth = 25.0;
try
{
newDB.Create();
}
catch (Exception e)
{
WriteLine(string.Format("Could not create database \"{0}\"", newDatabase), OutputKind.Error);
ReportException(e);
WarnAndExit("");
}
}
//copy the users
foreach (User oldUser in db.Users)
{
User newUser = newDB.Users[oldUser.Name];
if (newUser == null)
{
Notify("Processing user " + oldUser.Name);
try
{
newUser = new User(newDB, oldUser.Name);
newUser.DefaultSchema = oldUser.DefaultSchema;
newUser.UserType = oldUser.UserType;
newUser.Login = oldUser.Login;
newDB.Users.Add(newUser);
newUser.Create();
StringCollection roles = oldUser.EnumRoles();
foreach (string role in roles) newUser.AddToRole(role);
newUser.Alter();
}
catch (Exception e)
{
ReportException(e);
示例12: AddUserButton_Click
private void AddUserButton_Click(System.Object sender,
System.EventArgs e)
{
Database db;
User usr;
try
{
db = (Database)DatabasesComboBox.SelectedItem;
// Create the user object
usr = new User(db, UserNameTextBox.Text);
usr.Login = LoginsComboBox.Text;
usr.Create();
ShowUsers();
// Select the user we just created and make sure it's viewable
ListViewItem UsersListViewItem = UsersListView.
FindItemWithText(UserNameTextBox.Text);
UsersListViewItem.Selected = true;
UsersListViewItem.EnsureVisible();
}
catch (SmoException ex)
{
ExceptionMessageBox emb = new ExceptionMessageBox(ex);
emb.Show(this);
}
}
示例13: GetUser
public User GetUser()
{
if (null == _user)
{
_user = new User(GetDatabase(), "User1");
_user.Login = GetLogin().Name;
_user.Create();
_toDrop.Add(_user);
}
return _user;
}
示例14: CreateLogin
/// <summary>
/// Creates a database login for the specified user.
/// </summary>
/// <param name="userName">Name of the user.</param>
/// <param name="password">The password for the user.</param>
/// <param name="makeDatabaseOwner">If set to <c>true</c>, the user will be a database owner (db_owner).</param>
public void CreateLogin(string userName, string password, bool makeDatabaseOwner)
{
if (!String.IsNullOrWhiteSpace(userName))
{
Login login = new Login(SqlServer, userName);
login.DefaultDatabase = _info.DatabaseName;
login.LoginType = LoginType.SqlLogin;
login.PasswordPolicyEnforced = false;
login.PasswordExpirationEnabled = false;
login.Create(password, LoginCreateOptions.None);
// Create new user and map to login account
User user = new User(SqlServer.Databases[_info.DatabaseName], userName);
user.Login = userName;
user.Create();
if (makeDatabaseOwner)
{
user.AddToRole("db_owner");
}
}
}
示例15: TryCreate
private void TryCreate(Database database, SqlServerUser user)
{
try
{
Logger.WriteLine("User: {0}", user);
var newUser = new User(database, user.Name)
{
Login = user.Login
};
newUser.Create();
foreach (var role in user.Roles)
{
newUser.AddToRole(role);
}
}
catch (FailedOperationException ex)
{
Logger.WriteLine("Adding user {0} failed. Reason: {1} ", user.Name, ex.Message);
}
}