narsil/Tanshu.Accounts.PointOfSale/User Management/ChangePassword.cs
tanshu 3ca8b29e04 Regression: BillItemKey added the compare methods back
Regression: PrintLocation added the compare methods back
Breaking: Kot.Code is now integers
Breaking: Kot Update is now via Stored Procedure to get DB Values
Breaking: Reprints Insert is now via Stored Procedure to get DV Values
Breaking: Voucher.BillID and KotID are now integers
Breaking: Voucher Insert/Update is now via Stored Procedures to get DV Values also Dirty Checking for Voucher has been overwritten to set dirty for LastEditDate update
Fix: Login forms simplified
Feature: PrintLocation and Products are cached application wide.
2014-11-02 13:33:31 +05:30

103 lines
3.5 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class ChangePassword : Form
{
IKeyboardControl keyboardControl;
public ChangePassword(IKeyboardControl keyboardControl)
{
InitializeComponent();
this.keyboardControl = keyboardControl;
var control = keyboardControl as UserControl;
if (control != null)
{
control.Location = new System.Drawing.Point(6, 140);
this.Controls.Add(control);
this.Size = this.SizeFromClientSize(new Size(6 + control.Width + 6, 140 + control.Height + 6));
}
}
private void ChangePassword_Load(object sender, EventArgs e)
{
txtUsername.Text = Session.User.Name;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnChangePassword_Click(object sender, EventArgs e)
{
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()
{
using (var bi = new UserBI())
{
var user = bi.ValidateUser(Session.User.Name, txtPassword.Text.Trim());
if (user == null)
return false;
bi.ChangePassword(user, txtnewPassword.Text.Trim());
bi.SaveChanges();
MessageBox.Show("Password changed", "Confirm");
return true;
}
}
private void btnMsr_Click(object sender, EventArgs e)
{
using (var bi = new UserBI())
{
var user = bi.ValidateUser(Session.User.Name, txtPassword.Text.Trim());
if (user == null)
return;
using (var frm = new MsrLoginForm(true))
{
frm.ShowDialog();
var msrString = frm.User().MsrString;
if (MessageBox.Show("Update Msr Card", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
DialogResult.Yes)
return;
user.MsrString = msrString;
bi.Update(user);
bi.SaveChanges();
MessageBox.Show("Msr Card Updated");
this.Close();
}
}
}
}
}