public customerScan(string fname, string lname, float pastLoyalPoints, string billNo, string dateToday, string CustomerId, float total, giftVTransition1 state) { InitializeComponent(); // _state = state; this.billNo = billNo; this.dateToday = dateToday; this.CustomerId = CustomerId; this.total = total; this.fname = fname; this.lname = lname; this.pastLoyalPoints = pastLoyalPoints; }
private void giftVoucherProcess() { //Local Variables string voucherBarcodeNo = txtScan.Text; float vValue = 0; int vStatus = 0; bool notExpired = false; string expiaryDate = ""; // dbString db = new dbString(); string connString = db.connectionSring; MySqlConnection conn = new MySqlConnection(connString); try { conn.Open(); string Query = "SELECT `vExpDate`, `status`, `value` FROM `giftvouchertable` WHERE `vBarcode` = '" + voucherBarcodeNo + "'"; MySqlCommand mySqlCommand = new MySqlCommand(Query, conn); MySqlDataReader rdr = mySqlCommand.ExecuteReader(); while (rdr.Read()) { expiaryDate = rdr[0].ToString(); vStatus = Convert.ToInt32(rdr[1]); vValue = Convert.ToSingle(rdr[2]); } rdr.Close(); try { exp = Convert.ToDateTime(expiaryDate); } catch { notExpired = false; // MessageBox.Show("Error in Date conversion"); } if (date > exp)//expied { notExpired = false; expiaryDate = ""; } else if (date <= exp)//Not Expired { // textBox1.Text = "Not Exp"; notExpired = true; expiaryDate = ""; } } catch { MessageBox.Show("Exception Occured in connecting to Database"); } finally { conn.Close(); } ////////////////////////////////////////////////// ///// if (vStatus == 1 && notExpired == true && (total >= vValue)) //Voucher Issued and not presented for redemption { if (proIdBuffer == "") { txtScan.Enabled = false; txtQty.Enabled = false; txtSearch.Enabled = false; giftVTransition1 state = new giftVTransition1(string.Empty, 0); var GV = new GiftVoucherPay(voucherBarcodeNo, state); GV.ShowDialog(); //textBox1.Text = state.Text; //textBox1.SelectionStart = state.CaretPosition; loyalty = loyalty + Convert.ToSingle(state.Text); txtLoyalty.Text = loyalty.ToString(); total = subTotal - loyalty - discount; txtTotal.Text = total.ToString(); } else { txtScan.Clear(); MessageBox.Show("Complete the existing transaction and try again"); txtCash.Focus(); } notExpired = false; } else if (vStatus == 2) //Voucher is redemmed { MessageBox.Show("This voucher already presented for redemption."); } else if (total < vValue) // if voucher cannot be fully utilized { MessageBox.Show("Total sum of amount should be greater than gift voucher value"); } else if (vStatus == 0)//New voucher { Regex validator500 = new Regex("^['V'][0-9]{10}[1]$"); if (validator500.Match(voucherBarcodeNo).Success) {// // voucherBarcodeNo.Text = "500.00"; var state = new giftVTransition1(string.Empty, 0); GiftVoucher gv = new GiftVoucher(voucherBarcodeNo, state); gv.ShowDialog(); txtScan.Text = "1111111110500"; txtScan.Enabled = false; txtQty.Enabled = false; btnAddItem.PerformClick(); } Regex validator1000 = new Regex("^['V'][0-9]{10}[2]$"); if (validator1000.Match(voucherBarcodeNo).Success) {// //txtValue.Text = "1000.00"; var state = new giftVTransition1(string.Empty, 0); GiftVoucher gv = new GiftVoucher(voucherBarcodeNo, state); gv.ShowDialog(); txtScan.Text = "1111111111000"; txtScan.Enabled = false; txtQty.Enabled = false; btnAddItem.PerformClick(); } Regex validator2000 = new Regex("^['V'][0-9]{10}[3]$"); if (validator2000.Match(voucherBarcodeNo).Success) {// //txtValue.Text = "2000.00"; var state = new giftVTransition1(string.Empty, 0); GiftVoucher gv = new GiftVoucher(voucherBarcodeNo, state); gv.ShowDialog(); txtScan.Text = "1111111112000"; txtScan.Enabled = false; txtQty.Enabled = false; btnAddItem.PerformClick(); } Regex validator5000 = new Regex("^['V'][0-9]{10}[4]$"); if (validator5000.Match(voucherBarcodeNo).Success) {// // txtValue.Text = "5000.00"; var state = new giftVTransition1(string.Empty, 0); GiftVoucher gv = new GiftVoucher(voucherBarcodeNo, state); gv.ShowDialog(); txtScan.Text = "1111111115000"; txtScan.Enabled = false; txtQty.Enabled = false; btnAddItem.PerformClick(); } } else if (notExpired == false)// if Voucher is Expired { MessageBox.Show("This voucher is Expired"); } // Reset Local Variables voucherBarcodeNo = ""; vValue = 0; vStatus = 0; notExpired = false; expiaryDate = ""; }
private void txtScan_TextChanged(object sender, EventArgs e) { lblTime.Text = DateTime.Now.ToShortTimeString(); //Update Time Regex validator = new Regex("^[0-9]{13}$"); Regex validator1 = new Regex("^['V'][0-9]{11}$"); Regex validator2 = new Regex("^['C'][0-9]{5}$"); if (validator.Match(txtScan.Text).Success) { txtQty.Text = "1"; scanForItem(); } else if (validator1.Match(txtScan.Text).Success) // for Gift Vouchers { btnAddItem.PerformClick(); txtQty.Text = "1"; giftVoucherProcess(); } else if (validator2.Match(txtScan.Text).Success) { //Block Further Items adding to Cart btnAddItem.PerformClick(); //Validity of card dbString db = new dbString(); string connString = db.connectionSring; MySqlConnection conn = new MySqlConnection(connString); string query = "SELECT `cusFirstName`, `cusLastName`, `cusLoyaltyPoints` FROM `customertable` WHERE `cusId` = '" + txtScan.Text + "'"; string cusFname = ""; string cusLname = ""; float cusPastLoyalPoints = 0; conn.Open(); try { MySqlCommand mySqlCommand = new MySqlCommand(query, conn); MySqlDataReader rdr = mySqlCommand.ExecuteReader(); while (rdr.Read()) { cusFname = rdr[0].ToString(); cusLname = rdr[1].ToString(); cusPastLoyalPoints = Convert.ToSingle(rdr[2]); } rdr.Close(); } catch { //MessageBox.Show("Error Connecting with the database. Try again Shortly."); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } if (cusFname != "") { giftVTransition1 state = new giftVTransition1(string.Empty, 0); customerScan customerScan = new customerScan(cusFname, cusLname, cusPastLoyalPoints, txtInvoice.Text, txtTransactionDate.Text, txtScan.Text, total, state); customerScan.ShowDialog(); //txtRedem.Text = loyalty.ToString(); try { redeem = Convert.ToSingle(state.Text); txtRedem.Text = redeem.ToString(); } catch { } //Prevent further items adding //ClearVariables; } else { MessageBox.Show("Invalied Card"); } } }
public GiftVoucher(string barcode, giftVTransition1 state) { InitializeComponent(); barC = barcode; _state = state; }