protected void btnCreate_Click(object sender, EventArgs e)
        {
            mtvTheLoai.ActiveViewIndex = 1;
            clsTheLoai tl = new clsTheLoai();
            tl.TenTheLoai = txtName.Text;
            tl.MoTa = txtMota.Text;
            tl.Hot = ckbHot.Checked;
            tl.Stt = Convert.ToInt32(txtViTri.Text);
            tl.Images = DateTime.Now.Second + fileUp.FileName;
            clsBSTheLoai bsTL = new clsBSTheLoai();
            //if (fileUp.HasFile)
            //{
                if (bsTL.InsertTL(tl))
                {
                    lblMes.Text = "<script>alert('Danh mục phụ đã được tạo');</script>";
                    mtvTheLoai.ActiveViewIndex = 0;
                    grvTheLoai.DataBind();
                    //fileUp.SaveAs(Server.MapPath("~/Images/HinhAnh/") + DateTime.Now.Second + fileUp.FileName);
                }
                else
                {
                    lblMes.Text = "<script>alert('Lỗi, vui lòng kiểm tra dữ liệu !');</script>";
                }

               // }
            //else {
               //     lblMes.Text = "<script>alert('Bạn chưa chọn hình ảnh !');</script>";
              //  }
        }
Пример #2
0
        // Sua danh muc
        public bool EditTheLoai(clsTheLoai dm,int type)
        {
            string sql="";
            if (type==1)
            {
                sql = "Update tblTheloai set TenTheLoai=@TenTheLoai,MaDanhMuc=@MaDanhMuc,MaQuocGia=@MaQuocGia,Mota=@Mota,STT=@STT,Hot=@Hot,ImageTL=@ImageTL Where ID=@ID";

            }
            else if (type==2)
            {
                sql= "Update tblTheloai set TenTheLoai=@TenTheLoai,MaDanhMuc=@MaDanhMuc,MaQuocGia=@MaQuocGia,Mota=@Mota,STT=@STT,Hot=@Hot Where ID=@ID";

            }
              bool st = false;
            clsDAConnection conn = new clsDAConnection();
            conn.openCon();
            using (SqlCommand com = conn.getCon().CreateCommand())
            {
                com.CommandType = CommandType.Text;
                com.CommandText = sql;

                // Create a SqlParameter object for the title parameter.
                SqlParameter p1 = com.CreateParameter();
                p1.ParameterName = "@TenTheLoai";
                p1.SqlDbType = SqlDbType.NVarChar;
                p1.Size = 50;
                p1.Value = dm.TenTheLoai;
                com.Parameters.Add(p1);

                // Use a shorthand syntax to add the id parameter.
                com.Parameters.Add("@MaDanhMuc", SqlDbType.Int).Value = dm.MyDanhMuc;
                com.Parameters.Add("@MaQuocGia", SqlDbType.Int).Value = dm.MyQuocGia;
                com.Parameters.Add("@Mota", SqlDbType.NVarChar, 1000).Value = dm.MoTa;
                com.Parameters.Add("@STT", SqlDbType.Int).Value = dm.Stt;
                com.Parameters.Add("@Hot", SqlDbType.Int).Value = dm.Hot;
                com.Parameters.Add("@ID", SqlDbType.Int).Value = dm.Id;
                if (type==1)
                {
                    com.Parameters.Add("@ImageTL", SqlDbType.NVarChar).Value = dm.Images;
                }
                // Execute the command and process the result.
                if (com.ExecuteNonQuery() == 1)
                {
                    st = true;
                }
                conn.closeCon();
                return st;
            }
        }
Пример #3
0
 public bool DeleteTheLoai(clsTheLoai dm)
 {
     string sql = "Delete from tblTheLoai Where ID=@ID";
     bool st = false;
     clsDAConnection conn = new clsDAConnection();
     conn.openCon();
     using (SqlCommand com = conn.getCon().CreateCommand())
     {
         com.CommandType = CommandType.Text;
         com.CommandText = sql;
         com.Parameters.Add("@ID", SqlDbType.Int).Value = dm.Id;
         // Execute the command and process the result.
         if (com.ExecuteNonQuery() == 1)
         {
             st = true;
         }
         conn.closeCon();
         return st;
     }
 }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            clsTheLoai tl = new clsTheLoai();
            tl.TenTheLoai = txtNameEdit.Text;
            tl.MoTa = txtMotaEdit.Text;
            tl.Hot = ckbHotEdit.Checked;
            tl.Stt = Convert.ToInt32(txtViTriEdit.Text);
            tl.Id = Convert.ToInt32(hfID.Value);
            tl.Images = DateTime.Now.Second + fileEdit.FileName;
            clsBSTheLoai bsTL = new clsBSTheLoai();
            int type = 2;
            //if (CheckBox1.Checked)
            //{
            //    type = 1;
            //}
            //else {
            //    type = 2;
            //}

            if (bsTL.EditTL(tl,2))
            {
                if (type==1)
                {
                    //if (fileEdit.HasFile)
                    //{
                    //    //fileEdit.SaveAs(Server.MapPath("~/Images/HinhAnh/") + DateTime.Now.Second + fileUp.FileName);
                    //}
                    //else {
                    //    lblMes.Text = "<script>alert('Bạn chưa chọn file');</script>";
                    //}

                }
                lblMes.Text = "<script>alert('Danh mục phụ đã được sửa');</script>";
                mtvTheLoai.ActiveViewIndex = 0;
                grvTheLoai.DataBind();
            }
            else
            {
                lblMes.Text = "<script>alert('Lỗi, vui lòng kiểm tra dữ liệu !');</script>";
            }
        }
