using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LLNet.Tienda.MainForms.Forms
{
    public partial class frmEnganche : LLNet.GUI.FormBases.frmBase
    {
        public frmEnganche()
        {
            InitializeComponent();

            GUI.CApp.TraducirForm(this);
        }

        public override void Init(object[] pArgs)
        {
            base.Init(pArgs);

            if (pArgs != null)
                txtTotal.EditValue = pArgs[0];
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void frmEnganche_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            { 
                case Keys.F12:
                    btnAceptar_Click(null, null);
                    break;
                case Keys.Escape:
                    btnSalir_Click(null, null);
                    break;
            }
        }

        private void speEnganche_EditValueChanged(object sender, EventArgs e)
        {
            txtEnganche.EditValue = Convert.ToDecimal(txtTotal.EditValue) * ((DevExpress.XtraEditors.SpinEdit)sender).Value / 100;
        }

        private void txtEnganche_EditValueChanged(object sender, EventArgs e)
        {
            if (Utils.Helpers.ObjToStr(((DevExpress.XtraEditors.TextEdit)sender).EditValue).Trim() != string.Empty)
            {
                if (Convert.ToDecimal(((DevExpress.XtraEditors.TextEdit)sender).EditValue) > Convert.ToDecimal(txtTotal.EditValue))
                    speEnganche.EditValue = 100;
                else
                    speEnganche.EditValue = Convert.ToDecimal(((DevExpress.XtraEditors.TextEdit)sender).EditValue) / Convert.ToDecimal(txtTotal.EditValue) * 100;

            }
            else
                speEnganche.EditValue = 0;
        }
    }
}