Exemplo n.º 1
0
        public static void Delete(Baiviet bv)
        {
            using (SqlConnection cnn = ConnectDataBase())
            {
                SqlCommand cmd = new SqlCommand("sp_Baiviet_Delete", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@mabv", bv.Mabv);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception)
                {

                }
            }
        }
Exemplo n.º 2
0
        public static void Insert(Baiviet bv)
        {
            using (SqlConnection cnn=ConnectDataBase())
            {
                SqlCommand cmd = new SqlCommand("sp_Baiviet_Insert", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@mabv", bv.Mabv);
                cmd.Parameters.AddWithValue("@ngayviet", bv.Ngayviet);
                cmd.Parameters.AddWithValue("@anhbaiviet", bv.Anhbaiviet);
                cmd.Parameters.AddWithValue("@tieude", bv.Tieude);
                cmd.Parameters.AddWithValue("@noidung", bv.Noidung);

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception)
                {

                }
            }
        }
Exemplo n.º 3
0
 public static void Baiviet_Insert(Baiviet bv)
 {
     BaivietDAO.Insert(bv);
 }
Exemplo n.º 4
0
 public static void Baiviet_Delete(Baiviet bv)
 {
     BaivietDAO.Delete(bv);
 }
Exemplo n.º 5
0
    protected void grb_baiviet_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string mabv = grb_baiviet.DataKeys[e.RowIndex].Value.ToString();

        Baiviet bv = new Baiviet();

        bv.Mabv = mabv;
        BaivietBUS.Baiviet_Delete(bv);
        FileInfo file = new FileInfo(Server.MapPath("~/images/common/") + mabv + ".jpg");
        if (file.Exists)
        {
            file.Delete();
        }
        Baiviet_Show();
    }
Exemplo n.º 6
0
    protected void btn_dangbaiviet_Click(object sender, EventArgs e)
    {
        Baiviet bv = new Baiviet();
        bv.Mabv = DateTime.Now.ToString("yyyyMMddHHmmss");
        bv.Ngayviet = DateTime.Now;
        bv.Anhbaiviet = bv.Mabv + ".jpg";
        bv.Tieude = txt_tieude.Text;
        bv.Noidung = cke_editor.Text;
        if (ful_anhbaiviet.HasFile && bv.Tieude != "" && bv.Noidung != "" && bv.Tieude.Length < 80)
        {
            ful_anhbaiviet.SaveAs(Server.MapPath("~/images/common/") + ful_anhbaiviet.FileName);
            FileInfo info = new FileInfo(ful_anhbaiviet.FileName);
            if (info.Extension == ".jpg")
            {
                File.Move(Server.MapPath("~/images/common/") + info.Name, Server.MapPath("~/images/common/") + bv.Anhbaiviet);

                try
                {
                    BaivietBUS.Baiviet_Insert(bv);
                    Baiviet_Show();
                    Response.Redirect(Request.Url.AbsoluteUri);//Refresh để tránh tình trang add thêm dữ liệu vào
                }
                catch (Exception ex)
                {
                    Response.Write("<script>alert('" + ex.Message + "')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Định dạng ảnh phải là JPEG(*.jpg)')</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('Bạn chưa nhập đầy đủ dữ liệu hoặc tiêu đề quá dài')</script>");
        }
    }