Esempio n. 1
0
        /// <summary>
        /// Prüft eine MetroTextBox auf ein gültiges Datumstrennzeichen und setzt dieses (gibt TRUE bei korrektem Zeichen zurück)
        /// </summary>
        public bool Set_DatTrenn(IWin32Window owner, ref MetroTextBox textBox)
        {
            bool correct = false;

            if (textBox.Text.Length == 1)
            {
                char dattrenn = Convert.ToChar(textBox.Text);
                if (dattrenn == '.' || dattrenn == '-' || dattrenn == '/')
                {
                    Datumstrennzeichen = dattrenn;
                    correct            = true;
                }
                else
                {
                    MetroMessageBox.Show(owner, "Das eingegebene Datumstrennzeichen ist ungülig! Gülige Zeichen sind ausschießlich '.', '-' und '/' !", "Error bei Datumstrennzeichen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    correct = false;
                    textBox.Focus();
                    textBox.SelectAll();
                }
            }
            else
            {
                if (textBox.Text.Length != 0)
                {
                    textBox.Text = textBox.Text.Substring(0, 1);
                    Set_DatTrenn(owner, ref textBox);
                }
            }
            return(correct);
        }
Esempio n. 2
0
        /// <summary>
        /// Prüft eine MetroTextBox auf ein gültiges Dezimalsymbol und setzt dieses (gibt TRUE bei korrektem Zeichen zurück)
        /// </summary>
        public bool Set_DezSym(IWin32Window owner, ref MetroTextBox textBox)
        {
            bool correct = false;

            if (textBox.Text.Length == 1)
            {
                char dezsym = Convert.ToChar(textBox.Text);
                if (dezsym == ',' || dezsym == '.')
                {
                    Dezimaltrennzeichen = dezsym;
                    correct             = true;
                }
                else
                {
                    MetroMessageBox.Show(owner, "Das eingegebene Dezimalsymbol ist ungülig! Gülige Zeichen sind ausschießlich ',' und '.' !", "Error bei Dezimalsymbol", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    correct = false;
                    textBox.Focus();
                    textBox.SelectAll();
                }
            }
            else
            {
                if (textBox.Text.Length != 0)
                {
                    textBox.Text = textBox.Text.Substring(0, 1);
                    Set_DezSym(owner, ref textBox);
                }
            }
            return(correct);
        }
Esempio n. 3
0
        //validation for if it is a non negative int32
        public static bool IsNonNegativeInt32(MetroTextBox txtBox, string name, Label lblError)
        {
            bool isValid = true;
            int  value;

            if (!Int32.TryParse(txtBox.Text, out value))
            {
                isValid       = false;
                lblError.Text = name + " must be a number. Type: Int32";
                txtBox.SelectAll();
                txtBox.Focus();
            }
            else if (value < 0) // negetive
            {
                isValid       = false;
                lblError.Text = name + " must be positive or zero";
                txtBox.SelectAll();
                txtBox.Focus();
            }
            return(isValid);
        }
Esempio n. 4
0
        //validation for if input is a decimal
        public static bool IsADecimal(MetroTextBox txtBox, string name, Label lblError)
        {
            bool    isValid = true;
            decimal dec;

            if (!Decimal.TryParse(txtBox.Text, out dec))
            {
                isValid       = false;
                lblError.Text = name + " must be a number. Type: Decimal";
                txtBox.SelectAll();
                txtBox.Focus();
            }
            return(isValid);
        }
Esempio n. 5
0
        private void SelectAll(MetroTextBox tb)
        {
            if (string.IsNullOrEmpty(tb.Text))
            {
                return;
            }
            tb.SelectAll();
//            try
//            {
//                Clipboard.SetText(tb.Text, TextDataFormat.UnicodeText);
//            }
//            catch
//            {
//            }
        }
Esempio n. 6
0
        //validation for if it is a non negative decimal
        public static bool NotNegativeDeciaml(MetroTextBox txtBox, string name, Label lblError)
        {
            bool    isValid = true;
            decimal value;
            decimal notNegative;

            notNegative = Convert.ToDecimal(txtBox.Text);

            if (!Decimal.TryParse(txtBox.Text, out value))
            {
                isValid = false;
                IsADecimal(txtBox, name, lblError);
            }
            else if (notNegative < 0) // if negative
            {
                isValid       = false;
                lblError.Text = name + " must be positive or zero";
                txtBox.SelectAll();
                txtBox.Focus();
            }
            return(isValid);
        }
Esempio n. 7
0
        private void CalcularDescuentoRecargo(InputCalculo input)
        {
            decimal mto = 0, impuesto = 0;

            if (txtSubtotal.Text.Trim() != "" && decimal.TryParse(txtSubtotal.Text.Trim(), out decimal subtotal))
            {
                mto = subtotal;
                if (txtImpuesto.Text.Trim() != "" && decimal.TryParse(txtImpuesto.Text.Trim(), out impuesto))
                {
                    mto += impuesto;
                }

                #region Definiendo los txt's y el caso

                bool         isPorcentaje = false;
                string       estampa = "";
                MetroTextBox txtPorc = new MetroTextBox(), txtMto = new MetroTextBox();
                try
                {
                    switch (input)
                    {
                    case InputCalculo.PorcDescuento:
                    {
                        txtPorc      = txtPorcDescuento;
                        txtMto       = txtDescuento;
                        isPorcentaje = true;
                        estampa      = "descuento";
                    }
                    break;

                    case InputCalculo.PorcRecargo:
                    {
                        txtPorc      = txtPorcRecargo;
                        txtMto       = txtRecargo;
                        isPorcentaje = true;
                        estampa      = "recargo";
                    }
                    break;

                    case InputCalculo.MtoDescuento:
                    {
                        txtPorc = txtPorcDescuento;
                        txtMto  = txtDescuento;
                        estampa = "descuento";
                    }
                    break;

                    case InputCalculo.MtoRecargo:
                    {
                        txtPorc = txtPorcRecargo;
                        txtMto  = txtRecargo;
                        estampa = "recargo";
                    }
                    break;
                    }
                    #endregion

                    //CÁLCULO POR PORCENTAJE
                    if (isPorcentaje)
                    {
                        decimal porc = 0;
                        if (txtPorc.Text.Trim() == "")
                        {
                            txtMto.Clear();
                        }
                        else if (decimal.TryParse(txtPorc.Text.Trim(), out porc))
                        {
                            if (porc < 0)
                            {
                                MessageBox.Show($"Ingrese un valor positivo al porcentaje del {estampa}.", "Mensaje Eagle", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                txtMto.Clear();
                                txtPorc.SelectAll();
                            }
                            else
                            {
                                decimal mtoCalculado = 0;
                                mtoCalculado = mto * (porc / 100.0m);
                                if (input == InputCalculo.PorcDescuento && mtoCalculado >= mto)
                                {
                                    MessageBox.Show($"El descuento ({mtoCalculado}) no puede ser mayor o igual al monto del subtotal más el impuesto ({mto}).", "Mensaje Eagle", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    txtMto.Clear();
                                    txtPorc.SelectAll();
                                }
                                else
                                {
                                    txtMto.Text = mtoCalculado.RoundOut(numDec);
                                    CalcularMontos();
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show($"Ingrese un valor numérico en el porcentaje del {estampa}.", "Mensaje Eagle", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            txtMto.Clear();
                            txtPorc.SelectAll();
                        }
                    }
                    else//CÁLCULO POR MONTO
                    {
                        decimal mtoPropuesto = 0;
                        if (txtMto.Text.Trim() == "")
                        {
                            txtPorc.Clear();
                        }
                        else if ((decimal.TryParse(txtMto.Text.Trim(), out mtoPropuesto)))
                        {
                            if (mtoPropuesto < 0)
                            {
                                MessageBox.Show($"Ingrese un valor positivo al monto del {estampa}.", "Mensaje Eagle", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                txtPorc.Clear();
                                txtMto.SelectAll();
                            }
                            else
                            {
                                decimal porcCalculado = (mtoPropuesto / mto) * 100.0m;
                                if (input == InputCalculo.MtoDescuento && mtoPropuesto >= mto)
                                {
                                    MessageBox.Show($"El descuento ({mtoPropuesto}) no puede ser mayor o igual al monto del subtotal más el impuesto ({mto}).", "Mensaje Eagle", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    txtPorc.Clear();
                                    txtMto.Clear();
                                    txtMto.Focus();
                                }
                                else
                                {
                                    txtPorc.Text = porcCalculado.RoundOut(numDec);
                                    CalcularMontos();
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show($"Ingrese un valor numérico en el monto del {estampa}.", "Mensaje Eagle", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            txtPorc.Clear();
                            txtMto.SelectAll();
                        }
                    }
                }
                catch (Exception e)
                {
                    if (isPorcentaje)
                    {
                        txtMto.Clear();
                    }
                    else
                    {
                        txtPorc.Clear();
                    }
                    MessageBox.Show($"No se pudo calcular el {estampa}. Excepción: " + e.Message, "Mensaje Eagle", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }