private void metroTile1_Click(object sender, EventArgs e)
        {
            ePrinting print = new ePrinting();
            print.isLandscape = true;
            print.forReport = true;
            print.date = dtDailyReportDate.Value.ToShortDateString();
            print.OPType = (cmbOPType.Text == "BTR") ? 1 : (cmbOPType.Text == "UNDERGRAD") ? 2 : (cmbOPType.Text == "MASTERAL") ? 3 : (cmbOPType.Text == "FIDUCIARY") ? 4 : (cmbOPType.Text == "IGP") ? 5 : 0;
            print.OPTypeText = cmbOPType.Text;

            print.ePrint("DRLayoutOne");
        }
 private void btnPrint_Click(object sender, EventArgs e)
 {
     ePrinting ePrint = new ePrinting();
     ePrint.ePrint();
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (lvDataEntryOP.Items.Count > 0)
            {
                float total = float.Parse(lbTotal.Text);

                if (total > 0 && (!string.IsNullOrEmpty(tbFirstname.Text) && !string.IsNullOrEmpty(tbLastname.Text)))
                {
                    OrderOfPayment OP = null;
                    StudentAccount SAccount = new StudentAccount();
                    Dictionary<string, float> amountPerParticular = SAccount.getAmountPerParticular(lvDataEntryOP,2);
                    string payor = tbFirstname.Text.Replace("'","''") + " " + tbMiddlename.Text + " " + tbLastname.Text;

                    int orderOfPaymentType = 0 ;
                    try
                    {
                        orderOfPaymentType = int.Parse((mrbUndergrad.Checked) ? mrbUndergrad.Tag.ToString() : (mrbMasteral.Checked) ? mrbMasteral.Tag.ToString() : (mrbFiduciary.Checked) ? mrbFiduciary.Tag.ToString() : (mrbBtr.Checked) ? mrbBtr.Tag.ToString() : (mrbIGD.Checked) ? mrbIGD.Tag.ToString() : "0" );
                        paymentType = (mtrbCash.Checked) ? mtrbCash.Tag.ToString() : (mtrbCheck.Checked) ? mtrbCheck.Tag.ToString() : "0";
                    }
                    catch (Exception ex)
                    {

                        MessageBox.Show(ex.Message);
                    }

                    // check payment type
                    // check if has student ID
                    int studentID = 0;
                    if(lbStudID.Text != "[ Student ID ]")
                        studentID = int.Parse(lbStudID.Text);

                    string purpose = "Other Fees";

                    // Purpose
                    if (isTuitionFee)
                    {
                        purpose = "Tuition Fee/Misc";
                    }

                    // has check details
                    if (Payor.validateCheckDetails(mtbBankName.Text, mtbCheckNo.Text, mtdCheckDate.Value.ToShortDateString(), mtbCheckAmount.Text) && mtrbCheck.Checked)
                    {
                        OP = new OrderOfPayment(float.Parse(tAmount.Text), int.Parse(tPaymentOrNo.Text), dtOrDate.Value.ToShortDateString(), purpose, payor, studentID, tbRemarks.Text, mtbBankName.Text, mtbCheckNo.Text, mtdCheckDate.Value.ToShortDateString(), float.Parse(mtbCheckAmount.Text),int.Parse(paymentType));
                    }
                    else if (mtrbCash.Checked)
                        OP = new OrderOfPayment(float.Parse(tAmount.Text), int.Parse(tPaymentOrNo.Text), dtOrDate.Value.ToShortDateString(), purpose, payor, studentID, tbRemarks.Text, null, null, null, 0, int.Parse(paymentType));
                    else
                        MessageBox.Show("There are some fields missing!");
                    // final validation
                    if (OP != null)
                    {
                        if (OP.createOP())
                        {
                            OP.addOPItem(int.Parse(tPaymentOrNo.Text), amountPerParticular, orderOfPaymentType);
                            MessageBox.Show("Successful! \n \t Please Proceed to Payment");

                            Dictionary<string, string> OPData = OP.getOPDataWOOR(int.Parse(tPaymentOrNo.Text));
                            ePrinting print = new ePrinting(OPData);
                            print.ePrint("OP");

                            this.Dispose();
                            frmOrPayDataEntry  temp  = new frmOrPayDataEntry();
                            temp.ShowDialog();

                        }
                    }

                }
                else
                {
                    MessageBox.Show("Invalid Input / Missing Field");
                }
            }
            else
            {
                MessageBox.Show("Please add an item");
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool hasPayment = false;
            if (float.Parse(tbAmount.Text) < float.Parse(lblAmountToPay.Text))
            {
                MessageBox.Show(" Invalid Amount");
            }
            else
            {

                string query = "SELECT SA.SeqNo, SA.StudID, SA.SemNo, SA.Particular, SA.Amount, ISNULL(SA.Payment,0), ISNULL(SA.Balance,0),OP.Amount FROM Student_Account as SA JOIN tbl_PayOrder as OP ON SA.StudID = OP.StudID WHERE OP.OPNo = ";
                int recordCount = new clsDB().Con().countRecord(query + orderOfPaymentNo);
                string[][] data = new string[recordCount][];

                // if it is for Student Account
                if (recordCount > 0)
                {
                    new clsDB().Con().SelectData(query + orderOfPaymentNo, data);

                    StudentAccount sa = new StudentAccount();
                    Dictionary<string, string> studentAccountData = sa.getData(data);

                    int tuitionSeqNo = int.Parse(studentAccountData["tuitionSeqNo"]);
                    float mFee = float.Parse(studentAccountData["mFee"]);
                    int StudID = int.Parse(studentAccountData["StudID"]);
                    int semNo = int.Parse(studentAccountData["SemNo"]);

                    if (StudentAccount.updatePayment(sa.seqNo, tuitionSeqNo, float.Parse(tbAmount.Text), StudID, mFee, semNo))
                    {
                        hasPayment = true;
                    }
                    else
                    {
                        MessageBox.Show("There was an error!");
                    }

                }
                // if for Misc Fees and other payments
                else
                {
                    hasPayment = true;
                }

            }

            // Final Procedure
            if (hasPayment)
            {
                string checkAmount = null, checkDate = null, checkNo = null, bankName = null, PaymentType = null ;

                OPData.TryGetValue("CheckAmount", out checkAmount);
                OPData.TryGetValue("CheckNo", out checkNo);
                OPData.TryGetValue("CheckDate", out checkDate);
                OPData.TryGetValue("BankName", out bankName);
                 OPData.TryGetValue("PaymentType", out PaymentType);

                clsCollection col = new clsCollection(orderOfPaymentNo, int.Parse(OrderOfPayment.getLastORNo()), dtORDate.Value.ToShortDateString(), float.Parse(tbAmount.Text), OPData["Payor"].Replace("'","''"), checkNo,bankName, checkDate, float.Parse(checkAmount), int.Parse(PaymentType));

                if (OP.updateOP(int.Parse(tbORNo.Text), orderOfPaymentNo))
                    if (col.create())
                    {
                        OP.paidOP(orderOfPaymentNo);
                        col.addCollectionItem();

                        string[][] particularsAmount = OP.getOrderOfPaymentItem(orderOfPaymentNo);

                        OPData["collectionDate"] = dtORDate.Value.ToShortDateString();
                        int currOrNumber = int.Parse(OrderOfPayment.getLastORNo()) - 1;
                        OPData["ORNumber"] = ""+currOrNumber;

                        ePrinting print = new ePrinting(OPData, particularsAmount);

                        // temporary fix for OTHER Payment
                        if (OPData["Purpose"] == "Other Fees")
                            print.isOtherPayment = true;

                        print.ePrint("OR");

                        Close();
                    }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            // instantiate student object
            try
            {
                if ( !Helper.strIsEmpty(tAmount.Text, true))
                {
                    Student st = new Student(listView1.Items[0].SubItems[1].Text);

                    string course = st.course();

                    // temporary conditioning to check if a student is masteral or undergrad
                    int OPType = (course.StartsWith("B")) ? 2 : 3;

                    Dictionary<string,float> amountPerParticular = SAccount.getAmountPerParticular(listView1,3,"tuition/msc");

                    if (amountPerParticular["Tuition Fee"] > 0 && amountPerParticular["Tuition Fee"] > float.Parse(tAmount.Text))
                    {
                        amountPerParticular["Tuition Fee"] = float.Parse(tAmount.Text) - float.Parse(lbMscFee.Text);

                    }

                    // validation
                    bool isValid = false;
                    string paymentType = (isFullPayment) ? "full" : "partial";

                    bool isCheck = false;
                    if (mtrbCheck.Checked)
                        isCheck = true;
                    else if (mtrbCash.Checked)
                        isCheck = false;

                    // check if NSTP is selected
                    string NSTP = (mtrbCWTS.Checked) ? mtrbCWTS.Text : (mtrbROTC.Checked) ? mtrbROTC.Text : null;

                    if (string.IsNullOrEmpty(NSTP)  && hasNSTP)
                    {
                        isValid = false;
                        MessageBox.Show("Please select NSTP Type");
                        return;
                    }

                    isValid = StudentAccount.validateAmout(paymentType, float.Parse(lbTotal.Text), float.Parse(tAmount.Text), float.Parse(lbTuitionFee.Text), float.Parse(lbMscFee.Text), isCheck);

                    if (isValid )
                    {
                        // ---------------- FINAL PROCEDURE -------------------
                        if (isValid)
                        {
                            OrderOfPayment OP = null;
                            if (Payor.validateCheckDetails(mtbBankName.Text, mtbCheckNo.Text, mtdCheckDate.Value.ToShortDateString(), mtbCheckAmount.Text) && mtrbCheck.Checked)
                            {
                                OP = new OrderOfPayment(float.Parse(tAmount.Text), int.Parse(tPaymentOrNo.Text), dtOrDate.Value.ToShortDateString(), "Tuition Fee/Misc", studentData[3] +' '+ studentData[4] +' '+studentData[2], int.Parse(studentData[0]), "", mtbBankName.Text, mtbCheckNo.Text, mtdCheckDate.Value.ToShortDateString(), float.Parse(mtbCheckAmount.Text));
                            }
                            else if (mtrbCash.Checked)
                                OP = new OrderOfPayment(float.Parse(tAmount.Text), int.Parse(tPaymentOrNo.Text), dtOrDate.Value.ToShortDateString(), "Tuition Fee/Misc", studentData[3] + ' ' + studentData[4] + ' ' + studentData[2], int.Parse(studentData[0]));
                            else
                                MessageBox.Show("There are some fields missing!");
                            // validated
                            if (OP != null)
                            {
                                if (OP.createOP())
                                {
                                    OP.addOPItem(int.Parse(tPaymentOrNo.Text), amountPerParticular, OPType, NSTP);
                                    MessageBox.Show("Successful! \n \t Please Proceed to Payment");

                                    Dictionary<string, string> OPData = OP.getOPDataWOOR(int.Parse(tPaymentOrNo.Text));
                                    ePrinting print = new ePrinting(OPData);
                                    print.ePrint("OP");

                                    Close();

                                }
                            }

                        }

                    }
                }
                else
                {
                    MessageBox.Show("Please select ");
                }

            }
            catch(Exception ex)
            {
                MessageBox.Show("There are some fields missing", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }