コード例 #1
0
 private void birthday_Leave(object sender, EventArgs e)
 {
     if (GF.validateDateTime(birthday))
     {
         if (birthday.MaskFull)
         {
             current_age.Text = GF.calculateAge(birthday.Text);
         }
     }
 }
コード例 #2
0
        bool validateForm()
        {
            bool    halt        = false;
            Control haltControl = null;

            var tabIndex = new List <int>();

            foreach (Control ctl in this.Controls)
            {
                string type = ctl.GetType().ToString().ToUpper();
                if (!type.Contains("BUTTON") && !type.Contains("LABEL") && !type.Contains("GROUPBOX") && !type.Contains("PICTUREBOX") && !type.Contains("PANEL") && !string.IsNullOrEmpty((ctl.Tag ?? "").ToString()))
                {
                    tabIndex.Add(ctl.TabIndex);
                    Console.WriteLine(ctl.TabIndex.ToString());
                }
            }

            tabIndex.Sort();

            foreach (int index in tabIndex)
            {
                Control ctl  = this.Controls.Cast <Control>().Where(p => p.TabIndex == index).First();
                string  type = ctl.GetType().ToString().ToUpper();

                if (type.IndexOf("TEXTBOX") > -1)
                {
                    if (type.IndexOf("MASKED") > -1) // MaskedTextBox
                    {
                        if (((MaskedTextBox)ctl).Text.Trim().Length < 10)
                        {
                            halt        = true;
                            haltControl = ctl;
                            break;
                        }
                    }
                    else // Simple Textbox
                    {
                        if (!((TextBox)ctl).ReadOnly)
                        {
                            if (string.IsNullOrEmpty(((TextBox)ctl).Text.Trim()))
                            {
                                halt        = true;
                                haltControl = ctl;
                                break;
                            }
                        }
                    }
                }
                if (type.IndexOf("COMBOBOX") > -1)
                {
                    if (string.IsNullOrEmpty(((ComboBox)ctl).Text.Trim()))
                    {
                        halt        = true;
                        haltControl = ctl;
                        break;
                    }
                }
            }

            if (halt)
            {
                GF.Error("กรุณากรอก '" + haltControl.Tag.ToString() + "'");
                haltControl.Select();
                return(false);
            }

            if (!GF.validateDateTime(birthday))
            {
                return(false);
            }

            return(true);
        }