protected void AttemptTransaction(string cuser, long barcode, decimal amount, string concept, int PINtry)
 {
     TransactionStatus ts;
     GoDine a = new GoDine();
     ts = a.Transaction_from_GcBC_2_CUser_PIN(barcode, cuser, amount, concept, 0, PINtry);
     string status = "";
     if (!ts.cuserexist) {
         status = status + "\nCompany user does not exist";
     }
     if (!ts.giftcardexist){
         status = status + "\nGift card is not valid";
     }
     if (status == "")  {
         if (!ts.enoughmoney)
         {
             Response.Write("START\nWARNING\nNot enough money,  $" + ts.moneyleft.ToString("0.00") + "   left.\nSTOP");
         }
         else if (ts.status == 1000)
         {
             Response.Write("START\nSUCCESS\nTRANSACTION SUCCESS\nThere is    $" + ts.moneyleft.ToString("0.00") + "    left in the gift card.\nSTOP");
         }
         else if (ts.PINprotected)
         {
             Response.Write("START\nPROTECTED\nGift card is password protected, insert PIN\nSTOP");
         }
         else
         {
             Response.Write("START\n0\nUnknown problem. Please contact GoDine.\nSTOP");
         }
     }
     else {
         Response.Write("START\nWARNING" + status + "\nSTOP");
     }
 }
    protected void btnpayment0_Click(object sender, EventArgs e)
    {
        GoDine a = new GoDine();
        long barcode = 0;
        decimal amount = 0;
        string problems = "";
        lblproblems.Text = "";
        lblsuccess.Text = "";
        ///////////////////////////// PRELIMINARY VERIFICATION PHASE
        if (!IsValidString(tbcuser.Text))
        {
            problems = problems + "Company User is not valid. ";
        }
        try
        {
            barcode = Convert.ToInt64(tbbarcode.Text);
            barcode = UTILITIES.GC_Del_CheckSum(barcode);
            if (barcode <= 0){
                problems = problems + "Barcode is not valid. ";
            }
        }catch{
            problems = problems + "Barcode is not valid. ";
        }
        try{
            amount = Convert.ToDecimal(tbamount.Text);
            if (amount <= 0){
                problems = problems + "Amount to pay must be positive. ";
            }
        }
        catch
        {
            problems = problems + "Amount to pay must be a number. ";
        }
        if (tbcuser.Text.Length > 50) {
            problems = problems + "Company user is not valid. ";
        }
        if (!IsValidString(tbconcept.Text))
        {
            problems = problems + "Concept is not valid. ";
        }

        ////////////////////////// SECOND VERIFICATION PHASE
        if (problems == "")
        {
            string concept = tbconcept.Text;
            int PINtry = -123456;
            TransactionStatus ts = a.Transaction_from_GcBC_2_CUser_PIN(barcode, tbcuser.Text, amount, concept, 0, PINtry);
            if (!ts.cuserexist){
                problems = problems + "Company user does not exist. ";
            }
            if (!ts.giftcardexist) {
                problems = problems + "Barcode is not valid. ";
            }

            if (problems == "")
            {
                if (!ts.enoughmoney)
                {
                    lblproblems.Text = "Not enough money,     $" + ts.moneyleft.ToString("0.00") + "     left.";
                }
                else if (ts.PINprotected)
                {
                    tbamount.Enabled = false;
                    tbbarcode.Enabled = false;
                    tbconcept.Enabled = false;
                    tbcuser.Enabled = false;
                    tbPIN.Visible = true;
                    btntransaction.Visible = false;
                    btntransactionPIN.Visible = true;
                    lblPINfix.Visible = true;
                    lblproblemsPIN.Visible = true;
                    lblok_step1.Text = "This gift card is password-protected. Insert PIN.";
                    lblproblems.Text = "";
                }
                else if (ts.status == 1000)
                {
                    Notify_Transaction_Success(ts);
                }
                else {
                    lblproblems.Text = "Unknown problem. Please contact GoDine.";
                }
            }
            else {
                lblproblems.Text = problems;
            }
        }
        else
        {
            lblproblems.Text = problems;
        }
    }
    protected void btnpaymentPIN_Click(object sender, EventArgs e)
    {
        int PINtry = -123;
        bool PINformatted = false;
        lblproblemsPIN.Text = "";
        try {
            PINtry = Convert.ToInt32(tbPIN.Text);
            if (PINtry >= 0) {
                PINformatted = true;
            }
        } catch{
            PINformatted = false;
        }

        if (PINformatted)
        {
            TransactionStatus ts;
            GoDine a = new GoDine();
            ts = a.Transaction_from_GcBC_2_CUser_PIN(Convert.ToInt64(tbbarcode.Text), tbcuser.Text, Convert.ToDecimal(tbamount.Text), tbconcept.Text, 0, PINtry);
            if (ts.status == 1000)
            {
                Notify_Transaction_Success(ts);
            }
            else {
                lblproblemsPIN.Text = "PIN is not correct.";
            }
        }
        else {
            lblproblemsPIN.Text = "PIN is not valid.";
        }
    }