コード例 #1
0
        public bool xoa(LoaiDocGiaDTO ldg)
        {
            string query = string.Empty;

            query += "DELETE FROM [dbo].[tblLoaiDocGia] WHERE [maLoaiDocGia] = @maLoaiDocGia";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@maLoaiDocGia", ldg.MaLoaiDocGia);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #2
0
        public bool them(LoaiDocGiaDTO ldg)
        {
            bool re = ldgDAL.them(ldg);

            cmd_String = ldgDAL.cmd_string;
            return(re);
        }
コード例 #3
0
        private void button_Sua_Click(object sender, EventArgs e)
        {
            //1. Map data from GUI
            LoaiDocGiaDTO ldg = new LoaiDocGiaDTO();

            ldg.MaLoaiDocGia  = this.textBox_Ma.Text;
            ldg.TenLoaiDocGia = this.textBox_TenLoaiDocGia.Text;


            DialogResult dlr = MessageBox.Show("Bạn có muốn sửa thẻ với mã " + ldg.MaLoaiDocGia + " không?", "Xác nhận!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (dlr == DialogResult.Yes)
            {
                //2. Kiểm tra data hợp lệ or not
                if (ldg.TenLoaiDocGia.Length <= 0)
                {
                    MessageBox.Show("Sửa thất bại, vui lòng kiểm tra lại thông tin.");
                    return;
                }


                //3. Thêm vào DB
                bool kq = ldgBus.sua(ldg);
                if (kq == false)
                {
                    MessageBox.Show("Sửa Độc giả thất bại. Vui lòng kiểm tra lại dũ liệu");
                }
                else
                {
                    MessageBox.Show("Sửa Độc giả thành công");
                    this.loadData_Vao_GridView();
                }
            }
        }
コード例 #4
0
        private void button_Xoa_Click(object sender, EventArgs e)
        {
            //1. Map data from GUI
            LoaiDocGiaDTO ldg = new LoaiDocGiaDTO();

            ldg.MaLoaiDocGia = this.textBox_Ma.Text;

            DialogResult dlr = MessageBox.Show("Bạn có muốn xoa loai voi ma  " + ldg.MaLoaiDocGia + " khổng?", "Xác nhận!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (dlr == DialogResult.Yes)
            {
                //2. Kiểm tra data hợp lệ or not

                //3. Thêm vào DB
                bool kq = ldgBus.xoa(ldg);
                if (kq == false)
                {
                    MessageBox.Show("Xóa loai độc giả thất bại. Vui lòng kiểm tra lại dũ liệu");
                }
                else
                {
                    MessageBox.Show("Xóa loai độc giả thành công");
                    loadData_Vao_GridView();
                    this.dvg_QuanLyLoaiDocGia.FirstDisplayedScrollingRowIndex = 0;
                }
            }
            else
            {
                MessageBox.Show("Không xóa.");
            }
        }
コード例 #5
0
        TheDocGiaDTO GetData()
        {
            string        name       = txtName.Text;
            string        address    = txtAddress.Text;
            string        email      = txtEmail.Text;
            DateTime      dtBirth    = dtpBirth.Value;
            LoaiDocGiaDTO loaidocgia = (LoaiDocGiaDTO)cmbType.SelectedItem;

            TheDocGiaDTO result = new TheDocGiaDTO();

            if (dgv.CurrentRow != null)
            {
                result.MaThe      = ((TheDocGiaDTO)dgv.CurrentRow.DataBoundItem).MaThe;
                result.NgayLapThe = (DateTime)dgv.CurrentRow.Cells["NgayLapThe"].Value;
                result.NgayHetHan = (DateTime)dgv.CurrentRow.Cells["NgayHetHan"].Value;
            }

            result.HoTen      = name;
            result.DiaChi     = address;
            result.Email      = email;
            result.NgaySinh   = dtBirth;
            result.LoaiDocGia = loaidocgia;

            return(result);
        }
コード例 #6
0
        public bool them(LoaiDocGiaDTO ldg)
        {
            string query = string.Empty;

            query += "INSERT INTO [dbo].[tblLoaiDocGia]([maLoaiDocGia],[tenLoaiDocGia])";
            query += " VALUES(@MaLoaiDocGia,@TenLoaiDocGia)";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@MaLoaiDocGia", ldg.MaLoaiDocGia);
                    cmd.Parameters.AddWithValue("@TenLoaiDocGia", ldg.TenLoaiDocGia);


                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();

                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #7
0
        public bool sua(LoaiDocGiaDTO ldg)
        {
            string query = string.Empty;

            query += "UPDATE [dbo].[tblLoaiDocGia]  SET ";
            query += "[tenLoaiDocGia]] = @[tenLoaiDocGia],";

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@tenLoaiDocGia", ldg.TenLoaiDocGia);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #8
0
//         public IList getAll()
//         {
//             string sql = "select * from LoaiDocGia";
//             DataTable dt = executeQuery(sql);
//
//             List<LoaiDocGiaDTO> result = new List<LoaiDocGiaDTO>(dt.Rows.Count);
//             foreach (DataRow dr in dt.Rows)
//             {
//                 result.Add(GetDataFromDataRow(dr));
//             }
//             return result;
//         }
        protected override object GetDataFromDataRow(DataRow dr)
        {
            LoaiDocGiaDTO dto = new LoaiDocGiaDTO();

            dto.MaLoaiDocGia  = (int)dr["MaLoaiDocGia"];
            dto.TenLoaiDocGia = (string)dr["TenLoaiDocGia"];
            return(dto);
        }
コード例 #9
0
        public List <LoaiDocGiaDTO> select()
        {
            string query = string.Empty;

            query += "select * from[dbo].[tblLoaiDocGia]";


            List <LoaiDocGiaDTO> lsLoaiDocGia = new List <LoaiDocGiaDTO>();

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                Console.WriteLine("Load loai doc gia");
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    try
                    {
                        con.Open();
                        SqlDataReader reader = null;

                        reader = cmd.ExecuteReader();

                        if (reader.HasRows == true)
                        {
                            while (reader.Read())
                            {
                                LoaiDocGiaDTO ldg = new LoaiDocGiaDTO();

                                ldg.MaLoaiDocGia = reader["maLoaiDocGia"].ToString();
                                Console.WriteLine("Ma loai doc gia: " + ldg.MaLoaiDocGia);
                                ldg.TenLoaiDocGia = reader["tenLoaiDocGia"].ToString();
                                Console.WriteLine("Ten loai doc gia: " + ldg.TenLoaiDocGia);



                                lsLoaiDocGia.Add(ldg);
                            }
                        }

                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(null);
                    }
                }
            }
            return(lsLoaiDocGia);
        }
コード例 #10
0
        private void button_Them_Click(object sender, EventArgs e)
        {
            //1. Map data from GUI
            LoaiDocGiaDTO        ldg     = new LoaiDocGiaDTO();
            List <LoaiDocGiaDTO> listldg = new List <LoaiDocGiaDTO>();

            listldg = ldgBus.select("");
            String Ma = this.TaoMa(listldg[listldg.Count - 1].MaLoaiDocGia);



            DialogResult dlr = MessageBox.Show("Bạn có muốn thêm thẻ với mã " + Ma + " không?", "Xác nhận!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (dlr == DialogResult.Yes)
            {
                ldg.MaLoaiDocGia = Ma;

                ldg.TenLoaiDocGia = this.textBox_TenLoaiDocGia.Text;


                //2. Kiểm tra data hợp lệ or not
                if (ldg.TenLoaiDocGia.Length <= 0)
                {
                    MessageBox.Show("Thêm thất bại, vui lòng kiểm tra lại thông tin.");
                    return;
                }


                //3. Thêm vào DB
                bool kq = ldgBus.them(ldg);
                if (kq == false)
                {
                    MessageBox.Show("Thêm Độc giả thất bại. Vui lòng kiểm tra lại dũ liệu");
                }
                else
                {
                    MessageBox.Show("Thêm Độc giả thành công");
                    this.loadData_Vao_GridView();
                }
            }
            else
            {
                MessageBox.Show("Không thêm.");
            }
        }
コード例 #11
0
        protected override object GetDataFromDataRow(System.Data.DataRow dr)
        {
            TheDocGiaDTO dto = new TheDocGiaDTO();

            dto.HoTen      = (string)dr["HoTen"];
            dto.MaThe      = (int)dr["MaThe"];
            dto.DiaChi     = (string)dr["DiaChi"];
            dto.Email      = (string)dr["Email"];
            dto.NgaySinh   = (DateTime)dr["NgaySinh"];
            dto.NgayLapThe = (DateTime)dr["NgayLapThe"];
            dto.NgayHetHan = (DateTime)dr["NgayHetHan"];

            LoaiDocGiaDTO temp = new LoaiDocGiaDTO();

            temp.MaLoaiDocGia  = (int)dr["MaLoaiDocGia"];
            temp.TenLoaiDocGia = lstLoaiDocGiaDTO[lstLoaiDocGiaDTO.IndexOf(temp)].TenLoaiDocGia;
            dto.LoaiDocGia     = temp;

            return(dto);
        }
コード例 #12
0
        private void getThongTinMa(string ma)
        {
            LoaiDocGiaDTO dg = new LoaiDocGiaDTO();

            Console.WriteLine(" Ma da chon: " + ma);

            List <LoaiDocGiaDTO> listDocGia = ldgBus.select(ma);

            if (listDocGia == null)
            {
                return;
            }
            Console.WriteLine(" Get thong tin thanh cong.");
            dg = listDocGia[0];
            if (dg == null)
            {
                MessageBox.Show("Get thong tin DG tu db that bai");
            }
            else
            {
                this.textBox_TenLoaiDocGia.Text = dg.TenLoaiDocGia;
            }
        }
コード例 #13
0
        public bool sua(LoaiDocGiaDTO ldg)
        {
            Console.WriteLine("Sua loai doc gia.");
            string query = string.Empty;

            query += "UPDATE [dbo].[tblLoaiDocGia]  SET ";
            query += "[tenLoaiDocGia] = @tenLoaiDocGia ";
            query += "WHERE [maLoaiDocGia] = @maLoaiDocGia";
            Console.WriteLine("Query: " + query);
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@tenLoaiDocGia", ldg.TenLoaiDocGia);
                    cmd.Parameters.AddWithValue("@maLoaiDocGia", ldg.MaLoaiDocGia);
                    Console.WriteLine("Bat dau query.");
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                        Console.WriteLine("ex query thanh cong.");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ex query that bai.");
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #14
0
        public bool sua(LoaiDocGiaDTO ldg)
        {
            bool re = ldgDAL.sua(ldg);

            return(re);
        }
コード例 #15
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            // Lấy thông tin của các chuỗi điều kiện
            string        strName    = txtName.Text.Trim();
            string        strAddress = txtAddress.Text.Trim();
            string        strEmail   = txtEmail.Text.Trim();
            LoaiDocGiaDTO loaidocgia = (LoaiDocGiaDTO)cmbType.SelectedItem;
            DateTime      dtBegin    = dtpBegin.Value;
            DateTime      dtEnd      = dtpEnd.Value;
            DateTime      dtBirth    = dtpBirth.Value;

            // Thêm điều kiện
            BUS_Service bus = new BUS_Service();

            List <string> lstKey   = new List <string>();
            List <object> lstValue = new List <object>();
            List <bool>   lstExact = new List <bool>();

            // Họ tên
            if (strName != "")
            {
                lstKey.Add("HoTen");
                lstValue.Add(strName);
                lstExact.Add(false);
            }
            // Số nhà
            if (strAddress != "")
            {
                lstKey.Add("SoNha");
                lstValue.Add(strAddress);
                lstExact.Add(false);
            }
            // Đường
            if (strEmail != "")
            {
                lstKey.Add("Email");
                lstValue.Add(strEmail);
                lstExact.Add(false);
            }

            lstKey.Add("MaLoaiDocGia");
            lstValue.Add(loaidocgia.MaLoaiDocGia);
            lstExact.Add(true);

            if (chkBegin.Checked == true)
            {
                lstKey.Add("NgayLapThe");
                lstValue.Add(dtBegin);
                lstExact.Add(true);
            }
            if (chkEnd.Checked == true)
            {
                lstKey.Add("NgayHetHan");
                lstValue.Add(dtEnd);
                lstExact.Add(true);
            }
            if (chkBirth.Checked == true)
            {
                lstKey.Add("NgaySinh");
                lstValue.Add(dtBirth);
                lstExact.Add(true);
            }

            TheDocGiaDTO[] result = bus.TheDocGia_GetByProperties(lstKey.ToArray(), lstValue.ToArray(), lstExact.ToArray());
            dgv.DataSource = result;

            // Thông báo
            if (result.Length == 0)
            {
                MessageBox.Show("Không có thẻ độc giả tương ứng.");
            }
            else
            {
                MessageBox.Show(result.Length + " thẻ độc giả được tìm thấy.");
            }

//            bus.Close();
        }