Beispiel #1
0
        private void StartRead_Click(object sender, EventArgs e)
        {
            TxtData.Clear();
            if (FileList.SelectedNode != null && FileList.SelectedNode != FileList.Nodes[0])
            {
                TreeNode nowNode = FileList.SelectedNode;
                String   DirPath = Path.Combine(directory_.Text, nowNode.Text);

                if (nowNode.Text.Contains(".txt"))
                {
                    try
                    {
                        FileStream file   = new FileStream(DirPath, FileMode.Open, FileAccess.Read);
                        byte[]     byData = new byte[file.Length];
                        file.Seek(0, SeekOrigin.Begin);
                        int readbyte = file.Read(byData, 0, byData.Length);
                        TxtData.AppendText(new string(Encoding.ASCII.GetChars(byData, 0, readbyte)));

                        file.Close();
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Beispiel #2
0
        //button register
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(rezult);

            if (TxtFirstname.Text == "")
            {
                MessageBox.Show("Please enter confirm password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtFirstname.Focus();
                return;
            }
            if (TxtFamilyname.Text == "")
            {
                MessageBox.Show("Please enter username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtFamilyname.Focus();
                return;
            }

            if (TxtData.Text == "")
            {
                MessageBox.Show("Please enter username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtData.Focus();
                return;
            }
            if (TxtNumber.Text == "")
            {
                MessageBox.Show("Please enter username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtNumber.Focus();
                return;
            }
            try
            {
                SqlConnection myConnection = default(SqlConnection);
                myConnection = new SqlConnection(@"Data Source=DESKTOP-NP1RDM2\BAZALUIMARIAN;Initial Catalog=task;Persist Security Info=True;User ID=sa; Password = 0299");
                String query = "INSERT INTO dbo.Clientapp (family_name,first_name,clientappdate,number) VALUES (@family_name,@first_name,@clientappdate,@number)";

                using (SqlCommand command = new SqlCommand(query, con))
                {
                    command.Parameters.AddWithValue("@family_name", TxtFamilyname.Text);
                    command.Parameters.AddWithValue("@first_name", TxtFirstname.Text);
                    command.Parameters.AddWithValue("@clientappdate", TxtData.Text);
                    command.Parameters.AddWithValue("@number", TxtNumber.Text);

                    MessageBox.Show("Register successfully !We will call you back today !", "Register Successfully", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    con.Open();
                    int result = command.ExecuteNonQuery();
                    Hide();

                    // Check Error
                    if (result < 0)
                    {
                        MessageBox.Show("Register Denied", "Register Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        TxtNumber.Clear();
                        TxtFirstname.Clear();
                        TxtFamilyname.Clear();
                        TxtData.Clear();
                        TxtFamilyname.Focus();
                        Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 // EXAMPLE #2 *****************************************************
 private void BtnAddToList_Click(object sender, EventArgs e)
 {
     LBoxData.Items.Add(TxtData.Text);
     TxtData.Clear();
     TxtData.Focus();
 }