Beispiel #1
0
        protected void btnThem_Click(object sender, EventArgs e)
        {
            if (txtMaNXB.Text != "" && txtTenNXB.Text != "")
            {
                // Lấy các giá trị từ giao diện
                NXB    nXB    = LayDuLieuTuForm();
                NXBDAO nXBDAO = new NXBDAO();
                // Kiểm tra mã nxb này đã tồn tại trong CSDL chưa
                bool exist = nXBDAO.CheckNXB(nXB.MaNXB);
                if (exist)
                {
                    lblMessage.Text = "Tài khoản đã tồn tại";
                }
                else
                {
                    // Thực hiện ghi xuống CSDL
                    bool result = nXBDAO.Insert(nXB);

                    if (result)
                    {
                        lblMessage.Text = "Thêm thành công!";
                        LayDuLieuVaoGridView();
                    }
                    else
                    {
                        lblMessage.Text = "Có lỗi. Vui lòng thử lại sau";
                    }
                }
            }
            else
            {
                lblMessage.Text = "Vui lòng điền đầy đủ thông tin";
            }
        }
Beispiel #2
0
        // GET: NXB/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null) // không có ID
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NXB nxb = db.NXBs.Find(id);

            if (nxb == null) // có ID nhưng không tìm thấy thông tin về id đó
            {
                return(HttpNotFound());
            }
            else
            {
                DataTable dttbNXB = new DataTable();
                using (SqlConnection sqlCon = new SqlConnection(connectionString))
                {
                    sqlCon.Open();
                    string SQL = "DECLARE @id INT; set @id = " + id + "; select * from DAUSACH" +
                                 " inner join NXB on DAUSACH.MaNXB = NXB.MaNXB where NXB.MaNXB = @id";
                    SqlDataAdapter sqlDa = new SqlDataAdapter(SQL, sqlCon); /**/
                    sqlDa.Fill(dttbNXB);
                }
                return(View(dttbNXB));
            }
        }
Beispiel #3
0
        //lay ma sach lon nhat
        public string GetMaNXBMax()
        {
            string manxb = "";

            try
            {
                //string masach = "";
                int maso;
                SQLDataContext.SQLData.sp_getMaNXBMax(ref manxb);
                maso = int.Parse(manxb.Substring(3)) + 1;
                if (maso.ToString().Length == 1)
                {
                    manxb = "NXB00" + maso.ToString();
                }
                else if (maso.ToString().Length == 2)
                {
                    manxb = "NXB0" + maso.ToString();
                }
                else
                {
                    manxb = "NXB" + maso.ToString();
                }

                SQLDataContext.CreateDataContext();
                NXB nxb = new NXB();
                nxb.MANXB = manxb;
                SQLDataContext.SQLData.NXBs.InsertOnSubmit(nxb);
                SQLDataContext.SQLData.SubmitChanges();
                return(manxb);
            }
            catch
            {
                return("demo");
            }
        }
Beispiel #4
0
        public ActionResult ChinhSuaNXB(int idNXB)
        {
            string        mainconn = ConfigurationManager.ConnectionStrings["WEBBANSACH"].ConnectionString;
            SqlConnection sqlconn  = new SqlConnection(mainconn);
            SqlCommand    sqlcomm  = new SqlCommand("[dbo].[XemChiTietNXB]");

            sqlconn.Open();
            sqlcomm.Connection  = sqlconn;
            sqlcomm.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter sd = new SqlDataAdapter(sqlcomm);

            sqlcomm.Parameters.AddWithValue("@MaNXB", idNXB);

            DataTable dt = new DataTable();

            sd.Fill(dt);
            sqlconn.Close();
            NXB xem = new NXB();

            foreach (DataRow dr in dt.Rows)
            {
                xem.MaNXB  = Convert.ToInt32(dr["MaNXB"]);
                xem.TenNXB = Convert.ToString(dr["TenNXB"]);
                xem.DiaChi = Convert.ToString(dr["DiaChi"]);
                xem.SDT    = Convert.ToString(dr["SDT"]);
            }
            return(View(xem));
        }
        public ViewResult XemChiTiet(int MaSach = 0)
        {
            Sach sach = db.Saches.SingleOrDefault(n => n.MaSach == MaSach);

            if (sach == null)
            {
                //Trả về trang báo lỗi
                Response.StatusCode = 404;
                return(null);
            }
            ChuDe chuDe = db.ChuDes.Single(n => n.MaChuDe == sach.MaChuDe);

            ViewBag.TenChuDe = chuDe.TenChuDe;
            //ChuDe cd = db.ChuDes.Single(n => n.MaChuDe == sach.MaChuDe);
            //ViewBag.TenCD = cd.TenChuDe;
            //ViewBag.TenChuDe = db.ChuDes.Single(n => n.MaChuDe == sach.MaChuDe).TenChuDe;
            NXB nXB = db.NXBs.Single(n => n.MaNXB == sach.MaNXB);

            ViewBag.TenNhaXuatBan = nXB.TenNXB;

            var list = (from s in db.SoHuus
                        where s.MaSach == MaSach
                        select s).ToList();

            foreach (var item in list)
            {
                ViewBag.TenTacGia = db.TacGias.Single(n => n.MaTacGia == item.MaTacGia).TenTacGia;
            }

            return(View(sach));
        }
Beispiel #6
0
        private NXB getNXBByForm()
        {
            NXB ans = new NXB();

            ans.TENNXB = txtTenNXB.Text;

            return(ans);
        }
Beispiel #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            NXB nXB = db.nXBs.Find(id);

            db.nXBs.Remove(nXB);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        private NXB getNHAXUATBANByForm()
        {
            NXB ans = new NXB();

            ans.TEN = txtTenNXB.Text;

            return(ans);
        }
Beispiel #9
0
 public static int Delete_NXB(NXB a)
 {
     SqlParameter[] para = new SqlParameter[]
     {
         new SqlParameter("@manxb", a.MaNXB),
     };
     return(DataProvider.ExecuteNonQuery("Delete_NXB", para));
 }
Beispiel #10
0
 public int edit(NXB r)
 {
     if (nxb.edit(r) == 1)
     {
         return(1);
     }
     return(0);
 }
Beispiel #11
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            NXB tg = getNXBByID();

            if (tg.ID == 0)
            {
                MessageBox.Show("Chưa có thông tin nhà xuất bản nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (btnSua.Text == "Sửa")
            {
                btnSua.Text     = "Lưu";
                btnThem.Enabled = false;
                btnXoa.Text     = "Hủy";

                groupThongTin.Enabled = true;
                dgvNXB.Enabled        = false;

                btnTimKiem.Enabled = false;
                txtTimKiem.Enabled = false;
                return;
            }

            if (btnSua.Text == "Lưu")
            {
                if (Check())
                {
                    btnSua.Text     = "Sửa";
                    btnThem.Enabled = true;
                    btnXoa.Text     = "Xóa";

                    groupThongTin.Enabled = false;
                    dgvNXB.Enabled        = true;

                    btnTimKiem.Enabled = true;
                    txtTimKiem.Enabled = true;

                    NXB tgs = getNXBByForm();
                    tg.TENNXB = tgs.TENNXB;

                    try
                    {
                        db.SaveChanges();
                        MessageBox.Show("Sửa thông tin nhà xuất bản  thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Sửa thông tin nhà xuất bản thất bại\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    LoadDgvNhanVien();
                }

                return;
            }
        }
Beispiel #12
0
 public bool sua(NXB n)
 {
     if (string.IsNullOrEmpty(n.maNXB))
     {
         return(false);
     }
     nxb.update(n);
     return(true);
 }
        public void ToExcel()
        {
            var listNhaXuatBan = new List <NXB>();
            var list           = db.NXBs.ToList();

            foreach (var item in list)
            {
                var model = new NXB();
                model.Manhaxuatban  = item.Manhaxuatban;
                model.Tennhaxuatban = item.Tennhaxuatban;
                model.Diachi        = item.Diachi;
                listNhaXuatBan.Add(model);
            }


            ExcelPackage   pck = new ExcelPackage();
            ExcelWorksheet ws  = pck.Workbook.Worksheets.Add("Report");

            ws.Cells["A1"].Value = "Communication";
            ws.Cells["B1"].Value = "Com2";

            ws.Cells["A2"].Value = "Report";
            ws.Cells["B2"].Value = "Report2";

            ws.Cells["A3"].Value = "Date";
            ws.Cells["B3"].Value = string.Format("{0:dd MMMM yyyy} at {0:H: mm tt}", DateTimeOffset.Now);

            ws.Cells["A6"].Value = "Ma Nha Xuat Ban";
            ws.Cells["B6"].Value = "Ten Nha Xuat Ban";
            ws.Cells["C6"].Value = "Dia Chi";


            int rowStart = 7;

            foreach (var item in list)
            {
                if (item.Manhaxuatban.Count() < 5)
                {
                    ws.Row(rowStart).Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                    ws.Row(rowStart).Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml(string.Format("pink")));
                }

                ws.Cells[string.Format("A{0}", rowStart)].Value = item.Manhaxuatban;
                ws.Cells[string.Format("B{0}", rowStart)].Value = item.Tennhaxuatban;
                ws.Cells[string.Format("C{0}", rowStart)].Value = item.Diachi;

                rowStart++;
            }

            ws.Cells["A:AZ"].AutoFitColumns();
            Response.Clear();
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.AddHeader("content-disposition", "attachment: filename=" + "ExcelReport.xlsx");
            Response.BinaryWrite(pck.GetAsByteArray());
            Response.End();
        }
Beispiel #14
0
 public NhaXuatBan(NXB nxb)
 {
     MaSoNXB     = nxb.masonxb;
     TenNXB      = nxb.ten;
     DiaChi      = nxb.diachi;
     SoDienThoai = nxb.sodienthoai;
     SoTaiKhoan  = nxb.sotaikhoan;
     TrangThai   = nxb.trangthai;
     NganHang    = nxb.nganhang;
 }
Beispiel #15
0
 public ActionResult Edit([Bind(Include = "MANXB,TENNXB,DIACHI,SDT,STK")] NXB nxb)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nxb).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nxb));
 }
Beispiel #16
0
 public ActionResult Edit([Bind(Include = "NXB_id,NXB_name,Address,AcountNumber,Phone,Email")] NXB nXB)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nXB).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nXB));
 }
Beispiel #17
0
        public int edit(NXB ls)
        {
            string sql = "update NXB set Name=N'" + ls.Name + "',Description=N'" + ls.Description + "'  where ID='" + ls.Id + "'";

            if (data.Edit(sql) > 0)
            {
                return(1);
            }
            return(0);
        }
Beispiel #18
0
 public ActionResult Edit([Bind(Include = "ID,TenNXB")] NXB nXB)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nXB).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nXB));
 }
Beispiel #19
0
        public void Delete(string id)
        {
            NXB nXB = db.NXBs.Find(id);

            if (nXB != null)
            {
                db.NXBs.Remove(nXB);
                db.SaveChanges();
            }
        }
Beispiel #20
0
        public ActionResult Create([Bind(Include = "ID,TenNXB")] NXB nXB)
        {
            if (ModelState.IsValid)
            {
                db.nXBs.Add(nXB);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(nXB));
        }
Beispiel #21
0
        public bool insert(NXB n)
        {
            if (dataTable("select * from NHAXUATBAN where MaNXB ='" + n.maNXB + "'").Rows.Count > 0)
            {
                return(false);
            }
            string sqlCommand = string.Format("insert into NHAXUATBAN values ('{0}',N'{1}',N'{2}','{3}',N'{4}')", n.maNXB, n.tenNXB, n.diaChi, n.email, n.thongTin);

            Excute(sqlCommand);
            return(true);
        }
Beispiel #22
0
        public ActionResult Create([Bind(Include = "MANXB,TENNXB,DIACHI,SDT,STK")] NXB nxb)
        {
            if (ModelState.IsValid)
            {
                db.NXBs.Add(nxb);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(nxb));
        }
Beispiel #23
0
        public ActionResult Create([Bind(Include = "NXB_id,NXB_name,Address,AcountNumber,Phone,Email")] NXB nXB)
        {
            if (ModelState.IsValid)
            {
                db.NXBs.Add(nXB);
                db.SaveChanges();
                return(RedirectToAction("Create"));
            }

            return(View(nXB));
        }
Beispiel #24
0
        public bool XoaNXB(string MaNXB)
        {
            QLThuVienEntities qltvEntity = new QLThuVienEntities();
            NXB nxb = new NXB();

            nxb.MaNXB = MaNXB;
            qltvEntity.NXBs.Attach(nxb);
            qltvEntity.NXBs.Remove(nxb);
            qltvEntity.SaveChanges();
            return(true);
        }
Beispiel #25
0
 public bool ThemNXB(NXB nxb)
 {
     try
     {
         SuaNXB(nxb);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #26
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string manxb  = GridView1.SelectedRow.Cells[0].Text;
            NXBDAO nXBDAO = new NXBDAO();
            NXB    nXB    = nXBDAO.GetTheLoaiByMaNXB(manxb);

            if (nXB != null)
            {
                // Đổ dữ liệu từ đối tượng TheLoai vào các trường trên Form
                DoDuLieuLenForm(nXB);
            }
        }
Beispiel #27
0
        public bool ThemNXB(string MaNXB, string TenNXB, string DiaChi)
        {
            QLThuVienEntities qltvEntity = new QLThuVienEntities();
            NXB nxb = new NXB();

            nxb.MaNXB  = MaNXB;
            nxb.TenNXB = TenNXB;
            nxb.DiaChi = DiaChi;
            qltvEntity.NXBs.Add(nxb);
            qltvEntity.SaveChanges();
            return(true);
        }
Beispiel #28
0
 //delete ma sach rong
 public void DeleteMaNXBMax()
 {
     try
     {
         NXB nxb = SQLDataContext.SQLData.NXBs.Single(xb => xb.TENNXB == null);
         SQLDataContext.SQLData.NXBs.DeleteOnSubmit(nxb);
         SQLDataContext.SQLData.SubmitChanges();
     }
     catch
     {
     }
 }
Beispiel #29
0
        // GET: Phieunhaps/Create
        public ActionResult Create()
        {
            List <NXB> nxb = db.NXBs.ToList();
            NXB        a   = new NXB();

            a.IdNXB  = 0;
            a.TenNXB = "Vui lòng chọn NXB";
            nxb.Add(a);
            ViewBag.IdNXB  = new SelectList(nxb, "IdNXB", "TenNXB");
            ViewBag.idsach = new SelectList(db.Saches, "IdSach", "TenSach");
            return(View());
        }
Beispiel #30
0
 public bool XoaNXB(NXB nxb)
 {
     try
     {
         SQLDataContext.SQLData.SP_XOANXB(nxb.MANXB);
         return(true);
     }
     catch
     {
         return(false);
     }
 }