2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using System.Drawing;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
using System.Windows.Forms;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
using Tanshu.Accounts.Contracts;
|
|
|
|
|
using Tanshu.Accounts.Helpers;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
using Tanshu.Common.KeyboardControl;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class ChangePassword : Form
|
|
|
|
|
{
|
2011-02-09 12:03:22 +00:00
|
|
|
|
IKeyboardControl keyboardControl;
|
|
|
|
|
public ChangePassword(IKeyboardControl keyboardControl)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
this.keyboardControl = keyboardControl;
|
|
|
|
|
|
|
|
|
|
var control = keyboardControl as UserControl;
|
|
|
|
|
if (control != null)
|
|
|
|
|
{
|
|
|
|
|
control.Location = new System.Drawing.Point(6, 140);
|
|
|
|
|
this.Controls.Add(control);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
this.Size = this.SizeFromClientSize(new Size(6 + control.Width + 6, 140 + control.Height + 6));
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangePassword_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2011-01-06 07:17:00 +00:00
|
|
|
|
txtUsername.Text = Session.User.Name;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 08:03:31 +00:00
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 08:03:31 +00:00
|
|
|
|
private void btnChangePassword_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (txtPassword.Text.Trim() == "")
|
|
|
|
|
MessageBox.Show("Old password can not be blank", "Blank not allowed");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (txtnewPassword.Text.Trim() == "")
|
|
|
|
|
MessageBox.Show("New password can not be blank", "Blank not allowed");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (txtnewPassword.Text.Trim() != txtConfirmPassword.Text.Trim())
|
|
|
|
|
MessageBox.Show("New password not matched to confirm password", "Password not matched");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ChangeUserPassword())
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
MessageBox.Show("old Password not matched for user", "Wrong Password");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ChangeUserPassword()
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var bi = new UserBI())
|
2014-11-02 08:03:31 +00:00
|
|
|
|
{
|
|
|
|
|
var user = bi.ValidateUser(Session.User.Name, txtPassword.Text.Trim());
|
|
|
|
|
if (user == null)
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return false;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
bi.ChangePassword(user, txtnewPassword.Text.Trim());
|
|
|
|
|
bi.SaveChanges();
|
|
|
|
|
MessageBox.Show("Password changed", "Confirm");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
|
|
|
|
|
private void btnMsr_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var bi = new UserBI())
|
2011-02-18 16:54:48 +00:00
|
|
|
|
{
|
2014-11-02 08:03:31 +00:00
|
|
|
|
var user = bi.ValidateUser(Session.User.Name, txtPassword.Text.Trim());
|
|
|
|
|
if (user == null)
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
using (var frm = new MsrLoginForm(true))
|
2011-02-18 16:54:48 +00:00
|
|
|
|
{
|
2014-11-02 08:03:31 +00:00
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
var msrString = frm.User().MsrString;
|
|
|
|
|
if (MessageBox.Show("Update Msr Card", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
|
|
|
|
|
DialogResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
user.MsrString = msrString;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
bi.Update(user);
|
2014-10-12 09:41:45 +00:00
|
|
|
|
bi.SaveChanges();
|
2014-11-02 08:03:31 +00:00
|
|
|
|
MessageBox.Show("Msr Card Updated");
|
|
|
|
|
this.Close();
|
2011-02-18 16:54:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|