Пример #1
0
        public DataTable Select()
        {
            SqlConnection cn = new SqlConnection(cnString);

            cn = CDatabase.Get_Database_Connection();

            DataTable tb = new DataTable();

            try
            {
                string sqlText = "SELECT * from HANG_HOA";
                tb = CDatabase.Get_Data_Table(sqlText);

                CDatabase.Execute_SQL(sqlText);
                //MyDataGrid_SP.DataContext = tb.DefaultView;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                CDatabase.Close_Database_Connection();
            }
            return(tb);
        }
Пример #2
0
        public DataTable Search_HangTonKho(string keyWord)
        {
            SqlConnection cn = new SqlConnection(cnString);

            cn = CDatabase.Get_Database_Connection();

            DataTable tb = new DataTable();

            try
            {
                string sqlText = "SELECT h.MAHH as 'Mã hàng hóa', h.TENHH as 'Tên hàng hóa', n.TENNHOM as 'Tên nhóm hàng', h.SLTON as 'Số lượng còn trong kho' from HANG_HOA h, NHOM_HANG n WHERE h.MANHOM=n.MANHOM AND (h.MAHH LIKE '%" + keyWord + "%'OR h.TENHH LIKE '%" + keyWord + "%' OR n.TENNHOM LIKE '%" + keyWord + "%')";
                tb = CDatabase.Get_Data_Table(sqlText);

                CDatabase.Execute_SQL(sqlText);
                //MyDataGrid_SP.DataContext = tb.DefaultView;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                CDatabase.Close_Database_Connection();
            }
            return(tb);
        }
Пример #3
0
        public void DoanhThu_HomNay()
        {
            SqlConnection cn = new SqlConnection(cnString);

            cn = CDatabase.Get_Database_Connection();

            DataTable tb = new DataTable();

            try
            {
                string sqlText = "SELECT * FROM HOA_DON WHERE month(getdate())=month(NGAYNHAP)";
                tb = CDatabase.Get_Data_Table(sqlText);

                CDatabase.Execute_SQL(sqlText);
                //MyDataGrid_SP.DataContext = tb.DefaultView;

                object SumRevenue = null;
                SumRevenue = tb.Compute("Sum(TONGTIEN)", "");
                MessageBox.Show("Doanh thu là : " + SumRevenue.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                CDatabase.Close_Database_Connection();
            }
        }
Пример #4
0
        public bool Update(CProductBLL p)
        {
            bool          isSuccess = false;
            SqlConnection cn        = new SqlConnection(cnString);

            cn = CDatabase.Get_Database_Connection();
            try
            {
                string sqlText = "UPDATE HANG_HOA SET MAHH=@m_MaHH,MAHTDG=@m_MaHTDG,MANHOM=@m_MaNhom,TENHH=@m_TenHH, DVT=@m_DVT, DONGIA=@m_DonGia, SLTON=@m_SLTon WHERE MAHH=@m_MaHH";

                SqlCommand cmd = new SqlCommand(sqlText, cn);

                cmd.Parameters.AddWithValue("@m_MaHH", p.m_MaHH);
                cmd.Parameters.AddWithValue("@m_MaHTDG", p.m_MaHTDG);
                cmd.Parameters.AddWithValue("@m_MaNhom", p.m_MaNhom);
                cmd.Parameters.AddWithValue("@m_TenHH", p.m_TenHH);
                cmd.Parameters.AddWithValue("@m_DVT", p.m_DVT);
                cmd.Parameters.AddWithValue("@m_DonGia", p.m_DonGia);
                cmd.Parameters.AddWithValue("@m_SLTon", p.m_SLTon);

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                CDatabase.Close_Database_Connection();
            }

            return(isSuccess);
        }
Пример #5
0
        public bool Insert(CBillBLL p)
        {
            bool          isSuccess = false;
            SqlConnection cn        = new SqlConnection(cnString);

            cn = CDatabase.Get_Database_Connection();
            try
            {
                string sqlText = "insert into HOA_DON(MAHD,MANV,MADL,NGAYLAP,MAKM,TONGTIEN) values (@m_MaHD,@m_MaNV,@m_MaDL,@m_NgayLap, @m_MaKM, @m_TongTien)";

                SqlCommand cmd = new SqlCommand(sqlText, cn);

                cmd.Parameters.AddWithValue("@m_MaHD", p.m_MaHD);
                cmd.Parameters.AddWithValue("@m_MaNV", p.m_MaNV);
                cmd.Parameters.AddWithValue("@m_MaDL", p.m_MaDL);
                cmd.Parameters.AddWithValue("@m_NgayLap", p.m_NgayLap);
                cmd.Parameters.AddWithValue("@m_MaKM", p.m_MaKM);
                cmd.Parameters.AddWithValue("@m_TongTien", p.m_TongTien);

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                CDatabase.Close_Database_Connection();
            }
            return(isSuccess);
        }
Пример #6
0
        public bool Delete(CProductBLL p)
        {
            bool          isSuccess = false;
            SqlConnection cn        = new SqlConnection(cnString);

            cn = CDatabase.Get_Database_Connection();
            try
            {
                string sqlText = "DELETE FROM HANG_HOA WHERE MAHH=@m_MaHH";

                SqlCommand cmd = new SqlCommand(sqlText, cn);

                cmd.Parameters.AddWithValue("@m_MaHH", p.m_MaHH);


                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                CDatabase.Close_Database_Connection();
            }

            return(isSuccess);
        }