You are on page 1of 14

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 System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Assignment2FACADE
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());

}
}
public class AutoClosingMessageBox
{
System.Threading.Timer _timeoutTimer;
string _caption;
AutoClosingMessageBox(string text, string caption, int timeout)
{
_caption = caption;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
using (_timeoutTimer)
MessageBox.Show(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 != IntPtr.Zero)
SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
_timeoutTimer.Dispose();
}
const int WM_CLOSE = 0x0010;
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet =
System.Runtime.InteropServices.CharSet.Auto)]
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")


{
AutoClosingMessageBox.Show("Login Success", "Redirecting....", 1000);
Form1 ob8 = (Form1)Application.OpenForms["Form1"];
ob8.LblName.Visible = true;
ob8.LblName.Text = "HI " + userName;
ob8.Btnbutton1.Visible = false;
ob8.BtnLogin.Visible = false;
ob8.Btncontinue.Visible = true;

HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 2
Visual Programming

ob8.BtnSignout.Visible = true;
Form2 ob7 = (Form2)Application.OpenForms["Form2"];
ob7.Close();

}
else
{
MessageBox.Show("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)Application.OpenForms["Form5"];
Form3 ob8 = (Form3)Application.OpenForms["Form3"];
ob8.Close();
AutoClosingMessageBox.Show("Card Verified", "Redirecting....", 1000);
ob7.BtnPayNow.Visible = true;
ob7.PicVisa.Visible = true;
ob7.Lbltxtpayment.Visible = false;
ob7.lblcardAsterik.Visible = true;
string RepCardNo = cardNum.Remove(4);
RepCardNo += "************";
ob7.lblcardAsterik.Text = RepCardNo;
ob7.CmbpaymentMethod.Visible = false;
ob7.BtnProceed.Visible = false;

}
else
MessageBox.Show("Invalid Credit Card");

}
class Payamount
{
public void CreditLimit(double PayAmount)
{

if (PayAmount > 20001)


{
Form5 ob7 = (Form5)Application.OpenForms["Form5"];
ob7.LblpayError.Visible = true;
ob7.LblpayError.Text = "*Amount exceeding your Dialy Credit Limit";

HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 3
Visual Programming

ob7.BtnPayNow.Visible = false;
ob7.BtnGoBack.Visible = true;

}
else
{
AutoClosingMessageBox.Show("Payment Successfull", "Redirecting....",
1000);

Form1 ob2 = (Form1)Application.OpenForms["Form1"];


ob2.Btncontinue.Visible = false;
ob2.BtnExit.Visible = true;
ob2.LbltxtCardLimtit.Visible = true;
ob2.LbltxtRemainbalance.Visible = true;
ob2.LblShowRaimingBln.Visible = true;
ob2.LblShowRaimingBln.Text = (200000 - PayAmount).ToString();
ob2.LblShowRaiminglimit.Visible = true;
ob2.LblShowRaiminglimit.Text = (20000 - PayAmount).ToString();
Form5 ob7 = (Form5)Application.OpenForms["Form5"];
ob7.Close();
}

}
}

HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 4
Visual Programming

Form2:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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 = txtUser.Text;

HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 5
Visual Programming

string Password = txtPass.Text;


//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 this.lblLoginFirst; }
}
public void EnablelblFirst()
{
this.lblLoginFirst.Enabled = true;
}
}
}

Form3:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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 (txtCCardNum.Text.Length > 16)
{
lblCardNoInvalid.Text = "* Max 16 digit Allowed";
}
if (txtCCardNum.Text.Length == 0)
{
lblCardNoInvalid.Text = "* Please Enter value";
}
if (txtCCardNum.Text.Length > 0 && txtCCardNum.Text.Length < 16)
{
lblCardNoInvalid.Text = "* Please Enter Complete Value";
}
if (txtCcvNum.Text.Length > 3)
{
lblCcvError.Text = "* Max 3 digit Allowed";
}
if (txtCcvNum.Text.Length == 0)
{
lblCcvError.Text = "* Please Enter value";
}
if ( txtCcvNum.Text.Length < 3)
{
lblCcvError.Text = "* Please Enter Complete Value";
}
try
{
double CardNo = Int64.Parse(txtCCardNum.Text);
}
catch (FormatException)
{
lblCardException.Text = "* Please enter number only:";
}

HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 7
Visual Programming

try
{
double CcvNo = Int64.Parse(txtCCardNum.Text);
}
catch (FormatException)
{

lblCcvException.Text = "* Please enter number only:";


}

