Ejemplo n.º 1
0
        private void ThemSach_Load(object sender, EventArgs e)
        {
            CTL.NgonNgu dataNgonNgu = new CTL.NgonNgu();
            ComboboxItem item;

            DataTable dtNgonNgu = dataNgonNgu.loadNgonNgu();
            DataTable dtTuaSach = dataSach.loadTuaSach();
            DataTable dtDauSach = dataSach.loadDauSachTuaSach();
            DataTable dtCuonSach = dataSach.loadCuonSach();

            int matuasach = timSTT(dtTuaSach, "Mã tựa sách");
            int madausach = timSTT(dtDauSach, "Mã đầu sách");
            int macuonsach = timSTT(dtCuonSach, "Mã cuốn sách");

            #region Tựa sách
            txtmatuasach.Text = matuasach.ToString();
            #endregion

            #region Đầu sách
            txtmadausach.Text = madausach.ToString();

            for (int i = 0; i < dtTuaSach.Rows.Count; i++)
            {
                item = new ComboboxItem();
                item.Text = dtTuaSach.Rows[i]["Mã tựa sách"].ToString() + " - " + dtTuaSach.Rows[i]["Tên tựa sách"].ToString();
                item.Value = dtTuaSach.Rows[i]["Mã tựa sách"].ToString();
                cbxtuasach.Items.Add(item);
            }

            for (int i = 0; i < dtNgonNgu.Rows.Count; i++)
            {
                item = new ComboboxItem();
                item.Text = dtNgonNgu.Rows[i]["Ngôn ngữ"].ToString();
                item.Value = dtNgonNgu.Rows[i]["Ngôn ngữ"].ToString();
                cbxngonngu.Items.Add(item);
            }

            if (cbxtuasach.Items.Count > 0)
                cbxtuasach.SelectedIndex = 0;

            if (cbxngonngu.Items.Count > 0)
                cbxngonngu.SelectedIndex = 0;

            #endregion

            #region Cuốn sách

            for (int i = 0; i < dtDauSach.Rows.Count; i++)
            {
                item = new ComboboxItem();
                item.Text = dtDauSach.Rows[i]["Mã đầu sách"].ToString() + " - " + dtDauSach.Rows[i]["Tên tựa sách"].ToString() + " - " + dtDauSach.Rows[i]["Ngôn ngữ"].ToString();
                item.Value = dtDauSach.Rows[i]["Mã đầu sách"].ToString();
                cbxmadausach.Items.Add(item);
            }

            if (cbxmadausach.Items.Count > 0)
                cbxmadausach.SelectedIndex = 0;
            txtmacuonsach.Text = macuonsach.ToString();
            #endregion
        }
Ejemplo n.º 2
0
        private void SuaSach_Load(object sender, EventArgs e)
        {
            CTL.NgonNgu dataNgonNgu = new CTL.NgonNgu();
            ComboboxItem item;

            DataTable dtNgonNgu = dataNgonNgu.loadNgonNgu();
            DataTable dtTuaSach = dataSach.loadTuaSach();
            DataTable dtDauSach = dataSach.loadDauSachTuaSach();
            DataTable dtCuonSach = dataSach.loadCuonSach();

            TUASACH ts;
            DAUSACH ds;
            CUONSACH cs;

            tcsuasach.SelectedTabIndex = selectedTab;
            if (selectedTab == 0)
            {
                tithemtuasach.Visible = true;
                tithemdausach.Visible = false;
                tithemcuonsach.Visible = false;

                ts = dataSach.timTuaSach(mts);
                txtmatuasach.Text = ts.matuasach;
                txttentuasach.Text = ts.tentuasach;
                txttacgia.Text = ts.tacgia;
                txtgioithieu.Text = ts.gioithieu;
            }
            else if (selectedTab == 1)
            {
                tithemtuasach.Visible = false;
                tithemdausach.Visible = true;
                tithemcuonsach.Visible = false;

                ds = dataSach.timDauSach(mds);

                txtmadausach.Text = ds.madausach;
                if (ds.tinhtrang == true)
                    cbdausach.Checked = true;

                for (int i = 0; i < dtTuaSach.Rows.Count; i++)
                {
                    item = new ComboboxItem();
                    item.Text = dtTuaSach.Rows[i]["Mã tựa sách"].ToString() + " - " + dtTuaSach.Rows[i]["Tên tựa sách"].ToString();
                    item.Value = dtTuaSach.Rows[i]["Mã tựa sách"].ToString();
                    cbxmatuasach.Items.Add(item);
                }

                for (int i = 0; i < dtNgonNgu.Rows.Count; i++)
                {
                    item = new ComboboxItem();
                    item.Text = dtNgonNgu.Rows[i]["Ngôn ngữ"].ToString();
                    item.Value = dtNgonNgu.Rows[i]["Ngôn ngữ"].ToString();
                    cbxngonngu.Items.Add(item);
                }

                for (int i = 0; i < cbxmatuasach.Items.Count; i++)
                {
                    if ((cbxmatuasach.Items[i] as ComboboxItem).Value.ToString() == ds.matuasach)
                    {
                        cbxmatuasach.SelectedIndex = i;
                        break;
                    }
                }

                for (int i = 0; i < cbxngonngu.Items.Count; i++)
                {
                    if ((cbxngonngu.Items[i] as ComboboxItem).Value.ToString() == ds.ngonngu)
                    {
                        cbxngonngu.SelectedIndex = i;
                        break;
                    }
                }

            }
            else if (selectedTab == 2)
            {
                tithemtuasach.Visible = false;
                tithemdausach.Visible = false;
                tithemcuonsach.Visible = true;

                cs = dataSach.timCuonSach(mcs);

                txtmacuonsach.Text = cs.macuonsach;
                if (cs.tinhtrang == true)
                    cbcuonsach.Checked = true;

                for (int i = 0; i < dtDauSach.Rows.Count; i++)
                {
                    item = new ComboboxItem();
                    item.Text = dtDauSach.Rows[i]["Mã đầu sách"].ToString() + " - " + dtDauSach.Rows[i]["Tên tựa sách"].ToString() + " - " + dtDauSach.Rows[i]["Ngôn ngữ"].ToString();
                    item.Value = dtDauSach.Rows[i]["Mã đầu sách"].ToString();
                    cbxmadausach.Items.Add(item);
                }

                for (int i = 0; i < cbxmadausach.Items.Count; i++)
                {
                    if ((cbxmadausach.Items[i] as ComboboxItem).Value.ToString() == cs.madausach)
                    {
                        cbxmadausach.SelectedIndex = i;
                        break;
                    }
                }

            }
        }