コード例 #1
0
ファイル: frmNoiCau_Nhap.cs プロジェクト: tomyanh/TiengViet
        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();
            }
        }
コード例 #2
0
ファイル: frmNoiCau.cs プロジェクト: tomyanh/TiengViet
        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);
        }
コード例 #3
0
        private void btnBaiKe_Click(object sender, EventArgs e)
        {
            BaiHoc baike = null;

            if (baihocTV == null)
            {
                baike = MyFunction.danhsachBaihoc.OrderBy(x => x.thutu).ToList().FirstOrDefault();
            }
            else
            {
                baike = MyFunction.danhsachBaihoc.OrderBy(x => x.thutu).ToList().FirstOrDefault(x => x.thutu > baihocTV.thutu);
            }

            if (baike == null)
            {
                MessageBox.Show("Đây là bài cuối !!!");
                return;
            }
            baihocTV = baike;
            HienThiBaiHoc();
        }
コード例 #4
0
        private void btnBaiTruoc_Click(object sender, EventArgs e)
        {
            BaiHoc bai = null;

            if (baihocTV == null)
            {
                bai = MyFunction.danhsachBaihoc.OrderBy(x => x.thutu).ToList().LastOrDefault();
            }
            else
            {
                bai = MyFunction.danhsachBaihoc.OrderBy(x => x.thutu).ToList().LastOrDefault(x => x.thutu < baihocTV.thutu);
            }


            if (bai == null)
            {
                MessageBox.Show("Đây là bài đầu tiên !!!");
                return;
            }
            baihocTV = bai;
            HienThiBaiHoc();
        }
コード例 #5
0
ファイル: frmNoiCau_Nhap.cs プロジェクト: tomyanh/TiengViet
        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();
        }
コード例 #6
0
ファイル: frmNoiCau_Nhap.cs プロジェクト: tomyanh/TiengViet
        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();
        }