コード例 #1
0
        private void txtCustomerID_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            #region txtPurchaseID
            if (sender == txtPurchaseID)
            {
                if (e.KeyCode == Keys.PageDown || e.KeyCode == Keys.F3)
                {
                    return;
                }


                if (e.KeyCode.ToString() == "F2")
                {
                    if (oPurchase.View())
                    {
                        oPayment.PurchaseID = oPurchase.ID;
                        txtPurchaseID.Text  = oPurchase.ID;
                        oVendor.Find(oPurchase.VendID);
                        txtName.Text         = oVendor.Name;
                        txtAmountDue.Enabled = false;
                        txtAmountDue.Text    = (oPurchase.Total + oPurchase.GetPayments()).ToString();
                        ctrType.Focus();
                        //txtAmount.Focus();
                    }
                    return;
                }

                if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Tab)
                {
                    if (txtPurchaseID.Text.Trim().Length == 0)
                    {
                        Clear();
                        txtPurchaseID.Focus();
                    }

                    if (oPurchase.Find(txtPurchaseID.Text))
                    {
                        oPayment.PurchaseID = oPurchase.ID;
                        txtPurchaseID.Text  = oPurchase.ID;
                        oVendor.Find(oPurchase.VendID);
                        txtName.Text         = oVendor.Name;
                        txtAmountDue.Enabled = false;
                        txtAmountDue.Text    = (oPurchase.GetTotal() + oPurchase.GetPayments()).ToString();
                        //txtAmountDue.Text = oPurchase.StatementAmountDue.ToString();
                        //txtAmount.Focus();
                        ctrType.Focus();
                        return;
                    }
                    else
                    {
                        Clear();
                    }
                }
            }
            #endregion
            #region txtChargeID
            if (sender == txtChargeID)
            {
                if (e.KeyCode.ToString() == "F2")
                {
                    if (oPayment.View(txtPurchaseID.Text))
                    {
                        Display();
                        txtChargeID.Text = oPayment.ID;
                    }
                    return;
                }

                if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Tab)
                {
                    if (oPayment.Find(txtChargeID.Text))
                    {
                        Display();
                        txtChargeID.Text = oPayment.ID;
                    }
                    return;
                }
            }
            #endregion
            #region txtAmount
            if (sender == txtAmount)
            {
                if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Tab)
                {
                    if (txtAmount.Number != 0.00)
                    {
                        txtComment.Focus();
                    }

                    return;
                }
            }
            #endregion
            #region txtText
            if (sender == txtComment)
            {
                if (e.KeyCode != Keys.PageDown)
                {
                    return;
                }
            }
            #endregion


            #region Default Option
            //Default option
            switch (e.KeyCode)
            {
            case Keys.Tab:
                if (!e.Shift)
                {
                    this.SelectNextControl(this.ActiveControl, true, true, true, true);
                }
                break;

            case Keys.Enter:
                this.SelectNextControl(this.ActiveControl, true, true, true, true);
                break;

            case Keys.Down:
                this.SelectNextControl(this.ActiveControl, true, true, true, true);
                break;

            case Keys.Up:
                this.SelectNextControl(this.ActiveControl, false, true, true, true);
                break;

            case Keys.F8:
                break;

            case Keys.F3:
            {
                if (txtChargeID.Text.Trim() != String.Empty)
                {
                    if (MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        MessageBox.Show("Operation Cancelled");
                        return;
                    }
                    else
                    {
                        oPayment.Delete();
                        // oPurchase.GetPayments();
                        // oPurchase.UpdateCurrentTotals();
                        // oPurchase.HasChanged = true;
                        Clear();
                        txtPurchaseID.Focus();
                    }
                }
            }
            break;

            case Keys.F7:
                this.Close();
                break;

            case Keys.PageDown:

                oPayment.ID   = txtChargeID.Text;
                oPayment.Date = (DateTime)txtDate.Value;

                oPayment.Comment = txtComment.Text;
                switch (ctrType.Text)
                {
                case "Payment":
                    oPayment.Type   = "P";
                    oPayment.Amount = txtAmount.Number * -1;
                    break;

                case "Adjustment":
                    oPayment.Type   = "A";
                    oPayment.Amount = txtAmount.Number;
                    break;

                case "Invoice":
                    oPayment.Type = "I";
                    // if (txtAmount.Number < 0)
                    oPayment.Amount = txtAmount.Number;
                    break;

                default:
                    oPayment.Amount = txtAmount.Number;
                    break;
                }


                if (txtChargeID.Text == "")
                {
                    oPayment.Insert();
                    // if (oPayment.Type == "P" && oPurchase.StatementAmountDue != 0)
                    //     oPurchase.PrintStatement(null, PrinterDevice.Printer);
                }
                else
                {
                    oPayment.Save();
                }
                //oPurchase.GetPayments();
                //oPurchase.UpdateCurrentTotals();
                //oPurchase.HasChanged = true;
                Clear();
                //txtCustomerID.Clear();
                txtPurchaseID.Focus();
                break;
            }
            #endregion
        }