コード例 #1
0
 public bool TinTuc_Insert(Entity.TinTuc Data)
 {
     try
     {
         using (SqlCommand dbCmd = new SqlCommand("sp_TinTuc_Insert", GetConnection()))
         {
             dbCmd.CommandType = CommandType.StoredProcedure;
             dbCmd.Parameters.Add(new SqlParameter("@tieuDe", Data.TieuDe));
             dbCmd.Parameters.Add(new SqlParameter("@tomtat", Data.Tomtat));
             dbCmd.Parameters.Add(new SqlParameter("@noidung", Data.Noidung));
             dbCmd.Parameters.Add(new SqlParameter("@ngayviet", Data.Ngayviet));
             dbCmd.Parameters.Add(new SqlParameter("@id_nhanvien", Data.Id_nhanvien));
             dbCmd.Parameters.Add(new SqlParameter("@urlHinhAnh", Data.UrlHinhAnh));
             dbCmd.Parameters.Add(new SqlParameter("@Active", Data.Active));
             dbCmd.ExecuteNonQuery();
         }
         //Clear cache
         System.Web.HttpContext.Current.Cache.Remove("TinTuc");
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #2
0
        public List <TinTuc> TinTuc_GetByTop(string Top, string Where, string Order)
        {
            List <Entity.TinTuc> list = new List <Entity.TinTuc>();

            using (SqlCommand dbCmd = new SqlCommand("sp_TinTuc_GetByTop", GetConnection()))
            {
                Entity.TinTuc obj = new Entity.TinTuc();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                dr.Close();
                dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.TinTucIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return(list);
        }
コード例 #3
0
 public Entity.TinTuc TinTucIDataReader(IDataReader dr)
 {
     Entity.TinTuc obj = new Entity.TinTuc();
     obj.Id          = (dr["Id"] is DBNull) ? string.Empty : dr["Id"].ToString();
     obj.TieuDe      = (dr["TieuDe"] is DBNull) ? string.Empty : dr["TieuDe"].ToString();
     obj.Tomtat      = (dr["Tomtat"] is DBNull) ? string.Empty : dr["Tomtat"].ToString();
     obj.Noidung     = (dr["Noidung"] is DBNull) ? string.Empty : dr["Noidung"].ToString();
     obj.Ngayviet    = (dr["Ngayviet"] is DBNull) ? string.Empty : dr["Ngayviet"].ToString();
     obj.Id_nhanvien = (dr["Id_nhanvien"] is DBNull) ? string.Empty : dr["Id_nhanvien"].ToString();
     obj.UrlHinhAnh  = (dr["UrlHinhAnh"] is DBNull) ? string.Empty : dr["UrlHinhAnh"].ToString();
     obj.LuotXem     = (dr["LuotXem"] is DBNull) ? string.Empty : dr["LuotXem"].ToString();
     obj.Active      = (dr["Active"] is DBNull) ? string.Empty : dr["Active"].ToString();
     return(obj);
 }
コード例 #4
0
 public static bool TinTuc_Update(Entity.TinTuc data)
 {
     return(cmb.TinTuc_Update(data));
 }
コード例 #5
0
 public static bool TinTuc_Insert(Entity.TinTuc data)
 {
     return(cmb.TinTuc_Insert(data));
 }
コード例 #6
0
        protected void btnSave_Top_Click(object sender, EventArgs e)
        {
            Entity.TinTuc dt = new Entity.TinTuc();
            if (insert == true)
            {
                dt.TieuDe      = txttieude.Text;
                dt.Tomtat      = txttomtat.Text;
                dt.Noidung     = txtnoidung.Text;
                dt.Ngayviet    = txtngayviet.Text;
                dt.Id_nhanvien = txtIdNhanvien.Text;
                if (FileUpload2.HasFile)
                {
                    try
                    {
                        string Duoi_filename = Path.GetExtension(FileUpload2.FileName);
                        string filename      = FileUpload2.FileName.ToString();

                        if (Duoi_filename == ".jpeg" || Duoi_filename == ".jpg" || Duoi_filename == ".png" || Duoi_filename == ".PNG" || Duoi_filename == ".JPG" || Duoi_filename == ".JPEG")
                        {
                            FileUpload2.SaveAs(Server.MapPath("~/images/") + filename);
                            dt.UrlHinhAnh = "images/" + filename;
                        }
                        else
                        {
                            Response.Write("<script>alert('Bạn chỉ được upload jpg,png,jpeg')</script>");
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                else
                {
                }


                dt.Active = ckbActive.Checked == true ? "True" : "False";
                TinTucService.TinTuc_Insert(dt);
                Response.Write("<script>alert('Insert thành công!!!')</script>");
                getData();
            }
            else
            {
                dt.Id          = txtID.Text;
                dt.TieuDe      = txttieude.Text;
                dt.Tomtat      = txttomtat.Text;
                dt.Noidung     = txtnoidung.Text;
                dt.Ngayviet    = txtngayviet.Text;
                dt.Id_nhanvien = txtIdNhanvien.Text;
                if (FileUpload2.HasFile)
                {
                    try
                    {
                        string Duoi_filename = Path.GetExtension(FileUpload2.FileName);
                        string filename      = FileUpload2.FileName.ToString();

                        if (Duoi_filename == ".jpeg" || Duoi_filename == ".jpg" || Duoi_filename == ".png" || Duoi_filename == ".PNG" || Duoi_filename == ".JPG" || Duoi_filename == ".JPEG")
                        {
                            FileUpload2.SaveAs(Server.MapPath("~/images/") + filename);
                            dt.UrlHinhAnh = "images/" + filename;
                        }
                        else
                        {
                            Response.Write("<script>alert('Bạn chỉ được upload jpg,png,jpeg')</script>");
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                else
                {
                    dt.UrlHinhAnh = fileUpLoad;
                }

                dt.Active = ckbActive.Checked == true ? "True" : "False";
                TinTucService.TinTuc_Update(dt);
                Response.Write("<script>alert('Update thành công!!!')</script>");
                getData();
            }
            insert         = true;
            pnData.Visible = true;
            pnInfo.Visible = false;
            ClearText();
        }