本文整理汇总了C#中System.Entity.GetAllUsers方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.GetAllUsers方法的具体用法?C# Entity.GetAllUsers怎么用?C# Entity.GetAllUsers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.GetAllUsers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btn_deleteUSer_Click
private void btn_deleteUSer_Click(object sender, EventArgs e)
{
if (databaseAvailable)
{
Entity en = new Entity();
en.DeleteUser(Convert.ToInt32(txt_deleteId.Text));
XMLhelpers.SaveUsersToXml(en.GetAllUsers());
}
else
{
List<User> userList = XMLhelpers.FetchUsersFromXml();
User deletedUser = userList.FirstOrDefault(x => x.id == Convert.ToInt32(txt_deleteId.Text));
userList.Remove(deletedUser);
XMLhelpers.SaveUsersToXml(userList);
}
}
示例2: createUserOk_Click
private void createUserOk_Click(object sender, EventArgs e)
{
//If the database is available, save the data directly to the database
if (databaseAvailable)
{
Entity en = new Entity();
if (en.CreateUser(txt_username.Text, txt_email.Text))
{
MessageBox.Show("User succesfully created!");
XMLhelpers.SaveUsersToXml(en.GetAllUsers());
}
else
{
MessageBox.Show("Failed to create user");
}
//TODO add stuff!
}
else
{
//If the database is NOT available, save the data to the XML document.
List<User> userList = XMLhelpers.FetchUsersFromXml();
int nextId = 0;
foreach (var user in userList)
{
if (user.id > nextId)
{
nextId = user.id;
}
}
nextId++;
User newUser = new User();
newUser.email = txt_email.Text;
newUser.username = txt_username.Text;
newUser.id = nextId;
userList.Add(newUser);
XMLhelpers.SaveUsersToXml(userList);
}
}
示例3: btn_editUserOk_Click
private void btn_editUserOk_Click(object sender, EventArgs e)
{
if (databaseAvailable)
{
Entity en = new Entity();
en.EditUser(Convert.ToInt32(txt_editUserId.Text), txt_editUsername.Text, txt_editEmail.Text);
XMLhelpers.SaveUsersToXml(en.GetAllUsers());
}
else
{
List<User> userList = XMLhelpers.FetchUsersFromXml();
//Update the item in the list.
User userToEdit = userList.FirstOrDefault(x => x.id == Convert.ToInt32(txt_editUserId.Text));
userToEdit.username = txt_editUsername.Text;
userToEdit.email = txt_editEmail.Text;
XMLhelpers.SaveUsersToXml(userList);
}
}
示例4: WindowsForms_Load
private void WindowsForms_Load(object sender, EventArgs e)
{
appPath = Path.GetDirectoryName(Application.ExecutablePath);
scText = "Congratulations! You clicked the button! " + Environment.NewLine +
"Now, enter some text and save it. It will be saved to a .txt file.";
folderName = @"\UserFiles";
folderPath = appPath + folderName;
scOpenFileDialog.InitialDirectory = folderPath;
Entity en = new Entity();
databaseAvailable = en.IsDatabaseAvailable();
//If the database is available...
if (databaseAvailable)
{
//Check if the users.xml file exists
string usersXml = @"\users.xml";
var usersXmlExists = File.Exists(appPath + usersXml);
//If it doesn't exist, and the database is available, create it with the values from the database
if (!usersXmlExists)
{
XMLhelpers.SaveUsersToXml(en.GetAllUsers());
}
//If the users in the database and the xml document differs, update the database with the local data.
List<User> xmlUserList = XMLhelpers.FetchUsersFromXml();
List<User> userList = en.GetAllUsers();
bool inSync = true;
//If the size of the lists are equal, we can loop through and compare directly
if (xmlUserList.Count() == userList.Count())
{
for (int i = 0; i < xmlUserList.Count(); i++)
{
if (xmlUserList[i].username != userList[i].username || xmlUserList[i].email != userList[i].email || xmlUserList[i].id != userList[i].id)
{
inSync = false;
}
}
}
else
{
//If the size is different, we dont need to loop to figure out they are de-synced.
inSync = false;
}
if (!inSync)
{
MessageBox.Show("Detected unsynced data. Overwriting database with local data.");
en.TruncateTable();
en.PopulateTable(xmlUserList);
userList = en.GetAllUsers();
dataGridView1.DataSource = userList;
}
else
{
dataGridView1.DataSource = userList;
}
//The database is available, and data has been fetched from it. Now, just save the data into XML so it
//is available offline also!
XMLhelpers.SaveUsersToXml(userList);
}
else
{
this.Text += " - Offline mode";
MessageBox.Show("Can't connect to database. Starting in offline mode");
//Check if the users.xml file exists
string usersXml = @"\users.xml";
var usersXmlExists = File.Exists(appPath + usersXml);
//If it doesn't exist, and the database is not available, create it with a placeholder user
if (!usersXmlExists)
{
List<User> placeholderUserList = new List<User>();
User placeholderUser = new User();
placeholderUser.id = 1;
placeholderUser.username = "PlaceholderUser";
placeholderUser.email = "PlaceholderEmail";
placeholderUserList.Add(placeholderUser);
XMLhelpers.SaveUsersToXml(placeholderUserList);
}
//In offline mode, all data is loaded from the local xml document.
dataGridView1.DataSource = XMLhelpers.FetchUsersFromXml();
}
}
示例5: update_Click
private void update_Click(object sender, EventArgs e)
{
if (databaseAvailable)
{
Entity en = new Entity();
List<User> userList = en.GetAllUsers();
dataGridView1.DataSource = userList;
}
else
{
dataGridView1.DataSource = XMLhelpers.FetchUsersFromXml();
}
}
示例6: showUsers_Click
private void showUsers_Click(object sender, EventArgs e)
{
Entity en = new Entity();
List<User> userList = en.GetAllUsers();
foreach (var item in userList)
{
scRichText.Text += item.username + Environment.NewLine;
}
}