Ejemplo n.º 1
0
        private void btnChonBai_Click(object sender, EventArgs e)
        {
            frmBai f = new frmBai();

            f.ShowDialog();
            id_chon = f.id_chon;
            f.Dispose();
            BaiHoc bh = MyFunction.ThongtinBaihoc(id_chon);

            if (bh == null)
            {
                return;
            }

            baihocTV = bh;

            HienThiBaiHoc();
        }
Ejemplo n.º 2
0
        private void lstBaihoc_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstBaihoc.SelectedIndices.Count <= 0)
            {
                return;
            }
            int intselectedindex = lstBaihoc.SelectedIndices[0];

            if (intselectedindex >= 0)
            {
                String id = lstBaihoc.Items[intselectedindex].SubItems[0].Text;
                txtID.Text = id;

                BaiHoc bh = MyFunction.ThongtinBaihoc(int.Parse(id));
                txtTieude.Text  = bh.tieude.ToString();
                txtNoidung.Text = MyFunction.NoidungToText(bh.baihoc);
                txtThutu.Text   = bh.thutu.ToString();
            }
        }
Ejemplo n.º 3
0
        public frmHoc()
        {
            InitializeComponent();
            init_color_list();


            MyFunction.FromXml();

            //set_font();

            //frmBai f = new frmBai();
            //f.ShowDialog();
            //id_chon = f.id_chon;
            //f.Dispose();
            //baihocTV = MyFunction.ThongtinBaihoc(id_chon);

            id_chon = -1;
            //btnBaiKe_Click(null,null);
        }
Ejemplo n.º 4
0
        BaiHoc lay_baihoc()
        {
            if (bai_chon == -1)
            {
                MyFunction.FromXml_NoiCau();
                danhsachNoiCau = MyFunction.danhsachBaihoc;
            }


            if (danhsachNoiCau.Count == 0)
            {
                return(null);
            }

            //Random randomBaihoc = new Random();
            //int idx = randomBaihoc.Next(0, danhsachNoiCau.Count);


            BaiHoc bai = null;

            if (bai_chon == -1)
            {
                bai = danhsachNoiCau.OrderBy(x => x.thutu).ToList().FirstOrDefault();
            }
            else
            {
                bai = MyFunction.danhsachBaihoc.OrderBy(x => x.thutu).ToList().FirstOrDefault(x => x.thutu > bai_chon);
            }


            if (bai == null)
            {
                bai_chon = -1;
                MessageBox.Show("Hết rồi !!!");
                return(null);
            }
            baihocTV = bai;
            bai_chon = bai.thutu;


            return(bai);
        }
Ejemplo n.º 5
0
        void ve_trai(List <Cau> cau)
        {
            int x = pnMain.Width / 2 - rong - 100;
            int y = (pnMain.Height - cau.Count * cao - 20) / 2 - 50;

            Random rdDong = new Random();

            while (cau.Count > 0)
            {
                int idx = rdDong.Next(0, cau.Count);
                idx = rdDong.Next(0, cau.Count);

                Label lb = new Label();
                lb.Text = MyFunction.ConvertUNI2TCV(cau[idx].noidung);
                lb.Tag  = cau[idx].id;
                lb.Name = "myLblTrai" + cau[idx].id;

                lb.Font        = new Font(".VnAvant", 20, FontStyle.Bold);
                lb.BackColor   = Color.Aquamarine;
                lb.BorderStyle = BorderStyle.FixedSingle;
                lb.AutoSize    = false;
                lb.Width       = rong;
                lb.Height      = cao;
                lb.TextAlign   = ContentAlignment.MiddleCenter;
                lb.Cursor      = Cursors.Hand;

                Point p = new Point(x, y);

                lb.Location = p;

                lb.MouseDown += button_MouseDown;
                lb.MouseUp   += button_MouseUp;


                pnMain.Controls.Add(lb);

                y = y + cao + 20;

                cau.RemoveAt(idx);
            }
        }
Ejemplo n.º 6
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (txtID.Text != "")
            {
                BaiHoc bh = MyFunction.danhsachBaihoc.FirstOrDefault(x => x.Id == int.Parse(txtID.Text));

                if (bh != null)
                {
                    try
                    {
                        MyFunction.danhsachBaihoc.Remove(bh);
                        MyFunction.ToXml_NoiCau();

                        load_listBaihoc();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Khong Xoa Duoc");
                        return;
                    }
                }
            }
            init_input();
        }
