Пример #1
0
 private void ClearTextBoxes()
 {
     foreach (Control ctr in this.Controls)
     {
         if (ctr is TextBox)
         {
             TextBox txt = ctr as TextBox;
             txt.Clear();
         }
     }
     NametextBox.Focus();
 }
Пример #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (NametextBox.Text == "")
     {
         NametextBox.Focus();
     }
     else if (PasswordtextBox.Text == "")
     {
         PasswordtextBox.Focus();
     }
     else
     {   // Sign in process
         int usertype;
         if (radioButton1.Checked == true)
         {
             //User 0
             usertype = 0;
         }
         else
         {
             //Admin 1
             usertype = 1;
         }
         try
         {
             conn.Open();
             // Insert to table
             SqlCommand com = new SqlCommand("INSERT INTO[user] (UserName,Password,UserType,Sign)  VALUES(@UserName,@Password,@UserType,@Sign)", conn);
             com.Parameters.AddWithValue("@UserName", NametextBox.Text);
             com.Parameters.AddWithValue("@Password", PasswordtextBox.Text);
             com.Parameters.AddWithValue("@UserType", usertype);
             com.Parameters.AddWithValue("@Sign", 0);
             com.ExecuteNonQuery();
             conn.Close();
             //After Insert Job :
             FUser_Load(sender, e); // Load again the form to refresh
             NametextBox.Text = PasswordtextBox.Text = "";
             NametextBox.Focus();
             MessageBox.Show("User has been registered", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception)
         {
             MessageBox.Show("This Username has been already exsit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        private void btnStarSave_Click(object sender, EventArgs e)
        {
            //see if any part of RA is wrong
            if (RAHrTxt_Valid == false || RAMinTxt_Valid == false || RASecTxt_Valid == false)
            {
                MessageBox.Show("Right Ascension not correct");
                RAHrTxt.Focus();
            }

            //see if any part of Dec is wrong
            else if (DecDTxt_Valid == false || DecMinTxt_Valid == false || DecSecTxt_Valid == false)
            {
                MessageBox.Show("Declination not correct");
                DecDTxt.Focus();
            }

            //see if name invalid
            else if (Name_Valid == false)
            {
                MessageBox.Show("Invalid name. cant be blank or start with a space");
                NametextBox.Focus();
            }

            else
            {
                //data is valid add entry to database
                connect.Open();
                SqlCommand cmd = connect.CreateCommand();
                cmd.CommandType = CommandType.Text;
                //create sql command
                cmd.CommandText = "insert into StarFavorites (Name, RAHr, RAMin, RASec, DDeg, DMin, DSec) VALUES (@Name,  @RAHr, @RAMin, @RASec, @DDeg, @DMin, @DSec)";
                cmd.Parameters.AddWithValue("@Name", starName);
                cmd.Parameters.AddWithValue("@RAHr", RAHr);
                cmd.Parameters.AddWithValue("@RAMin", RAMin);
                cmd.Parameters.AddWithValue("@RASec", RASec);
                cmd.Parameters.AddWithValue("@DDeg", DDeg);
                cmd.Parameters.AddWithValue("@DMin", DMin);
                cmd.Parameters.AddWithValue("@DSec", DSec);
                cmd.ExecuteNonQuery();
                connect.Close();
                LoadTable();

                starPanel.LoadComboBox();
            }
        }