Пример #5
0
        public clsTheLoai GetById(int id)
        {
            clsDAConnection con = new clsDAConnection();
            try
            {
                clsTheLoai obj = new clsTheLoai();
                string str = "select * from tblTheLoai where id=@id";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@id", id);
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                if (dr.Read())
                {

                    if (dr["tentheloai"] != DBNull.Value)
                    {
                        obj.TenTheLoai = dr["tentheloai"].ToString();
                    }
                    if (dr["stt"] != DBNull.Value)
                    {
                        obj.Stt = Convert.ToInt32(dr["stt"].ToString());
                    }
                    if (dr["MaQuocGia"] != DBNull.Value)
                    {
                        obj.QuocGia.Id = Convert.ToInt32(dr["MaQuocGia"].ToString());
                    }
                    if (dr["MaDanhMuc"] != DBNull.Value)
                    {
                        obj.DanhMuc.Id = Convert.ToInt32(dr["MaDanhMuc"].ToString());
                    }
                    if (dr["id"] != DBNull.Value)
                    {
                        obj.Id = Convert.ToInt32(dr["id"].ToString());
                    }
                }
                con.closeCon();
                return obj;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
Пример #6
0
        public bool InsertTL(clsTheLoai dm)
        {
            string sql = "Insert into tblTheLoai(TenTheLoai,MaDanhMuc,MaQuocGia,MoTa,STT,Hot) values(@TenTheLoai,@MaDanhMuc,@MaQuocGia,@MoTa,@STT,@Hot)";
            bool st = false;
            clsDAConnection conn = new clsDAConnection();
            conn.openCon();
            using (SqlCommand com = conn.getCon().CreateCommand())
            {
                com.CommandType = CommandType.Text;
                com.CommandText = sql;

                // Create a SqlParameter object for the title parameter.
                SqlParameter p1 = com.CreateParameter();
                p1.ParameterName = "@TenTheLoai";
                p1.SqlDbType = SqlDbType.NVarChar;
                p1.Size = 50;
                p1.Value = dm.TenTheLoai;
                com.Parameters.Add(p1);

                // Use a shorthand syntax to add the id parameter.
                com.Parameters.Add("@MaDanhMuc", SqlDbType.Int).Value = dm.MyDanhMuc;
                com.Parameters.Add("@MaQuocGia", SqlDbType.Int).Value = dm.MyQuocGia;
                com.Parameters.Add("@Mota", SqlDbType.NVarChar, 1000).Value = dm.MoTa;
                com.Parameters.Add("@STT", SqlDbType.Int).Value = dm.Stt;
                com.Parameters.Add("@Hot", SqlDbType.Int).Value = dm.Hot;
                //com.Parameters.Add("@ImageTL", SqlDbType.NVarChar).Value = dm.Images;
                // Execute the command and process the result.
                if (com.ExecuteNonQuery() == 1)
                {
                    st = true;
                }
                conn.closeCon();
                return st;
            }
        }
Пример #7
0
 public List<clsTheLoai> GetByQuocGia2(int id)
 {
     clsDAConnection con = new clsDAConnection();
     try
     {
         List<clsTheLoai> list = new List<clsTheLoai>();
         string str = "select * from tblTheLoai where maquocgia=@maquocgia and madanhmuc<>1 and hot=1";
         SqlCommand com = new SqlCommand(str, con.getCon());
         com.Parameters.AddWithValue("@maquocgia", id);
         con.openCon();
         SqlDataReader dr = com.ExecuteReader();
         while (dr.Read())
         {
             clsTheLoai obj = new clsTheLoai();
             if (dr["tentheloai"] != DBNull.Value)
             {
                 obj.TenTheLoai = dr["tentheloai"].ToString();
             }
             if (dr["stt"] != DBNull.Value)
             {
                 obj.Stt = Convert.ToInt32(dr["stt"].ToString());
             }
             if (dr["MaQuocGia"] != DBNull.Value)
             {
                 obj.QuocGia.Id = Convert.ToInt32(dr["MaQuocGia"].ToString());
             }
             if (dr["MaDanhMuc"] != DBNull.Value)
             {
                 obj.DanhMuc.Id = Convert.ToInt32(dr["MaDanhMuc"].ToString());
             }
             if (dr["id"] != DBNull.Value)
             {
                 obj.Id = Convert.ToInt32(dr["id"].ToString());
             }
             list.Add(obj);
         }
         con.closeCon();
         return list;
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         con.closeCon();
     }
 }
 protected void btnXoa_Click(object sender, EventArgs e)
 {
     LinkButton lbt = (LinkButton)sender;
     HiddenField h = (HiddenField)lbt.FindControl("hfID");
     clsTheLoai tl = new clsTheLoai();
     tl.Id = Convert.ToInt32(h.Value);
     clsBSTheLoai t = new clsBSTheLoai();
     if (t.DelTL(tl))
     {
         lblMes.Text = "<script>alert('Danh mục phụ đã được xóa');</script>";
         mtvTheLoai.ActiveViewIndex = 0;
         grvTheLoai.DataBind();
     }
     else
     {
         lblMes.Text = "<script>alert('Lỗi, không thể xóa !');</script>";
     }
 }
Пример #9
0
 public bool InsertTL(clsTheLoai dm)
 {
     clsDATheLoai d = new clsDATheLoai();
     return d.InsertTL(dm);
 }
Пример #10
0
 public bool EditTL(clsTheLoai dm,int type)
 {
     clsDATheLoai d = new clsDATheLoai();
     return d.EditTheLoai(dm,type);
 }
Пример #11
0
 public bool DelTL(clsTheLoai dm)
 {
     clsDATheLoai d = new clsDATheLoai();
     return d.DeleteTheLoai(dm);
 }