Ejemplo n.º 7
0
        private void init_Tu()
        {
            int_all();
            Random randomX = new Random();
            Random randomY = new Random();

            int Y = this.Height / 2;
            int X = 0;


            listCtr_Tu = new List <Label>();
            List <string> listTu = new List <string>();

            lblBai.Text = MyFunction.ConvertUNI2TCV("Bài " + baihocTV.tieude);
            txtBai.Text = "";
            foreach (Noidung nd in baihocTV.baihoc)
            {
                txtBai.Text += MyFunction.ConvertUNI2TCV(nd.noidung) + Environment.NewLine;
                foreach (string str in nd.noidung.Split(' '))
                {
                    listTu.Add(str);
                }
            }

            int sotu         = listTu.Count;
            int sotu_motdong = (this.panel1.Width - le_trai) / (rong + 5);

            int sodong = (int)Math.Ceiling((double)sotu / (double)sotu_motdong);

            int vY = panel1.Height - sodong * (cao + 5);

            List <Point> vitri_Tu = new List <Point>();

            for (int i = 0; i < sodong; i++)
            {
                vitri_Tu.Add(new Point(le_trai, vY));

                vY = vY + cao + 5;
            }

            int idxCnt = 0;

            while (listTu.Count > 0)
            {
                Random randomTu    = new Random();
                int    randomIndex = randomTu.Next(0, listTu.Count);
                Random randomDong  = new Random();
                int    dong        = randomDong.Next(0, vitri_Tu.Count);

                Point p = vitri_Tu[dong];


                Label l = new Label();
                l.Name = "myLblCtr_Tu" + idxCnt;
                l.Text = MyFunction.ConvertUNI2TCV(listTu[randomIndex]);

                l.Font = new Font(".VnAvant", 26, FontStyle.Bold);
                //l.Font = new Font(MyFunction.myfonts.Families[0],20, FontStyle.Bold);
                //l.UseCompatibleTextRendering = true;
                l.BackColor   = init_color();
                l.BorderStyle = BorderStyle.FixedSingle;
                //l.ForeColor = Color.Yellow;
                l.AutoSize  = false;
                l.Width     = rong;
                l.Height    = cao;
                l.TextAlign = ContentAlignment.MiddleCenter;
                l.Cursor    = Cursors.Hand;
                l.BringToFront();


                l.Location = p;


                l.MouseMove += LOnMouseMove;
                l.MouseDown += LOnMouseDown;
                l.MouseUp   += LOnMouseUp;

                this.panel1.Controls.Add(l);
                listCtr_Tu.Add(l);


                idxCnt++;

                listTu.RemoveAt(randomIndex);

                p.X = p.X + (rong + 5);


                if (p.X > panel1.Width - (rong + 5))
                {
                    vitri_Tu.RemoveAt(dong);
                }
                else
                {
                    vitri_Tu[dong] = p;
                }
            }
        }
Ejemplo n.º 8
0
 BaiHoc Load_Baihoc(int bai)
 {
     MyFunction.FromXml_NoiCau();
     return(MyFunction.danhsachBaihoc.FirstOrDefault(x => x.Id == bai));
 }
Ejemplo n.º 9
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            ////foreach (BaiHoc bh in MyFunction.danhsachBaihoc)
            ////{
            ////    //bh.Id = int.Parse(bh.tieude.Replace("Bài ", "").Replace("Bai", "").Replace(" ", "").Trim());
            ////    bh.tieude = bh.tieude.Replace("Bài ", "").Replace("Bai", "").Replace(" ", "").Trim();

            ////}

            ////MyFunction.ToXml_NoiCau();

            ////return;

            if (txtTieude.Text.Trim() == "" || txtNoidung.Text.Trim() == "")
            {
                MessageBox.Show("Chưa nhập đủ thông tin");
                return;
            }

            List <string> txt = txtNoidung.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList();

            int            dong   = 0;
            List <Noidung> baihoc = new List <Noidung>();


            foreach (string str in txt)
            {
                if (str.Trim().Length > 0)
                {
                    Noidung nd = new Noidung();
                    dong++;
                    nd.dong    = dong;
                    nd.noidung = str.Trim();

                    baihoc.Add(nd);
                }
            }


            if (txtID.Text != "")
            {
                int idx = MyFunction.danhsachBaihoc.FindIndex(x => x.Id == int.Parse(txtID.Text));
                MyFunction.danhsachBaihoc[idx].tieude = int.Parse(txtTieude.Text.Trim());
                MyFunction.danhsachBaihoc[idx].baihoc = baihoc;
                MyFunction.danhsachBaihoc[idx].thutu  = int.Parse(txtThutu.Text);
            }
            else
            {
                BaiHoc bh = new BaiHoc();
                bh.Id     = MyFunction.Get_MaxId() + 1;
                bh.tieude = int.Parse(txtTieude.Text.Trim());
                bh.baihoc = baihoc;
                bh.thutu  = int.Parse(txtThutu.Text);
                MyFunction.danhsachBaihoc.Add(bh);
            }

            MyFunction.ToXml_NoiCau();

            load_listBaihoc();
            init_input();
        }
