コード例 #1
0
 public int Delete(LoaiHang lh)
 {
     if (Load_DAL("select * from LoaiHang where MaLH ='" + lh.MaLH + "'").Rows.Count == 0)
     {
         return(2);
     }
     else
     {
         if (Load_DAL("select * from MatHang where MaLH ='" + lh.MaLH + "'").Rows.Count > 0)
         {
             return(3);
         }
         else
         {
             SqlCommand cmd = new SqlCommand("Delete_LoaiHang", con);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new SqlParameter("@malh", lh.MaLH));
             try { if (con.State != ConnectionState.Open)
                   {
                       con.Open();
                   }
             } catch { return(-2); }
             try { cmd.ExecuteNonQuery(); return(1); } catch { return(0); } finally { if (con.State == ConnectionState.Open)
                                                                                      {
                                                                                          con.Close();
                                                                                      }
             }
         }
     }
 }
コード例 #2
0
        public List <LoaiHang> LayToanBoLoaiHang()
        {
            try
            {
                List <LoaiHang> dsLH = new List <LoaiHang>();
                OpenConnection();
                SqlCommand command = new SqlCommand();
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = "select * from LoaiHang";
                command.Connection  = conn;

                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string   maLH     = reader.GetString(0);
                    string   tenLH    = reader.GetString(1);
                    string   maSinhSP = reader.GetString(2);
                    LoaiHang lh       = new LoaiHang()
                    {
                        MaLoaiHang      = maLH,
                        TenLoaiHang     = tenLH,
                        MaSanPhamTuSinh = maSinhSP
                    };
                    dsLH.Add(lh);
                }
                reader.Close();
                return(dsLH);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public void xoaLoaiHang(LoaiHang lh)
        {
            string sqlUpdate = "delete from LoaiHang where maLoai=@maLoai";

            KetNoiCSDL.moKetNoi();
            SqlCommand cmd = new SqlCommand(sqlUpdate, KetNoiCSDL.connect);

            cmd.Parameters.AddWithValue("maLoai", lh.MaLoai);
            cmd.ExecuteNonQuery();
            KetNoiCSDL.dongKetNoi();
        }
コード例 #4
0
        public void xoaLoaiHang(LoaiHang lh)
        {
            string query = "delete from LoaiHang where maLoaiHang=@maLoaiHang";

            Connect.openConnect();
            SqlCommand cmd = new SqlCommand(query, Connect.connect);

            cmd.Parameters.AddWithValue("maLoaiHang", lh.MaLoaiHang);
            cmd.ExecuteNonQuery();
            Connect.closeConnect();
        }
コード例 #5
0
        public void themLoaiHang(LoaiHang lh)
        {
            string query = "insert into LoaiHang values(@tenLoaiHang)";

            Connect.openConnect();
            SqlCommand cmd = new SqlCommand(query, Connect.connect);

            cmd.Parameters.AddWithValue("tenLoaiHang", lh.TenLoaiHang);
            cmd.ExecuteNonQuery();
            Connect.closeConnect();
        }
コード例 #6
0
        public void suaLoaiHang(LoaiHang lh)
        {
            string query = "update LoaiHang set  tenLoaiHang =@tenLoaiHang where maLoaiHang =@maLoaiHang ";

            Connect.openConnect();
            SqlCommand cmd = new SqlCommand(query, Connect.connect);

            cmd.Parameters.AddWithValue("maLoaiHang", lh.MaLoaiHang);
            cmd.Parameters.AddWithValue("tenLoaiHang", lh.TenLoaiHang);
            cmd.ExecuteNonQuery();
            Connect.closeConnect();
        }
コード例 #7
0
        public void suaLoaiHang(LoaiHang lh)
        {
            string sqlUpdate = "update LoaiHang set  tenLoai=@tenLoai, ghiChu=@ghiChu where maLoai=@maLoai";

            KetNoiCSDL.moKetNoi();
            SqlCommand cmd = new SqlCommand(sqlUpdate, KetNoiCSDL.connect);

            cmd.Parameters.AddWithValue("maLoai", lh.MaLoai);
            cmd.Parameters.AddWithValue("tenLoai", lh.TenLoai);
            cmd.Parameters.AddWithValue("ghiChu", lh.GhiChu);;
            cmd.ExecuteNonQuery();
            KetNoiCSDL.dongKetNoi();
        }
コード例 #8
0
        public void themLoaiHang(LoaiHang lh)
        {
            string sqlSelect = "insert into LoaiHang values(@maLoai, @tenLoai, @ghiChu)";

            KetNoiCSDL.moKetNoi();
            SqlCommand cmd = new SqlCommand(sqlSelect, KetNoiCSDL.connect);

            cmd.Parameters.AddWithValue("maLoai", lh.MaLoai);
            cmd.Parameters.AddWithValue("tenLoai", lh.TenLoai);
            cmd.Parameters.AddWithValue("ghiChu", lh.GhiChu);
            cmd.ExecuteNonQuery();
            KetNoiCSDL.dongKetNoi();
        }
コード例 #9
0
        public List <LoaiHang> layTatCaLoaiHang()
        {
            List <LoaiHang> arr = new List <LoaiHang>();

            KetNoiCSDL.moKetNoi();
            string        get = "select * from LoaiHang";
            SqlCommand    cmd = new SqlCommand(get, KetNoiCSDL.connect);
            SqlDataReader dr  = cmd.ExecuteReader();

            while (dr.Read())
            {
                LoaiHang lh = new LoaiHang(dr["maLoai"] + "", dr["tenLoai"] + "", dr["ghiChu"] + "");
                arr.Add(lh);
            }
            KetNoiCSDL.dongKetNoi();
            return(arr);
        }
コード例 #10
0
        public List <LoaiHang> layLoaiHang()
        {
            List <LoaiHang> arr = new List <LoaiHang>();


            Connect.openConnect();
            string        get = "select * from LoaiHang";
            SqlCommand    cmd = new SqlCommand(get, Connect.connect);
            SqlDataReader dr  = cmd.ExecuteReader();

            while (dr.Read())
            {
                LoaiHang x = new LoaiHang(int.Parse(dr["maLoaiHang"] + ""), dr["tenLoaiHang"] + "");
                arr.Add(x);
            }
            Connect.closeConnect();
            return(arr);
        }
コード例 #11
0
        public List <LoaiHang> timLoaiHang(LoaiHang lh)
        {
            List <LoaiHang> arr = new List <LoaiHang>();

            KetNoiCSDL.moKetNoi();
            string     get = "select * from LoaiHang where maLoai=@maLoai";
            SqlCommand cmd = new SqlCommand(get, KetNoiCSDL.connect);

            cmd.Parameters.AddWithValue("maLoai", lh.MaLoai);
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                LoaiHang loaiHang = new LoaiHang(dr["maLoai"].ToString(), dr["tenLoai"].ToString(), dr["ghiChu"].ToString());
                arr.Add(loaiHang);
            }
            KetNoiCSDL.dongKetNoi();
            return(arr);
        }
