예제 #1
0
        private List <Class_MonAn> test1()
        {
            string             sql  = "SELECT * FROM MonAn";
            List <Class_MonAn> list = new List <Class_MonAn>();
            SqlConnection      con  = new SqlConnection();

            con.ConnectionString = @"Data Source=ADMIN\SQLEXPRESS;Initial Catalog=QLNhaHang;Integrated Security=True";
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);

            using (DbDataReader reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string      MaMonAn    = reader.GetString(0);
                        string      TenMonAn   = reader.GetString(1);
                        string      MaCongDung = reader.GetString(2);
                        string      MaLoai     = reader.GetString(3);
                        string      CachLam    = reader.GetString(4);
                        string      YeuCau     = reader.GetString(5);
                        decimal     DonGia     = reader.GetDecimal(6);
                        Class_MonAn Test       = new Class_MonAn(MaMonAn, TenMonAn, MaCongDung, MaLoai, CachLam, YeuCau, DonGia);
                        list.Add(Test);
                    }
                }
            }
            con.Close();
            return(list);
        }
예제 #2
0
        public void update(Class_MonAn mon_an)
        {
            string sql = "UPDATE MonAn WHERE SET MaMonAn=" + mon_an.MaMonAn1 + ",TenMonAn=N'" +
                         mon_an.TenMonAn1 + "', MaCongDung=N'" + mon_an.MaCongDung1 + "', MaLoai='" + mon_an.MaLoai1
                         + ",CachLam=N'" + mon_an.CachLam1 + ",YeuCau=N'" + mon_an.YeuCau1 + ",DonGia=N'" + mon_an.DonGia1 + "')";

            query.insert(sql);
        }
예제 #3
0
        public void insert(Class_MonAn mon_an)
        {
            string sql = "INSERT INTO MonAn(MaMonAn,TenMonAn,MaCongDung,MaLoai,CachLam,YeuCau,DonGia) VALUES(";

            sql += mon_an.MaMonAn1 + ",N'" + mon_an.TenMonAn1 + "',N'" + mon_an.MaCongDung1 + "',N'" + mon_an.MaLoai1 + "',N'"
                   + mon_an.CachLam1 + "',N'" + mon_an.YeuCau1 + "',N'" + mon_an.DonGia1 + "')";
            query.insert(sql);
        }
예제 #4
0
        public new List <Class_MonAn> Select()
        {
            string             sql  = "SELECT * FROM MonAn";
            List <Class_MonAn> list = new List <Class_MonAn>();
            SqlConnection      con  = new SqlConnection();

            con.ConnectionString = @"Data Source=DESKTOP-MFCIF4Q\SQLEXPRESS;Initial Catalog=QLNhaHang;Integrated Security=True";
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);

            using (DbDataReader reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string MaMonAn    = reader.GetString(0);
                        string TenMonAn   = reader.GetString(1);
                        string MaCongDung = reader.GetString(2);
                        string MaLoai     = reader.GetString(3);
                        string CachLam    = reader.GetString(4);
                        string YeuCau     = reader.GetString(5);
                        var    Tg         = reader.GetValue(6);
                        double DonGia;
                        if (Tg == DBNull.Value)
                        {
                            DonGia = 0;
                        }
                        else
                        {
                            DonGia = Convert.ToDouble(Tg);
                        }
                        //double DonGia = reader.GetDouble(6);
                        Class_MonAn Test = new Class_MonAn(MaMonAn, TenMonAn, MaCongDung, MaLoai, CachLam, YeuCau, DonGia);
                        list.Add(Test);
                    }
                }
            }
            con.Close();
            return(list);
        }
예제 #5
0
        public new List <Class_MonAn> Select()
        {
            string             sql  = "SELECT * FROM MonAn";
            List <Class_MonAn> list = new List <Class_MonAn>();

            query.ketnoiSQL();
            using (DbDataReader reader = query.Reader(sql))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string MaMonAn    = reader.GetString(0);
                        string TenMonAn   = reader.GetString(1);
                        string MaCongDung = reader.GetString(2);
                        string MaLoai     = reader.GetString(3);
                        string CachLam    = reader.GetString(4);
                        string YeuCau     = reader.GetString(5);
                        var    Tg         = reader.GetValue(6);
                        double DonGia;
                        if (Tg == DBNull.Value)
                        {
                            DonGia = 0;
                        }
                        else
                        {
                            DonGia = Convert.ToDouble(Tg);
                        }
                        //double DonGia = reader.GetDouble(6);
                        Class_MonAn Test = new Class_MonAn(MaMonAn, TenMonAn, MaCongDung, MaLoai, CachLam, YeuCau, DonGia);
                        list.Add(Test);
                    }
                }
            }
            query.DongketnoiSQL();
            return(list);
        }
예제 #6
0
        public void delete(Class_MonAn mon_an)
        {
            string sql = "DELETE FROM MonAn WHERE MaMonAn = " + mon_an.MaMonAn1;

            query.insert(sql);
        }