Ejemplo n.º 10
0
        public void Load_Bai()
        {
            if (lstBai == null || lstBai.Count == 0)
            {
                return;
            }

            if (bai == -1)
            {
                bai = lstBai.OrderBy(s => s).FirstOrDefault();
            }
            else
            {
                if (phan == 2) //Den bai ke tiep
                {
                    int bai_ke;
                    bai_ke = lstBai.OrderBy(s => s).FirstOrDefault(s => s > bai);

                    if (bai_ke == 0)
                    {
                        MessageBox.Show("Hết rồi !!!");
                        return;
                    }
                    bai  = bai_ke;
                    phan = -1;
                }
            }

            if (phan < 1)
            {
                //kiem tra Bai co phan 1 khong
                var p = lst1.FirstOrDefault(s => s == bai);
                if (p > 0)
                {
                    phan = 1;
                }
                else
                {
                    phan = 2;
                }
                init_uControl(bai, phan);
            }
            else if (phan == 1)
            {
                //kiem tra co phan 2 khong, neu co phan 2 thi hien thi phan 2. neu khong co thi hien thi bai ke tiep

                //kiem tra Bai co phan 2 khong
                var p = lst2.FirstOrDefault(s => s == bai);
                if (p > 0)
                {
                    phan = 2;
                    init_uControl(bai, phan);
                }
                else
                {
                    phan = 2;
                    Load_Bai();
                    return;
                }
            }

            lblBai.Text = MyFunction.ConvertUNI2TCV("Bài " + bai);
        }
Ejemplo n.º 11
0
        public void HienThiBaiHoc(List <int> lstBai)
        {
            int rong  = 150;
            int cao   = 45;
            int space = 5;
            int le    = 50;
            int X     = le;
            int Y     = le;

            int sobai         = lstBai.Count;
            int sobai_motdong = (this.pnMain.Width - le) / (rong + space);
            int sodong        = (int)Math.Ceiling((double)sobai / (double)sobai_motdong);

            int Y_batdau = (this.pnMain.Height - sodong * (cao + space)) / 2;

            if (Y_batdau < 0)
            {
                Y_batdau = 5;
            }
            Y = Y_batdau;

            for (int i = 0; i < lstBai.Count; i++)
            {
                Label l = new Label();
                l.Name = "myLblCtr_bai" + i;
                l.Text = MyFunction.ConvertUNI2TCV("Bài " + lstBai[i]);
                l.Tag  = lstBai[i];

                l.Font = new Font(".VnAvant", 16, FontStyle.Regular);

                l.BackColor   = Color.Bisque;
                l.BorderStyle = BorderStyle.FixedSingle;
                //l.ForeColor = Color.Blue;
                l.AutoSize  = false;
                l.Width     = rong;
                l.Height    = cao;
                l.TextAlign = ContentAlignment.MiddleCenter;
                l.Cursor    = Cursors.Hand;
                l.BringToFront();


                //l.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;

                Point p = new Point(X, Y);
                l.Location = p;

                l.Click += LOnClick;
                //l.MouseHover += LOnMouseHover;
                l.MouseLeave += LOnMouseLeave;
                l.MouseMove  += LOnMouseMove;

                this.pnMain.Controls.Add(l);

                X = X + rong + space;

                if (X > this.pnMain.Width - (rong + space))
                {
                    X = le;
                    Y = Y + cao + space;
                }
            }
        }