if (txtCCardNum.Text.Length == 16 && txtCcvNum.Text.Length == 3)


{
try
{
double CardNo = Int64.Parse(txtCCardNum.Text);
}
catch (FormatException)
{
lblCardException.Text = "* Please enter number only:";
}

try
{
double CcvNo = Int64.Parse(txtCCardNum.Text);
}
catch (FormatException)
{

lblCcvException.Text = "* Please enter number only:";


}
//calling using facade class
Checkout _Checkout = new Checkout();
_Checkout.CreditcardConfirmation(txtCCardNum.Text,txtCcvNum.Text,
cmbMonth.Text, cmbYear.Text);
}

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 System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Assignment2FACADE
{
public partial class Form5 : Form
{

public Form5()
{
InitializeComponent();
}

private void lblSalesPrice_Click(object sender, EventArgs e)


{

}
public Label lblSalesprice
{
get { return this.lblSalesPrice; }
}

HUMZA-ZAHID(01-131162-008) SUBTAIN-HAIDER(01-131162-049) 9
Visual Programming

public void Enablesignout()


{
this.lblSalesPrice.Enabled = true;
}

private void lblShippingCharges_Click(object sender, EventArgs e)


{

}
public Label lblSippingharges
{
get { return this.lblShippingCharges; }
}
public void EnableshippingCharges()
{
this.lblShippingCharges.Enabled = true;
}

private void lblSubtotal_Click(object sender, EventArgs e)


{

}
public Label lblSubTtl
{
get { return this.lblSubtotal; }
}
public void EnablelblSubttl()
{
this.lblSubtotal.Enabled = true;
}

private void lblWhtTax_Click(object sender, EventArgs e)


{

}
public Label lblWhtTx
{
get { return this.lblWhtTax; }
}
public void EnableWhtTx()
{
this.lblWhtTax.Enabled = true;
}

private void lblTotal_Click(object sender, EventArgs e)


{

}
public Label lblTtl
{
get { return this.lblTotal; }
}
public void Enablettl()
{
this.lblTotal.Enabled = 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 (cmbPaymentMethod.Text == "Pay With CreditCard")
{
Form3 form3 = new Form3();
form3.ShowDialog();

}
else if (cmbPaymentMethod.Text == "Cash On Delivery")
{
Form1 ob2 = (Form1)Application.OpenForms["Form1"];
ob2.LbltxtCardLimtit.Visible = true;
double total = Convert.ToDouble(Math.Round(decimal.Parse(lblTotal.Text),
3));
ob2.LbltxtCardLimtit.Text = ("Your order is will be dispatched soon
Please Keep the exact " + total + " Ready");
ob2.Btncontinue.Visible = false;
ob2.BtnExit.Visible = true;
Close();

}
}
public Button BtnProceed
{
get { return this.btnProceed; }
}
public void EnablebtnProceed()
{
this.btnProceed.Enabled = true;
}

private void cmbPaymentMethod_SelectedIndexChanged(object sender, EventArgs e)


{

}
public ComboBox CmbpaymentMethod
{
get { return this.cmbPaymentMethod; }
}
public void EnablecmbPaymentMethod()
{
this.cmbPaymentMethod.Enabled = 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()
{
this.pictureBox1.Enabled = true;
}

private void lbltxtPayment_Click(object sender, EventArgs e)


{

}
public Label Lbltxtpayment
{
get { return this.lbltxtPayment; }
}
public void EnableLbltxtpayment()
{
this.lbltxtPayment.Enabled = true;
}

private void lblCardasterisk_Click(object sender, EventArgs e)


{

}
public Label lblcardAsterik
{
get { return this.lblCardasterisk; }
}
public void EnableCardAsterisk()
{
this.lblCardasterisk.Enabled = true;
}

private void btnPaynow_Click(object sender, EventArgs e)


{
Checkout checkout = new Checkout();
Form1 form1 = new Form1();
double total = Convert.ToDouble(Math.Round(decimal.Parse(lblTotal.Text), 3));
//calling using facede class
checkout.PaymentVerification(total);

}
public Button BtnPayNow
{
get { return this.btnPaynow; }
}
public void EnablePayNow()
{
this.btnPaynow.Enabled = 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 this.lblPaymentError; }


}
public void EnablelblPayError()
{
this.lblPaymentError.Enabled = true;
}

private void btnGoback_Click(object sender, EventArgs e)


{
Close();
}
public Button BtnGoBack
{
get { return this.btnGoback; }
}
public void EnablelbtnGoback()
{
this.btnGoback.Enabled = 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

You might also like