narsil/Tanshu.Accounts.PointOfSale/User Management/UserForm.cs

86 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.PointOfSale
{
public partial class UserForm : Form
{
User user;
public UserForm(int? userID)
{
InitializeComponent();
if (userID.HasValue)
user = UserBI.GetUser(userID.Value);
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnCreateUSer_Click(object sender, EventArgs e)
{
UserBI.Delete(user.UserID);
btnCancel_Click(sender, e);
}
private void NewUser_Load(object sender, EventArgs e)
{
if (user != null)
{
txtUsername.Text = user.Name;
txtPassword.Text = user.Password;
chkLocked.Checked = user.LockedOut;
}
}
private bool Save()
{
if (user == null)
user = new User();
user.Name = txtUsername.Text.Trim();
user.Password = Tanshu.Common.Md5.Hash(txtPassword.Text.Trim(), "v2");
user.LockedOut = (chkLocked.Checked == true ? true : false);
if (user.UserID == 0)
UserBI.Insert(user);
else
UserBI.Update(user);
return true;
}
private void btnSave_Click(object sender, EventArgs e)
{
if (!ValidateValues())
{
MessageBox.Show("Missing Information: Please check the form.");
txtUsername.Focus();
}
else
{
Save();
btnCancel_Click(sender, e);
}
}
private bool ValidateValues()
{
if (txtUsername.Text.Trim() == "")
return false;
if (txtPassword.Text.Trim() == "")
return false;
return true;
}
}
}