コード例 #12
0
        public List <LoaiHang> danhSachMaLoaiHang(string ma)
        {
            List <LoaiHang> list = new List <LoaiHang>();

            KetNoiCSDL.moKetNoi();
            string     sql = "select LoaiHang.maLoai, tenLoai from LoaiHang";
            SqlCommand cmd = new SqlCommand(sql, KetNoiCSDL.connect);

            cmd.Parameters.AddWithValue("ma", ma);
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                LoaiHang lh = new LoaiHang(dr["maLoai"].ToString(), dr["tenLoai"].ToString());
                list.Add(lh);
            }
            KetNoiCSDL.dongKetNoi();
            list.Count();
            return(list);
        }
コード例 #13
0
        public List <LoaiHang> layLoaiHangTheoMa(string maLoaiHang)
        {
            List <LoaiHang> arr = new List <LoaiHang>();

            Connect.openConnect();
            string     get = "select * from LoaiHang where maLoaiHang LIKE @maLoaiHang + '%'";
            SqlCommand cmd = new SqlCommand(get, Connect.connect);

            cmd.Parameters.AddWithValue("maLoaiHang", maLoaiHang);

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                LoaiHang x = new LoaiHang(int.Parse(dr["maLoaiHang"] + ""), dr["tenLoaiHang"] + "");
                arr.Add(x);
            }
            Connect.closeConnect();
            return(arr);
        }
コード例 #14
0
        public void SuaLoaiHang(LoaiHang lh)
        {
            try
            {
                OpenConnection();
                SqlCommand command = new SqlCommand();

                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "pro_SuaLoaiHang";
                command.Connection  = conn;



                command.Parameters.Add("@MaLoaiHang", SqlDbType.NVarChar).Value      = lh.MaLoaiHang;
                command.Parameters.Add("@TenLoaiHang", SqlDbType.NVarChar).Value     = lh.TenLoaiHang;
                command.Parameters.Add("@MaSanPhamTuSinh", SqlDbType.NVarChar).Value = lh.MaSanPhamTuSinh;

                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }