Visual Programming
Assignment # 2
Question: Implement FAÇADE pattern for the following application: [CLO-2]
A member of a system is ordering some food from a store but system needs to
verify username and password using a subclass. User also have privilege to use
credit card for payment to purchase items. An application should be able to
perform verification for credit card and payment amount (remaining/limit of a
credit card).
Procedure:
Form1:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace Assignment2FACADE
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
[Link]();
[Link](false);
[Link](new Form1());
}
}
public class AutoClosingMessageBox
{
[Link] _timeoutTimer;
string _caption;
AutoClosingMessageBox(string text, string caption, int timeout)
{
_caption = caption;
_timeoutTimer = new [Link](OnTimerElapsed,
null, timeout, [Link]);
using (_timeoutTimer)
[Link](text, caption);
}
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 1
Visual Programming
public static void Show(string text, string caption, int timeout)
{
new AutoClosingMessageBox(text, caption, timeout);
}
void OnTimerElapsed(object state)
{
IntPtr mbWnd = FindWindow("#32770", _caption); // lpClassName is #32770 for
MessageBox
if (mbWnd != [Link])
SendMessage(mbWnd, WM_CLOSE, [Link], [Link]);
_timeoutTimer.Dispose();
}
const int WM_CLOSE = 0x0010;
[[Link]("[Link]", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[[Link]("[Link]", CharSet =
[Link])]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr
lParam);
}
public class Checkout
{
private Username _username = new Username();
private Creditcard _creditcard = new Creditcard();
private Payamount _payamount = new Payamount();
public void UsernameConfirmation(string UserName, string Password)
{
_username.ValidateUser(UserName, Password);
}
public void CreditcardConfirmation(string cardNum, string ccv, string
datem,string datey)
{
_creditcard.ValidateCreditcard(cardNum, ccv, datem, datey);
}
public void PaymentVerification(double total)
{
_payamount.CreditLimit(total);
}
}
class Username
{
public void ValidateUser(string userName, string password)
{
if (userName == "admin" && password == "12345")
{
[Link]("Login Success", "Redirecting....", 1000);
Form1 ob8 = (Form1)[Link]["Form1"];
[Link] = true;
[Link] = "HI " + userName;
[Link] = false;
[Link] = false;
[Link] = true;
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 2
Visual Programming
[Link] = true;
Form2 ob7 = (Form2)[Link]["Form2"];
[Link]();
}
else
{
[Link]("Enter wrong credentials");
}
class Creditcard
{
public void ValidateCreditcard(string cardNum,string ccv,string datem,string
datey )
{
if (cardNum == "1234567891234567" && ccv == "123" && datem == "11" && datey==
"22")
{
Form5 ob7 = (Form5)[Link]["Form5"];
Form3 ob8 = (Form3)[Link]["Form3"];
[Link]();
[Link]("Card Verified", "Redirecting....", 1000);
[Link] = true;
[Link] = true;
[Link] = false;
[Link] = true;
string RepCardNo = [Link](4);
RepCardNo += "************";
[Link] = RepCardNo;
[Link] = false;
[Link] = false;
}
else
[Link]("Invalid Credit Card");
}
class Payamount
{
public void CreditLimit(double PayAmount)
{
if (PayAmount > 20001)
{
Form5 ob7 = (Form5)[Link]["Form5"];
[Link] = true;
[Link] = "*Amount exceeding your Dialy Credit Limit";
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 3
Visual Programming
[Link] = false;
[Link] = true;
}
else
{
[Link]("Payment Successfull", "Redirecting....",
1000);
Form1 ob2 = (Form1)[Link]["Form1"];
[Link] = false;
[Link] = true;
[Link] = true;
[Link] = true;
[Link] = true;
[Link] = (200000 - PayAmount).ToString();
[Link] = true;
[Link] = (20000 - PayAmount).ToString();
Form5 ob7 = (Form5)[Link]["Form5"];
[Link]();
}
}
}
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 4
Visual Programming
Form2:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace Assignment2FACADE
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
private void btnLogin_Click(object sender, EventArgs e)
{
string UserName = [Link];
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 5
Visual Programming
string Password = [Link];
//calling using facade class
Checkout _Checkout = new Checkout();
_Checkout.UsernameConfirmation(UserName, Password);
private void txtUser_TextChanged(object sender, EventArgs e)
{
private void lblLoginFirst_Click(object sender, EventArgs e)
{
}
public Label lblLoginError
{
get { return [Link]; }
}
public void EnablelblFirst()
{
[Link] = true;
}
}
}
Form3:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace Assignment2FACADE
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 6
Visual Programming
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
private void label2_Click(object sender, EventArgs e)
{
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
private void btnProcess_Click(object sender, EventArgs e)
{
if ([Link] > 16)
{
[Link] = "* Max 16 digit Allowed";
}
if ([Link] == 0)
{
[Link] = "* Please Enter value";
}
if ([Link] > 0 && [Link] < 16)
{
[Link] = "* Please Enter Complete Value";
}
if ([Link] > 3)
{
[Link] = "* Max 3 digit Allowed";
}
if ([Link] == 0)
{
[Link] = "* Please Enter value";
}
if ( [Link] < 3)
{
[Link] = "* Please Enter Complete Value";
}
try
{
double CardNo = [Link]([Link]);
}
catch (FormatException)
{
[Link] = "* Please enter number only:";
}
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 7
Visual Programming
try
{
double CcvNo = [Link]([Link]);
}
catch (FormatException)
{
[Link] = "* Please enter number only:";
}
if ([Link] == 16 && [Link] == 3)
{
try
{
double CardNo = [Link]([Link]);
}
catch (FormatException)
{
[Link] = "* Please enter number only:";
}
try
{
double CcvNo = [Link]([Link]);
}
catch (FormatException)
{
[Link] = "* Please enter number only:";
}
//calling using facade class
Checkout _Checkout = new Checkout();
_Checkout.CreditcardConfirmation([Link],[Link],
[Link], [Link]);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
private void lblCardException_Click(object sender, EventArgs e)
{
}
}
}
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 8
Visual Programming
Form4:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace Assignment2FACADE
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void lblSalesPrice_Click(object sender, EventArgs e)
{
}
public Label lblSalesprice
{
get { return [Link]; }
}
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 9
Visual Programming
public void Enablesignout()
{
[Link] = true;
}
private void lblShippingCharges_Click(object sender, EventArgs e)
{
}
public Label lblSippingharges
{
get { return [Link]; }
}
public void EnableshippingCharges()
{
[Link] = true;
}
private void lblSubtotal_Click(object sender, EventArgs e)
{
}
public Label lblSubTtl
{
get { return [Link]; }
}
public void EnablelblSubttl()
{
[Link] = true;
}
private void lblWhtTax_Click(object sender, EventArgs e)
{
}
public Label lblWhtTx
{
get { return [Link]; }
}
public void EnableWhtTx()
{
[Link] = true;
}
private void lblTotal_Click(object sender, EventArgs e)
{
}
public Label lblTtl
{
get { return [Link]; }
}
public void Enablettl()
{
[Link] = true;
}
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 10
Visual Programming
private void Form5_Load(object sender, EventArgs e)
{
private void button1_Click(object sender, EventArgs e)
{
if ([Link] == "Pay With CreditCard")
{
Form3 form3 = new Form3();
[Link]();
}
else if ([Link] == "Cash On Delivery")
{
Form1 ob2 = (Form1)[Link]["Form1"];
[Link] = true;
double total = [Link]([Link]([Link]([Link]),
3));
[Link] = ("Your order is will be dispatched soon
Please Keep the exact " + total + " Ready");
[Link] = false;
[Link] = true;
Close();
}
}
public Button BtnProceed
{
get { return [Link]; }
}
public void EnablebtnProceed()
{
[Link] = true;
}
private void cmbPaymentMethod_SelectedIndexChanged(object sender, EventArgs e)
{
}
public ComboBox CmbpaymentMethod
{
get { return [Link]; }
}
public void EnablecmbPaymentMethod()
{
[Link] = true;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
public PictureBox PicVisa
{
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 11
Visual Programming
get { return this.pictureBox1; }
}
public void Enablepicturebox()
{
[Link] = true;
}
private void lbltxtPayment_Click(object sender, EventArgs e)
{
}
public Label Lbltxtpayment
{
get { return [Link]; }
}
public void EnableLbltxtpayment()
{
[Link] = true;
}
private void lblCardasterisk_Click(object sender, EventArgs e)
{
}
public Label lblcardAsterik
{
get { return [Link]; }
}
public void EnableCardAsterisk()
{
[Link] = true;
}
private void btnPaynow_Click(object sender, EventArgs e)
{
Checkout checkout = new Checkout();
Form1 form1 = new Form1();
double total = [Link]([Link]([Link]([Link]), 3));
//calling using facede class
[Link](total);
}
public Button BtnPayNow
{
get { return [Link]; }
}
public void EnablePayNow()
{
[Link] = true;
}
private void lblPaymentError_Click(object sender, EventArgs e)
{
}
public Label LblpayError
{
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 12
Visual Programming
get { return [Link]; }
}
public void EnablelblPayError()
{
[Link] = true;
}
private void btnGoback_Click(object sender, EventArgs e)
{
Close();
}
public Button BtnGoBack
{
get { return [Link]; }
}
public void EnablelbtnGoback()
{
[Link] = true;
}
}
}
Output:
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 13
Visual Programming
HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 14