Example #1
0
        // Chuyển giá trị trong Textbox thành tblTacGia
        public tblTacGia Textbox_To_tblTacGia()
        {
            try
            {
                tblTacGia result = new tblTacGia();


                result.id       = (int)this.numbid.Value;
                result.ten      = (this.txtten.Text == null ? null : (string)(this.txtten.Text));
                result.ngaySinh = this.datengaySinh.Value;
                result.moTa     = (this.txtmoTa.Text == null ? null : (string)(this.txtmoTa.Text));

                return(result);
            }
            catch (Exception ex) { ShowMessage(ex.Message, false); } // Không load được hoặc xảy ra lỗi
            return(null);
        }
Example #2
0
        // xóa TacGia
        public bool DeleteTacGia(tblTacGia item)
        {
            string        sql = "Delete SACH Where MATAGIA= @MATAGIA";
            SqlConnection con = dc.GetConnection();

            try
            {
                cmd = new SqlCommand(sql, con);
                con.Open();
                cmd.Parameters.Add("@MATAGIA", SqlDbType.Int).Value = item.MATACGIA;

                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Example #3
0
        // chỉnh sửa TacGia
        public bool UpdateTacGia(tblTacGia item)
        {
            string sql = "Update TACGIA " +
                         "set MATACGIA = @MATACGIA, TENTACGIA = @TENTACGIA" +
                         " WHERE MATACGIA = @MATACGIA ";
            SqlConnection con = dc.GetConnection();

            try
            {
                cmd = new SqlCommand(sql, con);
                con.Open();
                cmd.Parameters.Add("@MATACGIA", SqlDbType.Int).Value       = item.MATACGIA;
                cmd.Parameters.Add("@TENTACGIA", SqlDbType.NVarChar).Value = item.TENTACGIA;

                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Example #4
0
        // Chuyển giá trị trong DataGridView thành tblTacGia
        public tblTacGia DataGridView_To_tblTacGia(int index)
        {
            try
            {
                tblTacGia result = new tblTacGia();


                var id = this.dgvData.Rows[index].Cells["id"].Value;
                if (id != null)
                {
                    result.id = int.Parse(id.ToString());
                }

                var ten = this.dgvData.Rows[index].Cells["ten"].Value;
                if (ten != null)
                {
                    result.ten = (ten == null ? null : (string)(ten));
                }

                var ngaySinh = this.dgvData.Rows[index].Cells["ngaySinh"].Value;
                if (ngaySinh != null)
                {
                    result.ngaySinh = (ngaySinh == null ? null : (DateTime?)DateTime.Parse(ngaySinh.ToString()));
                }

                var moTa = this.dgvData.Rows[index].Cells["moTa"].Value;
                if (moTa != null)
                {
                    result.moTa = (moTa == null ? null : (string)(moTa));
                }

                return(result);
            }
            catch (Exception ex) { ShowMessage(ex.Message, false); } // Không load được hoặc xảy ra lỗi
            return(null);
        }
Example #5
0
        // thêm TacGia
        public bool InsertTacGia(tblTacGia item)
        {
            string sql = "insert into TACGIA(C) " +
                         "VALUES(@MATACGIA,@TENTACGIA)";


            SqlConnection con = dc.GetConnection();

            try
            {
                cmd = new SqlCommand(sql, con);
                con.Open();
                cmd.Parameters.Add("@MATACGIA", SqlDbType.Int).Value       = item.MATACGIA;
                cmd.Parameters.Add("@TENTACGIA", SqlDbType.NVarChar).Value = item.TENTACGIA;

                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
 public bool DeleteTacGia(tblTacGia kh)
 {
     return(daBLL.DeleteTacGia(kh));
 }
 public bool UpdateTacGia(tblTacGia kh)
 {
     return(daBLL.UpdateTacGia(kh));
 }
 public bool InsertTacGia(tblTacGia kh)
 {
     return(daBLL.InsertTacGia(kh));
 }
Example #9
0
        public ActionResult Create(tblTacGia model, HttpPostedFile filePost, FormCollection collection)
        {
            string fileLocation = "";

            if (Request.Files["filePost"].ContentLength <= 0)
            {
                model.IMAGE = "";
            }
            ModelState["filePost"].Errors.Clear();

            //if (ModelState.IsValid == true)
            //{
            if (Request.Files["filePost"].ContentLength > 0)
            {
                string fileExtension = System.IO.Path.GetExtension(Request.Files["filePost"].FileName);
                fileLocation = Server.MapPath("~/Content/") + Request.Files["filePost"].FileName;
                if (System.IO.File.Exists(fileLocation))
                {
                    System.IO.File.Delete(fileLocation);
                }
                Request.Files["filePost"].SaveAs(fileLocation);
            }
            string strRadio = collection["customRadio"].ToString();

            if (strRadio == "Nam")
            {
                model.GIOI_TINH = 1;
            }
            else if (strRadio == "Nu")
            {
                model.GIOI_TINH = 0;
            }
            db = new TRUONGHOCDbContext();
            model.TRANG_THAI = 1;
            int iContent = fileLocation.IndexOf("Content");

            if (iContent > 0)
            {
                model.IMAGE = @"\" + fileLocation.Substring(iContent, fileLocation.Length - iContent);
            }
            var item = db.tblTacGias.Where(x => x.TRANG_THAI == 1).ToList();

            foreach (var itemTG in item)
            {
                if (model.MA_TACGIA == itemTG.MA_TACGIA)
                {
                    ModelState.AddModelError("", "Mã đã tồn tại");
                    break;
                }
            }

            if (ModelState.IsValid)
            {
                db.tblTacGias.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index", "TacGia"));
            }
            else
            {
                return(View());
            }
        }