News Ticker

Menu

Tuần 1 - Bài 3


Source fBai3.cs

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

namespace Bai3
{
    public partial class fBai3 : Form
    {
        public fBai3()
        {
            InitializeComponent();

            if (Test() == false)
            {
                btnCout.Enabled = false;
                btnClear.Enabled = false;
            }

        }

      private bool Test()
        {
            if ((txbInputA.Text.Length == 0 || txbInputB.Text.Length == 0) || ((!Char.IsDigit(txbInputA.Text[txbInputA.Text.Length - 1])) || (!Char.IsDigit(txbInputB.Text[txbInputB.Text.Length - 1]))))
                return false;
            return true;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult r;
            r = MessageBox.Show("Thí chủ muốn thoát chứ?", 
                "THÔNG BÁO NÈ!", MessageBoxButtons.YesNo, 
                MessageBoxIcon.Question, 
                MessageBoxDefaultButton.Button1);
            if (r == DialogResult.No)
                e.Cancel = true;
        }

        private void txbInputA_TextChanged(object sender, EventArgs e)
        {
            if (Test() == false)
            {
                btnCout.Enabled = false;
                btnClear.Enabled = false;
            }
            else if (Test() == true)
            {
                btnCout.Enabled = true;
                btnClear.Enabled = true;
            }

            //////////////////////////
            ///
            Control ctr = (Control)sender;
            if(ctr.Text.Length >0 && !Char.IsDigit(ctr.Text[ctr.Text.Length - 1]))
            {
                this.erroNotify.SetError(ctr, "This is not value number!");
                txbResult.Text = "Thí chủ nhấn nhầm rồi kìa!";
            }
            else
            {
                this.erroNotify.Clear();
                txbResult.Text = "";
            }

        }

        private void txbInputB_TextChanged(object sender, EventArgs e)
        {
            if (Test() == false)
            {
                btnCout.Enabled = false;
                btnClear.Enabled = false;
            }
            else if (Test() == true)
            {
                btnCout.Enabled = true;
                btnClear.Enabled = true;
            }

            ////////////////

            Control ctr = (Control)sender;
            if (ctr.Text.Length > 0 && !Char.IsDigit(ctr.Text[ctr.Text.Length - 1]))
            {
                this.erroNotify.SetError(ctr, "This is not value number!");
                txbResult.Text = "Thí chủ nhấn nhầm rồi kìa!";
            }
            else
            {
                this.erroNotify.Clear();
                txbResult.Text = "";
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
                ClearData();
        }

        private void ClearData()
        {
            txbInputA.Clear();
            txbInputB.Clear();
            txbResult.Clear();
            txbInputA.Focus();
        }
        private void btnCout_Click(object sender, EventArgs e)
        {
          
                int a, b;
                double c;

                if (txbInputA.Text.Length == 0 && txbInputB.Text.Length == 0)
                {
                    txbResult.Text = "Thí chủ không có gì để tính toán cả!";
                }
                else if (txbInputA.Text.Length == 0 || txbInputB.Text.Length == 0)
                {
                    txbResult.Text = "Thí chủ nhập thiếu rồi kìa!";
                }
                else
                {
                        a = Convert.ToInt32(txbInputA.Text);
                        b = Convert.ToInt32(txbInputB.Text);

                        if (a == 0 && b == 0)
                            txbResult.Text = "Phương trình có cả đống nghiệm!";

                        else if(a == 0 && b!= 0)
                            txbResult.Text = "Phương trình vô nghiệm rồi bạn!";

                        else if(a != 0)
                        {
                            c = (double)-b / (double)a;
                            c = Math.Round(c, 3);
                            txbResult.Text = "X = " + c.ToString();
                        }

                }


        }

 
    }
}

Link: Project

Share This:

Post Tags:

Welcome To Task Marks

I'm Task Marks. Tôi là chủ trang web này, trang này tôi dùng để chia sẽ tài liệu và những thứ linh tinh khác. Cảm ơn mọi người đã ghé thăm trang web của chúng tôi.Nếu có thắt mắt xin vui lòng liên hệ
Mail: devnguhoc@gmail.com

No Comment to " Tuần 1 - Bài 3 "

  • To add an Emoticons Show Icons
  • To add code Use [pre]code here[/pre]
  • To add an Image Use [img]IMAGE-URL-HERE[/img]
  • To add Youtube video just paste a video link like http://www.youtube.com/watch?v=0x_gnfpL3RM